金属纹理格式bgra8Unorm_srgb在Metal Family 2 GPU上不可写入



我正在将一个具有MTLPixelFormat.bgra8Unorm_srgb的纹理传递给一个计算着色器,该着色器对此纹理具有texture2d<float, access::write>。我得到以下错误:

  • 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.

我有一个">金属族2 GPU";(Intel Iris Plus Graphics 640,Metal系列:支持,Metal GPUFamily macOS 2(,根据苹果文档,MTLPixelFormat.BGRA8Unorm_sRGB像素格式的纹理应该是可写的。

我做错了什么?

以下是我用来创建纹理的代码(的一部分(:

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

以下是着色器代码(的一部分(:

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);
}

根据金属特征集合表:MTLGPUFamilyMac2处理器的BGRA8Unorm_sRGB纹理格式,具有以下功能:

  • 过滤器
  • 颜色
  • MSAA
  • 解决
  • 混合

这意味着设备上的函数无法写入格式为BGRA8Unorm_sRGB的纹理。

最新更新