From 7878497c94fcd6d60a52df1118601809e3246a43 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 29 Mar 2021 13:17:10 -0700 Subject: [PATCH] mesa: Clean up _mesa_layout_parameters after previous commit MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit After the previous change, PASS 1 can be trivially pulled out of the loop. With PASS 1 removed, the loop can be unrolled, and a lot of code can be deleted (from the unrolls). This saves a couple lines of code, and it makes the function a little easier to follow. Reviewed-by: Marek Olšák Part-of: --- src/mesa/program/prog_parameter_layout.c | 221 +++++++++++++++---------------- 1 file changed, 108 insertions(+), 113 deletions(-) diff --git a/src/mesa/program/prog_parameter_layout.c b/src/mesa/program/prog_parameter_layout.c index fadee60..d94b120 100644 --- a/src/mesa/program/prog_parameter_layout.c +++ b/src/mesa/program/prog_parameter_layout.c @@ -151,146 +151,141 @@ _mesa_layout_parameters(struct asm_parser_state *state) layout = _mesa_new_parameter_list_sized(state->prog->Parameters->NumParameters); - for (unsigned f = 0; f < 2; f++) { - unsigned file = !f ? PROGRAM_CONSTANT : PROGRAM_STATE_VAR; - - /* PASS 1: Move any parameters that are accessed indirectly from the - * original parameter list to the new parameter list. - */ - for (inst = state->inst_head; inst != NULL; inst = inst->next) { - for (unsigned i = 0; i < 3; i++) { - if (inst->SrcReg[i].Base.RelAddr) { - /* Only attempt to add the to the new parameter list once. - */ - if (!inst->SrcReg[i].Symbol->pass1_done) { - const int new_begin = - copy_indirect_accessed_array(state->prog->Parameters, layout, - inst->SrcReg[i].Symbol->param_binding_begin, - inst->SrcReg[i].Symbol->param_binding_length); - - if (new_begin < 0) { - _mesa_free_parameter_list(layout); - return GL_FALSE; - } - - inst->SrcReg[i].Symbol->param_binding_begin = new_begin; - inst->SrcReg[i].Symbol->pass1_done = 1; + /* PASS 1: Move any parameters that are accessed indirectly from the + * original parameter list to the new parameter list. + */ + for (inst = state->inst_head; inst != NULL; inst = inst->next) { + for (unsigned i = 0; i < 3; i++) { + if (inst->SrcReg[i].Base.RelAddr) { + /* Only attempt to add the to the new parameter list once. + */ + if (!inst->SrcReg[i].Symbol->pass1_done) { + const int new_begin = + copy_indirect_accessed_array(state->prog->Parameters, layout, + inst->SrcReg[i].Symbol->param_binding_begin, + inst->SrcReg[i].Symbol->param_binding_length); + + if (new_begin < 0) { + _mesa_free_parameter_list(layout); + return GL_FALSE; } - /* Previously the Index was just the offset from the parameter - * array. Now that the base of the parameter array is known, the - * index can be updated to its actual value. - */ - inst->Base.SrcReg[i] = inst->SrcReg[i].Base; - inst->Base.SrcReg[i].Index += - inst->SrcReg[i].Symbol->param_binding_begin; + inst->SrcReg[i].Symbol->param_binding_begin = new_begin; + inst->SrcReg[i].Symbol->pass1_done = 1; } + + /* Previously the Index was just the offset from the parameter + * array. Now that the base of the parameter array is known, the + * index can be updated to its actual value. + */ + inst->Base.SrcReg[i] = inst->SrcReg[i].Base; + inst->Base.SrcReg[i].Index += + inst->SrcReg[i].Symbol->param_binding_begin; } } + } - /* PASS 2: Add sorted state variables. NOTE: This pass does **not** - * modify the instruction with the updated index. The sorting step - * might invalidate the index that was calculated by - * _mesa_add_state_reference. Instead, it relies on PASS 3 to do this. - */ - if (file == PROGRAM_STATE_VAR) { - unsigned first_state_var = layout->NumParameters; - - /* Add state variables with constant indexing. */ - for (inst = state->inst_head; inst != NULL; inst = inst->next) { - for (unsigned i = 0; i < 3; i++) { - const struct gl_program_parameter *p; - const int idx = inst->SrcReg[i].Base.Index; + /* PASS 2: Move any constants that are not accessed indirectly from the + * original parameter list to the new parameter list. + */ + for (inst = state->inst_head; inst != NULL; inst = inst->next) { + for (unsigned i = 0; i < 3; i++) { + const int idx = inst->SrcReg[i].Base.Index; + const struct gl_program_parameter *const p = + &state->prog->Parameters->Parameters[idx]; + unsigned swizzle = SWIZZLE_NOOP; - p = &state->prog->Parameters->Parameters[idx]; + if (inst->SrcReg[i].Base.RelAddr || + inst->SrcReg[i].Base.File <= PROGRAM_OUTPUT || + inst->SrcReg[i].Base.File >= PROGRAM_WRITE_ONLY || + p->Type != PROGRAM_CONSTANT) + continue; - if (inst->SrcReg[i].Base.RelAddr || - inst->SrcReg[i].Base.File <= PROGRAM_OUTPUT || - inst->SrcReg[i].Base.File >= PROGRAM_WRITE_ONLY || - p->Type != file) - continue; + inst->Base.SrcReg[i] = inst->SrcReg[i].Base; - _mesa_add_state_reference(layout, p->StateIndexes); - } - } + unsigned pvo = state->prog->Parameters->Parameters[idx].ValueOffset; + const gl_constant_value *const v = + state->prog->Parameters->ParameterValues + pvo; - /* Sort if we have added at least 2 state vars. */ - if (first_state_var + 2 <= layout->NumParameters) { - /* All state vars should be vec4s. */ - for (unsigned i = first_state_var; i < layout->NumParameters; i++) { - assert(layout->Parameters[i].Size == 4); - assert(layout->Parameters[i].ValueOffset == i * 4); - } + inst->Base.SrcReg[i].Index = + _mesa_add_unnamed_constant(layout, v, p->Size, &swizzle); - qsort(layout->Parameters + first_state_var, - layout->NumParameters - first_state_var, - sizeof(layout->Parameters[0]), compare_state_var); + inst->Base.SrcReg[i].Swizzle = + _mesa_combine_swizzles(swizzle, inst->Base.SrcReg[i].Swizzle); - /* Fix offsets. */ - for (unsigned i = first_state_var; i < layout->NumParameters; i++) { - layout->Parameters[i].ValueOffset = i * 4; - } - } + inst->SrcReg[i].Base.File = p->Type; + inst->Base.SrcReg[i].File = p->Type; } + } - /* PASS 3: Move any parameters that are not accessed indirectly from the - * original parameter list to the new parameter list. - */ - for (inst = state->inst_head; inst != NULL; inst = inst->next) { - for (unsigned i = 0; i < 3; i++) { - const struct gl_program_parameter *p; - const int idx = inst->SrcReg[i].Base.Index; - unsigned swizzle = SWIZZLE_NOOP; - - /* All relative addressed operands were processed on the first - * pass. Just skip them here. - */ - if (inst->SrcReg[i].Base.RelAddr) { - continue; - } + /* PASS 3: Add sorted state variables. NOTE: This pass does **not** modify + * the instruction with the updated index. The sorting step might + * invalidate the index that was calculated by _mesa_add_state_reference. + * Instead, it relies on PASS 4 to do this. + */ + unsigned first_state_var = layout->NumParameters; - p = &state->prog->Parameters->Parameters[idx]; + for (inst = state->inst_head; inst != NULL; inst = inst->next) { + for (unsigned i = 0; i < 3; i++) { + const struct gl_program_parameter *p; + const int idx = inst->SrcReg[i].Base.Index; - if ((inst->SrcReg[i].Base.File <= PROGRAM_OUTPUT) - || (inst->SrcReg[i].Base.File >= PROGRAM_WRITE_ONLY)) { - continue; - } + p = &state->prog->Parameters->Parameters[idx]; - if (p->Type != file) { - continue; - } + if (inst->SrcReg[i].Base.RelAddr || + inst->SrcReg[i].Base.File <= PROGRAM_OUTPUT || + inst->SrcReg[i].Base.File >= PROGRAM_WRITE_ONLY || + p->Type != PROGRAM_STATE_VAR) + continue; - inst->Base.SrcReg[i] = inst->SrcReg[i].Base; + _mesa_add_state_reference(layout, p->StateIndexes); + } + } - switch (p->Type) { - case PROGRAM_CONSTANT: { - unsigned pvo = state->prog->Parameters->Parameters[idx].ValueOffset; - const gl_constant_value *const v = - state->prog->Parameters->ParameterValues + pvo; + /* Sort if we have added at least 2 state vars. */ + if (first_state_var + 2 <= layout->NumParameters) { + /* All state vars should be vec4s. */ + for (unsigned i = first_state_var; i < layout->NumParameters; i++) { + assert(layout->Parameters[i].Size == 4); + assert(layout->Parameters[i].ValueOffset == i * 4); + } - inst->Base.SrcReg[i].Index = - _mesa_add_unnamed_constant(layout, v, p->Size, & swizzle); + qsort(layout->Parameters + first_state_var, + layout->NumParameters - first_state_var, + sizeof(layout->Parameters[0]), compare_state_var); - inst->Base.SrcReg[i].Swizzle = - _mesa_combine_swizzles(swizzle, inst->Base.SrcReg[i].Swizzle); - break; - } + /* Fix offsets. */ + for (unsigned i = first_state_var; i < layout->NumParameters; i++) { + layout->Parameters[i].ValueOffset = i * 4; + } + } - case PROGRAM_STATE_VAR: - inst->Base.SrcReg[i].Index = - _mesa_add_state_reference(layout, p->StateIndexes); - break; + /* PASS 4: Fix up the index and file information for instructions whose + * parameters were added to the parameter list in PASS 3. + */ + for (inst = state->inst_head; inst != NULL; inst = inst->next) { + for (unsigned i = 0; i < 3; i++) { + const int idx = inst->SrcReg[i].Base.Index; + const struct gl_program_parameter *const p = + &state->prog->Parameters->Parameters[idx]; - default: - break; - } + if (inst->SrcReg[i].Base.RelAddr || + inst->SrcReg[i].Base.File <= PROGRAM_OUTPUT || + inst->SrcReg[i].Base.File >= PROGRAM_WRITE_ONLY || + p->Type != PROGRAM_STATE_VAR) + continue; - inst->SrcReg[i].Base.File = p->Type; - inst->Base.SrcReg[i].File = p->Type; - } + inst->Base.SrcReg[i] = inst->SrcReg[i].Base; + + inst->Base.SrcReg[i].Index = + _mesa_add_state_reference(layout, p->StateIndexes); + + inst->SrcReg[i].Base.File = p->Type; + inst->Base.SrcReg[i].File = p->Type; } } + assert(layout->NumParameters <= state->prog->Parameters->NumParameters); _mesa_recompute_parameter_bounds(layout); layout->StateFlags = state->prog->Parameters->StateFlags; -- 2.7.4