First attempt at using private back/z buffers.
authorRoland Scheidegger <sroland@tungstengraphics.com>
Tue, 10 Jul 2007 16:07:38 +0000 (18:07 +0200)
committerRoland Scheidegger <sroland@tungstengraphics.com>
Tue, 10 Jul 2007 16:07:38 +0000 (18:07 +0200)
Allocate and use private back and z/stencil buffers.
This is still very broken.

src/mesa/drivers/dri/i915tex/intel_blit.c
src/mesa/drivers/dri/i915tex/intel_context.c
src/mesa/drivers/dri/i915tex/intel_context.h
src/mesa/drivers/dri/i915tex/intel_fbo.c
src/mesa/drivers/dri/i915tex/intel_screen.c
src/mesa/drivers/dri/i915tex/intel_screen.h

index dbe4ba2ac5ef3e678d9401fbb9022b1db3a98cb7..5dcb0ddebbb621deca01698d595aa8c78afcfed4 100644 (file)
@@ -88,6 +88,7 @@ intelCopyBuffer(const __DRIdrawablePrivate * dPriv,
       const int nbox = dPriv->numClipRects;
       const drm_clip_rect_t *pbox = dPriv->pClipRects;
       const int pitch = frontRegion->pitch;
+      const int srcpitch = backRegion->pitch;
       const int cpp = frontRegion->cpp;
       int BR13, CMD;
       int i;
@@ -96,9 +97,12 @@ intelCopyBuffer(const __DRIdrawablePrivate * dPriv,
       ASSERT(intel_fb->Base.Name == 0);    /* Not a user-created FBO */
       ASSERT(frontRegion);
       ASSERT(backRegion);
-      ASSERT(frontRegion->pitch == backRegion->pitch);
+//      ASSERT(frontRegion->pitch == backRegion->pitch);
       ASSERT(frontRegion->cpp == backRegion->cpp);
 
+      DBG("copy buffer, front pitch %d back pitch %d\n",
+        frontRegion->pitch, backRegion->pitch);
+
       if (cpp == 2) {
         BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24);
         CMD = XY_SRC_COPY_BLT_CMD;
@@ -142,7 +146,7 @@ intelCopyBuffer(const __DRIdrawablePrivate * dPriv,
         OUT_RELOC(frontRegion->buffer, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_WRITE,
                   DRM_BO_MASK_MEM | DRM_BO_FLAG_WRITE, 0);
         OUT_BATCH((pbox->y1 << 16) | pbox->x1);
-        OUT_BATCH(BR13 & 0xffff);
+        OUT_BATCH((srcpitch * cpp) & 0xffff);
         OUT_RELOC(backRegion->buffer, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ,
                   DRM_BO_MASK_MEM | DRM_BO_FLAG_READ, 0);
 
index c927dca8e5aab4f7f40c808044ed10fc2c074814..028e57e5ab6ab88521adc006daab25cdda4c09d8 100644 (file)
@@ -569,6 +569,13 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
                  __DRIdrawablePrivate * driReadPriv)
 {
 
+#if 0
+   if (driDrawPriv) {
+      fprintf(stderr, "x %d, y %d, width %d, height %d\n",
+             driDrawPriv->x, driDrawPriv->y, driDrawPriv->w, driDrawPriv->h);
+   }
+#endif
+
    if (driContextPriv) {
       struct intel_context *intel =
          (struct intel_context *) driContextPriv->driverPrivate;
@@ -576,6 +583,9 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
         (struct intel_framebuffer *) driDrawPriv->driverPrivate;
       GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate;
 
+      /* this is a hack so we have a valid context when the region allocation
+         is done. Need a per-screen context? */
+      intel->intelScreen->dummyctxptr = intel;
 
       /* XXX FBO temporary fix-ups! */
       /* if the renderbuffers don't have regions, init them from the context */
@@ -613,6 +623,7 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
       }
 
       _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
+      intel->intelScreen->dummyctxptr = &intel->ctx;
 
       /* The drawbuffer won't always be updated by _mesa_make_current: 
        */
index 9d060eb866f7e70be411f13626ba6b790e268294..7a9af1b5fdab9289fa0b30bc0c0941140a0d688a 100644 (file)
@@ -353,7 +353,7 @@ __memcpy(void *to, const void *from, size_t n)
 /* ================================================================
  * Debugging:
  */
-#define DO_DEBUG               0
+#define DO_DEBUG               1
 #if DO_DEBUG
 extern int INTEL_DEBUG;
 #else
index 349912ffecdb52873ffe2771ec5e144753b4bdec..d3f14bcd25824adf4fbea704e45357bc5736d374 100644 (file)
@@ -257,7 +257,7 @@ intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
       break;
    default:
       _mesa_problem(ctx,
-                    "Unexpected format in intel_alloc_renderbuffer_storage");
+                    "Unexpected format (%x) in intel_alloc_renderbuffer_storage", internalFormat);
       return GL_FALSE;
    }
 
@@ -453,6 +453,29 @@ intel_create_renderbuffer(GLenum intFormat, GLsizei width, GLsizei height,
    return irb;
 }
 
+struct gl_renderbuffer *
+intel_new_renderbuffer_fb(GLcontext * ctx, GLuint intFormat)
+{
+   struct intel_renderbuffer *irb;
+
+   irb = CALLOC_STRUCT(intel_renderbuffer);
+   if (!irb) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
+      return NULL;
+   }
+
+   _mesa_init_renderbuffer(&irb->Base, 0);
+   irb->Base.ClassID = INTEL_RB_CLASS;
+   irb->Base.InternalFormat = intFormat;
+
+   /* intel-specific methods */
+   irb->Base.Delete = intel_delete_renderbuffer;
+   irb->Base.AllocStorage = intel_alloc_renderbuffer_storage;
+   irb->Base.GetPointer = intel_get_pointer;
+   /* span routines set in alloc_storage function */
+
+   return &irb->Base;
+}
 
 /**
  * Create a new renderbuffer object.
index 2acdead63d5d02207c820a2499add5b1e3d0a559..a5a9c796254b56ea99452021d32b4710834b2490 100644 (file)
@@ -156,7 +156,7 @@ intel_recreate_static(intelScreenPrivate *intelScreen,
   }
   return region;
 }
-    
+
 
 /* Create intel_region structs to describe the static front,back,depth
  * buffers created by the xserver. 
@@ -192,7 +192,7 @@ intel_recreate_static_regions(intelScreenPrivate *intelScreen)
                            intelScreen->rotated.pitch /
                            intelScreen->cpp, intelScreen->height);
 
-
+#if 0
    intelScreen->back_region =
       intel_recreate_static(intelScreen,
                            intelScreen->back_region,
@@ -226,6 +226,7 @@ intel_recreate_static_regions(intelScreenPrivate *intelScreen)
                            intelScreen->cpp,
                            intelScreen->depth.pitch / intelScreen->cpp,
                            intelScreen->height);
+#endif
 }
 
 /**
@@ -382,7 +383,7 @@ intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
    intelScreen->rotatedWidth = sarea->virtualX;
    intelScreen->rotatedHeight = sarea->virtualY;
 
-   if (0)
+   if (1)
       intelPrintSAREA(sarea);
 }
 
@@ -614,6 +615,7 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
                                &intel_fb->color_rb[0]->Base);
       }
 
+#if 0
       if (mesaVis->doubleBufferMode) {
          intel_fb->color_rb[1]
             = intel_create_renderbuffer(rgbFormat,
@@ -640,7 +642,6 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
            _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base);
         }
       }
-
       if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) {
          /* combined depth/stencil buffer */
          struct intel_renderbuffer *depthStencilRb
