From eef710fc53113a5b3d6bbf7d9a20f63d7add7911 Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Wed, 19 Feb 2014 15:27:01 +0100 Subject: [PATCH] i965/fs: Use a separate variable to keep track of the last uniform index seen. Like the VEC4 back-end does. It will make dynamic allocation of the param_size array easier in a future commit. Reviewed-by: Paul Berry --- src/mesa/drivers/dri/i965/brw_fs.cpp | 53 +++++++++----------- src/mesa/drivers/dri/i965/brw_fs.h | 3 ++ src/mesa/drivers/dri/i965/brw_fs_fp.cpp | 2 +- src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 11 ++-- src/mesa/drivers/dri/i965/brw_wm.c | 1 + 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index b7495f4a3fb..0fd9e908f58 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -904,7 +904,7 @@ fs_visitor::setup_uniform_values(ir_variable *ir) * order we'd walk the type, so walk the list of storage and find anything * with our name, or the prefix of a component that starts with our name. */ - unsigned params_before = stage_prog_data->nr_params; + unsigned params_before = uniforms; for (unsigned u = 0; u < shader_prog->NumUserUniformStorage; u++) { struct gl_uniform_storage *storage = &shader_prog->UniformStorage[u]; @@ -920,14 +920,12 @@ fs_visitor::setup_uniform_values(ir_variable *ir) slots *= storage->array_elements; for (unsigned i = 0; i < slots; i++) { - stage_prog_data->param[stage_prog_data->nr_params++] = - &storage->storage[i].f; + stage_prog_data->param[uniforms++] = &storage->storage[i].f; } } /* Make sure we actually initialized the right amount of stuff here. */ - assert(params_before + ir->type->component_slots() == - stage_prog_data->nr_params); + assert(params_before + ir->type->component_slots() == uniforms); (void)params_before; } @@ -960,7 +958,7 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir) break; last_swiz = swiz; - stage_prog_data->param[stage_prog_data->nr_params++] = + stage_prog_data->param[uniforms++] = &fp->Base.Parameters->ParameterValues[index][swiz].f; } } @@ -1396,13 +1394,17 @@ fs_visitor::emit_math(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1) void fs_visitor::assign_curb_setup() { - c->prog_data.curb_read_length = ALIGN(stage_prog_data->nr_params, 8) / 8; if (dispatch_width == 8) { c->prog_data.first_curbe_grf = c->nr_payload_regs; + stage_prog_data->nr_params = uniforms; } else { c->prog_data.first_curbe_grf_16 = c->nr_payload_regs; + /* Make sure we didn't try to sneak in an extra uniform */ + assert(uniforms == 0); } + c->prog_data.curb_read_length = ALIGN(stage_prog_data->nr_params, 8) / 8; + /* Map the offsets in the UNIFORM file to fixed HW regs. */ foreach_list(node, &this->instructions) { fs_inst *inst = (fs_inst *)node; @@ -1725,10 +1727,10 @@ bool fs_visitor::remove_dead_constants() { if (dispatch_width == 8) { - this->params_remap = ralloc_array(mem_ctx, int, stage_prog_data->nr_params); - this->nr_params_remap = stage_prog_data->nr_params; + this->params_remap = ralloc_array(mem_ctx, int, uniforms); + this->nr_params_remap = uniforms; - for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) + for (unsigned int i = 0; i < uniforms; i++) this->params_remap[i] = -1; /* Find which params are still in use. */ @@ -1746,8 +1748,7 @@ fs_visitor::remove_dead_constants() * "Out-of-bounds reads return undefined values, which include * values from other variables of the active program or zero." */ - if (constant_nr < 0 || - constant_nr >= (int)stage_prog_data->nr_params) { + if (constant_nr < 0 || constant_nr >= (int)uniforms) { constant_nr = 0; } @@ -1765,14 +1766,14 @@ fs_visitor::remove_dead_constants() * now we don't care. */ unsigned int new_nr_params = 0; - for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) { + for (unsigned int i = 0; i < uniforms; i++) { if (this->params_remap[i] != -1) { this->params_remap[i] = new_nr_params++; } } /* Update the list of params to be uploaded to match our new numbering. */ - for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) { + for (unsigned int i = 0; i < uniforms; i++) { int remapped = this->params_remap[i]; if (remapped == -1) @@ -1781,7 +1782,7 @@ fs_visitor::remove_dead_constants() stage_prog_data->param[remapped] = stage_prog_data->param[i]; } - stage_prog_data->nr_params = new_nr_params; + uniforms = new_nr_params; } else { /* This should have been generated in the SIMD8 pass already. */ assert(this->params_remap); @@ -1825,9 +1826,9 @@ fs_visitor::remove_dead_constants() void fs_visitor::move_uniform_array_access_to_pull_constants() { - int pull_constant_loc[stage_prog_data->nr_params]; + int pull_constant_loc[uniforms]; - for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) { + for (unsigned int i = 0; i < uniforms; i++) { pull_constant_loc[i] = -1; } @@ -1898,7 +1899,7 @@ fs_visitor::setup_pull_constants() { /* Only allow 16 registers (128 uniform components) as push constants. */ unsigned int max_uniform_components = 16 * 8; - if (stage_prog_data->nr_params <= max_uniform_components) + if (uniforms <= max_uniform_components) return; if (dispatch_width == 16) { @@ -1911,8 +1912,8 @@ fs_visitor::setup_pull_constants() */ unsigned int pull_uniform_base = max_uniform_components; - int pull_constant_loc[stage_prog_data->nr_params]; - for (unsigned int i = 0; i < stage_prog_data->nr_params; i++) { + int pull_constant_loc[uniforms]; + for (unsigned int i = 0; i < uniforms; i++) { if (i < pull_uniform_base) { pull_constant_loc[i] = -1; } else { @@ -1933,7 +1934,7 @@ fs_visitor::setup_pull_constants() } } } - stage_prog_data->nr_params = pull_uniform_base; + uniforms = pull_uniform_base; foreach_list(node, &this->instructions) { fs_inst *inst = (fs_inst *)node; @@ -3307,7 +3308,6 @@ bool fs_visitor::run() { sanity_param_count = fp->Base.Parameters->NumParameters; - uint32_t orig_nr_params = stage_prog_data->nr_params; bool allocated_without_spills; assign_binding_table_offsets(); @@ -3451,16 +3451,11 @@ fs_visitor::run() if (!allocated_without_spills) schedule_instructions(SCHEDULE_POST); - if (dispatch_width == 8) { + if (dispatch_width == 8) c->prog_data.reg_blocks = brw_register_blocks(grf_used); - } else { + else c->prog_data.reg_blocks_16 = brw_register_blocks(grf_used); - /* Make sure we didn't try to sneak in an extra uniform */ - assert(orig_nr_params == stage_prog_data->nr_params); - (void) orig_nr_params; - } - /* If any state parameters were appended, then ParameterValues could have * been realloced, in which case the driver uniform storage set up by * _mesa_associate_uniform_storage() would point to freed memory. Make diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index 5f9cb596539..0362c5d3cd7 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -502,6 +502,9 @@ public: int *regs_live_at_ip; + /** Number of uniform variable components visited. */ + unsigned uniforms; + /* This is the map from UNIFORM hw_reg + reg_offset as generated by * the visitor to the packed uniform number after * remove_dead_constants() that represents the actual uploaded diff --git a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp index 5a677a7df3c..49eaf054406 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp @@ -586,7 +586,7 @@ fs_visitor::setup_fp_regs() for (unsigned p = 0; p < prog->Parameters->NumParameters; p++) { for (unsigned int i = 0; i < 4; i++) { - stage_prog_data->param[stage_prog_data->nr_params++] = + stage_prog_data->param[uniforms++] = &prog->Parameters->ParameterValues[p][i].f; } } diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp index 169eaf1279b..b0fed9eecda 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp @@ -102,7 +102,7 @@ fs_visitor::visit(ir_variable *ir) } } } else if (ir->data.mode == ir_var_uniform) { - int param_index = stage_prog_data->nr_params; + int param_index = uniforms; /* Thanks to the lower_ubo_reference pass, we will see only * ir_binop_ubo_load expressions and not ir_dereference_variable for UBO @@ -1467,14 +1467,14 @@ fs_visitor::rescale_texcoord(ir_texture *ir, fs_reg coordinate, return coordinate; } - scale_x = fs_reg(UNIFORM, stage_prog_data->nr_params); - scale_y = fs_reg(UNIFORM, stage_prog_data->nr_params + 1); + scale_x = fs_reg(UNIFORM, uniforms); + scale_y = fs_reg(UNIFORM, uniforms + 1); GLuint index = _mesa_add_state_reference(params, (gl_state_index *)tokens); - stage_prog_data->param[stage_prog_data->nr_params++] = + stage_prog_data->param[uniforms++] = &prog->Parameters->ParameterValues[index][0].f; - stage_prog_data->param[stage_prog_data->nr_params++] = + stage_prog_data->param[uniforms++] = &prog->Parameters->ParameterValues[index][1].f; } @@ -2984,6 +2984,7 @@ fs_visitor::fs_visitor(struct brw_context *brw, this->live_intervals = NULL; this->regs_live_at_ip = NULL; + this->uniforms = 0; this->params_remap = NULL; this->nr_params_remap = 0; diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index 31c68f4c3f4..0d0d6ec82ff 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -171,6 +171,7 @@ bool do_wm_prog(struct brw_context *brw, c->prog_data.base.param = rzalloc_array(NULL, const float *, param_count); c->prog_data.base.pull_param = rzalloc_array(NULL, const float *, param_count); + c->prog_data.base.nr_params = param_count; memcpy(&c->key, key, sizeof(*key)); -- 2.30.2