Module: Mesa Branch: main Commit: 2baa40b0411c25cf0a0c3787077a6a13b560a04e URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2baa40b0411c25cf0a0c3787077a6a13b560a04e
Author: Pierre-Eric Pelloux-Prayer <[email protected]> Date: Mon Sep 12 11:00:04 2022 +0200 mesa: simplify _mesa_texstore_z24_s8 and s8_z24 The spec says: If the base internal format is DEPTH_STENCIL and format is not DEPTH_STENCIL, then the values of the stencil index texture components are undefined. Which can be translated as: we don't need to bother preserving the original stencil values. Suggested by Emma Anholt. Reviewed-by: Emma Anholt <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18484> --- src/mesa/main/texstore.c | 65 ++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 8679b52bb77..d5d0ac57bef 100755 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -345,6 +345,17 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS) return GL_FALSE; } + /* + * The spec "8.5. TEXTURE IMAGE SPECIFICATION" says: + * + * If the base internal format is DEPTH_STENCIL and format is not DEPTH_STENCIL, + * then the values of the stencil index texture components are undefined. + * + * but there doesn't seem to be corresponding text saying that depth is + * undefined when a stencil format is supplied. + */ + const bool keepdepth = (srcFormat == GL_STENCIL_INDEX); + /* In case we only upload depth we need to preserve the stencil */ for (img = 0; img < srcDepth; img++) { GLuint *dstRow = (GLuint *) dstSlices[img]; @@ -355,24 +366,16 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS) img, 0, 0); for (row = 0; row < srcHeight; row++) { GLint i; - GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE; - - if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */ - keepstencil = GL_TRUE; - } - else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */ - keepdepth = GL_TRUE; - } - if (keepdepth == GL_FALSE) + if (!keepdepth) /* the 24 depth bits will be in the low position: */ _mesa_unpack_depth_span(ctx, srcWidth, GL_UNSIGNED_INT, /* dst type */ - keepstencil ? depth : dstRow, /* dst addr */ + depth, /* dst addr */ depthScale, srcType, src, srcPacking); - if (keepstencil == GL_FALSE) + if (srcFormat != GL_DEPTH_COMPONENT) /* get the 8-bit stencil values */ _mesa_unpack_stencil_span(ctx, srcWidth, GL_UNSIGNED_BYTE, /* dst type */ @@ -381,10 +384,10 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS) ctx->_ImageTransferState); for (i = 0; i < srcWidth; i++) { - if (keepstencil) - dstRow[i] = depth[i] << 8 | (dstRow[i] & 0x000000FF); - else + if (keepdepth) dstRow[i] = (dstRow[i] & 0xFFFFFF00) | (stencil[i] & 0xFF); + else + dstRow[i] = depth[i] << 8 | (stencil[i] & 0xFF); } src += srcRowStride; dstRow += dstRowStride / sizeof(GLuint); @@ -427,6 +430,17 @@ _mesa_texstore_s8_z24(TEXSTORE_PARAMS) return GL_FALSE; } + /* + * The spec "8.5. TEXTURE IMAGE SPECIFICATION" says: + * + * If the base internal format is DEPTH_STENCIL and format is not DEPTH_STENCIL, + * then the values of the stencil index texture components are undefined. + * + * but there doesn't seem to be corresponding text saying that depth is + * undefined when a stencil format is supplied. + */ + const bool keepdepth = (srcFormat == GL_STENCIL_INDEX); + for (img = 0; img < srcDepth; img++) { GLuint *dstRow = (GLuint *) dstSlices[img]; const GLubyte *src @@ -434,18 +448,11 @@ _mesa_texstore_s8_z24(TEXSTORE_PARAMS) srcWidth, srcHeight, srcFormat, srcType, img, 0, 0); + for (row = 0; row < srcHeight; row++) { GLint i; - GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE; - if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */ - keepstencil = GL_TRUE; - } - else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */ - keepdepth = GL_TRUE; - } - - if (keepdepth == GL_FALSE) + if (!keepdepth) /* the 24 depth bits will be in the low position: */ _mesa_unpack_depth_span(ctx, srcWidth, GL_UNSIGNED_INT, /* dst type */ @@ -453,7 +460,7 @@ _mesa_texstore_s8_z24(TEXSTORE_PARAMS) depthScale, srcType, src, srcPacking); - if (keepstencil == GL_FALSE) + if (srcFormat != GL_DEPTH_COMPONENT) /* get the 8-bit stencil values */ _mesa_unpack_stencil_span(ctx, srcWidth, GL_UNSIGNED_BYTE, /* dst type */ @@ -463,14 +470,12 @@ _mesa_texstore_s8_z24(TEXSTORE_PARAMS) /* merge stencil values into depth values */ for (i = 0; i < srcWidth; i++) { - if (!keepstencil && !keepdepth) - dstRow[i] = depth[i] | (stencil[i] << 24); - else if (keepstencil) - dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000); - else + if (keepdepth) dstRow[i] = (dstRow[i] & 0xFFFFFF) | (stencil[i] << 24); - + else + dstRow[i] = depth[i] | (stencil[i] << 24); } + src += srcRowStride; dstRow += dstRowStride / sizeof(GLuint); }
