Skip to content

Commit 84130b8

Browse files
committed
Fix invalid access mode for texture_buffer
1 parent 9580e31 commit 84130b8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

source/slang/slang-emit-metal.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,15 @@ void MetalSourceEmitter::_emitHLSLTextureType(IRTextureTypeBase* texType)
136136
switch (texType->getAccess())
137137
{
138138
case SLANG_RESOURCE_ACCESS_READ:
139-
m_writer->emit("access::sample");
140-
break;
139+
{
140+
// Metal does not support access::sample for texture buffers, so we need to emit
141+
// access::read instead.
142+
if (texType->GetBaseShape() == SLANG_TEXTURE_BUFFER)
143+
m_writer->emit("access::read");
144+
else
145+
m_writer->emit("access::sample");
146+
break;
147+
}
141148

142149
case SLANG_RESOURCE_ACCESS_WRITE:
143150
m_writer->emit("access::write");

tests/metal/test_buffer.slang

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test that Buffer<T> maps to texture_buffer<uint, access::read> in Metal
2+
3+
//TEST:SIMPLE(filecheck=METAL): -stage compute -entry computeMain -target metal
4+
5+
6+
// METAL: texture_buffer<uint, access::read> inputBuffer_{{.*}}
7+
Buffer<uint> inputBuffer;
8+
9+
RWStructuredBuffer<uint> outputBuffer;
10+
11+
[numthreads(4, 1, 1)]
12+
void computeMain(uint3 dtid : SV_DispatchThreadID)
13+
{
14+
uint idx = dtid.x;
15+
// Load values from the buffer to verify correct access
16+
outputBuffer[idx] = inputBuffer.Load(idx);
17+
}

0 commit comments

Comments
 (0)