yum-mirror/slang

Making it easier to work with shaders

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

Mukund KeshavaConsolidate multiple inouts/outs into struct (#6435)b86925c19

master
1.3 KiB36 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -stage closesthit -entry main -target spirv -emit-spirv-directly
2
3// This test checks whether the spirv generated when there are multiple inout or out variables, they 
4// all get consolidated into one IncomingRayPayloadKHR.
5
6struct ReflectionRay
7{
8    float4 color;
9};
10
11StructuredBuffer<float4> colors;
12
13[shader("closesthit")]
14void main(
15    BuiltInTriangleIntersectionAttributes attributes,
16    inout ReflectionRay ioPayload,
17    out float3 dummy)
18{
19    uint materialID = (InstanceIndex() << 1)
20        + InstanceID()
21        + PrimitiveIndex()
22        + HitKind();
23
24    ioPayload.color = colors[materialID];
25    dummy = HitTriangleVertexPosition(0);
26}
27
28// CHECK: OpEntryPoint ClosestHitKHR %main "main" %{{.*}} %{{.*}} %gl_PrimitiveID %{{.*}} %gl_InstanceID %colors %{{.*}}
29// CHECK: %_struct_{{.*}} = OpTypeStruct %ReflectionRay %v3float
30// CHECK: %_ptr_IncomingRayPayloadKHR__struct_{{.*}} = OpTypePointer IncomingRayPayloadKHR %_struct_{{.*}}
31// CHECK: %main = OpFunction %void None %{{.*}}
32// CHECK: %materialID = OpIAdd %uint %{{.*}} %{{.*}}
33// CHECK: %{{.*}} = OpAccessChain %_ptr_StorageBuffer_v4float %colors %int_0 %materialID
34// CHECK: %{{.*}} = OpLoad %v4float %{{.*}}
35// CHECK: %{{.*}} = OpAccessChain %_ptr_Input_v3float %{{.*}} %uint_0
36// CHECK: %{{.*}} = OpLoad %v3float %{{.*}}