【发布时间】:2019-12-12 08:40:54
【问题描述】:
我正在尝试编写用于从 RGB 转换为 YUV 的 Metal 计算着色器,但出现构建错误。
typedef struct {
float3x3 matrix;
float3 offset;
} ColorConversion;
// Compute kernel
kernel void kernelRGBtoYUV(texture2d<half, access::sample> inputTexture [[ texture(0) ]],
texture2d<half, access::write> textureY [[ texture(1) ]],
texture2d<half, access::write> textureCbCr [[ texture(2) ]],
constant ColorConversion &colorConv [[ buffer(0) ]],
uint2 gid [[thread_position_in_grid]])
{
// Make sure we don't read or write outside of the texture
if ((gid.x >= inputTexture.get_width()) || (gid.y >= inputTexture.get_height())) {
return;
}
float3 inputColor = float3(inputTexture.read(gid).rgb);
float3 yuv = colorConv.matrix*inputColor + colorConv.offset;
half2 uv = half2(yuv.gb);
textureY.write(half(yuv.x), gid);
if (gid.x % 2 == 0 && gid.y % 2 == 0) {
textureCbCr.write(uv, uint2(gid.x / 2, gid.y / 2));
}
}
最后一行,即写入textureCbCr会抛出错误:
no matching member function for call to 'write'
【问题讨论】:
-
这是一个 texture2d,已在计算着色器中声明为参数。
-
应该是rg,只有两个颜色分量。
-
您能解释一下您是如何使用
ColorConversion结构的吗?offset是什么意思,转换矩阵不总是一样的吗? -
Deepak,你能分享一下工作示例代码吗?我有同样的要求,这对我有很大帮助。
标签: ios opengl-es metal metalkit metal-performance-shaders