Skip to content

Commit f1ea8a7

Browse files
committed
shared: only retain entry point vars with preserve-bindings
1 parent 7a6a745 commit f1ea8a7

File tree

5 files changed

+76
-83
lines changed

5 files changed

+76
-83
lines changed

crates/rustc_codegen_spirv/src/linker/entry_interface.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Id = Word;
1313
///
1414
/// This is needed for (arguably-not-interface) `Private` in SPIR-V >= 1.4,
1515
/// but also any interface variables declared "out of band" (e.g. via `asm!`).
16-
pub fn gather_all_interface_vars_from_uses(module: &mut Module) {
16+
pub fn gather_all_interface_vars_from_uses(module: &mut Module, preserve_bindings: bool) {
1717
// Start by mapping out which global (i.e. `OpVariable` or constants) IDs
1818
// can be used to access any interface-relevant `OpVariable`s
1919
// (where "interface-relevant" depends on the version, see comments below).
@@ -87,12 +87,15 @@ pub fn gather_all_interface_vars_from_uses(module: &mut Module) {
8787
entry.operands[1].unwrap_id_ref()
8888
);
8989

90-
// NOTE(eddyb) it might be better to remove any unused vars, or warn
91-
// the user about their presence, but for now this keeps them around.
92-
let mut interface_vars: IndexSet<Id> = entry.operands[3..]
93-
.iter()
94-
.map(|operand| operand.unwrap_id_ref())
95-
.collect();
90+
// `preserve_bindings` retains any declared entry point vars, otherwise we may DCE them
91+
let mut interface_vars: IndexSet<Id> = if preserve_bindings {
92+
entry.operands[3..]
93+
.iter()
94+
.map(|operand| operand.unwrap_id_ref())
95+
.collect()
96+
} else {
97+
IndexSet::default()
98+
};
9699

97100
interface_vars.extend(&used_vars_per_fn_idx[entry_func_idx]);
98101

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ pub fn link(
654654

655655
{
656656
let _timer = sess.timer("link_gather_all_interface_vars_from_uses");
657-
entry_interface::gather_all_interface_vars_from_uses(&mut output);
657+
entry_interface::gather_all_interface_vars_from_uses(&mut output, opts.preserve_bindings);
658658
}
659659

660660
if opts.spirv_metadata == SpirvMetadata::NameVariables {
Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
11
OpCapability Shader
22
OpMemoryModel Logical Simple
3-
OpEntryPoint GLCompute %1 "main" %2 %3 %4 %5 %6
3+
OpEntryPoint GLCompute %1 "main" %2 %3 %4 %5
44
OpExecutionMode %1 LocalSize 2 1 1
55
OpName %2 "input"
66
OpName %3 "output"
7-
OpName %6 "inv_id"
8-
OpName %4 "used_shared"
9-
OpName %5 "dce_shared"
10-
OpDecorate %9 Block
11-
OpMemberDecorate %9 0 Offset 0
7+
OpName %4 "inv_id"
8+
OpName %5 "used_shared"
9+
OpDecorate %8 Block
10+
OpMemberDecorate %8 0 Offset 0
1211
OpDecorate %2 NonWritable
1312
OpDecorate %2 Binding 0
1413
OpDecorate %2 DescriptorSet 0
1514
OpDecorate %3 Binding 1
1615
OpDecorate %3 DescriptorSet 0
17-
OpDecorate %6 BuiltIn LocalInvocationIndex
18-
%10 = OpTypeFloat 32
19-
%9 = OpTypeStruct %10
20-
%11 = OpTypePointer StorageBuffer %9
21-
%12 = OpTypePointer Workgroup %10
22-
%13 = OpTypeInt 32 1
23-
%14 = OpTypeInt 32 0
24-
%15 = OpConstant %14 2
25-
%16 = OpTypeArray %13 %15
26-
%17 = OpTypePointer Workgroup %16
27-
%18 = OpTypeVector %14 3
28-
%19 = OpTypePointer Input %18
29-
%20 = OpTypeVoid
30-
%21 = OpTypeFunction %20
31-
%22 = OpTypePointer StorageBuffer %10
32-
%2 = OpVariable %11 StorageBuffer
33-
%23 = OpConstant %14 0
34-
%3 = OpVariable %11 StorageBuffer
35-
%6 = OpVariable %19 Input
36-
%24 = OpTypeBool
37-
%4 = OpVariable %12 Workgroup
38-
%25 = OpConstant %14 264
39-
%26 = OpConstant %14 1
40-
%5 = OpVariable %17 Workgroup
16+
OpDecorate %4 BuiltIn LocalInvocationIndex
17+
%9 = OpTypeFloat 32
18+
%8 = OpTypeStruct %9
19+
%10 = OpTypePointer StorageBuffer %8
20+
%11 = OpTypePointer Workgroup %9
21+
%12 = OpTypeInt 32 0
22+
%13 = OpConstant %12 2
23+
%14 = OpTypeVector %12 3
24+
%15 = OpTypePointer Input %14
25+
%16 = OpTypeVoid
26+
%17 = OpTypeFunction %16
27+
%18 = OpTypePointer StorageBuffer %9
28+
%2 = OpVariable %10 StorageBuffer
29+
%19 = OpConstant %12 0
30+
%3 = OpVariable %10 StorageBuffer
31+
%4 = OpVariable %15 Input
32+
%20 = OpTypeBool
33+
%5 = OpVariable %11 Workgroup
34+
%21 = OpConstant %12 264
35+
%22 = OpConstant %12 1
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
OpCapability Shader
22
OpMemoryModel Logical Simple
3-
OpEntryPoint Fragment %1 "main" %2
3+
OpEntryPoint Fragment %1 "main"
44
OpExecutionMode %1 OriginUpperLeft
5-
%3 = OpString "$DIR/issue-723-output.rs"
6-
OpName %4 "issue_723_output::main"
7-
OpDecorate %2 Location 0
8-
%5 = OpTypeFloat 32
9-
%6 = OpTypeVector %5 4
10-
%7 = OpTypePointer Output %6
11-
%8 = OpTypeVoid
12-
%9 = OpTypeFunction %8
13-
%2 = OpVariable %7 Output
5+
%2 = OpString "$DIR/issue-723-output.rs"
6+
OpName %3 "issue_723_output::main"
7+
%4 = OpTypeVoid
8+
%5 = OpTypeFunction %4

tests/compiletests/ui/dis/scalars.supported.stderr

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@ OpMemoryModel Logical Simple
77
OpEntryPoint Fragment %1 "main" %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12
88
OpExecutionMode %1 OriginUpperLeft
99
%13 = OpString "$DIR/scalars.rs"
10-
OpName %3 "in_u8"
11-
OpName %4 "in_u16"
12-
OpName %5 "in_u32"
13-
OpName %6 "in_u64"
14-
OpName %7 "in_i8"
15-
OpName %8 "in_i16"
16-
OpName %9 "in_i32"
17-
OpName %10 "in_i64"
18-
OpName %11 "in_f32"
19-
OpName %12 "in_f64"
20-
OpName %2 "out"
10+
OpName %2 "in_u8"
11+
OpName %3 "in_u16"
12+
OpName %4 "in_u32"
13+
OpName %5 "in_u64"
14+
OpName %6 "in_i8"
15+
OpName %7 "in_i16"
16+
OpName %8 "in_i32"
17+
OpName %9 "in_i64"
18+
OpName %10 "in_f32"
19+
OpName %11 "in_f64"
20+
OpName %12 "out"
21+
OpDecorate %2 Flat
22+
OpDecorate %2 Location 0
2123
OpDecorate %3 Flat
22-
OpDecorate %3 Location 0
24+
OpDecorate %3 Location 1
2325
OpDecorate %4 Flat
24-
OpDecorate %4 Location 1
26+
OpDecorate %4 Location 2
2527
OpDecorate %5 Flat
26-
OpDecorate %5 Location 2
28+
OpDecorate %5 Location 3
2729
OpDecorate %6 Flat
28-
OpDecorate %6 Location 3
30+
OpDecorate %6 Location 4
2931
OpDecorate %7 Flat
30-
OpDecorate %7 Location 4
32+
OpDecorate %7 Location 5
3133
OpDecorate %8 Flat
32-
OpDecorate %8 Location 5
34+
OpDecorate %8 Location 6
3335
OpDecorate %9 Flat
34-
OpDecorate %9 Location 6
35-
OpDecorate %10 Flat
36-
OpDecorate %10 Location 7
37-
OpDecorate %11 Location 8
38-
OpDecorate %12 Flat
39-
OpDecorate %12 Location 9
40-
OpDecorate %2 Location 0
36+
OpDecorate %9 Location 7
37+
OpDecorate %10 Location 8
38+
OpDecorate %11 Flat
39+
OpDecorate %11 Location 9
40+
OpDecorate %12 Location 0
4141
%14 = OpTypeInt 32 0
4242
%15 = OpTypePointer Output %14
4343
%16 = OpTypeInt 8 0
@@ -61,18 +61,18 @@ OpDecorate %2 Location 0
6161
%34 = OpTypePointer Input %33
6262
%35 = OpTypeVoid
6363
%36 = OpTypeFunction %35
64-
%3 = OpVariable %17 Input
65-
%4 = OpVariable %19 Input
66-
%5 = OpVariable %20 Input
67-
%6 = OpVariable %22 Input
68-
%7 = OpVariable %24 Input
69-
%8 = OpVariable %26 Input
70-
%9 = OpVariable %28 Input
71-
%10 = OpVariable %30 Input
72-
%11 = OpVariable %32 Input
73-
%12 = OpVariable %34 Input
64+
%2 = OpVariable %17 Input
65+
%3 = OpVariable %19 Input
66+
%4 = OpVariable %20 Input
67+
%5 = OpVariable %22 Input
68+
%6 = OpVariable %24 Input
69+
%7 = OpVariable %26 Input
70+
%8 = OpVariable %28 Input
71+
%9 = OpVariable %30 Input
72+
%10 = OpVariable %32 Input
73+
%11 = OpVariable %34 Input
7474
%37 = OpConstant %16 8
75-
%2 = OpVariable %15 Output
75+
%12 = OpVariable %15 Output
7676
%38 = OpConstant %18 16
7777
%39 = OpConstant %14 32
7878
%40 = OpConstant %21 64

0 commit comments

Comments
 (0)