Hi,
GL_EXT_packed_depth_stencil spec doesn't support 8/24 reversed format
and Mesa doesn't support it as well. Unfortunately Intel devices hold
24-bit Z depth value in lower 3 bytes and 8-bit stencil value in upper
byte, so currently a depth_stencil texture doesn't work well on 915/965.
The attached patch tries to fix this issue in mesa core. (Although
this can be done in a device driver, I think it is more simple to do in
mesa core). Could you take a look?
Thanks
Haihao
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index 5fa9d95..218f9a9 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -609,6 +609,9 @@ intelInitContext(struct intel_context *intel,
ctx->Const.MaxPointSizeAA = 3.0;
ctx->Const.PointSizeGranularity = 1.0;
+ /* Z depth value in lower 3 bytes */
+ ctx->Const.DepthStencilInvert = GL_TRUE;
+
/* reinitialize the context point state.
* It depend on constants in __GLcontextRec::Const
*/
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index aa9d112..eb6b65b 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -902,6 +902,9 @@ _mesa_init_constants(GLcontext *ctx)
ctx->Const.ColorReadFormat = GL_RGBA;
ctx->Const.ColorReadType = GL_UNSIGNED_BYTE;
+ /* GL_EXT_packed_depth_stencil */
+ ctx->Const.DepthStencilInvert = GL_FALSE;
+
#if FEATURE_EXT_framebuffer_object
ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 6f17e46..99d6592 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2499,6 +2499,8 @@ struct gl_constants
/* GL_ARB_vertex_shader */
GLuint MaxVertexTextureImageUnits;
GLuint MaxVarying;
+ /* GL_EXT_packed_depth_stencil */
+ GLboolean DepthStencilInvert;
};
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 25381e3..ce3e591 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -2391,7 +2391,8 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
ASSERT(srcType == GL_UNSIGNED_INT_24_8_EXT);
if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes) {
+ !srcPacking->SwapBytes &&
+ !ctx->Const.DepthStencilInvert) {
/* simple path */
memcpy_texture(ctx, dims,
dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
@@ -2433,8 +2434,13 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
srcType, src, srcPacking,
ctx->_ImageTransferState);
/* merge stencil values into depth values */
- for (i = 0; i < srcWidth; i++)
+ for (i = 0; i < srcWidth; i++) {
+ if (ctx->Const.DepthStencilInvert) {
+ dstRow[i] = (dstRow[i] >> 8);
+ stencil[i] = (stencil[i] << 24);
+ }
dstRow[i] |= stencil[i];
+ }
src += srcRowStride;
dstRow += dstRowStride / sizeof(GLuint);
@@ -3621,6 +3627,16 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
const GLuint *src = (const GLuint *) texImage->Data;
src += width * row + width * height * img;
_mesa_memcpy(dest, src, width * sizeof(GLuint));
+
+ if (ctx->Const.DepthStencilInvert) {
+ GLuint *pdest = dest, i;
+
+ for (i = 0; i < width; i++) {
+ *pdest = ((*pdest << 8) | (*pdest >> 24));
+ pdest++;
+ }
+ }
+
if (ctx->Pack.SwapBytes) {
_mesa_swap4((GLuint *) dest, width);
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev