mesa: Deduplicate _mesa_pack_uint_z_row().

util_format_pack_z_32unorm() 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:31:53 -07:00 committed by Marge Bot
parent 8a773d770e
commit 90f98b56f8
2 changed files with 5 additions and 78 deletions

View File

@ -89,9 +89,12 @@ _mesa_pack_float_z_row(mesa_format format, uint32_t n,
util_format_pack_z_float(format, dst, src, n);
}
extern void
static inline void
_mesa_pack_uint_z_row(mesa_format format, uint32_t n,
const uint32_t *src, void *dst);
const uint32_t *src, void *dst)
{
util_format_pack_z_32unorm(format, dst, src, n);
}
static inline void
_mesa_pack_ubyte_stencil_row(mesa_format format, uint32_t n,

View File

@ -441,82 +441,6 @@ _mesa_get_pack_ubyte_stencil_func(mesa_format format)
}
/**
* The incoming Z values are always in the range [0, 0xffffffff].
*/
void
_mesa_pack_uint_z_row(mesa_format format, uint32_t n,
const uint32_t *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);
uint32_t i;
for (i = 0; i < n; i++) {
uint32_t s = d[i] & 0xff;
uint32_t z = src[i] & 0xffffff00;
d[i] = z | 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);
uint32_t i;
for (i = 0; i < n; i++) {
uint32_t s = d[i] & 0xff000000;
uint32_t z = src[i] >> 8;
d[i] = s | z;
}
}
break;
case MESA_FORMAT_Z_UNORM16:
{
uint16_t *d = ((uint16_t *) dst);
uint32_t i;
for (i = 0; i < n; i++) {
d[i] = src[i] >> 16;
}
}
break;
case MESA_FORMAT_Z_UNORM32:
memcpy(dst, src, n * sizeof(float));
break;
case MESA_FORMAT_Z_FLOAT32:
{
uint32_t *d = ((uint32_t *) dst);
const double scale = 1.0 / (double) 0xffffffff;
uint32_t i;
for (i = 0; i < n; i++) {
d[i] = (uint32_t) (src[i] * scale);
assert(d[i] >= 0.0f);
assert(d[i] <= 1.0f);
}
}
break;
case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
{
struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
const double scale = 1.0 / (double) 0xffffffff;
uint32_t i;
for (i = 0; i < n; i++) {
d[i].z = (float) (src[i] * scale);
assert(d[i].z >= 0.0f);
assert(d[i].z <= 1.0f);
}
}
break;
default:
unreachable("unexpected format in _mesa_pack_uint_z_row()");
}
}
/**
* Incoming Z/stencil values are always in uint_24_8 format.
*/