From a8929603acbb68236e795fc00ca2706ab0f57411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Fri, 7 Jan 2022 15:07:55 +0000 Subject: [PATCH] spv-in: OpVectorInsertDynamic allow unsigned index --- src/front/spv/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 4de53aad07..e1de8bdaf6 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -1687,7 +1687,24 @@ impl> Parser { let root_handle = get_expr_handle!(composite_id, root_lexp); let root_type_lookup = self.lookup_type.lookup(root_lexp.type_id)?; let index_lexp = self.lookup_expression.lookup(index_id)?; - let index_handle = get_expr_handle!(index_id, index_lexp); + let mut index_handle = get_expr_handle!(index_id, index_lexp); + let index_type = self.lookup_type.lookup(index_lexp.type_id)?.handle; + + // SPIR-V allows signed and unsigned indices but naga's is strict about + // types and since the `index_constants` are all signed integers, we need + // to cast the index to a signed integer if it's unsigned. + if let Some(crate::ScalarKind::Uint) = + ctx.type_arena[index_type].inner.scalar_kind() + { + index_handle = ctx.expressions.append( + crate::Expression::As { + expr: index_handle, + kind: crate::ScalarKind::Sint, + convert: None, + }, + span, + ) + } let num_components = match ctx.type_arena[root_type_lookup.handle].inner { crate::TypeInner::Vector { size, .. } => size as usize,