Mesa (main): vk/format, v3dv: Add a vulkan -> pipe swizzle helper
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Oct 18 16:38:35 UTC 2021
Module: Mesa
Branch: main
Commit: 7a90aa8d2e36ed65d0be14eaa03aeaa943a2c00b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a90aa8d2e36ed65d0be14eaa03aeaa943a2c00b
Author: Connor Abbott <cwabbott0 at gmail.com>
Date: Wed Oct 13 17:28:07 2021 +0200
vk/format, v3dv: Add a vulkan -> pipe swizzle helper
And use it to replace the one in v3dv.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13359>
---
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 d03814d986d..5f5ef742a5a 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 f6e6bcec7cf..f5da22bac88 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 f03a35e2ad7..76a8cd248e0 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
More information about the mesa-commit
mailing list