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 <ian.d.romanick@intel.com>
This commit is contained in:
Timothy Arceri 2016-11-02 14:28:12 +11:00
parent 6d3458cbfb
commit 2ea021a1eb
2 changed files with 26 additions and 31 deletions

View File

@ -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;

View File

@ -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();