libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.43k stars 1.75k forks source link

GPU Vulkan: using `R11G11B10_UFLOAT` for a colour target or storage texture causes validation errors #10688

Closed OrichalcumCosmonaut closed 4 days ago

OrichalcumCosmonaut commented 1 week ago

Trying to use the recently added (https://github.com/libsdl-org/SDL/commit/fb7245fb93fa8fd332771e020cd11fdde6556cc6) SDL_GPU_TEXTUREFORMAT_R11G11B10_UFLOAT for a colour target or storage texture causes validation errors.

As a colour target:

VUID-VkFramebufferCreateInfo-pAttachments-00884(ERROR / SPEC): msgNum: 1851994217 - Validation Error: [ VUID-VkFramebufferCreateInfo-pAttachments-00884 ] Object 0: handle = 0xaeea8c0000000569, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0x4e67e50000000568, type = VK_OBJECT_TYPE_IMAGE_VIEW; | MessageID = 0x6e633069 | vkCreateFramebuffer(): pCreateInfo->pAttachments[0] has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. Here are the actual swizzle values:
r swizzle = VK_COMPONENT_SWIZZLE_R
g swizzle = VK_COMPONENT_SWIZZLE_G
b swizzle = VK_COMPONENT_SWIZZLE_B
a swizzle = VK_COMPONENT_SWIZZLE_ONE
. The Vulkan spec states: If flags does not include VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT, each element of pAttachments must have been created with the identity swizzle (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkFramebufferCreateInfo-pAttachments-00884)
    Objects: 2
        [0] 0xaeea8c0000000569, type: 18, name: NULL
        [1] 0x4e67e50000000568, type: 14, name: NULL

As a storage texture:

VUID-VkWriteDescriptorSet-descriptorType-00336(ERROR / SPEC): msgNum: -1034359560 - Validation Error: [ VUID-VkWriteDescriptorSet-descriptorType-00336 ] Object 0: handle = 0x4801de000000056b, type = VK_OBJECT_TYPE_IMAGE_VIEW; Object 1: handle = 0xaeea8c0000000569, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0xc258ecf8 | vkUpdateDescriptorSets(): pDescriptorWrites[0].pImageInfo[0].imageView has a non-identiy swizzle component, here are the actual swizzle values:
r swizzle = VK_COMPONENT_SWIZZLE_R
g swizzle = VK_COMPONENT_SWIZZLE_G
b swizzle = VK_COMPONENT_SWIZZLE_B
a swizzle = VK_COMPONENT_SWIZZLE_ONE
. The Vulkan spec states: If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView member of each element of pImageInfo must have been created with the identity swizzle (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkWriteDescriptorSet-descriptorType-00336)
    Objects: 2
        [0] 0x4801de000000056b, type: 14, name: NULL
        [1] 0xaeea8c0000000569, type: 10, name: NULL
Akaricchi commented 1 week ago

Could you please test #10693 and make sure the subpixel ordering is correct? Thanks.

OrichalcumCosmonaut commented 1 week ago

That does fix the validation errors for R11G11B10_UFLOAT without causing any visual issues, not sure about the other formats though.

I think the swizzle for R10G10B10A2_UNORM is equivalent to the identity swizzle anyway, all that would need testing is B5G6R5_UNORM and B5G5R5A1_UNORM.

Probably related: https://github.com/thatcosmonaut/SDL/issues/56

Akaricchi commented 1 week ago

We've discussed this internally earlier, and I'm pretty sure that none of the formats require swizzling, except A8. The swizzling was a result of confusion about Vulkan's naming convention for packed formats. Vulkan's name order is most-significant-bit-first, while DXGI's and Metal's is least-significant-bit-first. Hence the Vulkan names looking "backwards". The actual layout should be the same.