yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
3.5 KiB121 linesraw
1// hit-object-reorder-thread.slang
2
3//TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0
4//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none 
5//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -emit-spirv-directly
6
7//DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -profile sm_6_5 -render-feature ray-query
8//DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query
9
10//TEST_INPUT: set scene = AccelerationStructure
11uniform RaytracingAccelerationStructure scene;
12
13//TEST_INPUT:set outputBuffer = out ubuffer(data=[0, 0, 0, 0], stride=4)
14RWStructuredBuffer<uint> outputBuffer;
15
16struct SomeValues
17{
18    int a;
19    float b;
20};
21
22uint calcValue(HitObject hit)
23{
24    uint r = 0;
25    
26    if (hit.IsHit())
27    {
28        uint instanceIndex = hit.GetInstanceIndex();
29        uint instanceID = hit.GetInstanceID();
30        uint geometryIndex = hit.GetGeometryIndex();
31        uint primitiveIndex = hit.GetPrimitiveIndex();
32
33        SomeValues objSomeValues = hit.GetAttributes<SomeValues>();
34        
35        r += instanceIndex;
36        r += instanceID;
37        r += geometryIndex;
38        r += primitiveIndex;
39        r += objSomeValues.a;
40    }
41    
42    return r;
43}
44
45void rayGenerationMain() 
46{
47    int2 launchID = int2(DispatchRaysIndex().xy);
48    int2 launchSize = int2(DispatchRaysDimensions().xy);
49
50    int idx = launchID.x;
51    
52    SomeValues someValues = { idx, idx * 2.0f };
53
54    RayDesc ray;  
55    ray.Origin = float3(idx, 0, 0);
56    ray.TMin = 0.01f;
57    ray.Direction = float3(0, 1, 0);
58    ray.TMax = 1e4f;
59    
60    RAY_FLAG rayFlags = RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_CULL_BACK_FACING_TRIANGLES;
61    uint instanceInclusionMask = 0xff;
62    uint rayContributionToHitGroupIndex = 0;
63    uint multiplierForGeometryContributionToHitGroupIndex = 4;
64    uint missShaderIndex = 0;
65
66    // SPIRV: OpHitObjectTraceRayNV
67    HitObject hit = HitObject::TraceRay(scene, 
68        rayFlags, 
69        instanceInclusionMask, 
70        rayContributionToHitGroupIndex, 
71        multiplierForGeometryContributionToHitGroupIndex, 
72        missShaderIndex, 
73        ray, 
74        someValues);
75
76    uint r = calcValue(hit);
77    // SPIRV: OpReorderThreadWithHitObjectNV
78    ReorderThread( hit );
79    
80    // Change the payload
81    SomeValues otherValues = { idx * -1, idx * 4.0f };
82
83    // Now Invoke to cast another ray, with the new payload
84    // SPIRV: OpHitObjectExecuteShaderNV
85    HitObject::Invoke( scene, hit, otherValues );
86    
87    r += calcValue(hit);
88  
89    // !!! TODO(JS) !!!
90    // NOTE! If I enable this I end up with a recursive failure in AST traversal, if 
91    // otherValues is redefined.
92
93    // Reorder
94    // SPIRV: OpReorderThreadWithHitObjectNV
95    ReorderThread(hit, uint(idx & 3), 2);
96
97    
98    // Change the payload
99    otherValues = { idx * -2, idx * 8.0f };
100
101    // Now Invoke to cast another ray, with the new payload
102    // SPIRV: OpHitObjectExecuteShaderNV
103    HitObject::Invoke( scene, hit, otherValues );
104    
105    r += calcValue(hit);
106
107    // Reorder
108    // SPIRV: OpReorderThreadWithHintNV
109    ReorderThread(uint(idx & 1), 1);
110    
111    // Change the payload
112    otherValues = { idx * -4, idx * 16.0f };
113
114    // Now Invoke to cast another ray, with the new payload
115    // SPIRV: OpHitObjectExecuteShaderNV
116    HitObject::Invoke( scene, hit, otherValues );
117    
118    r += calcValue(hit);
119    
120    outputBuffer[idx] = r;
121}