diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2025-08-15 08:24:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-15 15:24:06 +0000 |
| commit | f75bf474ef87737c87ef6dcb431bd0b87faee0a8 (patch) | |
| tree | 14ed00217409b67316311ddbf09e072ee6ecdc83 /tests/cuda | |
| parent | feb1569d972f294ce482ea8b1645da6cde4e982d (diff) | |
[CUDA] Fix incorrect `kIROp_RaytracingAccelerationStructureType` emitting logic (#8168)
Fixes: #8167
Current emitting logic does not work, this has been corrected.
The provided test ensures our CUDA code is valid by compiling PTX from
it.
`m_writer->emit("OptixTraversableHandle");` should be `out <<` since
`out` adds to type-name-cache; otherwise using a type twice will produce
bad type-names (since we filled type-name cache with "" instead of
"typeName")
Diffstat (limited to 'tests/cuda')
| -rw-r--r-- | tests/cuda/raygeneration.slang | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/cuda/raygeneration.slang b/tests/cuda/raygeneration.slang new file mode 100644 index 000000000..5e3e0c38b --- /dev/null +++ b/tests/cuda/raygeneration.slang @@ -0,0 +1,91 @@ +//TEST:SIMPLE(filecheck=CHECK): -target cuda +//TEST:SIMPLE(filecheck=CHECK-PTX): -target ptx + +// Test that we emit a valid raygeneration kernel. +// This test will fail if either: (1) `OptixTraversableHandle` is not emitted +// as a local var for `RaytracingAccelerationStructure` or (2)`RaytracingAccelerationStructure` +// is not hoisted into use-site. + +// CHECK: void{{.*}}raygenMain +// CHECK-PTX: .visible .entry{{.*}}raygenMain + +struct Ray { + float3 origin; + float t_min; + float3 dir; + float t_max; + + __init(float3 origin, float3 dir, float t_min = 0.f, float t_max = 1000.0) + { + this.origin = origin; + this.dir = dir; + this.t_min = t_min; + this.t_max = t_max; + } + + RayDesc to_ray_desc() { return { origin, t_min, dir, t_max }; } +}; + + +struct Camera { + float3 position; + float3 image_u; + float3 image_v; + float3 image_w; + + Ray get_ray(float2 uv) + { + uv = uv * 2 - 1; + float3 dir = normalize(uv.x * image_u + uv.y * image_v + image_w); + return Ray(position, dir); + } +}; + +struct Scene { + RaytracingAccelerationStructure tlas; + + Camera camera; +}; + +struct Path { + uint2 pixel; + uint vertex_index; + Ray ray; + float3 thp; + float3 L; + int rng; + + __init(uint2 pixel, Ray ray, int rng) + { + this.pixel = pixel; + this.vertex_index = 0; + this.ray = ray; + this.thp = float3(1); + this.L = float3(0); + this.rng = rng; + } +}; +ParameterBlock<Scene> g_scene; +RWTexture2D<float4> g_output; + +[require(sm_6_8, cuda)] +[shader("raygeneration")] +void raygenMain() +{ + uint2 pixel = DispatchRaysIndex().xy; + float3 L = float3(0); + Ray ray = g_scene.camera.get_ray(pixel.xy); + Path path = Path(pixel, ray, 1); + TraceRay( + g_scene.tlas, + 0, + 0xff, + 0, + 0, + 0, + path.ray.to_ray_desc(), + path + ); + L += path.L; + g_output[pixel] = float4(L, 1); +} |
