From 8b66cd7dd425a6e88b7d4aa0824c032c47c5b9eb Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 8 Nov 2016 15:22:09 -0800 Subject: [PATCH] glsl: Add a drirc option to skip precision mismatch error checks. Commit 259fc505454ea6a67aeacf6cdebf1398d9947759 added linker error for mismatching uniform precision, as required by GLES specification and conformance test-suite. GLBenchmark 2.7 built for OpenGL ES has shaders which violate this rule, on a dead varying that will be eliminated. The shaders are also only used for the loading screen, so the bug can be worked around by using the -skip_load_frames option. Still, it's a pretty widely used application, so presumably other implementations accept this, and I suspect we're going to have a lot of annoying explaining to do if we don't keep it working. This commit adds a drirc option, disable_glsl_precision_mismatch_error, which can be used to turn the linker error into a warning. This patch was originally written by Eero Tamminen, but I converted it from an environment variable to a driconf option. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97532 Signed-off-by: Kenneth Graunke --- src/compiler/glsl/linker.cpp | 28 ++++++++++++++++--------- src/mesa/drivers/dri/common/drirc | 4 ++++ src/mesa/drivers/dri/common/xmlpool/t_options.h | 4 ++++ src/mesa/drivers/dri/i965/brw_context.c | 3 +++ src/mesa/drivers/dri/i965/intel_screen.c | 1 + src/mesa/main/mtypes.h | 5 +++++ 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index aceea8d..6b242bf 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -862,7 +862,8 @@ validate_intrastage_arrays(struct gl_shader_program *prog, * Perform validation of global variables used across multiple shaders */ void -cross_validate_globals(struct gl_shader_program *prog, +cross_validate_globals(const struct gl_context *ctx, + struct gl_shader_program *prog, struct exec_list *ir, glsl_symbol_table *variables, bool uniforms_only) { @@ -1090,10 +1091,16 @@ cross_validate_globals(struct gl_shader_program *prog, */ if (prog->IsES && (prog->Version != 310 || !var->get_interface_type()) && existing->data.precision != var->data.precision) { - linker_error(prog, "declarations for %s `%s` have " - "mismatching precision qualifiers\n", - mode_string(var), var->name); - return; + if (ctx->Const.DisableGLSLPrecisionMismatchError) { + linker_warning(prog, "declarations for %s `%s` have " + "mismatching precision qualifiers\n", + mode_string(var), var->name); + } else { + linker_error(prog, "declarations for %s `%s` have " + "mismatching precision qualifiers\n", + mode_string(var), var->name); + return; + } } } else variables->add_variable(var); @@ -1105,15 +1112,16 @@ cross_validate_globals(struct gl_shader_program *prog, * Perform validation of uniforms used across multiple shader stages */ void -cross_validate_uniforms(struct gl_shader_program *prog) +cross_validate_uniforms(const struct gl_context *ctx, + struct gl_shader_program *prog) { glsl_symbol_table variables; for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; - cross_validate_globals(prog, prog->_LinkedShaders[i]->ir, &variables, - true); + cross_validate_globals(ctx, prog, prog->_LinkedShaders[i]->ir, + &variables, true); } } @@ -2112,7 +2120,7 @@ link_intrastage_shaders(void *mem_ctx, for (unsigned i = 0; i < num_shaders; i++) { if (shader_list[i] == NULL) continue; - cross_validate_globals(prog, shader_list[i]->ir, &variables, false); + cross_validate_globals(ctx, prog, shader_list[i]->ir, &variables, false); } if (!prog->LinkStatus) @@ -4878,7 +4886,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) * performed, then locations are assigned for uniforms, attributes, and * varyings. */ - cross_validate_uniforms(prog); + cross_validate_uniforms(ctx, prog); if (!prog->LinkStatus) goto done; diff --git a/src/mesa/drivers/dri/common/drirc b/src/mesa/drivers/dri/common/drirc index af84ee8..48010a9 100644 --- a/src/mesa/drivers/dri/common/drirc +++ b/src/mesa/drivers/dri/common/drirc @@ -100,5 +100,9 @@ TODO: document the other workarounds. + + + diff --git a/src/mesa/drivers/dri/common/xmlpool/t_options.h b/src/mesa/drivers/dri/common/xmlpool/t_options.h index 341c376..f987e1f 100644 --- a/src/mesa/drivers/dri/common/xmlpool/t_options.h +++ b/src/mesa/drivers/dri/common/xmlpool/t_options.h @@ -115,6 +115,10 @@ DRI_CONF_OPT_BEGIN_B(allow_glsl_extension_directive_midshader, def) \ DRI_CONF_DESC(en,gettext("Allow GLSL #extension directives in the middle of shaders")) \ DRI_CONF_OPT_END +#define DRI_CONF_DISABLE_GLSL_PRECISION_MISMATCH_ERROR(def) \ +DRI_CONF_OPT_BEGIN_B(disable_glsl_precision_mismatch_error, def) \ + DRI_CONF_DESC(en,gettext("Disable GLSL precision qualifier mismatch error checking")) \ +DRI_CONF_OPT_END /** diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index a01decd..0c13a4a 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -903,6 +903,9 @@ brw_process_driconf_options(struct brw_context *brw) ctx->Const.AllowGLSLExtensionDirectiveMidShader = driQueryOptionb(options, "allow_glsl_extension_directive_midshader"); + ctx->Const.DisableGLSLPrecisionMismatchError = + driQueryOptionb(options, "disable_glsl_precision_mismatch_error"); + ctx->Const.GLSLZeroInit = driQueryOptionb(options, "glsl_zero_init"); brw->dual_color_blend_by_location = diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index e1c3c19..928fb96 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -83,6 +83,7 @@ DRI_CONF_BEGIN DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false") DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION("false") DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER("false") + DRI_CONF_DISABLE_GLSL_PRECISION_MISMATCH_ERROR("false") DRI_CONF_OPT_BEGIN_B(shader_precompile, "true") DRI_CONF_DESC(en, "Perform code generation at shader link time.") diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 08f72e0..1cee292 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3489,6 +3489,11 @@ struct gl_constants GLboolean AllowGLSLExtensionDirectiveMidShader; /** + * Allow GLSL #extension directives in the middle of shaders. + */ + bool DisableGLSLPrecisionMismatchError; + + /** * Force uninitialized variables to default to zero. */ GLboolean GLSLZeroInit; -- 2.10.2