Skip to content

Commit 2eaa9fe

Browse files
committed
dedup OpVariable: remove OpVariable name from dedup key
1 parent fde0bd3 commit 2eaa9fe

File tree

3 files changed

+38
-94
lines changed

3 files changed

+38
-94
lines changed

crates/rustc_codegen_spirv/src/linker/duplicates.rs

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rspirv::binary::Assemble;
33
use rspirv::dr::{Instruction, Module, Operand};
44
use rspirv::spirv::{Op, Word};
55
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6-
use rustc_middle::bug;
76
use smallvec::SmallVec;
87
use std::collections::hash_map;
98
use std::mem;
@@ -104,24 +103,10 @@ fn gather_annotations(annotations: &[Instruction]) -> FxHashMap<Word, Vec<u32>>
104103
.collect()
105104
}
106105

107-
fn gather_names(debug_names: &[Instruction]) -> FxHashMap<Word, String> {
108-
debug_names
109-
.iter()
110-
.filter(|inst| inst.class.opcode == Op::Name)
111-
.map(|inst| {
112-
(
113-
inst.operands[0].unwrap_id_ref(),
114-
inst.operands[1].unwrap_literal_string().to_owned(),
115-
)
116-
})
117-
.collect()
118-
}
119-
120106
fn make_dedupe_key(
121107
inst: &Instruction,
122108
unresolved_forward_pointers: &FxHashSet<Word>,
123109
annotations: &FxHashMap<Word, Vec<u32>>,
124-
names: &FxHashMap<Word, String>,
125110
) -> Vec<u32> {
126111
let mut data = vec![inst.class.opcode as u32];
127112

@@ -144,29 +129,10 @@ fn make_dedupe_key(
144129
op.assemble_into(&mut data);
145130
}
146131
}
147-
if let Some(id) = inst.result_id {
148-
if let Some(annos) = annotations.get(&id) {
149-
data.extend_from_slice(annos);
150-
}
151-
if inst.class.opcode == Op::Variable {
152-
// Names only matter for OpVariable.
153-
if let Some(name) = names.get(&id) {
154-
// Jump through some hoops to shove a String into a Vec<u32>.
155-
//
156-
// FIXME(eddyb) this should `.assemble_into(&mut data)` the
157-
// `Operand::LiteralString(...)` from the original `Op::Name`.
158-
for chunk in name.as_bytes().chunks(4) {
159-
let slice = match *chunk {
160-
[a] => [a, 0, 0, 0],
161-
[a, b] => [a, b, 0, 0],
162-
[a, b, c] => [a, b, c, 0],
163-
[a, b, c, d] => [a, b, c, d],
164-
_ => bug!(),
165-
};
166-
data.push(u32::from_le_bytes(slice));
167-
}
168-
}
169-
}
132+
if let Some(id) = inst.result_id
133+
&& let Some(annos) = annotations.get(&id)
134+
{
135+
data.extend_from_slice(annos);
170136
}
171137

172138
data
@@ -198,7 +164,6 @@ pub fn remove_duplicate_types(module: &mut Module) {
198164

199165
// Collect a map from type ID to an annotation "key blob" (to append to the type key)
200166
let annotations = gather_annotations(&module.annotations);
201-
let names = gather_names(&module.debug_names);
202167

203168
for inst in &mut module.types_global_values {
204169
if inst.class.opcode == Op::TypeForwardPointer
@@ -222,7 +187,7 @@ pub fn remove_duplicate_types(module: &mut Module) {
222187
// all_inst_iter_mut pass below. However, the code is a lil bit cleaner this way I guess.
223188
rewrite_inst_with_rules(inst, &rewrite_rules);
224189

225-
let key = make_dedupe_key(inst, &unresolved_forward_pointers, &annotations, &names);
190+
let key = make_dedupe_key(inst, &unresolved_forward_pointers, &annotations);
226191

227192
match key_to_result_id.entry(key) {
228193
hash_map::Entry::Vacant(entry) => {
Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
11
OpCapability Shader
22
OpMemoryModel Logical Simple
3-
OpEntryPoint GLCompute %1 "entry_1" %2 %3
3+
OpEntryPoint GLCompute %1 "entry_1" %2
44
OpExecutionMode %1 LocalSize 1 1 1
5-
OpName %3 "_local_id2"
6-
OpName %5 "attr_duplicate::entry_1"
5+
OpName %4 "attr_duplicate::entry_1"
76
OpDecorate %2 BuiltIn LocalInvocationIndex
8-
OpDecorate %3 BuiltIn LocalInvocationIndex
9-
%6 = OpTypeInt 32 0
10-
%7 = OpTypePointer Input %6
11-
%8 = OpTypeVoid
12-
%9 = OpTypeFunction %8
13-
%2 = OpVariable %7 Input
14-
%3 = OpVariable %7 Input
15-
%10 = OpTypeFunction %8 %6 %6
16-
%1 = OpFunction %8 None %9
17-
%11 = OpLabel
18-
%12 = OpLoad %6 %2
19-
%13 = OpLoad %6 %3
20-
%14 = OpFunctionCall %8 %5 %12 %13
7+
%5 = OpTypeInt 32 0
8+
%6 = OpTypePointer Input %5
9+
%7 = OpTypeVoid
10+
%8 = OpTypeFunction %7
11+
%2 = OpVariable %6 Input
12+
%9 = OpTypeFunction %7 %5 %5
13+
%1 = OpFunction %7 None %8
14+
%10 = OpLabel
15+
%11 = OpLoad %5 %2
16+
%12 = OpLoad %5 %2
17+
%13 = OpFunctionCall %7 %4 %11 %12
2118
OpNoLine
2219
OpReturn
2320
OpFunctionEnd
24-
%5 = OpFunction %8 None %10
25-
%15 = OpFunctionParameter %6
26-
%16 = OpFunctionParameter %6
27-
%17 = OpLabel
21+
%4 = OpFunction %7 None %9
22+
%14 = OpFunctionParameter %5
23+
%15 = OpFunctionParameter %5
24+
%16 = OpLabel
2825
OpReturn
2926
OpFunctionEnd
30-
error: error:0:0 - [VUID-StandaloneSpirv-OpEntryPoint-09658] OpEntryPoint contains duplicate input variables with LocalInvocationIndex builtin
31-
%_local_id2 = OpVariable %_ptr_Input_uint Input
32-
|
33-
= note: spirv-val failed
34-
= note: module `$TEST_BUILD_DIR/entry/duplicate/attr_duplicate.vulkan1.2`
35-
36-
error: aborting due to 1 previous error
37-
Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
OpCapability Shader
22
OpMemoryModel Logical Simple
3-
OpEntryPoint GLCompute %1 "entry_1" %2 %3
3+
OpEntryPoint GLCompute %1 "entry_1" %2
44
OpExecutionMode %1 LocalSize 1 1 1
55
OpName %2 "_local_idx"
6-
OpName %6 "builtin_duplicate_std_attr::entry_1"
6+
OpName %5 "builtin_duplicate_std_attr::entry_1"
77
OpDecorate %2 BuiltIn LocalInvocationIndex
8-
OpDecorate %3 BuiltIn LocalInvocationIndex
9-
%7 = OpTypeInt 32 0
10-
%8 = OpTypePointer Input %7
11-
%9 = OpTypeVoid
12-
%10 = OpTypeFunction %9
13-
%2 = OpVariable %8 Input
14-
%11 = OpTypeFunction %9 %7
15-
%3 = OpVariable %8 Input
16-
%1 = OpFunction %9 None %10
17-
%12 = OpLabel
18-
%13 = OpLoad %7 %2
19-
%14 = OpFunctionCall %9 %6 %13
8+
%6 = OpTypeInt 32 0
9+
%7 = OpTypePointer Input %6
10+
%8 = OpTypeVoid
11+
%9 = OpTypeFunction %8
12+
%2 = OpVariable %7 Input
13+
%10 = OpTypeFunction %8 %6
14+
%1 = OpFunction %8 None %9
15+
%11 = OpLabel
16+
%12 = OpLoad %6 %2
17+
%13 = OpFunctionCall %8 %5 %12
2018
OpNoLine
2119
OpReturn
2220
OpFunctionEnd
23-
%6 = OpFunction %9 None %11
24-
%15 = OpFunctionParameter %7
25-
%16 = OpLabel
26-
%17 = OpLoad %7 %3
21+
%5 = OpFunction %8 None %10
22+
%14 = OpFunctionParameter %6
23+
%15 = OpLabel
24+
%16 = OpLoad %6 %2
2725
OpNoLine
2826
OpReturn
2927
OpFunctionEnd
30-
error: error:0:0 - [VUID-StandaloneSpirv-OpEntryPoint-09658] OpEntryPoint contains duplicate input variables with LocalInvocationIndex builtin
31-
%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
32-
|
33-
= note: spirv-val failed
34-
= note: module `$TEST_BUILD_DIR/entry/duplicate/builtin_duplicate_std_attr.vulkan1.2`
35-
36-
error: aborting due to 1 previous error
37-

0 commit comments

Comments
 (0)