i915: Fix complete texturing regression since 27505a105a
[mesa.git] / src / mesa / drivers / dri / i915 / i830_vtbl.c
index 7dba135c1cebf693482f6fca9b31e43a31cb1ecf..e85b2f9b5f23c66fb1b1060a0c2fde0fd1e4001f 100644 (file)
@@ -28,6 +28,7 @@
 #include "i830_context.h"
 #include "i830_reg.h"
 #include "intel_batchbuffer.h"
+#include "intel_mipmap_tree.h"
 #include "intel_regions.h"
 #include "intel_tris.h"
 #include "intel_fbo.h"
@@ -41,8 +42,8 @@
 
 #define FILE_DEBUG_FLAG DEBUG_STATE
 
-static GLboolean i830_check_vertex_size(struct intel_context *intel,
-                                        GLuint expected);
+static bool i830_check_vertex_size(struct intel_context *intel,
+                                  GLuint expected);
 
 #define SZ_TO_HW(sz)  ((sz-2)&0x3)
 #define EMIT_SZ(sz)   (EMIT_1F + (sz) - 1)
@@ -236,7 +237,7 @@ i830_reduced_primitive_state(struct intel_context *intel, GLenum rprim)
 /* Pull apart the vertex format registers and figure out how large a
  * vertex is supposed to be. 
  */
-static GLboolean
+static bool
 i830_check_vertex_size(struct intel_context *intel, GLuint expected)
 {
    struct i830_context *i830 = i830_context(&intel->ctx);
@@ -443,9 +444,9 @@ i830_emit_state(struct intel_context *intel)
 
    aper_array[aper_count++] = intel->batch.bo;
    if (dirty & I830_UPLOAD_BUFFERS) {
-      aper_array[aper_count++] = state->draw_region->buffer;
+      aper_array[aper_count++] = state->draw_region->bo;
       if (state->depth_region)
-         aper_array[aper_count++] = state->depth_region->buffer;
+         aper_array[aper_count++] = state->depth_region->bo;
    }
 
    for (i = 0; i < I830_TEX_UNITS; i++)
@@ -501,13 +502,13 @@ i830_emit_state(struct intel_context *intel)
       BEGIN_BATCH(count);
       OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR0]);
       OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR1]);
-      OUT_RELOC(state->draw_region->buffer,
+      OUT_RELOC(state->draw_region->bo,
                I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
 
       if (state->depth_region) {
          OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR0]);
          OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR1]);
-         OUT_RELOC(state->depth_region->buffer,
+         OUT_RELOC(state->depth_region->bo,
                   I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
       }
 
@@ -593,7 +594,7 @@ static uint32_t i830_render_target_format_for_mesa_format[MESA_FORMAT_COUNT] =
 };
 
 static bool
-i830_render_target_supported(gl_format format)
+i830_render_target_supported(struct intel_context *intel, gl_format format)
 {
    if (format == MESA_FORMAT_S8_Z24 ||
        format == MESA_FORMAT_X8_Z24 ||
@@ -715,34 +716,14 @@ i830_update_draw_buffer(struct intel_context *intel)
    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.
@@ -780,7 +761,7 @@ i830_update_draw_buffer(struct intel_context *intel)
 
        for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
            irb = intel_renderbuffer(fb->_ColorDrawBuffers[i]);
-           colorRegions[i] = irb ? irb->region : NULL;
+           colorRegions[i] = (irb && irb->mt) ? irb->mt->region : NULL;
        }
    }
    else {
@@ -798,102 +779,75 @@ i830_update_draw_buffer(struct intel_context *intel)
         /* drawing to user-created FBO */
         struct intel_renderbuffer *irb;
         irb = intel_renderbuffer(fb->_ColorDrawBuffers[0]);
-        colorRegions[0] = (irb && irb->region) ? irb->region : NULL;
+        colorRegions[0] = (irb && irb->mt->region) ? irb->mt->region : NULL;
       }
    }
 
    if (!colorRegions[0]) {
-      FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, GL_TRUE);
+      FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, true);
    }
    else {
-      FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE);
+      FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, false);
    }
 
    /* Check for depth fallback. */
-   if (irbDepth && irbDepth->region) {
-      assert(!fb_has_hiz || irbDepth->Base.Format != MESA_FORMAT_S8_Z24);
-      FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, GL_FALSE);
-      depthRegion = irbDepth->region;
-   } else if (irbDepth && !irbDepth->region) {
-      FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, GL_TRUE);
+   if (irbDepth && irbDepth->mt) {
+      FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, false);
+      depthRegion = irbDepth->mt->region;
+   } else if (irbDepth && !irbDepth->mt) {
+      FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, true);
       depthRegion = NULL;
    } else { /* !irbDepth */
       /* No fallback is needed because there is no depth buffer. */
-      FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, GL_FALSE);
+      FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, false);
       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);
-      FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, GL_FALSE);
-   } else if (irbStencil && !irbStencil->region) {
-      FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, GL_TRUE);
+   if (irbStencil && irbStencil->mt) {
+      assert(irbStencil->Base.Format == MESA_FORMAT_S8_Z24);
+      FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false);
+   } else if (irbStencil && !irbStencil->mt) {
+      FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, true);
    } else { /* !irbStencil */
       /* No fallback is needed because there is no stencil buffer. */
-      FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, GL_FALSE);
+      FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false);
    }
 
    /* 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.
     */
-   if (depthRegion == NULL && irbStencil && irbStencil->region
+   if (depthRegion == NULL && irbStencil && irbStencil->mt
        && irbStencil->Base.Format == MESA_FORMAT_S8_Z24) {
-      depthRegion = irbStencil->region;
+      depthRegion = irbStencil->mt->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);
-   }
+   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));
 
    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;
+   ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
+                      ctx->Scissor.Width, ctx->Scissor.Height);
 
-   if (ctx->Driver.DepthRange)
-      ctx->Driver.DepthRange(ctx,
-                            ctx->Viewport.Near,
-                            ctx->Viewport.Far);
+   ctx->Driver.DepthRange(ctx, ctx->Viewport.Near, ctx->Viewport.Far);
 
    /* 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;
+   ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
 }
 
 /* This isn't really handled at the moment.
@@ -926,6 +880,12 @@ i830_invalidate_state(struct intel_context *intel, GLuint new_state)
       i830_update_provoking_vertex(&intel->ctx);
 }
 
+static bool
+i830_is_hiz_depth_format(struct intel_context *intel, gl_format format)
+{
+   return false;
+}
+
 void
 i830InitVtbl(struct i830_context *i830)
 {
@@ -943,4 +903,5 @@ i830InitVtbl(struct i830_context *i830)
    i830->intel.vtbl.finish_batch = intel_finish_vb;
    i830->intel.vtbl.invalidate_state = i830_invalidate_state;
    i830->intel.vtbl.render_target_supported = i830_render_target_supported;
+   i830->intel.vtbl.is_hiz_depth_format = i830_is_hiz_depth_format;
 }