mesa: add/update comments in _mesa_copy_buffer_subdata()
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vtbl.c
index 16099386565e89e27e3aacc82a584117eb093623..be975d1c41b9d8c2ba932627cefb30ada58d8962 100644 (file)
@@ -49,7 +49,9 @@
 #include "brw_vs.h"
 #include "brw_wm.h"
 
-#include "../glsl/ralloc.h"
+#include "gen6_hiz.h"
+
+#include "glsl/ralloc.h"
 
 static void
 dri_bo_release(drm_intel_bo **bo)
@@ -68,7 +70,6 @@ static void brw_destroy_context( struct intel_context *intel )
 
    brw_destroy_state(brw);
    brw_draw_destroy( brw );
-   brw_clear_validated_bos(brw);
    ralloc_free(brw->wm.compile_data);
 
    dri_bo_release(&brw->curbe.curbe_bo);
@@ -94,37 +95,12 @@ brw_update_draw_buffer(struct intel_context *intel)
 {
    struct gl_context *ctx = &intel->ctx;
    struct gl_framebuffer *fb = ctx->DrawBuffer;
-   struct intel_region *colorRegions[MAX_DRAW_BUFFERS], *depthRegion = NULL;
-   struct intel_renderbuffer *irbDepth = NULL, *irbStencil = NULL;
-   bool fb_has_hiz = intel_framebuffer_has_hiz(fb);
 
    if (!fb) {
       /* this can happen during the initial context initialization */
       return;
    }
 
-   /*
-    * If intel_context is using separate stencil, but the depth attachment
-    * (gl_framebuffer.Attachment[BUFFER_DEPTH]) has a packed depth/stencil
-    * format, then we must install the real depth buffer at fb->_DepthBuffer
-    * and set fb->_DepthBuffer->Wrapped before calling _mesa_update_framebuffer.
-    * Otherwise, _mesa_update_framebuffer will create and install a swras
-    * depth wrapper instead.
-    *
-    * Ditto for stencil.
-    */
-   irbDepth = intel_get_renderbuffer(fb, BUFFER_DEPTH);
-   if (irbDepth && irbDepth->Base.Format == MESA_FORMAT_X8_Z24) {
-      _mesa_reference_renderbuffer(&fb->_DepthBuffer, &irbDepth->Base);
-      irbDepth->Base.Wrapped = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
-   }
-
-   irbStencil = intel_get_renderbuffer(fb, BUFFER_STENCIL);
-   if (irbStencil && irbStencil->Base.Format == MESA_FORMAT_S8) {
-      _mesa_reference_renderbuffer(&fb->_StencilBuffer, &irbStencil->Base);
-      irbStencil->Base.Wrapped = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
-   }
-
    /* Do this here, not core Mesa, since this function is called from
     * many places within the driver.
     */
@@ -143,135 +119,27 @@ brw_update_draw_buffer(struct intel_context *intel)
       return;
    }
 
-   /* How many color buffers are we drawing into?
-    *
-    * If there are zero buffers or the buffer is too big, don't configure any
-    * regions for hardware drawing.  We'll fallback to software below.  Not
-    * having regions set makes some of the software fallback paths faster.
+   /* Mesa's Stencil._Enabled field is updated when
+    * _NEW_BUFFERS | _NEW_STENCIL, but i965 code assumes that the value
+    * only changes with _NEW_STENCIL (which seems sensible).  So flag it
+    * here since this is the _NEW_BUFFERS path.
     */
-   if ((fb->Width > ctx->Const.MaxRenderbufferSize)
-       || (fb->Height > ctx->Const.MaxRenderbufferSize)
-       || (fb->_NumColorDrawBuffers == 0)) {
-      /* writing to 0  */
-      colorRegions[0] = NULL;
-   }
-   else if (fb->_NumColorDrawBuffers > 1) {
-       int i;
-       struct intel_renderbuffer *irb;
-
-       for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
-           irb = intel_renderbuffer(fb->_ColorDrawBuffers[i]);
-           colorRegions[i] = irb ? irb->region : NULL;
-       }
-   }
-   else {
-      /* Get the intel_renderbuffer for the single colorbuffer we're drawing
-       * into.
-       */
-      if (fb->Name == 0) {
-        /* drawing to window system buffer */
-        if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT)
-           colorRegions[0] = intel_get_rb_region(fb, BUFFER_FRONT_LEFT);
-        else
-           colorRegions[0] = intel_get_rb_region(fb, BUFFER_BACK_LEFT);
-      }
-      else {
-        /* drawing to user-created FBO */
-        struct intel_renderbuffer *irb;
-        irb = intel_renderbuffer(fb->_ColorDrawBuffers[0]);
-        colorRegions[0] = (irb && irb->region) ? irb->region : NULL;
-      }
-   }
+   intel->NewGLState |= (_NEW_DEPTH | _NEW_STENCIL);
 
-   /* Check for depth fallback. */
-   if (irbDepth && irbDepth->region) {
-      assert(!fb_has_hiz || irbDepth->Base.Format != MESA_FORMAT_S8_Z24);
-      depthRegion = irbDepth->region;
-   } else if (irbDepth && !irbDepth->region) {
-      depthRegion = NULL;
-   } else { /* !irbDepth */
-      /* No fallback is needed because there is no depth buffer. */
-      depthRegion = NULL;
-   }
-
-   /* Check for stencil fallback. */
-   if (irbStencil && irbStencil->region) {
-      if (!intel->has_separate_stencil)
-        assert(irbStencil->Base.Format == MESA_FORMAT_S8_Z24);
-      if (fb_has_hiz || intel->must_use_separate_stencil)
-        assert(irbStencil->Base.Format == MESA_FORMAT_S8);
-      if (irbStencil->Base.Format == MESA_FORMAT_S8)
-        assert(intel->has_separate_stencil);
-   }
-
-   /* If we have a (packed) stencil buffer attached but no depth buffer,
-    * we still need to set up the shared depth/stencil state so we can use it.
+   /* The driver uses this in places that need to look up
+    * renderbuffers' buffer objects.
     */
