ios - 基于内核的瓷砖着色器可以写入颜色附件吗?
问题描述
基于金属着色语言规范中的示例:
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(..) 写入 tile 着色器中的颜色附件,但我得到了非常奇怪的结果:
- 只有背景的像素被改变,但结果比我设置的要暗得多,例如我设置 color=float4(1,0,0,1) 但在屏幕上它是 float4(0.057, 0, 0, 1)
- 其他部分的颜色奇怪地取决于在前一个片段着色器传递中是否/写入图像块的内容,考虑我将图像块中的值设置为常量。
无论如何,感觉 imageblock.write() 在平铺着色器中无法正常工作。或者如何正确使用?
解决方案
解决了,有几件事导致我得到奇怪的结果: 1. 颜色格式是 srgb 2. 示例项目使用的 numSamples 是 4 3. 我在没有指定 imageblock_data_rate 的情况下进行了 imageblock write
在多重采样的情况下,需要为每个样本读取/写入图像块
推荐阅读
- c - ANSI C YACC 语法中的歧义
- c# - 用于在表中查找一对一关系的 Linq 查询
- laravel - 我想用 v-model 显示消息,但它不起作用
- c# - 如何使用 itextsharp C# 从签名字段中删除有效性未知图标?
- pandoc - 使用 pandoc 将 html 转换为 docx
- java - JdbcRowSet 返回 SQL 异常
- mysql - 连接 4 个表导致空结果
- javascript - 如何限制 Typescript 索引签名的键
- angular - 如何修复“node_modules/@types/prismjs/index.d.ts 错误中的错误找不到所需名称”角度错误
- php - 两个域的 php session_set_cookie_params()