Skip to content
Open
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
7 changes: 4 additions & 3 deletions source/slang/slang-emit-spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3073,9 +3073,10 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
}
if (format == SpvImageFormatUnknown && sampled == ImageOpConstants::readWriteImage)
{
// TODO: It may not be necessary to have both of these
// depending on if we read or write
requireSPIRVCapability(SpvCapabilityStorageImageReadWithoutFormat);
// Write-only textures (WTexture*) only need the write capability.
// Read-write and rasterizer-ordered textures need both.
if (inst->getAccess() != SLANG_RESOURCE_ACCESS_WRITE)
requireSPIRVCapability(SpvCapabilityStorageImageReadWithoutFormat);
requireSPIRVCapability(SpvCapabilityStorageImageWriteWithoutFormat);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/spirv/read-write-image-capability.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//TEST:SIMPLE(filecheck=CHECK):-target spirv -emit-spirv-directly

// When using a read-write texture (RWTexture2D) without an explicit format,
// both StorageImageReadWithoutFormat and StorageImageWriteWithoutFormat
// should be required.
// Companion to write-only-image-capability.slang.

// CHECK-DAG: OpCapability StorageImageReadWithoutFormat
// CHECK-DAG: OpCapability StorageImageWriteWithoutFormat

RWTexture2D<float4> rwTexture;

[shader("compute")]
[numthreads(1, 1, 1)]
void computeMain()
{
rwTexture[int2(0, 0)] = rwTexture[int2(1, 1)];
}
20 changes: 20 additions & 0 deletions tests/spirv/write-only-image-capability.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//TEST:SIMPLE(filecheck=CHECK):-target spirv -emit-spirv-directly

// When using a write-only texture (WTexture2D) without an explicit format,
// only StorageImageWriteWithoutFormat should be required, not
// StorageImageReadWithoutFormat.
// See: https://github.com/shader-slang/slang/issues/9997

// CHECK-NOT: OpCapability StorageImageReadWithoutFormat
// CHECK: OpCapability StorageImageWriteWithoutFormat
// CHECK: OpDecorate {{.*}} NonReadable
// CHECK-NOT: OpCapability StorageImageReadWithoutFormat

WTexture2D<float4> writeOnlyTexture;

[shader("compute")]
[numthreads(1, 1, 1)]
void computeMain()
{
writeOnlyTexture.Store(int2(0, 0), float4(0, 0, 0, 1));
}
Loading