【问题标题】:Can kernel based tile shader write to color attachment?基于内核的瓷砖着色器可以写入颜色附件吗?
【发布时间】: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(..) 写入平铺着色器中的颜色附件,但得到了非常奇怪的结果:

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

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

【问题讨论】:

    标签: ios graphics shader metal iosdeployment


    【解决方案1】:

    已解决,有几件事导致我得到奇怪的结果: 1.颜色格式为srgb 2. 示例项目使用的 numSamples 为 4 3.我做了imageblock write,没有指定imageblock_data_rate

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

    【讨论】:

      猜你喜欢
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      相关资源
      最近更新 更多