Mesa (main): vulkan: move common format helpers to vk_format

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 19 11:57:46 UTC 2021


Module: Mesa
Branch: main
Commit: ff89dc352321c60619b7d72fd1695c6a166ca92f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ff89dc352321c60619b7d72fd1695c6a166ca92f

Author: Alejandro Piñeiro <apinheiro at igalia.com>
Date:   Thu Nov 18 12:16:43 2021 +0100

vulkan: move common format helpers to vk_format

v3dv, radv, and turnip are using several C&P format helpers (most of
them wrappers over util_format_description based helpers).  methods.

This commit moves the common helpers to the already existing common
vk_format.h. For the case of v3dv we were able to remove the vk_format
header. For turnip and radv, a local vk_format.h header remains, with
methods that are only used for those drivers.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Danylo Piliaiev <dpiliaiev at igalia.com>
Reviewed-by: Juan A. Suarez <jasuarez at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13858>

---

 src/amd/vulkan/vk_format.h              |  69 ---------------------
 src/broadcom/vulkan/v3dv_cmd_buffer.c   |   1 -
 src/broadcom/vulkan/v3dv_formats.c      |   1 -
 src/broadcom/vulkan/v3dv_image.c        |   1 -
 src/broadcom/vulkan/v3dv_meta_clear.c   |   1 -
 src/broadcom/vulkan/v3dv_meta_copy.c    |   1 -
 src/broadcom/vulkan/v3dv_pipeline.c     |   2 -
 src/broadcom/vulkan/v3dv_private.h      |   1 +
 src/broadcom/vulkan/v3dv_uniforms.c     |   1 -
 src/broadcom/vulkan/v3dv_wsi.c          |   1 -
 src/broadcom/vulkan/v3dvx_cmd_buffer.c  |   2 -
 src/broadcom/vulkan/v3dvx_device.c      |   1 -
 src/broadcom/vulkan/v3dvx_image.c       |   2 -
 src/broadcom/vulkan/v3dvx_meta_common.c |   2 -
 src/broadcom/vulkan/v3dvx_pipeline.c    |   2 -
 src/broadcom/vulkan/vk_format_info.h    | 106 --------------------------------
 src/freedreno/vulkan/vk_format.h        |  82 ------------------------
 src/vulkan/util/vk_format.h             |  79 ++++++++++++++++++++++++
 18 files changed, 80 insertions(+), 275 deletions(-)

diff --git a/src/amd/vulkan/vk_format.h b/src/amd/vulkan/vk_format.h
index fc6a1afd6fe..517fba00388 100644
--- a/src/amd/vulkan/vk_format.h
+++ b/src/amd/vulkan/vk_format.h
@@ -32,12 +32,6 @@
 #include <vulkan/util/vk_format.h>
 #include <vulkan/vulkan.h>
 
-static inline const struct util_format_description *
-vk_format_description(VkFormat format)
-{
-   return util_format_description(vk_format_to_pipe_format(format));
-}
-
 /**
  * Return total bits needed for the pixel format per block.
  */
@@ -47,27 +41,6 @@ vk_format_get_blocksizebits(VkFormat format)
    return util_format_get_blocksizebits(vk_format_to_pipe_format(format));
 }
 
