Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix channel names in debug tracer and add cylinder scene #89

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions examples/trace/trace_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions examples/viewer/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static const std::vector<std::string> g_scenes = {
"textured_cube",
"gravity_spheres_volume",
"attributes",
"random_cylinders",
"file_obj"
//
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions examples/viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -120,6 +125,8 @@ void printUsage()
<< " [{--library|-l} <ANARI library>]\n"
<< " [{--device|-d} <ANARI device>]\n"
<< " [{--renderer|-r} <ANARI renderer>]\n"
<< " [{--trace|-t} <directory>]\n"
<< " [{--scene|-s} <scene>]\n"
<< " [.obj intput file]"
<< std::endl;
}
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions libs/anari_test_scenes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libs/anari_test_scenes/anari_test_scenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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;
}
Expand Down
135 changes: 135 additions & 0 deletions libs/anari_test_scenes/scenes/random_cylinders.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright 2021 The Khronos Group
// SPDX-License-Identifier: Apache-2.0

#include "random_cylinders.h"
// std
#include <random>

namespace anari {
namespace scenes {

RandomCylinders::RandomCylinders(anari::Device d) : TestScene(d)
{
m_world = anari::newObject<anari::World>(m_device);
}

RandomCylinders::~RandomCylinders()
{
anari::release(m_device, m_world);
}

std::vector<ParameterInfo> 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<anari::Surface>(d);
auto geom = anari::newObject<anari::Geometry>(d, "cylinder");
auto mat = anari::newObject<anari::Material>(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<int>("numCylinders", 2e3);
float radius = getParam<float>("radius", 1.5e-2f);
bool randomizeRadii = getParam<bool>("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<float> vert_dist(0.5f, 0.5f);

std::vector<glm::vec3> cylinderPositions(2*(size_t(numCylinders)));
std::vector<glm::vec4> cylinderColors(2*(size_t(numCylinders)));

for (int i = 0;i<numCylinders;++i) {
auto &a = cylinderPositions[2*i];
a.x = vert_dist(rng);
a.y = vert_dist(rng);
a.z = vert_dist(rng);

auto &b = cylinderPositions[2*i+1];
b.x = a.x + 0.1*vert_dist(rng);
b.y = a.y + 0.1*vert_dist(rng);
b.z = a.z + 0.1*vert_dist(rng);
}

for (auto &s : cylinderColors) {
s.x = vert_dist(rng);
s.y = vert_dist(rng);
s.z = vert_dist(rng);
s.w = 1.f;
}

anari::setAndReleaseParameter(d,
geom,
"vertex.position",
anari::newArray1D(d, cylinderPositions.data(), cylinderPositions.size()));
anari::setParameter(d, geom, "radius", radius);
anari::setParameter(d, geom, "caps", "none");

anari::setAndReleaseParameter(d,
geom,
"vertex.color",
anari::newArray1D(d, cylinderColors.data(), cylinderColors.size()));

if (randomizeRadii) {
std::normal_distribution<float> radii_dist(radius / 10.f, radius);

std::vector<float> 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
29 changes: 29 additions & 0 deletions libs/anari_test_scenes/scenes/random_cylinders.h
Original file line number Diff line number Diff line change
@@ -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<ParameterInfo> parameters() override;

anari::World world() override;

void commit() override;

private:
anari::World m_world{nullptr};
};

} // namespace scenes
} // namespace anari
19 changes: 10 additions & 9 deletions libs/debug_device/CodeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebugObject<ANARI_FRAME>>(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";
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/debug_device/CodeSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libs/debug_device/DebugBasics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libs/debug_device/DebugBasics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions libs/debug_device/DebugDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libs/debug_device/DebugInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libs/debug_device/DebugSerializerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libs/debug_device/EmptySerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Expand Down