etnaviv: fix ZS clear value computation
authorLucas Stach <l.stach@pengutronix.de>
Wed, 23 Nov 2022 11:29:40 +0000 (12:29 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 25 Nov 2022 21:23:01 +0000 (21:23 +0000)
Instead of hand-rolling our own conversion and apparently getting the
rounding wrong, just use the common util function.

Fixes piglit test spec@!opengl 1.1@depthstencil-default_fb-clear

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19958>

src/gallium/drivers/etnaviv/etnaviv_translate.h
src/gallium/drivers/etnaviv/etnaviv_util.h

index d155542..eb81001 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "util/format/u_format.h"
 #include "util/u_math.h"
+#include "util/u_pack_color.h"
 
 /* Returned when there is no match of pipe value to etna value */
 #define ETNA_NO_MATCH (~0)
@@ -449,24 +450,14 @@ translate_draw_mode(unsigned mode)
 }
 
 static inline uint32_t
-translate_clear_depth_stencil(enum pipe_format format, float depth,
-                              unsigned stencil)
+translate_clear_depth_stencil(enum pipe_format format, double depth,
+                              uint8_t stencil)
 {
-   uint32_t clear_value = 0;
+   uint32_t clear_value = util_pack_z_stencil(format, depth, stencil);
 
-   // XXX util_pack_color
-   switch (format) {
-   case PIPE_FORMAT_Z16_UNORM:
-      clear_value = etna_cfloat_to_uintN(depth, 16);
+   if (format == PIPE_FORMAT_Z16_UNORM)
       clear_value |= clear_value << 16;
-      break;
-   case PIPE_FORMAT_X8Z24_UNORM:
-   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
-      clear_value = (etna_cfloat_to_uintN(depth, 24) << 8) | (stencil & 0xFF);
-      break;
-   default:
-      DBG("Unhandled pipe format for depth stencil clear: %i", format);
-   }
+
    return clear_value;
 }
 
index f6fe4c4..48b1e7d 100644 (file)
@@ -43,19 +43,6 @@ etna_cfloat_to_uint8(float f)
    return f * 256.0f;
 }
 
-/* clamped float [0.0 .. 1.0] -> [0 .. (1<<bits)-1] */
-static inline uint32_t
-etna_cfloat_to_uintN(float f, int bits)
-{
-   if (f <= 0.0f)
-      return 0;
-
-   if (f >= (1.0f - 1.0f / (1 << bits)))
-      return (1 << bits) - 1;
-
-   return f * (1 << bits);
-}
-
 /* 1/log10(2) */
 #define RCPLOG2 (1.4426950408889634f)