From 56928794d0800824dc91e150cb345b5fec24d930 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:30:34 -0700 Subject: Fix incorrect SPV stride for unsized array (#3837) * Fix incorrect SPV stride for unsized array (#3825) In '-emit-spirv-directly' mode, slang generates the stride 0 for unsized array in `OpDecorate` instructions. For unsized array, the stride is invalid, but we need to provide a non-zero value to pass the spirv validator. * Decorate struct with unsized array field as 'Block' For the struct having unsized array fields, it has to be decorated as "Block", otherwise it will fails the spirv-val. So we add a check at in 'emitGlobalInst' when emitting spirv for 'kIROp_StructType', where if there is unsized array field inside the struct, emit a decorate instruction for above purpose. * Update decoration for kIROp_SizeAndAlignmentDecoration When add a decoration node for kIROp_SizeAndAlignmentDecoration, we implicitly convert the 64 bit size to 32 bit. In most cases, this should not be a problem because we won't have that large data type. However, we use 64-bit -1 to represent the size of unsized-array, so in that case, the conversion will change the size to 0, which is incorrect. So change that decoration to use 64-bit size. --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 104735c3e..68c6a33b3 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2649,6 +2649,11 @@ namespace Slang return (IRBasicType*)getType(kIROp_IntType); } + IRBasicType* IRBuilder::getInt64Type() + { + return (IRBasicType*)getType(kIROp_Int64Type); + } + IRBasicType* IRBuilder::getUIntType() { return (IRBasicType*)getType(kIROp_UIntType); -- cgit v1.2.3