From 580a1ba7065698ef86b6222b2bcbf89147b1e4e9 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 19 Apr 2021 14:49:08 -0700 Subject: [PATCH] mesa: Move per-pixel Z pack functions to swrast. Only swrast uses them, and this makes it clearer why we only need partial format support for them, avoids linker work deleting them for gallium drivers, and means they will automatically go away when we get to finally delete swrast. Reviewed-by: Ian Romanick Reviewed-by: Adam Jackson Part-of: --- src/mesa/main/format_pack.h | 15 ---- src/mesa/main/format_pack.py | 142 ----------------------------------- src/mesa/swrast/s_depth.c | 90 +++++++++++++++++++++- src/mesa/swrast/s_stencil.c | 62 ++++++++++++++- 4 files changed, 149 insertions(+), 160 deletions(-) diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h index ae5738e5c8f..7fd186beccc 100644 --- a/src/mesa/main/format_pack.h +++ b/src/mesa/main/format_pack.h @@ -34,21 +34,6 @@ extern "C" { #endif -/** Pack a uint32_t Z value to dest address */ -typedef void (*mesa_pack_uint_z_func)(const uint32_t *src, void *dst); - -/** Pack a uint8_t stencil value to dest address */ -typedef void (*mesa_pack_ubyte_stencil_func)(const uint8_t *src, void *dst); - - -extern mesa_pack_uint_z_func -_mesa_get_pack_uint_z_func(mesa_format format); - - -extern mesa_pack_ubyte_stencil_func -_mesa_get_pack_ubyte_stencil_func(mesa_format format); - - static inline void _mesa_pack_float_rgba_row(mesa_format format, uint32_t n, const float src[][4], void *dst) diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py index 286623b83c0..1a8d2f4e5d0 100644 --- a/src/mesa/main/format_pack.py +++ b/src/mesa/main/format_pack.py @@ -220,148 +220,6 @@ _mesa_pack_ubyte_rgba_rect(mesa_format format, uint32_t width, uint32_t height, } } - -/** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */ -struct z32f_x24s8 -{ - float z; - uint32_t x24s8; -}; - - -/** - ** Pack uint Z pixels. The incoming src value is always in - ** the range [0, 2^32-1]. - **/ - -static void -pack_uint_S8_UINT_Z24_UNORM(const uint32_t *src, void *dst) -{ - /* don't disturb the stencil values */ - uint32_t *d = ((uint32_t *) dst); - uint32_t s = *d & 0xff; - uint32_t z = *src & 0xffffff00; - *d = z | s; -} - -static void -pack_uint_Z24_UNORM_S8_UINT(const uint32_t *src, void *dst) -{ - /* don't disturb the stencil values */ - uint32_t *d = ((uint32_t *) dst); - uint32_t s = *d & 0xff000000; - uint32_t z = *src >> 8; - *d = s | z; -} - -static void -pack_uint_Z_UNORM16(const uint32_t *src, void *dst) -{ - uint16_t *d = ((uint16_t *) dst); - *d = *src >> 16; -} - -static void -pack_uint_Z_UNORM32(const uint32_t *src, void *dst) -{ - uint32_t *d = ((uint32_t *) dst); - *d = *src; -} - -/** - ** Pack uint to Z_FLOAT32 or Z_FLOAT32_X24S8. - **/ - -static void -pack_uint_Z_FLOAT32(const uint32_t *src, void *dst) -{ - float *d = ((float *) dst); - const double scale = 1.0 / (double) 0xffffffff; - *d = (float) (*src * scale); - assert(*d >= 0.0f); - assert(*d <= 1.0f); -} - -mesa_pack_uint_z_func -_mesa_get_pack_uint_z_func(mesa_format format) -{ - switch (format) { - case MESA_FORMAT_S8_UINT_Z24_UNORM: - case MESA_FORMAT_X8_UINT_Z24_UNORM: - return pack_uint_S8_UINT_Z24_UNORM; - case MESA_FORMAT_Z24_UNORM_S8_UINT: - case MESA_FORMAT_Z24_UNORM_X8_UINT: - return pack_uint_Z24_UNORM_S8_UINT; - case MESA_FORMAT_Z_UNORM16: - return pack_uint_Z_UNORM16; - case MESA_FORMAT_Z_UNORM32: - return pack_uint_Z_UNORM32; - case MESA_FORMAT_Z_FLOAT32: - case MESA_FORMAT_Z32_FLOAT_S8X24_UINT: - return pack_uint_Z_FLOAT32; - default: - unreachable("unexpected format in _mesa_get_pack_uint_z_func()"); - } -} - - -/** - ** Pack ubyte stencil pixels - **/ - -static void -pack_ubyte_stencil_Z24_S8(const uint8_t *src, void *dst) -{ - /* don't disturb the Z values */ - uint32_t *d = ((uint32_t *) dst); - uint32_t s = *src; - uint32_t z = *d & 0xffffff00; - *d = z | s; -} - -static void -pack_ubyte_stencil_S8_Z24(const uint8_t *src, void *dst) -{ - /* don't disturb the Z values */ - uint32_t *d = ((uint32_t *) dst); - uint32_t s = *src << 24; - uint32_t z = *d & 0xffffff; - *d = s | z; -} - -static void -pack_ubyte_stencil_S8(const uint8_t *src, void *dst) -{ - uint8_t *d = (uint8_t *) dst; - *d = *src; -} - -static void -pack_ubyte_stencil_Z32_FLOAT_X24S8(const uint8_t *src, void *dst) -{ - float *d = ((float *) dst); - d[1] = *src; -} - - -mesa_pack_ubyte_stencil_func -_mesa_get_pack_ubyte_stencil_func(mesa_format format) -{ - switch (format) { - case MESA_FORMAT_S8_UINT_Z24_UNORM: - return pack_ubyte_stencil_Z24_S8; - case MESA_FORMAT_Z24_UNORM_S8_UINT: - return pack_ubyte_stencil_S8_Z24; - case MESA_FORMAT_S_UINT8: - return pack_ubyte_stencil_S8; - case MESA_FORMAT_Z32_FLOAT_S8X24_UINT: - return pack_ubyte_stencil_Z32_FLOAT_X24S8; - default: - unreachable("unexpected format in _mesa_pack_ubyte_stencil_func()"); - } -} - - """ template = Template(string, future_imports=['division']) diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c index 7af764f671b..7e28935f901 100644 --- a/src/mesa/swrast/s_depth.c +++ b/src/mesa/swrast/s_depth.c @@ -238,6 +238,92 @@ get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb, } +/** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */ +struct z32f_x24s8 +{ + float z; + uint32_t x24s8; +}; + + +/** + ** Pack uint Z pixels. The incoming src value is always in + ** the range [0, 2^32-1]. + **/ + +static void +pack_uint_S8_UINT_Z24_UNORM(const uint32_t *src, void *dst) +{ + /* don't disturb the stencil values */ + uint32_t *d = ((uint32_t *) dst); + uint32_t s = *d & 0xff; + uint32_t z = *src & 0xffffff00; + *d = z | s; +} + +static void +pack_uint_Z24_UNORM_S8_UINT(const uint32_t *src, void *dst) +{ + /* don't disturb the stencil values */ + uint32_t *d = ((uint32_t *) dst); + uint32_t s = *d & 0xff000000; + uint32_t z = *src >> 8; + *d = s | z; +} + +static void +pack_uint_Z_UNORM16(const uint32_t *src, void *dst) +{ + uint16_t *d = ((uint16_t *) dst); + *d = *src >> 16; +} + +static void +pack_uint_Z_UNORM32(const uint32_t *src, void *dst) +{ + uint32_t *d = ((uint32_t *) dst); + *d = *src; +} + +/** + ** Pack uint to Z_FLOAT32 or Z_FLOAT32_X24S8. + **/ + +static void +pack_uint_Z_FLOAT32(const uint32_t *src, void *dst) +{ + float *d = ((float *) dst); + const double scale = 1.0 / (double) 0xffffffff; + *d = (float) (*src * scale); + assert(*d >= 0.0f); + assert(*d <= 1.0f); +} + +/** Pack a uint32_t Z value to dest address */ +typedef void (*mesa_pack_uint_z_func)(const uint32_t *src, void *dst); + +static mesa_pack_uint_z_func +get_pack_uint_z_func(mesa_format format) +{ + switch (format) { + case MESA_FORMAT_S8_UINT_Z24_UNORM: + case MESA_FORMAT_X8_UINT_Z24_UNORM: + return pack_uint_S8_UINT_Z24_UNORM; + case MESA_FORMAT_Z24_UNORM_S8_UINT: + case MESA_FORMAT_Z24_UNORM_X8_UINT: + return pack_uint_Z24_UNORM_S8_UINT; + case MESA_FORMAT_Z_UNORM16: + return pack_uint_Z_UNORM16; + case MESA_FORMAT_Z_UNORM32: + return pack_uint_Z_UNORM32; + case MESA_FORMAT_Z_FLOAT32: + case MESA_FORMAT_Z32_FLOAT_S8X24_UINT: + return pack_uint_Z_FLOAT32; + default: + unreachable("unexpected format in get_pack_uint_z_func()"); + } +} + /** * Put an array of 32-bit z values into the depth buffer. * Note: the z values are always in the range [0, 2^32-1]. @@ -262,7 +348,7 @@ put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb, } } else { - mesa_pack_uint_z_func packZ = _mesa_get_pack_uint_z_func(rb->Format); + mesa_pack_uint_z_func packZ = get_pack_uint_z_func(rb->Format); const GLint bpp = _mesa_get_format_bytes(rb->Format); const GLint rowStride = srb->RowStride; for (i = 0; i < count; i++) { @@ -379,7 +465,7 @@ _swrast_depth_test_span(struct gl_context *ctx, SWspan *span) } else { /* horizontal row */ - mesa_pack_uint_z_func packZ = _mesa_get_pack_uint_z_func(rb->Format); + mesa_pack_uint_z_func packZ = get_pack_uint_z_func(rb->Format); GLubyte *dst = zStart; GLuint i; for (i = 0; i < count; i++) { diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c index 5c1118bba69..70d814e9da5 100644 --- a/src/mesa/swrast/s_stencil.c +++ b/src/mesa/swrast/s_stencil.c @@ -320,6 +320,66 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb, } + +/** + ** Pack ubyte stencil pixels + **/ + +static void +pack_ubyte_stencil_Z24_S8(const uint8_t *src, void *dst) +{ + /* don't disturb the Z values */ + uint32_t *d = ((uint32_t *) dst); + uint32_t s = *src; + uint32_t z = *d & 0xffffff00; + *d = z | s; +} + +static void +pack_ubyte_stencil_S8_Z24(const uint8_t *src, void *dst) +{ + /* don't disturb the Z values */ + uint32_t *d = ((uint32_t *) dst); + uint32_t s = *src << 24; + uint32_t z = *d & 0xffffff; + *d = s | z; +} + +static void +pack_ubyte_stencil_S8(const uint8_t *src, void *dst) +{ + uint8_t *d = (uint8_t *) dst; + *d = *src; +} + +static void +pack_ubyte_stencil_Z32_FLOAT_X24S8(const uint8_t *src, void *dst) +{ + float *d = ((float *) dst); + d[1] = *src; +} + +/** Pack a uint8_t stencil value to dest address */ +typedef void (*mesa_pack_ubyte_stencil_func)(const uint8_t *src, void *dst); + +static mesa_pack_ubyte_stencil_func +get_pack_ubyte_stencil_func(mesa_format format) +{ + switch (format) { + case MESA_FORMAT_S8_UINT_Z24_UNORM: + return pack_ubyte_stencil_Z24_S8; + case MESA_FORMAT_Z24_UNORM_S8_UINT: + return pack_ubyte_stencil_S8_Z24; + case MESA_FORMAT_S_UINT8: + return pack_ubyte_stencil_S8; + case MESA_FORMAT_Z32_FLOAT_S8X24_UINT: + return pack_ubyte_stencil_Z32_FLOAT_X24S8; + default: + unreachable("unexpected format in get_pack_ubyte_stencil_func()"); + } +} + + /** * Put 8-bit stencil values at random locations into the stencil buffer. */ @@ -330,7 +390,7 @@ put_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb, { const GLint w = rb->Width, h = rb->Height; mesa_pack_ubyte_stencil_func pack_stencil = - _mesa_get_pack_ubyte_stencil_func(rb->Format); + get_pack_ubyte_stencil_func(rb->Format); GLuint i; for (i = 0; i < count; i++) {