我將一個帶有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),根據(jù)蘋果的文檔,具有MTLPixelFormat.BGRA8Unorm_sRGB
像素格式的紋理應(yīng)該是可寫的。
我做錯了什么?
以下是我用來創(chuàng)建紋理的(部分)代碼:
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);
}
根據(jù)金屬特征集表格:BGRA8Unorm_sRGBMTLGPUFamilyMac2處理器的紋理格式具有以下功能:
這意味著設(shè)備上的函數(shù)無法寫入格式為BGRA8Unorm_sRGB的紋理。