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-out] Don't include type parameter in splat expressions. #2469

Merged
merged 1 commit into from
Sep 12, 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
26 changes: 8 additions & 18 deletions src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,12 @@ impl<W: Write> Writer<W> {
}
write!(self.out, ")")?
}
Expression::Splat { size, value } => {
let size = back::vector_size_str(size);
write!(self.out, "vec{size}(")?;
write_expression(self, value)?;
write!(self.out, ")")?;
}
_ => unreachable!(),
}

Expand Down Expand Up @@ -1173,7 +1179,8 @@ impl<W: Write> Writer<W> {
Expression::Literal(_)
| Expression::Constant(_)
| Expression::ZeroValue(_)
| Expression::Compose { .. } => {
| Expression::Compose { .. }
| Expression::Splat { .. } => {
self.write_possibly_const_expression(
module,
expr,
Expand Down Expand Up @@ -1450,23 +1457,6 @@ impl<W: Write> Writer<W> {
self.write_expr(module, expr, func_ctx)?;
write!(self.out, ")")?;
}
Expression::Splat { size, value } => {
let inner = func_ctx.resolve_type(value, &module.types);
let (scalar_kind, scalar_width) = match *inner {
crate::TypeInner::Scalar { kind, width } => (kind, width),
_ => {
return Err(Error::Unimplemented(format!(
"write_expr expression::splat {inner:?}"
)));
}
};
let scalar = scalar_kind_str(scalar_kind, scalar_width);
let size = back::vector_size_str(size);

write!(self.out, "vec{size}<{scalar}>(")?;
self.write_expr(module, value, func_ctx)?;
write!(self.out, ")")?;
}
Expression::Load { pointer } => {
let is_atomic_pointer = func_ctx
.resolve_type(pointer, &module.types)
Expand Down
2 changes: 1 addition & 1 deletion tests/out/wgsl/900-implicit-conversions-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn implicit_dims_3(v_6: vec4<f32>) {
fn main_1() {
exact_1(1);
implicit(f32(1u));
implicit_dims_2(vec3<f32>(vec3<i32>(1)));
implicit_dims_2(vec3<f32>(vec3(1)));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/out/wgsl/901-lhs-field-select-frag.wgsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main_1() {
var a: vec4<f32>;

a = vec4<f32>(1.0);
a = vec4(1.0);
a.x = 2.0;
return;
}
Expand Down
26 changes: 13 additions & 13 deletions tests/out/wgsl/access.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ fn test_matrix_within_struct_accesses() {
let _e41 = idx;
let _e43 = idx;
let l6_ = baz.m[_e41][_e43];
t = Baz(mat3x2<f32>(vec2<f32>(1.0), vec2<f32>(2.0), vec2<f32>(3.0)));
t = Baz(mat3x2<f32>(vec2(1.0), vec2(2.0), vec2(3.0)));
let _e56 = idx;
idx = (_e56 + 1);
t.m = mat3x2<f32>(vec2<f32>(6.0), vec2<f32>(5.0), vec2<f32>(4.0));
t.m[0] = vec2<f32>(9.0);
t.m = mat3x2<f32>(vec2(6.0), vec2(5.0), vec2(4.0));
t.m[0] = vec2(9.0);
let _e72 = idx;
t.m[_e72] = vec2<f32>(90.0);
t.m[_e72] = vec2(90.0);
t.m[0][1] = 10.0;
let _e85 = idx;
t.m[0][_e85] = 20.0;
Expand Down Expand Up @@ -97,10 +97,10 @@ fn test_matrix_within_array_within_struct_accesses() {
let _e67 = idx_1;
idx_1 = (_e67 + 1);
t_1.am = array<mat4x2<f32>, 2>();
t_1.am[0] = mat4x2<f32>(vec2<f32>(8.0), vec2<f32>(7.0), vec2<f32>(6.0), vec2<f32>(5.0));
t_1.am[0][0] = vec2<f32>(9.0);
t_1.am[0] = mat4x2<f32>(vec2(8.0), vec2(7.0), vec2(6.0), vec2(5.0));
t_1.am[0][0] = vec2(9.0);
let _e93 = idx_1;
t_1.am[0][_e93] = vec2<f32>(90.0);
t_1.am[0][_e93] = vec2(90.0);
t_1.am[0][0][1] = 10.0;
let _e110 = idx_1;
t_1.am[0][0][_e110] = 20.0;
Expand All @@ -127,7 +127,7 @@ fn assign_through_ptr_fn(p: ptr<workgroup, u32>) {
}

fn assign_array_through_ptr_fn(foo_2: ptr<function, array<vec4<f32>, 2>>) {
(*foo_2) = array<vec4<f32>, 2>(vec4<f32>(1.0), vec4<f32>(2.0));
(*foo_2) = array<vec4<f32>, 2>(vec4(1.0), vec4(2.0));
return;
}

Expand All @@ -152,24 +152,24 @@ fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4<f32> {
c2_[(vi + 1u)] = 42;
let value = c2_[vi];
let _e48 = test_arr_as_arg(array<array<f32, 10>, 5>());
return vec4<f32>((_matrix * vec4<f32>(vec4<i32>(value))), 2.0);
return vec4<f32>((_matrix * vec4<f32>(vec4(value))), 2.0);
}

@fragment
fn foo_frag() -> @location(0) vec4<f32> {
bar._matrix[1][2] = 1.0;
bar._matrix = mat4x3<f32>(vec3<f32>(0.0), vec3<f32>(1.0), vec3<f32>(2.0), vec3<f32>(3.0));
bar.arr = array<vec2<u32>, 2>(vec2<u32>(0u), vec2<u32>(1u));
bar._matrix = mat4x3<f32>(vec3(0.0), vec3(1.0), vec3(2.0), vec3(3.0));
bar.arr = array<vec2<u32>, 2>(vec2(0u), vec2(1u));
bar.data[1].value = 1;
qux = vec2<i32>();
return vec4<f32>(0.0);
return vec4(0.0);
}

@compute @workgroup_size(1, 1, 1)
fn assign_through_ptr() {
var arr: array<vec4<f32>, 2>;

arr = array<vec4<f32>, 2>(vec4<f32>(6.0), vec4<f32>(7.0));
arr = array<vec4<f32>, 2>(vec4(6.0), vec4(7.0));
assign_through_ptr_fn((&val));
assign_array_through_ptr_fn((&arr));
return;
Expand Down
24 changes: 12 additions & 12 deletions tests/out/wgsl/bevy-pbr-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn F_Schlick(f0_: vec3<f32>, f90_: f32, VoH: f32) -> vec3<f32> {
let _e49 = VoH_1;
let _e52 = VoH_1;
let _e54 = pow5_((1.0 - _e52));
return (f0_ + ((vec3<f32>(_e45) - f0_) * _e54));
return (f0_ + ((vec3(_e45) - f0_) * _e54));
}

fn F_Schlick_1(f0_1: f32, f90_2: f32, VoH_2: f32) -> f32 {
Expand Down Expand Up @@ -247,7 +247,7 @@ fn fresnel(f0_3: vec3<f32>, LoH: f32) -> vec3<f32> {
LoH_1 = LoH;
let _e49 = f0_4;
let _e62 = f0_4;
f90_4 = clamp(dot(_e62, vec3<f32>((50.0 * 0.33))), 0.0, 1.0);
f90_4 = clamp(dot(_e62, vec3((50.0 * 0.33))), 0.0, 1.0);
let _e75 = f0_4;
let _e76 = f90_4;
let _e77 = LoH_1;
Expand Down Expand Up @@ -342,7 +342,7 @@ fn EnvBRDFApprox(f0_7: vec3<f32>, perceptual_roughness: f32, NoV_6: f32) -> vec3
let _e62 = perceptual_roughness_1;
let _e64 = c0_;
let _e66 = c1_;
r = ((vec4<f32>(_e62) * _e64) + _e66);
r = ((vec4(_e62) * _e64) + _e66);
let _e69 = r;
let _e71 = r;
let _e76 = NoV_7;
Expand All @@ -356,11 +356,11 @@ fn EnvBRDFApprox(f0_7: vec3<f32>, perceptual_roughness: f32, NoV_6: f32) -> vec3
a004_ = ((min((_e83.x * _e85.x), exp2((-(9.28) * _e94))) * _e98.x) + _e101.y);
let _e109 = a004_;
let _e112 = r;
AB = ((vec2<f32>(-(1.04), 1.04) * vec2<f32>(_e109)) + _e112.zw);
AB = ((vec2<f32>(-(1.04), 1.04) * vec2(_e109)) + _e112.zw);
let _e116 = f0_8;
let _e117 = AB;
let _e121 = AB;
return ((_e116 * vec3<f32>(_e117.x)) + vec3<f32>(_e121.y));
return ((_e116 * vec3(_e117.x)) + vec3(_e121.y));
}

fn perceptualRoughnessToRoughness(perceptualRoughness: f32) -> f32 {
Expand All @@ -381,7 +381,7 @@ fn reinhard(color: vec3<f32>) -> vec3<f32> {
color_1 = color;
let _e42 = color_1;
let _e45 = color_1;
return (_e42 / (vec3<f32>(1.0) + _e45));
return (_e42 / (vec3(1.0) + _e45));
}

fn reinhard_extended(color_2: vec3<f32>, max_white: f32) -> vec3<f32> {
Expand All @@ -395,10 +395,10 @@ fn reinhard_extended(color_2: vec3<f32>, max_white: f32) -> vec3<f32> {
let _e47 = color_3;
let _e48 = max_white_1;
let _e49 = max_white_1;
numerator = (_e44 * (vec3<f32>(1.0) + (_e47 / vec3<f32>((_e48 * _e49)))));
numerator = (_e44 * (vec3(1.0) + (_e47 / vec3((_e48 * _e49)))));
let _e56 = numerator;
let _e59 = color_3;
return (_e56 / (vec3<f32>(1.0) + _e59));
return (_e56 / (vec3(1.0) + _e59));
}

fn luminance(v_1: vec3<f32>) -> f32 {
Expand Down Expand Up @@ -788,7 +788,7 @@ fn main_1() {
let _e123 = textureSample(StandardMaterial_normal_map, StandardMaterial_normal_map_sampler, _e122);
let _e131 = v_Uv_1;
let _e132 = textureSample(StandardMaterial_normal_map, StandardMaterial_normal_map_sampler, _e131);
N_2 = (_e120 * normalize(((_e132.xyz * 2.0) - vec3<f32>(1.0))));
N_2 = (_e120 * normalize(((_e132.xyz * 2.0) - vec3(1.0))));
let _e142 = v_Uv_1;
let _e143 = textureSample(StandardMaterial_occlusion_texture, StandardMaterial_occlusion_texture_sampler, _e142);
occlusion = _e143.x;
Expand Down Expand Up @@ -817,15 +817,15 @@ fn main_1() {
let _e195 = metallic;
let _e199 = output_color;
let _e201 = metallic;
F0_4 = (vec3<f32>((((0.16 * _e190) * _e192) * (1.0 - _e195))) + (_e199.xyz * vec3<f32>(_e201)));
F0_4 = (vec3((((0.16 * _e190) * _e192) * (1.0 - _e195))) + (_e199.xyz * vec3(_e201)));
let _e206 = output_color;
let _e209 = metallic;
diffuseColor_4 = (_e206.xyz * vec3<f32>((1.0 - _e209)));
diffuseColor_4 = (_e206.xyz * vec3((1.0 - _e209)));
let _e214 = V_3;
let _e217 = V_3;
let _e219 = N_2;
R_4 = reflect(-(_e217), _e219);
light_accum = vec3<f32>(0.0);
light_accum = vec3(0.0);
i = 0;
loop {
let _e227 = i;
Expand Down
12 changes: 6 additions & 6 deletions tests/out/wgsl/binding-arrays.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ fn main(fragment_in: FragmentIn) -> @location(0) vec4<f32> {
let uniform_index = uni.index;
let non_uniform_index = fragment_in.index;
u1_ = 0u;
u2_ = vec2<u32>(0u);
u2_ = vec2(0u);
v1_ = 0.0;
v4_ = vec4<f32>(0.0);
let uv = vec2<f32>(0.0);
let pix = vec2<i32>(0);
v4_ = vec4(0.0);
let uv = vec2(0.0);
let pix = vec2(0);
let _e22 = textureDimensions(texture_array_unbounded[0]);
let _e23 = u2_;
u2_ = (_e23 + _e22);
Expand Down Expand Up @@ -165,8 +165,8 @@ fn main(fragment_in: FragmentIn) -> @location(0) vec4<f32> {
textureStore(texture_array_storage[non_uniform_index], pix, _e313);
let _e314 = u2_;
let _e315 = u1_;
let v2_ = vec2<f32>((_e314 + vec2<u32>(_e315)));
let v2_ = vec2<f32>((_e314 + vec2(_e315)));
let _e319 = v4_;
let _e326 = v1_;
return ((_e319 + vec4<f32>(v2_.x, v2_.y, v2_.x, v2_.y)) + vec4<f32>(_e326));
return ((_e319 + vec4<f32>(v2_.x, v2_.y, v2_.x, v2_.y)) + vec4(_e326));
}
18 changes: 9 additions & 9 deletions tests/out/wgsl/bitcast.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ fn main() {
var f3_: vec3<f32>;
var f4_: vec4<f32>;

i2_ = vec2<i32>(0);
i3_ = vec3<i32>(0);
i4_ = vec4<i32>(0);
u2_ = vec2<u32>(0u);
u3_ = vec3<u32>(0u);
u4_ = vec4<u32>(0u);
f2_ = vec2<f32>(0.0);
f3_ = vec3<f32>(0.0);
f4_ = vec4<f32>(0.0);
i2_ = vec2(0);
i3_ = vec3(0);
i4_ = vec4(0);
u2_ = vec2(0u);
u3_ = vec3(0u);
u4_ = vec4(0u);
f2_ = vec2(0.0);
f3_ = vec3(0.0);
f4_ = vec4(0.0);
let _e27 = i2_;
u2_ = bitcast<vec2<u32>>(_e27);
let _e29 = i3_;
Expand Down
16 changes: 8 additions & 8 deletions tests/out/wgsl/bits.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn main() {
var f4_: vec4<f32>;

i = 0;
i2_ = vec2<i32>(0);
i3_ = vec3<i32>(0);
i4_ = vec4<i32>(0);
i2_ = vec2(0);
i3_ = vec3(0);
i4_ = vec4(0);
u = 0u;
u2_ = vec2<u32>(0u);
u3_ = vec3<u32>(0u);
u4_ = vec4<u32>(0u);
f2_ = vec2<f32>(0.0);
f4_ = vec4<f32>(0.0);
u2_ = vec2(0u);
u3_ = vec3(0u);
u4_ = vec4(0u);
f2_ = vec2(0.0);
f4_ = vec4(0.0);
let _e28 = f4_;
u = pack4x8snorm(_e28);
let _e30 = f4_;
Expand Down
16 changes: 8 additions & 8 deletions tests/out/wgsl/bits_glsl-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ fn main_1() {
var f4_: vec4<f32>;

i = 0;
i2_ = vec2<i32>(0);
i3_ = vec3<i32>(0);
i4_ = vec4<i32>(0);
i2_ = vec2(0);
i3_ = vec3(0);
i4_ = vec4(0);
u = u32(0);
u2_ = vec2<u32>(u32(0));
u3_ = vec3<u32>(u32(0));
u4_ = vec4<u32>(u32(0));
f2_ = vec2<f32>(0.0);
f4_ = vec4<f32>(0.0);
u2_ = vec2(u32(0));
u3_ = vec3(u32(0));
u4_ = vec4(u32(0));
f2_ = vec2(0.0);
f4_ = vec4(0.0);
let _e33 = f4_;
u = pack4x8snorm(_e33);
let _e36 = f4_;
Expand Down
4 changes: 2 additions & 2 deletions tests/out/wgsl/boids.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ fn main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>) {
let _e97 = cMass;
let _e98 = cMassCount;
let _e102 = vPos;
cMass = ((_e97 / vec2<f32>(f32(_e98))) - _e102);
cMass = ((_e97 / vec2(f32(_e98))) - _e102);
}
let _e104 = cVelCount;
if (_e104 > 0) {
let _e107 = cVel;
let _e108 = cVelCount;
cVel = (_e107 / vec2<f32>(f32(_e108)));
cVel = (_e107 / vec2(f32(_e108)));
}
let _e112 = vVel;
let _e113 = cMass;
Expand Down
4 changes: 2 additions & 2 deletions tests/out/wgsl/bool-select-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ fn TevPerCompGT_1(a_2: vec3<f32>, b_2: vec3<f32>) -> vec3<f32> {
b_3 = b_2;
let _e7 = a_3;
let _e8 = b_3;
return select(vec3<f32>(0.0), vec3<f32>(1.0), (_e7 > _e8));
return select(vec3(0.0), vec3(1.0), (_e7 > _e8));
}

fn main_1() {
let _e1 = o_color;
let _e11 = TevPerCompGT_1(vec3<f32>(3.0), vec3<f32>(5.0));
let _e11 = TevPerCompGT_1(vec3(3.0), vec3(5.0));
o_color.x = _e11.x;
o_color.y = _e11.y;
o_color.z = _e11.z;
Expand Down
2 changes: 1 addition & 1 deletion tests/out/wgsl/clamp-splat-vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var<private> gl_Position: vec4<f32>;

fn main_1() {
let _e5 = a_pos_1;
let _e10 = clamp(_e5, vec2<f32>(0.0), vec2<f32>(1.0));
let _e10 = clamp(_e5, vec2(0.0), vec2(1.0));
gl_Position = vec4<f32>(_e10.x, _e10.y, 0.0, 1.0);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/out/wgsl/constant-array-size-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn function() -> vec4<f32> {
var sum: vec4<f32>;
var i: i32;

sum = vec4<f32>(f32(0));
sum = vec4(f32(0));
i = 0;
loop {
let _e9 = i;
Expand Down
6 changes: 3 additions & 3 deletions tests/out/wgsl/constructors.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const cp3_: array<i32, 4> = array<i32, 4>(0, 1, 2, 3);
fn main() {
var foo: Foo;

foo = Foo(vec4<f32>(1.0), 1);
foo = Foo(vec4(1.0), 1);
let m0_ = mat2x2<f32>(vec2<f32>(1.0, 0.0), vec2<f32>(0.0, 1.0));
let m1_ = mat4x4<f32>(vec4<f32>(1.0, 0.0, 0.0, 0.0), vec4<f32>(0.0, 1.0, 0.0, 0.0), vec4<f32>(0.0, 0.0, 1.0, 0.0), vec4<f32>(0.0, 0.0, 0.0, 1.0));
let cit0_ = vec2<u32>(0u);
let cit1_ = mat2x2<f32>(vec2<f32>(0.0), vec2<f32>(0.0));
let cit0_ = vec2(0u);
let cit1_ = mat2x2<f32>(vec2(0.0), vec2(0.0));
let cit2_ = array<i32, 4>(0, 1, 2, 3);
let ic0_ = bool(bool());
let ic1_ = i32(i32());
Expand Down
2 changes: 1 addition & 1 deletion tests/out/wgsl/declarations-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main_1() {
a_1 = _e41;
let _e57 = array_toomanyd[0][0][0][0][0][0][0];
b = _e57;
out_array[0] = vec4<f32>(2.0);
out_array[0] = vec4(2.0);
return;
}

Expand Down
Loading