Skip to content

Commit

Permalink
sr: Deduplicate match ranges like spirv header
Browse files Browse the repository at this point in the history
Solve some clippy lints by getting rid of these aliases of overlapping
`Op`s.  Unfortunately, just like in `spirv`, this biases towards the
`NV` rather than `KHR` stabilized raytracing ops.

Note that in `spirv` the `Op`s are aliases in code rather than omitted
altogether: don't think we can do that for the range match here though
unless deducing whether the shader was compiled with the NV or KHR
variant, even though the KHR variant is already stabilized for quite
some time.
  • Loading branch information
MarijnS95 committed Apr 6, 2023
1 parent 3a19780 commit f19da5f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 63 deletions.
8 changes: 8 additions & 0 deletions autogen/src/sr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::BTreeSet;

use crate::structs;
use crate::utils::*;

Expand Down Expand Up @@ -319,12 +321,18 @@ pub fn gen_sr_code_from_instruction_grammar(
let mut field_types = Vec::new();
let mut field_lifts = Vec::new();

let mut seen_discriminator = BTreeSet::new();

// Compose the token stream for all instructions
for inst in grammar_instructions
.iter() // Loop over all instructions
.filter(|i| i.class != Some(structs::Class::Constant))
// Skip constants
{
if !seen_discriminator.insert(inst.opcode) {
continue;
}

// Get the token for its enumerant
let inst_name = &inst.opname[2..];

Expand Down
49 changes: 0 additions & 49 deletions rspirv/lift/autogen_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5849,20 +5849,6 @@ impl LiftContext {
})
.ok_or(OperandError::Missing)?,
}),
5334u32 => Ok(ops::Op::ReportIntersectionKHR {
hit: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(*value),
Some(_) => return Err(OperandError::WrongType.into()),
None => None,
})
.ok_or(OperandError::Missing)?,
hit_kind: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(*value),
Some(_) => return Err(OperandError::WrongType.into()),
None => None,
})
.ok_or(OperandError::Missing)?,
}),
5335u32 => Ok(ops::Op::IgnoreIntersectionNV),
5336u32 => Ok(ops::Op::TerminateRayNV),
5337u32 => Ok(ops::Op::TraceNV {
Expand Down Expand Up @@ -6768,20 +6754,6 @@ impl LiftContext {
})
.ok_or(OperandError::Missing)?,
}),
5632u32 => Ok(ops::Op::DecorateStringGOOGLE {
target: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(*value),
Some(_) => return Err(OperandError::WrongType.into()),
None => None,
})
.ok_or(OperandError::Missing)?,
decoration: (match operands.next() {
Some(dr::Operand::Decoration(value)) => Some(*value),
Some(_) => return Err(OperandError::WrongType.into()),
None => None,
})
.ok_or(OperandError::Missing)?,
}),
5633u32 => Ok(ops::Op::MemberDecorateString {
struct_type: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(self.types.lookup_token(*value)),
Expand All @@ -6802,26 +6774,6 @@ impl LiftContext {
})
.ok_or(OperandError::Missing)?,
}),
5633u32 => Ok(ops::Op::MemberDecorateStringGOOGLE {
struct_type: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(self.types.lookup_token(*value)),
Some(_) => return Err(OperandError::WrongType.into()),
None => None,
})
.ok_or(OperandError::Missing)?,
member: (match operands.next() {
Some(dr::Operand::LiteralBit32(value)) => Some(*value),
Some(_) => return Err(OperandError::WrongType.into()),
None => None,
})
.ok_or(OperandError::Missing)?,
decoration: (match operands.next() {
Some(dr::Operand::Decoration(value)) => Some(*value),
Some(_) => return Err(OperandError::WrongType.into()),
None => None,
})
.ok_or(OperandError::Missing)?,
}),
5699u32 => Ok(ops::Op::VmeImageINTEL {
image_type: (match operands.next() {
Some(dr::Operand::IdRef(value)) => Some(self.types.lookup_token(*value)),
Expand Down Expand Up @@ -11118,7 +11070,6 @@ 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
13 changes: 0 additions & 13 deletions rspirv/sr/autogen_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,10 +1495,6 @@ pub enum Op {
hit: spirv::Word,
hit_kind: spirv::Word,
},
ReportIntersectionKHR {
hit: spirv::Word,
hit_kind: spirv::Word,
},
IgnoreIntersectionNV,
TerminateRayNV,
TraceNV {
Expand Down Expand Up @@ -1736,20 +1732,11 @@ pub enum Op {
target: spirv::Word,
decoration: spirv::Decoration,
},
DecorateStringGOOGLE {
target: spirv::Word,
decoration: spirv::Decoration,
},
MemberDecorateString {
struct_type: Token<Type>,
member: u32,
decoration: spirv::Decoration,
},
MemberDecorateStringGOOGLE {
struct_type: Token<Type>,
member: u32,
decoration: spirv::Decoration,
},
VmeImageINTEL {
image_type: Token<Type>,
sampler: spirv::Word,
Expand Down
1 change: 0 additions & 1 deletion rspirv/sr/autogen_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub enum Type {
PipeStorage,
NamedBarrier,
RayQueryKHR,
AccelerationStructureKHR,
CooperativeMatrixNV {
component_type: Token<Type>,
execution: spirv::Word,
Expand Down

0 comments on commit f19da5f

Please sign in to comment.