From 7a90aa8d2e36ed65d0be14eaa03aeaa943a2c00b Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Wed, 13 Oct 2021 17:28:07 +0200 Subject: [PATCH] vk/format, v3dv: Add a vulkan -> pipe swizzle helper And use it to replace the one in v3dv. Part-of: --- src/broadcom/vulkan/v3dv_image.c | 33 ++------------------------------- src/vulkan/util/vk_format.c | 34 ++++++++++++++++++++++++++++++++++ src/vulkan/util/vk_format.h | 3 +++ 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_image.c b/src/broadcom/vulkan/v3dv_image.c index d03814d..5f5ef74 100644 --- a/src/broadcom/vulkan/v3dv_image.c +++ b/src/broadcom/vulkan/v3dv_image.c @@ -451,29 +451,6 @@ v3dv_image_type_to_view_type(VkImageType type) } } -static enum pipe_swizzle -vk_component_mapping_to_pipe_swizzle(VkComponentSwizzle swz) -{ - assert(swz != VK_COMPONENT_SWIZZLE_IDENTITY); - - switch (swz) { - case VK_COMPONENT_SWIZZLE_ZERO: - return PIPE_SWIZZLE_0; - case VK_COMPONENT_SWIZZLE_ONE: - return PIPE_SWIZZLE_1; - case VK_COMPONENT_SWIZZLE_R: - return PIPE_SWIZZLE_X; - case VK_COMPONENT_SWIZZLE_G: - return PIPE_SWIZZLE_Y; - case VK_COMPONENT_SWIZZLE_B: - return PIPE_SWIZZLE_Z; - case VK_COMPONENT_SWIZZLE_A: - return PIPE_SWIZZLE_W; - default: - unreachable("Unknown VkComponentSwizzle"); - }; -} - VKAPI_ATTR VkResult VKAPI_CALL v3dv_CreateImageView(VkDevice _device, const VkImageViewCreateInfo *pCreateInfo, @@ -515,14 +492,8 @@ v3dv_CreateImageView(VkDevice _device, * util_format_compose_swizzles. Would be good to check if it would be * better to reimplement the latter using vk component */ - image_view_swizzle[0] = - vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.r); - image_view_swizzle[1] = - vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.g); - image_view_swizzle[2] = - vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.b); - image_view_swizzle[3] = - vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.a); + vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle, + image_view_swizzle); } iview->vk.format = format; diff --git a/src/vulkan/util/vk_format.c b/src/vulkan/util/vk_format.c index f6e6bce..f5da22b 100644 --- a/src/vulkan/util/vk_format.c +++ b/src/vulkan/util/vk_format.c @@ -339,3 +339,37 @@ vk_format_aspects(VkFormat format) return VK_IMAGE_ASPECT_COLOR_BIT; } } + +void +vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping, + unsigned char out_swizzle[4]) +{ + VkComponentSwizzle swizzle[4] = { mapping.r, mapping.g, mapping.b, mapping.a }; + for (unsigned i = 0; i < 4; i++) { + switch (swizzle[i]) { + case VK_COMPONENT_SWIZZLE_R: + out_swizzle[i] = PIPE_SWIZZLE_X; + break; + case VK_COMPONENT_SWIZZLE_G: + out_swizzle[i] = PIPE_SWIZZLE_Y; + break; + case VK_COMPONENT_SWIZZLE_B: + out_swizzle[i] = PIPE_SWIZZLE_Z; + break; + case VK_COMPONENT_SWIZZLE_A: + out_swizzle[i] = PIPE_SWIZZLE_W; + break; + case VK_COMPONENT_SWIZZLE_IDENTITY: + out_swizzle[i] = PIPE_SWIZZLE_X + i; + break; + case VK_COMPONENT_SWIZZLE_ZERO: + out_swizzle[i] = PIPE_SWIZZLE_0; + break; + case VK_COMPONENT_SWIZZLE_ONE: + out_swizzle[i] = PIPE_SWIZZLE_1; + break; + default: + unreachable("unknown swizzle"); + } + } +} diff --git a/src/vulkan/util/vk_format.h b/src/vulkan/util/vk_format.h index f03a35e..76a8cd2 100644 --- a/src/vulkan/util/vk_format.h +++ b/src/vulkan/util/vk_format.h @@ -88,6 +88,9 @@ vk_format_stencil_only(VkFormat format) return VK_FORMAT_S8_UINT; } +void vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping, + unsigned char out_swizzle[4]); + #ifdef __cplusplus } #endif -- 2.7.4