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
|
// hit-object-trace-ray.slang
//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
//TEST:SIMPLE(filecheck=CHECK): -target cuda -entry rayGenerationMain -stage raygeneration
//DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -profile sm_6_6 -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 SomeValues
{
int a;
float b;
};
uint calcValue(HitObject hit)
{
uint r = 0;
if (hit.IsHit())
{
uint instanceIndex = hit.GetInstanceIndex();
uint instanceID = hit.GetInstanceID();
uint geometryIndex = hit.GetGeometryIndex();
uint primitiveIndex = hit.GetPrimitiveIndex();
int clusterID = hit.GetClusterID();
float4 posRadius = hit.GetSpherePositionAndRadius();
float2x4 positionsRadii = hit.GetLssPositionsAndRadii();
uint isSphereHit = uint(hit.IsSphereHit());
uint isLssHit = uint(hit.IsLssHit());
SomeValues objSomeValues = hit.GetAttributes<SomeValues>();
r += instanceIndex;
r += instanceID;
r += geometryIndex;
r += primitiveIndex;
r += objSomeValues.a;
r += clusterID;
r += int(posRadius.x);
r += int(posRadius.y);
r += int(posRadius.z);
r += int(posRadius.w);
r += int(positionsRadii[0].x);
r += int(positionsRadii[0].y);
r += int(positionsRadii[0].z);
r += int(positionsRadii[0].w);
r += isSphereHit;
r += isLssHit;
}
return r;
}
void rayGenerationMain()
{
int2 launchID = int2(DispatchRaysIndex().xy);
int2 launchSize = int2(DispatchRaysDimensions().xy);
int idx = launchID.x;
SomeValues someValues = { idx, idx * 2.0f };
RayDesc ray;
ray.Origin = float3(idx, 0, 0);
ray.TMin = 0.01f;
ray.Direction = float3(0, 1, 0);
ray.TMax = 1e4f;
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: OpHitObjectTraceRayNV
// CHECK: optixTraverse
HitObject hit = HitObject::TraceRay(scene,
rayFlags,
instanceInclusionMask,
rayContributionToHitGroupIndex,
multiplierForGeometryContributionToHitGroupIndex,
missShaderIndex,
ray,
someValues);
outputBuffer[idx] = calcValue(hit);
}
|