i965: Make the param pointer arrays for the WM dynamically sized.
Saves 26.5MB of wasted memory allocation in the l4d2 demo. v2: Rebase on compare func change, fix comments. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> (v1) Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
parent
99596cba78
commit
f144b78dfb
|
@ -322,8 +322,8 @@ struct brw_wm_prog_data {
|
|||
* These must be the last fields of the struct (see
|
||||
* brw_wm_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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -631,6 +631,7 @@ struct brw_cache_item {
|
|||
|
||||
typedef bool (*cache_aux_compare_func)(const void *a, const void *b,
|
||||
int aux_size, const void *key);
|
||||
typedef void (*cache_aux_free_func)(const void *aux);
|
||||
|
||||
struct brw_cache {
|
||||
struct brw_context *brw;
|
||||
|
@ -648,6 +649,8 @@ struct brw_cache {
|
|||
* outside of the prog_data). If NULL, a plain memcmp is done.
|
||||
*/
|
||||
cache_aux_compare_func aux_compare[BRW_MAX_CACHE];
|
||||
/** Optional functions for freeing other pointers attached to a prog_data. */
|
||||
cache_aux_free_func aux_free[BRW_MAX_CACHE];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -528,8 +528,6 @@ fs_visitor::setup_uniform_values(int loc, const glsl_type *type)
|
|||
for (unsigned int i = 0; i < type->vector_elements; i++) {
|
||||
unsigned int param = c->prog_data.nr_params++;
|
||||
|
||||
assert(param < ARRAY_SIZE(c->prog_data.param));
|
||||
|
||||
this->param_index[param] = loc;
|
||||
this->param_offset[param] = i;
|
||||
}
|
||||
|
|
|
@ -343,6 +343,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_WM_PROG] = brw_wm_prog_data_free;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -357,6 +358,10 @@ brw_clear_cache(struct brw_context *brw, struct brw_cache *cache)
|
|||
for (i = 0; i < cache->size; i++) {
|
||||
for (c = cache->items[i]; c; c = next) {
|
||||
next = c->next;
|
||||
if (cache->aux_free[c->cache_id]) {
|
||||
const void *item_aux = c->key + c->key_size;
|
||||
cache->aux_free[c->cache_id](item_aux);
|
||||
}
|
||||
free((void *)c->key);
|
||||
free(c);
|
||||
}
|
||||
|
|
|
@ -273,6 +273,15 @@ brw_wm_prog_data_compare(const void *in_a, const void *in_b,
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
brw_wm_prog_data_free(const void *in_prog_data)
|
||||
{
|
||||
const struct brw_wm_prog_data *prog_data = in_prog_data;
|
||||
|
||||
ralloc_free((void *)prog_data->param);
|
||||
ralloc_free((void *)prog_data->pull_param);
|
||||
}
|
||||
|
||||
/**
|
||||
* All Mesa program -> GPU code generation goes through this function.
|
||||
* Depending on the instructions used (i.e. flow control instructions)
|
||||
|
@ -286,8 +295,12 @@ bool do_wm_prog(struct brw_context *brw,
|
|||
struct intel_context *intel = &brw->intel;
|
||||
struct brw_wm_compile *c;
|
||||
const GLuint *program;
|
||||
struct gl_shader *fs = NULL;
|
||||
GLuint program_size;
|
||||
|
||||
if (prog)
|
||||
fs = prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
|
||||
|
||||
c = brw->wm.compile_data;
|
||||
if (c == NULL) {
|
||||
brw->wm.compile_data = rzalloc(NULL, struct brw_wm_compile);
|
||||
|
@ -310,6 +323,28 @@ bool do_wm_prog(struct brw_context *brw,
|
|||
c->vreg = vreg;
|
||||
c->refs = refs;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
if (fs) {
|
||||
int param_count = fs->num_uniform_components;
|
||||
/* The backend also sometimes adds params for texture size. */
|
||||
param_count += 2 * BRW_MAX_TEX_UNIT;
|
||||
|
||||
c->prog_data.param = rzalloc_array(c, const float *, param_count);
|
||||
c->prog_data.pull_param = rzalloc_array(c, const float *, param_count);
|
||||
} else {
|
||||
/* brw_wm_pass0.c will also add references to 0.0 and 1.0 which are
|
||||
* uploaded as push parameters.
|
||||
*/
|
||||
int param_count = (fp->program.Base.Parameters->NumParameters + 2) * 4;
|
||||
c->prog_data.param = rzalloc_array(c, const float *, param_count);
|
||||
/* The old backend never does pull constants. */
|
||||
c->prog_data.pull_param = NULL;
|
||||
}
|
||||
|
||||
memcpy(&c->key, key, sizeof(*key));
|
||||
|
||||
c->fp = fp;
|
||||
|
|
|
@ -486,5 +486,6 @@ void brw_wm_debug_recompile(struct brw_context *brw,
|
|||
const struct brw_wm_prog_key *key);
|
||||
bool brw_wm_prog_data_compare(const void *a, const void *b,
|
||||
int aux_size, const void *key);
|
||||
void brw_wm_prog_data_free(const void *in_prog_data);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue