Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/slang/slang-emit-spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions source/slang/slang-ir-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions source/slang/slang-ir-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions tests/language-feature/constants/unsized-opaque-array.slang
Original file line number Diff line number Diff line change
@@ -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);
}
Loading