-   if (depthRegion == NULL && irbStencil && irbStencil->region
-       && irbStencil->Base.Format == MESA_FORMAT_S8_Z24) {
-      depthRegion = irbStencil->region;
-   }
-
-   /*
-    * Update depth and stencil test state
-    */
-   if (ctx->Driver.Enable) {
-      ctx->Driver.Enable(ctx, GL_DEPTH_TEST,
-                         (ctx->Depth.Test && fb->Visual.depthBits > 0));
-      ctx->Driver.Enable(ctx, GL_STENCIL_TEST,
-                         (ctx->Stencil.Enabled && fb->Visual.stencilBits > 0));
-   }
-   else {
-      /* Mesa's Stencil._Enabled field is updated when
-       * _NEW_BUFFERS | _NEW_STENCIL, but i965 code assumes that the value
-       * only changes with _NEW_STENCIL (which seems sensible).  So flag it
-       * here since this is the _NEW_BUFFERS path.
-       */
-      intel->NewGLState |= (_NEW_DEPTH | _NEW_STENCIL);
-   }
-
-   intel->vtbl.set_draw_region(intel, colorRegions, depthRegion,
-                               fb->_NumColorDrawBuffers);
    intel->NewGLState |= _NEW_BUFFERS;
 
-   /* update viewport since it depends on window size */
-#ifdef I915
-   intelCalcViewport(ctx);
-#else
-   intel->NewGLState |= _NEW_VIEWPORT;
-#endif
-   /* Set state we know depends on drawable parameters:
-    */
-   if (ctx->Driver.Scissor)
-      ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
-                         ctx->Scissor.Width, ctx->Scissor.Height);
-   intel->NewGLState |= _NEW_SCISSOR;
-
-   if (ctx->Driver.DepthRange)
-      ctx->Driver.DepthRange(ctx,
-                            ctx->Viewport.Near,
-                            ctx->Viewport.Far);
+   /* update viewport/scissor since it depends on window size */
+   intel->NewGLState |= _NEW_VIEWPORT | _NEW_SCISSOR;
 
    /* Update culling direction which changes depending on the
     * orientation of the buffer:
     */
-   if (ctx->Driver.FrontFace)
-      ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
-   else
-      intel->NewGLState |= _NEW_POLYGON;
-}
-
-/**
- * called from intelDrawBuffer()
- */
-static void brw_set_draw_region( struct intel_context *intel, 
-                                 struct intel_region *color_regions[],
-                                 struct intel_region *depth_region,
-                                 GLuint num_color_regions)
-{
+   intel->NewGLState |= _NEW_POLYGON;
 }
 
-
 /**
  * called from intel_batchbuffer_flush and children before sending a
  * batchbuffer off.
@@ -309,7 +177,14 @@ static void brw_new_batch( struct intel_context *intel )
 
    brw->state_batch_count = 0;
 
+   /* Gen7 needs to track what the real transform feedback vertex count was at
+    * the start of the batch, since the kernel will be resetting the offset to
+    * 0.
+    */
+   brw->sol.offset_0_batch_start = brw->sol.svbi_0_starting_index;
+
    brw->vb.nr_current_buffers = 0;
+   brw->ib.type = -1;
 
    /* Mark that the current program cache BO has been used by the GPU.
     * It will be reallocated if we need to put new programs in for the
@@ -329,11 +204,20 @@ static void brw_invalidate_state( struct intel_context *intel, GLuint new_state
 static bool brw_is_hiz_depth_format(struct intel_context *intel,
                                     gl_format format)
 {
-   /* In the future, this will support Z_FLOAT32. */
-   return intel->has_hiz && (format == MESA_FORMAT_X8_Z24);
+   if (!intel->has_hiz)
+      return false;
+
+   switch (format) {
+   case MESA_FORMAT_Z32_FLOAT:
+   case MESA_FORMAT_Z32_FLOAT_X24S8:
+   case MESA_FORMAT_X8_Z24:
+   case MESA_FORMAT_S8_Z24:
+      return true;
+   default:
+      return false;
+   }
 }
 
-
 void brwInitVtbl( struct brw_context *brw )
 {
    brw->intel.vtbl.check_vertex_size = 0;
@@ -347,8 +231,18 @@ void brwInitVtbl( struct brw_context *brw )
    brw->intel.vtbl.finish_batch = brw_finish_batch;
    brw->intel.vtbl.destroy = brw_destroy_context;
    brw->intel.vtbl.update_draw_buffer = brw_update_draw_buffer;
-   brw->intel.vtbl.set_draw_region = brw_set_draw_region;
    brw->intel.vtbl.debug_batch = brw_debug_batch;
    brw->intel.vtbl.render_target_supported = brw_render_target_supported;
    brw->intel.vtbl.is_hiz_depth_format = brw_is_hiz_depth_format;
+
+   if (brw->intel.has_hiz) {
+      brw->intel.vtbl.resolve_depth_slice = gen6_resolve_depth_slice;
+      brw->intel.vtbl.resolve_hiz_slice = gen6_resolve_hiz_slice;
+   }
+
+   if (brw->intel.gen >= 7) {
+      gen7_init_vtable_surface_functions(brw);
+   } else if (brw->intel.gen >= 4) {
+      gen4_init_vtable_surface_functions(brw);
+   }
 }