mesa: Branch 'master' - 2 commits

Brian Paul brianp at kemper.freedesktop.org
Thu Apr 19 17:23:53 UTC 2007


 src/mesa/main/image.c    |   31 +++++++++++++++++++++++++++++++
 src/mesa/swrast/s_span.c |   21 +++++++++++++++++----
 2 files changed, 48 insertions(+), 4 deletions(-)

New commits:
diff-tree 6bde08815fae2a5ba95e0446d8c73040d1f321bc (from 8e6207396c6314d07614c80670f4e3196e3a8551)
Author: Brian <brian at yutani.localnet.net>
Date:   Thu Apr 19 11:23:26 2007 -0600

    In _mesa_unpack_depth_span() look for special cases of GLuint->GLushort and GLushort->GLuint conversion.
    
    This improves performance and avoids int/float/int conversion problems that
    can introduce errors during glCopyTexImage().  Another fix for the depth peeling
    algorithm.

diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index 394a7c6..dcd7f10 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -3893,6 +3893,36 @@ _mesa_unpack_depth_span( const GLcontext
 {
    GLfloat depthTemp[MAX_WIDTH], *depthValues;
 
+   /* Look for special cases first.
+    * Not only are these faster, they're less prone to numeric conversion
+    * problems.  Otherwise, converting from an int type to a float then
+    * back to an int type can introduce errors that will show up as
+    * artifacts in things like depth peeling which uses glCopyTexImage.
+    */
+   if (ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) {
+      if (srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_SHORT) {
+         const GLuint *src = (const GLuint *) source;
+         GLushort *dst = (GLushort *) dest;
+         GLuint i;
+         for (i = 0; i < n; i++) {
+            dst[i] = src[i] >> 16;
+         }
+         return;
+      }
+      if (srcType == GL_UNSIGNED_SHORT && dstType == GL_UNSIGNED_INT) {
+         const GLushort *src = (const GLushort *) source;
+         GLuint *dst = (GLuint *) dest;
+         GLuint i;
+         for (i = 0; i < n; i++) {
+            dst[i] = src[i] | (src[i] << 16);
+         }
+         return;
+      }
+      /* XXX may want to add additional cases here someday */
+   }
+
+   /* general case path */
+
    if (dstType == GL_FLOAT) {
       depthValues = (GLfloat *) dest;
    }
@@ -3903,6 +3933,7 @@ _mesa_unpack_depth_span( const GLcontext
    /* XXX we need to obey srcPacking->SwapBytes here!!! */
    (void) srcPacking;
 
+   /* convert incoming values to GLfloat */
    switch (srcType) {
       case GL_BYTE:
           DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT);
diff-tree 8e6207396c6314d07614c80670f4e3196e3a8551 (from 5ca8d4ccf24af1c174ff791f15cf9f19defd9b7e)
Author: Brian <brian at yutani.localnet.net>
Date:   Thu Apr 19 11:21:14 2007 -0600

    Don't allow deferredTexture if using occlusion query and a frag shader.
    
    Occlusion query might depend on the shader killing/discarding fragments.
    Helps fix depth peeling technique.
    Also, minor tweaks in interpolate_wpos().

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index c6efea3..f3b7998 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -776,6 +776,9 @@ interpolate_wpos(GLcontext *ctx, SWspan 
 {
    GLfloat (*wpos)[4] = span->array->attribs[FRAG_ATTRIB_WPOS];
    GLuint i;
+   const GLfloat zScale = 1.0 / ctx->DrawBuffer->_DepthMaxF;
+   GLfloat w, dw;
+
    if (span->arrayMask & SPAN_XY) {
       for (i = 0; i < span->end; i++) {
          wpos[i][0] = (GLfloat) span->array->x[i];
@@ -788,10 +791,13 @@ interpolate_wpos(GLcontext *ctx, SWspan 
          wpos[i][1] = (GLfloat) span->y;
       }
    }
+
+   w = span->attrStart[FRAG_ATTRIB_WPOS][3];
+   dw = span->attrStepX[FRAG_ATTRIB_WPOS][3];
    for (i = 0; i < span->end; i++) {
-      wpos[i][2] = (GLfloat) span->array->z[i] / ctx->DrawBuffer->_DepthMaxF;
-      wpos[i][3] = span->attrStart[FRAG_ATTRIB_WPOS][3]
-                 + i * span->attrStepX[FRAG_ATTRIB_WPOS][3];
+      wpos[i][2] = (GLfloat) span->array->z[i] * zScale;
+      wpos[i][3] = w;
+      w += dw;
    }
 }
 
@@ -1401,7 +1407,10 @@ _swrast_write_rgba_span( GLcontext *ctx,
    ASSERT((span->interpMask & span->arrayMask) == 0);
    ASSERT((span->interpMask & SPAN_RGBA) ^ (span->arrayMask & SPAN_RGBA));
 
-   /* check for conditions that prevent deferred shading */
+   /* check for conditions that prevent deferred shading (doing shading
+    * after stencil/ztest).
+    * XXX move this code into state validation.
+    */
    if (ctx->Color.AlphaEnabled) {
       /* alpha test depends on post-texture/shader colors */
       deferredTexture = GL_FALSE;
@@ -1413,6 +1422,10 @@ _swrast_write_rgba_span( GLcontext *ctx,
             /* Z comes from fragment program/shader */
             deferredTexture = GL_FALSE;
          }
+         else if (ctx->Query.CurrentOcclusionObject) {
+            /* occlusion query depends on shader discard/kill results */
+            deferredTexture = GL_FALSE;
+         }
          else {
             deferredTexture = GL_TRUE;
          }



More information about the mesa-commit mailing list