util/format: Add a Z24_UNORM_PACKED format

Mali GPUs support Z24_UNORM stored on three bytes instead of four. Add
a new format for this case.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Reviewed-by: Christoph Pillmayer <christoph.pillmayer@arm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37158>
This commit is contained in:
Boris Brezillon 2025-09-03 17:51:32 +02:00 committed by Marge Bot
parent f67d267237
commit 18f352090d
3 changed files with 105 additions and 0 deletions

View file

@ -649,6 +649,12 @@
block: {width: 1, height: 1, depth: 1}
channels: [X8, UN24]
swizzles: [Y, _, _, _]
- name: Z24_UNORM_PACKED
layout: plain
colorspace: ZS
block: {width: 1, height: 1, depth: 1}
channels: [UN24]
swizzles: [X, _, _, _]
- name: Z32_FLOAT_S8X24_UINT
layout: plain
colorspace: ZS

View file

@ -204,6 +204,90 @@ util_format_z16_unorm_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_str
}
}
void
util_format_z24_unorm_packed_unpack_z_float(float *restrict dst_row, unsigned dst_stride,
const uint8_t *restrict src_row, unsigned src_stride,
unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; ++y) {
float *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; ++x) {
uint32_t tmp = src[0] | ((uint32_t)src[1] << 8) | ((uint32_t)src[2] << 16);
*dst++ = z24_unorm_to_z32_float(tmp);
src += 3;
}
src_row += src_stride/sizeof(*src_row);
dst_row += dst_stride/sizeof(*dst_row);
}
}
void
util_format_z24_unorm_packed_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,
const float *restrict src_row, unsigned src_stride,
unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; ++y) {
const float *src = src_row;
uint8_t *dst = dst_row;
for(x = 0; x < width; ++x) {
uint32_t tmp = z32_float_to_z24_unorm(*src++);
dst[0] = tmp;
dst[1] = tmp >> 8;
dst[2] = tmp >> 16;
dst += 3;
}
dst_row += dst_stride/sizeof(*dst_row);
src_row += src_stride/sizeof(*src_row);
}
}
void
util_format_z24_unorm_packed_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,
const uint8_t *restrict src_row, unsigned src_stride,
unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; ++y) {
uint32_t *dst = dst_row;
const uint8_t *src = src_row;
for(x = 0; x < width; ++x) {
uint32_t tmp = src[0] | ((uint32_t)src[1] << 8) | ((uint32_t)src[2] << 16);
*dst++ = z24_unorm_to_z32_unorm(tmp);
src += 3;
}
src_row += src_stride/sizeof(*src_row);
dst_row += dst_stride/sizeof(*dst_row);
}
}
void
util_format_z24_unorm_packed_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,
const uint32_t *restrict src_row, unsigned src_stride,
unsigned width, unsigned height)
{
unsigned x, y;
for(y = 0; y < height; ++y) {
const uint32_t *src = src_row;
uint16_t *dst = (uint16_t *)dst_row;
for(x = 0; x < width; ++x) {
uint32_t tmp = z32_unorm_to_z24_unorm(*src++);
dst[0] = tmp;
dst[1] = tmp >> 8;
dst[2] = tmp >> 16;
dst += 3;
}
dst_row += dst_stride/sizeof(*dst_row);
src_row += src_stride/sizeof(*src_row);
}
}
void
util_format_z32_unorm_unpack_z_float(float *restrict dst_row, unsigned dst_stride,
const uint8_t *restrict src_row, unsigned src_stride,

View file

@ -62,6 +62,21 @@ void
util_format_z16_unorm_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint32_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height);
void
util_format_z24_unorm_packed_unpack_z_float(float *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height);
void
util_format_z24_unorm_packed_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride, const float *restrict src_row, unsigned src_stride, unsigned width, unsigned height);
void
util_format_z24_unorm_packed_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height);
void
util_format_z24_unorm_packed_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride, const uint32_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height);
void
util_format_z32_unorm_unpack_z_float(float *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height);