From 783cab811d2fa91b839d86ccf99694a887f1b6e3 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 23 Mar 2022 15:10:51 +1000 Subject: [PATCH] util/format: add new z24/s8 packing helper to pack z32/s8. If zink runs on top of a vulkan impl with no 24-bit float support it needs support to pack into 24-bit for GL. To avoid having to make a temp copy, add a new helper to convert and pack. Reviewed-by: Kenneth Graunke Reviewed-By: Mike Blumenkrantz Part-of: --- src/util/format/u_format_zs.c | 20 ++++++++++++++++++++ src/util/format/u_format_zs.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/util/format/u_format_zs.c b/src/util/format/u_format_zs.c index 0bd5025d2a5..cc4e8026e4a 100644 --- a/src/util/format/u_format_zs.c +++ b/src/util/format/u_format_zs.c @@ -543,6 +543,26 @@ util_format_z24_unorm_s8_uint_pack_separate(uint8_t *restrict dst_row, unsigned } } +void +util_format_z24_unorm_s8_uint_pack_separate_z32(uint8_t *restrict dst_row, unsigned dst_stride, + const float *z_src_row, unsigned z_src_stride, + const uint8_t *s_src_row, unsigned s_src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for (y = 0; y < height; ++y) { + const float *z_src = z_src_row; + const uint8_t *s_src = s_src_row; + uint32_t *dst = (uint32_t *)dst_row; + for (x = 0; x < width; ++x) { + *dst++ = (z32_float_to_z24_unorm(*z_src++) & 0x00ffffff) | ((uint32_t)*s_src++ << 24); + } + dst_row += dst_stride / sizeof(*dst_row); + z_src_row += z_src_stride / sizeof(*z_src_row); + s_src_row += s_src_stride / sizeof(*s_src_row); + } +} + void util_format_s8_uint_z24_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 6ff802a9927..91f95f59eba 100644 --- a/src/util/format/u_format_zs.h +++ b/src/util/format/u_format_zs.h @@ -118,6 +118,9 @@ util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned d void util_format_z24_unorm_s8_uint_pack_separate(uint8_t *restrict dst_row, unsigned dst_stride, const uint32_t *z_src_row, unsigned z_src_stride, const uint8_t *s_src_row, unsigned s_src_stride, unsigned width, unsigned height); +void +util_format_z24_unorm_s8_uint_pack_separate_z32(uint8_t *restrict dst_row, unsigned dst_stride, const float *z_src_row, unsigned z_src_stride, const uint8_t *s_src_row, unsigned s_src_stride, unsigned width, unsigned height); + void util_format_z24_unorm_s8_uint_unpack_z24(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height);