-
Notifications
You must be signed in to change notification settings - Fork 23
Description
From #55
为了支持 offscreen 管线,所以需要给 pass 的 lua 封装增加 attachments 的支持。目前 master 上已经提交,不影响之前的接口。
在实现时遇到的几个问题:
当 pass 的 target 是 attachment view 时,需要保证 pipeline 里的 pixel format 和 depth format 都和 pass 的相同。不然 sokol 的校验层会报类似 VALIDATE_APIP_SWAPCHAIN_COLOR_FORMAT: sg_apply_pipeline: the pipeline .colors[0].pixel_format doesn't match the sg_pass.swapchain.color_format 这样的错误。
由于目前 soluna 只处理 2d 图片,所以实际上不使用深度图。在创建渲染 pass 时,如果 attachment 里不绑定 depth ,就需要在渲染管线里指定 .depth.pixel_format = SG_PIXELFORMAT_NONE 。但这会导致直接向 swapchain 渲染时出错,因为几乎所有 swapchain 都是有 depth 的。
暂时没有找到好的方法解决这个兼容问题:即无论是否使用 offscreen pipeline ,正常渲染的 pass 都不需要修改。可能的方法是在初始化 pass 的时候根据 pipeline 配置做不同的构造;或者干脆建两套 pass 适应不同的 pipeline 。这些对于 lua 这种的动态语言环境倒不是大问题。
但目前我倾向于直接在 offscreen pipeline 创建时也创建一个 depth view ,哪怕不用它。这是 sokol 官方教程推荐的方法。而且以后加 3d 渲染,深度总会用得上的。毕竟 2d 只是个特例。
不光是深度通道,颜色通道也有类似问题:
- for the Metal, D3D11 and WebGPU backends: SG_PIXELFORMAT_BGRA8
- for GL backends: SG_PIXELFORMAT_RGBA8
所以如果在 offscreen 管线下,给 attachment 设置固定的 SG_PIXELFORMAT_RGBA8 也会有问题。目前的解决方法是在创建 attachment 用的 image 时,把 pixel_format 填 0 ,这样 sokol 就会使用 swapchain 的格式。
现在在 offscreen 分支上,修改了 render.lua 增加了一个硬编码的 offscreen pipeline 。是纯 lua 写的,buffer 写死为 640x480 。目前跑 deepfuture 看起来没问题。暂时没想好以后怎样在运行时切换管线。
我希望有一个更完善的管线管理接口,不光是 offscreen 这一个需求。