yum-mirror/slang

Making it easier to work with shaders

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

Yong HeLower varying parameters as pointers instead of SSA values. (#5919)c43f6fa55

master
2.0 KiB76 linesraw
1// closesthit.slang
2
3//TEST:SIMPLE(filecheck=GL_SPIRV): -stage anyhit -entry main -target spirv-assembly -emit-spirv-via-glsl
4//TEST:SIMPLE(filecheck=SPIRV): -stage anyhit -entry main -target spirv
5
6struct SphereHitAttributes
7{
8    float3 normal;
9};
10
11
12struct ShadowRay
13{
14    float4 hitDistance;
15    float3 dummyOut;
16};
17
18struct Params
19{
20    Texture2D<float>    alphaMap;
21    SamplerState        sampler;
22    int                 mode;
23}
24ParameterBlock<Params> gParams;
25
26void main(
27    SphereHitAttributes attributes,
28    in out ShadowRay    ioPayload)
29{
30    if(gParams.mode != 0)
31    {
32        float val = gParams.alphaMap.SampleLevel(
33            gParams.sampler,
34            attributes.normal.xy, 0);
35        if(val > 0)
36        {
37            AcceptHitAndEndSearch();
38        }
39        else
40        {
41            IgnoreHit();
42        }
43    }
44
45    uint index = 0U;
46    ioPayload.dummyOut = HitTriangleVertexPosition(index);
47
48    index = 1U;
49    ioPayload.dummyOut += HitTriangleVertexPosition(index);
50
51    index = 2U;
52    ioPayload.dummyOut += HitTriangleVertexPosition(index);
53}
54
55// SPIRV-DAG: OpCapability RayTracing
56// SPIRV-DAG: OpCapability RayTracingPositionFetchKHR
57// SPIRV: OpEntryPoint
58// SPIRV: BuiltIn HitTriangleVertexPositionsKHR
59// SPIRV: OpTypePointer HitAttribute{{NV|KHR}}
60// SPIRV: OpVariable{{.*}}HitAttribute{{NV|KHR}}
61// SPIRV: OpIgnoreIntersectionKHR
62// SPIRV: OpTerminateRayKHR
63// SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
64// SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
65// SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
66
67// GL_SPIRV-DAG: OpCapability RayTracing
68// GL_SPIRV-DAG: OpCapability RayTracingPositionFetchKHR
69// GL_SPIRV: OpEntryPoint
70// GL_SPIRV: BuiltIn HitTriangleVertexPositionsKHR
71// GL_SPIRV-DAG: OpTypePointer HitAttribute{{NV|KHR}}
72// GL_SPIRV: OpTerminateRayKHR
73// GL_SPIRV: OpIgnoreIntersectionKHR
74// GL_SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
75// GL_SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
76// GL_SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}