glsl: store number of explicit uniform loactions in gl_shader_program

This allows us to cleanup the functions that pass this count around,
but more importantly we will be able to call the uniform linking
functions from that backends linker without having to pass this
information to the backend directly via Driver.LinkShader().

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Timothy Arceri
2016-12-04 22:47:17 +11:00
parent c054bbf0d4
commit 62f718bfcb
4 changed files with 25 additions and 29 deletions

View File

@@ -1042,12 +1042,10 @@ find_empty_block(struct gl_shader_program *prog,
static void static void
link_setup_uniform_remap_tables(struct gl_context *ctx, link_setup_uniform_remap_tables(struct gl_context *ctx,
struct gl_shader_program *prog, struct gl_shader_program *prog)
unsigned num_explicit_uniform_locs)
{ {
unsigned total_entries = num_explicit_uniform_locs; unsigned total_entries = prog->NumExplicitUniformLocations;
unsigned empty_locs = unsigned empty_locs = prog->NumUniformRemapTable - total_entries;
prog->NumUniformRemapTable - num_explicit_uniform_locs;
/* Reserve all the explicit locations of the active uniforms. */ /* Reserve all the explicit locations of the active uniforms. */
for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) { for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
@@ -1206,8 +1204,7 @@ link_setup_uniform_remap_tables(struct gl_context *ctx,
static void static void
link_assign_uniform_storage(struct gl_context *ctx, link_assign_uniform_storage(struct gl_context *ctx,
struct gl_shader_program *prog, struct gl_shader_program *prog,
const unsigned num_data_slots, const unsigned num_data_slots)
unsigned num_explicit_uniform_locs)
{ {
/* On the outside chance that there were no uniforms, bail out. /* On the outside chance that there were no uniforms, bail out.
*/ */
@@ -1266,15 +1263,14 @@ link_assign_uniform_storage(struct gl_context *ctx,
assert(parcel.values == data_end); assert(parcel.values == data_end);
#endif #endif
link_setup_uniform_remap_tables(ctx, prog, num_explicit_uniform_locs); link_setup_uniform_remap_tables(ctx, prog);
link_set_uniform_initializers(prog, boolean_true); link_set_uniform_initializers(prog, boolean_true);
} }
void void
link_assign_uniform_locations(struct gl_shader_program *prog, link_assign_uniform_locations(struct gl_shader_program *prog,
struct gl_context *ctx, struct gl_context *ctx)
unsigned int num_explicit_uniform_locs)
{ {
ralloc_free(prog->data->UniformStorage); ralloc_free(prog->data->UniformStorage);
prog->data->UniformStorage = NULL; prog->data->UniformStorage = NULL;
@@ -1335,6 +1331,5 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
hiddenUniforms->iterate(assign_hidden_uniform_slot_id, &uniform_size); hiddenUniforms->iterate(assign_hidden_uniform_slot_id, &uniform_size);
delete hiddenUniforms; delete hiddenUniforms;
link_assign_uniform_storage(ctx, prog, uniform_size.num_values, link_assign_uniform_storage(ctx, prog, uniform_size.num_values);
num_explicit_uniform_locs);
} }

View File

@@ -3378,12 +3378,14 @@ reserve_subroutine_explicit_locations(struct gl_shader_program *prog,
* any optimizations happen to handle also inactive uniforms and * any optimizations happen to handle also inactive uniforms and
* inactive array elements that may get trimmed away. * inactive array elements that may get trimmed away.
*/ */
static unsigned static void
check_explicit_uniform_locations(struct gl_context *ctx, check_explicit_uniform_locations(struct gl_context *ctx,
struct gl_shader_program *prog) struct gl_shader_program *prog)
{ {
prog->NumExplicitUniformLocations = 0;
if (!ctx->Extensions.ARB_explicit_uniform_location) if (!ctx->Extensions.ARB_explicit_uniform_location)
return 0; return;
/* This map is used to detect if overlapping explicit locations /* This map is used to detect if overlapping explicit locations
* occur with the same uniform (from different stage) or a different one. * occur with the same uniform (from different stage) or a different one.
@@ -3392,7 +3394,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
if (!uniform_map) { if (!uniform_map) {
linker_error(prog, "Out of memory during linking.\n"); linker_error(prog, "Out of memory during linking.\n");
return 0; return;
} }
unsigned entries_total = 0; unsigned entries_total = 0;
@@ -3420,7 +3422,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
} }
if (!ret) { if (!ret) {
delete uniform_map; delete uniform_map;
return 0; return;
} }
} }
} }
@@ -3445,7 +3447,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
} }
delete uniform_map; delete uniform_map;
return entries_total; prog->NumExplicitUniformLocations = entries_total;
} }
static bool static bool
@@ -4533,11 +4535,10 @@ disable_varying_optimizations_for_sso(struct gl_shader_program *prog)
static void static void
link_and_validate_uniforms(struct gl_context *ctx, link_and_validate_uniforms(struct gl_context *ctx,
struct gl_shader_program *prog, struct gl_shader_program *prog)
unsigned num_explicit_uniform_locs)
{ {
update_array_sizes(prog); update_array_sizes(prog);
link_assign_uniform_locations(prog, ctx, num_explicit_uniform_locs); link_assign_uniform_locations(prog, ctx);
link_assign_atomic_counter_resources(ctx, prog); link_assign_atomic_counter_resources(ctx, prog);
link_calculate_subroutine_compat(prog); link_calculate_subroutine_compat(prog);
@@ -4549,7 +4550,6 @@ link_and_validate_uniforms(struct gl_context *ctx,
static bool static bool
link_varyings_and_uniforms(unsigned first, unsigned last, link_varyings_and_uniforms(unsigned first, unsigned last,
unsigned num_explicit_uniform_locs,
struct gl_context *ctx, struct gl_context *ctx,
struct gl_shader_program *prog, void *mem_ctx) struct gl_shader_program *prog, void *mem_ctx)
{ {
@@ -4595,7 +4595,7 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
if (!link_varyings(prog, first, last, ctx, mem_ctx)) if (!link_varyings(prog, first, last, ctx, mem_ctx))
return false; return false;
link_and_validate_uniforms(ctx, prog, num_explicit_uniform_locs); link_and_validate_uniforms(ctx, prog);
if (!prog->data->LinkStatus) if (!prog->data->LinkStatus)
return false; return false;
@@ -4647,8 +4647,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
return; return;
} }
unsigned int num_explicit_uniform_locs = 0;
void *mem_ctx = ralloc_context(NULL); // temporary linker context void *mem_ctx = ralloc_context(NULL); // temporary linker context
prog->ARB_fragment_coord_conventions_enable = false; prog->ARB_fragment_coord_conventions_enable = false;
@@ -4828,7 +4826,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
last = i; last = i;
} }
num_explicit_uniform_locs = check_explicit_uniform_locations(ctx, prog); check_explicit_uniform_locations(ctx, prog);
link_assign_subroutine_types(prog); link_assign_subroutine_types(prog);
if (!prog->data->LinkStatus) if (!prog->data->LinkStatus)
@@ -4944,8 +4942,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
store_fragdepth_layout(prog); store_fragdepth_layout(prog);
if(!link_varyings_and_uniforms(first, last, num_explicit_uniform_locs, ctx, if(!link_varyings_and_uniforms(first, last, ctx, prog, mem_ctx))
prog, mem_ctx))
goto done; goto done;
/* OpenGL ES < 3.1 requires that a vertex shader and a fragment shader both /* OpenGL ES < 3.1 requires that a vertex shader and a fragment shader both

View File

@@ -35,8 +35,7 @@ link_invalidate_variable_locations(exec_list *ir);
extern void extern void
link_assign_uniform_locations(struct gl_shader_program *prog, link_assign_uniform_locations(struct gl_shader_program *prog,
struct gl_context *ctx, struct gl_context *ctx);
unsigned int num_explicit_uniform_locs);
extern void extern void
link_set_uniform_initializers(struct gl_shader_program *prog, link_set_uniform_initializers(struct gl_shader_program *prog,

View File

@@ -2834,6 +2834,11 @@ struct gl_shader_program
unsigned LastClipDistanceArraySize; unsigned LastClipDistanceArraySize;
unsigned LastCullDistanceArraySize; unsigned LastCullDistanceArraySize;
/**
* Total number of explicit uniform location including inactive uniforms.
*/
unsigned NumExplicitUniformLocations;
/** /**
* Map of active uniform names to locations * Map of active uniform names to locations
* *