Search code examples
gpushaderintelmetal

Metal texture format bgra8Unorm_srgb non-writable on Metal Family 2 GPU


I'm passing a texture with MTLPixelFormat.bgra8Unorm_srgb to a compute shader, which has a texture2d<float, access::write> for this texture. I am getting the following error:

  • validateComputeFunctionArguments:818: failed assertion Compute Function(rescaleTexture): Non-writeable texture format MTLPixelFormat.BGRA8Unorm_sRGB is being bound at index 1 to a shader argument with write access enabled.

I've a "Metal Family 2 GPU" (Intel Iris Plus Graphics 640, Metal family: Supported, Metal GPUFamily macOS 2), and according to the Apple documentation, a texture with MTLPixelFormat.BGRA8Unorm_sRGB pixel format should be writable.

What am I doing wrong?

Here is (a part of) the code I use to create the texture(s):

let desc = MTLTextureDescriptor.texture2DDescriptor(
    pixelFormat: MTLPixelFormat.bgra8Unorm_srgb,
    width: outputTextureWidth,
    height: outputTextureHeight,
    mipmapped: false)
desc.usage = [.shaderRead, .shaderWrite]
let tex = device.makeTexture(descriptor: desc)

Here is (a part of) shader code:

kernel void
rescaleTexture(texture2d<float, access::sample> source [[texture(0)]],
               texture2d<float, access::write> target [[texture(1)]],
               uint2 id [[thread_position_in_grid]])
{
    if (id.x >= target.get_width() || id.y >= target.get_height()) {
        return;
    }

    const float u = (float)id.x / (target.get_width () - 1);
    const float v = (float)id.y / (target.get_height () - 1);

    target.write (source.sample (sampler_linear_no_mipmap, float2 (u, v)), id);
}

Solution

  • According The Metal Feature Set Tables: BGRA8Unorm_sRGB texture format of MTLGPUFamilyMac2 processors, have the following capabilities:

    • Filter
    • Color
    • MSAA
    • Resolve
    • Blend

    This mean the texture with format of BGRA8Unorm_sRGB can not be written to by a function on your device.