Skip to content
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
10 changes: 10 additions & 0 deletions devices/rtx/apps/tests/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ if (VISRTX_ENABLE_MDL_SUPPORT)
add_test(NAME TestMdlModuleReuseSerial COMMAND TestMdlModuleReuse)
set_tests_properties(TestMdlModuleReuseSerial PROPERTIES
ENVIRONMENT "VISRTX_MDL_COMPILE_THREADS=1" TIMEOUT 120)
make_test(TestMdlSearchPaths)
set_tests_properties(TestMdlSearchPaths PROPERTIES TIMEOUT 300)
make_test(TestMdlIneurayHandoff)
make_test(TestMdlIneurayIntrospect)
set_tests_properties(TestMdlIneurayHandoff TestMdlIneurayIntrospect
PROPERTIES TIMEOUT 120)
make_test(TestMdlLogging)
set_tests_properties(TestMdlLogging PROPERTIES TIMEOUT 120)
make_test(TestMdlMultiDevice)
set_tests_properties(TestMdlMultiDevice PROPERTIES TIMEOUT 300)
make_test(TestMdlMaterialRegistryRelease)
make_test(TestMdlConcurrentCompile)
make_test(TestMdlCompileBenchmark)
Expand Down
122 changes: 122 additions & 0 deletions devices/rtx/apps/tests/api/TestMdlIneurayHandoff.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES.
// SPDX-License-Identifier: BSD-3-Clause

// Application-mediated INeuray handoff: the app reads the SDK instance from
// one device's `ineuray` property and passes it to another device's `ineuray`
// parameter. This is the supported path for sharing MDL across devices from
// different vendors, which cannot see each other's internals.

#define ANARI_EXTENSION_UTILITY_IMPL
#include <anari/anari_cpp/ext/std.h>
#include <anari/ext/visrtx/makeVisRTXDevice.h>
#include <anari/anari_cpp.hpp>
#include <array>
#include <cstdio>
#include <string>
using Vec3 = std::array<float, 3>;
using Vec4 = std::array<float, 4>;
static int errs = 0;
static void st(const void *,
ANARIDevice,
ANARIObject,
ANARIDataType,
ANARIStatusSeverity s,
ANARIStatusCode,
const char *m)
{
if (s == ANARI_SEVERITY_ERROR || s == ANARI_SEVERITY_FATAL_ERROR) {
++errs;
std::fprintf(stderr, "ERR: %s\n", m);
}
}
static std::string src()
{
return "mdl 1.6; import ::df::*; export material emitter()=material(surface: material_surface("
"emission: material_emission(emission: df::diffuse_edf(), intensity: color(4.0))));";
}
static anari::Frame scene(anari::Device d)
{
const std::array<Vec3, 4> v = {
Vec3{-1, -1, 0}, Vec3{1, -1, 0}, Vec3{1, 1, 0}, Vec3{-1, 1, 0}};
const std::array<std::array<unsigned, 3>, 2> i = {
std::array<unsigned, 3>{0, 1, 2}, std::array<unsigned, 3>{0, 2, 3}};
auto g = anari::newObject<anari::Geometry>(d, "triangle");
anari::setParameterArray1D(d, g, "vertex.position", v.data(), v.size());
anari::setParameterArray1D(d, g, "primitive.index", i.data(), i.size());
anari::commitParameters(d, g);
auto m = anari::newObject<anari::Material>(d, "mdl");
anari::setParameter(d, m, "sourceType", "code");
anari::setParameter(d, m, "source", src());
anari::setParameter(d, m, "materialName", "emitter");
anari::commitParameters(d, m);
auto s = anari::newObject<anari::Surface>(d);
anari::setAndReleaseParameter(d, s, "geometry", g);
anari::setAndReleaseParameter(d, s, "material", m);
anari::commitParameters(d, s);
auto w = anari::newObject<anari::World>(d);
anari::setParameterArray1D(d, w, "surface", &s, 1);
anari::commitParameters(d, w);
anari::release(d, s);
auto c = anari::newObject<anari::Camera>(d, "orthographic");
anari::setParameter(d, c, "position", Vec3{0, 0, 3});
anari::setParameter(d, c, "direction", Vec3{0, 0, -1});
anari::setParameter(d, c, "up", Vec3{0, 1, 0});
anari::setParameter(d, c, "height", 2.f);
anari::setParameter(d, c, "aspect", 1.f);
anari::commitParameters(d, c);
auto r = anari::newObject<anari::Renderer>(d, "quality");
anari::setParameter(d, r, "pixelSamples", 1);
anari::setParameter(d, r, "background", Vec4{0, 0, 0, 1});
anari::setParameter(d, r, "ambientRadiance", 0.f);
anari::commitParameters(d, r);
auto f = anari::newObject<anari::Frame>(d);
anari::setParameter(d, f, "size", std::array<unsigned, 2>{32, 32});
anari::setParameter(d, f, "channel.color", ANARI_FLOAT32_VEC4);
anari::setAndReleaseParameter(d, f, "camera", c);
anari::setAndReleaseParameter(d, f, "renderer", r);
anari::setAndReleaseParameter(d, f, "world", w);
anari::commitParameters(d, f);
return f;
}
int main()
{
auto A = makeVisRTXDevice(st);
anari::setParameter(A, A, "forceInit", true);
anari::commitParameters(A, A);
// Can the app READ the instance back out of device A?
void *p = nullptr;
int ok = anariGetProperty(
A, A, "ineuray", ANARI_VOID_POINTER, &p, sizeof(p), ANARI_WAIT);
std::printf("getProperty(\"ineuray\") -> returned=%d ptr=%p\n", ok, p);
if (!ok || !p) {
std::fprintf(
stderr, "FAIL: `ineuray` property unreadable; handoff impossible\n");
return 1;
}
{
auto B = makeVisRTXDevice(st);
anari::setParameter(B, B, "ineuray", p);
anari::setParameter(B, B, "forceInit", true);
anari::commitParameters(B, B);
auto f = scene(B);
anari::render(B, f);
anari::wait(B, f);
auto px = anari::map<Vec4>(B, f, "channel.color");
const float r = px.data[16 * 32 + 16][0];
std::printf("handoff render pixel r=%.3f errors=%d\n", r, errs);
if (r <= 0.1f) {
std::fprintf(stderr, "FAIL: adopted instance did not render MDL\n");
return 1;
}
anari::unmap(B, f, "channel.color");
anari::release(B, f);
anari::release(B, B);
}
anari::release(A, A);
if (errs) {
std::fprintf(stderr, "FAIL: %d error(s) during handoff\n", errs);
return 1;
}
std::puts("INeuray handoff between devices succeeded");
return 0;
}
75 changes: 75 additions & 0 deletions devices/rtx/apps/tests/api/TestMdlIneurayIntrospect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES.
// SPDX-License-Identifier: BSD-3-Clause

// The INeuray handoff is only usable if an application can discover it, so the
// `ineuray` device parameter and property must be part of the published
// VISRTX_MATERIAL_MDL extension description, not merely accepted by the code.

#include <anari/ext/visrtx/makeVisRTXDevice.h>
#include <anari/anari_cpp.hpp>

#include <cstdio>
#include <cstring>

namespace {

bool hasParameter(ANARIDevice d, const char *name, ANARIDataType type)
{
auto *params = (const ANARIParameter *)anariGetObjectInfo(
d, ANARI_DEVICE, "device", "parameter", ANARI_PARAMETER_LIST);
for (auto *p = params; p && p->name; ++p)
if (!std::strcmp(p->name, name) && p->type == type)
return true;
return false;
}

// ANARI's query generator has no "property" info name (its vocabulary is
// required/default/minimum/maximum/description/elementType/value/
// sourceExtension/extension/parameter/channel/use), so object properties --
// including the core spec's own geometryMaxIndex -- are not introspectable.
// The property is therefore verified by reading it, not by listing it.
bool propertyReadable(ANARIDevice d, const char *name)
{
void *value = nullptr;
return anariGetProperty(
d, d, name, ANARI_VOID_POINTER, &value, sizeof(value), ANARI_WAIT)
&& value != nullptr;
}

bool check(bool ok, const char *what)
{
std::printf("%-56s %s\n", what, ok ? "ok" : "MISSING");
return ok;
}

} // namespace

int main()
{
auto device = makeVisRTXDevice();
bool ok = true;
ok &= check(hasParameter(device, "ineuray", ANARI_VOID_POINTER),
"device parameter `ineuray` (ANARI_VOID_POINTER)");
// Readable only once MDL is initialized.
anari::setParameter(device, device, "forceInit", true);
anari::commitParameters(device, device);
ok &= check(propertyReadable(device, "ineuray"),
"device property `ineuray` readable (ANARI_VOID_POINTER)");
ok &= check(hasParameter(device, "mdlSearchPaths", ANARI_STRING),
"device parameter `mdlSearchPaths` (ANARI_STRING)");
ok &= check(hasParameter(device, "mdlResourceSearchPaths", ANARI_STRING),
"device parameter `mdlResourceSearchPaths` (ANARI_STRING)");
// The core device parameters must survive the merge.
ok &= check(hasParameter(device, "statusCallback", ANARI_STATUS_CALLBACK),
"core parameter `statusCallback` still advertised");
anari::release(device, device);

if (!ok) {
std::fprintf(stderr,
"FAIL: the MDL instance-sharing contract is not discoverable through "
"ANARI introspection\n");
return 1;
}
std::puts("MDL device parameters and properties are advertised");
return 0;
}
Loading
Loading