i965: Use intel_upload_space() for pull constant uploads.
authorEric Anholt <eric@anholt.net>
Fri, 1 Nov 2013 01:16:45 +0000 (18:16 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 26 Mar 2014 20:14:57 +0000 (13:14 -0700)
This also happens to fix a leak of the current GS pull constant BO on
context destroy, by just not holding on to the pull const bos after the
surface state is generated.

No statistically significant performance difference on GLB2.7 on HSW at
1024x768 (n=40) or 320x240 (n=44), or on BYT at 320x240 (n=47).

v2: Rebase on intel_upload simplification.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_vs_surface_state.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c

index 9a76ee1187ab260e84be85890ba83c39136d9973..e11365484cd4f549f145e1a7edfdfed77d798a92 100644 (file)
@@ -821,8 +821,6 @@ intelDestroyContext(__DRIcontext * driContextPriv)
    brw_draw_destroy(brw);
 
    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);
 
    free(brw->curbe.last_buf);
    free(brw->curbe.next_buf);
index e1196824571624c6989d9e90a1af8151561196b8..dbe504aab101dfa58b726ba2cce394096ad4a687 100644 (file)
@@ -933,9 +933,6 @@ struct brw_stage_state
     */
    drm_intel_bo *scratch_bo;
 
-   /** Pull constant buffer */
-   drm_intel_bo *const_bo;
-
    /** Offset in the program cache to the program */
    uint32_t prog_offset;
 
index bd97a22f63c96abb96604cb19777b63e51fe9b0a..cbe88ea0c7964373238db5d45c34da9de1f4ea23 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "brw_context.h"
 #include "brw_state.h"
-
+#include "intel_buffer_objects.h"
 
 void
 brw_upload_vec4_pull_constants(struct brw_context *brw,
@@ -52,9 +52,7 @@ brw_upload_vec4_pull_constants(struct brw_context *brw,
    _mesa_load_state_parameters(&brw->ctx, prog->Parameters);
 
    if (!prog_data->base.nr_pull_params) {
-      if (stage_state->const_bo) {
-        drm_intel_bo_unreference(stage_state->const_bo);
-        stage_state->const_bo = NULL;
+      if (stage_state->surf_offset[surf_index]) {
         stage_state->surf_offset[surf_index] = 0;
         brw->state.dirty.brw |= brw_new_constbuf;
       }
@@ -62,32 +60,28 @@ brw_upload_vec4_pull_constants(struct brw_context *brw,
    }
 
    /* _NEW_PROGRAM_CONSTANTS */
-   drm_intel_bo_unreference(stage_state->const_bo);
    uint32_t size = prog_data->base.nr_pull_params * 4;
-   stage_state->const_bo = drm_intel_bo_alloc(brw->bufmgr, "vec4_const_buffer",
-                                           size, 64);
-
-   drm_intel_gem_bo_map_gtt(stage_state->const_bo);
+   drm_intel_bo *const_bo = NULL;
+   uint32_t const_offset;
+   float *constants = intel_upload_space(brw, size, 64,
+                                         &const_bo, &const_offset);
 
    for (i = 0; i < prog_data->base.nr_pull_params; i++) {
-      memcpy(stage_state->const_bo->virtual + i * 4,
-            prog_data->base.pull_param[i],
-            4);
+      constants[i] = *prog_data->base.pull_param[i];
    }
 
    if (0) {
       for (i = 0; i < ALIGN(prog_data->base.nr_pull_params, 4) / 4; i++) {
-        float *row = (float *)stage_state->const_bo->virtual + i * 4;
+        float *row = &constants[i * 4];
         fprintf(stderr, "const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
                  i, row[0], row[1], row[2], row[3]);
       }
    }
 
-   drm_intel_gem_bo_unmap_gtt(stage_state->const_bo);
-
-   brw_create_constant_surface(brw, stage_state->const_bo, 0, size,
+   brw_create_constant_surface(brw, const_bo, const_offset, size,
                                &stage_state->surf_offset[surf_index],
                                false);
+   drm_intel_bo_unreference(const_bo);
 
    brw->state.dirty.brw |= brw_new_constbuf;
 }
index 61f7ba5daf7abb7a35c6510fba119ecdccb514e7..443820b4b889655a44239a65d0a94c78afc7f9a9 100644 (file)
@@ -467,37 +467,32 @@ brw_upload_wm_pull_constants(struct brw_context *brw)
    const int size = brw->wm.prog_data->base.nr_pull_params * sizeof(float);
    const int surf_index =
       brw->wm.prog_data->base.binding_table.pull_constants_start;
-   float *constants;
    unsigned int i;
 
    _mesa_load_state_parameters(ctx, params);
 
    /* CACHE_NEW_WM_PROG */
    if (brw->wm.prog_data->base.nr_pull_params == 0) {
-      if (brw->wm.base.const_bo) {
-        drm_intel_bo_unreference(brw->wm.base.const_bo);
-        brw->wm.base.const_bo = NULL;
+      if (brw->wm.base.surf_offset[surf_index]) {
         brw->wm.base.surf_offset[surf_index] = 0;
         brw->state.dirty.brw |= BRW_NEW_SURFACES;
       }
       return;
    }
 
-   drm_intel_bo_unreference(brw->wm.base.const_bo);
-   brw->wm.base.const_bo = drm_intel_bo_alloc(brw->bufmgr, "WM const bo",
-                                        size, 64);
-
    /* _NEW_PROGRAM_CONSTANTS */
-   drm_intel_gem_bo_map_gtt(brw->wm.base.const_bo);
-   constants = brw->wm.base.const_bo->virtual;
+   drm_intel_bo *const_bo = NULL;
+   uint32_t const_offset;
+   float *constants = intel_upload_space(brw, size, 64,
+                                         &const_bo, &const_offset);
    for (i = 0; i < brw->wm.prog_data->base.nr_pull_params; i++) {
       constants[i] = *brw->wm.prog_data->base.pull_param[i];
    }
-   drm_intel_gem_bo_unmap_gtt(brw->wm.base.const_bo);
 
-   brw_create_constant_surface(brw, brw->wm.base.const_bo, 0, size,
+   brw_create_constant_surface(brw, const_bo, const_offset, size,
                                &brw->wm.base.surf_offset[surf_index],
                                true);
+   drm_intel_bo_unreference(const_bo);
 
    brw->state.dirty.brw |= BRW_NEW_SURFACES;
 }