Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generating OpTypeAccelerationStructureKHR #187

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion autogen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ fn write_formatted(path: &PathBuf, contents: impl ToString) {
};
}

/// Maps some reserved instructions in the spec into their expected class in
/// order to generate the proper methods for those instructions.
fn map_reserved_instructions(grammar: &mut structs::Grammar) {
for instruction in grammar
.instructions
.iter_mut()
.filter(|i| i.class == Some(structs::Class::Reserved))
{
match &*instruction.opname {
| "OpTypeAccelerationStructureKHR"
| "OpTypeRayQueryKHR"
=> instruction.class = Some(structs::Class::Type),
_ => {}
}
}
}

fn main() {
// Path to the SPIR-V core grammar file.
let env_var = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -52,7 +69,12 @@ fn main() {
let mut file = fs::File::open(path).unwrap();
file.read_to_string(&mut contents).unwrap();
}
let grammar: structs::Grammar = serde_json::from_str(&contents).unwrap();

let grammar: structs::Grammar = {
let mut original = serde_json::from_str(&contents).unwrap();
map_reserved_instructions(&mut original);
original
};

// For GLSLstd450 extended instruction set.
{
Expand Down
25 changes: 25 additions & 0 deletions rspirv/dr/build/autogen_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,29 @@ impl Builder {
new_id
}
}
#[doc = "Appends an OpTypeRayQueryKHR instruction and returns the result id, or return the existing id if the instruction was already present."]
pub fn type_ray_query_khr(&mut self) -> spirv::Word {
let mut inst = dr::Instruction::new(spirv::Op::TypeRayQueryKHR, None, None, vec![]);
if let Some(id) = self.dedup_insert_type(&inst) {
id
} else {
let new_id = self.id();
inst.result_id = Some(new_id);
self.module.types_global_values.push(inst);
new_id
}
}
#[doc = "Appends an OpTypeAccelerationStructureKHR instruction and returns the result id, or return the existing id if the instruction was already present."]
pub fn type_acceleration_structure_khr(&mut self) -> spirv::Word {
let mut inst =
dr::Instruction::new(spirv::Op::TypeAccelerationStructureKHR, None, None, vec![]);
if let Some(id) = self.dedup_insert_type(&inst) {
id
} else {
let new_id = self.id();
inst.result_id = Some(new_id);
self.module.types_global_values.push(inst);
new_id
}
}
}
4 changes: 2 additions & 2 deletions rspirv/lift/autogen_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5338,7 +5338,6 @@ impl LiftContext {
})
.ok_or(OperandError::Missing)?,
}),
4472u32 => Ok(ops::Op::TypeRayQueryKHR),
4473u32 => Ok(ops::Op::RayQueryInitializeKHR {
ray_query: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
Expand Down Expand Up @@ -5803,7 +5802,6 @@ impl LiftContext {
.ok_or(OperandError::Missing)?,
}),
5341u32 => Ok(ops::Op::TypeAccelerationStructureNV),
5341u32 => Ok(ops::Op::TypeAccelerationStructureKHR),
5344u32 => Ok(ops::Op::ExecuteCallableNV {
sbt_index: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
Expand Down Expand Up @@ -8577,6 +8575,8 @@ impl LiftContext {
}),
322u32 => Ok(Type::PipeStorage),
327u32 => Ok(Type::NamedBarrier),
4472u32 => Ok(Type::RayQueryKHR),
5341u32 => Ok(Type::AccelerationStructureKHR),
_ => Err(InstructionError::WrongOpcode),
}
}
Expand Down
2 changes: 0 additions & 2 deletions rspirv/sr/autogen_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,6 @@ pub enum Op {
ConvertUToAccelerationStructureKHR {
accel: spirv::Word,
},
TypeRayQueryKHR,
RayQueryInitializeKHR {
ray_query: spirv::Word,
accel: spirv::Word,
Expand Down Expand Up @@ -1481,7 +1480,6 @@ pub enum Op {
payload_id: spirv::Word,
},
TypeAccelerationStructureNV,
TypeAccelerationStructureKHR,
ExecuteCallableNV {
sbt_index: spirv::Word,
callable_data_id: spirv::Word,
Expand Down
2 changes: 2 additions & 0 deletions rspirv/sr/autogen_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ pub enum Type {
},
PipeStorage,
NamedBarrier,
RayQueryKHR,
AccelerationStructureKHR,
}