Skip to content

Commit

Permalink
spv-in: Fix incorrect translation of SMod (#1995)
Browse files Browse the repository at this point in the history
Since spirv's SMod doesn't map to naga's IR modulo operator the
instruction is mapped into it's direct formula, this formula requires
some casts from int to float and back.

These casts were present but their `convert` field was left to `None`
which implied that they were bitcasts, causing some wildly incorrect
results.

This commit fixes it by setting the `convert` field to the same size as
the result type.
  • Loading branch information
JCapucho authored Jun 30, 2022
1 parent 27d38aa commit b746e0a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,19 +2045,24 @@ impl<I: Iterator<Item = u32>> Parser<I> {
body_idx,
);

let result_ty = self.lookup_type.lookup(result_type_id)?;
let inner = &ctx.type_arena[result_ty.handle].inner;
let kind = inner.scalar_kind().unwrap();
let size = inner.size(ctx.const_arena) as u8;

let left_cast = ctx.expressions.append(
crate::Expression::As {
expr: left,
kind: crate::ScalarKind::Float,
convert: None,
convert: Some(size),
},
span,
);
let right_cast = ctx.expressions.append(
crate::Expression::As {
expr: right,
kind: crate::ScalarKind::Float,
convert: None,
convert: Some(size),
},
span,
);
Expand All @@ -2079,16 +2084,11 @@ impl<I: Iterator<Item = u32>> Parser<I> {
},
span,
);
let result_ty = self.lookup_type.lookup(result_type_id)?;
let kind = ctx.type_arena[result_ty.handle]
.inner
.scalar_kind()
.unwrap();
let cast = ctx.expressions.append(
crate::Expression::As {
expr: floor,
kind,
convert: None,
convert: Some(size),
},
span,
);
Expand Down

0 comments on commit b746e0a

Please sign in to comment.