Skip to content

Commit 7c72c65

Browse files
committed
Add support for mapping reserved instructions
1 parent c60af4e commit 7c72c65

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

autogen/src/main.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ fn write_formatted(path: &PathBuf, contents: impl ToString) {
3535
};
3636
}
3737

38+
/// Maps some reserved instructions in the spec into their expected class in
39+
/// order to generate the proper methods for those instructions.
40+
fn map_reserved_instructions(grammar: &mut structs::Grammar) {
41+
for instruction in grammar
42+
.instructions
43+
.iter_mut()
44+
.filter(|i| i.class == Some(structs::Class::Reserved))
45+
{
46+
match &*instruction.opname {
47+
"OpTypeAccelerationStructureKHR" => instruction.class = Some(structs::Class::Type),
48+
_ => {}
49+
}
50+
}
51+
}
52+
3853
fn main() {
3954
// Path to the SPIR-V core grammar file.
4055
let env_var = env::var("CARGO_MANIFEST_DIR").unwrap();
@@ -52,7 +67,12 @@ fn main() {
5267
let mut file = fs::File::open(path).unwrap();
5368
file.read_to_string(&mut contents).unwrap();
5469
}
55-
let grammar: structs::Grammar = serde_json::from_str(&contents).unwrap();
70+
71+
let grammar: structs::Grammar = {
72+
let mut original = serde_json::from_str(&contents).unwrap();
73+
map_reserved_instructions(&mut original);
74+
original
75+
};
5676

5777
// For GLSLstd450 extended instruction set.
5878
{

rspirv/dr/build/autogen_type.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,17 @@ impl Builder {
345345
new_id
346346
}
347347
}
348+
#[doc = "Appends an OpTypeAccelerationStructureKHR instruction and returns the result id, or return the existing id if the instruction was already present."]
349+
pub fn type_acceleration_structure_khr(&mut self) -> spirv::Word {
350+
let mut inst =
351+
dr::Instruction::new(spirv::Op::TypeAccelerationStructureKHR, None, None, vec![]);
352+
if let Some(id) = self.dedup_insert_type(&inst) {
353+
id
354+
} else {
355+
let new_id = self.id();
356+
inst.result_id = Some(new_id);
357+
self.module.types_global_values.push(inst);
358+
new_id
359+
}
360+
}
348361
}

rspirv/lift/autogen_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5803,7 +5803,6 @@ impl LiftContext {
58035803
.ok_or(OperandError::Missing)?,
58045804
}),
58055805
5341u32 => Ok(ops::Op::TypeAccelerationStructureNV),
5806-
5341u32 => Ok(ops::Op::TypeAccelerationStructureKHR),
58075806
5344u32 => Ok(ops::Op::ExecuteCallableNV {
58085807
sbt_index: (match operands.next() {
58095808
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
@@ -8577,6 +8576,7 @@ impl LiftContext {
85778576
}),
85788577
322u32 => Ok(Type::PipeStorage),
85798578
327u32 => Ok(Type::NamedBarrier),
8579+
5341u32 => Ok(Type::AccelerationStructureKHR),
85808580
_ => Err(InstructionError::WrongOpcode),
85818581
}
85828582
}

rspirv/sr/autogen_ops.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,6 @@ pub enum Op {
14811481
payload_id: spirv::Word,
14821482
},
14831483
TypeAccelerationStructureNV,
1484-
TypeAccelerationStructureKHR,
14851484
ExecuteCallableNV {
14861485
sbt_index: spirv::Word,
14871486
callable_data_id: spirv::Word,

rspirv/sr/autogen_types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@ pub enum Type {
6969
},
7070
PipeStorage,
7171
NamedBarrier,
72+
AccelerationStructureKHR,
7273
}

0 commit comments

Comments
 (0)