OSDN Git Service

i965: Make the param pointer arrays for the VS dynamically sized.
authorEric Anholt <eric@anholt.net>
Mon, 27 Aug 2012 16:24:56 +0000 (09:24 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 7 Sep 2012 15:29:49 +0000 (08:29 -0700)
Saves 96MB of wasted memory in the l4d2 demo.

v2: Rebase on compare func change, change brace style.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_state_cache.c
src/mesa/drivers/dri/i965/brw_vs.c
src/mesa/drivers/dri/i965/brw_vs.h

index 0fe640c..3dac633 100644 (file)
@@ -459,8 +459,8 @@ struct brw_vs_prog_data {
    int num_surfaces;
 
    /* These pointers must appear last.  See brw_vs_prog_data_compare(). */
-   const float *param[MAX_UNIFORMS * 4]; /* should be: BRW_MAX_CURBE */
-   const float *pull_param[MAX_UNIFORMS * 4];
+   const float **param;
+   const float **pull_param;
 };
 
 
index b8a2fc3..d9bbcd9 100644 (file)
@@ -49,6 +49,7 @@
 #include "brw_state.h"
 #include "brw_vs.h"
 #include "brw_wm.h"
+#include "brw_vs.h"
 
 #define FILE_DEBUG_FLAG DEBUG_STATE
 
@@ -343,6 +344,7 @@ brw_init_caches(struct brw_context *brw)
 
    cache->aux_compare[BRW_VS_PROG] = brw_vs_prog_data_compare;
    cache->aux_compare[BRW_WM_PROG] = brw_wm_prog_data_compare;
+   cache->aux_free[BRW_VS_PROG] = brw_vs_prog_data_free;
    cache->aux_free[BRW_WM_PROG] = brw_wm_prog_data_free;
 }
 
index 1b11174..4507f6c 100644 (file)
@@ -220,6 +220,10 @@ do_vs_prog(struct brw_context *brw,
    void *mem_ctx;
    int aux_size;
    int i;
+   struct gl_shader *vs = NULL;
+
+   if (prog)
+      vs = prog->_LinkedShaders[MESA_SHADER_VERTEX];
 
    memset(&c, 0, sizeof(c));
    memcpy(&c.key, key, sizeof(*key));
@@ -229,6 +233,26 @@ do_vs_prog(struct brw_context *brw,
    brw_init_compile(brw, &c.func, mem_ctx);
    c.vp = vp;
 
+   /* Allocate the references to the uniforms that will end up in the
+    * prog_data associated with the compiled program, and which will be freed
+    * by the state cache.
+    */
+   int param_count;
+   if (vs) {
+      /* We add padding around uniform values below vec4 size, with the worst
+       * case being a float value that gets blown up to a vec4, so be
+       * conservative here.
+       */
+      param_count = vs->num_uniform_components * 4;
+
+      /* We also upload clip plane data as uniforms */
+      param_count += MAX_CLIP_PLANES * 4;
+   } else {
+      param_count = vp->program.Base.Parameters->NumParameters * 4;
+   }
+   c.prog_data.param = rzalloc_array(NULL, const float *, param_count);
+   c.prog_data.pull_param = rzalloc_array(NULL, const float *, param_count);
+
    c.prog_data.outputs_written = vp->program.Base.OutputsWritten;
    c.prog_data.inputs_read = vp->program.Base.InputsRead;
 
@@ -512,3 +536,12 @@ brw_vs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
 
    return success;
 }
+
+void
+brw_vs_prog_data_free(const void *in_prog_data)
+{
+   const struct brw_vs_prog_data *prog_data = in_prog_data;
+
+   ralloc_free((void *)prog_data->param);
+   ralloc_free((void *)prog_data->pull_param);
+}
index e69a713..307e8e7 100644 (file)
@@ -125,5 +125,6 @@ void brw_vs_debug_recompile(struct brw_context *brw,
                             const struct brw_vs_prog_key *key);
 bool brw_vs_prog_data_compare(const void *a, const void *b,
                               int aux_size, const void *key);
+void brw_vs_prog_data_free(const void *in_prog_data);
 
 #endif