From 350f8f1ecdd85e9660d8d557407bbf00709c02bb Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sat, 21 Oct 2023 12:23:50 -0700 Subject: [PATCH] [wgsl-in] Generate no code for trivial vector construction. Do not emit an `Expression::As` conversion for WGSL like `vec3(v)` where `v` is already a `vec3`. This doesn't fix any bugs, but it makes it clearer to the reader of `Lowerer::construct` that no conversion can actually take place in this case. --- src/front/wgsl/lower/construction.rs | 18 +++++++----------- tests/out/glsl/constructors.main.Compute.glsl | 1 - tests/out/hlsl/constructors.hlsl | 1 - tests/out/msl/constructors.msl | 1 - tests/out/spv/constructors.spvasm | 4 ++-- tests/out/wgsl/constructors.wgsl | 1 - 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/front/wgsl/lower/construction.rs b/src/front/wgsl/lower/construction.rs index ec3a338706..1f2bd21744 100644 --- a/src/front/wgsl/lower/construction.rs +++ b/src/front/wgsl/lower/construction.rs @@ -239,20 +239,16 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { ( Components::One { component, - ty_inner: - &crate::TypeInner::Vector { - size: src_size, - kind: src_kind, - .. - }, + ty_inner: &crate::TypeInner::Vector { size: src_size, .. }, .. }, ConcreteConstructor::PartialVector { size: dst_size }, - ) if dst_size == src_size => crate::Expression::As { - expr: component, - kind: src_kind, - convert: None, - }, + ) if dst_size == src_size => { + // This is a trivial conversion: the sizes match, and a Partial + // constructor doesn't specify a scalar type, so nothing can + // possibly happen. + return Ok(component); + } // Matrix conversion (matrix -> matrix) ( diff --git a/tests/out/glsl/constructors.main.Compute.glsl b/tests/out/glsl/constructors.main.Compute.glsl index 8ef0a60ba7..b3c3ec4e8b 100644 --- a/tests/out/glsl/constructors.main.Compute.glsl +++ b/tests/out/glsl/constructors.main.Compute.glsl @@ -34,7 +34,6 @@ void main() { bool ic0_ = bool(false); uvec2 ic4_ = uvec2(0u, 0u); mat2x3 ic5_ = mat2x3(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0)); - uvec2 ic6_ = uvec2(0u); mat2x3 ic7_ = mat2x3(0.0); } diff --git a/tests/out/hlsl/constructors.hlsl b/tests/out/hlsl/constructors.hlsl index 52de162f44..7d7aba12d5 100644 --- a/tests/out/hlsl/constructors.hlsl +++ b/tests/out/hlsl/constructors.hlsl @@ -52,6 +52,5 @@ void main() bool ic0_ = bool((bool)0); uint2 ic4_ = uint2(0u, 0u); float2x3 ic5_ = float2x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0)); - uint2 ic6_ = asuint((uint2)0); float2x3 ic7_ = asfloat((float2x3)0); } diff --git a/tests/out/msl/constructors.msl b/tests/out/msl/constructors.msl index b3a0ecd896..1fb68d7bf3 100644 --- a/tests/out/msl/constructors.msl +++ b/tests/out/msl/constructors.msl @@ -42,6 +42,5 @@ kernel void main_( bool ic0_ = static_cast(bool {}); metal::uint2 ic4_ = metal::uint2(0u, 0u); metal::float2x3 ic5_ = metal::float2x3(metal::float3(0.0, 0.0, 0.0), metal::float3(0.0, 0.0, 0.0)); - metal::uint2 ic6_ = as_type(metal::uint2 {}); metal::float2x3 ic7_ = metal::float2x3(metal::float2x3 {}); } diff --git a/tests/out/spv/constructors.spvasm b/tests/out/spv/constructors.spvasm index e8e2e25957..1cc220a9d6 100644 --- a/tests/out/spv/constructors.spvasm +++ b/tests/out/spv/constructors.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.1 ; Generator: rspirv -; Bound: 70 +; Bound: 69 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 @@ -79,6 +79,6 @@ OpDecorate %17 ArrayStride 4 OpBranch %66 %66 = OpLabel OpStore %63 %47 -%69 = OpCopyObject %20 %62 +%68 = OpCopyObject %20 %62 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/tests/out/wgsl/constructors.wgsl b/tests/out/wgsl/constructors.wgsl index f15bcb6c8d..1c9f733750 100644 --- a/tests/out/wgsl/constructors.wgsl +++ b/tests/out/wgsl/constructors.wgsl @@ -29,6 +29,5 @@ fn main() { let ic0_ = bool(bool()); let ic4_ = vec2(0u, 0u); let ic5_ = mat2x3(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0)); - let ic6_ = bitcast>(vec2()); let ic7_ = mat2x3(mat2x3()); }