From 6cee1eeda28c1ce1e5d326a0c43427b4776a1d09 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 8 Jun 2021 07:44:05 -0700 Subject: Various fixes to CUDA backend. (#1877) - Fix emitting `StructuredBuffer::Load`, which triggers emitting for `IROp_WrapExistential` that is previously unhandled. - Fix cuda layout around vectors, they should be aligned to 1,2,4,8,16 bytes instead of just using element type's alignment. That means `float4` has alignment of 16 instead of 4. - Fix `SLANG_CUDA_HANDLE_ERROR` macro definition. - Fix navis sometimes fail to find `Slang::kIROp_*` enum values when debugging external projects. Co-authored-by: Yong He Co-authored-by: jsmall-nvidia --- source/slang/slang-type-layout.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-type-layout.cpp') diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index 2568547a4..02b5b5bdc 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -465,6 +465,18 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl return arrayInfo; } + // Given `size` between [0, 16] return the smallest power-of-2 that is greater than or equal to `size`. + uint32_t getVectorAlignment(uint32_t size) + { + SLANG_ASSERT(size <= 16); + --size; + // Set every bit after the highest bit. + size |= (size >> 1); + size |= (size >> 2); + ++size; + return size; + } + SimpleLayoutInfo GetVectorLayout(BaseType elementType, SimpleLayoutInfo elementInfo, size_t elementCount) override { // Special case bool @@ -479,8 +491,8 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl SimpleLayoutInfo vectorInfo; vectorInfo.kind = elementInfo.kind; vectorInfo.size = elementInfo.size * elementCount; - vectorInfo.alignment = elementInfo.alignment; - + vectorInfo.alignment = getVectorAlignment( + (uint32_t)(elementInfo.size.getFiniteValue() * elementCount)); return vectorInfo; } -- cgit v1.2.3