i965: Fix up WM push constant setup on gen6.
authorEric Anholt <eric@anholt.net>
Sun, 22 Aug 2010 07:26:09 +0000 (00:26 -0700)
committerEric Anholt <eric@anholt.net>
Sun, 22 Aug 2010 07:52:18 +0000 (00:52 -0700)
Fixes glsl-algebraic-add-add-1.

src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_state_upload.c
src/mesa/drivers/dri/i965/brw_vtbl.c
src/mesa/drivers/dri/i965/gen6_wm_state.c

index cc4e6638e8ba39cd13537d9a390e9766271b0229..68fc8debc6e1d7b322b4da9474927a4a61ff659d 100644 (file)
@@ -654,7 +654,13 @@ struct brw_context
 
       drm_intel_bo *prog_bo;
       drm_intel_bo *state_bo;
-      drm_intel_bo *const_bo;
+      drm_intel_bo *const_bo; /* pull constant buffer. */
+      /**
+       *  This is the push constant BO on gen6.
+       *
+       * Pre-gen6, push constants live in the CURBE.
+       */
+      drm_intel_bo *push_const_bo;
    } wm;
 
 
index af08446f2d8fdaf20c8928fc1dfd7673eaf3a727..c5d296b1295111cec9611e7ff2e0c463bb0781e4 100644 (file)
@@ -107,6 +107,7 @@ extern const struct brw_tracked_state gen6_sf_vp;
 extern const struct brw_tracked_state gen6_urb;
 extern const struct brw_tracked_state gen6_viewport_state;
 extern const struct brw_tracked_state gen6_vs_state;
+extern const struct brw_tracked_state gen6_wm_constants;
 extern const struct brw_tracked_state gen6_wm_state;
 
 /***********************************************************************
index 97266124fe73a8fff624b275d43c449d26b6933b..f51b0719d17543fe3ba014820fc31b3f53e5edf8 100644 (file)
@@ -129,7 +129,7 @@ const struct brw_tracked_state *gen6_atoms[] =
    &gen6_cc_state_pointers,
 
    &brw_vs_constants, /* Before vs_surfaces and constant_buffer */
-   &brw_wm_constants, /* Before wm_surfaces and constant_buffer */
+   &gen6_wm_constants, /* Before wm_surfaces and constant_buffer */
 
    &brw_vs_surfaces,           /* must do before unit */
    &brw_wm_constant_surface,   /* must do before wm surfaces/bind bo */
index 14227a51332f1988370e8461f1168b1af6689cc9..8f1601d10f1bf18ba3d019a250273802f9efa6f0 100644 (file)
@@ -101,6 +101,7 @@ static void brw_destroy_context( struct intel_context *intel )
    dri_bo_release(&brw->wm.prog_bo);
    dri_bo_release(&brw->wm.state_bo);
    dri_bo_release(&brw->wm.const_bo);
+   dri_bo_release(&brw->wm.push_const_bo);
    dri_bo_release(&brw->cc.prog_bo);
    dri_bo_release(&brw->cc.state_bo);
    dri_bo_release(&brw->cc.vp_bo);
index 863c85449d9adc04061ef17fbb64ee01316f0e21..2cd640de17526e15b2652fc8ab41c9037416e9bc 100644 (file)
 #include "program/prog_statevars.h"
 #include "intel_batchbuffer.h"
 
+static void
+prepare_wm_constants(struct brw_context *brw)
+{
+   struct intel_context *intel = &brw->intel;
+   GLcontext *ctx = &intel->ctx;
+   const struct brw_fragment_program *fp =
+      brw_fragment_program_const(brw->fragment_program);
+
+   drm_intel_bo_unreference(brw->wm.push_const_bo);
+   brw->wm.push_const_bo = NULL;
+
+   /* Updates the ParamaterValues[i] pointers for all parameters of the
+    * basic type of PROGRAM_STATE_VAR.
+    */
+   /* XXX: Should this happen somewhere before to get our state flag set? */
+   _mesa_load_state_parameters(ctx, fp->program.Base.Parameters);
+
+   if (brw->wm.prog_data->nr_params != 0) {
+      float *constants;
+      unsigned int i;
+
+      brw->wm.push_const_bo = drm_intel_bo_alloc(intel->bufmgr,
+                                                "WM constant_bo",
+                                                brw->wm.prog_data->nr_params *
+                                                sizeof(float),
+                                                4096);
+      drm_intel_gem_bo_map_gtt(brw->wm.push_const_bo);
+      constants = brw->wm.push_const_bo->virtual;
+      for (i = 0; i < brw->wm.prog_data->nr_params; i++) {
+        constants[i] = *brw->wm.prog_data->param[i];
+      }
+      drm_intel_gem_bo_unmap_gtt(brw->wm.push_const_bo);
+   }
+}
+
+const struct brw_tracked_state gen6_wm_constants = {
+   .dirty = {
+      .mesa  = _NEW_PROGRAM_CONSTANTS,
+      .brw   = 0,
+      .cache = 0,
+   },
+   .prepare = prepare_wm_constants,
+};
+
 static void
 upload_wm_state(struct brw_context *brw)
 {
@@ -40,12 +84,9 @@ upload_wm_state(struct brw_context *brw)
    GLcontext *ctx = &intel->ctx;
    const struct brw_fragment_program *fp =
       brw_fragment_program_const(brw->fragment_program);
-   unsigned int nr_params = fp->program.Base.Parameters->NumParameters;
-   drm_intel_bo *constant_bo;
-   int i;
    uint32_t dw2, dw4, dw5, dw6;
 
-   if (fp->use_const_buffer || nr_params == 0) {
+   if (fp->use_const_buffer || brw->wm.prog_data->nr_params == 0) {
       /* Disable the push constant buffers. */
       BEGIN_BATCH(5);
       OUT_BATCH(CMD_3D_CONSTANT_PS_STATE << 16 | (5 - 2));
@@ -55,35 +96,17 @@ upload_wm_state(struct brw_context *brw)
       OUT_BATCH(0);
       ADVANCE_BATCH();
    } else {
-      /* Updates the ParamaterValues[i] pointers for all parameters of the
-       * basic type of PROGRAM_STATE_VAR.
-       */
-      _mesa_load_state_parameters(ctx, fp->program.Base.Parameters);
-
-      constant_bo = drm_intel_bo_alloc(intel->bufmgr, "WM constant_bo",
-                                      nr_params * 4 * sizeof(float),
-                                      4096);
-      drm_intel_gem_bo_map_gtt(constant_bo);
-      for (i = 0; i < nr_params; i++) {
-        memcpy((char *)constant_bo->virtual + i * 4 * sizeof(float),
-               fp->program.Base.Parameters->ParameterValues[i],
-               4 * sizeof(float));
-      }
-      drm_intel_gem_bo_unmap_gtt(constant_bo);
-
       BEGIN_BATCH(5);
       OUT_BATCH(CMD_3D_CONSTANT_PS_STATE << 16 |
                GEN6_CONSTANT_BUFFER_0_ENABLE |
                (5 - 2));
-      OUT_RELOC(constant_bo,
+      OUT_RELOC(brw->wm.push_const_bo,
                I915_GEM_DOMAIN_RENDER, 0, /* XXX: bad domain */
-               ALIGN(nr_params, 2) / 2 - 1);
+               ALIGN(brw->wm.prog_data->nr_params, 8) / 8 - 1);
       OUT_BATCH(0);
       OUT_BATCH(0);
       OUT_BATCH(0);
       ADVANCE_BATCH();
-
-      drm_intel_bo_unreference(constant_bo);
    }
 
    intel_batchbuffer_emit_mi_flush(intel->batch);