From 525b7f9d2811b1e550c2ce4f682d723300004522 Mon Sep 17 00:00:00 2001 From: hatoo Date: Wed, 9 Mar 2022 16:59:03 +0900 Subject: [PATCH 1/3] [glsl-out] Write constant sized array type for uniform --- src/back/glsl/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 76c5287820..c8dabbe58d 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -135,6 +135,12 @@ impl<'a> GlobalTypeKind<'a> { size: crate::ArraySize::Dynamic, .. } => Self::WrappedStruct, + // Naga IR permits globals to be constant sized arrays. Render + // these in GLSL as uniforms. + crate::TypeInner::Array { + size: crate::ArraySize::Constant(..), + .. + } => Self::WrappedStruct, _ => Self::Other, } } From 1ebc9ebd6a8f16091380e1c09a644c3dbb90cb3d Mon Sep 17 00:00:00 2001 From: hatoo Date: Wed, 9 Mar 2022 17:01:56 +0900 Subject: [PATCH 2/3] Update test case from wgpu's shadow example --- tests/in/shadow.wgsl | 116 +++- tests/out/glsl/shadow.fs_main.Fragment.glsl | 60 +- ...adow.fs_main_without_storage.Fragment.glsl | 79 +++ tests/out/glsl/shadow.vs_bake.Vertex.glsl | 38 ++ tests/out/glsl/shadow.vs_main.Vertex.glsl | 51 ++ tests/out/hlsl/shadow.hlsl | 133 +++- tests/out/hlsl/shadow.hlsl.config | 4 +- tests/out/msl/shadow.msl | 170 ++++- tests/out/spv/shadow.spvasm | 613 ++++++++++++------ tests/out/wgsl/shadow.wgsl | 118 +++- 10 files changed, 1063 insertions(+), 319 deletions(-) create mode 100644 tests/out/glsl/shadow.fs_main_without_storage.Fragment.glsl create mode 100644 tests/out/glsl/shadow.vs_bake.Vertex.glsl create mode 100644 tests/out/glsl/shadow.vs_main.Vertex.glsl diff --git a/tests/in/shadow.wgsl b/tests/in/shadow.wgsl index c50769d112..088608378c 100644 --- a/tests/in/shadow.wgsl +++ b/tests/in/shadow.wgsl @@ -1,61 +1,115 @@ struct Globals { + view_proj: mat4x4; num_lights: vec4; }; -@group(0) @binding(0) +@group(0) +@binding(0) var u_globals: Globals; +struct Entity { + world: mat4x4; + color: vec4; +}; + +@group(1) +@binding(0) +var u_entity: Entity; + +@stage(vertex) +fn vs_bake(@location(0) position: vec4) -> @builtin(position) vec4 { + return u_globals.view_proj * u_entity.world * vec4(position); +} + +struct VertexOutput { + @builtin(position) proj_position: vec4; + @location(0) world_normal: vec3; + @location(1) world_position: vec4; +}; + +@stage(vertex) +fn vs_main( + @location(0) position: vec4, + @location(1) normal: vec4, +) -> VertexOutput { + let w = u_entity.world; + let world_pos = u_entity.world * vec4(position); + var out: VertexOutput; + out.world_normal = mat3x3(w.x.xyz, w.y.xyz, w.z.xyz) * vec3(normal.xyz); + out.world_position = world_pos; + out.proj_position = u_globals.view_proj * world_pos; + return out; +} + +// fragment shader + struct Light { proj: mat4x4; pos: vec4; color: vec4; }; -struct Lights { - data: array; -}; - -@group(0) @binding(1) -var s_lights: Lights; -@group(0) @binding(2) +@group(0) +@binding(1) +var s_lights: array; +@group(0) +@binding(1) +var u_lights: array; // Used when storage types are not supported +@group(0) +@binding(2) var t_shadow: texture_depth_2d_array; -@group(0) @binding(3) +@group(0) +@binding(3) var sampler_shadow: sampler_comparison; fn fetch_shadow(light_id: u32, homogeneous_coords: vec4) -> f32 { - if homogeneous_coords.w <= 0.0 { + if (homogeneous_coords.w <= 0.0) { return 1.0; } + // compensate for the Y-flip difference between the NDC and texture coordinates let flip_correction = vec2(0.5, -0.5); - let light_local = homogeneous_coords.xy * flip_correction / homogeneous_coords.w + vec2(0.5, 0.5); - return textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z / homogeneous_coords.w); + // compute texture coordinates for shadow lookup + let proj_correction = 1.0 / homogeneous_coords.w; + let light_local = homogeneous_coords.xy * flip_correction * proj_correction + vec2(0.5, 0.5); + // do the lookup, using HW PCF and comparison + return textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z * proj_correction); } let c_ambient: vec3 = vec3(0.05, 0.05, 0.05); let c_max_lights: u32 = 10u; @stage(fragment) -fn fs_main( - @location(0) raw_normal: vec3, - @location(1) position: vec4 -) -> @location(0) vec4 { - let normal: vec3 = normalize(raw_normal); +fn fs_main(in: VertexOutput) -> @location(0) vec4 { + let normal = normalize(in.world_normal); // accumulate color - var color = c_ambient; - var i: u32 = 0u; - loop { - if i >= min(u_globals.num_lights.x, c_max_lights) { - break; - } - let light = s_lights.data[i]; - let shadow = fetch_shadow(i, light.proj * position); - let light_dir = normalize(light.pos.xyz - position.xyz); + var color: vec3 = c_ambient; + for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) { + let light = s_lights[i]; + // project into the light space + let shadow = fetch_shadow(i, light.proj * in.world_position); + // compute Lambertian diffuse term + let light_dir = normalize(light.pos.xyz - in.world_position.xyz); let diffuse = max(0.0, dot(normal, light_dir)); - color = color + shadow * diffuse * light.color.xyz; - continuing { - i = i + 1u; - } + // add light contribution + color += shadow * diffuse * light.color.xyz; } // multiply the light by material color - return vec4(color, 1.0); + return vec4(color, 1.0) * u_entity.color; +} + +// The fragment entrypoint used when storage buffers are not available for the lights +@stage(fragment) +fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4 { + let normal = normalize(in.world_normal); + var color: vec3 = c_ambient; + for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) { + // This line is the only difference from the entrypoint above. It uses the lights + // uniform instead of the lights storage buffer + let light = u_lights[i]; + let shadow = fetch_shadow(i, light.proj * in.world_position); + let light_dir = normalize(light.pos.xyz - in.world_position.xyz); + let diffuse = max(0.0, dot(normal, light_dir)); + color += shadow * diffuse * light.color.xyz; + } + return vec4(color, 1.0) * u_entity.color; } diff --git a/tests/out/glsl/shadow.fs_main.Fragment.glsl b/tests/out/glsl/shadow.fs_main.Fragment.glsl index 3e5562a711..fef409f10b 100644 --- a/tests/out/glsl/shadow.fs_main.Fragment.glsl +++ b/tests/out/glsl/shadow.fs_main.Fragment.glsl @@ -4,8 +4,18 @@ precision highp float; precision highp int; struct Globals { + mat4x4 view_proj; uvec4 num_lights; }; +struct Entity { + mat4x4 world; + vec4 color; +}; +struct VertexOutput { + vec4 proj_position; + vec3 world_normal; + vec4 world_position; +}; struct Light { mat4x4 proj; vec4 pos; @@ -13,9 +23,9 @@ struct Light { }; uniform Globals_block_0Fragment { Globals _group_0_binding_0_fs; }; -layout(std430) readonly buffer Lights_block_1Fragment { - Light data[]; -} _group_0_binding_1_fs; +uniform Entity_block_1Fragment { Entity _group_1_binding_0_fs; }; + +layout(std430) readonly buffer type_6_block_2Fragment { Light _group_0_binding_1_fs[]; }; uniform highp sampler2DArrayShadow _group_0_binding_2_fs; @@ -28,40 +38,42 @@ float fetch_shadow(uint light_id, vec4 homogeneous_coords) { return 1.0; } vec2 flip_correction = vec2(0.5, -0.5); - vec2 light_local = (((homogeneous_coords.xy * flip_correction) / vec2(homogeneous_coords.w)) + vec2(0.5, 0.5)); - float _e26 = textureGrad(_group_0_binding_2_fs, vec4(light_local, int(light_id), (homogeneous_coords.z / homogeneous_coords.w)), vec2(0.0), vec2(0.0)); - return _e26; + float proj_correction = (1.0 / homogeneous_coords.w); + vec2 light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + vec2(0.5, 0.5)); + float _e28 = textureGrad(_group_0_binding_2_fs, vec4(light_local, int(light_id), (homogeneous_coords.z * proj_correction)), vec2(0.0), vec2(0.0)); + return _e28; } void main() { - vec3 raw_normal = _vs2fs_location0; - vec4 position = _vs2fs_location1; + VertexOutput in_ = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1); vec3 color = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806); uint i = 0u; - vec3 normal = normalize(raw_normal); + vec3 normal_1 = normalize(in_.world_normal); bool loop_init = true; while(true) { if (!loop_init) { - uint _e40 = i; - i = (_e40 + 1u); + uint _e20 = i; + i = (_e20 + 1u); } loop_init = false; - uint _e12 = i; - uint _e15 = _group_0_binding_0_fs.num_lights.x; - if ((_e12 >= min(_e15, 10u))) { + uint _e14 = i; + uint _e17 = _group_0_binding_0_fs.num_lights.x; + if ((_e14 < min(_e17, 10u))) { + } else { break; } - uint _e19 = i; - Light light = _group_0_binding_1_fs.data[_e19]; - uint _e22 = i; - float _e25 = fetch_shadow(_e22, (light.proj * position)); - vec3 light_dir = normalize((light.pos.xyz - position.xyz)); - float diffuse = max(0.0, dot(normal, light_dir)); - vec3 _e34 = color; - color = (_e34 + ((_e25 * diffuse) * light.color.xyz)); + uint _e23 = i; + Light light = _group_0_binding_1_fs[_e23]; + uint _e26 = i; + float _e30 = fetch_shadow(_e26, (light.proj * in_.world_position)); + vec3 light_dir = normalize((light.pos.xyz - in_.world_position.xyz)); + float diffuse = max(0.0, dot(normal_1, light_dir)); + vec3 _e40 = color; + color = (_e40 + ((_e30 * diffuse) * light.color.xyz)); } - vec3 _e43 = color; - _fs2p_location0 = vec4(_e43, 1.0); + vec3 _e46 = color; + vec4 _e50 = _group_1_binding_0_fs.color; + _fs2p_location0 = (vec4(_e46, 1.0) * _e50); return; } diff --git a/tests/out/glsl/shadow.fs_main_without_storage.Fragment.glsl b/tests/out/glsl/shadow.fs_main_without_storage.Fragment.glsl new file mode 100644 index 0000000000..43f02cae10 --- /dev/null +++ b/tests/out/glsl/shadow.fs_main_without_storage.Fragment.glsl @@ -0,0 +1,79 @@ +#version 310 es + +precision highp float; +precision highp int; + +struct Globals { + mat4x4 view_proj; + uvec4 num_lights; +}; +struct Entity { + mat4x4 world; + vec4 color; +}; +struct VertexOutput { + vec4 proj_position; + vec3 world_normal; + vec4 world_position; +}; +struct Light { + mat4x4 proj; + vec4 pos; + vec4 color; +}; +uniform Globals_block_0Fragment { Globals _group_0_binding_0_fs; }; + +uniform Entity_block_1Fragment { Entity _group_1_binding_0_fs; }; + +uniform type_7_block_2Fragment { Light _group_0_binding_1_fs[10]; }; + +uniform highp sampler2DArrayShadow _group_0_binding_2_fs; + +layout(location = 0) smooth in vec3 _vs2fs_location0; +layout(location = 1) smooth in vec4 _vs2fs_location1; +layout(location = 0) out vec4 _fs2p_location0; + +float fetch_shadow(uint light_id, vec4 homogeneous_coords) { + if ((homogeneous_coords.w <= 0.0)) { + return 1.0; + } + vec2 flip_correction = vec2(0.5, -0.5); + float proj_correction = (1.0 / homogeneous_coords.w); + vec2 light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + vec2(0.5, 0.5)); + float _e28 = textureGrad(_group_0_binding_2_fs, vec4(light_local, int(light_id), (homogeneous_coords.z * proj_correction)), vec2(0.0), vec2(0.0)); + return _e28; +} + +void main() { + VertexOutput in_1 = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1); + vec3 color_1 = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806); + uint i_1 = 0u; + vec3 normal_1 = normalize(in_1.world_normal); + bool loop_init = true; + while(true) { + if (!loop_init) { + uint _e20 = i_1; + i_1 = (_e20 + 1u); + } + loop_init = false; + uint _e14 = i_1; + uint _e17 = _group_0_binding_0_fs.num_lights.x; + if ((_e14 < min(_e17, 10u))) { + } else { + break; + } + uint _e23 = i_1; + Light light = _group_0_binding_1_fs[_e23]; + uint _e26 = i_1; + float _e30 = fetch_shadow(_e26, (light.proj * in_1.world_position)); + vec3 light_dir = normalize((light.pos.xyz - in_1.world_position.xyz)); + float diffuse = max(0.0, dot(normal_1, light_dir)); + vec3 _e40 = color_1; + color_1 = (_e40 + ((_e30 * diffuse) * light.color.xyz)); + } + vec3 _e46 = color_1; + vec4 _e50 = _group_1_binding_0_fs.color; + _fs2p_location0 = (vec4(_e46, 1.0) * _e50); + return; +} + diff --git a/tests/out/glsl/shadow.vs_bake.Vertex.glsl b/tests/out/glsl/shadow.vs_bake.Vertex.glsl new file mode 100644 index 0000000000..6f6812a259 --- /dev/null +++ b/tests/out/glsl/shadow.vs_bake.Vertex.glsl @@ -0,0 +1,38 @@ +#version 310 es + +precision highp float; +precision highp int; + +struct Globals { + mat4x4 view_proj; + uvec4 num_lights; +}; +struct Entity { + mat4x4 world; + vec4 color; +}; +struct VertexOutput { + vec4 proj_position; + vec3 world_normal; + vec4 world_position; +}; +struct Light { + mat4x4 proj; + vec4 pos; + vec4 color; +}; +uniform Globals_block_0Vertex { Globals _group_0_binding_0_vs; }; + +uniform Entity_block_1Vertex { Entity _group_1_binding_0_vs; }; + +layout(location = 0) in ivec4 _p2vs_location0; + +void main() { + ivec4 position = _p2vs_location0; + mat4x4 _e4 = _group_0_binding_0_vs.view_proj; + mat4x4 _e6 = _group_1_binding_0_vs.world; + gl_Position = ((_e4 * _e6) * vec4(position)); + gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w); + return; +} + diff --git a/tests/out/glsl/shadow.vs_main.Vertex.glsl b/tests/out/glsl/shadow.vs_main.Vertex.glsl new file mode 100644 index 0000000000..a2e09ceec7 --- /dev/null +++ b/tests/out/glsl/shadow.vs_main.Vertex.glsl @@ -0,0 +1,51 @@ +#version 310 es + +precision highp float; +precision highp int; + +struct Globals { + mat4x4 view_proj; + uvec4 num_lights; +}; +struct Entity { + mat4x4 world; + vec4 color; +}; +struct VertexOutput { + vec4 proj_position; + vec3 world_normal; + vec4 world_position; +}; +struct Light { + mat4x4 proj; + vec4 pos; + vec4 color; +}; +uniform Globals_block_0Vertex { Globals _group_0_binding_0_vs; }; + +uniform Entity_block_1Vertex { Entity _group_1_binding_0_vs; }; + +layout(location = 0) in ivec4 _p2vs_location0; +layout(location = 1) in ivec4 _p2vs_location1; +layout(location = 0) smooth out vec3 _vs2fs_location0; +layout(location = 1) smooth out vec4 _vs2fs_location1; + +void main() { + ivec4 position_1 = _p2vs_location0; + ivec4 normal = _p2vs_location1; + VertexOutput out_ = VertexOutput(vec4(0.0), vec3(0.0), vec4(0.0)); + mat4x4 w = _group_1_binding_0_vs.world; + mat4x4 _e7 = _group_1_binding_0_vs.world; + vec4 world_pos = (_e7 * vec4(position_1)); + out_.world_normal = (mat3x3(w[0].xyz, w[1].xyz, w[2].xyz) * vec3(normal.xyz)); + out_.world_position = world_pos; + mat4x4 _e25 = _group_0_binding_0_vs.view_proj; + out_.proj_position = (_e25 * world_pos); + VertexOutput _e27 = out_; + gl_Position = _e27.proj_position; + _vs2fs_location0 = _e27.world_normal; + _vs2fs_location1 = _e27.world_position; + gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w); + return; +} + diff --git a/tests/out/hlsl/shadow.hlsl b/tests/out/hlsl/shadow.hlsl index e0d509c72c..5b0ef63fa9 100644 --- a/tests/out/hlsl/shadow.hlsl +++ b/tests/out/hlsl/shadow.hlsl @@ -2,9 +2,21 @@ static const float3 c_ambient = float3(0.05000000074505806, 0.05000000074505806, static const uint c_max_lights = 10; struct Globals { + row_major float4x4 view_proj; uint4 num_lights; }; +struct Entity { + row_major float4x4 world; + float4 color; +}; + +struct VertexOutput { + float4 proj_position : SV_Position; + linear float3 world_normal : LOC0; + linear float4 world_position : LOC1; +}; + struct Light { row_major float4x4 proj; float4 pos; @@ -12,13 +24,28 @@ struct Light { }; cbuffer u_globals : register(b0) { Globals u_globals; } +cbuffer u_entity : register(b0, space1) { Entity u_entity; } ByteAddressBuffer s_lights : register(t1); +cbuffer u_lights : register(b1) { Light u_lights[10]; } Texture2DArray t_shadow : register(t2); SamplerComparisonState sampler_shadow : register(s3); +struct VertexOutput_vs_main { + float3 world_normal : LOC0; + float4 world_position : LOC1; + float4 proj_position : SV_Position; +}; + struct FragmentInput_fs_main { - float3 raw_normal_1 : LOC0; - float4 position_1 : LOC1; + float3 world_normal_1 : LOC0; + float4 world_position_1 : LOC1; + float4 proj_position_1 : SV_Position; +}; + +struct FragmentInput_fs_main_without_storage { + float3 world_normal_2 : LOC0; + float4 world_position_2 : LOC1; + float4 proj_position_2 : SV_Position; }; float fetch_shadow(uint light_id, float4 homogeneous_coords) @@ -27,40 +54,100 @@ float fetch_shadow(uint light_id, float4 homogeneous_coords) return 1.0; } float2 flip_correction = float2(0.5, -0.5); - float2 light_local = (((homogeneous_coords.xy * flip_correction) / float2(homogeneous_coords.w.xx)) + float2(0.5, 0.5)); - float _expr26 = t_shadow.SampleCmpLevelZero(sampler_shadow, float3(light_local, int(light_id)), (homogeneous_coords.z / homogeneous_coords.w)); - return _expr26; + float proj_correction = (1.0 / homogeneous_coords.w); + float2 light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + float2(0.5, 0.5)); + float _expr28 = t_shadow.SampleCmpLevelZero(sampler_shadow, float3(light_local, int(light_id)), (homogeneous_coords.z * proj_correction)); + return _expr28; +} + +float4 vs_bake(int4 position : LOC0) : SV_Position +{ + float4x4 _expr4 = u_globals.view_proj; + float4x4 _expr6 = u_entity.world; + return mul(float4(position), mul(_expr6, _expr4)); +} + +VertexOutput_vs_main vs_main(int4 position_1 : LOC0, int4 normal : LOC1) +{ + VertexOutput out_ = (VertexOutput)0; + + float4x4 w = u_entity.world; + float4x4 _expr7 = u_entity.world; + float4 world_pos = mul(float4(position_1), _expr7); + out_.world_normal = mul(float3(normal.xyz), float3x3(w[0].xyz, w[1].xyz, w[2].xyz)); + out_.world_position = world_pos; + float4x4 _expr25 = u_globals.view_proj; + out_.proj_position = mul(world_pos, _expr25); + VertexOutput _expr27 = out_; + const VertexOutput vertexoutput = _expr27; + const VertexOutput_vs_main vertexoutput_1 = { vertexoutput.world_normal, vertexoutput.world_position, vertexoutput.proj_position }; + return vertexoutput_1; } float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0 { - float3 raw_normal = fragmentinput_fs_main.raw_normal_1; - float4 position = fragmentinput_fs_main.position_1; + VertexOutput in_ = { fragmentinput_fs_main.proj_position_1, fragmentinput_fs_main.world_normal_1, fragmentinput_fs_main.world_position_1 }; float3 color = float3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806); uint i = 0u; - float3 normal = normalize(raw_normal); + float3 normal_1 = normalize(in_.world_normal); bool loop_init = true; while(true) { if (!loop_init) { - uint _expr40 = i; - i = (_expr40 + 1u); + uint _expr20 = i; + i = (_expr20 + 1u); } loop_init = false; - uint _expr12 = i; - uint _expr15 = u_globals.num_lights.x; - if ((_expr12 >= min(_expr15, c_max_lights))) { + uint _expr14 = i; + uint _expr17 = u_globals.num_lights.x; + if ((_expr14 < min(_expr17, c_max_lights))) { + } else { + break; + } + uint _expr23 = i; + Light light = {float4x4(asfloat(s_lights.Load4(_expr23*96+0+0)), asfloat(s_lights.Load4(_expr23*96+0+16)), asfloat(s_lights.Load4(_expr23*96+0+32)), asfloat(s_lights.Load4(_expr23*96+0+48))), asfloat(s_lights.Load4(_expr23*96+64)), asfloat(s_lights.Load4(_expr23*96+80))}; + uint _expr26 = i; + const float _e30 = fetch_shadow(_expr26, mul(in_.world_position, light.proj)); + float3 light_dir = normalize((light.pos.xyz - in_.world_position.xyz)); + float diffuse = max(0.0, dot(normal_1, light_dir)); + float3 _expr40 = color; + color = (_expr40 + ((_e30 * diffuse) * light.color.xyz)); + } + float3 _expr46 = color; + float4 _expr50 = u_entity.color; + return (float4(_expr46, 1.0) * _expr50); +} + +float4 fs_main_without_storage(FragmentInput_fs_main_without_storage fragmentinput_fs_main_without_storage) : SV_Target0 +{ + VertexOutput in_1 = { fragmentinput_fs_main_without_storage.proj_position_2, fragmentinput_fs_main_without_storage.world_normal_2, fragmentinput_fs_main_without_storage.world_position_2 }; + float3 color_1 = float3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806); + uint i_1 = 0u; + + float3 normal_2 = normalize(in_1.world_normal); + bool loop_init_1 = true; + while(true) { + if (!loop_init_1) { + uint _expr20 = i_1; + i_1 = (_expr20 + 1u); + } + loop_init_1 = false; + uint _expr14 = i_1; + uint _expr17 = u_globals.num_lights.x; + if ((_expr14 < min(_expr17, c_max_lights))) { + } else { break; } - uint _expr19 = i; - Light light = {float4x4(asfloat(s_lights.Load4(_expr19*96+0+0+0)), asfloat(s_lights.Load4(_expr19*96+0+0+16)), asfloat(s_lights.Load4(_expr19*96+0+0+32)), asfloat(s_lights.Load4(_expr19*96+0+0+48))), asfloat(s_lights.Load4(_expr19*96+0+64)), asfloat(s_lights.Load4(_expr19*96+0+80))}; - uint _expr22 = i; - const float _e25 = fetch_shadow(_expr22, mul(position, light.proj)); - float3 light_dir = normalize((light.pos.xyz - position.xyz)); - float diffuse = max(0.0, dot(normal, light_dir)); - float3 _expr34 = color; - color = (_expr34 + ((_e25 * diffuse) * light.color.xyz)); + uint _expr23 = i_1; + Light light_1 = u_lights[_expr23]; + uint _expr26 = i_1; + const float _e30 = fetch_shadow(_expr26, mul(in_1.world_position, light_1.proj)); + float3 light_dir_1 = normalize((light_1.pos.xyz - in_1.world_position.xyz)); + float diffuse_1 = max(0.0, dot(normal_2, light_dir_1)); + float3 _expr40 = color_1; + color_1 = (_expr40 + ((_e30 * diffuse_1) * light_1.color.xyz)); } - float3 _expr43 = color; - return float4(_expr43, 1.0); + float3 _expr46 = color_1; + float4 _expr50 = u_entity.color; + return (float4(_expr46, 1.0) * _expr50); } diff --git a/tests/out/hlsl/shadow.hlsl.config b/tests/out/hlsl/shadow.hlsl.config index b9f047558a..2ed1c8fd71 100644 --- a/tests/out/hlsl/shadow.hlsl.config +++ b/tests/out/hlsl/shadow.hlsl.config @@ -1,3 +1,3 @@ -vertex=() -fragment=(fs_main:ps_5_1 ) +vertex=(vs_bake:vs_5_1 vs_main:vs_5_1 ) +fragment=(fs_main:ps_5_1 fs_main_without_storage:ps_5_1 ) compute=() diff --git a/tests/out/msl/shadow.msl b/tests/out/msl/shadow.msl index 5bdd3ba977..26af57fd2c 100644 --- a/tests/out/msl/shadow.msl +++ b/tests/out/msl/shadow.msl @@ -5,21 +5,31 @@ using metal::uint; struct _mslBufferSizes { - uint size1; + uint size2; }; constexpr constant unsigned c_max_lights = 10u; struct Globals { + metal::float4x4 view_proj; metal::uint4 num_lights; }; +struct Entity { + metal::float4x4 world; + metal::float4 color; +}; +struct VertexOutput { + metal::float4 proj_position; + metal::float3 world_normal; + metal::float4 world_position; +}; struct Light { metal::float4x4 proj; metal::float4 pos; metal::float4 color; }; -typedef Light type_3[1]; -struct Lights { - type_3 data; +typedef Light type_6[1]; +struct type_7 { + Light inner[10]; }; constant metal::float3 c_ambient = {0.05000000074505806, 0.05000000074505806, 0.05000000074505806}; @@ -33,52 +43,152 @@ float fetch_shadow( return 1.0; } metal::float2 flip_correction = metal::float2(0.5, -0.5); - metal::float2 light_local = ((homogeneous_coords.xy * flip_correction) / metal::float2(homogeneous_coords.w)) + metal::float2(0.5, 0.5); - float _e26 = t_shadow.sample_compare(sampler_shadow, light_local, static_cast(light_id), homogeneous_coords.z / homogeneous_coords.w); - return _e26; + float proj_correction = 1.0 / homogeneous_coords.w; + metal::float2 light_local = ((homogeneous_coords.xy * flip_correction) * proj_correction) + metal::float2(0.5, 0.5); + float _e28 = t_shadow.sample_compare(sampler_shadow, light_local, static_cast(light_id), homogeneous_coords.z * proj_correction); + return _e28; +} + +struct vs_bakeInput { + metal::int4 position [[attribute(0)]]; +}; +struct vs_bakeOutput { + metal::float4 member [[position]]; +}; +vertex vs_bakeOutput vs_bake( + vs_bakeInput varyings [[stage_in]] +, constant Globals& u_globals [[user(fake0)]] +, constant Entity& u_entity [[user(fake0)]] +) { + const auto position = varyings.position; + metal::float4x4 _e4 = u_globals.view_proj; + metal::float4x4 _e6 = u_entity.world; + return vs_bakeOutput { (_e4 * _e6) * static_cast(position) }; +} + + +struct vs_mainInput { + metal::int4 position_1 [[attribute(0)]]; + metal::int4 normal [[attribute(1)]]; +}; +struct vs_mainOutput { + metal::float4 proj_position [[position]]; + metal::float3 world_normal [[user(loc0), center_perspective]]; + metal::float4 world_position [[user(loc1), center_perspective]]; +}; +vertex vs_mainOutput vs_main( + vs_mainInput varyings_1 [[stage_in]] +, constant Globals& u_globals [[user(fake0)]] +, constant Entity& u_entity [[user(fake0)]] +) { + const auto position_1 = varyings_1.position_1; + const auto normal = varyings_1.normal; + VertexOutput out; + metal::float4x4 w = u_entity.world; + metal::float4x4 _e7 = u_entity.world; + metal::float4 world_pos = _e7 * static_cast(position_1); + out.world_normal = metal::float3x3(w[0].xyz, w[1].xyz, w[2].xyz) * static_cast(normal.xyz); + out.world_position = world_pos; + metal::float4x4 _e25 = u_globals.view_proj; + out.proj_position = _e25 * world_pos; + VertexOutput _e27 = out; + const auto _tmp = _e27; + return vs_mainOutput { _tmp.proj_position, _tmp.world_normal, _tmp.world_position }; } + struct fs_mainInput { - metal::float3 raw_normal [[user(loc0), center_perspective]]; - metal::float4 position [[user(loc1), center_perspective]]; + metal::float3 world_normal [[user(loc0), center_perspective]]; + metal::float4 world_position [[user(loc1), center_perspective]]; }; struct fs_mainOutput { - metal::float4 member [[color(0)]]; + metal::float4 member_2 [[color(0)]]; }; fragment fs_mainOutput fs_main( - fs_mainInput varyings [[stage_in]] + fs_mainInput varyings_2 [[stage_in]] +, metal::float4 proj_position [[position]] , constant Globals& u_globals [[user(fake0)]] -, device Lights const& s_lights [[user(fake0)]] +, constant Entity& u_entity [[user(fake0)]] +, device type_6 const& s_lights [[user(fake0)]] , metal::depth2d_array t_shadow [[user(fake0)]] , metal::sampler sampler_shadow [[user(fake0)]] , constant _mslBufferSizes& _buffer_sizes [[user(fake0)]] ) { - const auto raw_normal = varyings.raw_normal; - const auto position = varyings.position; + const VertexOutput in = { proj_position, varyings_2.world_normal, varyings_2.world_position }; metal::float3 color = c_ambient; uint i = 0u; - metal::float3 normal = metal::normalize(raw_normal); + metal::float3 normal_1 = metal::normalize(in.world_normal); bool loop_init = true; while(true) { if (!loop_init) { - uint _e40 = i; - i = _e40 + 1u; + uint _e20 = i; + i = _e20 + 1u; } loop_init = false; - uint _e12 = i; - uint _e15 = u_globals.num_lights.x; - if (_e12 >= metal::min(_e15, c_max_lights)) { + uint _e14 = i; + uint _e17 = u_globals.num_lights.x; + if (_e14 < metal::min(_e17, c_max_lights)) { + } else { + break; + } + uint _e23 = i; + Light light = s_lights[_e23]; + uint _e26 = i; + float _e30 = fetch_shadow(_e26, light.proj * in.world_position, t_shadow, sampler_shadow); + metal::float3 light_dir = metal::normalize(light.pos.xyz - in.world_position.xyz); + float diffuse = metal::max(0.0, metal::dot(normal_1, light_dir)); + metal::float3 _e40 = color; + color = _e40 + ((_e30 * diffuse) * light.color.xyz); + } + metal::float3 _e46 = color; + metal::float4 _e50 = u_entity.color; + return fs_mainOutput { metal::float4(_e46, 1.0) * _e50 }; +} + + +struct fs_main_without_storageInput { + metal::float3 world_normal [[user(loc0), center_perspective]]; + metal::float4 world_position [[user(loc1), center_perspective]]; +}; +struct fs_main_without_storageOutput { + metal::float4 member_3 [[color(0)]]; +}; +fragment fs_main_without_storageOutput fs_main_without_storage( + fs_main_without_storageInput varyings_3 [[stage_in]] +, metal::float4 proj_position_1 [[position]] +, constant Globals& u_globals [[user(fake0)]] +, constant Entity& u_entity [[user(fake0)]] +, constant type_7& u_lights [[user(fake0)]] +, metal::depth2d_array t_shadow [[user(fake0)]] +, metal::sampler sampler_shadow [[user(fake0)]] +) { + const VertexOutput in_1 = { proj_position_1, varyings_3.world_normal, varyings_3.world_position }; + metal::float3 color_1 = c_ambient; + uint i_1 = 0u; + metal::float3 normal_2 = metal::normalize(in_1.world_normal); + bool loop_init_1 = true; + while(true) { + if (!loop_init_1) { + uint _e20 = i_1; + i_1 = _e20 + 1u; + } + loop_init_1 = false; + uint _e14 = i_1; + uint _e17 = u_globals.num_lights.x; + if (_e14 < metal::min(_e17, c_max_lights)) { + } else { break; } - uint _e19 = i; - Light light = s_lights.data[_e19]; - uint _e22 = i; - float _e25 = fetch_shadow(_e22, light.proj * position, t_shadow, sampler_shadow); - metal::float3 light_dir = metal::normalize(light.pos.xyz - position.xyz); - float diffuse = metal::max(0.0, metal::dot(normal, light_dir)); - metal::float3 _e34 = color; - color = _e34 + ((_e25 * diffuse) * light.color.xyz); + uint _e23 = i_1; + Light light_1 = u_lights.inner[_e23]; + uint _e26 = i_1; + float _e30 = fetch_shadow(_e26, light_1.proj * in_1.world_position, t_shadow, sampler_shadow); + metal::float3 light_dir_1 = metal::normalize(light_1.pos.xyz - in_1.world_position.xyz); + float diffuse_1 = metal::max(0.0, metal::dot(normal_2, light_dir_1)); + metal::float3 _e40 = color_1; + color_1 = _e40 + ((_e30 * diffuse_1) * light_1.color.xyz); } - metal::float3 _e43 = color; - return fs_mainOutput { metal::float4(_e43, 1.0) }; + metal::float3 _e46 = color_1; + metal::float4 _e50 = u_entity.color; + return fs_main_without_storageOutput { metal::float4(_e46, 1.0) * _e50 }; } diff --git a/tests/out/spv/shadow.spvasm b/tests/out/spv/shadow.spvasm index 3d4f4119a4..a6be5de2dc 100644 --- a/tests/out/spv/shadow.spvasm +++ b/tests/out/spv/shadow.spvasm @@ -1,199 +1,444 @@ ; SPIR-V ; Version: 1.2 ; Generator: rspirv -; Bound: 125 +; Bound: 279 OpCapability Shader OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Fragment %79 "fs_main" %71 %74 %77 -OpExecutionMode %79 OriginUpperLeft +OpEntryPoint Vertex %86 "vs_bake" %81 %84 +OpEntryPoint Vertex %114 "vs_main" %106 %108 %110 %111 %113 +OpEntryPoint Fragment %165 "fs_main" %156 %159 %162 %164 +OpEntryPoint Fragment %229 "fs_main_without_storage" %222 %224 %226 %228 +OpExecutionMode %165 OriginUpperLeft +OpExecutionMode %229 OriginUpperLeft OpSource GLSL 450 -OpName %9 "c_max_lights" -OpMemberName %14 0 "num_lights" -OpName %14 "Globals" -OpMemberName %17 0 "proj" -OpMemberName %17 1 "pos" -OpMemberName %17 2 "color" -OpName %17 "Light" -OpMemberName %19 0 "data" -OpName %19 "Lights" -OpName %24 "c_ambient" -OpName %25 "u_globals" -OpName %28 "s_lights" -OpName %30 "t_shadow" -OpName %32 "sampler_shadow" -OpName %35 "light_id" -OpName %36 "homogeneous_coords" -OpName %37 "fetch_shadow" -OpName %66 "color" -OpName %68 "i" -OpName %71 "raw_normal" -OpName %74 "position" -OpName %79 "fs_main" -OpMemberDecorate %14 0 Offset 0 -OpMemberDecorate %17 0 Offset 0 -OpMemberDecorate %17 0 ColMajor -OpMemberDecorate %17 0 MatrixStride 16 -OpMemberDecorate %17 1 Offset 64 -OpMemberDecorate %17 2 Offset 80 -OpDecorate %18 ArrayStride 96 +OpName %11 "c_max_lights" +OpMemberName %18 0 "view_proj" +OpMemberName %18 1 "num_lights" +OpName %18 "Globals" +OpMemberName %19 0 "world" +OpMemberName %19 1 "color" +OpName %19 "Entity" +OpMemberName %22 0 "proj_position" +OpMemberName %22 1 "world_normal" +OpMemberName %22 2 "world_position" +OpName %22 "VertexOutput" +OpMemberName %24 0 "proj" +OpMemberName %24 1 "pos" +OpMemberName %24 2 "color" +OpName %24 "Light" +OpName %30 "c_ambient" +OpName %31 "u_globals" +OpName %34 "u_entity" +OpName %37 "s_lights" +OpName %40 "u_lights" +OpName %43 "t_shadow" +OpName %45 "sampler_shadow" +OpName %48 "light_id" +OpName %49 "homogeneous_coords" +OpName %50 "fetch_shadow" +OpName %81 "position" +OpName %86 "vs_bake" +OpName %103 "out" +OpName %106 "position" +OpName %108 "normal" +OpName %110 "proj_position" +OpName %111 "world_normal" +OpName %113 "world_position" +OpName %114 "vs_main" +OpName %151 "color" +OpName %152 "i" +OpName %156 "proj_position" +OpName %159 "world_normal" +OpName %162 "world_position" +OpName %165 "fs_main" +OpName %218 "color" +OpName %219 "i" +OpName %222 "proj_position" +OpName %224 "world_normal" +OpName %226 "world_position" +OpName %229 "fs_main_without_storage" +OpMemberDecorate %18 0 Offset 0 +OpMemberDecorate %18 0 ColMajor +OpMemberDecorate %18 0 MatrixStride 16 +OpMemberDecorate %18 1 Offset 64 OpMemberDecorate %19 0 Offset 0 -OpDecorate %25 DescriptorSet 0 -OpDecorate %25 Binding 0 -OpDecorate %26 Block -OpMemberDecorate %26 0 Offset 0 -OpDecorate %28 NonWritable -OpDecorate %28 DescriptorSet 0 -OpDecorate %28 Binding 1 -OpDecorate %19 Block -OpDecorate %30 DescriptorSet 0 -OpDecorate %30 Binding 2 -OpDecorate %32 DescriptorSet 0 -OpDecorate %32 Binding 3 -OpDecorate %71 Location 0 -OpDecorate %74 Location 1 -OpDecorate %77 Location 0 +OpMemberDecorate %19 0 ColMajor +OpMemberDecorate %19 0 MatrixStride 16 +OpMemberDecorate %19 1 Offset 64 +OpMemberDecorate %22 0 Offset 0 +OpMemberDecorate %22 1 Offset 16 +OpMemberDecorate %22 2 Offset 32 +OpMemberDecorate %24 0 Offset 0 +OpMemberDecorate %24 0 ColMajor +OpMemberDecorate %24 0 MatrixStride 16 +OpMemberDecorate %24 1 Offset 64 +OpMemberDecorate %24 2 Offset 80 +OpDecorate %25 ArrayStride 96 +OpDecorate %26 ArrayStride 96 +OpDecorate %31 DescriptorSet 0 +OpDecorate %31 Binding 0 +OpDecorate %32 Block +OpMemberDecorate %32 0 Offset 0 +OpDecorate %34 DescriptorSet 1 +OpDecorate %34 Binding 0 +OpDecorate %35 Block +OpMemberDecorate %35 0 Offset 0 +OpDecorate %37 NonWritable +OpDecorate %37 DescriptorSet 0 +OpDecorate %37 Binding 1 +OpDecorate %38 Block +OpMemberDecorate %38 0 Offset 0 +OpDecorate %40 DescriptorSet 0 +OpDecorate %40 Binding 1 +OpDecorate %41 Block +OpMemberDecorate %41 0 Offset 0 +OpDecorate %43 DescriptorSet 0 +OpDecorate %43 Binding 2 +OpDecorate %45 DescriptorSet 0 +OpDecorate %45 Binding 3 +OpDecorate %81 Location 0 +OpDecorate %81 Flat +OpDecorate %84 BuiltIn Position +OpDecorate %106 Location 0 +OpDecorate %106 Flat +OpDecorate %108 Location 1 +OpDecorate %108 Flat +OpDecorate %110 BuiltIn Position +OpDecorate %111 Location 0 +OpDecorate %113 Location 1 +OpDecorate %156 BuiltIn FragCoord +OpDecorate %159 Location 0 +OpDecorate %162 Location 1 +OpDecorate %164 Location 0 +OpDecorate %222 BuiltIn FragCoord +OpDecorate %224 Location 0 +OpDecorate %226 Location 1 +OpDecorate %228 Location 0 %2 = OpTypeVoid -%4 = OpTypeFloat 32 -%3 = OpConstant %4 0.0 -%5 = OpConstant %4 1.0 -%6 = OpConstant %4 0.5 -%7 = OpConstant %4 -0.5 -%8 = OpConstant %4 0.05 -%10 = OpTypeInt 32 0 -%9 = OpConstant %10 10 -%11 = OpConstant %10 0 -%12 = OpConstant %10 1 -%13 = OpTypeVector %10 4 -%14 = OpTypeStruct %13 -%16 = OpTypeVector %4 4 +%4 = OpTypeInt 32 1 +%3 = OpConstant %4 10 +%6 = OpTypeFloat 32 +%5 = OpConstant %6 0.0 +%7 = OpConstant %6 1.0 +%8 = OpConstant %6 0.5 +%9 = OpConstant %6 -0.5 +%10 = OpConstant %6 0.05 +%12 = OpTypeInt 32 0 +%11 = OpConstant %12 10 +%13 = OpConstant %12 0 +%14 = OpConstant %12 1 +%16 = OpTypeVector %6 4 %15 = OpTypeMatrix %16 4 -%17 = OpTypeStruct %15 %16 %16 -%18 = OpTypeRuntimeArray %17 -%19 = OpTypeStruct %18 -%20 = OpTypeImage %4 2D 1 1 0 1 Unknown -%21 = OpTypeSampler -%22 = OpTypeVector %4 2 -%23 = OpTypeVector %4 3 -%24 = OpConstantComposite %23 %8 %8 %8 -%26 = OpTypeStruct %14 -%27 = OpTypePointer Uniform %26 -%25 = OpVariable %27 Uniform -%29 = OpTypePointer StorageBuffer %19 -%28 = OpVariable %29 StorageBuffer -%31 = OpTypePointer UniformConstant %20 -%30 = OpVariable %31 UniformConstant -%33 = OpTypePointer UniformConstant %21 -%32 = OpVariable %33 UniformConstant -%38 = OpTypeFunction %4 %10 %16 -%41 = OpTypePointer Uniform %14 -%44 = OpTypeBool -%56 = OpTypeInt 32 1 -%61 = OpTypeSampledImage %20 -%67 = OpTypePointer Function %23 -%69 = OpTypePointer Function %10 -%72 = OpTypePointer Input %23 -%71 = OpVariable %72 Input -%75 = OpTypePointer Input %16 -%74 = OpVariable %75 Input -%78 = OpTypePointer Output %16 -%77 = OpVariable %78 Output -%80 = OpTypeFunction %2 -%91 = OpTypePointer Uniform %13 -%92 = OpTypePointer Uniform %10 -%99 = OpTypePointer StorageBuffer %18 -%101 = OpTypePointer StorageBuffer %17 -%37 = OpFunction %4 None %38 -%35 = OpFunctionParameter %10 -%36 = OpFunctionParameter %16 -%34 = OpLabel -%39 = OpLoad %20 %30 -%40 = OpLoad %21 %32 -OpBranch %42 -%42 = OpLabel -%43 = OpCompositeExtract %4 %36 3 -%45 = OpFOrdLessThanEqual %44 %43 %3 -OpSelectionMerge %46 None -OpBranchConditional %45 %47 %46 +%17 = OpTypeVector %12 4 +%18 = OpTypeStruct %15 %17 +%19 = OpTypeStruct %15 %16 +%20 = OpTypeVector %4 4 +%21 = OpTypeVector %6 3 +%22 = OpTypeStruct %16 %21 %16 +%23 = OpTypeMatrix %21 3 +%24 = OpTypeStruct %15 %16 %16 +%25 = OpTypeRuntimeArray %24 +%26 = OpTypeArray %24 %3 +%27 = OpTypeImage %6 2D 1 1 0 1 Unknown +%28 = OpTypeSampler +%29 = OpTypeVector %6 2 +%30 = OpConstantComposite %21 %10 %10 %10 +%32 = OpTypeStruct %18 +%33 = OpTypePointer Uniform %32 +%31 = OpVariable %33 Uniform +%35 = OpTypeStruct %19 +%36 = OpTypePointer Uniform %35 +%34 = OpVariable %36 Uniform +%38 = OpTypeStruct %25 +%39 = OpTypePointer StorageBuffer %38 +%37 = OpVariable %39 StorageBuffer +%41 = OpTypeStruct %26 +%42 = OpTypePointer Uniform %41 +%40 = OpVariable %42 Uniform +%44 = OpTypePointer UniformConstant %27 +%43 = OpVariable %44 UniformConstant +%46 = OpTypePointer UniformConstant %28 +%45 = OpVariable %46 UniformConstant +%51 = OpTypeFunction %6 %12 %16 +%54 = OpTypePointer Uniform %19 +%55 = OpTypePointer Uniform %18 +%56 = OpTypePointer Uniform %26 +%57 = OpTypePointer StorageBuffer %25 +%60 = OpTypeBool +%75 = OpTypeSampledImage %27 +%82 = OpTypePointer Input %20 +%81 = OpVariable %82 Input +%85 = OpTypePointer Output %16 +%84 = OpVariable %85 Output +%87 = OpTypeFunction %2 +%91 = OpTypePointer Uniform %15 +%99 = OpTypePointer Output %6 +%104 = OpTypePointer Function %22 +%106 = OpVariable %82 Input +%108 = OpVariable %82 Input +%110 = OpVariable %85 Output +%112 = OpTypePointer Output %21 +%111 = OpVariable %112 Output +%113 = OpVariable %85 Output +%124 = OpTypePointer Function %21 +%132 = OpTypeVector %4 3 +%137 = OpTypePointer Function %16 +%138 = OpConstant %12 2 +%153 = OpTypePointer Function %12 +%157 = OpTypePointer Input %16 +%156 = OpVariable %157 Input +%160 = OpTypePointer Input %21 +%159 = OpVariable %160 Input +%162 = OpVariable %157 Input +%164 = OpVariable %85 Output +%179 = OpTypePointer Uniform %17 +%180 = OpTypePointer Uniform %12 +%188 = OpTypePointer StorageBuffer %24 +%214 = OpTypePointer Uniform %16 +%222 = OpVariable %157 Input +%224 = OpVariable %160 Input +%226 = OpVariable %157 Input +%228 = OpVariable %85 Output +%250 = OpTypePointer Uniform %24 +%50 = OpFunction %6 None %51 +%48 = OpFunctionParameter %12 +%49 = OpFunctionParameter %16 %47 = OpLabel -OpReturnValue %5 -%46 = OpLabel -%48 = OpCompositeConstruct %22 %6 %7 -%49 = OpVectorShuffle %22 %36 %36 0 1 -%50 = OpFMul %22 %49 %48 -%51 = OpCompositeExtract %4 %36 3 -%52 = OpCompositeConstruct %22 %51 %51 -%53 = OpFDiv %22 %50 %52 -%54 = OpCompositeConstruct %22 %6 %6 -%55 = OpFAdd %22 %53 %54 -%57 = OpBitcast %56 %35 -%58 = OpCompositeExtract %4 %36 2 -%59 = OpCompositeExtract %4 %36 3 -%60 = OpFDiv %4 %58 %59 -%62 = OpConvertUToF %4 %57 -%63 = OpCompositeConstruct %23 %55 %62 -%64 = OpSampledImage %61 %39 %40 -%65 = OpImageSampleDrefExplicitLod %4 %64 %63 %60 Lod %3 -OpReturnValue %65 +%52 = OpLoad %27 %43 +%53 = OpLoad %28 %45 +OpBranch %58 +%58 = OpLabel +%59 = OpCompositeExtract %6 %49 3 +%61 = OpFOrdLessThanEqual %60 %59 %5 +OpSelectionMerge %62 None +OpBranchConditional %61 %63 %62 +%63 = OpLabel +OpReturnValue %7 +%62 = OpLabel +%64 = OpCompositeConstruct %29 %8 %9 +%65 = OpCompositeExtract %6 %49 3 +%66 = OpFDiv %6 %7 %65 +%67 = OpVectorShuffle %29 %49 %49 0 1 +%68 = OpFMul %29 %67 %64 +%69 = OpVectorTimesScalar %29 %68 %66 +%70 = OpCompositeConstruct %29 %8 %8 +%71 = OpFAdd %29 %69 %70 +%72 = OpBitcast %4 %48 +%73 = OpCompositeExtract %6 %49 2 +%74 = OpFMul %6 %73 %66 +%76 = OpConvertUToF %6 %72 +%77 = OpCompositeConstruct %21 %71 %76 +%78 = OpSampledImage %75 %52 %53 +%79 = OpImageSampleDrefExplicitLod %6 %78 %77 %74 Lod %5 +OpReturnValue %79 OpFunctionEnd -%79 = OpFunction %2 None %80 -%70 = OpLabel -%66 = OpVariable %67 Function %24 -%68 = OpVariable %69 Function %11 -%73 = OpLoad %23 %71 -%76 = OpLoad %16 %74 -%81 = OpAccessChain %41 %25 %11 -%82 = OpLoad %20 %30 -%83 = OpLoad %21 %32 -OpBranch %84 -%84 = OpLabel -%85 = OpExtInst %23 %1 Normalize %73 -OpBranch %86 -%86 = OpLabel -OpLoopMerge %87 %89 None -OpBranch %88 -%88 = OpLabel -%90 = OpLoad %10 %68 -%93 = OpAccessChain %92 %81 %11 %11 -%94 = OpLoad %10 %93 -%95 = OpExtInst %10 %1 UMin %94 %9 -%96 = OpUGreaterThanEqual %44 %90 %95 -OpSelectionMerge %97 None -OpBranchConditional %96 %98 %97 -%98 = OpLabel -OpBranch %87 -%97 = OpLabel -%100 = OpLoad %10 %68 -%102 = OpAccessChain %101 %28 %11 %100 -%103 = OpLoad %17 %102 -%104 = OpLoad %10 %68 -%105 = OpCompositeExtract %15 %103 0 -%106 = OpMatrixTimesVector %16 %105 %76 -%107 = OpFunctionCall %4 %37 %104 %106 -%108 = OpCompositeExtract %16 %103 1 -%109 = OpVectorShuffle %23 %108 %108 0 1 2 -%110 = OpVectorShuffle %23 %76 %76 0 1 2 -%111 = OpFSub %23 %109 %110 -%112 = OpExtInst %23 %1 Normalize %111 -%113 = OpDot %4 %85 %112 -%114 = OpExtInst %4 %1 FMax %3 %113 -%115 = OpLoad %23 %66 -%116 = OpFMul %4 %107 %114 -%117 = OpCompositeExtract %16 %103 2 -%118 = OpVectorShuffle %23 %117 %117 0 1 2 -%119 = OpVectorTimesScalar %23 %118 %116 -%120 = OpFAdd %23 %115 %119 -OpStore %66 %120 -OpBranch %89 -%89 = OpLabel -%121 = OpLoad %10 %68 -%122 = OpIAdd %10 %121 %12 -OpStore %68 %122 -OpBranch %86 -%87 = OpLabel -%123 = OpLoad %23 %66 -%124 = OpCompositeConstruct %16 %123 %5 -OpStore %77 %124 +%86 = OpFunction %2 None %87 +%80 = OpLabel +%83 = OpLoad %20 %81 +%88 = OpAccessChain %55 %31 %13 +%89 = OpAccessChain %54 %34 %13 +OpBranch %90 +%90 = OpLabel +%92 = OpAccessChain %91 %88 %13 +%93 = OpLoad %15 %92 +%94 = OpAccessChain %91 %89 %13 +%95 = OpLoad %15 %94 +%96 = OpMatrixTimesMatrix %15 %93 %95 +%97 = OpConvertSToF %16 %83 +%98 = OpMatrixTimesVector %16 %96 %97 +OpStore %84 %98 +%100 = OpAccessChain %99 %84 %14 +%101 = OpLoad %6 %100 +%102 = OpFNegate %6 %101 +OpStore %100 %102 +OpReturn +OpFunctionEnd +%114 = OpFunction %2 None %87 +%105 = OpLabel +%103 = OpVariable %104 Function +%107 = OpLoad %20 %106 +%109 = OpLoad %20 %108 +%115 = OpAccessChain %55 %31 %13 +%116 = OpAccessChain %54 %34 %13 +OpBranch %117 +%117 = OpLabel +%118 = OpAccessChain %91 %116 %13 +%119 = OpLoad %15 %118 +%120 = OpAccessChain %91 %116 %13 +%121 = OpLoad %15 %120 +%122 = OpConvertSToF %16 %107 +%123 = OpMatrixTimesVector %16 %121 %122 +%125 = OpCompositeExtract %16 %119 0 +%126 = OpVectorShuffle %21 %125 %125 0 1 2 +%127 = OpCompositeExtract %16 %119 1 +%128 = OpVectorShuffle %21 %127 %127 0 1 2 +%129 = OpCompositeExtract %16 %119 2 +%130 = OpVectorShuffle %21 %129 %129 0 1 2 +%131 = OpCompositeConstruct %23 %126 %128 %130 +%133 = OpVectorShuffle %132 %109 %109 0 1 2 +%134 = OpConvertSToF %21 %133 +%135 = OpMatrixTimesVector %21 %131 %134 +%136 = OpAccessChain %124 %103 %14 +OpStore %136 %135 +%139 = OpAccessChain %137 %103 %138 +OpStore %139 %123 +%140 = OpAccessChain %91 %115 %13 +%141 = OpLoad %15 %140 +%142 = OpMatrixTimesVector %16 %141 %123 +%143 = OpAccessChain %137 %103 %13 +OpStore %143 %142 +%144 = OpLoad %22 %103 +%145 = OpCompositeExtract %16 %144 0 +OpStore %110 %145 +%146 = OpAccessChain %99 %110 %14 +%147 = OpLoad %6 %146 +%148 = OpFNegate %6 %147 +OpStore %146 %148 +%149 = OpCompositeExtract %21 %144 1 +OpStore %111 %149 +%150 = OpCompositeExtract %16 %144 2 +OpStore %113 %150 +OpReturn +OpFunctionEnd +%165 = OpFunction %2 None %87 +%154 = OpLabel +%151 = OpVariable %124 Function %30 +%152 = OpVariable %153 Function %13 +%158 = OpLoad %16 %156 +%161 = OpLoad %21 %159 +%163 = OpLoad %16 %162 +%155 = OpCompositeConstruct %22 %158 %161 %163 +%166 = OpAccessChain %55 %31 %13 +%167 = OpAccessChain %54 %34 %13 +%168 = OpAccessChain %57 %37 %13 +%169 = OpLoad %27 %43 +%170 = OpLoad %28 %45 +OpBranch %171 +%171 = OpLabel +%172 = OpCompositeExtract %21 %155 1 +%173 = OpExtInst %21 %1 Normalize %172 +OpBranch %174 +%174 = OpLabel +OpLoopMerge %175 %177 None +OpBranch %176 +%176 = OpLabel +%178 = OpLoad %12 %152 +%181 = OpAccessChain %180 %166 %14 %13 +%182 = OpLoad %12 %181 +%183 = OpExtInst %12 %1 UMin %182 %11 +%184 = OpULessThan %60 %178 %183 +OpSelectionMerge %185 None +OpBranchConditional %184 %185 %186 +%186 = OpLabel +OpBranch %175 +%185 = OpLabel +%187 = OpLoad %12 %152 +%189 = OpAccessChain %188 %168 %187 +%190 = OpLoad %24 %189 +%191 = OpLoad %12 %152 +%192 = OpCompositeExtract %15 %190 0 +%193 = OpCompositeExtract %16 %155 2 +%194 = OpMatrixTimesVector %16 %192 %193 +%195 = OpFunctionCall %6 %50 %191 %194 +%196 = OpCompositeExtract %16 %190 1 +%197 = OpVectorShuffle %21 %196 %196 0 1 2 +%198 = OpCompositeExtract %16 %155 2 +%199 = OpVectorShuffle %21 %198 %198 0 1 2 +%200 = OpFSub %21 %197 %199 +%201 = OpExtInst %21 %1 Normalize %200 +%202 = OpDot %6 %173 %201 +%203 = OpExtInst %6 %1 FMax %5 %202 +%204 = OpLoad %21 %151 +%205 = OpFMul %6 %195 %203 +%206 = OpCompositeExtract %16 %190 2 +%207 = OpVectorShuffle %21 %206 %206 0 1 2 +%208 = OpVectorTimesScalar %21 %207 %205 +%209 = OpFAdd %21 %204 %208 +OpStore %151 %209 +OpBranch %177 +%177 = OpLabel +%210 = OpLoad %12 %152 +%211 = OpIAdd %12 %210 %14 +OpStore %152 %211 +OpBranch %174 +%175 = OpLabel +%212 = OpLoad %21 %151 +%213 = OpCompositeConstruct %16 %212 %7 +%215 = OpAccessChain %214 %167 %14 +%216 = OpLoad %16 %215 +%217 = OpFMul %16 %213 %216 +OpStore %164 %217 +OpReturn +OpFunctionEnd +%229 = OpFunction %2 None %87 +%220 = OpLabel +%218 = OpVariable %124 Function %30 +%219 = OpVariable %153 Function %13 +%223 = OpLoad %16 %222 +%225 = OpLoad %21 %224 +%227 = OpLoad %16 %226 +%221 = OpCompositeConstruct %22 %223 %225 %227 +%230 = OpAccessChain %55 %31 %13 +%231 = OpAccessChain %54 %34 %13 +%232 = OpAccessChain %56 %40 %13 +%233 = OpLoad %27 %43 +%234 = OpLoad %28 %45 +OpBranch %235 +%235 = OpLabel +%236 = OpCompositeExtract %21 %221 1 +%237 = OpExtInst %21 %1 Normalize %236 +OpBranch %238 +%238 = OpLabel +OpLoopMerge %239 %241 None +OpBranch %240 +%240 = OpLabel +%242 = OpLoad %12 %219 +%243 = OpAccessChain %180 %230 %14 %13 +%244 = OpLoad %12 %243 +%245 = OpExtInst %12 %1 UMin %244 %11 +%246 = OpULessThan %60 %242 %245 +OpSelectionMerge %247 None +OpBranchConditional %246 %247 %248 +%248 = OpLabel +OpBranch %239 +%247 = OpLabel +%249 = OpLoad %12 %219 +%251 = OpAccessChain %250 %232 %249 +%252 = OpLoad %24 %251 +%253 = OpLoad %12 %219 +%254 = OpCompositeExtract %15 %252 0 +%255 = OpCompositeExtract %16 %221 2 +%256 = OpMatrixTimesVector %16 %254 %255 +%257 = OpFunctionCall %6 %50 %253 %256 +%258 = OpCompositeExtract %16 %252 1 +%259 = OpVectorShuffle %21 %258 %258 0 1 2 +%260 = OpCompositeExtract %16 %221 2 +%261 = OpVectorShuffle %21 %260 %260 0 1 2 +%262 = OpFSub %21 %259 %261 +%263 = OpExtInst %21 %1 Normalize %262 +%264 = OpDot %6 %237 %263 +%265 = OpExtInst %6 %1 FMax %5 %264 +%266 = OpLoad %21 %218 +%267 = OpFMul %6 %257 %265 +%268 = OpCompositeExtract %16 %252 2 +%269 = OpVectorShuffle %21 %268 %268 0 1 2 +%270 = OpVectorTimesScalar %21 %269 %267 +%271 = OpFAdd %21 %266 %270 +OpStore %218 %271 +OpBranch %241 +%241 = OpLabel +%272 = OpLoad %12 %219 +%273 = OpIAdd %12 %272 %14 +OpStore %219 %273 +OpBranch %238 +%239 = OpLabel +%274 = OpLoad %21 %218 +%275 = OpCompositeConstruct %16 %274 %7 +%276 = OpAccessChain %214 %231 %14 +%277 = OpLoad %16 %276 +%278 = OpFMul %16 %275 %277 +OpStore %228 %278 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/tests/out/wgsl/shadow.wgsl b/tests/out/wgsl/shadow.wgsl index 393003ad26..a94295422f 100644 --- a/tests/out/wgsl/shadow.wgsl +++ b/tests/out/wgsl/shadow.wgsl @@ -1,24 +1,36 @@ struct Globals { + view_proj: mat4x4; num_lights: vec4; }; +struct Entity { + world: mat4x4; + color: vec4; +}; + +struct VertexOutput { + @builtin(position) proj_position: vec4; + @location(0) world_normal: vec3; + @location(1) world_position: vec4; +}; + struct Light { proj: mat4x4; pos: vec4; color: vec4; }; -struct Lights { - data: array; -}; - let c_ambient: vec3 = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806); let c_max_lights: u32 = 10u; @group(0) @binding(0) var u_globals: Globals; +@group(1) @binding(0) +var u_entity: Entity; +@group(0) @binding(1) +var s_lights: array; @group(0) @binding(1) -var s_lights: Lights; +var u_lights: array; @group(0) @binding(2) var t_shadow: texture_depth_2d_array; @group(0) @binding(3) @@ -29,36 +41,92 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4) -> f32 { return 1.0; } let flip_correction = vec2(0.5, -0.5); - let light_local = (((homogeneous_coords.xy * flip_correction) / vec2(homogeneous_coords.w)) + vec2(0.5, 0.5)); - let _e26 = textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), (homogeneous_coords.z / homogeneous_coords.w)); - return _e26; + let proj_correction = (1.0 / homogeneous_coords.w); + let light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + vec2(0.5, 0.5)); + let _e28 = textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), (homogeneous_coords.z * proj_correction)); + return _e28; +} + +@stage(vertex) +fn vs_bake(@location(0) position: vec4) -> @builtin(position) vec4 { + let _e4 = u_globals.view_proj; + let _e6 = u_entity.world; + return ((_e4 * _e6) * vec4(position)); +} + +@stage(vertex) +fn vs_main(@location(0) position_1: vec4, @location(1) normal: vec4) -> VertexOutput { + var out: VertexOutput; + + let w = u_entity.world; + let _e7 = u_entity.world; + let world_pos = (_e7 * vec4(position_1)); + out.world_normal = (mat3x3(w[0].xyz, w[1].xyz, w[2].xyz) * vec3(normal.xyz)); + out.world_position = world_pos; + let _e25 = u_globals.view_proj; + out.proj_position = (_e25 * world_pos); + let _e27 = out; + return _e27; } @stage(fragment) -fn fs_main(@location(0) raw_normal: vec3, @location(1) position: vec4) -> @location(0) vec4 { +fn fs_main(in: VertexOutput) -> @location(0) vec4 { var color: vec3 = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806); var i: u32 = 0u; - let normal = normalize(raw_normal); + let normal_1 = normalize(in.world_normal); + loop { + let _e14 = i; + let _e17 = u_globals.num_lights.x; + if (_e14 < min(_e17, c_max_lights)) { + } else { + break; + } + let _e23 = i; + let light = s_lights[_e23]; + let _e26 = i; + let _e30 = fetch_shadow(_e26, (light.proj * in.world_position)); + let light_dir = normalize((light.pos.xyz - in.world_position.xyz)); + let diffuse = max(0.0, dot(normal_1, light_dir)); + let _e40 = color; + color = (_e40 + ((_e30 * diffuse) * light.color.xyz)); + continuing { + let _e20 = i; + i = (_e20 + 1u); + } + } + let _e46 = color; + let _e50 = u_entity.color; + return (vec4(_e46, 1.0) * _e50); +} + +@stage(fragment) +fn fs_main_without_storage(in_1: VertexOutput) -> @location(0) vec4 { + var color_1: vec3 = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806); + var i_1: u32 = 0u; + + let normal_2 = normalize(in_1.world_normal); loop { - let _e12 = i; - let _e15 = u_globals.num_lights.x; - if (_e12 >= min(_e15, c_max_lights)) { + let _e14 = i_1; + let _e17 = u_globals.num_lights.x; + if (_e14 < min(_e17, c_max_lights)) { + } else { break; } - let _e19 = i; - let light = s_lights.data[_e19]; - let _e22 = i; - let _e25 = fetch_shadow(_e22, (light.proj * position)); - let light_dir = normalize((light.pos.xyz - position.xyz)); - let diffuse = max(0.0, dot(normal, light_dir)); - let _e34 = color; - color = (_e34 + ((_e25 * diffuse) * light.color.xyz)); + let _e23 = i_1; + let light_1 = u_lights[_e23]; + let _e26 = i_1; + let _e30 = fetch_shadow(_e26, (light_1.proj * in_1.world_position)); + let light_dir_1 = normalize((light_1.pos.xyz - in_1.world_position.xyz)); + let diffuse_1 = max(0.0, dot(normal_2, light_dir_1)); + let _e40 = color_1; + color_1 = (_e40 + ((_e30 * diffuse_1) * light_1.color.xyz)); continuing { - let _e40 = i; - i = (_e40 + 1u); + let _e20 = i_1; + i_1 = (_e20 + 1u); } } - let _e43 = color; - return vec4(_e43, 1.0); + let _e46 = color_1; + let _e50 = u_entity.color; + return (vec4(_e46, 1.0) * _e50); } From 3aa53ddf2bb27f25088f5dcccad613da5c1e0a7b Mon Sep 17 00:00:00 2001 From: hatoo Date: Fri, 11 Mar 2022 15:17:02 +0900 Subject: [PATCH 3/3] Remove `vs_bake` entry point from `tests/in/shadow.wgsl` This entry point isn't useful for testing. --- tests/in/shadow.wgsl | 2 + tests/out/glsl/shadow.vs_bake.Vertex.glsl | 38 -- tests/out/glsl/shadow.vs_main.Vertex.glsl | 4 +- tests/out/hlsl/shadow.hlsl | 11 +- tests/out/hlsl/shadow.hlsl.config | 2 +- tests/out/msl/shadow.msl | 40 +- tests/out/spv/shadow.spvasm | 559 ++++++++++------------ tests/out/wgsl/shadow.wgsl | 11 +- 8 files changed, 285 insertions(+), 382 deletions(-) delete mode 100644 tests/out/glsl/shadow.vs_bake.Vertex.glsl diff --git a/tests/in/shadow.wgsl b/tests/in/shadow.wgsl index 088608378c..0b64b2f8d0 100644 --- a/tests/in/shadow.wgsl +++ b/tests/in/shadow.wgsl @@ -16,10 +16,12 @@ struct Entity { @binding(0) var u_entity: Entity; +/* Not useful for testing @stage(vertex) fn vs_bake(@location(0) position: vec4) -> @builtin(position) vec4 { return u_globals.view_proj * u_entity.world * vec4(position); } +*/ struct VertexOutput { @builtin(position) proj_position: vec4; diff --git a/tests/out/glsl/shadow.vs_bake.Vertex.glsl b/tests/out/glsl/shadow.vs_bake.Vertex.glsl deleted file mode 100644 index 6f6812a259..0000000000 --- a/tests/out/glsl/shadow.vs_bake.Vertex.glsl +++ /dev/null @@ -1,38 +0,0 @@ -#version 310 es - -precision highp float; -precision highp int; - -struct Globals { - mat4x4 view_proj; - uvec4 num_lights; -}; -struct Entity { - mat4x4 world; - vec4 color; -}; -struct VertexOutput { - vec4 proj_position; - vec3 world_normal; - vec4 world_position; -}; -struct Light { - mat4x4 proj; - vec4 pos; - vec4 color; -}; -uniform Globals_block_0Vertex { Globals _group_0_binding_0_vs; }; - -uniform Entity_block_1Vertex { Entity _group_1_binding_0_vs; }; - -layout(location = 0) in ivec4 _p2vs_location0; - -void main() { - ivec4 position = _p2vs_location0; - mat4x4 _e4 = _group_0_binding_0_vs.view_proj; - mat4x4 _e6 = _group_1_binding_0_vs.world; - gl_Position = ((_e4 * _e6) * vec4(position)); - gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w); - return; -} - diff --git a/tests/out/glsl/shadow.vs_main.Vertex.glsl b/tests/out/glsl/shadow.vs_main.Vertex.glsl index a2e09ceec7..dce8b2f7d6 100644 --- a/tests/out/glsl/shadow.vs_main.Vertex.glsl +++ b/tests/out/glsl/shadow.vs_main.Vertex.glsl @@ -31,12 +31,12 @@ layout(location = 0) smooth out vec3 _vs2fs_location0; layout(location = 1) smooth out vec4 _vs2fs_location1; void main() { - ivec4 position_1 = _p2vs_location0; + ivec4 position = _p2vs_location0; ivec4 normal = _p2vs_location1; VertexOutput out_ = VertexOutput(vec4(0.0), vec3(0.0), vec4(0.0)); mat4x4 w = _group_1_binding_0_vs.world; mat4x4 _e7 = _group_1_binding_0_vs.world; - vec4 world_pos = (_e7 * vec4(position_1)); + vec4 world_pos = (_e7 * vec4(position)); out_.world_normal = (mat3x3(w[0].xyz, w[1].xyz, w[2].xyz) * vec3(normal.xyz)); out_.world_position = world_pos; mat4x4 _e25 = _group_0_binding_0_vs.view_proj; diff --git a/tests/out/hlsl/shadow.hlsl b/tests/out/hlsl/shadow.hlsl index 5b0ef63fa9..aca4edda3c 100644 --- a/tests/out/hlsl/shadow.hlsl +++ b/tests/out/hlsl/shadow.hlsl @@ -60,20 +60,13 @@ float fetch_shadow(uint light_id, float4 homogeneous_coords) return _expr28; } -float4 vs_bake(int4 position : LOC0) : SV_Position -{ - float4x4 _expr4 = u_globals.view_proj; - float4x4 _expr6 = u_entity.world; - return mul(float4(position), mul(_expr6, _expr4)); -} - -VertexOutput_vs_main vs_main(int4 position_1 : LOC0, int4 normal : LOC1) +VertexOutput_vs_main vs_main(int4 position : LOC0, int4 normal : LOC1) { VertexOutput out_ = (VertexOutput)0; float4x4 w = u_entity.world; float4x4 _expr7 = u_entity.world; - float4 world_pos = mul(float4(position_1), _expr7); + float4 world_pos = mul(float4(position), _expr7); out_.world_normal = mul(float3(normal.xyz), float3x3(w[0].xyz, w[1].xyz, w[2].xyz)); out_.world_position = world_pos; float4x4 _expr25 = u_globals.view_proj; diff --git a/tests/out/hlsl/shadow.hlsl.config b/tests/out/hlsl/shadow.hlsl.config index 2ed1c8fd71..40d109c83c 100644 --- a/tests/out/hlsl/shadow.hlsl.config +++ b/tests/out/hlsl/shadow.hlsl.config @@ -1,3 +1,3 @@ -vertex=(vs_bake:vs_5_1 vs_main:vs_5_1 ) +vertex=(vs_main:vs_5_1 ) fragment=(fs_main:ps_5_1 fs_main_without_storage:ps_5_1 ) compute=() diff --git a/tests/out/msl/shadow.msl b/tests/out/msl/shadow.msl index 26af57fd2c..5286b0bd07 100644 --- a/tests/out/msl/shadow.msl +++ b/tests/out/msl/shadow.msl @@ -49,26 +49,8 @@ float fetch_shadow( return _e28; } -struct vs_bakeInput { - metal::int4 position [[attribute(0)]]; -}; -struct vs_bakeOutput { - metal::float4 member [[position]]; -}; -vertex vs_bakeOutput vs_bake( - vs_bakeInput varyings [[stage_in]] -, constant Globals& u_globals [[user(fake0)]] -, constant Entity& u_entity [[user(fake0)]] -) { - const auto position = varyings.position; - metal::float4x4 _e4 = u_globals.view_proj; - metal::float4x4 _e6 = u_entity.world; - return vs_bakeOutput { (_e4 * _e6) * static_cast(position) }; -} - - struct vs_mainInput { - metal::int4 position_1 [[attribute(0)]]; + metal::int4 position [[attribute(0)]]; metal::int4 normal [[attribute(1)]]; }; struct vs_mainOutput { @@ -77,16 +59,16 @@ struct vs_mainOutput { metal::float4 world_position [[user(loc1), center_perspective]]; }; vertex vs_mainOutput vs_main( - vs_mainInput varyings_1 [[stage_in]] + vs_mainInput varyings [[stage_in]] , constant Globals& u_globals [[user(fake0)]] , constant Entity& u_entity [[user(fake0)]] ) { - const auto position_1 = varyings_1.position_1; - const auto normal = varyings_1.normal; + const auto position = varyings.position; + const auto normal = varyings.normal; VertexOutput out; metal::float4x4 w = u_entity.world; metal::float4x4 _e7 = u_entity.world; - metal::float4 world_pos = _e7 * static_cast(position_1); + metal::float4 world_pos = _e7 * static_cast(position); out.world_normal = metal::float3x3(w[0].xyz, w[1].xyz, w[2].xyz) * static_cast(normal.xyz); out.world_position = world_pos; metal::float4x4 _e25 = u_globals.view_proj; @@ -102,10 +84,10 @@ struct fs_mainInput { metal::float4 world_position [[user(loc1), center_perspective]]; }; struct fs_mainOutput { - metal::float4 member_2 [[color(0)]]; + metal::float4 member_1 [[color(0)]]; }; fragment fs_mainOutput fs_main( - fs_mainInput varyings_2 [[stage_in]] + fs_mainInput varyings_1 [[stage_in]] , metal::float4 proj_position [[position]] , constant Globals& u_globals [[user(fake0)]] , constant Entity& u_entity [[user(fake0)]] @@ -114,7 +96,7 @@ fragment fs_mainOutput fs_main( , metal::sampler sampler_shadow [[user(fake0)]] , constant _mslBufferSizes& _buffer_sizes [[user(fake0)]] ) { - const VertexOutput in = { proj_position, varyings_2.world_normal, varyings_2.world_position }; + const VertexOutput in = { proj_position, varyings_1.world_normal, varyings_1.world_position }; metal::float3 color = c_ambient; uint i = 0u; metal::float3 normal_1 = metal::normalize(in.world_normal); @@ -151,10 +133,10 @@ struct fs_main_without_storageInput { metal::float4 world_position [[user(loc1), center_perspective]]; }; struct fs_main_without_storageOutput { - metal::float4 member_3 [[color(0)]]; + metal::float4 member_2 [[color(0)]]; }; fragment fs_main_without_storageOutput fs_main_without_storage( - fs_main_without_storageInput varyings_3 [[stage_in]] + fs_main_without_storageInput varyings_2 [[stage_in]] , metal::float4 proj_position_1 [[position]] , constant Globals& u_globals [[user(fake0)]] , constant Entity& u_entity [[user(fake0)]] @@ -162,7 +144,7 @@ fragment fs_main_without_storageOutput fs_main_without_storage( , metal::depth2d_array t_shadow [[user(fake0)]] , metal::sampler sampler_shadow [[user(fake0)]] ) { - const VertexOutput in_1 = { proj_position_1, varyings_3.world_normal, varyings_3.world_position }; + const VertexOutput in_1 = { proj_position_1, varyings_2.world_normal, varyings_2.world_position }; metal::float3 color_1 = c_ambient; uint i_1 = 0u; metal::float3 normal_2 = metal::normalize(in_1.world_normal); diff --git a/tests/out/spv/shadow.spvasm b/tests/out/spv/shadow.spvasm index a6be5de2dc..aeb85c96b5 100644 --- a/tests/out/spv/shadow.spvasm +++ b/tests/out/spv/shadow.spvasm @@ -1,17 +1,16 @@ ; SPIR-V ; Version: 1.2 ; Generator: rspirv -; Bound: 279 +; Bound: 261 OpCapability Shader OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Vertex %86 "vs_bake" %81 %84 -OpEntryPoint Vertex %114 "vs_main" %106 %108 %110 %111 %113 -OpEntryPoint Fragment %165 "fs_main" %156 %159 %162 %164 -OpEntryPoint Fragment %229 "fs_main_without_storage" %222 %224 %226 %228 -OpExecutionMode %165 OriginUpperLeft -OpExecutionMode %229 OriginUpperLeft +OpEntryPoint Vertex %93 "vs_main" %83 %86 %88 %90 %92 +OpEntryPoint Fragment %147 "fs_main" %138 %141 %144 %146 +OpEntryPoint Fragment %211 "fs_main_without_storage" %204 %206 %208 %210 +OpExecutionMode %147 OriginUpperLeft +OpExecutionMode %211 OriginUpperLeft OpSource GLSL 450 OpName %11 "c_max_lights" OpMemberName %18 0 "view_proj" @@ -20,10 +19,10 @@ OpName %18 "Globals" OpMemberName %19 0 "world" OpMemberName %19 1 "color" OpName %19 "Entity" -OpMemberName %22 0 "proj_position" -OpMemberName %22 1 "world_normal" -OpMemberName %22 2 "world_position" -OpName %22 "VertexOutput" +OpMemberName %21 0 "proj_position" +OpMemberName %21 1 "world_normal" +OpMemberName %21 2 "world_position" +OpName %21 "VertexOutput" OpMemberName %24 0 "proj" OpMemberName %24 1 "pos" OpMemberName %24 2 "color" @@ -38,27 +37,25 @@ OpName %45 "sampler_shadow" OpName %48 "light_id" OpName %49 "homogeneous_coords" OpName %50 "fetch_shadow" -OpName %81 "position" -OpName %86 "vs_bake" -OpName %103 "out" -OpName %106 "position" -OpName %108 "normal" -OpName %110 "proj_position" -OpName %111 "world_normal" -OpName %113 "world_position" -OpName %114 "vs_main" -OpName %151 "color" -OpName %152 "i" -OpName %156 "proj_position" -OpName %159 "world_normal" -OpName %162 "world_position" -OpName %165 "fs_main" -OpName %218 "color" -OpName %219 "i" -OpName %222 "proj_position" -OpName %224 "world_normal" -OpName %226 "world_position" -OpName %229 "fs_main_without_storage" +OpName %80 "out" +OpName %83 "position" +OpName %86 "normal" +OpName %88 "proj_position" +OpName %90 "world_normal" +OpName %92 "world_position" +OpName %93 "vs_main" +OpName %133 "color" +OpName %134 "i" +OpName %138 "proj_position" +OpName %141 "world_normal" +OpName %144 "world_position" +OpName %147 "fs_main" +OpName %200 "color" +OpName %201 "i" +OpName %204 "proj_position" +OpName %206 "world_normal" +OpName %208 "world_position" +OpName %211 "fs_main_without_storage" OpMemberDecorate %18 0 Offset 0 OpMemberDecorate %18 0 ColMajor OpMemberDecorate %18 0 MatrixStride 16 @@ -67,9 +64,9 @@ OpMemberDecorate %19 0 Offset 0 OpMemberDecorate %19 0 ColMajor OpMemberDecorate %19 0 MatrixStride 16 OpMemberDecorate %19 1 Offset 64 -OpMemberDecorate %22 0 Offset 0 -OpMemberDecorate %22 1 Offset 16 -OpMemberDecorate %22 2 Offset 32 +OpMemberDecorate %21 0 Offset 0 +OpMemberDecorate %21 1 Offset 16 +OpMemberDecorate %21 2 Offset 32 OpMemberDecorate %24 0 Offset 0 OpMemberDecorate %24 0 ColMajor OpMemberDecorate %24 0 MatrixStride 16 @@ -98,24 +95,21 @@ OpDecorate %43 DescriptorSet 0 OpDecorate %43 Binding 2 OpDecorate %45 DescriptorSet 0 OpDecorate %45 Binding 3 -OpDecorate %81 Location 0 -OpDecorate %81 Flat -OpDecorate %84 BuiltIn Position -OpDecorate %106 Location 0 -OpDecorate %106 Flat -OpDecorate %108 Location 1 -OpDecorate %108 Flat -OpDecorate %110 BuiltIn Position -OpDecorate %111 Location 0 -OpDecorate %113 Location 1 -OpDecorate %156 BuiltIn FragCoord -OpDecorate %159 Location 0 -OpDecorate %162 Location 1 -OpDecorate %164 Location 0 -OpDecorate %222 BuiltIn FragCoord -OpDecorate %224 Location 0 -OpDecorate %226 Location 1 -OpDecorate %228 Location 0 +OpDecorate %83 Location 0 +OpDecorate %83 Flat +OpDecorate %86 Location 1 +OpDecorate %86 Flat +OpDecorate %88 BuiltIn Position +OpDecorate %90 Location 0 +OpDecorate %92 Location 1 +OpDecorate %138 BuiltIn FragCoord +OpDecorate %141 Location 0 +OpDecorate %144 Location 1 +OpDecorate %146 Location 0 +OpDecorate %204 BuiltIn FragCoord +OpDecorate %206 Location 0 +OpDecorate %208 Location 1 +OpDecorate %210 Location 0 %2 = OpTypeVoid %4 = OpTypeInt 32 1 %3 = OpConstant %4 10 @@ -134,17 +128,17 @@ OpDecorate %228 Location 0 %17 = OpTypeVector %12 4 %18 = OpTypeStruct %15 %17 %19 = OpTypeStruct %15 %16 -%20 = OpTypeVector %4 4 -%21 = OpTypeVector %6 3 -%22 = OpTypeStruct %16 %21 %16 -%23 = OpTypeMatrix %21 3 +%20 = OpTypeVector %6 3 +%21 = OpTypeStruct %16 %20 %16 +%22 = OpTypeVector %4 4 +%23 = OpTypeMatrix %20 3 %24 = OpTypeStruct %15 %16 %16 %25 = OpTypeRuntimeArray %24 %26 = OpTypeArray %24 %3 %27 = OpTypeImage %6 2D 1 1 0 1 Unknown %28 = OpTypeSampler %29 = OpTypeVector %6 2 -%30 = OpConstantComposite %21 %10 %10 %10 +%30 = OpConstantComposite %20 %10 %10 %10 %32 = OpTypeStruct %18 %33 = OpTypePointer Uniform %32 %31 = OpVariable %33 Uniform @@ -168,40 +162,38 @@ OpDecorate %228 Location 0 %57 = OpTypePointer StorageBuffer %25 %60 = OpTypeBool %75 = OpTypeSampledImage %27 -%82 = OpTypePointer Input %20 -%81 = OpVariable %82 Input -%85 = OpTypePointer Output %16 -%84 = OpVariable %85 Output -%87 = OpTypeFunction %2 -%91 = OpTypePointer Uniform %15 -%99 = OpTypePointer Output %6 -%104 = OpTypePointer Function %22 -%106 = OpVariable %82 Input -%108 = OpVariable %82 Input -%110 = OpVariable %85 Output -%112 = OpTypePointer Output %21 -%111 = OpVariable %112 Output -%113 = OpVariable %85 Output -%124 = OpTypePointer Function %21 -%132 = OpTypeVector %4 3 -%137 = OpTypePointer Function %16 -%138 = OpConstant %12 2 -%153 = OpTypePointer Function %12 -%157 = OpTypePointer Input %16 -%156 = OpVariable %157 Input -%160 = OpTypePointer Input %21 -%159 = OpVariable %160 Input -%162 = OpVariable %157 Input -%164 = OpVariable %85 Output -%179 = OpTypePointer Uniform %17 -%180 = OpTypePointer Uniform %12 -%188 = OpTypePointer StorageBuffer %24 -%214 = OpTypePointer Uniform %16 -%222 = OpVariable %157 Input -%224 = OpVariable %160 Input -%226 = OpVariable %157 Input -%228 = OpVariable %85 Output -%250 = OpTypePointer Uniform %24 +%81 = OpTypePointer Function %21 +%84 = OpTypePointer Input %22 +%83 = OpVariable %84 Input +%86 = OpVariable %84 Input +%89 = OpTypePointer Output %16 +%88 = OpVariable %89 Output +%91 = OpTypePointer Output %20 +%90 = OpVariable %91 Output +%92 = OpVariable %89 Output +%94 = OpTypeFunction %2 +%98 = OpTypePointer Uniform %15 +%105 = OpTypePointer Function %20 +%113 = OpTypeVector %4 3 +%118 = OpTypePointer Function %16 +%119 = OpConstant %12 2 +%127 = OpTypePointer Output %6 +%135 = OpTypePointer Function %12 +%139 = OpTypePointer Input %16 +%138 = OpVariable %139 Input +%142 = OpTypePointer Input %20 +%141 = OpVariable %142 Input +%144 = OpVariable %139 Input +%146 = OpVariable %89 Output +%161 = OpTypePointer Uniform %17 +%162 = OpTypePointer Uniform %12 +%170 = OpTypePointer StorageBuffer %24 +%196 = OpTypePointer Uniform %16 +%204 = OpVariable %139 Input +%206 = OpVariable %142 Input +%208 = OpVariable %139 Input +%210 = OpVariable %89 Output +%232 = OpTypePointer Uniform %24 %50 = OpFunction %6 None %51 %48 = OpFunctionParameter %12 %49 = OpFunctionParameter %16 @@ -229,216 +221,195 @@ OpReturnValue %7 %73 = OpCompositeExtract %6 %49 2 %74 = OpFMul %6 %73 %66 %76 = OpConvertUToF %6 %72 -%77 = OpCompositeConstruct %21 %71 %76 +%77 = OpCompositeConstruct %20 %71 %76 %78 = OpSampledImage %75 %52 %53 %79 = OpImageSampleDrefExplicitLod %6 %78 %77 %74 Lod %5 OpReturnValue %79 OpFunctionEnd -%86 = OpFunction %2 None %87 -%80 = OpLabel -%83 = OpLoad %20 %81 -%88 = OpAccessChain %55 %31 %13 -%89 = OpAccessChain %54 %34 %13 -OpBranch %90 -%90 = OpLabel -%92 = OpAccessChain %91 %88 %13 -%93 = OpLoad %15 %92 -%94 = OpAccessChain %91 %89 %13 -%95 = OpLoad %15 %94 -%96 = OpMatrixTimesMatrix %15 %93 %95 -%97 = OpConvertSToF %16 %83 -%98 = OpMatrixTimesVector %16 %96 %97 -OpStore %84 %98 -%100 = OpAccessChain %99 %84 %14 -%101 = OpLoad %6 %100 -%102 = OpFNegate %6 %101 -OpStore %100 %102 +%93 = OpFunction %2 None %94 +%82 = OpLabel +%80 = OpVariable %81 Function +%85 = OpLoad %22 %83 +%87 = OpLoad %22 %86 +%95 = OpAccessChain %55 %31 %13 +%96 = OpAccessChain %54 %34 %13 +OpBranch %97 +%97 = OpLabel +%99 = OpAccessChain %98 %96 %13 +%100 = OpLoad %15 %99 +%101 = OpAccessChain %98 %96 %13 +%102 = OpLoad %15 %101 +%103 = OpConvertSToF %16 %85 +%104 = OpMatrixTimesVector %16 %102 %103 +%106 = OpCompositeExtract %16 %100 0 +%107 = OpVectorShuffle %20 %106 %106 0 1 2 +%108 = OpCompositeExtract %16 %100 1 +%109 = OpVectorShuffle %20 %108 %108 0 1 2 +%110 = OpCompositeExtract %16 %100 2 +%111 = OpVectorShuffle %20 %110 %110 0 1 2 +%112 = OpCompositeConstruct %23 %107 %109 %111 +%114 = OpVectorShuffle %113 %87 %87 0 1 2 +%115 = OpConvertSToF %20 %114 +%116 = OpMatrixTimesVector %20 %112 %115 +%117 = OpAccessChain %105 %80 %14 +OpStore %117 %116 +%120 = OpAccessChain %118 %80 %119 +OpStore %120 %104 +%121 = OpAccessChain %98 %95 %13 +%122 = OpLoad %15 %121 +%123 = OpMatrixTimesVector %16 %122 %104 +%124 = OpAccessChain %118 %80 %13 +OpStore %124 %123 +%125 = OpLoad %21 %80 +%126 = OpCompositeExtract %16 %125 0 +OpStore %88 %126 +%128 = OpAccessChain %127 %88 %14 +%129 = OpLoad %6 %128 +%130 = OpFNegate %6 %129 +OpStore %128 %130 +%131 = OpCompositeExtract %20 %125 1 +OpStore %90 %131 +%132 = OpCompositeExtract %16 %125 2 +OpStore %92 %132 OpReturn OpFunctionEnd -%114 = OpFunction %2 None %87 -%105 = OpLabel -%103 = OpVariable %104 Function -%107 = OpLoad %20 %106 -%109 = OpLoad %20 %108 -%115 = OpAccessChain %55 %31 %13 -%116 = OpAccessChain %54 %34 %13 -OpBranch %117 -%117 = OpLabel -%118 = OpAccessChain %91 %116 %13 -%119 = OpLoad %15 %118 -%120 = OpAccessChain %91 %116 %13 -%121 = OpLoad %15 %120 -%122 = OpConvertSToF %16 %107 -%123 = OpMatrixTimesVector %16 %121 %122 -%125 = OpCompositeExtract %16 %119 0 -%126 = OpVectorShuffle %21 %125 %125 0 1 2 -%127 = OpCompositeExtract %16 %119 1 -%128 = OpVectorShuffle %21 %127 %127 0 1 2 -%129 = OpCompositeExtract %16 %119 2 -%130 = OpVectorShuffle %21 %129 %129 0 1 2 -%131 = OpCompositeConstruct %23 %126 %128 %130 -%133 = OpVectorShuffle %132 %109 %109 0 1 2 -%134 = OpConvertSToF %21 %133 -%135 = OpMatrixTimesVector %21 %131 %134 -%136 = OpAccessChain %124 %103 %14 -OpStore %136 %135 -%139 = OpAccessChain %137 %103 %138 -OpStore %139 %123 -%140 = OpAccessChain %91 %115 %13 -%141 = OpLoad %15 %140 -%142 = OpMatrixTimesVector %16 %141 %123 -%143 = OpAccessChain %137 %103 %13 -OpStore %143 %142 -%144 = OpLoad %22 %103 -%145 = OpCompositeExtract %16 %144 0 -OpStore %110 %145 -%146 = OpAccessChain %99 %110 %14 -%147 = OpLoad %6 %146 -%148 = OpFNegate %6 %147 -OpStore %146 %148 -%149 = OpCompositeExtract %21 %144 1 -OpStore %111 %149 -%150 = OpCompositeExtract %16 %144 2 -OpStore %113 %150 +%147 = OpFunction %2 None %94 +%136 = OpLabel +%133 = OpVariable %105 Function %30 +%134 = OpVariable %135 Function %13 +%140 = OpLoad %16 %138 +%143 = OpLoad %20 %141 +%145 = OpLoad %16 %144 +%137 = OpCompositeConstruct %21 %140 %143 %145 +%148 = OpAccessChain %55 %31 %13 +%149 = OpAccessChain %54 %34 %13 +%150 = OpAccessChain %57 %37 %13 +%151 = OpLoad %27 %43 +%152 = OpLoad %28 %45 +OpBranch %153 +%153 = OpLabel +%154 = OpCompositeExtract %20 %137 1 +%155 = OpExtInst %20 %1 Normalize %154 +OpBranch %156 +%156 = OpLabel +OpLoopMerge %157 %159 None +OpBranch %158 +%158 = OpLabel +%160 = OpLoad %12 %134 +%163 = OpAccessChain %162 %148 %14 %13 +%164 = OpLoad %12 %163 +%165 = OpExtInst %12 %1 UMin %164 %11 +%166 = OpULessThan %60 %160 %165 +OpSelectionMerge %167 None +OpBranchConditional %166 %167 %168 +%168 = OpLabel +OpBranch %157 +%167 = OpLabel +%169 = OpLoad %12 %134 +%171 = OpAccessChain %170 %150 %169 +%172 = OpLoad %24 %171 +%173 = OpLoad %12 %134 +%174 = OpCompositeExtract %15 %172 0 +%175 = OpCompositeExtract %16 %137 2 +%176 = OpMatrixTimesVector %16 %174 %175 +%177 = OpFunctionCall %6 %50 %173 %176 +%178 = OpCompositeExtract %16 %172 1 +%179 = OpVectorShuffle %20 %178 %178 0 1 2 +%180 = OpCompositeExtract %16 %137 2 +%181 = OpVectorShuffle %20 %180 %180 0 1 2 +%182 = OpFSub %20 %179 %181 +%183 = OpExtInst %20 %1 Normalize %182 +%184 = OpDot %6 %155 %183 +%185 = OpExtInst %6 %1 FMax %5 %184 +%186 = OpLoad %20 %133 +%187 = OpFMul %6 %177 %185 +%188 = OpCompositeExtract %16 %172 2 +%189 = OpVectorShuffle %20 %188 %188 0 1 2 +%190 = OpVectorTimesScalar %20 %189 %187 +%191 = OpFAdd %20 %186 %190 +OpStore %133 %191 +OpBranch %159 +%159 = OpLabel +%192 = OpLoad %12 %134 +%193 = OpIAdd %12 %192 %14 +OpStore %134 %193 +OpBranch %156 +%157 = OpLabel +%194 = OpLoad %20 %133 +%195 = OpCompositeConstruct %16 %194 %7 +%197 = OpAccessChain %196 %149 %14 +%198 = OpLoad %16 %197 +%199 = OpFMul %16 %195 %198 +OpStore %146 %199 OpReturn OpFunctionEnd -%165 = OpFunction %2 None %87 -%154 = OpLabel -%151 = OpVariable %124 Function %30 -%152 = OpVariable %153 Function %13 -%158 = OpLoad %16 %156 -%161 = OpLoad %21 %159 -%163 = OpLoad %16 %162 -%155 = OpCompositeConstruct %22 %158 %161 %163 -%166 = OpAccessChain %55 %31 %13 -%167 = OpAccessChain %54 %34 %13 -%168 = OpAccessChain %57 %37 %13 -%169 = OpLoad %27 %43 -%170 = OpLoad %28 %45 -OpBranch %171 -%171 = OpLabel -%172 = OpCompositeExtract %21 %155 1 -%173 = OpExtInst %21 %1 Normalize %172 -OpBranch %174 -%174 = OpLabel -OpLoopMerge %175 %177 None -OpBranch %176 -%176 = OpLabel -%178 = OpLoad %12 %152 -%181 = OpAccessChain %180 %166 %14 %13 -%182 = OpLoad %12 %181 -%183 = OpExtInst %12 %1 UMin %182 %11 -%184 = OpULessThan %60 %178 %183 -OpSelectionMerge %185 None -OpBranchConditional %184 %185 %186 -%186 = OpLabel -OpBranch %175 -%185 = OpLabel -%187 = OpLoad %12 %152 -%189 = OpAccessChain %188 %168 %187 -%190 = OpLoad %24 %189 -%191 = OpLoad %12 %152 -%192 = OpCompositeExtract %15 %190 0 -%193 = OpCompositeExtract %16 %155 2 -%194 = OpMatrixTimesVector %16 %192 %193 -%195 = OpFunctionCall %6 %50 %191 %194 -%196 = OpCompositeExtract %16 %190 1 -%197 = OpVectorShuffle %21 %196 %196 0 1 2 -%198 = OpCompositeExtract %16 %155 2 -%199 = OpVectorShuffle %21 %198 %198 0 1 2 -%200 = OpFSub %21 %197 %199 -%201 = OpExtInst %21 %1 Normalize %200 -%202 = OpDot %6 %173 %201 -%203 = OpExtInst %6 %1 FMax %5 %202 -%204 = OpLoad %21 %151 -%205 = OpFMul %6 %195 %203 -%206 = OpCompositeExtract %16 %190 2 -%207 = OpVectorShuffle %21 %206 %206 0 1 2 -%208 = OpVectorTimesScalar %21 %207 %205 -%209 = OpFAdd %21 %204 %208 -OpStore %151 %209 -OpBranch %177 -%177 = OpLabel -%210 = OpLoad %12 %152 -%211 = OpIAdd %12 %210 %14 -OpStore %152 %211 -OpBranch %174 -%175 = OpLabel -%212 = OpLoad %21 %151 -%213 = OpCompositeConstruct %16 %212 %7 -%215 = OpAccessChain %214 %167 %14 -%216 = OpLoad %16 %215 -%217 = OpFMul %16 %213 %216 -OpStore %164 %217 -OpReturn -OpFunctionEnd -%229 = OpFunction %2 None %87 +%211 = OpFunction %2 None %94 +%202 = OpLabel +%200 = OpVariable %105 Function %30 +%201 = OpVariable %135 Function %13 +%205 = OpLoad %16 %204 +%207 = OpLoad %20 %206 +%209 = OpLoad %16 %208 +%203 = OpCompositeConstruct %21 %205 %207 %209 +%212 = OpAccessChain %55 %31 %13 +%213 = OpAccessChain %54 %34 %13 +%214 = OpAccessChain %56 %40 %13 +%215 = OpLoad %27 %43 +%216 = OpLoad %28 %45 +OpBranch %217 +%217 = OpLabel +%218 = OpCompositeExtract %20 %203 1 +%219 = OpExtInst %20 %1 Normalize %218 +OpBranch %220 %220 = OpLabel -%218 = OpVariable %124 Function %30 -%219 = OpVariable %153 Function %13 -%223 = OpLoad %16 %222 -%225 = OpLoad %21 %224 -%227 = OpLoad %16 %226 -%221 = OpCompositeConstruct %22 %223 %225 %227 -%230 = OpAccessChain %55 %31 %13 -%231 = OpAccessChain %54 %34 %13 -%232 = OpAccessChain %56 %40 %13 -%233 = OpLoad %27 %43 -%234 = OpLoad %28 %45 -OpBranch %235 -%235 = OpLabel -%236 = OpCompositeExtract %21 %221 1 -%237 = OpExtInst %21 %1 Normalize %236 -OpBranch %238 -%238 = OpLabel -OpLoopMerge %239 %241 None -OpBranch %240 -%240 = OpLabel -%242 = OpLoad %12 %219 -%243 = OpAccessChain %180 %230 %14 %13 -%244 = OpLoad %12 %243 -%245 = OpExtInst %12 %1 UMin %244 %11 -%246 = OpULessThan %60 %242 %245 -OpSelectionMerge %247 None -OpBranchConditional %246 %247 %248 -%248 = OpLabel -OpBranch %239 -%247 = OpLabel -%249 = OpLoad %12 %219 -%251 = OpAccessChain %250 %232 %249 -%252 = OpLoad %24 %251 -%253 = OpLoad %12 %219 -%254 = OpCompositeExtract %15 %252 0 -%255 = OpCompositeExtract %16 %221 2 -%256 = OpMatrixTimesVector %16 %254 %255 -%257 = OpFunctionCall %6 %50 %253 %256 -%258 = OpCompositeExtract %16 %252 1 -%259 = OpVectorShuffle %21 %258 %258 0 1 2 -%260 = OpCompositeExtract %16 %221 2 -%261 = OpVectorShuffle %21 %260 %260 0 1 2 -%262 = OpFSub %21 %259 %261 -%263 = OpExtInst %21 %1 Normalize %262 -%264 = OpDot %6 %237 %263 -%265 = OpExtInst %6 %1 FMax %5 %264 -%266 = OpLoad %21 %218 -%267 = OpFMul %6 %257 %265 -%268 = OpCompositeExtract %16 %252 2 -%269 = OpVectorShuffle %21 %268 %268 0 1 2 -%270 = OpVectorTimesScalar %21 %269 %267 -%271 = OpFAdd %21 %266 %270 -OpStore %218 %271 -OpBranch %241 -%241 = OpLabel -%272 = OpLoad %12 %219 -%273 = OpIAdd %12 %272 %14 -OpStore %219 %273 -OpBranch %238 -%239 = OpLabel -%274 = OpLoad %21 %218 -%275 = OpCompositeConstruct %16 %274 %7 -%276 = OpAccessChain %214 %231 %14 -%277 = OpLoad %16 %276 -%278 = OpFMul %16 %275 %277 -OpStore %228 %278 +OpLoopMerge %221 %223 None +OpBranch %222 +%222 = OpLabel +%224 = OpLoad %12 %201 +%225 = OpAccessChain %162 %212 %14 %13 +%226 = OpLoad %12 %225 +%227 = OpExtInst %12 %1 UMin %226 %11 +%228 = OpULessThan %60 %224 %227 +OpSelectionMerge %229 None +OpBranchConditional %228 %229 %230 +%230 = OpLabel +OpBranch %221 +%229 = OpLabel +%231 = OpLoad %12 %201 +%233 = OpAccessChain %232 %214 %231 +%234 = OpLoad %24 %233 +%235 = OpLoad %12 %201 +%236 = OpCompositeExtract %15 %234 0 +%237 = OpCompositeExtract %16 %203 2 +%238 = OpMatrixTimesVector %16 %236 %237 +%239 = OpFunctionCall %6 %50 %235 %238 +%240 = OpCompositeExtract %16 %234 1 +%241 = OpVectorShuffle %20 %240 %240 0 1 2 +%242 = OpCompositeExtract %16 %203 2 +%243 = OpVectorShuffle %20 %242 %242 0 1 2 +%244 = OpFSub %20 %241 %243 +%245 = OpExtInst %20 %1 Normalize %244 +%246 = OpDot %6 %219 %245 +%247 = OpExtInst %6 %1 FMax %5 %246 +%248 = OpLoad %20 %200 +%249 = OpFMul %6 %239 %247 +%250 = OpCompositeExtract %16 %234 2 +%251 = OpVectorShuffle %20 %250 %250 0 1 2 +%252 = OpVectorTimesScalar %20 %251 %249 +%253 = OpFAdd %20 %248 %252 +OpStore %200 %253 +OpBranch %223 +%223 = OpLabel +%254 = OpLoad %12 %201 +%255 = OpIAdd %12 %254 %14 +OpStore %201 %255 +OpBranch %220 +%221 = OpLabel +%256 = OpLoad %20 %200 +%257 = OpCompositeConstruct %16 %256 %7 +%258 = OpAccessChain %196 %213 %14 +%259 = OpLoad %16 %258 +%260 = OpFMul %16 %257 %259 +OpStore %210 %260 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/tests/out/wgsl/shadow.wgsl b/tests/out/wgsl/shadow.wgsl index a94295422f..a5dbb554ef 100644 --- a/tests/out/wgsl/shadow.wgsl +++ b/tests/out/wgsl/shadow.wgsl @@ -48,19 +48,12 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4) -> f32 { } @stage(vertex) -fn vs_bake(@location(0) position: vec4) -> @builtin(position) vec4 { - let _e4 = u_globals.view_proj; - let _e6 = u_entity.world; - return ((_e4 * _e6) * vec4(position)); -} - -@stage(vertex) -fn vs_main(@location(0) position_1: vec4, @location(1) normal: vec4) -> VertexOutput { +fn vs_main(@location(0) position: vec4, @location(1) normal: vec4) -> VertexOutput { var out: VertexOutput; let w = u_entity.world; let _e7 = u_entity.world; - let world_pos = (_e7 * vec4(position_1)); + let world_pos = (_e7 * vec4(position)); out.world_normal = (mat3x3(w[0].xyz, w[1].xyz, w[2].xyz) * vec3(normal.xyz)); out.world_position = world_pos; let _e25 = u_globals.view_proj;