diff --git a/examples/trace/trace_wrapper.c b/examples/trace/trace_wrapper.c index 0e29b109..b430071b 100644 --- a/examples/trace/trace_wrapper.c +++ b/examples/trace/trace_wrapper.c @@ -57,6 +57,7 @@ void* data(uint64_t offset, uint64_t size) { } void image(const char *channel, const void *pixels, int width, int height, ANARIDataType type) { + printf("%d %d\n", width, height); static int count = 0; count += 1; char filename[100]; @@ -78,13 +79,16 @@ void trace(ANARIDevice device) { int main(int argc, char *argv[]) { + const char *lib = argc>1 ? argv[1] : "helide"; + const char *dev = argc>2 ? argv[2] : "default"; + if(load_whole_file("data.bin")) { fprintf(stderr, "ERROR: could not open data file.\n"); return 1; } - ANARILibrary library = anariLoadLibrary("example", statusFunc, NULL); - ANARIDevice device = anariNewDevice(library, "default"); + ANARILibrary library = anariLoadLibrary(lib, statusFunc, NULL); + ANARIDevice device = anariNewDevice(library, dev); if (!device) { fprintf(stderr, "ERROR: could not create device\n"); diff --git a/examples/viewer/MainWindow.cpp b/examples/viewer/MainWindow.cpp index ea45ac82..9486db89 100644 --- a/examples/viewer/MainWindow.cpp +++ b/examples/viewer/MainWindow.cpp @@ -29,6 +29,7 @@ static const std::vector g_scenes = { "textured_cube", "gravity_spheres_volume", "attributes", + "random_cylinders", "file_obj" // }; @@ -226,7 +227,7 @@ MainWindow::MainWindow(const glm::uvec2 &windowSize) ImGui_ImplOpenGL3_Init(); ImGuiIO &io = ImGui::GetIO(); - io.FontGlobalScale = 1.25f; + io.FontGlobalScale = 1.0f; // set GLFW callbacks glfwSetFramebufferSizeCallback(g_window, @@ -484,7 +485,7 @@ void MainWindow::buildUI() ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav - | ImGuiWindowFlags_NoMove; + | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground; ImGui::SetNextWindowPos(ImVec2(10, 10), ImGuiCond_Always); diff --git a/examples/viewer/main.cpp b/examples/viewer/main.cpp index 7e457e7e..6f3b4581 100644 --- a/examples/viewer/main.cpp +++ b/examples/viewer/main.cpp @@ -23,6 +23,7 @@ ANARILibrary g_debug = nullptr; bool g_enableDebug = false; bool g_verbose = false; const bool g_true = true; +const char *g_traceDir = nullptr; /******************************************************************/ static std::string pathOf(const std::string &filename) @@ -97,6 +98,10 @@ static void initializeANARI(MainWindow *window) if (g_enableDebug) { ANARIDevice dbg = anariNewDevice(g_debug, "debug"); anari::setParameter(dbg, dbg, "wrappedDevice", ANARI_DEVICE, &dev); + if(g_traceDir) { + anari::setParameter(dbg, dbg, "traceDir", ANARI_STRING, g_traceDir); + anari::setParameter(dbg, dbg, "traceMode", ANARI_STRING, "code"); + } anari::commitParameters(dbg, dbg); anari::release(dev, dev); dev = dbg; @@ -120,6 +125,8 @@ void printUsage() << " [{--library|-l} ]\n" << " [{--device|-d} ]\n" << " [{--renderer|-r} ]\n" + << " [{--trace|-t} ]\n" + << " [{--scene|-s} ]\n" << " [.obj intput file]" << std::endl; } @@ -144,6 +151,8 @@ void parseCommandLine(int argc, const char *argv[]) g_verbose = true; } else if (arg == "--scene" || arg == "-s") { g_startupScene = argv[++i]; + } else if (arg == "--trace" || arg == "-t") { + g_traceDir = argv[++i]; } else { g_objFile = arg; } diff --git a/libs/anari_test_scenes/CMakeLists.txt b/libs/anari_test_scenes/CMakeLists.txt index 1101f651..833d8be9 100644 --- a/libs/anari_test_scenes/CMakeLists.txt +++ b/libs/anari_test_scenes/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(${PROJECT_NAME} STATIC scenes/gravity_spheres_volume.cpp scenes/instanced_cubes.cpp scenes/random_spheres.cpp + scenes/random_cylinders.cpp scenes/scene.cpp scenes/textured_cube.cpp scenes/attributes.cpp diff --git a/libs/anari_test_scenes/anari_test_scenes.cpp b/libs/anari_test_scenes/anari_test_scenes.cpp index dd7ad345..52cf0ecc 100644 --- a/libs/anari_test_scenes/anari_test_scenes.cpp +++ b/libs/anari_test_scenes/anari_test_scenes.cpp @@ -12,6 +12,7 @@ #include "scenes/gravity_spheres_volume.h" #include "scenes/instanced_cubes.h" #include "scenes/random_spheres.h" +#include "scenes/random_cylinders.h" #include "scenes/textured_cube.h" #include "scenes/attributes.h" @@ -35,6 +36,7 @@ static void init() scenes["instanced_cubes"] = &sceneInstancedCubes; scenes["textured_cube"] = &sceneTexturedCube; scenes["random_spheres"] = &sceneRandomSpheres; + scenes["random_cylinders"] = &sceneRandomCylinders; scenes["attributes"] = &sceneAttributes; scenes["file_obj"] = &sceneFileObj; } diff --git a/libs/anari_test_scenes/scenes/random_cylinders.cpp b/libs/anari_test_scenes/scenes/random_cylinders.cpp new file mode 100644 index 00000000..0b3c441d --- /dev/null +++ b/libs/anari_test_scenes/scenes/random_cylinders.cpp @@ -0,0 +1,135 @@ +// Copyright 2021 The Khronos Group +// SPDX-License-Identifier: Apache-2.0 + +#include "random_cylinders.h" +// std +#include + +namespace anari { +namespace scenes { + +RandomCylinders::RandomCylinders(anari::Device d) : TestScene(d) +{ + m_world = anari::newObject(m_device); +} + +RandomCylinders::~RandomCylinders() +{ + anari::release(m_device, m_world); +} + +std::vector RandomCylinders::parameters() +{ + return { + {"numCylinders", ANARI_INT32, int(1e3), "Number of cylinders to generate."}, + {"radius", ANARI_FLOAT32, 1.5e-2f, "Radius of all cylinders."} + // + }; +} + +anari::World RandomCylinders::world() +{ + return m_world; +} + +void RandomCylinders::commit() +{ + auto d = m_device; + + // Build this scene top-down to stress commit ordering guarantees + + setDefaultLight(m_world); + + auto surface = anari::newObject(d); + auto geom = anari::newObject(d, "cylinder"); + auto mat = anari::newObject(d, "matte"); + anari::setParameter(d, mat, "color", "color"); + anari::commitParameters(d, mat); + + anari::setAndReleaseParameter( + d, m_world, "surface", anari::newArray1D(d, &surface)); + + anari::commitParameters(d, m_world); + + anari::setParameter(d, surface, "geometry", geom); + anari::setParameter(d, surface, "material", mat); + + int numCylinders = getParam("numCylinders", 2e3); + float radius = getParam("radius", 1.5e-2f); + bool randomizeRadii = getParam("randomizeRadii", true); + + if (numCylinders < 1) + throw std::runtime_error("'numCylinders' must be >= 1"); + + if (radius <= 0.f) + throw std::runtime_error("'radius' must be > 0.f"); + + std::mt19937 rng; + rng.seed(0); + std::normal_distribution vert_dist(0.5f, 0.5f); + + std::vector cylinderPositions(2*(size_t(numCylinders))); + std::vector cylinderColors(2*(size_t(numCylinders))); + + for (int i = 0;i radii_dist(radius / 10.f, radius); + + std::vector cylinderRadii((size_t(numCylinders))); + for (auto &r : cylinderRadii) + r = radii_dist(rng); + + anari::setAndReleaseParameter(d, + geom, + "primitive.radius", + anari::newArray1D(d, cylinderRadii.data(), cylinderRadii.size())); + } + + anari::commitParameters(d, geom); + anari::commitParameters(d, mat); + anari::commitParameters(d, surface); + + // cleanup + + anari::release(d, surface); + anari::release(d, geom); + anari::release(d, mat); +} + +TestScene *sceneRandomCylinders(anari::Device d) +{ + return new RandomCylinders(d); +} + +} // namespace scenes +} // namespace anari \ No newline at end of file diff --git a/libs/anari_test_scenes/scenes/random_cylinders.h b/libs/anari_test_scenes/scenes/random_cylinders.h new file mode 100644 index 00000000..d3ac85b8 --- /dev/null +++ b/libs/anari_test_scenes/scenes/random_cylinders.h @@ -0,0 +1,29 @@ +// Copyright 2021 The Khronos Group +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "scene.h" + +namespace anari { +namespace scenes { + +TestScene *sceneRandomCylinders(anari::Device d); + +struct RandomCylinders : public TestScene +{ + RandomCylinders(anari::Device d); + ~RandomCylinders(); + + std::vector parameters() override; + + anari::World world() override; + + void commit() override; + + private: + anari::World m_world{nullptr}; +}; + +} // namespace scenes +} // namespace anari diff --git a/libs/debug_device/CodeSerializer.cpp b/libs/debug_device/CodeSerializer.cpp index d892f349..9f30f54e 100644 --- a/libs/debug_device/CodeSerializer.cpp +++ b/libs/debug_device/CodeSerializer.cpp @@ -486,26 +486,27 @@ void CodeSerializer::anariNewFrame(ANARIDevice device, ANARIFrame result) { out << " = anariNewFrame(device);\n"; } -void CodeSerializer::anariMapFrame(ANARIDevice device, ANARIFrame object, const char* channel, const void *mapped) { +void CodeSerializer::anariMapFrame(ANARIDevice device, ANARIFrame object, const char* channel, uint32_t *width, uint32_t *height, ANARIDataType *pixelType, const void *mapped) { uint64_t local = locals++; + sanitized_name schannel{channel}; out << "uint32_t width_local" << local << ";\n"; out << "uint32_t height_local" << local << ";\n"; out << "ANARIDataType type_local" << local << ";\n"; - out << "const void *mapped_" << channel << local << " = anariMapFrame(device, "; + out << "const void *mapped_" << schannel << local << " = anariMapFrame(device, "; printObjectName(object); out << ", \"" << channel << "\", &width_local" << local; out << ", &height_local" << local; out << ", &type_local" << local; out << ");\n"; + out + << "// returned width = " << (width ? std::to_string(*width) : "(null)") + << " height = " << (height ? std::to_string(*height) : "(null)") + << " format = " << (pixelType ? anari::toString(*pixelType) : "(null)") + << "\n"; + if(auto info = dd->getDynamicObjectInfo>(object)) { - ANARIDataType mappingType = ANARI_UNKNOWN; - if(std::strncmp(channel, "color", 5)==0) { - mappingType = info->colorType; - } else if(std::strncmp(channel, "depth", 5)==0) { - mappingType = info->depthType; - } - out << "image(\"" << channel << "\", mapped_" << channel << local << ", "; + out << "image(\"" << channel << "\", mapped_" << schannel << local << ", "; out << "width_local" << local << ", " << "height_local" << local << ", " << "type_local" << local << ");\n"; } } diff --git a/libs/debug_device/CodeSerializer.h b/libs/debug_device/CodeSerializer.h index df345a50..908beddc 100644 --- a/libs/debug_device/CodeSerializer.h +++ b/libs/debug_device/CodeSerializer.h @@ -42,7 +42,7 @@ class CodeSerializer : public SerializerInterface { void anariRetain(ANARIDevice device, ANARIObject object) override; void anariGetProperty(ANARIDevice device, ANARIObject object, const char* name, ANARIDataType type, void* mem, uint64_t size, ANARIWaitMask mask, int result) override; void anariNewFrame(ANARIDevice device, ANARIFrame result) override; - void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, const void *mapped) override; + void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, uint32_t *width, uint32_t *height, ANARIDataType *pixelType, const void *mapped) override; void anariUnmapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) override; void anariNewRenderer(ANARIDevice device, const char* type, ANARIRenderer result) override; void anariRenderFrame(ANARIDevice device, ANARIFrame frame) override; diff --git a/libs/debug_device/DebugBasics.cpp b/libs/debug_device/DebugBasics.cpp index c6a9bf03..cbc6cdd2 100644 --- a/libs/debug_device/DebugBasics.cpp +++ b/libs/debug_device/DebugBasics.cpp @@ -275,7 +275,7 @@ void DebugBasics::anariGetProperty(ANARIDevice device, ANARIObject object, const void DebugBasics::anariNewFrame(ANARIDevice device) { (void)device; } -void DebugBasics::anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) { +void DebugBasics::anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, uint32_t *width, uint32_t *height, ANARIDataType *pixelType) { DEBUG_FUNCTION_SOURCE(anariMapFrame, frame) (void)device; (void)channel; diff --git a/libs/debug_device/DebugBasics.h b/libs/debug_device/DebugBasics.h index ef6754b9..fee78504 100644 --- a/libs/debug_device/DebugBasics.h +++ b/libs/debug_device/DebugBasics.h @@ -40,7 +40,7 @@ class DebugBasics : public DebugInterface { void anariRetain(ANARIDevice device, ANARIObject object) override; void anariGetProperty(ANARIDevice device, ANARIObject object, const char* name, ANARIDataType type, void* mem, uint64_t size, ANARIWaitMask mask) override; void anariNewFrame(ANARIDevice device) override; - void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) override; + void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, uint32_t *width, uint32_t *height, ANARIDataType *pixelType) override; void anariUnmapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) override; void anariNewRenderer(ANARIDevice device, const char* type) override; void anariRenderFrame(ANARIDevice device, ANARIFrame frame) override; diff --git a/libs/debug_device/DebugDevice.cpp b/libs/debug_device/DebugDevice.cpp index 639d5f6e..bf108378 100644 --- a/libs/debug_device/DebugDevice.cpp +++ b/libs/debug_device/DebugDevice.cpp @@ -701,12 +701,12 @@ const void *DebugDevice::frameBufferMap(ANARIFrame fb, uint32_t *height, ANARIDataType *pixelType) { - debug->anariMapFrame(this_device(), fb, channel); + debug->anariMapFrame(this_device(), fb, channel, width, height, pixelType); const void *mapped = anariMapFrame( wrapped, unwrapHandle(fb), channel, width, height, pixelType); if (serializer) { - serializer->anariMapFrame(this_device(), fb, channel, mapped); + serializer->anariMapFrame(this_device(), fb, channel, width, height, pixelType, mapped); } return mapped; diff --git a/libs/debug_device/DebugInterface.h b/libs/debug_device/DebugInterface.h index d97ac715..016256f0 100644 --- a/libs/debug_device/DebugInterface.h +++ b/libs/debug_device/DebugInterface.h @@ -35,7 +35,7 @@ class DebugInterface { virtual void anariRetain(ANARIDevice device, ANARIObject object) = 0; virtual void anariGetProperty(ANARIDevice device, ANARIObject object, const char* name, ANARIDataType type, void* mem, uint64_t size, ANARIWaitMask mask) = 0; virtual void anariNewFrame(ANARIDevice device) = 0; - virtual void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) = 0; + virtual void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, uint32_t *width, uint32_t *height, ANARIDataType *pixelType) = 0; virtual void anariUnmapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) = 0; virtual void anariNewRenderer(ANARIDevice device, const char* type) = 0; virtual void anariRenderFrame(ANARIDevice device, ANARIFrame frame) = 0; diff --git a/libs/debug_device/DebugSerializerInterface.h b/libs/debug_device/DebugSerializerInterface.h index 042d6a91..f087e850 100644 --- a/libs/debug_device/DebugSerializerInterface.h +++ b/libs/debug_device/DebugSerializerInterface.h @@ -35,7 +35,7 @@ class SerializerInterface { virtual void anariRetain(ANARIDevice device, ANARIObject object) = 0; virtual void anariGetProperty(ANARIDevice device, ANARIObject object, const char* name, ANARIDataType type, void* mem, uint64_t size, ANARIWaitMask mask, int result) = 0; virtual void anariNewFrame(ANARIDevice device, ANARIFrame result) = 0; - virtual void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, const void *mapped) = 0; + virtual void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, uint32_t *width, uint32_t *height, ANARIDataType *pixelType, const void *mapped) = 0; virtual void anariUnmapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) = 0; virtual void anariNewRenderer(ANARIDevice device, const char* type, ANARIRenderer result) = 0; virtual void anariRenderFrame(ANARIDevice device, ANARIFrame frame) = 0; diff --git a/libs/debug_device/EmptySerializer.h b/libs/debug_device/EmptySerializer.h index 1026a262..dd7c72e9 100644 --- a/libs/debug_device/EmptySerializer.h +++ b/libs/debug_device/EmptySerializer.h @@ -37,7 +37,7 @@ class EmptySerializer : public SerializerInterface { void anariRetain(ANARIDevice device, ANARIObject object) override { } void anariGetProperty(ANARIDevice device, ANARIObject object, const char* name, ANARIDataType type, void* mem, uint64_t size, ANARIWaitMask mask, int result) override { } void anariNewFrame(ANARIDevice device, ANARIFrame result) override { } - void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, const void *mapped) override { } + void anariMapFrame(ANARIDevice device, ANARIFrame frame, const char* channel, uint32_t *width, uint32_t *height, ANARIDataType *pixelType, const void *mapped) override { } void anariUnmapFrame(ANARIDevice device, ANARIFrame frame, const char* channel) override { } void anariNewRenderer(ANARIDevice device, const char* type, ANARIRenderer result) override { } void anariRenderFrame(ANARIDevice device, ANARIFrame frame) override { }