Skip to content

Commit e2e10fb

Browse files
authored
Add test case for RayQuery parameter. (shader-slang#3140)
* Add test case for RayQuery parameter. * Update expeccted failure. --------- Co-authored-by: Yong He <yhe@nvidia.com>
1 parent 9d7c9b9 commit e2e10fb

3 files changed

+80
-0
lines changed

tests/bugs/ray-query-in-generic.slang

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
//TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query
3+
//TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query
4+
5+
//TEST_INPUT: set scene = AccelerationStructure
6+
uniform RaytracingAccelerationStructure scene;
7+
8+
struct Ray
9+
{
10+
float3 origin;
11+
float tMin;
12+
float3 dir;
13+
float tMax;
14+
15+
/**
16+
* Initializes a ray.
17+
*/
18+
__init(float3 origin, float3 dir, float tMin = 0.f, float tMax = 10000.0)
19+
{
20+
this.origin = origin;
21+
this.dir = dir;
22+
this.tMin = tMin;
23+
this.tMax = tMax;
24+
}
25+
26+
/**
27+
* Convert to DXR RayDesc.
28+
*/
29+
RayDesc toRayDesc() { return { origin, tMin, dir, tMax }; }
30+
31+
/**
32+
* Evaluate position on the ray.
33+
* @param[in] t Ray parameter.
34+
* @return Returns evaluated position.
35+
*/
36+
float3 eval(float t) { return origin + t * dir; }
37+
};
38+
39+
RaytracingAccelerationStructure sceneBVH;
40+
41+
// TODO: remove force inline here will result in an error.
42+
[ForceInline]
43+
bool traceSceneVisibilityRayImpl<let Flags : int>(const bool useAlphaTest, inout RayQuery<Flags> q, const Ray ray, uint rayFlags, uint instanceInclusionMask)
44+
{
45+
var rayDesc = ray.toRayDesc();
46+
q.TraceRayInline(
47+
scene,
48+
rayFlags,
49+
0xff,
50+
rayDesc);
51+
q.Proceed();
52+
if (q.CommittedStatus() == COMMITTED_TRIANGLE_HIT)
53+
{
54+
q.CommittedRayT();
55+
return true;
56+
}
57+
return false;
58+
}
59+
60+
bool traceSceneVisibilityRay<let UseAlphaTest : int>(const Ray ray, uint rayFlags, uint instanceInclusionMask)
61+
{
62+
RayQuery rayQuery;
63+
return traceSceneVisibilityRayImpl(false, rayQuery, ray, rayFlags, instanceInclusionMask);
64+
}
65+
66+
//TEST_INPUT:set outputBuffer = out ubuffer(data=[0], stride=4)
67+
RWStructuredBuffer<float> outputBuffer;
68+
69+
[shader("compute")]
70+
[numthreads(1, 1, 1)]
71+
void computeMain(
72+
uint3 threadIdx: SV_DispatchThreadID)
73+
{
74+
Ray ray = Ray(float3(0.1, 0.1, 0.0), float3(0, 0, 1), 0.1);
75+
if (traceSceneVisibilityRay<0>(ray, 0, 0xffff))
76+
outputBuffer[threadIdx.x] = 1.0;
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type: float
2+
1.000000

tests/expected-failure.txt

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ tests/bugs/matrix-reshape.slang.1 (vk)
6060
tests/bugs/nested-switch.slang.1 (vk)
6161
tests/bugs/parameter-block-load.slang (vk)
6262
tests/bugs/parens-cast-issue.slang.1 (vk)
63+
tests/bugs/ray-query-in-generic.slang.1 (vk)
6364
tests/bugs/string-inline.slang.4 (vk)
6465
tests/bugs/vec-compare.slang.2 (vk)
6566
tests/bugs/vec-init.slang.2 (vk)

0 commit comments

Comments
 (0)