mesa: Deduplicate _mesa_pack_float_z_row().

util_format_pack_z_float() does the same thing but supports more formats.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10336>
This commit is contained in:
Eric Anholt
2021-04-16 12:29:59 -07:00
committed by Marge Bot
parent 0e20f6a1e9
commit 8a773d770e
2 changed files with 5 additions and 76 deletions
+5 -2
View File
@@ -82,9 +82,12 @@ _mesa_pack_ubyte_rgba_rect(mesa_format format, uint32_t width, uint32_t height,
const uint8_t *src, int32_t srcRowStride,
void *dst, int32_t dstRowStride);
extern void
static inline void
_mesa_pack_float_z_row(mesa_format format, uint32_t n,
const float *src, void *dst);
const float *src, void *dst)
{
util_format_pack_z_float(format, dst, src, n);
}
extern void
_mesa_pack_uint_z_row(mesa_format format, uint32_t n,
-74
View File
@@ -441,80 +441,6 @@ _mesa_get_pack_ubyte_stencil_func(mesa_format format)
}
void
_mesa_pack_float_z_row(mesa_format format, uint32_t n,
const float *src, void *dst)
{
switch (format) {
case MESA_FORMAT_S8_UINT_Z24_UNORM:
case MESA_FORMAT_X8_UINT_Z24_UNORM:
{
/* don't disturb the stencil values */
uint32_t *d = ((uint32_t *) dst);
const double scale = (double) 0xffffff;
uint32_t i;
for (i = 0; i < n; i++) {
uint32_t s = d[i] & 0xff;
uint32_t z = (uint32_t) (src[i] * scale);
assert(z <= 0xffffff);
d[i] = (z << 8) | s;
}
}
break;
case MESA_FORMAT_Z24_UNORM_S8_UINT:
case MESA_FORMAT_Z24_UNORM_X8_UINT:
{
/* don't disturb the stencil values */
uint32_t *d = ((uint32_t *) dst);
const double scale = (double) 0xffffff;
uint32_t i;
for (i = 0; i < n; i++) {
uint32_t s = d[i] & 0xff000000;
uint32_t z = (uint32_t) (src[i] * scale);
assert(z <= 0xffffff);
d[i] = s | z;
}
}
break;
case MESA_FORMAT_Z_UNORM16:
{
uint16_t *d = ((uint16_t *) dst);
const float scale = (float) 0xffff;
uint32_t i;
for (i = 0; i < n; i++) {
d[i] = (uint16_t) (src[i] * scale);
}
}
break;
case MESA_FORMAT_Z_UNORM32:
{
uint32_t *d = ((uint32_t *) dst);
const double scale = (double) 0xffffffff;
uint32_t i;
for (i = 0; i < n; i++) {
d[i] = (uint32_t) (src[i] * scale);
}
}
break;
case MESA_FORMAT_Z_FLOAT32:
memcpy(dst, src, n * sizeof(float));
break;
case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
{
struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
uint32_t i;
for (i = 0; i < n; i++) {
d[i].z = src[i];
}
}
break;
default:
unreachable("unexpected format in _mesa_pack_float_z_row()");
}
}
/**
* The incoming Z values are always in the range [0, 0xffffffff].
*/