1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// hit-object-output.slang
// This test validates that `HitObject`s can be used
// as function results (including `out` parameters)
//TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -emit-spirv-directly
//DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -profile sm_6_5 -render-feature ray-query
//DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query
//TEST_INPUT: set scene = AccelerationStructure
uniform RaytracingAccelerationStructure scene;
//TEST_INPUT:set outputBuffer = out ubuffer(data=[0, 0, 0, 0], stride=4)
RWStructuredBuffer<uint> outputBuffer;
struct MyAttributes
{
uint value;
};
struct MyRayPayload
{
uint value;
};
void accumulate(inout uint value, HitObject hit)
{
value = value*256;
if (hit.IsHit())
{
value += 16 + hit.GetAttributes<MyAttributes>().value;
}
}
RayDesc makeRay(uint idx, uint variation)
{
RayDesc ray;
ray.Origin = float3(idx, 0, variation);
ray.TMin = 0.01f;
ray.Direction = float3(0, 1, 0);
ray.TMax = 1e4f;
return ray;
}
HitObject myTraceRay(uint idx)
{
MyRayPayload payload = { idx };
RayDesc ray = makeRay(idx, 0);
RAY_FLAG rayFlags = RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_CULL_BACK_FACING_TRIANGLES;
uint instanceInclusionMask = 0xff;
uint rayContributionToHitGroupIndex = 0;
uint multiplierForGeometryContributionToHitGroupIndex = 4;
uint missShaderIndex = 0;
// SPIRV-DAG: OpHitObjectTraceRayNV
return HitObject::TraceRay(scene,
rayFlags,
instanceInclusionMask,
rayContributionToHitGroupIndex,
multiplierForGeometryContributionToHitGroupIndex,
missShaderIndex,
ray,
payload);
}
void copyHitObjectHandle(
out HitObject dst,
HitObject src)
{
dst = src;
}
void myMakeMiss(
uint idx,
inout HitObject h)
{
RayDesc ray = makeRay(idx, 1);
h = HitObject::MakeMiss(idx, ray);
}
void rayGenerationMain()
{
uint idx = uint(DispatchRaysIndex().x);
uint r = 0;
HitObject hit = myTraceRay(idx);
accumulate(r, hit);
#if 0 // cannot support this right now
HitObject hit2;
copyHitObjectHandle(hit2, hit);
accumulate(r, hit2);
#else
accumulate(r, hit);
#endif
myMakeMiss(idx, hit);
accumulate(r, hit);
accumulate(r, hit);
outputBuffer[idx] = r;
}
|