Skip to content

Commit c6e74ff

Browse files
committed
Draft: Add all extinst
1 parent 3e8814d commit c6e74ff

File tree

10 files changed

+1141
-263
lines changed

10 files changed

+1141
-263
lines changed

autogen/src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ fn main() {
129129
};
130130

131131
let extended_instruction_sets = [
132-
("GLSL.std.450", "GLOp", "https://www.khronos.org/registry/spir-v/specs/unified1/GLSL.std.450.html"),
133-
("OpenCL.std.100", "CLOp", "https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.ExtendedInstructionSet.100.html"),
134-
("NonSemantic.DebugPrintF", "DebugPrintFOp", "https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/docs/debug_printf.md"),
132+
("GLSL.std.450", "GLOp", "https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html"),
133+
("OpenCL.std.100", "CLOp", "https://registry.khronos.org/SPIR-V/specs/unified1/OpenCL.ExtendedInstructionSet.100.html"),
134+
("OpenCL.debuginfo.100", "CLDebugInfoOp", "https://registry.khronos.org/SPIR-V/specs/unified1/OpenCL.DebugInfo.100.html"),
135+
("NonSemantic.DebugPrintF", "DebugPrintFOp", "https://github.khronos.org/SPIRV-Registry/nonsemantic/NonSemantic.DebugPrintf.html"),
136+
("NonSemantic.DebugBreak", "DebugBreakOp", "https://github.khronos.org/SPIRV-Registry/nonsemantic/NonSemantic.DebugBreak.html"),
137+
("DebugInfo", "DebugInfoOp", "https://registry.khronos.org/SPIR-V/specs/unified1/DebugInfo.html"),
135138
];
136139
let extended_instruction_sets = extended_instruction_sets.map(|(ext, op, url)| {
137140
let grammar: structs::ExtInstSetGrammar = serde_json::from_str(
@@ -172,16 +175,16 @@ fn main() {
172175
table::gen_grammar_inst_table_operand_kinds(&grammar),
173176
);
174177
// Extended instruction sets
175-
for (ext, _, _, grammar) in extended_instruction_sets {
178+
for (ext, spirv_op, _, grammar) in extended_instruction_sets {
176179
write_formatted(
177180
&autogen_src_dir.join(format!(
178181
"../rspirv/grammar/autogen_{}.rs",
179182
ext.replace(".", "_").to_lowercase()
180183
)),
181184
table::gen_instruction_table(
182185
&grammar.instructions,
186+
Some(spirv_op),
183187
&format!("{}_INSTRUCTION_TABLE", ext.replace(".", "_").to_uppercase()),
184-
true,
185188
),
186189
);
187190
}

autogen/src/table.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ fn convert_quantifier(quantifier: structs::Quantifier) -> Ident {
2121
/// `is_ext` indicates whether the grammar is for an extended instruction set.
2222
pub(crate) fn gen_instruction_table(
2323
grammar: &[structs::Instruction],
24+
ext_op_name: Option<&str>,
2425
name: &str,
25-
is_ext: bool,
2626
) -> TokenStream {
27+
let ext_op_name = ext_op_name.map(as_ident);
2728
// Vector for strings for all instructions.
2829
let instructions = grammar.iter().map(|inst| {
2930
// Vector of strings for all operands.
@@ -34,11 +35,10 @@ pub(crate) fn gen_instruction_table(
3435
});
3536
let caps = inst.capabilities.iter().map(|cap| as_ident(cap));
3637
let exts = &inst.extensions;
37-
if is_ext {
38+
if let Some(spirv_op) = &ext_op_name {
3839
let opname = as_ident(&inst.opname);
39-
let opcode = inst.opcode;
4040
quote! {
41-
ext_inst!(#opname, #opcode, [#(#caps),*], [#(#exts),*], [#(#operands),*])
41+
ext_inst!(#spirv_op, #opname, [#(#caps),*], [#(#exts),*], [#(#operands),*])
4242
}
4343
} else {
4444
let opname = as_ident(inst.opname.strip_prefix("Op").unwrap());
@@ -48,7 +48,8 @@ pub(crate) fn gen_instruction_table(
4848
}
4949
});
5050
let name = as_ident(name);
51-
let inst_type = as_ident(if is_ext {
51+
52+
let inst_type = as_ident(if ext_op_name.is_some() {
5253
"ExtendedInstruction"
5354
} else {
5455
"Instruction"
@@ -68,7 +69,7 @@ pub fn gen_grammar_inst_table_operand_kinds(grammar: &structs::Grammar) -> Token
6869
.map(|kind| as_ident(&kind.kind));
6970

7071
// Instruction table.
71-
let table = gen_instruction_table(&grammar.instructions, "INSTRUCTION_TABLE", false);
72+
let table = gen_instruction_table(&grammar.instructions, None, "INSTRUCTION_TABLE");
7273

7374
quote! {
7475
#[doc = "All operand kinds in the SPIR-V grammar."]

0 commit comments

Comments
 (0)