@@ -670,6 +671,39 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
          _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
       }
 
+#else
+      if (mesaVis->doubleBufferMode) {
+         intel_fb->color_rb[1]
+            = intel_new_renderbuffer_fb(NULL, rgbFormat);
+         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
+                               &intel_fb->color_rb[1]->Base);
+        if (screen->third.handle) {
+           struct gl_renderbuffer *tmp_rb = NULL;
+
+           intel_fb->color_rb[2]
+              = intel_new_renderbuffer_fb(NULL, rgbFormat);
+           _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base);
+        }
+      }
+      if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) {
+         /* combined depth/stencil buffer */
+         struct intel_renderbuffer *depthStencilRb
+            = intel_new_renderbuffer_fb(NULL, GL_DEPTH24_STENCIL8_EXT);
+         /* note: bind RB to two attachment points */
+         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
+                               &depthStencilRb->Base);
+         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
+                               &depthStencilRb->Base);
+      }
+      else if (mesaVis->depthBits == 16) {
+         /* just 16-bit depth buffer, no hw stencil */
+         struct intel_renderbuffer *depthRb
+            = intel_new_renderbuffer_fb(NULL, GL_DEPTH_COMPONENT16);
+         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
+      }
+
+#endif
+
       /* now add any/all software-based renderbuffers we may need */
       _mesa_add_soft_renderbuffers(&intel_fb->Base,
                                    GL_FALSE, /* never sw color */
@@ -939,11 +973,18 @@ struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
    * context at screen creation. For now just use the current context.
    */
 
-  GET_CURRENT_CONTEXT(ctx);
+/*  GET_CURRENT_CONTEXT(ctx);
   if (ctx == NULL) {
      _mesa_problem(NULL, "No current context in intelScreenContext\n");
      return NULL;
   }
   return intel_context(ctx);
+*/
+  if (intelScreen->dummyctxptr == NULL) {
+     _mesa_problem(NULL, "No current context in intelScreenContext\n");
+     return NULL;
+  }
+  return intelScreen->dummyctxptr;
+
 }
 
index bac43aadddf0015096d6100f72b5f0f88acf1b16..783ee35524bdc48e133f72c18f51067a2aa7f066 100644 (file)
@@ -96,6 +96,7 @@ typedef struct
    struct _DriBufferPool *staticPool;
    unsigned int maxBatchSize;
    GLboolean havePools;
+   struct intel_context *dummyctxptr;
 } intelScreenPrivate;