From 20afbfea3134050fa93e48b5bb4edd59552384ec Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Thu, 3 Jul 2025 09:38:23 -0700 Subject: Don't use access::sample for multisample texture in metal (#7601) * don't use access::sample for multisample texture * Add test case * format code (#7603) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --------- Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-emit-metal.cpp | 6 +++--- tests/metal/texture-multisample.slang | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/metal/texture-multisample.slang diff --git a/source/slang/slang-emit-metal.cpp b/source/slang/slang-emit-metal.cpp index a2e339942..9232fc95d 100644 --- a/source/slang/slang-emit-metal.cpp +++ b/source/slang/slang-emit-metal.cpp @@ -138,9 +138,9 @@ void MetalSourceEmitter::_emitHLSLTextureType(IRTextureTypeBase* texType) { case SLANG_RESOURCE_ACCESS_READ: { - // Metal does not support access::sample for texture buffers, so we need to emit - // access::read instead. - if (texType->GetBaseShape() == SLANG_TEXTURE_BUFFER) + // Metal does not support access::sample for texture buffers and multisampled textures, + // so we need to emit access::read instead. + if (texType->GetBaseShape() == SLANG_TEXTURE_BUFFER || texType->isMultisample()) m_writer->emit("access::read"); else m_writer->emit("access::sample"); diff --git a/tests/metal/texture-multisample.slang b/tests/metal/texture-multisample.slang new file mode 100644 index 000000000..4bd6e3be0 --- /dev/null +++ b/tests/metal/texture-multisample.slang @@ -0,0 +1,16 @@ +//TEST:SIMPLE(filecheck=METAL): -stage compute -entry computeMain -target metal -DEMIT_SOURCE + +// TEST_INPUT: RWTexture2D(size=4, content = zero, sampleCount=2):name texMS +Texture2DMS texMS; +// TEST_INPUT: RWTexture2D(size=4, content = zero):name output +RWTexture2D output; + +[numthreads(1, 1, 1)] +void computeMain() +{ + int2 location = int2(0, 0); + uint sampleIndex = 0; + // METAL: {{.*}}access::read{{.*}} + float4 v = texMS.Load(location, sampleIndex); + output[location] = v; +} \ No newline at end of file -- cgit v1.2.3