Mesa (master): zink: make zink_format all about raw format-translation

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 16 21:03:51 UTC 2020


Module: Mesa
Branch: master
Commit: 123f3d0d647eb870f76fb018909ce7f1cb562ca6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=123f3d0d647eb870f76fb018909ce7f1cb562ca6

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Mon Dec  7 19:50:04 2020 +0100

zink: make zink_format all about raw format-translation

This moves the parts of zink_format.c that also operates on zink_screen
into zink_screen.c. This has the benefit that we can start testing the
enum-translation code separately from the state.

This will make the next commit a bit cleaner.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7982>

---

 src/gallium/drivers/zink/zink_format.c | 46 +++------------------------------
 src/gallium/drivers/zink/zink_format.h | 34 ++++++++++++++++++++++++
 src/gallium/drivers/zink/zink_screen.c | 47 ++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 43 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_format.c b/src/gallium/drivers/zink/zink_format.c
index a39c68ab106..1bf104bc4fd 100644
--- a/src/gallium/drivers/zink/zink_format.c
+++ b/src/gallium/drivers/zink/zink_format.c
@@ -1,4 +1,4 @@
-#include "zink_screen.h"
+#include "zink_format.h"
 
 static const VkFormat formats[PIPE_FORMAT_COUNT] = {
 #define MAP_FORMAT_NORM(FMT) \
@@ -129,48 +129,8 @@ static const VkFormat formats[PIPE_FORMAT_COUNT] = {
    [PIPE_FORMAT_BPTC_RGB_UFLOAT] = VK_FORMAT_BC6H_UFLOAT_BLOCK,
 };
 
-bool
-zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format)
-{
-   VkFormatProperties props;
-   vkGetPhysicalDeviceFormatProperties(screen->pdev, format, &props);
-   return (props.linearTilingFeatures | props.optimalTilingFeatures) &
-          VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
-}
-
-static enum pipe_format
-emulate_x8(enum pipe_format format)
-{
-   /* convert missing X8 variants to A8 */
-   switch (format) {
-   case PIPE_FORMAT_B8G8R8X8_UNORM:
-      return PIPE_FORMAT_B8G8R8A8_UNORM;
-
-   case PIPE_FORMAT_B8G8R8X8_SRGB:
-      return PIPE_FORMAT_B8G8R8A8_SRGB;
-
-   default:
-      return format;
-   }
-}
-
 VkFormat
-zink_get_format(struct zink_screen *screen, enum pipe_format format)
+zink_pipe_format_to_vk_format(enum pipe_format format)
 {
-   VkFormat ret = formats[emulate_x8(format)];
-
-   if (ret == VK_FORMAT_X8_D24_UNORM_PACK32 &&
-       !screen->have_X8_D24_UNORM_PACK32) {
-      assert(zink_is_depth_format_supported(screen, VK_FORMAT_D32_SFLOAT));
-      return VK_FORMAT_D32_SFLOAT;
-   }
-
-   if (ret == VK_FORMAT_D24_UNORM_S8_UINT &&
-       !screen->have_D24_UNORM_S8_UINT) {
-      assert(zink_is_depth_format_supported(screen,
-                                            VK_FORMAT_D32_SFLOAT_S8_UINT));
-      return VK_FORMAT_D32_SFLOAT_S8_UINT;
-   }
-
-   return ret;
+   return formats[format];
 }
diff --git a/src/gallium/drivers/zink/zink_format.h b/src/gallium/drivers/zink/zink_format.h
new file mode 100644
index 00000000000..966ee9bd9a8
--- /dev/null
+++ b/src/gallium/drivers/zink/zink_format.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2020 Collabora Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef ZINK_FORMAT_H
+#define ZINK_FORMAT_H
+
+#include "pipe/p_format.h"
+
+#include <vulkan/vulkan.h>
+
+VkFormat
+zink_pipe_format_to_vk_format(enum pipe_format format);
+
+#endif
diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c
index 074d206a128..64fc85855f4 100644
--- a/src/gallium/drivers/zink/zink_screen.c
+++ b/src/gallium/drivers/zink/zink_screen.c
@@ -27,6 +27,7 @@
 #include "zink_context.h"
 #include "zink_device_info.h"
 #include "zink_fence.h"
+#include "zink_format.h"
 #include "zink_instance.h"
 #include "zink_public.h"
 #include "zink_resource.h"
@@ -735,6 +736,52 @@ zink_flush_frontbuffer(struct pipe_screen *pscreen,
       winsys->displaytarget_display(winsys, res->dt, winsys_drawable_handle, sub_box);
 }
 
+bool
+zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format)
+{
+   VkFormatProperties props;
+   vkGetPhysicalDeviceFormatProperties(screen->pdev, format, &props);
+   return (props.linearTilingFeatures | props.optimalTilingFeatures) &
+          VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
+}
+
+static enum pipe_format
+emulate_x8(enum pipe_format format)
+{
+   /* convert missing X8 variants to A8 */
+   switch (format) {
+   case PIPE_FORMAT_B8G8R8X8_UNORM:
+      return PIPE_FORMAT_B8G8R8A8_UNORM;
+
+   case PIPE_FORMAT_B8G8R8X8_SRGB:
+      return PIPE_FORMAT_B8G8R8A8_SRGB;
+
+   default:
+      return format;
+   }
+}
+
+VkFormat
+zink_get_format(struct zink_screen *screen, enum pipe_format format)
+{
+   VkFormat ret = zink_pipe_format_to_vk_format(emulate_x8(format));
+
+   if (ret == VK_FORMAT_X8_D24_UNORM_PACK32 &&
+       !screen->have_X8_D24_UNORM_PACK32) {
+      assert(zink_is_depth_format_supported(screen, VK_FORMAT_D32_SFLOAT));
+      return VK_FORMAT_D32_SFLOAT;
+   }
+
+   if (ret == VK_FORMAT_D24_UNORM_S8_UINT &&
+       !screen->have_D24_UNORM_S8_UINT) {
+      assert(zink_is_depth_format_supported(screen,
+                                            VK_FORMAT_D32_SFLOAT_S8_UINT));
+      return VK_FORMAT_D32_SFLOAT_S8_UINT;
+   }
+
+   return ret;
+}
+
 static bool
 load_instance_extensions(struct zink_screen *screen)
 {



More information about the mesa-commit mailing list