OpenGL和Vulkan的Color Renderable Format

本文探讨了OpenGL ES 2.0和Vulkan在颜色渲染格式上的差异。OpenGL的渲染格式相对简单,而Vulkan则更为复杂,需要考虑Sampleable和Renderable两种资源类型,并通过VkFormatFeatureFlagBits来确定不同用途的Image格式。Vulkan中,创建ImageView时,如果包含VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,系统会自动追加VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT属性,表明该格式可用于颜色附件。

Color Renderable format通常指的是作为GPU输出缓冲区的attachment的资源格式。
OpenGL纹理的Color Renderable是确定的,种类也很少。
Vulkan的Image/Texture资源可以分为两种: Sampleable,Renderable。其中Vulkan的Renderable,比OpenGL的要复杂,种类相对要多很多。

本文介绍两者在使用上的区别。

OpenGL ES 2.0

OpenGL的Renderable很简单,根据OpenGL ES 2.0的规范,下面这些格式才是Renderable(包括了Color Renderable):

在这里插入图片描述

Vulkan

Vulkan的情形要复杂一些,每个不同用途的Image,支持的格式都是有区别的。
所以Vulkan在处理Image的格式的时候分为两步:

  • 先确定Image的用途
    通过VkFormatFeatureFlagBits来确定Image的不同用途。譬如作为输出的Swap chain Image 通常是VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT 类型。

  • 每种用途的Image有着对应的Image格式
    在https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html, “37.3. Required Format Support”里面提到了每种格式。

但是Spec里面确实也有Color Renderable Format的描述。主要的意思是,在VkImageFormatProperties::linearTilingFeatures或者VkImageFormatProperties::optimalTilingFeatures里面设置了VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT属性的VkFormat就是Color Renderable的。所以Color Renderable可以理解为:

VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT && VkFormat

有意思的是,在SW的Vulkan例子程序里面,并没有找到VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT的使用。但是在Spec里面还有一个说法:在创建ImageView的时候,如果VkImageViewCreateInfo.usage包括了VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
那么image view’s format features必须包含VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT。例子里面确实包含了VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT。所以我理解的是,检测到VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,系统会自动给image view’s format features追加属性VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT。

那么,什么是Image View Format Features呢?其实和前面提到的VkImageFormatProperties很类似:

typedef struct VkFormatProperties {
    VkFormatFeatureFlags    linearTilingFeatures;
    VkFormatFeatureFlags    optimalTilingFeatures;
    VkFormatFeatureFlags    bufferFeatures;
} VkFormatProperties;

Vulkan spec还提供了一个表格,汇合了所有的Image格式:
“The following image formats can be passed to, and may be returned from Vulkan commands.”:
https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkFormat

root@localhost:~# eglinfo EGL client extensions string: EGL_EXT_device_base EGL_EXT_device_enumeration EGL_EXT_device_query EGL_EXT_platform_base EGL_KHR_client_get_all_proc_addresses EGL_EXT_client_extensions EGL_KHR_debug EGL_EXT_platform_device EGL_EXT_platform_wayland EGL_KHR_platform_wayland EGL_EXT_platform_x11 EGL_KHR_platform_x11 EGL_EXT_platform_xcb EGL_MESA_platform_gbm EGL_KHR_platform_gbm EGL_MESA_platform_surfaceless GBM platform: EGL API version: 1.5 EGL vendor string: Mesa Project EGL version string: 1.5 EGL client APIs: OpenGL OpenGL_ES EGL extensions string: EGL_ANDROID_blob_cache EGL_EXT_buffer_age EGL_EXT_create_context_robustness EGL_EXT_image_dma_buf_import EGL_EXT_image_dma_buf_import_modifiers EGL_KHR_cl_event2 EGL_KHR_config_attribs EGL_KHR_context_flush_control EGL_KHR_create_context EGL_KHR_create_context_no_error EGL_KHR_fence_sync EGL_KHR_get_all_proc_addresses EGL_KHR_gl_colorspace EGL_KHR_gl_renderbuffer_image EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_3D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_KHR_no_config_context EGL_KHR_reusable_sync EGL_KHR_surfaceless_context EGL_EXT_pixel_format_float EGL_KHR_wait_sync EGL_MESA_configless_context EGL_MESA_image_dma_buf_export EGL_MESA_query_driver Configurations: bf lv colorbuffer dp st ms vis cav bi renderable supported id sz l r g b a th cl ns b id eat nd gl es es2 vg surfaces --------------------------------------------------------------------- 0x01 32 0 10 10 10 2 0 0 0 0 0x30335241-- y y y win 0x02 32 0 10 10 10 2 16 0 0 0 0x30335241-- y y y win 0x03 32 0 10 10 10 2 24 0 0 0 0x30335241-- y y y win 0x04 32 0 10 10 10 2 24 8 0 0 0x30335241-- y y y win 0x05 32 0 10 10 10 2 32 0 0 0 0x30335241-- y y y win 0x06 32 0 10 10 10 2 0 0 4 1 0x
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值