mesa: Clean up _mesa_layout_parameters after previous commit

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 <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9867>
This commit is contained in:
Ian Romanick 2021-03-29 13:17:10 -07:00 committed by Marge Bot
parent 9413c6aec3
commit 7878497c94

View file

@ -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);
/* 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;
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;
}
}
}
/* 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;
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 != file)
continue;
_mesa_add_state_reference(layout, p->StateIndexes);
}
}
/* 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->SrcReg[i].Symbol->param_binding_begin = new_begin;
inst->SrcReg[i].Symbol->pass1_done = 1;
}
qsort(layout->Parameters + first_state_var,
layout->NumParameters - first_state_var,
sizeof(layout->Parameters[0]), compare_state_var);
/* Fix offsets. */
for (unsigned i = first_state_var; i < layout->NumParameters; i++) {
layout->Parameters[i].ValueOffset = i * 4;
}
}
}
/* 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.
/* 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.
*/
if (inst->SrcReg[i].Base.RelAddr) {
continue;
}
p = &state->prog->Parameters->Parameters[idx];
if ((inst->SrcReg[i].Base.File <= PROGRAM_OUTPUT)
|| (inst->SrcReg[i].Base.File >= PROGRAM_WRITE_ONLY)) {
continue;
}
if (p->Type != file) {
continue;
}
inst->Base.SrcReg[i] = inst->SrcReg[i].Base;
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;
inst->Base.SrcReg[i].Index =
_mesa_add_unnamed_constant(layout, v, p->Size, & swizzle);
inst->Base.SrcReg[i].Swizzle =
_mesa_combine_swizzles(swizzle, inst->Base.SrcReg[i].Swizzle);
break;
}
case PROGRAM_STATE_VAR:
inst->Base.SrcReg[i].Index =
_mesa_add_state_reference(layout, p->StateIndexes);
break;
default:
break;
}
inst->SrcReg[i].Base.File = p->Type;
inst->Base.SrcReg[i].File = p->Type;
inst->Base.SrcReg[i].Index +=
inst->SrcReg[i].Symbol->param_binding_begin;
}
}
}
/* 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;
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;
inst->Base.SrcReg[i] = inst->SrcReg[i].Base;
unsigned pvo = state->prog->Parameters->Parameters[idx].ValueOffset;
const gl_constant_value *const v =
state->prog->Parameters->ParameterValues + pvo;
inst->Base.SrcReg[i].Index =
_mesa_add_unnamed_constant(layout, v, p->Size, &swizzle);
inst->Base.SrcReg[i].Swizzle =
_mesa_combine_swizzles(swizzle, inst->Base.SrcReg[i].Swizzle);
inst->SrcReg[i].Base.File = p->Type;
inst->Base.SrcReg[i].File = p->Type;
}
}
/* 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;
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;
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_STATE_VAR)
continue;
_mesa_add_state_reference(layout, p->StateIndexes);
}
}
/* 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);
}
qsort(layout->Parameters + first_state_var,
layout->NumParameters - first_state_var,
sizeof(layout->Parameters[0]), compare_state_var);
/* Fix offsets. */
for (unsigned i = first_state_var; i < layout->NumParameters; i++) {
layout->Parameters[i].ValueOffset = i * 4;
}
}
/* 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];
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;
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;