diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-09-23 20:49:35 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-23 20:49:35 -0700 |
| commit | fd2ac531c0fcb05bba421184b7443dc034281322 (patch) | |
| tree | 13ea22195c0e075d8e4012b307e85ef50168f484 /source/slang | |
| parent | 895405212aa286701031a4f62b6904938105411c (diff) | |
Fix GLSL output for byte-address loads of vectors (#1558)
While working on #1557, it became clear that something was going wrong when using `*ByteAddressBuffer.Load<T>` to load a vector type on GLSL/SPIR-V targets.
The root problem was that the IR-level layout logic (which computes the "natural" layout of a type) had not yet been extended to handle vectors. The fix is simple enough, but it highlights the fact that we probably need to go ahead and "complete" that layout logic sooner or later.
This change includes a test case that covers the behavior added here, as well as the case that #1557 fixes. Unfortunately, due to CI system limitations, the HLSL/dxc part of the test is not yet enabled.
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-ir-layout.cpp | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp index 0003d279a..6ea1093f5 100644 --- a/source/slang/slang-ir-layout.cpp +++ b/source/slang/slang-ir-layout.cpp @@ -49,6 +49,30 @@ namespace Slang { +static Result _calcNaturalArraySizeAndAlignment(IRType* elementType, IRInst* elementCountInst, IRSizeAndAlignment* outSizeAndAlignment) +{ + auto elementCountLit = as<IRIntLit>(elementCountInst); + if(!elementCountLit) + return SLANG_FAIL; + auto elementCount = elementCountLit->getValue(); + + if( elementCount == 0 ) + { + *outSizeAndAlignment = IRSizeAndAlignment(0, 1); + return SLANG_OK; + } + + IRSizeAndAlignment elementTypeLayout; + SLANG_RETURN_ON_FAIL(getNaturalSizeAndAlignment(elementType, &elementTypeLayout)); + + auto elementStride = elementTypeLayout.getStride(); + + *outSizeAndAlignment = IRSizeAndAlignment( + elementStride * (elementCount - 1) + elementTypeLayout.size, + elementTypeLayout.alignment); + return SLANG_OK; +} + static Result _calcNaturalSizeAndAlignment(IRType* type, IRSizeAndAlignment* outSizeAndAlignment) { switch( type->op ) @@ -141,27 +165,21 @@ static Result _calcNaturalSizeAndAlignment(IRType* type, IRSizeAndAlignment* out { auto arrayType = cast<IRArrayType>(type); - auto elementCountLit = as<IRIntLit>(arrayType->getElementCount()); - if(!elementCountLit) - return SLANG_FAIL; - auto elementCount = elementCountLit->getValue(); - - if( elementCount == 0 ) - { - *outSizeAndAlignment = IRSizeAndAlignment(0, 1); - return SLANG_OK; - } - - auto elementType = arrayType->getElementType(); - IRSizeAndAlignment elementTypeLayout; - SLANG_RETURN_ON_FAIL(getNaturalSizeAndAlignment(elementType, &elementTypeLayout)); + return _calcNaturalArraySizeAndAlignment( + arrayType->getElementType(), + arrayType->getElementCount(), + outSizeAndAlignment); + } + break; - auto elementStride = elementTypeLayout.getStride(); + case kIROp_VectorType: + { + auto vecType = cast<IRVectorType>(type); - *outSizeAndAlignment = IRSizeAndAlignment( - elementStride * (elementCount - 1) + elementTypeLayout.size, - elementTypeLayout.alignment); - return SLANG_OK; + return _calcNaturalArraySizeAndAlignment( + vecType->getElementType(), + vecType->getElementCount(), + outSizeAndAlignment); } break; |
