i965: Try to avoid stalls on the GPU when doing glBufferSubData().
[mesa.git] / src / mesa / drivers / dri / i965 / brw_context.c
index ec3a750e87f6831ec14b17eae2061bdb53c54d99..cb82fb042ef39411f99c9097b4f278c25997fbd0 100644 (file)
@@ -37,7 +37,6 @@
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/points.h"
-#include "main/simple_list.h"
 #include "main/version.h"
 #include "main/vtxfmt.h"
 
@@ -395,7 +394,18 @@ brw_initialize_context_constants(struct brw_context *brw)
 
    ctx->Const.NativeIntegers = true;
    ctx->Const.UniformBooleanTrue = 1;
+
+   /* From the gen4 PRM, volume 4 page 127:
+    *
+    *     "For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
+    *      the base address of the first element of the surface, computed in
+    *      software by adding the surface base address to the byte offset of
+    *      the element in the buffer."
+    *
+    * However, unaligned accesses are slower, so enforce buffer alignment.
+    */
    ctx->Const.UniformBufferOffsetAlignment = 16;
+   ctx->Const.TextureBufferOffsetAlignment = 16;
 
    if (brw->gen >= 6) {
       ctx->Const.MaxVarying = 32;
@@ -530,7 +540,15 @@ brwCreateContext(gl_api api,
    brw->must_use_separate_stencil = screen->hw_must_use_separate_stencil;
    brw->has_swizzling = screen->hw_has_swizzling;
 
-   brwInitVtbl( brw );
+   if (brw->gen >= 7) {
+      gen7_init_vtable_surface_functions(brw);
+      gen7_init_vtable_sampler_functions(brw);
+      brw->vtbl.emit_depth_stencil_hiz = gen7_emit_depth_stencil_hiz;
+   } else {
+      gen4_init_vtable_surface_functions(brw);
+      gen4_init_vtable_sampler_functions(brw);
+      brw->vtbl.emit_depth_stencil_hiz = brw_emit_depth_stencil_hiz;
+   }
 
    brw_init_driver_functions(brw, &functions);
 
@@ -683,39 +701,58 @@ intelDestroyContext(__DRIcontext * driContextPriv)
    struct gl_context *ctx = &brw->ctx;
 
    assert(brw); /* should never be null */
-   if (brw) {
-      /* Dump a final BMP in case the application doesn't call SwapBuffers */
-      if (INTEL_DEBUG & DEBUG_AUB) {
-         intel_batchbuffer_flush(brw);
-         aub_dump_bmp(&brw->ctx);
-      }
+   if (!brw)
+      return;
 
-      _mesa_meta_free(&brw->ctx);
+   /* Dump a final BMP in case the application doesn't call SwapBuffers */
+   if (INTEL_DEBUG & DEBUG_AUB) {
+      intel_batchbuffer_flush(brw);
+      aub_dump_bmp(&brw->ctx);
+   }
 
-      brw->vtbl.destroy(brw);
+   _mesa_meta_free(&brw->ctx);
 
-      if (ctx->swrast_context) {
-         _swsetup_DestroyContext(&brw->ctx);
-         _tnl_DestroyContext(&brw->ctx);
-      }
-      _vbo_DestroyContext(&brw->ctx);
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
+      /* Force a report. */
+      brw->shader_time.report_time = 0;
 
-      if (ctx->swrast_context)
-         _swrast_DestroyContext(&brw->ctx);
+      brw_collect_and_report_shader_time(brw);
+      brw_destroy_shader_time(brw);
+   }
 
-      intel_batchbuffer_free(brw);
+   brw_destroy_state(brw);
+   brw_draw_destroy(brw);
 
-      drm_intel_bo_unreference(brw->first_post_swapbuffers_batch);
-      brw->first_post_swapbuffers_batch = NULL;
+   drm_intel_bo_unreference(brw->curbe.curbe_bo);
+   drm_intel_bo_unreference(brw->vs.base.const_bo);
+   drm_intel_bo_unreference(brw->wm.base.const_bo);
 
-      driDestroyOptionCache(&brw->optionCache);
+   free(brw->curbe.last_buf);
+   free(brw->curbe.next_buf);
 
-      /* free the Mesa context */
-      _mesa_free_context_data(&brw->ctx);
+   drm_intel_gem_context_destroy(brw->hw_ctx);
 
-      ralloc_free(brw);
-      driContextPriv->driverPrivate = NULL;
+   if (ctx->swrast_context) {
+      _swsetup_DestroyContext(&brw->ctx);
+      _tnl_DestroyContext(&brw->ctx);
    }
+   _vbo_DestroyContext(&brw->ctx);
+
+   if (ctx->swrast_context)
+      _swrast_DestroyContext(&brw->ctx);
+
+   intel_batchbuffer_free(brw);
+
+   drm_intel_bo_unreference(brw->first_post_swapbuffers_batch);
+   brw->first_post_swapbuffers_batch = NULL;
+
+   driDestroyOptionCache(&brw->optionCache);
+
+   /* free the Mesa context */
+   _mesa_free_context_data(&brw->ctx);
+
+   ralloc_free(brw);
+   driContextPriv->driverPrivate = NULL;
 }
 
 GLboolean