基于内核的瓦片着色器可以写入颜色附件吗?

问题描述 投票:0回答:1

基于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(..)写入图块着色器中的颜色附件,但结果很奇怪:

  1. 仅更改背景像素,但结果比我设置的要暗得多,例如我设置了color = float4(1,0,0,1),但在屏幕上是float4(0.057,0,0,1)
  2. 其他部分的颜色奇怪地取决于在上一片段着色器通道中是否/向图像块写入了什么,请考虑将图像块中的值设置为常量。

无论如何,感觉imageblock.write()在瓷砖着色器中无法正常工作。或如何正确使用它?

ios graphics shader metal iosdeployment
1个回答
0
投票

解决了,有几件事导致我得到了奇怪的结果:1.颜色格式为srgb2.示例项目使用的numSamples是43.我没有指定imageblock_data_rate

进行imageblock写入

在多重采样的情况下,需要为每个采样读/写图像块

© www.soinside.com 2019 - 2024. All rights reserved.