Mesa (main): v3dv: split v3dv_device hw version dependant code to a new source file

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 22 10:35:42 UTC 2021


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

Author: Alejandro Piñeiro <apinheiro at igalia.com>
Date:   Mon Jun 14 23:36:08 2021 +0200

v3dv: split v3dv_device hw version dependant code to a new source file

Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11310>

---

 src/broadcom/vulkan/meson.build       |   1 +
 src/broadcom/vulkan/v3dv_cmd_buffer.c |   4 +-
 src/broadcom/vulkan/v3dv_device.c     | 158 +----------------------------
 src/broadcom/vulkan/v3dv_meta_clear.c |   4 +-
 src/broadcom/vulkan/v3dvx_device.c    | 182 ++++++++++++++++++++++++++++++++++
 src/broadcom/vulkan/v3dvx_private.h   |  11 ++
 6 files changed, 199 insertions(+), 161 deletions(-)

diff --git a/src/broadcom/vulkan/meson.build b/src/broadcom/vulkan/meson.build
index 59bc8960b88..2f4063ed71a 100644
--- a/src/broadcom/vulkan/meson.build
+++ b/src/broadcom/vulkan/meson.build
@@ -54,6 +54,7 @@ libv3dv_files = files(
 )
 
 files_per_version = files(
+  'v3dvx_device.c',
   'v3dvx_formats.c',
   'v3dvx_image.c',
   'v3dvx_pipeline.c',
diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c
index 7776b3ce25e..e7aac250279 100644
--- a/src/broadcom/vulkan/v3dv_cmd_buffer.c
+++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c
@@ -2473,8 +2473,8 @@ cmd_buffer_subpass_create_job(struct v3dv_cmd_buffer *cmd_buffer,
 
       uint8_t internal_bpp;
       bool msaa;
-      v3dv_framebuffer_compute_internal_bpp_msaa(framebuffer, subpass,
-                                                 &internal_bpp, &msaa);
+      v3dv_X(job->device, framebuffer_compute_internal_bpp_msaa)
+         (framebuffer, subpass, &internal_bpp, &msaa);
 
       v3dv_job_start_frame(job,
                            framebuffer->width,
diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c
index bb3104214ef..d6f95fa381d 100644
--- a/src/broadcom/vulkan/v3dv_device.c
+++ b/src/broadcom/vulkan/v3dv_device.c
@@ -34,8 +34,6 @@
 
 #include "common/v3d_debug.h"
 
-#include "broadcom/cle/v3dx_pack.h"
-
 #include "compiler/v3d_compiler.h"
 
 #include "drm-uapi/v3d_drm.h"
@@ -2303,66 +2301,6 @@ v3dv_DestroyBuffer(VkDevice _device,
    vk_object_free(&device->vk, pAllocator, buffer);
 }
 
-/**
- * This computes the maximum bpp used by any of the render targets used by
- * a particular subpass and checks if any of those render targets are
- * multisampled. If we don't have a subpass (when we are not inside a
- * render pass), then we assume that all framebuffer attachments are used.
- */
-void
-v3dv_framebuffer_compute_internal_bpp_msaa(
-   const struct v3dv_framebuffer *framebuffer,
-   const struct v3dv_subpass *subpass,
-   uint8_t *max_bpp,
-   bool *msaa)
-{
-   STATIC_ASSERT(RENDER_TARGET_MAXIMUM_32BPP == 0);
-   *max_bpp = RENDER_TARGET_MAXIMUM_32BPP;
-   *msaa = false;
-
-   if (subpass) {
-      for (uint32_t i = 0; i < subpass->color_count; i++) {
-         uint32_t att_idx = subpass->color_attachments[i].attachment;
-         if (att_idx == VK_ATTACHMENT_UNUSED)
-            continue;
-
-         const struct v3dv_image_view *att = framebuffer->attachments[att_idx];
-         assert(att);
-
-         if (att->aspects & VK_IMAGE_ASPECT_COLOR_BIT)
-            *max_bpp = MAX2(*max_bpp, att->internal_bpp);
-
-         if (att->image->samples > VK_SAMPLE_COUNT_1_BIT)
-            *msaa = true;
-      }
-
-      if (!*msaa && subpass->ds_attachment.attachment != VK_ATTACHMENT_UNUSED) {
-         const struct v3dv_image_view *att =
-            framebuffer->attachments[subpass->ds_attachment.attachment];
-         assert(att);
-
-         if (att->image->samples > VK_SAMPLE_COUNT_1_BIT)
-            *msaa = true;
-      }
-
-      return;
-   }
-
-   assert(framebuffer->attachment_count <= 4);
-   for (uint32_t i = 0; i < framebuffer->attachment_count; i++) {
-      const struct v3dv_image_view *att = framebuffer->attachments[i];
-      assert(att);
-
-      if (att->aspects & VK_IMAGE_ASPECT_COLOR_BIT)
-         *max_bpp = MAX2(*max_bpp, att->internal_bpp);
-
-      if (att->image->samples > VK_SAMPLE_COUNT_1_BIT)
-         *msaa = true;
-   }
-
-   return;
-}
-
 VKAPI_ATTR VkResult VKAPI_CALL
 v3dv_CreateFramebuffer(VkDevice _device,
                        const VkFramebufferCreateInfo *pCreateInfo,
@@ -2514,100 +2452,6 @@ v3dv_ResetEvent(VkDevice _device, VkEvent _event)
    return VK_SUCCESS;
 }
 
-static const enum V3DX(Wrap_Mode) vk_to_v3d_wrap_mode[] = {
-   [VK_SAMPLER_ADDRESS_MODE_REPEAT]          = V3D_WRAP_MODE_REPEAT,
-   [VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT] = V3D_WRAP_MODE_MIRROR,
-   [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE]   = V3D_WRAP_MODE_CLAMP,
-   [VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE] = V3D_WRAP_MODE_MIRROR_ONCE,
-   [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER] = V3D_WRAP_MODE_BORDER,
-};
-
-static const enum V3DX(Compare_Function)
-vk_to_v3d_compare_func[] = {
-   [VK_COMPARE_OP_NEVER]                        = V3D_COMPARE_FUNC_NEVER,
-   [VK_COMPARE_OP_LESS]                         = V3D_COMPARE_FUNC_LESS,
-   [VK_COMPARE_OP_EQUAL]                        = V3D_COMPARE_FUNC_EQUAL,
-   [VK_COMPARE_OP_LESS_OR_EQUAL]                = V3D_COMPARE_FUNC_LEQUAL,
-   [VK_COMPARE_OP_GREATER]                      = V3D_COMPARE_FUNC_GREATER,
-   [VK_COMPARE_OP_NOT_EQUAL]                    = V3D_COMPARE_FUNC_NOTEQUAL,
-   [VK_COMPARE_OP_GREATER_OR_EQUAL]             = V3D_COMPARE_FUNC_GEQUAL,
-   [VK_COMPARE_OP_ALWAYS]                       = V3D_COMPARE_FUNC_ALWAYS,
-};
-
-static void
-pack_sampler_state(struct v3dv_sampler *sampler,
-                   const VkSamplerCreateInfo *pCreateInfo)
-{
-   enum V3DX(Border_Color_Mode) border_color_mode;
-
-   /* For now we only support the preset Vulkan border color modes. If we
-    * want to implement VK_EXT_custom_border_color in the future we would have
-    * to use V3D_BORDER_COLOR_FOLLOWS, and fill up border_color_word_[0/1/2/3]
-    * SAMPLER_STATE.
-    */
-   switch (pCreateInfo->borderColor) {
-   case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
-   case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
-      border_color_mode = V3D_BORDER_COLOR_0000;
-      break;
-   case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
-   case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
-      border_color_mode = V3D_BORDER_COLOR_0001;
-      break;
-   case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
-   case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
-      border_color_mode = V3D_BORDER_COLOR_1111;
-      break;
-   default:
-      unreachable("Unknown border color");
-      break;
-   }
-
-   /* For some texture formats, when clamping to transparent black border the
-    * CTS expects alpha to be set to 1 instead of 0, but the border color mode
-    * will take priority over the texture state swizzle, so the only way to
-    * fix that is to apply a swizzle in the shader. Here we keep track of
-    * whether we are activating that mode and we will decide if we need to
-    * activate the texture swizzle lowering in the shader key at compile time
-    * depending on the actual texture format.
-    */
-   if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
-        pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
-        pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) &&
-       border_color_mode == V3D_BORDER_COLOR_0000) {
-      sampler->clamp_to_transparent_black_border = true;
-   }
-
-   v3dvx_pack(sampler->sampler_state, SAMPLER_STATE, s) {
-      if (pCreateInfo->anisotropyEnable) {
-         s.anisotropy_enable = true;
-         if (pCreateInfo->maxAnisotropy > 8)
-            s.maximum_anisotropy = 3;
-         else if (pCreateInfo->maxAnisotropy > 4)
-            s.maximum_anisotropy = 2;
-         else if (pCreateInfo->maxAnisotropy > 2)
-            s.maximum_anisotropy = 1;
-      }
-
-      s.border_color_mode = border_color_mode;
-
-      s.wrap_i_border = false; /* Also hardcoded on v3d */
-      s.wrap_s = vk_to_v3d_wrap_mode[pCreateInfo->addressModeU];
-      s.wrap_t = vk_to_v3d_wrap_mode[pCreateInfo->addressModeV];
-      s.wrap_r = vk_to_v3d_wrap_mode[pCreateInfo->addressModeW];
-      s.fixed_bias = pCreateInfo->mipLodBias;
-      s.max_level_of_detail = MIN2(MAX2(0, pCreateInfo->maxLod), 15);
-      s.min_level_of_detail = MIN2(MAX2(0, pCreateInfo->minLod), 15);
-      s.srgb_disable = 0; /* Not even set by v3d */
-      s.depth_compare_function =
-         vk_to_v3d_compare_func[pCreateInfo->compareEnable ?
-                                pCreateInfo->compareOp : VK_COMPARE_OP_NEVER];
-      s.mip_filter_nearest = pCreateInfo->mipmapMode == VK_SAMPLER_MIPMAP_MODE_NEAREST;
-      s.min_filter_nearest = pCreateInfo->minFilter == VK_FILTER_NEAREST;
-      s.mag_filter_nearest = pCreateInfo->magFilter == VK_FILTER_NEAREST;
-   }
-}
-
 VKAPI_ATTR VkResult VKAPI_CALL
 v3dv_CreateSampler(VkDevice _device,
                  const VkSamplerCreateInfo *pCreateInfo,
@@ -2626,7 +2470,7 @@ v3dv_CreateSampler(VkDevice _device,
 
    sampler->compare_enable = pCreateInfo->compareEnable;
    sampler->unnormalized_coordinates = pCreateInfo->unnormalizedCoordinates;
-   pack_sampler_state(sampler, pCreateInfo);
+   v3dv_X(device, pack_sampler_state)(sampler, pCreateInfo);
 
    *pSampler = v3dv_sampler_to_handle(sampler);
 
diff --git a/src/broadcom/vulkan/v3dv_meta_clear.c b/src/broadcom/vulkan/v3dv_meta_clear.c
index 29e3e0e7d70..d95924f4b03 100644
--- a/src/broadcom/vulkan/v3dv_meta_clear.c
+++ b/src/broadcom/vulkan/v3dv_meta_clear.c
@@ -1372,8 +1372,8 @@ emit_tlb_clear_job(struct v3dv_cmd_buffer *cmd_buffer,
 
    uint8_t internal_bpp;
    bool msaa;
-   v3dv_framebuffer_compute_internal_bpp_msaa(framebuffer, subpass,
-                                              &internal_bpp, &msaa);
+   v3dv_X(job->device, framebuffer_compute_internal_bpp_msaa)
+      (framebuffer, subpass, &internal_bpp, &msaa);
 
    v3dv_job_start_frame(job,
                         framebuffer->width,
diff --git a/src/broadcom/vulkan/v3dvx_device.c b/src/broadcom/vulkan/v3dvx_device.c
new file mode 100644
index 00000000000..3cd4870a597
--- /dev/null
+++ b/src/broadcom/vulkan/v3dvx_device.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright © 2021 Raspberry Pi
+ *
+ * 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.
+ */
+
+#include "v3dv_private.h"
+
+#include "broadcom/common/v3d_macros.h"
+#include "broadcom/cle/v3dx_pack.h"
+#include "broadcom/compiler/v3d_compiler.h"
+
+static const enum V3DX(Wrap_Mode) vk_to_v3d_wrap_mode[] = {
+   [VK_SAMPLER_ADDRESS_MODE_REPEAT]          = V3D_WRAP_MODE_REPEAT,
+   [VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT] = V3D_WRAP_MODE_MIRROR,
+   [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE]   = V3D_WRAP_MODE_CLAMP,
+   [VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE] = V3D_WRAP_MODE_MIRROR_ONCE,
+   [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER] = V3D_WRAP_MODE_BORDER,
+};
+
+static const enum V3DX(Compare_Function)
+vk_to_v3d_compare_func[] = {
+   [VK_COMPARE_OP_NEVER]                        = V3D_COMPARE_FUNC_NEVER,
+   [VK_COMPARE_OP_LESS]                         = V3D_COMPARE_FUNC_LESS,
+   [VK_COMPARE_OP_EQUAL]                        = V3D_COMPARE_FUNC_EQUAL,
+   [VK_COMPARE_OP_LESS_OR_EQUAL]                = V3D_COMPARE_FUNC_LEQUAL,
+   [VK_COMPARE_OP_GREATER]                      = V3D_COMPARE_FUNC_GREATER,
+   [VK_COMPARE_OP_NOT_EQUAL]                    = V3D_COMPARE_FUNC_NOTEQUAL,
+   [VK_COMPARE_OP_GREATER_OR_EQUAL]             = V3D_COMPARE_FUNC_GEQUAL,
+   [VK_COMPARE_OP_ALWAYS]                       = V3D_COMPARE_FUNC_ALWAYS,
+};
+
+void
+v3dX(pack_sampler_state)(struct v3dv_sampler *sampler,
+                         const VkSamplerCreateInfo *pCreateInfo)
+{
+   enum V3DX(Border_Color_Mode) border_color_mode;
+
+   /* For now we only support the preset Vulkan border color modes. If we
+    * want to implement VK_EXT_custom_border_color in the future we would have
+    * to use V3D_BORDER_COLOR_FOLLOWS, and fill up border_color_word_[0/1/2/3]
+    * SAMPLER_STATE.
+    */
+   switch (pCreateInfo->borderColor) {
+   case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
+   case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
+      border_color_mode = V3D_BORDER_COLOR_0000;
+      break;
+   case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
+   case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
+      border_color_mode = V3D_BORDER_COLOR_0001;
+      break;
+   case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
+   case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
+      border_color_mode = V3D_BORDER_COLOR_1111;
+      break;
+   default:
+      unreachable("Unknown border color");
+      break;
+   }
+
+   /* For some texture formats, when clamping to transparent black border the
+    * CTS expects alpha to be set to 1 instead of 0, but the border color mode
+    * will take priority over the texture state swizzle, so the only way to
+    * fix that is to apply a swizzle in the shader. Here we keep track of
+    * whether we are activating that mode and we will decide if we need to
+    * activate the texture swizzle lowering in the shader key at compile time
+    * depending on the actual texture format.
+    */
+   if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
+        pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
+        pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) &&
+       border_color_mode == V3D_BORDER_COLOR_0000) {
+      sampler->clamp_to_transparent_black_border = true;
+   }
+
+   v3dvx_pack(sampler->sampler_state, SAMPLER_STATE, s) {
+      if (pCreateInfo->anisotropyEnable) {
+         s.anisotropy_enable = true;
+         if (pCreateInfo->maxAnisotropy > 8)
+            s.maximum_anisotropy = 3;
+         else if (pCreateInfo->maxAnisotropy > 4)
+            s.maximum_anisotropy = 2;
+         else if (pCreateInfo->maxAnisotropy > 2)
+            s.maximum_anisotropy = 1;
+      }
+
+      s.border_color_mode = border_color_mode;
+
+      s.wrap_i_border = false; /* Also hardcoded on v3d */
+      s.wrap_s = vk_to_v3d_wrap_mode[pCreateInfo->addressModeU];
+      s.wrap_t = vk_to_v3d_wrap_mode[pCreateInfo->addressModeV];
+      s.wrap_r = vk_to_v3d_wrap_mode[pCreateInfo->addressModeW];
+      s.fixed_bias = pCreateInfo->mipLodBias;
+      s.max_level_of_detail = MIN2(MAX2(0, pCreateInfo->maxLod), 15);
+      s.min_level_of_detail = MIN2(MAX2(0, pCreateInfo->minLod), 15);
+      s.srgb_disable = 0; /* Not even set by v3d */
+      s.depth_compare_function =
+         vk_to_v3d_compare_func[pCreateInfo->compareEnable ?
+                                pCreateInfo->compareOp : VK_COMPARE_OP_NEVER];
+      s.mip_filter_nearest = pCreateInfo->mipmapMode == VK_SAMPLER_MIPMAP_MODE_NEAREST;
+      s.min_filter_nearest = pCreateInfo->minFilter == VK_FILTER_NEAREST;
+      s.mag_filter_nearest = pCreateInfo->magFilter == VK_FILTER_NEAREST;
+   }
+}
+
+/**
+ * This computes the maximum bpp used by any of the render targets used by
+ * a particular subpass and checks if any of those render targets are
+ * multisampled. If we don't have a subpass (when we are not inside a
+ * render pass), then we assume that all framebuffer attachments are used.
+ */
+void
+v3dX(framebuffer_compute_internal_bpp_msaa)(
+   const struct v3dv_framebuffer *framebuffer,
+   const struct v3dv_subpass *subpass,
+   uint8_t *max_bpp,
+   bool *msaa)
+{
+   STATIC_ASSERT(RENDER_TARGET_MAXIMUM_32BPP == 0);
+   *max_bpp = RENDER_TARGET_MAXIMUM_32BPP;
+   *msaa = false;
+
+   if (subpass) {
+      for (uint32_t i = 0; i < subpass->color_count; i++) {
+         uint32_t att_idx = subpass->color_attachments[i].attachment;
+         if (att_idx == VK_ATTACHMENT_UNUSED)
+            continue;
+
+         const struct v3dv_image_view *att = framebuffer->attachments[att_idx];
+         assert(att);
+
+         if (att->aspects & VK_IMAGE_ASPECT_COLOR_BIT)
+            *max_bpp = MAX2(*max_bpp, att->internal_bpp);
+
+         if (att->image->samples > VK_SAMPLE_COUNT_1_BIT)
+            *msaa = true;
+      }
+
+      if (!*msaa && subpass->ds_attachment.attachment != VK_ATTACHMENT_UNUSED) {
+         const struct v3dv_image_view *att =
+            framebuffer->attachments[subpass->ds_attachment.attachment];
+         assert(att);
+
+         if (att->image->samples > VK_SAMPLE_COUNT_1_BIT)
+            *msaa = true;
+      }
+
+      return;
+   }
+
+   assert(framebuffer->attachment_count <= 4);
+   for (uint32_t i = 0; i < framebuffer->attachment_count; i++) {
+      const struct v3dv_image_view *att = framebuffer->attachments[i];
+      assert(att);
+
+      if (att->aspects & VK_IMAGE_ASPECT_COLOR_BIT)
+         *max_bpp = MAX2(*max_bpp, att->internal_bpp);
+
+      if (att->image->samples > VK_SAMPLE_COUNT_1_BIT)
+         *msaa = true;
+   }
+
+   return;
+}
diff --git a/src/broadcom/vulkan/v3dvx_private.h b/src/broadcom/vulkan/v3dvx_private.h
index 0ab189d21f8..2de8996903c 100644
--- a/src/broadcom/vulkan/v3dvx_private.h
+++ b/src/broadcom/vulkan/v3dvx_private.h
@@ -29,6 +29,17 @@
 #error This file is included by means other than v3dv_private.h
 #endif
 
+/* Used at v3dv_device */
+
+void
+v3dX(pack_sampler_state)(struct v3dv_sampler *sampler,
+                         const VkSamplerCreateInfo *pCreateInfo);
+
+void
+v3dX(framebuffer_compute_internal_bpp_msaa)(const struct v3dv_framebuffer *framebuffer,
+                                            const struct v3dv_subpass *subpass,
+                                            uint8_t *max_bpp, bool *msaa);
+
 /* Used at v3dv_format */
 const struct v3dv_format *
 v3dX(get_format)(VkFormat);



More information about the mesa-commit mailing list