Mesa (main): panvk: Use pan_pack_color

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 16 16:50:52 UTC 2021


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

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Fri Aug 13 21:10:55 2021 +0000

panvk: Use pan_pack_color

This is in common code now. Inherit all the bug fixes from panfrost.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12365>

---

 src/panfrost/vulkan/panvk_cmd_buffer.c | 88 +---------------------------------
 1 file changed, 2 insertions(+), 86 deletions(-)

diff --git a/src/panfrost/vulkan/panvk_cmd_buffer.c b/src/panfrost/vulkan/panvk_cmd_buffer.c
index aa160c8f3fa..3a19c93ab99 100644
--- a/src/panfrost/vulkan/panvk_cmd_buffer.c
+++ b/src/panfrost/vulkan/panvk_cmd_buffer.c
@@ -34,7 +34,6 @@
 #include "pan_encoder.h"
 
 #include "util/rounding.h"
-#include "util/u_pack_color.h"
 #include "vk_format.h"
 
 static VkResult
@@ -577,90 +576,6 @@ panvk_TrimCommandPool(VkDevice device,
       panvk_destroy_cmdbuf(cmdbuf);
 }
 
-static void
-panvk_pack_color_32(uint32_t *packed, uint32_t v)
-{
-   for (unsigned i = 0; i < 4; ++i)
-      packed[i] = v;
-}
-
-static void
-panvk_pack_color_64(uint32_t *packed, uint32_t lo, uint32_t hi)
-{
-   for (unsigned i = 0; i < 4; i += 2) {
-      packed[i + 0] = lo;
-      packed[i + 1] = hi;
-   }
-}
-
-void
-panvk_pack_color(struct panvk_clear_value *out,
-                 const VkClearColorValue *in,
-                 enum pipe_format format)
-{
-   const struct util_format_description *desc = util_format_description(format);
-
-   /* Alpha magicked to 1.0 if there is no alpha */
-   bool has_alpha = util_format_has_alpha(format);
-   float clear_alpha = has_alpha ? in->float32[3] : 1.0f;
-   uint32_t *packed = out->color;
-
-   if (util_format_is_rgba8_variant(desc) && desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB) {
-      panvk_pack_color_32(packed,
-                          ((uint32_t) float_to_ubyte(clear_alpha) << 24) |
-                          ((uint32_t) float_to_ubyte(in->float32[2]) << 16) |
-                          ((uint32_t) float_to_ubyte(in->float32[1]) <<  8) |
-                          ((uint32_t) float_to_ubyte(in->float32[0]) <<  0));
-   } else if (format == PIPE_FORMAT_B5G6R5_UNORM) {
-      /* First, we convert the components to R5, G6, B5 separately */
-      unsigned r5 = _mesa_roundevenf(SATURATE(in->float32[0]) * 31.0);
-      unsigned g6 = _mesa_roundevenf(SATURATE(in->float32[1]) * 63.0);
-      unsigned b5 = _mesa_roundevenf(SATURATE(in->float32[2]) * 31.0);
-
-      /* Then we pack into a sparse u32. TODO: Why these shifts? */
-      panvk_pack_color_32(packed, (b5 << 25) | (g6 << 14) | (r5 << 5));
-   } else if (format == PIPE_FORMAT_B4G4R4A4_UNORM) {
-      /* Convert to 4-bits */
-      unsigned r4 = _mesa_roundevenf(SATURATE(in->float32[0]) * 15.0);
-      unsigned g4 = _mesa_roundevenf(SATURATE(in->float32[1]) * 15.0);
-      unsigned b4 = _mesa_roundevenf(SATURATE(in->float32[2]) * 15.0);
-      unsigned a4 = _mesa_roundevenf(SATURATE(clear_alpha) * 15.0);
-
-      /* Pack on *byte* intervals */
-      panvk_pack_color_32(packed, (a4 << 28) | (b4 << 20) | (g4 << 12) | (r4 << 4));
-   } else if (format == PIPE_FORMAT_B5G5R5A1_UNORM) {
-      /* Scale as expected but shift oddly */
-      unsigned r5 = _mesa_roundevenf(SATURATE(in->float32[0]) * 31.0);
-      unsigned g5 = _mesa_roundevenf(SATURATE(in->float32[1]) * 31.0);
-      unsigned b5 = _mesa_roundevenf(SATURATE(in->float32[2]) * 31.0);
-      unsigned a1 = _mesa_roundevenf(SATURATE(clear_alpha) * 1.0);
-
-      panvk_pack_color_32(packed, (a1 << 31) | (b5 << 25) | (g5 << 15) | (r5 << 5));
-   } else {
-      /* Otherwise, it's generic subject to replication */
-
-      union util_color out = { 0 };
-      unsigned size = util_format_get_blocksize(format);
-
-      util_pack_color(in->float32, format, &out);
-
-      if (size == 1) {
-         unsigned b = out.ui[0];
-         unsigned s = b | (b << 8);
-         panvk_pack_color_32(packed, s | (s << 16));
-      } else if (size == 2)
-         panvk_pack_color_32(packed, out.ui[0] | (out.ui[0] << 16));
-      else if (size == 3 || size == 4)
-         panvk_pack_color_32(packed, out.ui[0]);
-      else if (size == 6 || size == 8)
-         panvk_pack_color_64(packed, out.ui[0], out.ui[1]);
-      else if (size == 12 || size == 16)
-         memcpy(packed, out.ui, 16);
-      else
-         unreachable("Unknown generic format size packing clear colour");
-   }
-}
-
 static void
 panvk_cmd_prepare_clear_values(struct panvk_cmd_buffer *cmdbuf,
                                const VkClearValue *in)
@@ -677,7 +592,8 @@ panvk_cmd_prepare_clear_values(struct panvk_cmd_buffer *cmdbuf,
              cmdbuf->state.clear[i].stencil = in[i].depthStencil.stencil;
           }
        } else if (attachment->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-          panvk_pack_color(&cmdbuf->state.clear[i], &in[i].color, fmt);
+          union pipe_color_union *col = (union pipe_color_union *) &in[i].color;
+          pan_pack_color(cmdbuf->state.clear[i].color, col, fmt);
        }
    }
 }



More information about the mesa-commit mailing list