Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 96a7b1a

Browse files
teoxoyjimblandy
authored andcommitted
omit non referenced expressions
1 parent 763ec5d commit 96a7b1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1918
-2793
lines changed

src/back/glsl/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,8 +1803,6 @@ impl<'a, W: Write> Writer<'a, W> {
18031803
Some(self.namer.call(name))
18041804
} else if self.need_bake_expressions.contains(&handle) {
18051805
Some(format!("{}{}", back::BAKE_PREFIX, handle.index()))
1806-
} else if info.ref_count == 0 {
1807-
Some(self.namer.call(""))
18081806
} else {
18091807
None
18101808
};

src/back/hlsl/writer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,6 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
13361336
Some(self.namer.call(name))
13371337
} else if self.need_bake_expressions.contains(&handle) {
13381338
Some(format!("_expr{}", handle.index()))
1339-
} else if info.ref_count == 0 {
1340-
Some(self.namer.call(""))
13411339
} else {
13421340
None
13431341
};

src/back/msl/writer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,8 +2581,6 @@ impl<W: Write> Writer<W> {
25812581
// Don't assume the names in `named_expressions` are unique,
25822582
// or even valid. Use the `Namer`.
25832583
Some(self.namer.call(name))
2584-
} else if info.ref_count == 0 {
2585-
Some(self.namer.call(""))
25862584
} else {
25872585
// If this expression is an index that we're going to first compare
25882586
// against a limit, and then actually use as an index, then we may

src/back/spv/block.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ impl<'w> BlockContext<'w> {
220220
expr_handle: Handle<crate::Expression>,
221221
block: &mut Block,
222222
) -> Result<(), Error> {
223+
let is_named_expression = self
224+
.ir_function
225+
.named_expressions
226+
.contains_key(&expr_handle);
227+
228+
if self.fun_info[expr_handle].ref_count == 0 && !is_named_expression {
229+
return Ok(());
230+
}
231+
223232
let result_type_id = self.get_expression_type_id(&self.fun_info[expr_handle].ty);
224233
let id = match self.ir_function.expressions[expr_handle] {
225234
crate::Expression::Access { base, index: _ } if self.is_intermediate(base) => {

src/back/wgsl/writer.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,6 @@ impl<W: Write> Writer<W> {
634634
// Otherwise, we could accidentally write variable name instead of full expression.
635635
// Also, we use sanitized names! It defense backend from generating variable with name from reserved keywords.
636636
Some(self.namer.call(name))
637-
} else if info.ref_count == 0 {
638-
write!(self.out, "{level}_ = ")?;
639-
self.write_expr(module, handle, func_ctx)?;
640-
writeln!(self.out, ";")?;
641-
continue;
642637
} else {
643638
let expr = &func_ctx.expressions[handle];
644639
let min_ref_count = expr.bake_ref_count();

src/valid/analyzer.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,17 @@ impl FunctionInfo {
675675
requirements: UniformityRequirements::empty(),
676676
},
677677
E::Math {
678-
arg, arg1, arg2, ..
678+
fun: _,
679+
arg,
680+
arg1,
681+
arg2,
682+
arg3,
679683
} => {
680684
let arg1_nur = arg1.and_then(|h| self.add_ref(h));
681685
let arg2_nur = arg2.and_then(|h| self.add_ref(h));
686+
let arg3_nur = arg3.and_then(|h| self.add_ref(h));
682687
Uniformity {
683-
non_uniform_result: self.add_ref(arg).or(arg1_nur).or(arg2_nur),
688+
non_uniform_result: self.add_ref(arg).or(arg1_nur).or(arg2_nur).or(arg3_nur),
684689
requirements: UniformityRequirements::empty(),
685690
}
686691
}
@@ -868,7 +873,7 @@ impl FunctionInfo {
868873
S::Loop {
869874
ref body,
870875
ref continuing,
871-
break_if: _,
876+
break_if,
872877
} => {
873878
let body_uniformity =
874879
self.process_block(body, other_functions, disruptor, expression_arena)?;
@@ -879,6 +884,9 @@ impl FunctionInfo {
879884
continuing_disruptor,
880885
expression_arena,
881886
)?;
887+
if let Some(expr) = break_if {
888+
let _ = self.add_ref(expr);
889+
}
882890
body_uniformity | continuing_uniformity
883891
}
884892
S::Return { value } => FunctionUniformity {

tests/in/access.wgsl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ fn test_matrix_within_struct_accesses() {
4040
idx--;
4141

4242
// loads
43-
_ = baz.m;
44-
_ = baz.m[0];
45-
_ = baz.m[idx];
46-
_ = baz.m[0][1];
47-
_ = baz.m[0][idx];
48-
_ = baz.m[idx][1];
49-
_ = baz.m[idx][idx];
43+
let l0 = baz.m;
44+
let l1 = baz.m[0];
45+
let l2 = baz.m[idx];
46+
let l3 = baz.m[0][1];
47+
let l4 = baz.m[0][idx];
48+
let l5 = baz.m[idx][1];
49+
let l6 = baz.m[idx][idx];
5050

5151
var t = Baz(mat3x2<f32>(vec2<f32>(1.0), vec2<f32>(2.0), vec2<f32>(3.0)));
5252

@@ -75,14 +75,14 @@ fn test_matrix_within_array_within_struct_accesses() {
7575
idx--;
7676

7777
// loads
78-
_ = nested_mat_cx2.am;
79-
_ = nested_mat_cx2.am[0];
80-
_ = nested_mat_cx2.am[0][0];
81-
_ = nested_mat_cx2.am[0][idx];
82-
_ = nested_mat_cx2.am[0][0][1];
83-
_ = nested_mat_cx2.am[0][0][idx];
84-
_ = nested_mat_cx2.am[0][idx][1];
85-
_ = nested_mat_cx2.am[0][idx][idx];
78+
let l0 = nested_mat_cx2.am;
79+
let l1 = nested_mat_cx2.am[0];
80+
let l2 = nested_mat_cx2.am[0][0];
81+
let l3 = nested_mat_cx2.am[0][idx];
82+
let l4 = nested_mat_cx2.am[0][0][1];
83+
let l5 = nested_mat_cx2.am[0][0][idx];
84+
let l6 = nested_mat_cx2.am[0][idx][1];
85+
let l7 = nested_mat_cx2.am[0][idx][idx];
8686

8787
var t = MatCx2InArray(array<mat4x2<f32>, 2>());
8888

@@ -134,7 +134,7 @@ fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4<f32> {
134134
c2[vi + 1u] = 42;
135135
let value = c2[vi];
136136

137-
_ = test_arr_as_arg(array<array<f32, 10>, 5>());
137+
test_arr_as_arg(array<array<f32, 10>, 5>());
138138

139139
return vec4<f32>(_matrix * vec4<f32>(vec4<i32>(value)), 2.0);
140140
}

tests/in/array-in-ctor.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ var<storage> ah: Ah;
66

77
@compute @workgroup_size(1)
88
fn cs_main() {
9-
_ = ah;
9+
let ah = ah;
1010
}

tests/in/atomicOps.wgsl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ fn cs_main(@builtin(local_invocation_id) id: vec3<u32>) {
3434

3535
workgroupBarrier();
3636

37-
atomicLoad(&storage_atomic_scalar);
38-
atomicLoad(&storage_atomic_arr[1]);
39-
atomicLoad(&storage_struct.atomic_scalar);
40-
atomicLoad(&storage_struct.atomic_arr[1]);
41-
atomicLoad(&workgroup_atomic_scalar);
42-
atomicLoad(&workgroup_atomic_arr[1]);
43-
atomicLoad(&workgroup_struct.atomic_scalar);
44-
atomicLoad(&workgroup_struct.atomic_arr[1]);
37+
let l0 = atomicLoad(&storage_atomic_scalar);
38+
let l1 = atomicLoad(&storage_atomic_arr[1]);
39+
let l2 = atomicLoad(&storage_struct.atomic_scalar);
40+
let l3 = atomicLoad(&storage_struct.atomic_arr[1]);
41+
let l4 = atomicLoad(&workgroup_atomic_scalar);
42+
let l5 = atomicLoad(&workgroup_atomic_arr[1]);
43+
let l6 = atomicLoad(&workgroup_struct.atomic_scalar);
44+
let l7 = atomicLoad(&workgroup_struct.atomic_arr[1]);
4545

4646
workgroupBarrier();
4747

tests/in/globals.wgsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ fn test_msl_packed_vec3() {
4545
let data = alignment;
4646

4747
// loads
48-
_ = data.v3;
49-
_ = data.v3.zx;
48+
let l0 = data.v3;
49+
let l1 = data.v3.zx;
5050
test_msl_packed_vec3_as_arg(data.v3);
5151

5252
// matrix vector multiplication
53-
_ = data.v3 * mat3x3<f32>();
54-
_ = mat3x3<f32>() * data.v3;
53+
let mvm0 = data.v3 * mat3x3<f32>();
54+
let mvm1 = mat3x3<f32>() * data.v3;
5555

5656
// scalar vector multiplication
57-
_ = data.v3 * 2.0;
58-
_ = 2.0 * data.v3;
57+
let svm0 = data.v3 * 2.0;
58+
let svm1 = 2.0 * data.v3;
5959
}
6060

6161
@compute @workgroup_size(1)

0 commit comments

Comments
 (0)