summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerran Schmidt <jerrans@nvidia.com>2025-07-02 14:22:42 +1000
committerGitHub <noreply@github.com>2025-07-02 04:22:42 +0000
commit7ffb9f53e41c409a51c41318442067cc6c7e4f48 (patch)
tree9934b27fd55e4720d0a2941fd0a339ffcb34c2e5
parent415adcfd774d30d90e62d15bb7b814464f6930a6 (diff)
Fix for emitting ArrayStride decoration for arrays of opaque types (#7568)
* WIP opaque type decoration fix * Clearer intent * Formatting * Added test for fix
-rw-r--r--source/slang/slang-emit-spirv.cpp4
-rw-r--r--source/slang/slang-ir-util.cpp13
-rw-r--r--source/slang/slang-ir-util.h2
-rw-r--r--tests/language-feature/constants/unsized-opaque-array.slang14
4 files changed, 32 insertions, 1 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 62c667de1..7f6202a7f 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -2060,7 +2060,9 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
inst->getOp() == kIROp_ArrayType
? emitOpTypeArray(inst, elementType, irArrayType->getElementCount())
: emitOpTypeRuntimeArray(inst, elementType);
- if (shouldEmitArrayStride(irArrayType->getElementType()))
+ // Arrays of opaque types should not emit a stride
+ if (!isIROpaqueType(elementType) &&
+ shouldEmitArrayStride(irArrayType->getElementType()))
{
auto stride = 0;
// If the array type has no stride, it indicates that this array type is only
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp
index 687841d5e..69bd2c6c2 100644
--- a/source/slang/slang-ir-util.cpp
+++ b/source/slang/slang-ir-util.cpp
@@ -2408,4 +2408,17 @@ bool isSignedType(IRType* type)
}
}
+bool isIROpaqueType(IRType* type)
+{
+ switch (type->getOp())
+ {
+ case kIROp_TextureType:
+ case kIROp_SamplerStateType:
+ case kIROp_SamplerComparisonStateType:
+ return true;
+ default:
+ return false;
+ }
+}
+
} // namespace Slang
diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h
index edb8fdf09..e325fbdc2 100644
--- a/source/slang/slang-ir-util.h
+++ b/source/slang/slang-ir-util.h
@@ -421,6 +421,8 @@ constexpr bool anyOf(Range&& range, Predicate&& pred)
IRType* getUnsignedTypeFromSignedType(IRBuilder* builder, IRType* type);
bool isSignedType(IRType* type);
+
+bool isIROpaqueType(IRType* type);
} // namespace Slang
#endif
diff --git a/tests/language-feature/constants/unsized-opaque-array.slang b/tests/language-feature/constants/unsized-opaque-array.slang
new file mode 100644
index 000000000..2aab695f6
--- /dev/null
+++ b/tests/language-feature/constants/unsized-opaque-array.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry main -emit-spirv-directly
+
+// SPIRV-NOT: OpDecorate {{.*}} ArrayStride 8
+layout(binding = 0)
+Texture2D textures[];
+
+RWTexture2D<uint> tex;
+
+[shader("compute")]
+[numthreads(1,1,1)]
+void main(uint3 threadId : SV_DispatchThreadID)
+{
+ tex[threadId.xy] = uint(textures[0][threadId.xy].r);
+} \ No newline at end of file