gpt4 book ai didi

ios - Metal RGB 到 YUV 转换计算着色器

转载 作者:行者123 更新时间:2023-12-01 15:57:40 26 4
gpt4 key购买 nike

我正在尝试编写用于从 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'

enter image description here我做错了什么?

最佳答案

根据 Metal 着色语言规范,write 的所有重载的第一个参数在 texture2d<>是 4 元素向量。即使您写入的纹理少于 4 个组件,情况也是如此。因此,您可以通过将错误行替换为以下内容来解决此问题:

textureCbCr.write(half4(yuv.xyzz), uint2(gid.x / 2, gid.y / 2));

并且在执行写入时,多余的组件将被屏蔽掉。

关于ios - Metal RGB 到 YUV 转换计算着色器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57348166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com