yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
91430870a
master
1//TEST:SIMPLE(filecheck=VERT): -target wgsl -stage vertex -entry vertexMain 2//TEST:SIMPLE(filecheck=FRAG): -target wgsl -stage fragment -entry fragmentMain 3 4// Tests three aspects: 5// 1. Flatten the nested struct for the return type of the entry-point 6// 2. For fragment shader, SV_TARGET index must be emitted as @location(index) 7// 3. For non-fragment shader, the user defined semantics should be emitted as @location(index) 8 9struct FragmentOutput 10{ 11 //FRAG: @location(1) color1 12 float4 color1 : SV_TARGET1; 13 14 //FRAG: @location(0) color0 15 float4 color0 : SV_TARGET0; 16}; 17 18struct NestedVertexOutput 19{ 20 float4 color : COLOR0; 21}; 22 23struct VertexOutput 24{ 25 //VERT: @location(0) uv 26 //FRAG-DAG: @location(0) uv 27 float2 uv : TEXCOORD0; 28 29 //VERT: @location(1) color 30 //FRAG-DAG: @location(1) color 31 NestedVertexOutput nested; 32 33 //VERT: @builtin(position) position 34 //FRAG-DAG: @builtin(position) position 35 float4 position : SV_Position; 36}; 37 38VertexOutput vertexMain() 39{ 40 VertexOutput out; 41 out.position = float4(1.0, 1.0, 1.0, 1.0); 42 out.uv = float2(0.5, 0.5); 43 out.nested.color = float4(0.0, 0.0, 0.0, 0.0); 44 return out; 45} 46 47//FRAG-DAG: @location(3) color3 48//FRAG-DAG: @location(6) color6 49FragmentOutput fragmentMain(VertexOutput input, float4 color3: COLOR3, float4 color6: COLOR6) 50{ 51 FragmentOutput out; 52 out.color0 = input.nested.color + color3; 53 out.color1 = input.nested.color + color6; 54 return out; 55}