yum-mirror/slang

Making it easier to work with shaders

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

Yong HeMap `SV_InstanceID` to `gl_InstanceIndex-gl_BaseInstance` (#6468)6f2ce72b0

master
1.4 KiB47 linesraw
1//TEST:SIMPLE(filecheck=CHECK_SPIRV): -entry main -stage vertex -target spirv
2//TEST:SIMPLE(filecheck=CHECK_GLSL): -entry main -stage vertex -target glsl
3//TEST:SIMPLE(filecheck=CHECK_HLSL): -entry main -stage vertex -target hlsl
4//TEST:SIMPLE(filecheck=CHECK_METAL): -entry main -stage vertex -target metal
5
6StructuredBuffer<float> scales;
7
8struct VSInput
9{
10    uint vertexID : SV_VertexID;
11    uint instanceID : SV_InstanceID;
12};
13
14struct VSOutput
15{
16    float4 position : SV_POSITION;
17};
18
19VSOutput main(VSInput input, 
20              uint startVertexLocation : SV_StartVertexLocation, 
21              uint startInstanceLocation : SV_StartInstanceLocation,
22              uint viewIndex : SV_ViewID)
23{
24    VSOutput output;
25
26    float x = (float)(input.vertexID + startVertexLocation) * 0.1f;
27    float y = (float)(input.instanceID + startInstanceLocation) * 0.2f;
28    output.position = float4(x, y, 0.0f, 1.0f) * scales[viewIndex];
29
30    // CHECK_SPIRV: BuiltIn BaseVertex
31    // CHECK_GLSL: gl_BaseVertex
32    // CHECK_HLSL: SV_StartVertexLocation
33    // CHECK_METAL: base_vertex
34
35    // CHECK_SPIRV: BuiltIn InstanceIndex
36    // CHECK_GLSL: gl_BaseInstance
37    // CHECK_HLSL: SV_StartInstanceLocation
38    // CHECK_METAL: base_instance
39
40    // CHECK_SPIRV: BuiltIn ViewIndex
41    // CHECK_GLSL: gl_ViewIndex
42    // CHECK_HLSL: SV_ViewID
43    // CHECK_METAL: amplification_id
44
45    return output;
46}
47