Skip to content

Commit

Permalink
debug_printf: refactor debug_printf ext_inst handling
Browse files Browse the repository at this point in the history
  • Loading branch information
exrook committed Jan 25, 2024
1 parent 9ee1553 commit b010834
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions naga/src/front/spv/ext_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,31 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
"GLSL.std.450" => self.parse_ext_inst_glsl_std(
ext_name, inst, ext_inst, span, ctx, emitter, block, block_id, body_idx,
),
"NonSemantic.DebugPrintf" if ext_inst.inst_id == 1 => {
self.parse_ext_inst_debug_printf(inst, span, ctx, emitter, block, body_idx)
}
"NonSemantic.DebugPrintf" => self.parse_ext_inst_debug_printf(
ext_name, inst, ext_inst, span, ctx, emitter, block, body_idx,
),

_ => Err(Error::UnsupportedExtInst(ext_inst.inst_id, ext_name)),
}
}
#[allow(clippy::too_many_arguments)]
fn parse_ext_inst_debug_printf(
&mut self,
ext_name: &'static str,
inst: super::Instruction,
ext_inst: ExtInst,
span: crate::Span,
ctx: &mut super::BlockContext,
emitter: &mut crate::proc::Emitter,
block: &mut crate::Block,
body_idx: usize,
) -> Result<(), Error> {
let base_wc = 5;

if ext_inst.inst_id != 1 {
return Err(Error::UnsupportedExtInst(ext_inst.inst_id, ext_name));
}

inst.expect_at_least(base_wc + 1)?;
let format_id = self.next()?;
let format = self.strings.lookup(format_id)?.clone();
Expand All @@ -77,7 +86,7 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
#[allow(clippy::too_many_arguments)]
fn parse_ext_inst_glsl_std(
&mut self,
set_name: &'static str,
ext_name: &'static str,
inst: super::Instruction,
ext_inst: ExtInst,
span: crate::Span,
Expand All @@ -93,7 +102,7 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
let base_wc = 5;

let gl_op = Glo::from_u32(ext_inst.inst_id)
.ok_or(Error::UnsupportedExtInst(ext_inst.inst_id, set_name))?;
.ok_or(Error::UnsupportedExtInst(ext_inst.inst_id, ext_name))?;

let fun = match gl_op {
Glo::Round => Mf::Round,
Expand Down Expand Up @@ -159,15 +168,15 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
Glo::FindUMsb | Glo::FindSMsb => Mf::FindMsb,
// TODO: https://github.com/gfx-rs/naga/issues/2526
Glo::Modf | Glo::Frexp => {
return Err(Error::UnsupportedExtInst(ext_inst.inst_id, set_name))
return Err(Error::UnsupportedExtInst(ext_inst.inst_id, ext_name))
}
Glo::IMix
| Glo::PackDouble2x32
| Glo::UnpackDouble2x32
| Glo::InterpolateAtCentroid
| Glo::InterpolateAtSample
| Glo::InterpolateAtOffset => {
return Err(Error::UnsupportedExtInst(ext_inst.inst_id, set_name))
return Err(Error::UnsupportedExtInst(ext_inst.inst_id, ext_name))
}
};

Expand Down

0 comments on commit b010834

Please sign in to comment.