summaryrefslogtreecommitdiffstats
path: root/tests/vkray/anyhit.slang
blob: 8f5a6e597fc7433fc69cd3b45375ef7c8ab609b5 (plain)
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
// closesthit.slang

//TEST:SIMPLE(filecheck=GL_SPIRV): -stage anyhit -entry main -target spirv-assembly -emit-spirv-via-glsl
//TEST:SIMPLE(filecheck=SPIRV): -stage anyhit -entry main -target spirv

struct SphereHitAttributes
{
    float3 normal;
};


struct ShadowRay
{
    float4 hitDistance;
    float3 dummyOut;
};

struct Params
{
    Texture2D<float>    alphaMap;
    SamplerState        sampler;
    int                 mode;
}
ParameterBlock<Params> gParams;

void main(
    SphereHitAttributes attributes,
    in out ShadowRay    ioPayload)
{
    if(gParams.mode != 0)
    {
        float val = gParams.alphaMap.SampleLevel(
            gParams.sampler,
            attributes.normal.xy, 0);
        if(val > 0)
        {
            AcceptHitAndEndSearch();
        }
        else
        {
            IgnoreHit();
        }
    }

    uint index = 0U;
    ioPayload.dummyOut = HitTriangleVertexPosition(index);

    index = 1U;
    ioPayload.dummyOut += HitTriangleVertexPosition(index);

    index = 2U;
    ioPayload.dummyOut += HitTriangleVertexPosition(index);
}

// SPIRV-DAG: OpCapability RayTracing
// SPIRV-DAG: OpCapability RayTracingPositionFetchKHR
// SPIRV: OpEntryPoint
// SPIRV: BuiltIn HitTriangleVertexPositionsKHR
// SPIRV: OpTypePointer HitAttribute{{NV|KHR}}
// SPIRV: OpVariable{{.*}}HitAttribute{{NV|KHR}}
// SPIRV: OpIgnoreIntersectionKHR
// SPIRV: OpTerminateRayKHR
// SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
// SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
// SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}

// GL_SPIRV-DAG: OpCapability RayTracing
// GL_SPIRV-DAG: OpCapability RayTracingPositionFetchKHR
// GL_SPIRV: OpEntryPoint
// GL_SPIRV: BuiltIn HitTriangleVertexPositionsKHR
// GL_SPIRV-DAG: OpTypePointer HitAttribute{{NV|KHR}}
// GL_SPIRV: OpTerminateRayKHR
// GL_SPIRV: OpIgnoreIntersectionKHR
// GL_SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
// GL_SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}
// GL_SPIRV-DAG: %{{.*}} = OpAccessChain %{{.*}} %{{.*}} %{{.*}}