diff options
| author | Darren Wihandi <65404740+fairywreath@users.noreply.github.com> | 2025-05-16 15:01:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-16 12:01:24 -0700 |
| commit | da951e06e7eb8ad1b9c91d6176be8165ea4f2b45 (patch) | |
| tree | 84df8551021ad8806531fc2ed59058f65fbfa256 /source/slang/slang-emit-spirv.cpp | |
| parent | 0244c96d637f47fa264d441a82d3dca78889373b (diff) | |
Address structured buffer `GetDimensions` issues for WGSL, GLSL and SPIRV (#7010)
* Fix structured buffer get dimensions
* Further fixes and added tests
* Remove unnecessary include
* Fix test issues
* attempt to fix wgpu crash
* test remove half usage in test
* attempt to fix WGPU test issue
* Another attempt to fix WGSL test - make test similar to the existing GetDimensions test
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 7d202c7c1..54417899c 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -6878,12 +6878,21 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex kResultID, inst->getOperand(0), SpvLiteralInteger::from32(0)); - auto elementType = as<IRPtrType>(inst->getOperand(0)->getDataType())->getValueType(); - IRIntegerValue stride = 0; - if (auto sizeDecor = elementType->findDecoration<IRSizeAndAlignmentDecoration>()) - { - stride = align(sizeDecor->getSize(), (int)sizeDecor->getAlignment()); - } + + // The buffer is a global parameter, so it's a pointer + auto bufPtrType = cast<IRPtrTypeBase>(inst->getOperand(0)->getDataType()); + // It's lowered to a struct type.. + auto bufType = cast<IRStructType>(bufPtrType->getValueType()); + // containing an unsized array, specifically one with an explicit + // stride, which is not expressible in spirv_asm blocks + auto arrayType = cast<IRArrayTypeBase>(bufType->getFields().getFirst()->getFieldType()); + + // The element type should have a `SizeAndAlignment` decoration created during lowering. + auto sizeDecor = + arrayType->getElementType()->findDecoration<IRSizeAndAlignmentDecoration>(); + SLANG_ASSERT(sizeDecor); + const auto stride = align(sizeDecor->getSize(), (int)sizeDecor->getAlignment()); + auto strideOperand = emitIntConstant(stride, builder.getUIntType()); auto result = emitOpCompositeConstruct(parent, inst, inst->getDataType(), arrayLength, strideOperand); |
