Mesa (master): panfrost/midgard: Add helper to encode constant bias

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 26 16:09:33 UTC 2019


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

Author: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Date:   Tue Jun 18 09:02:20 2019 -0700

panfrost/midgard: Add helper to encode constant bias

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>

---

 .../drivers/panfrost/midgard/midgard_compile.c     | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
index 09b11c2ddee..323879aea77 100644
--- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c
+++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
@@ -36,6 +36,7 @@
 #include "main/imports.h"
 #include "compiler/nir/nir_builder.h"
 #include "util/half_float.h"
+#include "util/u_math.h"
 #include "util/u_debug.h"
 #include "util/u_dynarray.h"
 #include "util/list.h"
@@ -1451,6 +1452,39 @@ midgard_tex_format(enum glsl_sampler_dim dim)
         }
 }
 
+/* Tries to attach an explicit LOD / bias as a constant. Returns whether this
+ * was successful */
+
+static bool
+pan_attach_constant_bias(
+                compiler_context *ctx,
+                nir_src lod,
+                midgard_texture_word *word)
+{
+        /* To attach as constant, it has to *be* constant */
+
+        if (!nir_src_is_const(lod))
+                return false;
+
+        float f = nir_src_as_float(lod);
+
+        /* Break into fixed-point */
+        signed lod_int = f;
+        float lod_frac = f - lod_int;
+
+        /* Carry over negative fractions */
+        if (lod_frac < 0.0) {
+                lod_int--;
+                lod_frac += 1.0;
+        }
+
+        /* Encode */
+        word->bias = float_to_ubyte(lod_frac);
+        word->bias_int = lod_int;
+
+        return true;
+}
+
 static void
 emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
 		  unsigned midgard_texop)




More information about the mesa-commit mailing list