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

sr: Add ray-tracing types and deduce OpPhi type in a consistent way #175

Merged
merged 2 commits into from
Apr 1, 2021
Merged
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
51 changes: 29 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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))
{
if instruction.opname.starts_with("OpType")
// Ignore AccelerationStructureNV which has the same opcode as AccelerationStructureKHR
&& instruction.opname != "OpTypeAccelerationStructureNV"
{
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
53 changes: 53 additions & 0 deletions rspirv/dr/build/autogen_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,57 @@ 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
}
}
#[doc = "Appends an OpTypeCooperativeMatrixNV instruction and returns the result id, or return the existing id if the instruction was already present."]
pub fn type_cooperative_matrix_nv(
&mut self,
component_type: spirv::Word,
execution: spirv::Word,
rows: spirv::Word,
columns: spirv::Word,
) -> spirv::Word {
let mut inst = dr::Instruction::new(
spirv::Op::TypeCooperativeMatrixNV,
None,
None,
vec![
dr::Operand::IdRef(component_type),
dr::Operand::IdScope(execution),
dr::Operand::IdRef(rows),
dr::Operand::IdRef(columns),
],
);
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
}
}
}
56 changes: 28 additions & 28 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 All @@ -5818,32 +5816,6 @@ impl LiftContext {
})
.ok_or(OperandError::Missing)?,
}),
5358u32 => Ok(ops::Op::TypeCooperativeMatrixNV {
component_type: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(self.types.lookup_token(*value)),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
execution: (match operands.next() {
Some(&dr::Operand::IdScope(ref value)) => Some(*value),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
rows: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
columns: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
}),
5359u32 => Ok(ops::Op::CooperativeMatrixLoadNV {
pointer: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
Expand Down Expand Up @@ -8577,6 +8549,34 @@ impl LiftContext {
}),
322u32 => Ok(Type::PipeStorage),
327u32 => Ok(Type::NamedBarrier),
4472u32 => Ok(Type::RayQueryKHR),
5341u32 => Ok(Type::AccelerationStructureKHR),
5358u32 => Ok(Type::CooperativeMatrixNV {
component_type: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(self.types.lookup_token(*value)),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
execution: (match operands.next() {
Some(&dr::Operand::IdScope(ref value)) => Some(*value),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
rows: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
columns: (match operands.next() {
Some(&dr::Operand::IdRef(ref value)) => Some(*value),
Some(_) => Err(OperandError::WrongType)?,
None => None,
})
.ok_or(OperandError::Missing)?,
}),
_ => Err(InstructionError::WrongOpcode),
}
}
Expand Down
8 changes: 0 additions & 8 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,17 +1480,10 @@ pub enum Op {
payload_id: spirv::Word,
},
TypeAccelerationStructureNV,
TypeAccelerationStructureKHR,
ExecuteCallableNV {
sbt_index: spirv::Word,
callable_data_id: spirv::Word,
},
TypeCooperativeMatrixNV {
component_type: Token<Type>,
execution: spirv::Word,
rows: spirv::Word,
columns: spirv::Word,
},
CooperativeMatrixLoadNV {
pointer: spirv::Word,
stride: spirv::Word,
Expand Down
8 changes: 8 additions & 0 deletions rspirv/sr/autogen_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ pub enum Type {
},
PipeStorage,
NamedBarrier,
RayQueryKHR,
AccelerationStructureKHR,
CooperativeMatrixNV {
component_type: Token<Type>,
execution: spirv::Word,
rows: spirv::Word,
columns: spirv::Word,
},
}