【发布时间】:2020-09-20 22:21:10
【问题描述】:
基于 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(..) 写入平铺着色器中的颜色附件,但得到了非常奇怪的结果:
- 只改变了背景的像素,但结果比我设置的要暗得多,例如我设置了 color=float4(1,0,0,1) 但在屏幕上它是 float4(0.057, 0, 0, 1)
- 奇怪的是,其他部分的颜色取决于在之前的片段着色器通道中是否/写入了图像块的内容,考虑我将图像块中的值设置为常量。
无论如何,感觉 imageblock.write() 在平铺着色器中无法正常工作。 或者如何正确使用?
【问题讨论】:
标签: ios graphics shader metal iosdeployment