基于Metal着色语言规范中的示例:
Example:
struct Foo {
float4 a [[color(0)]];
int4 b [[color(1)]];
};
kernel void
my_kernel(imageblock<Foo, imageblock_layout_implicit> img_blk,
ushort2 lid [[thread_index_in_threadgroup]] …)
{
…
Foo f = img_blk.read(lid); float4 r = f.a;
…
f.a = r;
…
img_blk.write(f, lid);
}
作为图像块别名颜色附件的成员,我认为在“ imgblk.write(...)”之后,图像块将被写入相应的颜色附件。
[我在Apple的示例上进行了实验:Forward-plus with tile shading,我尝试使用imageblock.write(..)写入图块着色器中的颜色附件,但结果很奇怪:
无论如何,感觉imageblock.write()在瓷砖着色器中无法正常工作。或如何正确使用它?
解决了,有几件事导致我得到了奇怪的结果:1.颜色格式为srgb2.示例项目使用的numSamples是43.我没有指定imageblock_data_rate
进行imageblock写入在多重采样的情况下,需要为每个采样读/写图像块