-/**
- * Return bytes per block (not pixel) for the given format.
- */
-static inline unsigned
-vk_format_get_blocksize(VkFormat format)
-{
-   return util_format_get_blocksize(vk_format_to_pipe_format(format));
-}
-
-static inline unsigned
-vk_format_get_blockwidth(VkFormat format)
-{
-   return util_format_get_blockwidth(vk_format_to_pipe_format(format));
-}
-
-static inline unsigned
-vk_format_get_blockheight(VkFormat format)
-{
-   return util_format_get_blockheight(vk_format_to_pipe_format(format));
-}
-
 /**
  * Return the index of the first non-void channel
  * -1 if no non-void channels
@@ -109,48 +82,12 @@ vk_format_compose_swizzles(const VkComponentMapping *mapping, const unsigned cha
    dst[3] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_A, swz, mapping->a);
 }
 
-static inline bool
-vk_format_is_compressed(VkFormat format)
-{
-   return util_format_is_compressed(vk_format_to_pipe_format(format));
-}
-
 static inline bool
 vk_format_is_subsampled(VkFormat format)
 {
    return util_format_is_subsampled_422(vk_format_to_pipe_format(format));
 }
 
-static inline bool
-vk_format_is_int(VkFormat format)
-{
-   return util_format_is_pure_integer(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_uint(VkFormat format)
-{
-   return util_format_is_pure_uint(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_sint(VkFormat format)
-{
-   return util_format_is_pure_sint(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_unorm(VkFormat format)
-{
-   return util_format_is_unorm(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_srgb(VkFormat format)
-{
-   return util_format_is_srgb(vk_format_to_pipe_format(format));
-}
-
 static inline VkFormat
 vk_format_no_srgb(VkFormat format)
 {
@@ -256,12 +193,6 @@ vk_to_non_srgb_format(VkFormat format)
    }
 }
 
-static inline unsigned
-vk_format_get_nr_components(VkFormat format)
-{
-   return util_format_get_nr_components(vk_format_to_pipe_format(format));
-}
-
 static inline unsigned
 vk_format_get_plane_count(VkFormat format)
 {
diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c
index ae43b12af94..0acbf1a0582 100644
--- a/src/broadcom/vulkan/v3dv_cmd_buffer.c
+++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c
@@ -23,7 +23,6 @@
 
 #include "v3dv_private.h"
 #include "util/u_pack_color.h"
-#include "vk_format_info.h"
 #include "vk_util.h"
 
 void
diff --git a/src/broadcom/vulkan/v3dv_formats.c b/src/broadcom/vulkan/v3dv_formats.c
index 6e32d341a25..f36d4d9b54d 100644
--- a/src/broadcom/vulkan/v3dv_formats.c
+++ b/src/broadcom/vulkan/v3dv_formats.c
@@ -23,7 +23,6 @@
 
 #include "v3dv_private.h"
 #include "vk_util.h"
-#include "vk_format_info.h"
 
 #include "drm-uapi/drm_fourcc.h"
 #include "util/format/u_format.h"
diff --git a/src/broadcom/vulkan/v3dv_image.c b/src/broadcom/vulkan/v3dv_image.c
index 5f5ef742a5a..06ecb2bfa12 100644
--- a/src/broadcom/vulkan/v3dv_image.c
+++ b/src/broadcom/vulkan/v3dv_image.c
@@ -26,7 +26,6 @@
 #include "drm-uapi/drm_fourcc.h"
 #include "util/format/u_format.h"
 #include "util/u_math.h"
-#include "vk_format_info.h"
 #include "vk_util.h"
 #include "vulkan/wsi/wsi_common.h"
 
diff --git a/src/broadcom/vulkan/v3dv_meta_clear.c b/src/broadcom/vulkan/v3dv_meta_clear.c
index 23de9833530..12d69844d12 100644
--- a/src/broadcom/vulkan/v3dv_meta_clear.c
+++ b/src/broadcom/vulkan/v3dv_meta_clear.c
@@ -25,7 +25,6 @@
 #include "v3dv_meta_common.h"
 
 #include "compiler/nir/nir_builder.h"
-#include "vk_format_info.h"
 #include "util/u_pack_color.h"
 
 static void
diff --git a/src/broadcom/vulkan/v3dv_meta_copy.c b/src/broadcom/vulkan/v3dv_meta_copy.c
index 1aec0869cc8..dbfd9e89844 100644
--- a/src/broadcom/vulkan/v3dv_meta_copy.c
+++ b/src/broadcom/vulkan/v3dv_meta_copy.c
@@ -25,7 +25,6 @@
 #include "v3dv_meta_common.h"
 
 #include "compiler/nir/nir_builder.h"
-#include "vk_format_info.h"
 #include "util/u_pack_color.h"
 #include "vulkan/runtime/vk_common_entrypoints.h"
 
diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c
index 0f5c07de052..742f96c2bb6 100644
--- a/src/broadcom/vulkan/v3dv_pipeline.c
+++ b/src/broadcom/vulkan/v3dv_pipeline.c
@@ -26,8 +26,6 @@
 #include "v3dv_debug.h"
 #include "v3dv_private.h"
 
-#include "vk_format_info.h"
-
 #include "common/v3d_debug.h"
 
 #include "compiler/nir/nir_builder.h"
diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h
index 314e058269b..a3c3354c397 100644
--- a/src/broadcom/vulkan/v3dv_private.h
+++ b/src/broadcom/vulkan/v3dv_private.h
@@ -37,6 +37,7 @@
 #include <vk_enum_to_str.h>
 
 #include "vk_device.h"
+#include "vk_format.h"
 #include "vk_instance.h"
 #include "vk_image.h"
 #include "vk_log.h"
diff --git a/src/broadcom/vulkan/v3dv_uniforms.c b/src/broadcom/vulkan/v3dv_uniforms.c
index 47bc3a0b17c..3bec40e9127 100644
--- a/src/broadcom/vulkan/v3dv_uniforms.c
+++ b/src/broadcom/vulkan/v3dv_uniforms.c
@@ -26,7 +26,6 @@
  */
 
 #include "v3dv_private.h"
