diff options
author | Timothy Arceri <[email protected]> | 2016-11-02 14:28:12 +1100 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2016-11-30 14:13:52 +1100 |
commit | 2ea021a1ebb768b13c533f6bea56cdfb4a9cc3b3 (patch) | |
tree | 7a747ac81ed0493583f97bce84a5398e41b6231e /src/compiler/glsl | |
parent | 6d3458cbfbb4efb5a2ee33ad17e11f45163b6180 (diff) |
glsl: use linked_shaders bitmask to iterate stages for subroutine fields
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.
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/compiler/glsl')
-rw-r--r-- | src/compiler/glsl/link_uniforms.cpp | 12 | ||||
-rw-r--r-- | src/compiler/glsl/linker.cpp | 45 |
2 files changed, 26 insertions, 31 deletions
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index 66bcbda1336..dd6336e12da 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -1140,10 +1140,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; @@ -1172,10 +1172,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 d26517ace29..764938bdb6e 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -3144,11 +3144,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) @@ -3159,7 +3158,7 @@ link_calculate_subroutine_compat(struct gl_shader_program *prog) if (!uni) continue; - 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; @@ -3181,14 +3180,14 @@ 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) { - if (sh->NumSubroutineUniformRemapTable > MAX_SUBROUTINE_UNIFORM_LOCATIONS) - linker_error(prog, "Too many %s shader subroutine uniforms\n", - _mesa_shader_stage_to_string(i)); - } + if (sh->NumSubroutineUniformRemapTable > MAX_SUBROUTINE_UNIFORM_LOCATIONS) + linker_error(prog, "Too many %s shader subroutine uniforms\n", + _mesa_shader_stage_to_string(i)); } } /** @@ -3383,12 +3382,11 @@ 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) - continue; - foreach_in_list(ir_instruction, node, sh->ir) { ir_variable *var = node->as_variable(); if (!var || var->data.mode != ir_var_uniform) @@ -4317,14 +4315,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)) @@ -4372,12 +4368,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(); |