From 9356ba751f77bcb3d4be87c7339d2d3ec13ca015 Mon Sep 17 00:00:00 2001 From: Nicolai Hähnle Date: Mon, 19 Jun 2017 21:25:28 +0200 Subject: glsl/linker: move some non-GLSL specific steps to link_shader Those steps run after the actual intra-stage linking and will be re-used for SPIR-V linking. --- src/compiler/glsl/linker.cpp | 108 ++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index b4784c5119..cc4a9291d9 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -2178,11 +2178,6 @@ link_intrastage_shaders(void *mem_ctx, unsigned num_shaders, bool allow_missing_main) { - struct gl_uniform_block *ubo_blocks = NULL; - struct gl_uniform_block *ssbo_blocks = NULL; - unsigned num_ubo_blocks = 0; - unsigned num_ssbo_blocks = 0; - /* Check that global variables defined in multiple shaders are consistent. */ glsl_symbol_table variables; @@ -2336,54 +2331,6 @@ link_intrastage_shaders(void *mem_ctx, v.run(linked->ir); v.fixup_unnamed_interface_types(); - if (!prog->data->cache_fallback) { - /* Link up uniform blocks defined within this stage. */ - link_uniform_blocks(mem_ctx, ctx, prog, linked, &ubo_blocks, - &num_ubo_blocks, &ssbo_blocks, &num_ssbo_blocks); - - if (!prog->data->LinkStatus) { - _mesa_delete_linked_shader(ctx, linked); - return NULL; - } - - /* Copy ubo blocks to linked shader list */ - linked->Program->sh.UniformBlocks = - ralloc_array(linked, gl_uniform_block *, num_ubo_blocks); - ralloc_steal(linked, ubo_blocks); - for (unsigned i = 0; i < num_ubo_blocks; i++) { - linked->Program->sh.UniformBlocks[i] = &ubo_blocks[i]; - } - linked->Program->info.num_ubos = num_ubo_blocks; - - /* Copy ssbo blocks to linked shader list */ - linked->Program->sh.ShaderStorageBlocks = - ralloc_array(linked, gl_uniform_block *, num_ssbo_blocks); - ralloc_steal(linked, ssbo_blocks); - for (unsigned i = 0; i < num_ssbo_blocks; i++) { - linked->Program->sh.ShaderStorageBlocks[i] = &ssbo_blocks[i]; - } - linked->Program->info.num_ssbos = num_ssbo_blocks; - } - - /* At this point linked should contain all of the linked IR, so - * validate it to make sure nothing went wrong. - */ - validate_ir_tree(linked->ir); - - /* Set the size of geometry shader input arrays */ - if (linked->Stage == MESA_SHADER_GEOMETRY) { - unsigned num_vertices = - vertices_per_prim(gl_prog->info.gs.input_primitive); - array_resize_visitor input_resize_visitor(num_vertices, prog, - MESA_SHADER_GEOMETRY); - foreach_in_list(ir_instruction, ir, linked->ir) { - ir->accept(&input_resize_visitor); - } - } - - if (ctx->Const.VertexID_is_zero_based) - lower_vertex_id(linked); - #ifdef DEBUG /* Compute the source checksum. */ linked->SourceChecksum = 0; @@ -4846,6 +4793,61 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) link_intrastage_shaders(mem_ctx, ctx, prog, shader_list[stage], num_shaders[stage], false); + if (prog->data->LinkStatus) { + if (!prog->data->cache_fallback) { + struct gl_uniform_block *ubo_blocks = NULL; + struct gl_uniform_block *ssbo_blocks = NULL; + unsigned num_ubo_blocks = 0; + unsigned num_ssbo_blocks = 0; + + /* Link up uniform blocks defined within this stage. */ + link_uniform_blocks(mem_ctx, ctx, prog, sh, &ubo_blocks, + &num_ubo_blocks, &ssbo_blocks, &num_ssbo_blocks); + + if (!prog->data->LinkStatus) { + _mesa_delete_linked_shader(ctx, sh); + goto done; + } + + /* Copy ubo blocks to linked shader list */ + sh->Program->sh.UniformBlocks = + ralloc_array(sh, gl_uniform_block *, num_ubo_blocks); + ralloc_steal(sh, ubo_blocks); + for (unsigned i = 0; i < num_ubo_blocks; i++) { + sh->Program->sh.UniformBlocks[i] = &ubo_blocks[i]; + } + sh->Program->info.num_ubos = num_ubo_blocks; + + /* Copy ssbo blocks to linked shader list */ + sh->Program->sh.ShaderStorageBlocks = + ralloc_array(sh, gl_uniform_block *, num_ssbo_blocks); + ralloc_steal(sh, ssbo_blocks); + for (unsigned i = 0; i < num_ssbo_blocks; i++) { + sh->Program->sh.ShaderStorageBlocks[i] = &ssbo_blocks[i]; + } + sh->Program->info.num_ssbos = num_ssbo_blocks; + } + + /* At this point linked should contain all of the linked IR, so + * validate it to make sure nothing went wrong. + */ + validate_ir_tree(sh->ir); + + /* Set the size of geometry shader input arrays */ + if (sh->Stage == MESA_SHADER_GEOMETRY) { + unsigned num_vertices = + vertices_per_prim(sh->Program->info.gs.input_primitive); + array_resize_visitor input_resize_visitor(num_vertices, prog, + MESA_SHADER_GEOMETRY); + foreach_in_list(ir_instruction, ir, sh->ir) { + ir->accept(&input_resize_visitor); + } + } + + if (ctx->Const.VertexID_is_zero_based) + lower_vertex_id(sh); + } + if (!prog->data->LinkStatus) { if (sh) _mesa_delete_linked_shader(ctx, sh); -- cgit v1.2.3