关于vulkan中ImageCreateInfo和ImageViewCreateInfo还有RenderPassCreateInfo中的formate

作者遇到pipeline输出到framebuffer再拷贝到swapchain时颜色通道交换的问题。通过修改imageView Format参数得到不同结果,介绍了RenderPass、Image、ImageView的Format含义,指出image format依读图格式而定,renderpass format与framebuffer的image格式对齐等要点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近遇到个奇怪的问题,pipeline最后输出到一张framebuffer上,然后copy到swapchain,发现颜色的r同道和b通道交换了。在renderdoc上查看发现输出的图像颜色是正确的,拷贝到swapchain上就交换了。感觉很神奇,搞不懂是为啥。后来尝试了下修改不同的imageView Format参数能得到不同的结果,差了下api:

RenderPass Format:

format is a VkFormat value specifying the format of the image view that will be used for the attachment.

Image Format:

format is a VkFormat describing the format and type of the texel blocks that will be contained in the image.

Image View Format:

format is a VkFormat describing the format and type used to interpret texel blocks in the image.

很直白了:

RenderPass 的format是确定输出给attachment的格式,image format表示存储格式,image view format 表示如何采样,也就是如何看待这张图片。

具体来说,image format 应该根据你读图的格式来存储,通常stbi读图是rgba,freeimage是bgra,根据你的读图api决定。其次,你的renderpass format 应该跟你的 framebuffer的image 格式对齐,一个输出一个输入,最后,需要输出到swapchain的framebuffer的image view 格式应该和swapchain格式对齐。而你采样的图片的imageview format应该和图片的image format对齐,方便你在shader中使用。

非常有意思,理清楚了这个关系会觉得这种设计非常舒服。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值