From: Marek Olšák <marek.ol...@amd.com> to reduce the amount of GLSL optimizations for drivers that can do better. --- src/compiler/glsl/glsl_parser_extras.cpp | 14 +++++++++++--- src/compiler/glsl/linker.cpp | 16 ++++++++++++---- src/mesa/main/ff_fragment_shader.cpp | 10 +++++++--- src/mesa/main/mtypes.h | 7 +++++++ 4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index b12cf3d..e97cbf4 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -1942,26 +1942,34 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, } } if (!state->error && !shader->ir->is_empty()) { struct gl_shader_compiler_options *options = &ctx->Const.ShaderCompilerOptions[shader->Stage]; assign_subroutine_indexes(shader, state); lower_subroutine(shader->ir, state); + /* Do some optimization at compile time to reduce shader IR size * and reduce later work if the same shader is linked multiple times */ - while (do_common_optimization(shader->ir, false, false, options, - ctx->Const.NativeIntegers)) - ; + if (ctx->Const.GLSLOptimizeConservatively) { + /* Run it just once. */ + do_common_optimization(shader->ir, false, false, options, + ctx->Const.NativeIntegers); + } else { + /* Repeat it until it stops making changes. */ + while (do_common_optimization(shader->ir, false, false, options, + ctx->Const.NativeIntegers)) + ; + } validate_ir_tree(shader->ir); enum ir_variable_mode other; switch (shader->Stage) { case MESA_SHADER_VERTEX: other = ir_var_shader_in; break; case MESA_SHADER_FRAGMENT: other = ir_var_shader_out; diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index f4f918a..13fbb30 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -5041,24 +5041,32 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) goto done; if (ctx->Const.ShaderCompilerOptions[i].LowerCombinedClipCullDistance) { lower_clip_cull_distance(prog, prog->_LinkedShaders[i]); } if (ctx->Const.LowerTessLevel) { lower_tess_level(prog->_LinkedShaders[i]); } - while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false, - &ctx->Const.ShaderCompilerOptions[i], - ctx->Const.NativeIntegers)) - ; + if (ctx->Const.GLSLOptimizeConservatively) { + /* Run it just once. */ + do_common_optimization(prog->_LinkedShaders[i]->ir, true, false, + &ctx->Const.ShaderCompilerOptions[i], + ctx->Const.NativeIntegers); + } else { + /* Repeat it until it stops making changes. */ + while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false, + &ctx->Const.ShaderCompilerOptions[i], + ctx->Const.NativeIntegers)) + ; + } lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir, i); propagate_invariance(prog->_LinkedShaders[i]->ir); } /* Validation for special cases where we allow sampler array indexing * with loop induction variable. This check emits a warning or error * depending if backend can handle dynamic indexing. */ if ((!prog->IsES && prog->data->Version < 130) || diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp index fd2c71f..48b84e8 100644 --- a/src/mesa/main/ff_fragment_shader.cpp +++ b/src/mesa/main/ff_fragment_shader.cpp @@ -1247,23 +1247,27 @@ create_new_program(struct gl_context *ctx, struct state_key *key) p.instructions = &main_sig->body; if (key->num_draw_buffers) emit_instructions(&p); validate_ir_tree(p.shader->ir); const struct gl_shader_compiler_options *options = &ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT]; - while (do_common_optimization(p.shader->ir, false, false, options, - ctx->Const.NativeIntegers)) - ; + /* Conservative approach: Don't optimize here, the linker does it too. */ + if (!ctx->Const.GLSLOptimizeConservatively) { + while (do_common_optimization(p.shader->ir, false, false, options, + ctx->Const.NativeIntegers)) + ; + } + reparent_ir(p.shader->ir, p.shader->ir); p.shader->CompileStatus = true; p.shader->Version = state->language_version; p.shader_program->Shaders = (gl_shader **)malloc(sizeof(*p.shader_program->Shaders)); p.shader_program->Shaders[0] = p.shader; p.shader_program->NumShaders = 1; _mesa_glsl_link_shader(ctx, p.shader_program); diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index c7535a3..2693a80 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3636,20 +3636,27 @@ struct gl_constants * * XXX Remove these as soon as a better solution is available. */ GLboolean GLSLSkipStrictMaxUniformLimitCheck; /** Whether gl_FragCoord and gl_FrontFacing are system values. */ bool GLSLFragCoordIsSysVal; bool GLSLFrontFacingIsSysVal; /** + * Run the minimum amount of GLSL optimizations to be able to link + * shaders optimally (eliminate dead varyings and uniforms) and just do + * all the necessary lowering. + */ + bool GLSLOptimizeConservatively; + + /** * Always use the GetTransformFeedbackVertexCount() driver hook, rather * than passing the transform feedback object to the drawing function. */ GLboolean AlwaysUseGetTransformFeedbackVertexCount; /** GL_ARB_map_buffer_alignment */ GLuint MinMapBufferAlignment; /** * Disable varying packing. This is out of spec, but potentially useful -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev