summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-type-layout.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-06-08 07:44:05 -0700
committerGitHub <noreply@github.com>2021-06-08 10:44:05 -0400
commit6cee1eeda28c1ce1e5d326a0c43427b4776a1d09 (patch)
tree6e4559e48fecf5f71aece8b128184925b2d0f790 /source/slang/slang-type-layout.cpp
parentfb50fab76a723f46026474ea5bb0226c297d1fd5 (diff)
Various fixes to CUDA backend. (#1877)
- Fix emitting `StructuredBuffer<ISomething>::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 <yhe@nvidia.com> Co-authored-by: jsmall-nvidia <jsmall@nvidia.com>
Diffstat (limited to 'source/slang/slang-type-layout.cpp')
-rw-r--r--source/slang/slang-type-layout.cpp16
1 files changed, 14 insertions, 2 deletions
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;
}