diff options
author | Timothy Arceri <[email protected]> | 2016-06-30 14:55:40 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2016-06-30 16:51:25 +1000 |
commit | 1fb8c6df884c2a17cf980c4ea32db4c214903b55 (patch) | |
tree | a21b0de699816ce28de37dd61531a025cc984114 /src/compiler | |
parent | 378f07ccb5bff7857d87a4fe5dff0b5e83f99895 (diff) |
glsl/mesa: split gl_shader in two
There are two distinctly different uses of this struct. The first
is to store GL shader objects. The second is to store information
about a shader stage thats been linked.
The two uses actually share few fields and there is clearly confusion
about their use. For example the linked shaders map one to one with
a program so can simply be destroyed along with the program. However
previously we were calling reference counting on the linked shaders.
We were also creating linked shaders with a name even though it
is always 0 and called the driver version of the _mesa_new_shader()
function unnecessarily for GL shader objects.
Acked-by: Iago Toral Quiroga <[email protected]>
Diffstat (limited to 'src/compiler')
25 files changed, 161 insertions, 121 deletions
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index a22fd5b3e08..0ad3be10760 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -134,7 +134,7 @@ glsl_to_nir(const struct gl_shader_program *shader_prog, gl_shader_stage stage, const nir_shader_compiler_options *options) { - struct gl_shader *sh = shader_prog->_LinkedShaders[stage]; + struct gl_linked_shader *sh = shader_prog->_LinkedShaders[stage]; nir_shader *shader = nir_shader_create(NULL, stage, options); diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h index ba14e34b71e..ba790762a62 100644 --- a/src/compiler/glsl/ir_optimization.h +++ b/src/compiler/glsl/ir_optimization.h @@ -86,7 +86,8 @@ bool do_copy_propagation(exec_list *instructions); bool do_copy_propagation_elements(exec_list *instructions); bool do_constant_propagation(exec_list *instructions); void do_dead_builtin_varyings(struct gl_context *ctx, - gl_shader *producer, gl_shader *consumer, + gl_linked_shader *producer, + gl_linked_shader *consumer, unsigned num_tfeedback_decls, class tfeedback_decl *tfeedback_decls); bool do_dead_code(exec_list *instructions, bool uniform_locations_assigned); @@ -119,26 +120,30 @@ bool lower_variable_index_to_cond_assign(gl_shader_stage stage, bool lower_temp, bool lower_uniform); bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz); bool lower_const_arrays_to_uniforms(exec_list *instructions); -bool lower_clip_cull_distance(struct gl_shader_program *prog, gl_shader *shader); +bool lower_clip_cull_distance(struct gl_shader_program *prog, + gl_linked_shader *shader); void lower_output_reads(unsigned stage, exec_list *instructions); bool lower_packing_builtins(exec_list *instructions, int op_mask); -void lower_shared_reference(struct gl_shader *shader, unsigned *shared_size); -void lower_ubo_reference(struct gl_shader *shader, bool clamp_block_indices); +void lower_shared_reference(struct gl_linked_shader *shader, + unsigned *shared_size); +void lower_ubo_reference(struct gl_linked_shader *shader, + bool clamp_block_indices); void lower_packed_varyings(void *mem_ctx, unsigned locations_used, ir_variable_mode mode, - unsigned gs_input_vertices, gl_shader *shader, + unsigned gs_input_vertices, + gl_linked_shader *shader, bool disable_varying_packing, bool xfb_enabled); bool lower_vector_insert(exec_list *instructions, bool lower_nonconstant_index); -bool lower_vector_derefs(gl_shader *shader); -void lower_named_interface_blocks(void *mem_ctx, gl_shader *shader); +bool lower_vector_derefs(gl_linked_shader *shader); +void lower_named_interface_blocks(void *mem_ctx, gl_linked_shader *shader); bool optimize_redundant_jumps(exec_list *instructions); bool optimize_split_arrays(exec_list *instructions, bool linked); bool lower_offset_arrays(exec_list *instructions); void optimize_dead_builtin_variables(exec_list *instructions, enum ir_variable_mode other); -bool lower_tess_level(gl_shader *shader); +bool lower_tess_level(gl_linked_shader *shader); -bool lower_vertex_id(gl_shader *shader); +bool lower_vertex_id(gl_linked_shader *shader); bool lower_subroutine(exec_list *instructions, struct _mesa_glsl_parse_state *state); void propagate_invariance(exec_list *instructions); diff --git a/src/compiler/glsl/link_atomics.cpp b/src/compiler/glsl/link_atomics.cpp index 277d4737ab7..fa845e9d1eb 100644 --- a/src/compiler/glsl/link_atomics.cpp +++ b/src/compiler/glsl/link_atomics.cpp @@ -150,7 +150,7 @@ namespace { *num_buffers = 0; for (unsigned i = 0; i < MESA_SHADER_STAGES; ++i) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (sh == NULL) continue; diff --git a/src/compiler/glsl/link_functions.cpp b/src/compiler/glsl/link_functions.cpp index de194c32451..079f3b959ef 100644 --- a/src/compiler/glsl/link_functions.cpp +++ b/src/compiler/glsl/link_functions.cpp @@ -37,7 +37,7 @@ namespace { class call_link_visitor : public ir_hierarchical_visitor { public: - call_link_visitor(gl_shader_program *prog, gl_shader *linked, + call_link_visitor(gl_shader_program *prog, gl_linked_shader *linked, gl_shader **shader_list, unsigned num_shaders) { this->prog = prog; @@ -297,7 +297,7 @@ private: * linked shader that are accessed by the function. It is also used to add * global variables from the shader where the function originated. */ - gl_shader *linked; + gl_linked_shader *linked; /** * Table of variables local to the function. @@ -335,7 +335,7 @@ find_matching_signature(const char *name, const exec_list *actual_parameters, bool -link_function_calls(gl_shader_program *prog, gl_shader *main, +link_function_calls(gl_shader_program *prog, gl_linked_shader *main, gl_shader **shader_list, unsigned num_shaders) { call_link_visitor v(prog, main, shader_list, num_shaders); diff --git a/src/compiler/glsl/link_interface_blocks.cpp b/src/compiler/glsl/link_interface_blocks.cpp index 5858eeedc2d..447d9a45c63 100644 --- a/src/compiler/glsl/link_interface_blocks.cpp +++ b/src/compiler/glsl/link_interface_blocks.cpp @@ -343,8 +343,8 @@ validate_intrastage_interface_blocks(struct gl_shader_program *prog, void validate_interstage_inout_blocks(struct gl_shader_program *prog, - const gl_shader *producer, - const gl_shader *consumer) + const gl_linked_shader *producer, + const gl_linked_shader *consumer) { interface_block_definitions definitions; /* VS -> GS, VS -> TCS, VS -> TES, TES -> GS */ @@ -384,15 +384,15 @@ validate_interstage_inout_blocks(struct gl_shader_program *prog, void validate_interstage_uniform_blocks(struct gl_shader_program *prog, - gl_shader **stages, int num_stages) + gl_linked_shader **stages) { interface_block_definitions definitions; - for (int i = 0; i < num_stages; i++) { + for (int i = 0; i < MESA_SHADER_STAGES; i++) { if (stages[i] == NULL) continue; - const gl_shader *stage = stages[i]; + const gl_linked_shader *stage = stages[i]; foreach_in_list(ir_instruction, node, stage->ir) { ir_variable *var = node->as_variable(); if (!var || !var->get_interface_type() || diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp index b816dab9cb7..4b51d40c14b 100644 --- a/src/compiler/glsl/link_uniform_blocks.cpp +++ b/src/compiler/glsl/link_uniform_blocks.cpp @@ -391,7 +391,7 @@ void link_uniform_blocks(void *mem_ctx, struct gl_context *ctx, struct gl_shader_program *prog, - struct gl_shader **shader_list, + struct gl_linked_shader **shader_list, unsigned num_shaders, struct gl_uniform_block **ubo_blocks, unsigned *num_ubo_blocks, diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp index acf8222079a..effbb6aea0c 100644 --- a/src/compiler/glsl/link_uniform_initializers.cpp +++ b/src/compiler/glsl/link_uniform_initializers.cpp @@ -131,7 +131,7 @@ set_opaque_binding(void *mem_ctx, gl_shader_program *prog, } for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) { - gl_shader *shader = prog->_LinkedShaders[sh]; + gl_linked_shader *shader = prog->_LinkedShaders[sh]; if (shader) { if (storage->type->base_type == GLSL_TYPE_SAMPLER && @@ -243,7 +243,7 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog, if (storage->type->is_sampler()) { for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) { - gl_shader *shader = prog->_LinkedShaders[sh]; + gl_linked_shader *shader = prog->_LinkedShaders[sh]; if (shader && storage->opaque[sh].active) { unsigned index = storage->opaque[sh].index; @@ -263,7 +263,7 @@ link_set_uniform_initializers(struct gl_shader_program *prog, void *mem_ctx = NULL; for (unsigned int i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *shader = prog->_LinkedShaders[i]; + struct gl_linked_shader *shader = prog->_LinkedShaders[i]; if (shader == NULL) continue; diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index 98ae3ad5371..807a8f3bd04 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -886,7 +886,7 @@ public: * shaders). */ static void -link_update_uniform_buffer_variables(struct gl_shader *shader) +link_update_uniform_buffer_variables(struct gl_linked_shader *shader) { foreach_in_list(ir_instruction, node, shader->ir) { ir_variable *const var = node->as_variable(); @@ -1022,7 +1022,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog, struct string_to_uint_map *hiddenUniforms = new string_to_uint_map; count_uniform_size uniform_size(prog->UniformHash, hiddenUniforms); for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (sh == NULL) continue; @@ -1204,7 +1204,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog, continue; for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) { - struct gl_shader *sh = prog->_LinkedShaders[j]; + struct gl_linked_shader *sh = prog->_LinkedShaders[j]; if (!sh) continue; @@ -1234,7 +1234,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog, if (uniforms[i].remap_location != UNMAPPED_UNIFORM_LOC) continue; for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) { - struct gl_shader *sh = prog->_LinkedShaders[j]; + struct gl_linked_shader *sh = prog->_LinkedShaders[j]; if (!sh) continue; diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp index ef8bdbe3ade..db42bb1b714 100644 --- a/src/compiler/glsl/link_varyings.cpp +++ b/src/compiler/glsl/link_varyings.cpp @@ -107,7 +107,7 @@ create_xfb_varying_names(void *mem_ctx, const glsl_type *t, char **name, } bool -process_xfb_layout_qualifiers(void *mem_ctx, const gl_shader *sh, +process_xfb_layout_qualifiers(void *mem_ctx, const gl_linked_shader *sh, unsigned *num_tfeedback_decls, char ***varying_names) { @@ -370,7 +370,8 @@ cross_validate_front_and_back_color(struct gl_shader_program *prog, */ void cross_validate_outputs_to_inputs(struct gl_shader_program *prog, - gl_shader *producer, gl_shader *consumer) + gl_linked_shader *producer, + gl_linked_shader *consumer) { glsl_symbol_table parameters; ir_variable *explicit_locations[MAX_VARYINGS_INCL_PATCH][4] = @@ -556,7 +557,7 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog, */ void remove_unused_shader_inputs_and_outputs(bool is_separate_shader_object, - gl_shader *sh, + gl_linked_shader *sh, enum ir_variable_mode mode) { if (is_separate_shader_object) @@ -1938,7 +1939,8 @@ canonicalize_shader_io(exec_list *ir, enum ir_variable_mode io_mode) * with a max of MAX_VARYING. */ uint64_t -reserved_varying_slot(struct gl_shader *stage, ir_variable_mode io_mode) +reserved_varying_slot(struct gl_linked_shader *stage, + ir_variable_mode io_mode) { assert(io_mode == ir_var_shader_in || io_mode == ir_var_shader_out); /* Avoid an overflow of the returned value */ @@ -1997,7 +1999,8 @@ bool assign_varying_locations(struct gl_context *ctx, void *mem_ctx, struct gl_shader_program *prog, - gl_shader *producer, gl_shader *consumer, + gl_linked_shader *producer, + gl_linked_shader *consumer, unsigned num_tfeedback_decls, tfeedback_decl *tfeedback_decls, const uint64_t reserved_slots) @@ -2260,7 +2263,7 @@ assign_varying_locations(struct gl_context *ctx, bool check_against_output_limit(struct gl_context *ctx, struct gl_shader_program *prog, - gl_shader *producer, + gl_linked_shader *producer, unsigned num_explicit_locations) { unsigned output_vectors = num_explicit_locations; @@ -2304,7 +2307,7 @@ check_against_output_limit(struct gl_context *ctx, bool check_against_input_limit(struct gl_context *ctx, struct gl_shader_program *prog, - gl_shader *consumer, + gl_linked_shader *consumer, unsigned num_explicit_locations) { unsigned input_vectors = num_explicit_locations; diff --git a/src/compiler/glsl/link_varyings.h b/src/compiler/glsl/link_varyings.h index 39e907039a6..afce56e5221 100644 --- a/src/compiler/glsl/link_varyings.h +++ b/src/compiler/glsl/link_varyings.h @@ -291,7 +291,8 @@ private: void cross_validate_outputs_to_inputs(struct gl_shader_program *prog, - gl_shader *producer, gl_shader *consumer); + gl_linked_shader *producer, + gl_linked_shader *consumer); bool parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog, @@ -299,13 +300,13 @@ parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog, char **varying_names, tfeedback_decl *decls); bool -process_xfb_layout_qualifiers(void *mem_ctx, const gl_shader *sh, +process_xfb_layout_qualifiers(void *mem_ctx, const gl_linked_shader *sh, unsigned *num_tfeedback_decls, char ***varying_names); void remove_unused_shader_inputs_and_outputs(bool is_separate_shader_object, - gl_shader *sh, + gl_linked_shader *sh, enum ir_variable_mode mode); bool @@ -318,24 +319,26 @@ bool assign_varying_locations(struct gl_context *ctx, void *mem_ctx, struct gl_shader_program *prog, - gl_shader *producer, gl_shader *consumer, + gl_linked_shader *producer, + gl_linked_shader *consumer, unsigned num_tfeedback_decls, tfeedback_decl *tfeedback_decls, const uint64_t reserved_slots); uint64_t -reserved_varying_slot(struct gl_shader *stage, ir_variable_mode io_mode); +reserved_varying_slot(struct gl_linked_shader *stage, + ir_variable_mode io_mode); bool check_against_output_limit(struct gl_context *ctx, struct gl_shader_program *prog, - gl_shader *producer, + gl_linked_shader *producer, unsigned num_explicit_locations); bool check_against_input_limit(struct gl_context *ctx, struct gl_shader_program *prog, - gl_shader *consumer, + gl_linked_shader *consumer, unsigned num_explicit_locations); #endif /* GLSL_LINK_VARYINGS_H */ diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index 411d2feec74..926520eb1b8 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -655,7 +655,7 @@ link_invalidate_variable_locations(exec_list *ir) */ static void analyze_clip_cull_usage(struct gl_shader_program *prog, - struct gl_shader *shader, + struct gl_linked_shader *shader, struct gl_context *ctx, GLuint *clip_distance_array_size, GLuint *cull_distance_array_size) @@ -750,7 +750,7 @@ analyze_clip_cull_usage(struct gl_shader_program *prog, */ void validate_vertex_shader_executable(struct gl_shader_program *prog, - struct gl_shader *shader, + struct gl_linked_shader *shader, struct gl_context *ctx) { if (shader == NULL) @@ -805,7 +805,7 @@ validate_vertex_shader_executable(struct gl_shader_program *prog, void validate_tess_eval_shader_executable(struct gl_shader_program *prog, - struct gl_shader *shader, + struct gl_linked_shader *shader, struct gl_context *ctx) { if (shader == NULL) @@ -824,7 +824,7 @@ validate_tess_eval_shader_executable(struct gl_shader_program *prog, */ void validate_fragment_shader_executable(struct gl_shader_program *prog, - struct gl_shader *shader) + struct gl_linked_shader *shader) { if (shader == NULL) return; @@ -851,7 +851,7 @@ validate_fragment_shader_executable(struct gl_shader_program *prog, */ void validate_geometry_shader_executable(struct gl_shader_program *prog, - struct gl_shader *shader, + struct gl_linked_shader *shader, struct gl_context *ctx) { if (shader == NULL) @@ -873,7 +873,7 @@ static void validate_geometry_shader_emissions(struct gl_context *ctx, struct gl_shader_program *prog) { - struct gl_shader *sh = prog->_LinkedShaders[MESA_SHADER_GEOMETRY]; + struct gl_linked_shader *sh = prog->_LinkedShaders[MESA_SHADER_GEOMETRY]; if (sh != NULL) { find_emit_vertex_visitor emit_vertex(ctx->Const.MaxVertexStreams - 1); @@ -1240,7 +1240,7 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog, } for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; InterfaceBlockStageIndex[i] = new int[max_num_buffer_blocks]; for (unsigned int j = 0; j < max_num_buffer_blocks; j++) @@ -1285,7 +1285,7 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog, int stage_index = InterfaceBlockStageIndex[i][j]; if (stage_index != -1) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; blks[j].stageref |= (1 << i); @@ -1314,7 +1314,7 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog, * Populates a shaders symbol table with all global declarations */ static void -populate_symbol_table(gl_shader *sh) +populate_symbol_table(gl_linked_shader *sh) { sh->symbols = new(sh) glsl_symbol_table; @@ -1352,12 +1352,12 @@ populate_symbol_table(gl_shader *sh) * should be added. */ void -remap_variables(ir_instruction *inst, struct gl_shader *target, +remap_variables(ir_instruction *inst, struct gl_linked_shader *target, hash_table *temps) { class remap_visitor : public ir_hierarchical_visitor { public: - remap_visitor(struct gl_shader *target, + remap_visitor(struct gl_linked_shader *target, hash_table *temps) { this->target = target; @@ -1392,7 +1392,7 @@ remap_variables(ir_instruction *inst, struct gl_shader *target, } private: - struct gl_shader *target; + struct gl_linked_shader *target; glsl_symbol_table *symbols; exec_list *instructions; hash_table *temps; @@ -1427,7 +1427,7 @@ remap_variables(ir_instruction *inst, struct gl_shader *target, */ exec_node * move_non_declarations(exec_list *instructions, exec_node *last, - bool make_copies, gl_shader *target) + bool make_copies, gl_linked_shader *target) { hash_table *temps = NULL; @@ -1682,7 +1682,7 @@ private: static void link_xfb_stride_layout_qualifiers(struct gl_context *ctx, struct gl_shader_program *prog, - struct gl_shader *linked_shader, + struct gl_linked_shader *linked_shader, struct gl_shader **shader_list, unsigned num_shaders) { @@ -1746,7 +1746,7 @@ link_xfb_stride_layout_qualifiers(struct gl_context *ctx, */ static void link_tcs_out_layout_qualifiers(struct gl_shader_program *prog, - struct gl_shader *linked_shader, + struct gl_linked_shader *linked_shader, struct gl_shader **shader_list, unsigned num_shaders) { @@ -1801,7 +1801,7 @@ link_tcs_out_layout_qualifiers(struct gl_shader_program *prog, */ static void link_tes_in_layout_qualifiers(struct gl_shader_program *prog, - struct gl_shader *linked_shader, + struct gl_linked_shader *linked_shader, struct gl_shader **shader_list, unsigned num_shaders) { @@ -1901,7 +1901,7 @@ link_tes_in_layout_qualifiers(struct gl_shader_program *prog, */ static void link_fs_input_layout_qualifiers(struct gl_shader_program *prog, - struct gl_shader *linked_shader, + struct gl_linked_shader *linked_shader, struct gl_shader **shader_list, unsigned num_shaders) { @@ -1969,7 +1969,7 @@ link_fs_input_layout_qualifiers(struct gl_shader_program *prog, */ static void link_gs_inout_layout_qualifiers(struct gl_shader_program *prog, - struct gl_shader *linked_shader, + struct gl_linked_shader *linked_shader, struct gl_shader **shader_list, unsigned num_shaders) { @@ -2076,7 +2076,7 @@ link_gs_inout_layout_qualifiers(struct gl_shader_program *prog, */ static void link_cs_input_layout_qualifiers(struct gl_shader_program *prog, - struct gl_shader *linked_shader, + struct gl_linked_shader *linked_shader, struct gl_shader **shader_list, unsigned num_shaders) { @@ -2138,7 +2138,7 @@ link_cs_input_layout_qualifiers(struct gl_shader_program *prog, * If this function is supplied a single shader, it is cloned, and the new * shader is returned. */ -static struct gl_shader * +static struct gl_linked_shader * link_intrastage_shaders(void *mem_ctx, struct gl_context *ctx, struct gl_shader_program *prog, @@ -2216,7 +2216,7 @@ link_intrastage_shaders(void *mem_ctx, */ gl_shader *main = NULL; for (unsigned i = 0; i < num_shaders; i++) { - if (!_mesa_get_main_function_signature(shader_list[i]->symbols)) { + if (_mesa_get_main_function_signature(shader_list[i]->symbols)) { main = shader_list[i]; break; } @@ -2228,7 +2228,7 @@ link_intrastage_shaders(void *mem_ctx, return NULL; } - gl_shader *linked = ctx->Driver.NewShader(NULL, 0, shader_list[0]->Stage); + gl_linked_shader *linked = ctx->Driver.NewShader(shader_list[0]->Stage); linked->ir = new(linked) exec_list; clone_ir_list(mem_ctx, linked->ir, main->ir); @@ -2299,7 +2299,7 @@ link_intrastage_shaders(void *mem_ctx, if (!ok) { - _mesa_delete_shader(ctx, linked); + _mesa_delete_linked_shader(ctx, linked); return NULL; } @@ -2317,7 +2317,7 @@ link_intrastage_shaders(void *mem_ctx, &num_ssbo_blocks); if (!prog->LinkStatus) { - _mesa_delete_shader(ctx, linked); + _mesa_delete_linked_shader(ctx, linked); return NULL; } @@ -2463,8 +2463,8 @@ resize_tes_inputs(struct gl_context *ctx, if (prog->_LinkedShaders[MESA_SHADER_TESS_EVAL] == NULL) return; - gl_shader *const tcs = prog->_LinkedShaders[MESA_SHADER_TESS_CTRL]; - gl_shader *const tes = prog->_LinkedShaders[MESA_SHADER_TESS_EVAL]; + gl_linked_shader *const tcs = prog->_LinkedShaders[MESA_SHADER_TESS_CTRL]; + gl_linked_shader *const tes = prog->_LinkedShaders[MESA_SHADER_TESS_EVAL]; /* If no control shader is present, then the TES inputs are statically * sized to MaxPatchVertices; the actual size of the arrays won't be @@ -2576,7 +2576,7 @@ assign_attribute_or_color_locations(gl_shader_program *prog, assert((target_index == MESA_SHADER_VERTEX) || (target_index == MESA_SHADER_FRAGMENT)); - gl_shader *const sh = prog->_LinkedShaders[target_index]; + gl_linked_shader *const sh = prog->_LinkedShaders[target_index]; if (sh == NULL) return true; @@ -2976,8 +2976,8 @@ assign_attribute_or_color_locations(gl_shader_program *prog, * unmatch flag if found so we don't optimise them away. */ static void -match_explicit_outputs_to_inputs(gl_shader *producer, - gl_shader *consumer) +match_explicit_outputs_to_inputs(gl_linked_shader *producer, + gl_linked_shader *consumer) { glsl_symbol_table parameters; ir_variable *explicit_locations[MAX_VARYINGS_INCL_PATCH][4] = @@ -3081,7 +3081,7 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog) unsigned total_shader_storage_blocks = 0; for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (sh == NULL) continue; @@ -3175,7 +3175,7 @@ static void link_calculate_subroutine_compat(struct gl_shader_program *prog) { for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; int count; if (!sh) continue; @@ -3213,7 +3213,7 @@ static void check_subroutine_resources(struct gl_shader_program *prog) { for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (sh) { if (sh->NumSubroutineUniformRemapTable > MAX_SUBROUTINE_UNIFORM_LOCATIONS) @@ -3236,7 +3236,7 @@ check_image_resources(struct gl_context *ctx, struct gl_shader_program *prog) return; for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (sh) { if (sh->NumImages > ctx->Const.Program[i].MaxImageUniforms) @@ -3340,7 +3340,7 @@ reserve_explicit_locations(struct gl_shader_program *prog, static bool reserve_subroutine_explicit_locations(struct gl_shader_program *prog, - struct gl_shader *sh, + struct gl_linked_shader *sh, ir_variable *var) { unsigned slots = var->type->uniform_locations(); @@ -3415,7 +3415,7 @@ check_explicit_uniform_locations(struct gl_context *ctx, unsigned entries_total = 0; for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = prog->_LinkedShaders[i]; + struct gl_linked_shader *sh = prog->_LinkedShaders[i]; if (!sh) continue; @@ -3620,7 +3620,7 @@ build_stageref(struct gl_shader_program *shProg, const char *name, assert(MESA_SHADER_STAGES < 8); for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = shProg->_LinkedShaders[i]; + struct gl_linked_shader *sh = shProg->_LinkedShaders[i]; if (!sh) continue; @@ -3859,7 +3859,7 @@ add_interface_variables(struct gl_shader_program *shProg, static bool add_packed_varyings(struct gl_shader_program *shProg, int stage, GLenum type) { - struct gl_shader *sh = shProg->_LinkedShaders[stage]; + struct gl_linked_shader *sh = shProg->_LinkedShaders[stage]; GLenum iface; if (!sh || !sh->packed_varyings) @@ -3895,7 +3895,7 @@ add_packed_varyings(struct gl_shader_program *shProg, int stage, GLenum type) static bool add_fragdata_arrays(struct gl_shader_program *shProg) { - struct gl_shader *sh = shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]; + struct gl_linked_shader *sh = shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]; if (!sh || !sh->fragdata_arrays) return true; @@ -4270,7 +4270,7 @@ build_program_resource_list(struct gl_context *ctx, } for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *sh = shProg->_LinkedShaders[i]; + struct gl_linked_shader *sh = shProg->_LinkedShaders[i]; GLuint type; if (!sh) @@ -4322,7 +4322,7 @@ static void link_assign_subroutine_types(struct gl_shader_program *prog) { for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - gl_shader *sh = prog->_LinkedShaders[i]; + gl_linked_shader *sh = prog->_LinkedShaders[i]; if (sh == NULL) continue; @@ -4428,7 +4428,7 @@ disable_varying_optimizations_for_sso(struct gl_shader_program *prog) return; for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) { - gl_shader *sh = prog->_LinkedShaders[stage]; + gl_linked_shader *sh = prog->_LinkedShaders[stage]; if (!sh) continue; @@ -4587,8 +4587,9 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) } for (unsigned int i = 0; i < MESA_SHADER_STAGES; i++) { - if (prog->_LinkedShaders[i] != NULL) - _mesa_delete_shader(ctx, prog->_LinkedShaders[i]); + if (prog->_LinkedShaders[i] != NULL) { + _mesa_delete_linked_shader(ctx, prog->_LinkedShaders[i]); + } prog->_LinkedShaders[i] = NULL; } @@ -4597,13 +4598,13 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) */ for (int stage = 0; stage < MESA_SHADER_STAGES; stage++) { if (num_shaders[stage] > 0) { - gl_shader *const sh = + gl_linked_shader *const sh = link_intrastage_shaders(mem_ctx, ctx, prog, shader_list[stage], num_shaders[stage]); if (!prog->LinkStatus) { if (sh) - _mesa_delete_shader(ctx, sh); + _mesa_delete_linked_shader(ctx, sh); goto done; } @@ -4626,11 +4627,11 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) } if (!prog->LinkStatus) { if (sh) - _mesa_delete_shader(ctx, sh); + _mesa_delete_linked_shader(ctx, sh); goto done; } - _mesa_reference_shader(ctx, &prog->_LinkedShaders[stage], sh); + prog->_LinkedShaders[stage] = sh; } } @@ -4701,8 +4702,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) } /* Cross-validate uniform blocks between shader stages */ - validate_interstage_uniform_blocks(prog, prog->_LinkedShaders, - MESA_SHADER_STAGES); + validate_interstage_uniform_blocks(prog, prog->_LinkedShaders); if (!prog->LinkStatus) goto done; @@ -4718,7 +4718,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) * This rule also applies to GLSL ES 3.00. */ if (max_version >= (prog->IsES ? 300 : 130)) { - struct gl_shader *sh = prog->_LinkedShaders[MESA_SHADER_FRAGMENT]; + struct gl_linked_shader *sh = prog->_LinkedShaders[MESA_SHADER_FRAGMENT]; if (sh) { lower_discard_flow(sh->ir); } @@ -4879,7 +4879,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) /* If the program is made up of only a single stage */ if (first == last) { - gl_shader *const sh = prog->_LinkedShaders[last]; + gl_linked_shader *const sh = prog->_LinkedShaders[last]; if (prog->SeparateShader) { const uint64_t reserved_slots = reserved_varying_slot(sh, ir_var_shader_in); @@ -4910,8 +4910,8 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) if (prog->_LinkedShaders[i] == NULL && i != 0) continue; - gl_shader *const sh_i = prog->_LinkedShaders[i]; - gl_shader *const sh_next = prog->_LinkedShaders[next]; + gl_linked_shader *const sh_i = prog->_LinkedShaders[i]; + gl_linked_shader *const sh_next = prog->_LinkedShaders[next]; const uint64_t reserved_out_slots = reserved_varying_slot(sh_i, ir_var_shader_out); diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h index 045dc1fff02..19b14d50696 100644 --- a/src/compiler/glsl/linker.h +++ b/src/compiler/glsl/linker.h @@ -27,7 +27,7 @@ #define GLSL_LINKER_H extern bool -link_function_calls(gl_shader_program *prog, gl_shader *main, +link_function_calls(gl_shader_program *prog, gl_linked_shader *main, gl_shader **shader_list, unsigned num_shaders); extern void @@ -57,7 +57,7 @@ extern void link_uniform_blocks(void *mem_ctx, struct gl_context *ctx, struct gl_shader_program *prog, - struct gl_shader **shader_list, + struct gl_linked_shader **shader_list, unsigned num_shaders, struct gl_uniform_block **ubo_blocks, unsigned *num_ubo_blocks, @@ -76,12 +76,12 @@ validate_intrastage_interface_blocks(struct gl_shader_program *prog, void validate_interstage_inout_blocks(struct gl_shader_program *prog, - const gl_shader *producer, - const gl_shader *consumer); + const gl_linked_shader *producer, + const gl_linked_shader *consumer); void validate_interstage_uniform_blocks(struct gl_shader_program *prog, - gl_shader **stages, int num_stages); + gl_linked_shader **stages); extern void link_assign_atomic_counter_resources(struct gl_context *ctx, diff --git a/src/compiler/glsl/lower_distance.cpp b/src/compiler/glsl/lower_distance.cpp index c2158f24f39..e2d7e2a5886 100644 --- a/src/compiler/glsl/lower_distance.cpp +++ b/src/compiler/glsl/lower_distance.cpp @@ -654,7 +654,8 @@ lower_distance_visitor_counter::handle_rvalue(ir_rvalue **rv) } bool -lower_clip_cull_distance(struct gl_shader_program *prog, gl_shader *shader) +lower_clip_cull_distance(struct gl_shader_program *prog, + struct gl_linked_shader *shader) { int clip_size, cull_size; diff --git a/src/compiler/glsl/lower_named_interface_blocks.cpp b/src/compiler/glsl/lower_named_interface_blocks.cpp index f780ecacbd2..dbf0c639028 100644 --- a/src/compiler/glsl/lower_named_interface_blocks.cpp +++ b/src/compiler/glsl/lower_named_interface_blocks.cpp @@ -289,7 +289,7 @@ flatten_named_interface_blocks_declarations::handle_rvalue(ir_rvalue **rvalue) } void -lower_named_interface_blocks(void *mem_ctx, gl_shader *shader) +lower_named_interface_blocks(void *mem_ctx, gl_linked_shader *shader) { flatten_named_interface_blocks_declarations v_decl(mem_ctx); v_decl.run(shader->ir); diff --git a/src/compiler/glsl/lower_packed_varyings.cpp b/src/compiler/glsl/lower_packed_varyings.cpp index 130b8f66ed6..a897d2fb59b 100644 --- a/src/compiler/glsl/lower_packed_varyings.cpp +++ b/src/compiler/glsl/lower_packed_varyings.cpp @@ -172,7 +172,7 @@ public: bool disable_varying_packing, bool xfb_enabled); - void run(struct gl_shader *shader); + void run(struct gl_linked_shader *shader); private: void bitwise_assign_pack(ir_rvalue *lhs, ir_rvalue *rhs); @@ -260,7 +260,7 @@ lower_packed_varyings_visitor::lower_packed_varyings_visitor( } void -lower_packed_varyings_visitor::run(struct gl_shader *shader) +lower_packed_varyings_visitor::run(struct gl_linked_shader *shader) { foreach_in_list(ir_instruction, node, shader->ir) { ir_variable *var = node->as_variable(); @@ -767,7 +767,7 @@ lower_packed_varyings_return_splicer::visit_leave(ir_return *ret) void lower_packed_varyings(void *mem_ctx, unsigned locations_used, ir_variable_mode mode, unsigned gs_input_vertices, - gl_shader *shader, bool disable_varying_packing, + gl_linked_shader *shader, bool disable_varying_packing, bool xfb_enabled) { exec_list *instructions = shader->ir; diff --git a/src/compiler/glsl/lower_shared_reference.cpp b/src/compiler/glsl/lower_shared_reference.cpp index e63e7dd8193..1702469fe65 100644 --- a/src/compiler/glsl/lower_shared_reference.cpp +++ b/src/compiler/glsl/lower_shared_reference.cpp @@ -51,7 +51,7 @@ class lower_shared_reference_visitor : public lower_buffer_access::lower_buffer_access { public: - lower_shared_reference_visitor(struct gl_shader *shader) + lower_shared_reference_visitor(struct gl_linked_shader *shader) : list_ctx(ralloc_context(NULL)), shader(shader), shared_size(0u) { list_inithead(&var_offsets); @@ -88,7 +88,7 @@ public: unsigned write_mask); void *list_ctx; - struct gl_shader *shader; + struct gl_linked_shader *shader; struct list_head var_offsets; unsigned shared_size; bool progress; @@ -475,7 +475,7 @@ lower_shared_reference_visitor::visit_enter(ir_call *ir) } /* unnamed namespace */ void -lower_shared_reference(struct gl_shader *shader, unsigned *shared_size) +lower_shared_reference(struct gl_linked_shader *shader, unsigned *shared_size) { if (shader->Stage != MESA_SHADER_COMPUTE) return; diff --git a/src/compiler/glsl/lower_tess_level.cpp b/src/compiler/glsl/lower_tess_level.cpp index bed2553222f..adca29ce424 100644 --- a/src/compiler/glsl/lower_tess_level.cpp +++ b/src/compiler/glsl/lower_tess_level.cpp @@ -440,7 +440,7 @@ lower_tess_level_visitor::visit_leave(ir_call *ir) bool -lower_tess_level(gl_shader *shader) +lower_tess_level(gl_linked_shader *shader) { if ((shader->Stage != MESA_SHADER_TESS_CTRL) && (shader->Stage != MESA_SHADER_TESS_EVAL)) diff --git a/src/compiler/glsl/lower_ubo_reference.cpp b/src/compiler/glsl/lower_ubo_reference.cpp index c27de0b2565..083f43f93a3 100644 --- a/src/compiler/glsl/lower_ubo_reference.cpp +++ b/src/compiler/glsl/lower_ubo_reference.cpp @@ -44,7 +44,7 @@ namespace { class lower_ubo_reference_visitor : public lower_buffer_access::lower_buffer_access { public: - lower_ubo_reference_visitor(struct gl_shader *shader, + lower_ubo_reference_visitor(struct gl_linked_shader *shader, bool clamp_block_indices) : shader(shader), clamp_block_indices(clamp_block_indices), struct_field(NULL), variable(NULL) @@ -105,7 +105,7 @@ public: ir_call *check_for_ssbo_atomic_intrinsic(ir_call *ir); ir_visitor_status visit_enter(ir_call *ir); - struct gl_shader *shader; + struct gl_linked_shader *shader; bool clamp_block_indices; struct gl_uniform_buffer_variable *ubo_var; const struct glsl_struct_field *struct_field; @@ -1090,7 +1090,7 @@ lower_ubo_reference_visitor::visit_enter(ir_call *ir) } /* unnamed namespace */ void -lower_ubo_reference(struct gl_shader *shader, bool clamp_block_indices) +lower_ubo_reference(struct gl_linked_shader *shader, bool clamp_block_indices) { lower_ubo_reference_visitor v(shader, clamp_block_indices); diff --git a/src/compiler/glsl/lower_vector_derefs.cpp b/src/compiler/glsl/lower_vector_derefs.cpp index 4a5d6f0da4c..f7bf68db364 100644 --- a/src/compiler/glsl/lower_vector_derefs.cpp +++ b/src/compiler/glsl/lower_vector_derefs.cpp @@ -94,7 +94,7 @@ vector_deref_visitor::handle_rvalue(ir_rvalue **rv) } bool -lower_vector_derefs(gl_shader *shader) +lower_vector_derefs(gl_linked_shader *shader) { vector_deref_visitor v; diff --git a/src/compiler/glsl/lower_vertex_id.cpp b/src/compiler/glsl/lower_vertex_id.cpp index ee69d940388..412b97e527b 100644 --- a/src/compiler/glsl/lower_vertex_id.cpp +++ b/src/compiler/glsl/lower_vertex_id.cpp @@ -122,7 +122,7 @@ lower_vertex_id_visitor::visit(ir_dereference_variable *ir) } bool -lower_vertex_id(gl_shader *shader) +lower_vertex_id(gl_linked_shader *shader) { /* gl_VertexID only exists in the vertex shader. */ diff --git a/src/compiler/glsl/opt_dead_builtin_varyings.cpp b/src/compiler/glsl/opt_dead_builtin_varyings.cpp index 2e40b78d20b..7feea3ba18b 100644 --- a/src/compiler/glsl/opt_dead_builtin_varyings.cpp +++ b/src/compiler/glsl/opt_dead_builtin_varyings.cpp @@ -272,7 +272,7 @@ public: */ class replace_varyings_visitor : public ir_rvalue_visitor { public: - replace_varyings_visitor(struct gl_shader *sha, + replace_varyings_visitor(struct gl_linked_shader *sha, const varying_info_visitor *info, unsigned external_texcoord_usage, unsigned external_color_usage, @@ -499,7 +499,7 @@ public: } private: - struct gl_shader *shader; + struct gl_linked_shader *shader; const varying_info_visitor *info; ir_variable *new_fragdata[MAX_DRAW_BUFFERS]; ir_variable *new_texcoord[MAX_TEXTURE_COORD_UNITS]; @@ -511,7 +511,7 @@ private: } /* anonymous namespace */ static void -lower_texcoord_array(struct gl_shader *shader, const varying_info_visitor *info) +lower_texcoord_array(struct gl_linked_shader *shader, const varying_info_visitor *info) { replace_varyings_visitor(shader, info, (1 << MAX_TEXTURE_COORD_UNITS) - 1, @@ -519,7 +519,7 @@ lower_texcoord_array(struct gl_shader *shader, const varying_info_visitor *info) } static void -lower_fragdata_array(struct gl_shader *shader) +lower_fragdata_array(struct gl_linked_shader *shader) { varying_info_visitor info(ir_var_shader_out, true); info.get(shader->ir, 0, NULL); @@ -530,7 +530,8 @@ lower_fragdata_array(struct gl_shader *shader) void do_dead_builtin_varyings(struct gl_context *ctx, - gl_shader *producer, gl_shader *consumer, + gl_linked_shader *producer, + gl_linked_shader *consumer, unsigned num_tfeedback_decls, tfeedback_decl *tfeedback_decls) { diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp index d0057df7f32..760fe8f01b5 100644 --- a/src/compiler/glsl/standalone.cpp +++ b/src/compiler/glsl/standalone.cpp @@ -222,7 +222,7 @@ initialize_context(struct gl_context *ctx, gl_api api) ctx->Const.GenerateTemporaryNames = true; ctx->Const.MaxPatchVertices = 32; - ctx->Driver.NewShader = _mesa_new_shader; + ctx->Driver.NewShader = _mesa_new_linked_shader; } /* Returned string will have 'ctx' as its ralloc owner. */ @@ -412,7 +412,7 @@ standalone_compile_shader(const struct standalone_options *_options, } for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - struct gl_shader *shader = whole_program->_LinkedShaders[i]; + struct gl_linked_shader *shader = whole_program->_LinkedShaders[i]; if (!shader) continue; diff --git a/src/compiler/glsl/standalone_scaffolding.cpp b/src/compiler/glsl/standalone_scaffolding.cpp index 396965af3b5..b5dc5231ee8 100644 --- a/src/compiler/glsl/standalone_scaffolding.cpp +++ b/src/compiler/glsl/standalone_scaffolding.cpp @@ -84,6 +84,19 @@ _mesa_new_shader(struct gl_context *ctx, GLuint name, gl_shader_stage stage) return shader; } +struct gl_linked_shader * +_mesa_new_linked_shader(gl_shader_stage stage) +{ + struct gl_linked_shader *shader; + + assert(stage == MESA_SHADER_FRAGMENT || stage == MESA_SHADER_VERTEX); + shader = rzalloc(NULL, struct gl_linked_shader); + if (shader) { + shader->Stage = stage; + } + return shader; +} + void _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh) { @@ -93,6 +106,13 @@ _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh) } void +_mesa_delete_linked_shader(struct gl_context *ctx, + struct gl_linked_shader *sh) +{ + ralloc_free(sh); +} + +void _mesa_clear_shader_program_data(struct gl_shader_program *shProg) { shProg->NumUniformStorage = 0; diff --git a/src/compiler/glsl/standalone_scaffolding.h b/src/compiler/glsl/standalone_scaffolding.h index 15dc7028f64..c6666c9c73d 100644 --- a/src/compiler/glsl/standalone_scaffolding.h +++ b/src/compiler/glsl/standalone_scaffolding.h @@ -44,10 +44,17 @@ _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, extern "C" struct gl_shader * _mesa_new_shader(struct gl_context *ctx, GLuint name, gl_shader_stage stage); +extern "C" struct gl_linked_shader * +_mesa_new_linked_shader(gl_shader_stage stage); + extern "C" void _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh); extern "C" void +_mesa_delete_linked_shader(struct gl_context *ctx, + struct gl_linked_shader *sh); + +extern "C" void _mesa_clear_shader_program_data(struct gl_shader_program *); extern "C" void diff --git a/src/compiler/glsl/test_optpass.cpp b/src/compiler/glsl/test_optpass.cpp index fed1fabf301..f19d7e6e6d5 100644 --- a/src/compiler/glsl/test_optpass.cpp +++ b/src/compiler/glsl/test_optpass.cpp @@ -200,7 +200,7 @@ int test_optpass(int argc, char **argv) struct gl_context *ctx = &local_ctx; initialize_context_to_defaults(ctx, API_OPENGL_COMPAT); - ctx->Driver.NewShader = _mesa_new_shader; + ctx->Driver.NewShader = _mesa_new_linked_shader; ir_variable::temporaries_allocate_names = true; struct gl_shader *shader = rzalloc(NULL, struct gl_shader); |