Skip to content

Commit d864e01

Browse files
MarijnS95claude
andcommitted
Cover basic RayQuery methods on the single-triangle BLAS
Adds five small InlineRT tests on top of the existing single-triangle BLAS, each isolating one RayQuery method: - miss-status: COMMITTED_NOTHING path (ray points away from geometry) - ray-t: CommittedRayT() returns exact 1.0 for the axis-aligned hit - barycentrics: CommittedTriangleBarycentrics() at world (0,0,0) returns exactly (0.25, 0.25) - world-ray-echo: WorldRayOrigin / WorldRayDirection / RayTMin / RayFlags round-trip into a structured buffer. Passes `-fvk-use-dx-layout` so the SPIR-V backend uses DXIL's tight float3 packing and the expected bytes match across DX/VK/MTL. - tmin-tmax-clip: two queries against the same BLAS — one with TMin past the hit, one with TMax before the hit — both must miss. Part of the inline-RT test coverage epic (#1258). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c8cbb51 commit d864e01

5 files changed

Lines changed: 422 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#--- source.hlsl
2+
3+
[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0);
4+
[[vk::binding(1, 0)]] RWStructuredBuffer<uint2> Output : register(u0);
5+
6+
[numthreads(1,1,1)]
7+
void main() {
8+
// Triangle vertices V0=(0,1,0), V1=(-1,-1,0), V2=(1,-1,0). Aim the ray at
9+
// world (0,0,0); the barycentric weights (1-u-v, u, v) that reconstruct
10+
// that point are (0.5, 0.25, 0.25), so CommittedTriangleBarycentrics()
11+
// must return exactly (0.25, 0.25).
12+
RayDesc Ray;
13+
Ray.Origin = float3(0, 0, 1);
14+
Ray.Direction = float3(0, 0, -1);
15+
Ray.TMin = 0.0;
16+
Ray.TMax = 100.0;
17+
RayQuery<RAY_FLAG_NONE> Q;
18+
Q.TraceRayInline(Scene, RAY_FLAG_NONE, 0xFF, Ray);
19+
Q.Proceed();
20+
Output[0] = asuint(Q.CommittedTriangleBarycentrics());
21+
}
22+
//--- pipeline.yaml
23+
---
24+
Shaders:
25+
- Stage: Compute
26+
Entry: main
27+
Buffers:
28+
- Name: Vertices
29+
Format: Float32
30+
Stride: 12
31+
Data: [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ]
32+
- Name: Output
33+
Format: UInt32
34+
Stride: 8
35+
FillSize: 8
36+
- Name: Expected
37+
Format: UInt32
38+
Stride: 8
39+
Data: [ 0x3e800000, 0x3e800000 ] # asuint((0.25, 0.25))
40+
AccelerationStructures:
41+
BLAS:
42+
- Name: TriangleBLAS
43+
Triangles:
44+
- VertexBuffer: Vertices
45+
VertexFormat: RGB32Float
46+
VertexStride: 12
47+
VertexCount: 3
48+
TLAS:
49+
- Name: Scene
50+
Instances:
51+
- BLAS: TriangleBLAS
52+
DescriptorSets:
53+
- Resources:
54+
- Name: Scene
55+
Kind: AccelerationStructure
56+
DirectXBinding:
57+
Register: 0
58+
Space: 0
59+
VulkanBinding:
60+
Binding: 0
61+
- Name: Output
62+
Kind: RWStructuredBuffer
63+
DirectXBinding:
64+
Register: 0
65+
Space: 0
66+
VulkanBinding:
67+
Binding: 1
68+
Results:
69+
- Result: CommittedTriangleBarycentrics
70+
Rule: BufferExact
71+
Actual: Output
72+
Expected: Expected
73+
...
74+
#--- end
75+
76+
# REQUIRES: acceleration-structure
77+
# XFAIL: Clang
78+
79+
# RUN: split-file %s %t
80+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
81+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#--- source.hlsl
2+
3+
[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0);
4+
[[vk::binding(1, 0)]] RWStructuredBuffer<uint> Output : register(u0);
5+
6+
[numthreads(1,1,1)]
7+
void main() {
8+
// Ray points away from the triangle (which sits at z=0); must not hit.
9+
RayDesc Ray;
10+
Ray.Origin = float3(0, 0, 1);
11+
Ray.Direction = float3(0, 0, 1);
12+
Ray.TMin = 0.0;
13+
Ray.TMax = 100.0;
14+
RayQuery<RAY_FLAG_NONE> Q;
15+
Q.TraceRayInline(Scene, RAY_FLAG_NONE, 0xFF, Ray);
16+
Q.Proceed();
17+
Output[0] = (uint)Q.CommittedStatus();
18+
}
19+
//--- pipeline.yaml
20+
---
21+
Shaders:
22+
- Stage: Compute
23+
Entry: main
24+
Buffers:
25+
- Name: Vertices
26+
Format: Float32
27+
Stride: 12
28+
Data: [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ]
29+
- Name: Output
30+
Format: UInt32
31+
Stride: 4
32+
FillSize: 4
33+
- Name: Expected
34+
Format: UInt32
35+
Stride: 4
36+
Data: [ 0 ] # COMMITTED_NOTHING
37+
AccelerationStructures:
38+
BLAS:
39+
- Name: TriangleBLAS
40+
Triangles:
41+
- VertexBuffer: Vertices
42+
VertexFormat: RGB32Float
43+
VertexStride: 12
44+
VertexCount: 3
45+
TLAS:
46+
- Name: Scene
47+
Instances:
48+
- BLAS: TriangleBLAS
49+
DescriptorSets:
50+
- Resources:
51+
- Name: Scene
52+
Kind: AccelerationStructure
53+
DirectXBinding:
54+
Register: 0
55+
Space: 0
56+
VulkanBinding:
57+
Binding: 0
58+
- Name: Output
59+
Kind: RWStructuredBuffer
60+
DirectXBinding:
61+
Register: 0
62+
Space: 0
63+
VulkanBinding:
64+
Binding: 1
65+
Results:
66+
- Result: MissStatus
67+
Rule: BufferExact
68+
Actual: Output
69+
Expected: Expected
70+
...
71+
#--- end
72+
73+
# REQUIRES: acceleration-structure
74+
# XFAIL: Clang
75+
76+
# RUN: split-file %s %t
77+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
78+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/InlineRT/ray-t.test

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#--- source.hlsl
2+
3+
[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0);
4+
[[vk::binding(1, 0)]] RWStructuredBuffer<uint> Output : register(u0);
5+
6+
[numthreads(1,1,1)]
7+
void main() {
8+
// Triangle sits at z=0 and the ray starts at z=1 heading along -z, so
9+
// CommittedRayT() must equal 1.0 exactly.
10+
RayDesc Ray;
11+
Ray.Origin = float3(0, 0, 1);
12+
Ray.Direction = float3(0, 0, -1);
13+
Ray.TMin = 0.0;
14+
Ray.TMax = 100.0;
15+
RayQuery<RAY_FLAG_NONE> Q;
16+
Q.TraceRayInline(Scene, RAY_FLAG_NONE, 0xFF, Ray);
17+
Q.Proceed();
18+
Output[0] = asuint(Q.CommittedRayT());
19+
}
20+
//--- pipeline.yaml
21+
---
22+
Shaders:
23+
- Stage: Compute
24+
Entry: main
25+
Buffers:
26+
- Name: Vertices
27+
Format: Float32
28+
Stride: 12
29+
Data: [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ]
30+
- Name: Output
31+
Format: UInt32
32+
Stride: 4
33+
FillSize: 4
34+
- Name: Expected
35+
Format: UInt32
36+
Stride: 4
37+
Data: [ 0x3f800000 ] # asuint(1.0)
38+
AccelerationStructures:
39+
BLAS:
40+
- Name: TriangleBLAS
41+
Triangles:
42+
- VertexBuffer: Vertices
43+
VertexFormat: RGB32Float
44+
VertexStride: 12
45+
VertexCount: 3
46+
TLAS:
47+
- Name: Scene
48+
Instances:
49+
- BLAS: TriangleBLAS
50+
DescriptorSets:
51+
- Resources:
52+
- Name: Scene
53+
Kind: AccelerationStructure
54+
DirectXBinding:
55+
Register: 0
56+
Space: 0
57+
VulkanBinding:
58+
Binding: 0
59+
- Name: Output
60+
Kind: RWStructuredBuffer
61+
DirectXBinding:
62+
Register: 0
63+
Space: 0
64+
VulkanBinding:
65+
Binding: 1
66+
Results:
67+
- Result: CommittedRayT
68+
Rule: BufferExact
69+
Actual: Output
70+
Expected: Expected
71+
...
72+
#--- end
73+
74+
# REQUIRES: acceleration-structure
75+
# XFAIL: Clang
76+
77+
# RUN: split-file %s %t
78+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
79+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#--- source.hlsl
2+
3+
[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0);
4+
[[vk::binding(1, 0)]] RWStructuredBuffer<uint> Output : register(u0);
5+
6+
[numthreads(1,1,1)]
7+
void main() {
8+
// The triangle sits at z=0 and the ray starts at z=1 along -z, so the hit
9+
// is at t=1.0. Probe two queries that each push the [TMin, TMax] window
10+
// off that hit — one starts above it, the other ends below it. Both must
11+
// return COMMITTED_NOTHING.
12+
RayDesc Ray;
13+
Ray.Origin = float3(0, 0, 1);
14+
Ray.Direction = float3(0, 0, -1);
15+
16+
Ray.TMin = 2.0;
17+
Ray.TMax = 100.0;
18+
RayQuery<RAY_FLAG_NONE> QFar;
19+
QFar.TraceRayInline(Scene, RAY_FLAG_NONE, 0xFF, Ray);
20+
QFar.Proceed();
21+
Output[0] = (uint)QFar.CommittedStatus();
22+
23+
Ray.TMin = 0.0;
24+
Ray.TMax = 0.5;
25+
RayQuery<RAY_FLAG_NONE> QNear;
26+
QNear.TraceRayInline(Scene, RAY_FLAG_NONE, 0xFF, Ray);
27+
QNear.Proceed();
28+
Output[1] = (uint)QNear.CommittedStatus();
29+
}
30+
//--- pipeline.yaml
31+
---
32+
Shaders:
33+
- Stage: Compute
34+
Entry: main
35+
Buffers:
36+
- Name: Vertices
37+
Format: Float32
38+
Stride: 12
39+
Data: [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ]
40+
- Name: Output
41+
Format: UInt32
42+
Stride: 4
43+
FillSize: 8
44+
- Name: Expected
45+
Format: UInt32
46+
Stride: 4
47+
Data: [ 0, 0 ] # Both queries miss → COMMITTED_NOTHING
48+
AccelerationStructures:
49+
BLAS:
50+
- Name: TriangleBLAS
51+
Triangles:
52+
- VertexBuffer: Vertices
53+
VertexFormat: RGB32Float
54+
VertexStride: 12
55+
VertexCount: 3
56+
TLAS:
57+
- Name: Scene
58+
Instances:
59+
- BLAS: TriangleBLAS
60+
DescriptorSets:
61+
- Resources:
62+
- Name: Scene
63+
Kind: AccelerationStructure
64+
DirectXBinding:
65+
Register: 0
66+
Space: 0
67+
VulkanBinding:
68+
Binding: 0
69+
- Name: Output
70+
Kind: RWStructuredBuffer
71+
DirectXBinding:
72+
Register: 0
73+
Space: 0
74+
VulkanBinding:
75+
Binding: 1
76+
Results:
77+
- Result: TMinTMaxClip
78+
Rule: BufferExact
79+
Actual: Output
80+
Expected: Expected
81+
...
82+
#--- end
83+
84+
# REQUIRES: acceleration-structure
85+
# XFAIL: Clang
86+
87+
# RUN: split-file %s %t
88+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
89+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)