From b746e0a4209133c0654d0c8959db97b45cf9358a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Thu, 30 Jun 2022 16:34:42 +0100 Subject: [PATCH] spv-in: Fix incorrect translation of SMod (#1995) 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. --- src/front/spv/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 9f5d710e1b..944d685935 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -2045,11 +2045,16 @@ impl> Parser { 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, ); @@ -2057,7 +2062,7 @@ impl> Parser { crate::Expression::As { expr: right, kind: crate::ScalarKind::Float, - convert: None, + convert: Some(size), }, span, ); @@ -2079,16 +2084,11 @@ impl> Parser { }, 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, );