-#include "vk_format_info.h"
 
 /* The only version specific structure that we need is
  * TMU_CONFIG_PARAMETER_1. This didn't seem to change significantly from
diff --git a/src/broadcom/vulkan/v3dv_wsi.c b/src/broadcom/vulkan/v3dv_wsi.c
index 6157c32d69c..d4723c8b40b 100644
--- a/src/broadcom/vulkan/v3dv_wsi.c
+++ b/src/broadcom/vulkan/v3dv_wsi.c
@@ -26,7 +26,6 @@
 #include "v3dv_private.h"
 #include "drm-uapi/drm_fourcc.h"
 #include "wsi_common_entrypoints.h"
-#include "vk_format_info.h"
 #include "vk_util.h"
 #include "wsi_common.h"
 
diff --git a/src/broadcom/vulkan/v3dvx_cmd_buffer.c b/src/broadcom/vulkan/v3dvx_cmd_buffer.c
index c2f2c77864b..4c2b1d4bade 100644
--- a/src/broadcom/vulkan/v3dvx_cmd_buffer.c
+++ b/src/broadcom/vulkan/v3dvx_cmd_buffer.c
@@ -30,8 +30,6 @@
 #include "vulkan/util/vk_format.h"
 #include "util/u_pack_color.h"
 
-#include "vk_format_info.h"
-
 void
 v3dX(job_emit_binning_flush)(struct v3dv_job *job)
 {
diff --git a/src/broadcom/vulkan/v3dvx_device.c b/src/broadcom/vulkan/v3dvx_device.c
index a48738aec42..0d23688c4dd 100644
--- a/src/broadcom/vulkan/v3dvx_device.c
+++ b/src/broadcom/vulkan/v3dvx_device.c
@@ -26,7 +26,6 @@
 #include "broadcom/common/v3d_macros.h"
 #include "broadcom/cle/v3dx_pack.h"
 #include "broadcom/compiler/v3d_compiler.h"
-#include "vk_format_info.h"
 #include "util/u_pack_color.h"
 #include "util/half_float.h"
 
diff --git a/src/broadcom/vulkan/v3dvx_image.c b/src/broadcom/vulkan/v3dvx_image.c
index a9aa0fb9797..292ac7c9736 100644
--- a/src/broadcom/vulkan/v3dvx_image.c
+++ b/src/broadcom/vulkan/v3dvx_image.c
@@ -26,8 +26,6 @@
 #include "broadcom/cle/v3dx_pack.h"
 #include "broadcom/compiler/v3d_compiler.h"
 
-#include "vk_format_info.h"
-
 /*
  * This method translates pipe_swizzle to the swizzle values used at the
  * packet TEXTURE_SHADER_STATE
diff --git a/src/broadcom/vulkan/v3dvx_meta_common.c b/src/broadcom/vulkan/v3dvx_meta_common.c
index eedc3f4c834..5c775200234 100644
--- a/src/broadcom/vulkan/v3dvx_meta_common.c
+++ b/src/broadcom/vulkan/v3dvx_meta_common.c
@@ -29,8 +29,6 @@
 #include "broadcom/cle/v3dx_pack.h"
 #include "broadcom/compiler/v3d_compiler.h"
 
-#include "vk_format_info.h"
-
 struct rcl_clear_info {
    const union v3dv_clear_value *clear_value;
    struct v3dv_image *image;
diff --git a/src/broadcom/vulkan/v3dvx_pipeline.c b/src/broadcom/vulkan/v3dvx_pipeline.c
index 0345e1954c0..7c6fae22ad1 100644
--- a/src/broadcom/vulkan/v3dvx_pipeline.c
+++ b/src/broadcom/vulkan/v3dvx_pipeline.c
@@ -26,8 +26,6 @@
 #include "broadcom/cle/v3dx_pack.h"
 #include "broadcom/compiler/v3d_compiler.h"
 
-#include "vk_format_info.h"
-
 static uint8_t
 blend_factor(VkBlendFactor factor, bool dst_alpha_one, bool *needs_constants)
 {
diff --git a/src/broadcom/vulkan/vk_format_info.h b/src/broadcom/vulkan/vk_format_info.h
deleted file mode 100644
index da85cb5b5dd..00000000000
--- a/src/broadcom/vulkan/vk_format_info.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright © 2016 Intel Corporation
- *
- * 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
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS 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 VK_FORMAT_INFO_H
-#define VK_FORMAT_INFO_H
-
-#include <stdbool.h>
-#include <vulkan/vulkan.h>
-
-#include "util/format/u_format.h"
-#include "vulkan/util/vk_format.h"
-
-/* FIXME: from freedreno vk_format.h, common place?*/
-static inline bool
-vk_format_is_int(VkFormat format)
-{
-   return util_format_is_pure_integer(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_sint(VkFormat format)
-{
-   return util_format_is_pure_sint(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_uint(VkFormat format)
-{
-   return util_format_is_pure_uint(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_unorm(VkFormat format)
-{
-   return util_format_is_unorm(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_snorm(VkFormat format)
-{
-   return util_format_is_snorm(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_float(VkFormat format)
-{
-   return util_format_is_float(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_srgb(VkFormat format)
-{
-   return util_format_is_srgb(vk_format_to_pipe_format(format));
-}
-
-static inline unsigned
-vk_format_get_blocksize(VkFormat format)
-{
-   return util_format_get_blocksize(vk_format_to_pipe_format(format));
-}
-
-static inline unsigned
-vk_format_get_blockwidth(VkFormat format)
-{
-   return util_format_get_blockwidth(vk_format_to_pipe_format(format));
-}
-
-static inline unsigned
-vk_format_get_blockheight(VkFormat format)
-{
-   return util_format_get_blockheight(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_compressed(VkFormat format)
-{
-   return util_format_is_compressed(vk_format_to_pipe_format(format));
-}
-
-static inline const struct util_format_description *
-vk_format_description(VkFormat format)
-{
-   return util_format_description(vk_format_to_pipe_format(format));
-}
-
-#endif /* VK_FORMAT_INFO_H */
diff --git a/src/freedreno/vulkan/vk_format.h b/src/freedreno/vulkan/vk_format.h
index 1a895fa264a..8aca5fef8e2 100644
--- a/src/freedreno/vulkan/vk_format.h
+++ b/src/freedreno/vulkan/vk_format.h
@@ -34,88 +34,12 @@
 
 #include <vulkan/vulkan.h>
 
-static inline const struct util_format_description *
-vk_format_description(VkFormat format)
-{
-   return util_format_description(vk_format_to_pipe_format(format));
-}
-
-/**
- * Return bytes per block (not pixel) for the given format.
- */
-static inline unsigned
-vk_format_get_blocksize(VkFormat format)
-{
-   return util_format_get_blocksize(vk_format_to_pipe_format(format));
-}
-
-static inline unsigned
-vk_format_get_blockwidth(VkFormat format)
-{
-   return util_format_get_blockwidth(vk_format_to_pipe_format(format));
-}
-
-static inline unsigned
-vk_format_get_blockheight(VkFormat format)
-{
-   return util_format_get_blockheight(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_compressed(VkFormat format)
-{
-   /* this includes 4:2:2 formats, which are compressed formats for vulkan */
-   return vk_format_get_blockwidth(format) > 1;
-}
-
 static inline bool
 vk_format_has_alpha(VkFormat format)
 {
    return util_format_has_alpha(vk_format_to_pipe_format(format));
 }
 
-static inline bool
-vk_format_is_int(VkFormat format)
-{
-   return util_format_is_pure_integer(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_uint(VkFormat format)
-{
-   return util_format_is_pure_uint(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_sint(VkFormat format)
-{
-   return util_format_is_pure_sint(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_srgb(VkFormat format)
-{
-   return util_format_is_srgb(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_unorm(VkFormat format)
-{
-   return util_format_is_unorm(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_snorm(VkFormat format)
-{
-   return util_format_is_snorm(vk_format_to_pipe_format(format));
-}
-
-static inline bool
-vk_format_is_float(VkFormat format)
-{
-   return util_format_is_float(vk_format_to_pipe_format(format));
-}
-
 static inline unsigned
 vk_format_get_component_bits(VkFormat format,
                              enum util_format_colorspace colorspace,
@@ -136,10 +60,4 @@ vk_format_get_component_bits(VkFormat format,
                                          colorspace, component);
 }
 
-static inline unsigned
-vk_format_get_nr_components(VkFormat format)
-{
-   return util_format_get_nr_components(vk_format_to_pipe_format(format));
-}
-
 #endif /* VK_FORMAT_H */
diff --git a/src/vulkan/util/vk_format.h b/src/vulkan/util/vk_format.h
index 76a8cd248e0..72b416c6f6e 100644
--- a/src/vulkan/util/vk_format.h
+++ b/src/vulkan/util/vk_format.h
@@ -91,6 +91,85 @@ vk_format_stencil_only(VkFormat format)
 void vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,
                                           unsigned char out_swizzle[4]);
 
+static inline bool
+vk_format_is_int(VkFormat format)
+{
+   return util_format_is_pure_integer(vk_format_to_pipe_format(format));
+}
+
+static inline bool
+vk_format_is_sint(VkFormat format)
+{
+   return util_format_is_pure_sint(vk_format_to_pipe_format(format));
+}
+
+static inline bool
+vk_format_is_uint(VkFormat format)
+{
+   return util_format_is_pure_uint(vk_format_to_pipe_format(format));
+}
+
+static inline bool
+vk_format_is_unorm(VkFormat format)
+{
+   return util_format_is_unorm(vk_format_to_pipe_format(format));
+}
+
+static inline bool
+vk_format_is_snorm(VkFormat format)
+{
+   return util_format_is_snorm(vk_format_to_pipe_format(format));
+}
+
+static inline bool
+vk_format_is_float(VkFormat format)
+{
+   return util_format_is_float(vk_format_to_pipe_format(format));
+}
+
+static inline bool
+vk_format_is_srgb(VkFormat format)
+{
+   return util_format_is_srgb(vk_format_to_pipe_format(format));
+}
+
+static inline unsigned
+vk_format_get_blocksize(VkFormat format)
+{
+   return util_format_get_blocksize(vk_format_to_pipe_format(format));
+}
+
+static inline unsigned
+vk_format_get_blockwidth(VkFormat format)
+{
+   return util_format_get_blockwidth(vk_format_to_pipe_format(format));
+}
+
+static inline unsigned
+vk_format_get_blockheight(VkFormat format)
+{
+   return util_format_get_blockheight(vk_format_to_pipe_format(format));
+}
+
+static inline bool
+vk_format_is_compressed(VkFormat format)
+{
+   /* this includes 4:2:2 formats, which are compressed formats for vulkan */
+   return vk_format_get_blockwidth(format) > 1;
+}
+
+static inline const struct util_format_description *
+vk_format_description(VkFormat format)
+{
+   return util_format_description(vk_format_to_pipe_format(format));
+}
+
+static inline unsigned
+vk_format_get_nr_components(VkFormat format)
+{
+   return util_format_get_nr_components(vk_format_to_pipe_format(format));
+}
+
 #ifdef __cplusplus
 }
 #endif



More information about the mesa-commit mailing list