Skip to content

Commit

Permalink
Globally sort and prefer stabilized over KHR over EXT over vendor opn…
Browse files Browse the repository at this point in the history
…ames
  • Loading branch information
MarijnS95 committed Apr 6, 2023
1 parent f19da5f commit 05d13a1
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 30 deletions.
62 changes: 58 additions & 4 deletions autogen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,68 @@ fn map_reserved_instructions(grammar: &mut structs::Grammar) {
.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"
{
if instruction.opname.starts_with("OpType") {
instruction.class = Some(structs::Class::Type);
}
}
}

fn opname_suffix_weight(opname: &str) -> u32 {
const VENDORS: [&str; 36] = [
"AMD",
"AMDX",
"ANDROID",
"ARM",
"BRCM",
"CHROMIUM",
"EXT",
"FB",
"FSL",
"FUCHSIA",
"GGP",
"GOOGLE",
"HUAWEI",
"IMG",
"INTEL",
"JUICE",
"KDAB",
"KHX",
"LUNARG",
"MESA",
"MVK",
"NN",
"NV",
"NVX",
"NXP",
"NZXT",
"QCOM",
"QNX",
"RASTERGRID",
"RENDERDOC",
"SAMSUNG",
"SEC",
"TIZEN",
"VALVE",
"VIV",
"VSI",
];

match opname {
_ if opname.ends_with("KHR") => 1,
_ if opname.ends_with("EXT") => 2,
_ if VENDORS.iter().any(|v| opname.ends_with(v)) => 3,
_ => 0,
}
}

fn sort_instructions(grammar: &mut structs::Grammar) {
grammar.instructions.sort_by(|l, r| {
l.opcode
.cmp(&r.opcode)
.then_with(|| opname_suffix_weight(&l.opname).cmp(&opname_suffix_weight(&r.opname)))
})
}

