【发布时间】:2022-01-02 14:39:44
【问题描述】:
我正在将带有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.
我有一个“Metal Family 2 GPU”(Intel Iris Plus Graphics 640,Metal family: Supported, Metal GPUFamily macOS 2),根据 Apple 文档,纹理带有 @987654324 @pixel 格式应该是可写的。
我做错了什么?
这是我用来创建纹理的(部分)代码:
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);
}
【问题讨论】: