i965: Make the old VS backend record pull constant references in pull_params[].
authorEric Anholt <eric@anholt.net>
Mon, 22 Aug 2011 18:32:11 +0000 (11:32 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 30 Aug 2011 19:09:40 +0000 (12:09 -0700)
We'll be using that to track things for the new VS backend, and this will
avoid cluttering brw_vs_surface_state.c for it.

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

index 21068d9cf735d1c7b9695af17e0fbb7413c66ec8..69821d919141f94c74da7ed09b4a5e6f56cecf3e 100644 (file)
@@ -312,6 +312,7 @@ struct brw_vs_prog_data {
    GLuint total_grf;
    GLbitfield64 outputs_written;
    GLuint nr_params;       /**< number of float params/constants */
+   GLuint nr_pull_params; /**< number of dwords referenced by pull_param[] */
    GLuint total_scratch;
 
    GLuint inputs_read;
index bfee811e13d66fe0e534a456f56f272a31edc5ab..63d40611d25e75ba3d95ebe2ccd968a6c6fa9286 100644 (file)
@@ -147,6 +147,8 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c )
    int constant = 0;
    int vert_result_reoder[VERT_RESULT_MAX];
    int bfc = 0;
+   struct brw_vertex_program *vp = c->vp;
+   const struct gl_program_parameter_list *params = vp->program.Base.Parameters;
 
    /* Determine whether to use a real constant buffer or use a block
     * of GRF registers for constants.  The later is faster but only
@@ -249,6 +251,18 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c )
    if (constant == max_constant)
       c->vp->use_const_buffer = GL_TRUE;
 
+   /* Set up the references to the pull parameters if present.  This backend
+    * uses a 1:1 mapping from Mesa IR's index to location in the pull constant
+    * buffer, while the new VS backend allocates values to the pull buffer on
+    * demand.
+    */
+   if (c->vp->use_const_buffer) {
+      for (i = 0; i < params->NumParameters * 4; i++) {
+        c->prog_data.pull_param[i] = &params->ParameterValues[i / 4][i % 4].f;
+      }
+      c->prog_data.nr_pull_params = i;
+   }
+
    for (i = 0; i < constant; i++) {
       c->regs[PROGRAM_STATE_VAR][i] = stride(brw_vec4_grf(reg + i / 2,
                                                          (i % 2) * 4),
index f9ee4d112a5b991c538c33ab364f8965731ceb11..6748ff9aeb51061d2b7da597ef2d047b77e10479 100644 (file)
@@ -47,10 +47,10 @@ prepare_vs_constants(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->intel.ctx;
    struct intel_context *intel = &brw->intel;
+   /* BRW_NEW_VERTEX_PROGRAM */
    struct brw_vertex_program *vp =
       (struct brw_vertex_program *) brw->vertex_program;
    const struct gl_program_parameter_list *params = vp->program.Base.Parameters;
-   const int size = params->NumParameters * 4 * sizeof(GLfloat);
    int i;
 
    if (vp->program.IsNVProgram)
@@ -61,8 +61,8 @@ prepare_vs_constants(struct brw_context *brw)
     */
    _mesa_load_state_parameters(&brw->intel.ctx, vp->program.Base.Parameters);
 
-   /* BRW_NEW_VERTEX_PROGRAM */
-   if (!vp->use_const_buffer) {
+   /* CACHE_NEW_VS_PROG */
+   if (!brw->vs.prog_data->nr_pull_params) {
       if (brw->vs.const_bo) {
         drm_intel_bo_unreference(brw->vs.const_bo);
         brw->vs.const_bo = NULL;
@@ -74,13 +74,14 @@ prepare_vs_constants(struct brw_context *brw)
    /* _NEW_PROGRAM_CONSTANTS */
    drm_intel_bo_unreference(brw->vs.const_bo);
    brw->vs.const_bo = drm_intel_bo_alloc(intel->bufmgr, "vp_const_buffer",
-                                        size, 64);
+                                        brw->vs.prog_data->nr_pull_params * 4,
+                                        64);
 
    drm_intel_gem_bo_map_gtt(brw->vs.const_bo);
-   for (i = 0; i < params->NumParameters; i++) {
-      memcpy(brw->vs.const_bo->virtual + i * 4 * sizeof(float),
-            params->ParameterValues[i],
-            4 * sizeof(float));
+   for (i = 0; i < brw->vs.prog_data->nr_pull_params; i++) {
+      memcpy(brw->vs.const_bo->virtual + i * 4,
+            brw->vs.prog_data->pull_param[i],
+            4);
    }
 
    if (0) {
@@ -99,7 +100,7 @@ const struct brw_tracked_state brw_vs_constants = {
    .dirty = {
       .mesa = (_NEW_PROGRAM_CONSTANTS),
       .brw = (BRW_NEW_VERTEX_PROGRAM),
-      .cache = 0
+      .cache = CACHE_NEW_VS_PROG,
    },
    .prepare = prepare_vs_constants,
 };