intel: move renderbuffer mapping to separate functions.
authorEric Anholt <eric@anholt.net>
Tue, 15 Jul 2008 21:26:19 +0000 (14:26 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 23 Jul 2008 17:21:24 +0000 (10:21 -0700)
This lets us avoid duplicated code for doing so, including the depthstencil
paths that aren't covered by SpanRenderStart/Finish.  Those paths were
missing the span funcs setup, leading to a null dereference in the fbotexture
demo.

src/mesa/drivers/dri/intel/intel_depthstencil.c
src/mesa/drivers/dri/intel/intel_span.c
src/mesa/drivers/dri/intel/intel_span.h

index 90baecd8c218ce03e8d246be396aaa2eb875b22e..70ba68e9e322fd52e44f3420b91a64bbb0ee1164 100644 (file)
@@ -39,7 +39,7 @@
 #include "intel_fbo.h"
 #include "intel_depthstencil.h"
 #include "intel_regions.h"
-
+#include "intel_span.h"
 
 /**
  * The GL_EXT_framebuffer_object allows the user to create their own
  *
  */
 
-
-
-static void
-map_regions(GLcontext * ctx,
-            struct intel_renderbuffer *depthRb,
-            struct intel_renderbuffer *stencilRb)
-{
-   struct intel_context *intel = intel_context(ctx);
-   if (depthRb && depthRb->region) {
-      intel_region_map(intel, depthRb->region);
-      depthRb->pfMap = depthRb->region->map;
-      depthRb->pfPitch = depthRb->region->pitch;
-   }
-   if (stencilRb && stencilRb->region) {
-      intel_region_map(intel, stencilRb->region);
-      stencilRb->pfMap = stencilRb->region->map;
-      stencilRb->pfPitch = stencilRb->region->pitch;
-   }
-}
-
-static void
-unmap_regions(GLcontext * ctx,
-              struct intel_renderbuffer *depthRb,
-              struct intel_renderbuffer *stencilRb)
-{
-   struct intel_context *intel = intel_context(ctx);
-   if (depthRb && depthRb->region) {
-      intel_region_unmap(intel, depthRb->region);
-      depthRb->pfMap = NULL;
-      depthRb->pfPitch = 0;
-   }
-   if (stencilRb && stencilRb->region) {
-      intel_region_unmap(intel, stencilRb->region);
-      stencilRb->pfMap = NULL;
-      stencilRb->pfPitch = 0;
-   }
-}
-
-
-
 /**
  * Undo the pairing/interleaving between depth and stencil buffers.
  * irb should be a depth/stencil or stencil renderbuffer.
  */
 void
-intel_unpair_depth_stencil(GLcontext * ctx, struct intel_renderbuffer *irb)
+intel_unpair_depth_stencil(GLcontext *ctx, struct intel_renderbuffer *irb)
 {
+   struct intel_context *intel = intel_context(ctx);
+   struct gl_renderbuffer *rb = &irb->Base;
+
    if (irb->PairedStencil) {
       /* irb is a depth/stencil buffer */
       struct gl_renderbuffer *stencilRb;
       struct intel_renderbuffer *stencilIrb;
 
-      ASSERT(irb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+      ASSERT(rb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
 
       stencilRb = _mesa_lookup_renderbuffer(ctx, irb->PairedStencil);
       stencilIrb = intel_renderbuffer(stencilRb);
       if (stencilIrb) {
          /* need to extract stencil values from the depth buffer */
-         ASSERT(stencilIrb->PairedDepth == irb->Base.Name);
-         map_regions(ctx, irb, stencilIrb);
-         _mesa_extract_stencil(ctx, &irb->Base, &stencilIrb->Base);
-         unmap_regions(ctx, irb, stencilIrb);
+        ASSERT(stencilIrb->PairedDepth == rb->Name);
+        intel_renderbuffer_map(intel, rb);
+        intel_renderbuffer_map(intel, stencilRb);
+        _mesa_extract_stencil(ctx, rb, stencilRb);
+        intel_renderbuffer_unmap(intel, stencilRb);
+        intel_renderbuffer_unmap(intel, rb);
          stencilIrb->PairedDepth = 0;
       }
       irb->PairedStencil = 0;
@@ -157,17 +122,19 @@ intel_unpair_depth_stencil(GLcontext * ctx, struct intel_renderbuffer *irb)
       struct gl_renderbuffer *depthRb;
       struct intel_renderbuffer *depthIrb;
 
-      ASSERT(irb->Base._ActualFormat == GL_STENCIL_INDEX8_EXT ||
-             irb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT);
+      ASSERT(rb->_ActualFormat == GL_STENCIL_INDEX8_EXT ||
+             rb->_ActualFormat == GL_DEPTH24_STENCIL8_EXT);
 
       depthRb = _mesa_lookup_renderbuffer(ctx, irb->PairedDepth);
       depthIrb = intel_renderbuffer(depthRb);
       if (depthIrb) {
          /* need to extract stencil values from the depth buffer */
-         ASSERT(depthIrb->PairedStencil == irb->Base.Name);
-         map_regions(ctx, depthIrb, irb);
-         _mesa_extract_stencil(ctx, &depthIrb->Base, &irb->Base);
-         unmap_regions(ctx, depthIrb, irb);
+        ASSERT(depthIrb->PairedStencil == rb->Name);
+        intel_renderbuffer_map(intel, rb);
+        intel_renderbuffer_map(intel, depthRb);
+        _mesa_extract_stencil(ctx, depthRb, rb);
+        intel_renderbuffer_unmap(intel, depthRb);
+        intel_renderbuffer_unmap(intel, rb);
          depthIrb->PairedStencil = 0;
       }
       irb->PairedDepth = 0;
@@ -194,6 +161,7 @@ void
 intel_validate_paired_depth_stencil(GLcontext * ctx,
                                     struct gl_framebuffer *fb)
 {
+   struct intel_context *intel = intel_context(ctx);
    struct intel_renderbuffer *depthRb, *stencilRb;
 
    depthRb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
@@ -230,9 +198,11 @@ intel_validate_paired_depth_stencil(GLcontext * ctx,
                    stencilRb->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT);
 
             /* establish new pairing: interleave stencil into depth buffer */
-            map_regions(ctx, depthRb, stencilRb);
+           intel_renderbuffer_map(intel, &depthRb->Base);
+           intel_renderbuffer_map(intel, &stencilRb->Base);
             _mesa_insert_stencil(ctx, &depthRb->Base, &stencilRb->Base);
-            unmap_regions(ctx, depthRb, stencilRb);
+           intel_renderbuffer_unmap(intel, &stencilRb->Base);
+           intel_renderbuffer_unmap(intel, &depthRb->Base);
             depthRb->PairedStencil = stencilRb->Base.Name;
             stencilRb->PairedDepth = depthRb->Base.Name;
          }
index 4f0855df0a90cfd4d9fbb318a3b8a93bb14176c0..c9d413ec438a8b0caca9687b0f190e7600c1e691 100644 (file)
@@ -474,7 +474,39 @@ static GLubyte *y_tile_swizzle(struct intel_renderbuffer *irb, struct intel_cont
 #define TAG(x) intel_YTile_##x##_z24_s8
 #include "stenciltmp.h"
 
+void
+intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
+{
+   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+
+   if (irb == NULL || irb->region == NULL)
+      return;
+
+   intel_region_map(intel, irb->region);
+
+   irb->pfMap = irb->region->map;
+   irb->pfPitch = irb->region->pitch;
+
+   intel_set_span_functions(intel, rb);
+}
+
+void
+intel_renderbuffer_unmap(struct intel_context *intel,
+                        struct gl_renderbuffer *rb)
+{
+   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+
+   if (irb == NULL || irb->region == NULL)
+      return;
 
+   intel_region_unmap(intel, irb->region);
+
+   irb->pfMap = NULL;
+   irb->pfPitch = 0;
+
+   rb->GetRow = NULL;
+   rb->PutRow = NULL;
+}
 
 /**
  * Map or unmap all the renderbuffers which we may need during
@@ -493,21 +525,13 @@ intel_map_unmap_buffers(struct intel_context *intel, GLboolean map)
 {
    GLcontext *ctx = &intel->ctx;
    GLuint i, j;
-   struct intel_renderbuffer *irb;
 
    /* color draw buffers */
    for (j = 0; j < ctx->DrawBuffer->_NumColorDrawBuffers; j++) {
-      struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[j];
-      irb = intel_renderbuffer(rb);
-      if (irb && irb->region) {
-        intel_set_span_functions(intel, rb);
-        if (map)
-           intel_region_map(intel, irb->region);
-        else
-           intel_region_unmap(intel, irb->region);
-        irb->pfMap = irb->region->map;
-        irb->pfPitch = irb->region->pitch;
-      }
+      if (map)
+        intel_renderbuffer_map(intel, ctx->DrawBuffer->_ColorDrawBuffers[j]);
+      else
+        intel_renderbuffer_unmap(intel, ctx->DrawBuffer->_ColorDrawBuffers[j]);
    }
 
    /* check for render to textures */
@@ -530,16 +554,10 @@ intel_map_unmap_buffers(struct intel_context *intel, GLboolean map)
    }
 
    /* color read buffers */
-   irb = intel_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
-   if (irb && irb->region) {
-      intel_set_span_functions(intel, ctx->ReadBuffer->_ColorReadBuffer);
-      if (map)
-         intel_region_map(intel, irb->region);
-      else
-         intel_region_unmap(intel, irb->region);
-      irb->pfMap = irb->region->map;
-      irb->pfPitch = irb->region->pitch;
-   }
+   if (map)
+      intel_renderbuffer_map(intel, ctx->ReadBuffer->_ColorReadBuffer);
+   else
+      intel_renderbuffer_unmap(intel, ctx->ReadBuffer->_ColorReadBuffer);
 
    /* Account for front/back color page flipping.
     * The span routines use the pfMap and pfPitch fields which will
@@ -572,40 +590,21 @@ intel_map_unmap_buffers(struct intel_context *intel, GLboolean map)
 
    /* depth buffer (Note wrapper!) */
    if (ctx->DrawBuffer->_DepthBuffer) {
-      irb = intel_renderbuffer(ctx->DrawBuffer->_DepthBuffer->Wrapped);
-      if (irb && irb->region) {
-         if (map) {
-           intel_set_span_functions(intel,
-                                    ctx->DrawBuffer->_DepthBuffer->Wrapped);
-            intel_region_map(intel, irb->region);
-            irb->pfMap = irb->region->map;
-            irb->pfPitch = irb->region->pitch;
-         }
-         else {
-            intel_region_unmap(intel, irb->region);
-            irb->pfMap = irb->region->map;
-            irb->pfPitch = irb->region->pitch;
-         }
-      }
+      if (map)
+        intel_renderbuffer_map(intel, ctx->DrawBuffer->_DepthBuffer->Wrapped);
+      else
+        intel_renderbuffer_unmap(intel,
+                                 ctx->DrawBuffer->_DepthBuffer->Wrapped);
    }
 
    /* stencil buffer (Note wrapper!) */
    if (ctx->DrawBuffer->_StencilBuffer) {
-      irb = intel_renderbuffer(ctx->DrawBuffer->_StencilBuffer->Wrapped);
-      if (irb && irb->region) {
-         if (map) {
-           intel_set_span_functions(intel,
-                                    ctx->DrawBuffer->_StencilBuffer->Wrapped);
-            intel_region_map(intel, irb->region);
-            irb->pfMap = irb->region->map;
-            irb->pfPitch = irb->region->pitch;
-         }
-         else {
-            intel_region_unmap(intel, irb->region);
-            irb->pfMap = irb->region->map;
-            irb->pfPitch = irb->region->pitch;
-         }
-      }
+      if (map)
+        intel_renderbuffer_map(intel,
+                               ctx->DrawBuffer->_StencilBuffer->Wrapped);
+      else
+        intel_renderbuffer_unmap(intel,
+                                 ctx->DrawBuffer->_StencilBuffer->Wrapped);
    }
 }
 
index d2d4d6ecd4816e105aefe768931458c10ef2011d..acbeb4abe1c1c6ebc3402df420909411e5095669 100644 (file)
@@ -32,5 +32,9 @@ extern void intelInitSpanFuncs(GLcontext * ctx);
 
 extern void intelSpanRenderFinish(GLcontext * ctx);
 extern void intelSpanRenderStart(GLcontext * ctx);
+void intel_renderbuffer_map(struct intel_context *intel,
+                           struct gl_renderbuffer *rb);
+void intel_renderbuffer_unmap(struct intel_context *intel,
+                             struct gl_renderbuffer *rb);
 
 #endif