Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wgsl-in] Generate no code for trivial vector/matrix construction. #2576

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/front/wgsl/lower/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
(
Expand Down Expand Up @@ -296,11 +292,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
columns: dst_columns,
rows: dst_rows,
},
) if dst_columns == src_columns && dst_rows == src_rows => crate::Expression::As {
expr: component,
kind: crate::ScalarKind::Float,
convert: None,
},
) if dst_columns == src_columns && dst_rows == src_rows => {
// 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);
}

// Vector constructor (splat) - infer type
(
Expand Down
2 changes: 0 additions & 2 deletions tests/out/glsl/constructors.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,5 @@ 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);
}

2 changes: 0 additions & 2 deletions tests/out/hlsl/constructors.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ 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);
}
2 changes: 0 additions & 2 deletions tests/out/msl/constructors.msl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ kernel void main_(
bool ic0_ = static_cast<bool>(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::uint2 {});
metal::float2x3 ic7_ = metal::float2x3(metal::float2x3 {});
}
3 changes: 1 addition & 2 deletions tests/out/spv/constructors.spvasm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 70
; Bound: 68
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
Expand Down Expand Up @@ -79,6 +79,5 @@ OpDecorate %17 ArrayStride 4
OpBranch %66
%66 = OpLabel
OpStore %63 %47
%69 = OpCopyObject %20 %62
OpReturn
OpFunctionEnd
2 changes: 0 additions & 2 deletions tests/out/wgsl/constructors.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ fn main() {
let ic0_ = bool(bool());
let ic4_ = vec2<u32>(0u, 0u);
let ic5_ = mat2x3<f32>(vec3<f32>(0.0, 0.0, 0.0), vec3<f32>(0.0, 0.0, 0.0));
let ic6_ = bitcast<vec2<u32>>(vec2<u32>());
let ic7_ = mat2x3<f32>(mat2x3<f32>());
}
Loading