[Mesa-dev] [PATCH 26/42] panfrost/midgard: Use Gallium framebuffer formats

Alyssa Rosenzweig alyssa.rosenzweig at collabora.com
Mon Jul 8 14:08:39 UTC 2019


Ideally, we would keep Galliumisms far away from the compiler;
unfortunately, Mesa hasn't standardized on system of format codes to be
shared across APIs and across drivers, so using Gallium formats is our
best bet in the short run.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
---
 .../panfrost/midgard/nir_lower_framebuffer.c  | 41 +++++++++++++++++--
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
index 2986c3c3393..f5182ca7394 100644
--- a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
+++ b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c
@@ -40,9 +40,10 @@
 #include "compiler/nir/nir.h"
 #include "compiler/nir/nir_builder.h"
 #include "nir_lower_blend.h"
+#include "util/u_format.h"
 
 static nir_ssa_def *
-nir_float_to_native(nir_builder *b, nir_ssa_def *c_float)
+nir_float_to_unorm8(nir_builder *b, nir_ssa_def *c_float)
 {
    /* First, we degrade quality to fp16; we don't need the extra bits */
    nir_ssa_def *degraded = nir_f2f16(b, c_float);
@@ -58,7 +59,7 @@ nir_float_to_native(nir_builder *b, nir_ssa_def *c_float)
 }
 
 static nir_ssa_def *
-nir_native_to_float(nir_builder *b, nir_ssa_def *c_native)
+nir_unorm8_to_float(nir_builder *b, nir_ssa_def *c_native)
 {
    /* First, we convert up from u8 to f16 */
    nir_ssa_def *converted = nir_u2f16(b, nir_u2u16(b, c_native));
@@ -69,12 +70,44 @@ nir_native_to_float(nir_builder *b, nir_ssa_def *c_native)
    return scaled;
 }
 
+
+
+static nir_ssa_def *
+nir_float_to_native(nir_builder *b,
+      nir_ssa_def *c_float,
+      const struct util_format_description *desc)
+{
+   if (util_format_is_unorm8(desc))
+      return nir_float_to_unorm8(b, c_float);
+   else {
+      printf("%s\n", desc->name);
+      unreachable("Unknown format name");
+   }
+}
+
+static nir_ssa_def *
+nir_native_to_float(nir_builder *b,
+   nir_ssa_def *c_native,
+   const struct util_format_description *desc)
+{
+   if (util_format_is_unorm8(desc))
+      return nir_unorm8_to_float(b, c_native);
+   else {
+      printf("%s\n", desc->name);
+      unreachable("Unknown format name");
+   }
+}
+
 void
 nir_lower_framebuffer(nir_shader *shader)
 {
    /* Blend shaders are represented as special fragment shaders */
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
+   enum pipe_format format = PIPE_FORMAT_R8G8B8A8_UNORM;
+   const struct util_format_description *format_desc =
+      util_format_description(format);
+
    nir_foreach_function(func, shader) {
       nir_foreach_block(block, func->impl) {
          nir_foreach_instr_safe(instr, block) {
@@ -106,7 +139,7 @@ nir_lower_framebuffer(nir_shader *shader)
                nir_ssa_def *c_nir = nir_ssa_for_src(&b, intr->src[1], 4);
 
                /* Format convert */
-               nir_ssa_def *converted = nir_float_to_native(&b, c_nir);
+               nir_ssa_def *converted = nir_float_to_native(&b, c_nir, format_desc);
 
                /* Rewrite to use a native store by creating a new intrinsic */
                nir_intrinsic_instr *new =
@@ -137,7 +170,7 @@ nir_lower_framebuffer(nir_shader *shader)
 
                /* Convert the raw value */
                nir_ssa_def *raw = &new->dest.ssa;
-               nir_ssa_def *converted = nir_native_to_float(&b, raw);
+               nir_ssa_def *converted = nir_native_to_float(&b, raw, format_desc);
 
                /* Rewrite to use the converted value */
                nir_src rewritten = nir_src_for_ssa(converted);
-- 
2.20.1



More information about the mesa-dev mailing list