Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal fix #6413

Merged
merged 2 commits into from
Feb 21, 2025
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
11 changes: 9 additions & 2 deletions source/slang/slang-emit-metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,15 @@ void MetalSourceEmitter::_emitHLSLTextureType(IRTextureTypeBase* texType)
switch (texType->getAccess())
{
case SLANG_RESOURCE_ACCESS_READ:
m_writer->emit("access::sample");
break;
{
// Metal does not support access::sample for texture buffers, so we need to emit
// access::read instead.
if (texType->GetBaseShape() == SLANG_TEXTURE_BUFFER)
m_writer->emit("access::read");
else
m_writer->emit("access::sample");
break;
}

case SLANG_RESOURCE_ACCESS_WRITE:
m_writer->emit("access::write");
Expand Down
17 changes: 17 additions & 0 deletions tests/metal/test_buffer.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Test that Buffer<T> maps to texture_buffer<uint, access::read> in Metal

//TEST:SIMPLE(filecheck=METAL): -stage compute -entry computeMain -target metal


// METAL: texture_buffer<uint, access::read> inputBuffer_{{.*}}
Buffer<uint> inputBuffer;

RWStructuredBuffer<uint> outputBuffer;

[numthreads(4, 1, 1)]
void computeMain(uint3 dtid : SV_DispatchThreadID)
{
uint idx = dtid.x;
// Load values from the buffer to verify correct access
outputBuffer[idx] = inputBuffer.Load(idx);
}
4 changes: 2 additions & 2 deletions tools/gfx/metal/metal-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ Result DeviceImpl::createTextureView(
MTL::PixelFormat pixelFormat = desc.format == Format::Unknown
? textureImpl->m_pixelFormat
: MetalUtil::translatePixelFormat(desc.format);
NS::Range levelRange(sr.baseArrayLayer, sr.layerCount);
NS::Range sliceRange(sr.mipLevel, sr.mipLevelCount);
NS::Range sliceRange(sr.baseArrayLayer, sr.layerCount);
NS::Range levelRange(sr.mipLevel, sr.mipLevelCount);

viewImpl->m_textureView = NS::TransferPtr(textureImpl->m_texture->newTextureView(
pixelFormat,
Expand Down
Loading