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