summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-06-26 14:39:40 -0500
committerGitHub <noreply@github.com>2025-06-26 12:39:40 -0700
commitbf94fc3f5b73033334db28846580f16df42d6a85 (patch)
tree067435e49aae2e7bc6a9eba138984746f09371c3 /source
parentd166fe8333c7dfc61c32fda5017461858eb4c3fa (diff)
Fix the invalid SPIRV decoration issue (#7527)
* Fix the invalid SPIRV decoration issue Close #7508. SPIRV doesn't allow decoration on type with Private or Function storage class. In our lowering logic, if the array type is used by buffer type it will always have stride operand after lowering, so if the array is not used by buffer type, it must be used only by thread_local or group_shared variable, and it will not have stride operand. For this case, we don't need to emit stride decoration for SPIRV.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-emit-spirv.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 3f3b5e707..7bd20649b 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -2063,14 +2063,21 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
if (shouldEmitArrayStride(irArrayType->getElementType()))
{
auto stride = 0;
+ // If the array type has no stride, it indicates that this array type is only
+ // used in Private or Function storage class (aka. thread-local or function
+ // scope variable), in that case SPIRV doesn't allow to decorate the array
+ // stride.
+ //
+ // The only exception is if the array type is unsized, because unsized array
+ // also has no stride operand, however unsized array can not be used in Private
+ // or Function, so we are safe to just decorate the stride for unsized array by
+ // calculating the natural stride.
if (auto strideInst = irArrayType->getArrayStride())
{
stride = (int)getIntVal(strideInst);
}
- else
+ else if (inst->getOp() == kIROp_UnsizedArrayType)
{
- // Stride may not have been calculated for basic element types. Calculate it
- // here.
IRSizeAndAlignment sizeAndAlignment;
getNaturalSizeAndAlignment(
m_targetProgram->getOptionSet(),
@@ -2079,11 +2086,14 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
stride = (int)sizeAndAlignment.getStride();
}
- emitOpDecorateArrayStride(
- getSection(SpvLogicalSectionID::Annotations),
- nullptr,
- arrayType,
- SpvLiteralInteger::from32(stride));
+ if (stride != 0)
+ {
+ emitOpDecorateArrayStride(
+ getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ arrayType,
+ SpvLiteralInteger::from32(stride));
+ }
}
return arrayType;
}