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

Set the bake count for loads back to 2 #6605

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]
#### Naga

- Show types of LHS and RHS in binary operation type mismatch errors. By @ErichDonGubler in [#6450](https://github.com/gfx-rs/wgpu/pull/6450).
- The GLSL parser now uses less expressions for function calls. By @magcius in [#6604](https://github.com/gfx-rs/wgpu/pull/6604).
- Sets the bake count for loads back to 2, which really helps improve the readability of generated WGSL code. By @magcius in [#6605](https://github.com/gfx-rs/wgpu/pull/6605).

#### General

Expand Down
4 changes: 0 additions & 4 deletions naga/src/back/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ impl crate::Expression {
crate::Expression::ImageSample { .. } | crate::Expression::ImageLoad { .. } => 1,
// derivatives use the control flow
crate::Expression::Derivative { .. } => 1,
// TODO: We need a better fix for named `Load` expressions
// More info - https://github.com/gfx-rs/naga/pull/914
// And https://github.com/gfx-rs/naga/issues/910
crate::Expression::Load { .. } => 1,
// cache expressions that are referenced multiple times
_ => 2,
}
Expand Down
10 changes: 1 addition & 9 deletions naga/src/front/glsl/ast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Cow, fmt};

use super::{builtins::MacroCall, context::ExprPos, Span};
use super::{builtins::MacroCall, Span};
use crate::{
AddressSpace, BinaryOperator, Binding, Constant, Expression, Function, GlobalVariable, Handle,
Interpolation, Literal, Sampling, StorageAccess, Type, UnaryOperator,
Expand Down Expand Up @@ -376,14 +376,6 @@ impl ParameterQualifier {
_ => false,
}
}

/// Converts from a parameter qualifier into a [`ExprPos`]
pub const fn as_pos(&self) -> ExprPos {
match *self {
ParameterQualifier::Out | ParameterQualifier::InOut => ExprPos::Lhs,
_ => ExprPos::Rhs,
}
}
}

/// The GLSL profile used by a shader.
Expand Down
8 changes: 5 additions & 3 deletions naga/src/front/glsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,10 @@ impl Frontend {
.zip(raw_args)
.zip(&parameters)
{
let (mut handle, meta) =
ctx.lower_expect_inner(stmt, self, *expr, parameter_info.qualifier.as_pos())?;

if parameter_info.qualifier.is_lhs() {
// Reprocess argument in LHS position
let (handle, meta) = ctx.lower_expect_inner(stmt, self, *expr, ExprPos::Lhs)?;

self.process_lhs_argument(
ctx,
meta,
Expand All @@ -803,6 +803,8 @@ impl Frontend {
continue;
}

let (mut handle, meta) = *call_argument;

let scalar_comps = scalar_components(&ctx.module.types[*parameter].inner);

// Apply implicit conversions as needed
Expand Down
5 changes: 2 additions & 3 deletions naga/tests/out/glsl/6438-conflicting-idents.vs.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ void main() {
vec2 xy = _p2vs_location0;
OurVertexShaderOutput vsOutput = OurVertexShaderOutput(vec4(0.0), vec2(0.0));
vsOutput.position = vec4(xy, 0.0, 1.0);
OurVertexShaderOutput _e6 = vsOutput;
gl_Position = _e6.position;
_vs2fs_location0 = _e6.texcoord;
gl_Position = vsOutput.position;
_vs2fs_location0 = vsOutput.texcoord;
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
}
Expand Down
9 changes: 3 additions & 6 deletions naga/tests/out/glsl/access.assign_through_ptr.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ struct AssignToMember {
};

float read_from_private(inout float foo_1) {
float _e1 = foo_1;
return _e1;
return foo_1;
}

float test_arr_as_arg(float a[5][10]) {
Expand All @@ -43,8 +42,7 @@ void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
uint _e2 = p_1.x;
return _e2;
return p_1.x;
}

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
Expand All @@ -53,8 +51,7 @@ void assign_to_arg_ptr_member(inout AssignToMember p_2) {
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
uint _e2 = p_3[1];
return _e2;
return p_3[1];
}

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ struct AssignToMember {
};

float read_from_private(inout float foo_1) {
float _e1 = foo_1;
return _e1;
return foo_1;
}

float test_arr_as_arg(float a[5][10]) {
Expand All @@ -43,8 +42,7 @@ void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
uint _e2 = p_1.x;
return _e2;
return p_1.x;
}

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
Expand All @@ -53,8 +51,7 @@ void assign_to_arg_ptr_member(inout AssignToMember p_2) {
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
uint _e2 = p_3[1];
return _e2;
return p_3[1];
}

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
Expand Down
9 changes: 3 additions & 6 deletions naga/tests/out/glsl/access.foo_frag.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ layout(std430) buffer type_13_block_1Fragment { ivec2 _group_0_binding_2_fs; };
layout(location = 0) out vec4 _fs2p_location0;

float read_from_private(inout float foo_1) {
float _e1 = foo_1;
return _e1;
return foo_1;
}

float test_arr_as_arg(float a[5][10]) {
Expand All @@ -53,8 +52,7 @@ void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
uint _e2 = p_1.x;
return _e2;
return p_1.x;
}

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
Expand All @@ -63,8 +61,7 @@ void assign_to_arg_ptr_member(inout AssignToMember p_2) {
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
uint _e2 = p_3[1];
return _e2;
return p_3[1];
}

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
Expand Down
73 changes: 23 additions & 50 deletions naga/tests/out/glsl/access.foo_vert.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,76 +39,51 @@ uniform MatCx2InArray_block_3Vertex { MatCx2InArray _group_0_binding_3_vs; };
void test_matrix_within_struct_accesses() {
int idx = 1;
Baz t = Baz(mat3x2(vec2(1.0), vec2(2.0), vec2(3.0)));
int _e3 = idx;
idx = (_e3 - 1);
idx = (idx - 1);
mat3x2 l0_ = _group_0_binding_1_vs.m;
vec2 l1_ = _group_0_binding_1_vs.m[0];
int _e14 = idx;
vec2 l2_ = _group_0_binding_1_vs.m[_e14];
vec2 l2_ = _group_0_binding_1_vs.m[idx];
float l3_ = _group_0_binding_1_vs.m[0][1];
int _e25 = idx;
float l4_ = _group_0_binding_1_vs.m[0][_e25];
int _e30 = idx;
float l5_ = _group_0_binding_1_vs.m[_e30][1];
int _e36 = idx;
int _e38 = idx;
float l6_ = _group_0_binding_1_vs.m[_e36][_e38];
int _e51 = idx;
idx = (_e51 + 1);
float l4_ = _group_0_binding_1_vs.m[0][idx];
float l5_ = _group_0_binding_1_vs.m[idx][1];
float l6_ = _group_0_binding_1_vs.m[idx][idx];
idx = (idx + 1);
t.m = mat3x2(vec2(6.0), vec2(5.0), vec2(4.0));
t.m[0] = vec2(9.0);
int _e66 = idx;
t.m[_e66] = vec2(90.0);
t.m[idx] = vec2(90.0);
t.m[0][1] = 10.0;
int _e76 = idx;
t.m[0][_e76] = 20.0;
int _e80 = idx;
t.m[_e80][1] = 30.0;
int _e85 = idx;
int _e87 = idx;
t.m[_e85][_e87] = 40.0;
t.m[0][idx] = 20.0;
t.m[idx][1] = 30.0;
t.m[idx][idx] = 40.0;
return;
}

void test_matrix_within_array_within_struct_accesses() {
int idx_1 = 1;
MatCx2InArray t_1 = MatCx2InArray(mat4x2[2](mat4x2(0.0), mat4x2(0.0)));
int _e3 = idx_1;
idx_1 = (_e3 - 1);
idx_1 = (idx_1 - 1);
mat4x2 l0_1[2] = _group_0_binding_3_vs.am;
mat4x2 l1_1 = _group_0_binding_3_vs.am[0];
vec2 l2_1 = _group_0_binding_3_vs.am[0][0];
int _e20 = idx_1;
vec2 l3_1 = _group_0_binding_3_vs.am[0][_e20];
vec2 l3_1 = _group_0_binding_3_vs.am[0][idx_1];
float l4_1 = _group_0_binding_3_vs.am[0][0][1];
int _e33 = idx_1;
float l5_1 = _group_0_binding_3_vs.am[0][0][_e33];
int _e39 = idx_1;
float l6_1 = _group_0_binding_3_vs.am[0][_e39][1];
int _e46 = idx_1;
int _e48 = idx_1;
float l7_ = _group_0_binding_3_vs.am[0][_e46][_e48];
int _e55 = idx_1;
idx_1 = (_e55 + 1);
float l5_1 = _group_0_binding_3_vs.am[0][0][idx_1];
float l6_1 = _group_0_binding_3_vs.am[0][idx_1][1];
float l7_ = _group_0_binding_3_vs.am[0][idx_1][idx_1];
idx_1 = (idx_1 + 1);
t_1.am = mat4x2[2](mat4x2(0.0), mat4x2(0.0));
t_1.am[0] = mat4x2(vec2(8.0), vec2(7.0), vec2(6.0), vec2(5.0));
t_1.am[0][0] = vec2(9.0);
int _e77 = idx_1;
t_1.am[0][_e77] = vec2(90.0);
t_1.am[0][idx_1] = vec2(90.0);
t_1.am[0][0][1] = 10.0;
int _e89 = idx_1;
t_1.am[0][0][_e89] = 20.0;
int _e94 = idx_1;
t_1.am[0][_e94][1] = 30.0;
int _e100 = idx_1;
int _e102 = idx_1;
t_1.am[0][_e100][_e102] = 40.0;
t_1.am[0][0][idx_1] = 20.0;
t_1.am[0][idx_1][1] = 30.0;
t_1.am[0][idx_1][idx_1] = 40.0;
return;
}

float read_from_private(inout float foo_1) {
float _e1 = foo_1;
return _e1;
return foo_1;
}

float test_arr_as_arg(float a[5][10]) {
Expand All @@ -126,8 +101,7 @@ void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
uint _e2 = p_1.x;
return _e2;
return p_1.x;
}

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
Expand All @@ -136,8 +110,7 @@ void assign_to_arg_ptr_member(inout AssignToMember p_2) {
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
uint _e2 = p_3[1];
return _e2;
return p_3[1];
}

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
Expand Down
27 changes: 9 additions & 18 deletions naga/tests/out/glsl/bitcast.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,15 @@ void main() {
vec2 f2_ = vec2(0.0);
vec3 f3_ = vec3(0.0);
vec4 f4_ = vec4(0.0);
ivec2 _e27 = i2_;
u2_ = uvec2(_e27);
ivec3 _e29 = i3_;
u3_ = uvec3(_e29);
ivec4 _e31 = i4_;
u4_ = uvec4(_e31);
uvec2 _e33 = u2_;
i2_ = ivec2(_e33);
uvec3 _e35 = u3_;
i3_ = ivec3(_e35);
uvec4 _e37 = u4_;
i4_ = ivec4(_e37);
ivec2 _e39 = i2_;
f2_ = intBitsToFloat(_e39);
ivec3 _e41 = i3_;
f3_ = intBitsToFloat(_e41);
ivec4 _e43 = i4_;
f4_ = intBitsToFloat(_e43);
u2_ = uvec2(i2_);
u3_ = uvec3(i3_);
u4_ = uvec4(i4_);
i2_ = ivec2(u2_);
i3_ = ivec3(u3_);
i4_ = ivec4(u4_);
f2_ = intBitsToFloat(i2_);
f3_ = intBitsToFloat(i3_);
f4_ = intBitsToFloat(i4_);
return;
}

Loading