yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
a6deb5ed8
master
1// TEST:SIMPLE(filecheck=CHECK_GLSL): -entry vertexMain -stage vertex -target glsl 2// TEST:SIMPLE(filecheck=CHECK_SPV): -entry vertexMain -stage vertex -emit-spirv-directly -target spirv 3// TEST:SIMPLE(filecheck=CHECK_SPV_VIA_GLSL): -entry vertexMain -stage vertex -emit-spirv-via-glsl -target spirv 4 5struct Inner1 6{ 7 float4 position; 8 Inner2* inner; 9} 10 11struct Inner2 12{ 13 float4 position; 14} 15 16struct Vertex 17{ 18 float4 position; 19 Inner1* inner; 20} 21 22struct VSOutput 23{ 24 float4 position : SV_Position; 25} 26 27struct PushConstants 28{ 29 float a; 30 Vertex* verts; 31}; 32 33[[vk::push_constant]] 34PushConstants pushConstants; 35 36ConstantBuffer<PushConstants> constantBuffer; 37 38// CHECK_SPV: OpEntryPoint 39// CHECK_SPV: OpTypePointer PhysicalStorageBuffer 40// CHECK_SPV: OpPtrAccessChain 41 42// CHECK_SPV_VIA_GLSL: Glslang 43// CHECK_SPV_VIA_GLSL: OpEntryPoint 44// CHECK_SPV_VIA_GLSL: OpTypePointer PhysicalStorageBuffer 45 46[shader("vertex")] 47VSOutput vertexMain(int vertexIndex: SV_VulkanVertexID) 48{ 49 // 50 // Test field access chains. 51 // 52 53 // CHECK_GLSL: (((((pushConstants_0.verts_0 + gl_VertexIndex)._data.inner_1) + 1)._data.inner_0) + 5)._data.position_0 54 let position1 = pushConstants.verts[vertexIndex].inner[1].inner[5].position; 55 56 // CHECK_GLSL: (((((constantBuffer_0.verts_0 + 7)._data.inner_1) + 3)._data.inner_0) + 4)._data.position_0 57 let position2 = constantBuffer.verts[7].inner[3].inner[4].position; 58 59 // CHECK_GLSL: (((constantBuffer_0.verts_0 + gl_VertexIndex)._data.inner_1) + 12)._data.position_1 60 let position3 = constantBuffer.verts[vertexIndex].inner[12].position; 61 62 // 63 // Test accesing from a variable. 64 // 65 66 // CHECK_GLSL: ((((pushConstants_0.verts_0 + 8)._data.inner_1 + 6)._data.inner_0))._data.position_0 67 let vertex = pushConstants.verts[8]; 68 let position4 = vertex.inner[6].inner.position; 69 70 VSOutput output; 71 output.position = position1 + position2 + position3 + position4; 72 output.position *= pushConstants.a; 73 74 return output; 75} 76