etnaviv: fix ZS clear value computation

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>
This commit is contained in:
Lucas Stach 2022-11-23 12:29:40 +01:00 committed by Marge Bot
parent 4449b5a271
commit 58259e1437
2 changed files with 6 additions and 28 deletions

View 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;
}

View 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)