yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
05f24d294
master
1//TEST:SIMPLE(filecheck=CHECK_SPIRV): -target spirv -fvk-use-entrypoint-name 2//TEST:SIMPLE(filecheck=CHECK_GLSL): -target glsl -fvk-use-entrypoint-name 3 4// 5// Check that SPIRV quad control execution modes and GLSL layout/attribute decorations are only 6// set on entry points that contain quad control functions and/or quad control decorations. 7// 8 9Texture2D colorTexture1; 10SamplerState samplerState; 11 12struct FragmentInput { 13 float2 uv : TEXCOORD0; 14}; 15 16float4 getFragColor(float2 uv) { 17 float4 fragColor = float4(1.0, 1.0, 1.0, 1.0); 18 bool nonUniformCondition = uv.x > 0.5; 19 20 if (QuadAny(nonUniformCondition)) { 21 float4 color = colorTexture1.Sample(samplerState, uv); 22 if (nonUniformCondition) { 23 fragColor = color; 24 } 25 } 26 27 return fragColor; 28} 29 30// CHECK_SPIRV: OpExtension "SPV_KHR_maximal_reconvergence" 31// CHECK_SPIRV: OpExecutionMode %fragmentMain1 MaximallyReconvergesKHR 32// CHECK_SPIRV: OpExecutionMode %fragmentMain1 QuadDerivativesKHR 33// CHECK_GLSL: layout(quad_derivatives) in 34// CHECK_GLSL: [maximally_reconverges] 35[shader("fragment")] 36float4 fragmentMain1(FragmentInput input) : SV_Target 37{ 38 bool nonUniformCondition = input.uv.x > 0.5; 39 40 float4 fragColor = float4(1.0, 1.0, 1.0, 1.0); 41 42 if (QuadAny(nonUniformCondition)) { 43 float4 color = colorTexture1.Sample(samplerState, input.uv); 44 if (nonUniformCondition) { 45 fragColor = color; 46 } 47 } 48 49 return fragColor; 50} 51 52// CHECK_SPIRV-NOT: OpExecutionMode %fragmentMain2 QuadDerivativesKHR 53// CHECK_SPIRV: OpExecutionMode %fragmentMain2 MaximallyReconvergesKHR 54// CHECK_GLSL-NOT: layout(quad_derivatives) in 55// CHECK_GLSL: [maximally_reconverges] 56[MaximallyReconverges] 57[shader("fragment")] 58float4 fragmentMain2(FragmentInput input) : SV_Target 59{ 60 return float4(1.0, 1.0, 1.0, 1.0); 61} 62 63 64// CHECK_SPIRV-NOT: OpExecutionMode %fragmentMain3 MaximallyReconvergesKHR 65// CHECK_SPIRV-NOT: OpExecutionMode %fragmentMain3 QuadDerivativesKHR 66// CHECK_SPIRV: OpExecutionMode %fragmentMain3 RequireFullQuadsKHR 67// CHECK_GLSL-NOT: layout(quad_derivatives) in 68// CHECK_GLSL: layout(full_quads) in 69// CHECK_GLSL-NOT: [maximally_reconverges] 70[RequireFullQuads] 71[shader("fragment")] 72float4 fragmentMain3(FragmentInput input) : SV_Target 73{ 74 return float4(1.0, 1.0, 1.0, 1.0); 75} 76 77// CHECK_SPIRV: OpExecutionMode %fragmentMain4 MaximallyReconvergesKHR 78// CHECK_SPIRV: OpExecutionMode %fragmentMain4 QuadDerivativesKHR 79// CHECK_GLSL: layout(quad_derivatives) in 80// CHECK_GLSL: [maximally_reconverges] 81[shader("fragment")] 82float4 fragmentMain4(FragmentInput input) : SV_Target 83{ 84 return getFragColor(input.uv); 85} 86 87// CHECK_SPIRV-NOT: OpExecutionMode %fragmentMain5 MaximallyReconvergesKHR 88// CHECK_SPIRV-NOT: OpExecutionMode %fragmentMain5 QuadDerivativesKHR 89// CHECK_SPIRV-NOT: OpExecutionMode %fragmentMain5 RequireFullQuadsKHR 90// CHECK_GLSL-NOT: layout(quad_derivatives) in 91// CHECK_GLSL-NOT: layout(full_quads) in 92// CHECK_GLSL-NOT: [maximally_reconverges] 93[shader("fragment")] 94float4 fragmentMain5(FragmentInput input) : SV_Target 95{ 96 return float4(1.0, 1.0, 1.0, 1.0); 97}