This should be faster than looping over every stage and null checking, but will also make the code a bit cleaner when we switch to getting more fields from gl_program rather than from gl_linked_shader as we can just copy the pointer and not need to worry about null checking then copying. --- src/compiler/glsl/link_uniforms.cpp | 12 ++++++------ src/compiler/glsl/linker.cpp | 34 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index b4c4c43..a660fad 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -1151,10 +1151,10 @@ link_setup_uniform_remap_tables(struct gl_context *ctx, const unsigned entries = MAX2(1, prog->data->UniformStorage[i].array_elements); - for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) { + unsigned mask = prog->data->linked_stages; + while (mask) { + const int j = u_bit_scan(&mask); struct gl_linked_shader *sh = prog->_LinkedShaders[j]; - if (!sh) - continue; if (!prog->data->UniformStorage[i].opaque[j].active) continue; @@ -1183,10 +1183,10 @@ link_setup_uniform_remap_tables(struct gl_context *ctx, const unsigned entries = MAX2(1, prog->data->UniformStorage[i].array_elements); - for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) { + unsigned mask = prog->data->linked_stages; + while (mask) { + const int j = u_bit_scan(&mask); struct gl_linked_shader *sh = prog->_LinkedShaders[j]; - if (!sh) - continue; if (!prog->data->UniformStorage[i].opaque[j].active) continue; diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index be4e18c..e4431e1 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -3127,11 +3127,10 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog) static void link_calculate_subroutine_compat(struct gl_shader_program *prog) { - for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + unsigned mask = prog->data->linked_stages; + while (mask) { + const int i = u_bit_scan(&mask); struct gl_linked_shader *sh = prog->_LinkedShaders[i]; - int count; - if (!sh) - continue; for (unsigned j = 0; j < sh->NumSubroutineUniformRemapTable; j++) { if (sh->SubroutineUniformRemapTable[j] == INACTIVE_UNIFORM_EXPLICIT_LOCATION) @@ -3143,7 +3142,7 @@ link_calculate_subroutine_compat(struct gl_shader_program *prog) continue; sh->NumSubroutineUniforms++; - count = 0; + int count = 0; if (sh->NumSubroutineFunctions == 0) { linker_error(prog, "subroutine uniform %s defined but no valid functions found\n", uni->type->name); continue; @@ -3165,7 +3164,9 @@ link_calculate_subroutine_compat(struct gl_shader_program *prog) static void check_subroutine_resources(struct gl_shader_program *prog) { - for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + unsigned mask = prog->data->linked_stages; + while (mask) { + const int i = u_bit_scan(&mask); struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (sh) { @@ -3367,7 +3368,9 @@ check_explicit_uniform_locations(struct gl_context *ctx, } unsigned entries_total = 0; - for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + unsigned mask = prog->data->linked_stages; + while (mask) { + const int i = u_bit_scan(&mask); struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (!sh) @@ -4301,14 +4304,12 @@ build_program_resource_list(struct gl_context *ctx, } } - for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + unsigned mask = shProg->data->linked_stages; + while (mask) { + const int i = u_bit_scan(&mask); struct gl_linked_shader *sh = shProg->_LinkedShaders[i]; - GLuint type; - if (!sh) - continue; - - type = _mesa_shader_stage_to_subroutine((gl_shader_stage)i); + GLuint type = _mesa_shader_stage_to_subroutine((gl_shader_stage)i); for (unsigned j = 0; j < sh->NumSubroutineFunctions; j++) { if (!add_program_resource(shProg, resource_set, type, &sh->SubroutineFunctions[j], 0)) @@ -4356,12 +4357,11 @@ validate_sampler_array_indexing(struct gl_context *ctx, static void link_assign_subroutine_types(struct gl_shader_program *prog) { - for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + unsigned mask = prog->data->linked_stages; + while (mask) { + const int i = u_bit_scan(&mask); gl_linked_shader *sh = prog->_LinkedShaders[i]; - if (sh == NULL) - continue; - sh->MaxSubroutineFunctionIndex = 0; foreach_in_list(ir_instruction, node, sh->ir) { ir_function *fn = node->as_function(); -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev