Skip to content

Commit

Permalink
make Helide more consistent with HeCore example
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffamstutz committed Jan 11, 2024
1 parent 23b0752 commit e1be197
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 73 deletions.
6 changes: 2 additions & 4 deletions libs/helide/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ anari_generate_queries(
NAME helide
PREFIX HelideDevice
CPP_NAMESPACE helide
JSON_DEFINITIONS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/helide_device.json
JSON_DEFINITIONS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/HelideDefinitions.json
)

## Core device target ##
Expand Down Expand Up @@ -97,9 +97,7 @@ project_sources(PRIVATE
)

include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME}
EXPORT_MACRO_NAME "HELIDE_DEVICE_INTERFACE"
)
generate_export_header(${PROJECT_NAME} EXPORT_MACRO_NAME "HELIDE_EXPORT")

project_include_directories(
PUBLIC
Expand Down
File renamed without changes.
82 changes: 20 additions & 62 deletions libs/helide/HelideDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,9 @@
#include "frame/Frame.h"
#include "scene/volume/spatial_field/SpatialField.h"

namespace helide {

///////////////////////////////////////////////////////////////////////////////
// Generated function declarations ////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

const char **query_object_types(ANARIDataType type);

const void *query_object_info(ANARIDataType type,
const char *subtype,
const char *infoName,
ANARIDataType infoType);

const void *query_param_info(ANARIDataType type,
const char *subtype,
const char *paramName,
ANARIDataType paramType,
const char *infoName,
ANARIDataType infoType);

const char **query_extensions();
#include "HelideDeviceQueries.h"

///////////////////////////////////////////////////////////////////////////////
// Helper functions ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

template <typename HANDLE_T, typename OBJECT_T>
inline HANDLE_T getHandleForAPI(OBJECT_T *object)
{
return (HANDLE_T)object;
}

template <typename OBJECT_T, typename HANDLE_T, typename... Args>
inline HANDLE_T createObjectForAPI(HelideGlobalState *s, Args &&...args)
{
return getHandleForAPI<HANDLE_T>(
new OBJECT_T(s, std::forward<Args>(args)...));
}
namespace helide {

///////////////////////////////////////////////////////////////////////////////
// HelideDevice definitions ///////////////////////////////////////////////////
Expand Down Expand Up @@ -85,9 +50,9 @@ ANARIArray1D HelideDevice::newArray1D(const void *appMemory,
md.numItems = numItems;

if (anari::isObject(type))
return createObjectForAPI<ObjectArray, ANARIArray1D>(deviceState(), md);
return (ANARIArray1D) new ObjectArray(deviceState(), md);
else
return createObjectForAPI<Array1D, ANARIArray1D>(deviceState(), md);
return (ANARIArray1D) new Array1D(deviceState(), md);
}

ANARIArray2D HelideDevice::newArray2D(const void *appMemory,
Expand All @@ -107,7 +72,7 @@ ANARIArray2D HelideDevice::newArray2D(const void *appMemory,
md.numItems1 = numItems1;
md.numItems2 = numItems2;

return createObjectForAPI<Array2D, ANARIArray2D>(deviceState(), md);
return (ANARIArray2D) new Array2D(deviceState(), md);
}

ANARIArray3D HelideDevice::newArray3D(const void *appMemory,
Expand All @@ -129,93 +94,86 @@ ANARIArray3D HelideDevice::newArray3D(const void *appMemory,
md.numItems2 = numItems2;
md.numItems3 = numItems3;

return createObjectForAPI<Array3D, ANARIArray3D>(deviceState(), md);
return (ANARIArray3D) new Array3D(deviceState(), md);
}

ANARICamera HelideDevice::newCamera(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARICamera>(
Camera::createInstance(subtype, deviceState()));
return (ANARICamera)Camera::createInstance(subtype, deviceState());
}

ANARIFrame HelideDevice::newFrame()
{
initDevice();
return createObjectForAPI<Frame, ANARIFrame>(deviceState());
return (ANARIFrame) new Frame(deviceState());
}

ANARIGeometry HelideDevice::newGeometry(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARIGeometry>(
Geometry::createInstance(subtype, deviceState()));
return (ANARIGeometry)Geometry::createInstance(subtype, deviceState());
}

ANARIGroup HelideDevice::newGroup()
{
initDevice();
return createObjectForAPI<Group, ANARIGroup>(deviceState());
return (ANARIGroup) new Group(deviceState());
}

ANARIInstance HelideDevice::newInstance(const char * /*subtype*/)
{
initDevice();
return createObjectForAPI<Instance, ANARIInstance>(deviceState());
return (ANARIInstance) new Instance(deviceState());
}

ANARILight HelideDevice::newLight(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARILight>(
Light::createInstance(subtype, deviceState()));
return (ANARILight)Light::createInstance(subtype, deviceState());
}

ANARIMaterial HelideDevice::newMaterial(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARIMaterial>(
Material::createInstance(subtype, deviceState()));
return (ANARIMaterial)Material::createInstance(subtype, deviceState());
}

ANARIRenderer HelideDevice::newRenderer(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARIRenderer>(
Renderer::createInstance(subtype, deviceState()));
return (ANARIRenderer)Renderer::createInstance(subtype, deviceState());
}

ANARISampler HelideDevice::newSampler(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARISampler>(
Sampler::createInstance(subtype, deviceState()));
return (ANARISampler)Sampler::createInstance(subtype, deviceState());
}

ANARISpatialField HelideDevice::newSpatialField(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARISpatialField>(
SpatialField::createInstance(subtype, deviceState()));
return (ANARISpatialField)SpatialField::createInstance(
subtype, deviceState());
}

ANARISurface HelideDevice::newSurface()
{
initDevice();
return createObjectForAPI<Surface, ANARISurface>(deviceState());
return (ANARISurface) new Surface(deviceState());
}

ANARIVolume HelideDevice::newVolume(const char *subtype)
{
initDevice();
return getHandleForAPI<ANARIVolume>(
Volume::createInstance(subtype, deviceState()));
return (ANARIVolume)Volume::createInstance(subtype, deviceState());
}

ANARIWorld HelideDevice::newWorld()
{
initDevice();
return createObjectForAPI<World, ANARIWorld>(deviceState());
return (ANARIWorld) new World(deviceState());
}

// Query functions ////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion libs/helide/HelideDeviceQueries.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Khronos Group
// Copyright 2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0

// This file was generated by generate_queries.py
Expand Down
2 changes: 1 addition & 1 deletion libs/helide/HelideDeviceQueries.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Khronos Group
// Copyright 2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0

// This file was generated by generate_queries.py
Expand Down
2 changes: 1 addition & 1 deletion libs/helide/HelideGlobalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

#include "RenderingSemaphore.h"
#include "helide_math.h"
#include "HelideMath.h"
// helium
#include "helium/BaseGlobalDeviceState.h"
// embree
Expand Down
4 changes: 2 additions & 2 deletions libs/helide/HelideLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ const char **HelideLibrary::getDeviceExtensions(const char * /*deviceType*/)

// Define library entrypoint //////////////////////////////////////////////////

extern "C" HELIDE_DEVICE_INTERFACE ANARI_DEFINE_LIBRARY_ENTRYPOINT(
extern "C" HELIDE_EXPORT ANARI_DEFINE_LIBRARY_ENTRYPOINT(
helide, handle, scb, scbPtr)
{
return (ANARILibrary) new helide::HelideLibrary(handle, scb, scbPtr);
}

extern "C" HELIDE_DEVICE_INTERFACE ANARIDevice anariNewHelideDevice(
extern "C" HELIDE_EXPORT ANARIDevice anariNewHelideDevice(
ANARIStatusCallback defaultCallback, const void *userPtr)
{
return (ANARIDevice) new helide::HelideDevice(defaultCallback, userPtr);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion libs/helide/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

#include "HelideGlobalState.h"
#include "helide_math.h"
#include "HelideMath.h"
// helium
#include "helium/BaseObject.h"
// std
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
extern "C" {
#endif

HELIDE_DEVICE_INTERFACE ANARIDevice anariNewHelideDevice(
HELIDE_EXPORT ANARIDevice anariNewHelideDevice(
ANARIStatusCallback defaultCallback ANARI_DEFAULT_VAL(0),
const void *userPtr ANARI_DEFAULT_VAL(0));

Expand Down

0 comments on commit e1be197

Please sign in to comment.