fn main() {
// Path to the SPIR-V core grammar file.
let env_var = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -73,6 +126,7 @@ fn main() {
let grammar: structs::Grammar = {
let mut original = serde_json::from_str(&contents).unwrap();
map_reserved_instructions(&mut original);
sort_instructions(&mut original);
original
};

Expand Down
4 changes: 2 additions & 2 deletions autogen/src/sr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ pub fn gen_sr_code_from_instruction_grammar(

// Compose the token stream for all instructions
for inst in grammar_instructions
.iter() // Loop over all instructions
.iter()
// Skip constants
.filter(|i| i.class != Some(structs::Class::Constant))
// Skip constants
{
if !seen_discriminator.insert(inst.opcode) {
continue;
Expand Down
24 changes: 12 additions & 12 deletions rspirv/dr/build/autogen_norm_insts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13729,8 +13729,8 @@ impl Builder {
self.insert_into_block(insert_point, inst)?;
Ok(())
}
#[doc = "Appends an OpReportIntersectionNV instruction to the current block."]
pub fn report_intersection_nv(
#[doc = "Appends an OpReportIntersectionKHR instruction to the current block."]
pub fn report_intersection_khr(
&mut self,
result_type: spirv::Word,
result_id: Option<spirv::Word>,
Expand All @@ -13740,16 +13740,16 @@ impl Builder {
let _id = result_id.unwrap_or_else(|| self.id());
#[allow(unused_mut)]
let mut inst = dr::Instruction::new(
spirv::Op::ReportIntersectionNV,
spirv::Op::ReportIntersectionKHR,
Some(result_type),
Some(_id),
vec![dr::Operand::IdRef(hit), dr::Operand::IdRef(hit_kind)],
);
self.insert_into_block(InsertPoint::End, inst)?;
Ok(_id)
}
#[doc = "Appends an OpReportIntersectionNV instruction to the current block."]
pub fn insert_report_intersection_nv(
#[doc = "Appends an OpReportIntersectionKHR instruction to the current block."]
pub fn insert_report_intersection_khr(
&mut self,
insert_point: InsertPoint,
result_type: spirv::Word,
Expand All @@ -13760,16 +13760,16 @@ impl Builder {
let _id = result_id.unwrap_or_else(|| self.id());
#[allow(unused_mut)]
let mut inst = dr::Instruction::new(
spirv::Op::ReportIntersectionNV,
spirv::Op::ReportIntersectionKHR,
Some(result_type),
Some(_id),
vec![dr::Operand::IdRef(hit), dr::Operand::IdRef(hit_kind)],
);
self.insert_into_block(insert_point, inst)?;
Ok(_id)
}
#[doc = "Appends an OpReportIntersectionKHR instruction to the current block."]
pub fn report_intersection_khr(
#[doc = "Appends an OpReportIntersectionNV instruction to the current block."]
pub fn report_intersection_nv(
&mut self,
result_type: spirv::Word,
result_id: Option<spirv::Word>,
Expand All @@ -13779,16 +13779,16 @@ impl Builder {
let _id = result_id.unwrap_or_else(|| self.id());
#[allow(unused_mut)]
let mut inst = dr::Instruction::new(
spirv::Op::ReportIntersectionKHR,
spirv::Op::ReportIntersectionNV,
Some(result_type),
Some(_id),
vec![dr::Operand::IdRef(hit), dr::Operand::IdRef(hit_kind)],
);
self.insert_into_block(InsertPoint::End, inst)?;
Ok(_id)
}
#[doc = "Appends an OpReportIntersectionKHR instruction to the current block."]
pub fn insert_report_intersection_khr(
#[doc = "Appends an OpReportIntersectionNV instruction to the current block."]
pub fn insert_report_intersection_nv(
&mut self,
insert_point: InsertPoint,
result_type: spirv::Word,
Expand All @@ -13799,7 +13799,7 @@ impl Builder {
let _id = result_id.unwrap_or_else(|| self.id());
#[allow(unused_mut)]
let mut inst = dr::Instruction::new(
spirv::Op::ReportIntersectionKHR,
spirv::Op::ReportIntersectionNV,
Some(result_type),
Some(_id),
vec![dr::Operand::IdRef(hit), dr::Operand::IdRef(hit_kind)],
Expand Down
27 changes: 27 additions & 0 deletions rspirv/dr/build/autogen_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,33 @@ impl Builder {
new_id
}
}
#[doc = "Appends an OpTypeAccelerationStructureNV instruction and returns the result id, or return the existing id if the instruction was already present."]
pub fn type_acceleration_structure_nv(&mut self) -> spirv::Word {
self.type_acceleration_structure_nv_id(None)
}
#[doc = "Appends an OpTypeAccelerationStructureNV instruction and returns the result id, or return the existing id if the instruction was already present."]
pub fn type_acceleration_structure_nv_id(
&mut self,
result_id: Option<spirv::Word>,
) -> spirv::Word {
let mut inst = dr::Instruction::new(
spirv::Op::TypeAccelerationStructureNV,
None,
result_id,
vec![],
);
if let Some(result_id) = result_id {
self.module.types_global_values.push(inst);
result_id
} else 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,
Expand Down
8 changes: 4 additions & 4 deletions rspirv/grammar/autogen_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,7 @@ static INSTRUCTION_TABLE: &[Instruction<'static>] = &[
[(IdRef, One), (IdRef, One)]
),
inst!(
ReportIntersectionNV,
ReportIntersectionKHR,
[RayTracingNV, RayTracingKHR],
["SPV_NV_ray_tracing", "SPV_KHR_ray_tracing"],
[
Expand All @@ -3606,7 +3606,7 @@ static INSTRUCTION_TABLE: &[Instruction<'static>] = &[
]
),
inst!(
ReportIntersectionKHR,
ReportIntersectionNV,
[RayTracingNV, RayTracingKHR],
["SPV_NV_ray_tracing", "SPV_KHR_ray_tracing"],
[
Expand Down Expand Up @@ -3680,7 +3680,7 @@ static INSTRUCTION_TABLE: &[Instruction<'static>] = &[
]
),
inst!(
TypeAccelerationStructureNV,
TypeAccelerationStructureKHR,
[RayTracingNV, RayTracingKHR, RayQueryKHR],
[
"SPV_NV_ray_tracing",
Expand All @@ -3690,7 +3690,7 @@ static INSTRUCTION_TABLE: &[Instruction<'static>] = &[
[(IdResult, One)]
),
inst!(
TypeAccelerationStructureKHR,
TypeAccelerationStructureNV,
[RayTracingNV, RayTracingKHR, RayQueryKHR],
[
"SPV_NV_ray_tracing",
Expand Down
4 changes: 2 additions & 2 deletions rspirv/lift/autogen_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5835,7 +5835,7 @@ impl LiftContext {
})
.ok_or(OperandError::Missing)?,
}),
5334u32 => Ok(ops::Op::ReportIntersectionNV {
5334u32 => Ok(ops::Op::ReportIntersectionKHR {
hit: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(*value),
Some(_) => return Err(OperandError::WrongType.into()),
Expand Down Expand Up @@ -6067,7 +6067,6 @@ impl LiftContext {
})
.ok_or(OperandError::Missing)?,
}),
5341u32 => Ok(ops::Op::TypeAccelerationStructureNV),
5344u32 => Ok(ops::Op::ExecuteCallableNV {
sbt_index: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(*value),
Expand Down Expand Up @@ -11070,6 +11069,7 @@ 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(value)) => Some(self.types.lookup_token(*value)),
Expand Down
3 changes: 1 addition & 2 deletions rspirv/sr/autogen_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ pub enum Op {
index_offset: spirv::Word,
packed_indices: spirv::Word,
},
ReportIntersectionNV {
ReportIntersectionKHR {
hit: spirv::Word,
hit_kind: spirv::Word,
},
Expand Down Expand Up @@ -1538,7 +1538,6 @@ pub enum Op {
time: spirv::Word,
payload: spirv::Word,
},
TypeAccelerationStructureNV,
ExecuteCallableNV {
sbt_index: spirv::Word,
callable_data_id: spirv::Word,
Expand Down
1 change: 1 addition & 0 deletions rspirv/sr/autogen_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub enum Type {
PipeStorage,
NamedBarrier,
RayQueryKHR,
AccelerationStructureKHR,
CooperativeMatrixNV {
component_type: Token<Type>,
execution: spirv::Word,
Expand Down
8 changes: 4 additions & 4 deletions spirv/autogen_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2859,13 +2859,13 @@ pub enum Op {
ImageSampleFootprintNV = 5283u32,
GroupNonUniformPartitionNV = 5296u32,
WritePackedPrimitiveIndices4x8NV = 5299u32,
ReportIntersectionNV = 5334u32,
ReportIntersectionKHR = 5334u32,
IgnoreIntersectionNV = 5335u32,
TerminateRayNV = 5336u32,
TraceNV = 5337u32,
TraceMotionNV = 5338u32,
TraceRayMotionNV = 5339u32,
TypeAccelerationStructureNV = 5341u32,
TypeAccelerationStructureKHR = 5341u32,
ExecuteCallableNV = 5344u32,
TypeCooperativeMatrixNV = 5358u32,
CooperativeMatrixLoadNV = 5359u32,
Expand Down Expand Up @@ -3193,8 +3193,8 @@ impl Op {
#[allow(clippy::upper_case_acronyms)]
#[allow(non_upper_case_globals)]
impl Op {
pub const ReportIntersectionKHR: Op = Op::ReportIntersectionNV;
pub const TypeAccelerationStructureKHR: Op = Op::TypeAccelerationStructureNV;
pub const ReportIntersectionNV: Op = Op::ReportIntersectionKHR;
pub const TypeAccelerationStructureNV: Op = Op::TypeAccelerationStructureKHR;
pub const DecorateStringGOOGLE: Op = Op::DecorateString;
pub const MemberDecorateStringGOOGLE: Op = Op::MemberDecorateString;
}
Expand Down

0 comments on commit 05d13a1

Please sign in to comment.