From 18f352090d442d7ca5c3e01047eb58c5f52c26d9 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Wed, 3 Sep 2025 17:51:32 +0200 Subject: [PATCH] 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 Reviewed-by: Eric R. Smith Reviewed-by: Christoph Pillmayer Part-of: --- src/util/format/u_format.yaml | 6 +++ src/util/format/u_format_zs.c | 84 +++++++++++++++++++++++++++++++++++ src/util/format/u_format_zs.h | 15 +++++++ 3 files changed, 105 insertions(+) diff --git a/src/util/format/u_format.yaml b/src/util/format/u_format.yaml index 9d6050540d1..b1012095f00 100644 --- a/src/util/format/u_format.yaml +++ b/src/util/format/u_format.yaml @@ -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 diff --git a/src/util/format/u_format_zs.c b/src/util/format/u_format_zs.c index 4fe54c59254..4326daef526 100644 --- a/src/util/format/u_format_zs.c +++ b/src/util/format/u_format_zs.c @@ -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, diff --git a/src/util/format/u_format_zs.h b/src/util/format/u_format_zs.h index 00bc0a79a91..c192e018549 100644 --- a/src/util/format/u_format_zs.h +++ b/src/util/format/u_format_zs.h @@ -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);