Mesa (staging/21.1): util/driconf: add new ignore_write_to_readonly_var workaround
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jun 30 08:10:55 UTC 2021
Module: Mesa
Branch: staging/21.1
Commit: 633eec4158941c5213a721a8947ec8fca11792b4
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=633eec4158941c5213a721a8947ec8fca11792b4
Author: Timothy Arceri <tarceri at itsqueeze.com>
Date: Fri Jun 25 21:29:31 2021 +1000
util/driconf: add new ignore_write_to_readonly_var workaround
This forces the GLSL compiler to ignore writes to readonly vars
rather than throwing an error.
Cc: mesa-stable
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11602>
(cherry picked from commit a73e7305e9fda66b5951d539fc3341470d4aff5c)
---
.pick_status.json | 2 +-
src/compiler/glsl/ast_to_hir.cpp | 19 +++++++++++++++----
src/compiler/glsl/glsl_parser_extras.cpp | 2 ++
src/compiler/glsl/glsl_parser_extras.h | 1 +
src/gallium/auxiliary/pipe-loader/driinfo_gallium.h | 1 +
src/gallium/frontends/dri/dri_screen.c | 2 ++
src/gallium/include/frontend/api.h | 1 +
src/mesa/main/mtypes.h | 6 ++++++
src/mesa/state_tracker/st_extensions.c | 2 ++
src/util/driconf.h | 4 ++++
10 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index baa8338cd7f..f2fe1a90831 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -481,7 +481,7 @@
"description": "util/driconf: add new ignore_write_to_readonly_var workaround",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": null
},
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index b0918386cbb..c42156fc65c 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -941,6 +941,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
if (lhs_var)
lhs_var->data.assigned = true;
+ bool omit_assignment = false;
if (!error_emitted) {
if (non_lvalue_description != NULL) {
_mesa_glsl_error(&lhs_loc, state,
@@ -957,10 +958,15 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
* no such distinction, that is why this check here is limited to
* buffer variables alone.
*/
- _mesa_glsl_error(&lhs_loc, state,
- "assignment to read-only variable '%s'",
- lhs_var->name);
- error_emitted = true;
+
+ if (state->ignore_write_to_readonly_var)
+ omit_assignment = true;
+ else {
+ _mesa_glsl_error(&lhs_loc, state,
+ "assignment to read-only variable '%s'",
+ lhs_var->name);
+ error_emitted = true;
+ }
} else if (lhs->type->is_array() &&
!state->check_version(state->allow_glsl_120_subset_in_110 ? 110 : 120,
300, &lhs_loc,
@@ -1018,6 +1024,11 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
error_emitted = true;
}
+ if (omit_assignment) {
+ *out_rvalue = needs_rvalue ? ir_rvalue::error_value(ctx) : NULL;
+ return error_emitted;
+ }
+
/* Most callers of do_assignment (assign, add_assign, pre_inc/dec,
* but not post_inc) need the converted assigned value as an rvalue
* to handle things like:
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index f210b08392d..839982506a7 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -321,6 +321,8 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
ctx->Const.AllowGLSL120SubsetIn110;
this->allow_builtin_variable_redeclaration =
ctx->Const.AllowGLSLBuiltinVariableRedeclaration;
+ this->ignore_write_to_readonly_var =
+ ctx->Const.GLSLIgnoreWriteToReadonlyVar;
this->cs_input_local_size_variable_specified = false;
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index 18e3f86a64f..6a7bf1747bb 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -945,6 +945,7 @@ struct _mesa_glsl_parse_state {
bool allow_extension_directive_midshader;
bool allow_glsl_120_subset_in_110;
bool allow_builtin_variable_redeclaration;
+ bool ignore_write_to_readonly_var;
/**
* Known subroutine type declarations.
diff --git a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
index 9c5cdfba5f0..8e72946298e 100644
--- a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
+++ b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
@@ -29,6 +29,7 @@ DRI_CONF_SECTION_DEBUG
DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION(false)
DRI_CONF_FORCE_GLSL_ABS_SQRT(false)
DRI_CONF_GLSL_CORRECT_DERIVATIVES_AFTER_DISCARD(false)
+ DRI_CONF_GLSL_IGNORE_WRITE_TO_READONLY_VAR(false)
DRI_CONF_ALLOW_DRAW_OUT_OF_ORDER(false)
DRI_CONF_ALLOW_INCORRECT_PRIMITIVE_ID(false)
DRI_CONF_FORCE_COMPAT_PROFILE(false)
diff --git a/src/gallium/frontends/dri/dri_screen.c b/src/gallium/frontends/dri/dri_screen.c
index c5c62e59330..d19feaa4c41 100644
--- a/src/gallium/frontends/dri/dri_screen.c
+++ b/src/gallium/frontends/dri/dri_screen.c
@@ -86,6 +86,8 @@ dri_fill_st_options(struct dri_screen *screen)
driQueryOptionb(optionCache, "allow_glsl_builtin_variable_redeclaration");
options->allow_higher_compat_version =
driQueryOptionb(optionCache, "allow_higher_compat_version");
+ options->glsl_ignore_write_to_readonly_var =
+ driQueryOptionb(optionCache, "glsl_ignore_write_to_readonly_var");
options->glsl_zero_init = driQueryOptionb(optionCache, "glsl_zero_init");
options->force_integer_tex_nearest =
driQueryOptionb(optionCache, "force_integer_tex_nearest");
diff --git a/src/gallium/include/frontend/api.h b/src/gallium/include/frontend/api.h
index 936b09227f4..fae1c9bfbf0 100644
--- a/src/gallium/include/frontend/api.h
+++ b/src/gallium/include/frontend/api.h
@@ -232,6 +232,7 @@ struct st_config_options
bool allow_glsl_relaxed_es;
bool allow_glsl_builtin_variable_redeclaration;
bool allow_higher_compat_version;
+ bool glsl_ignore_write_to_readonly_var;
bool glsl_zero_init;
bool vs_position_always_invariant;
bool force_glsl_abs_sqrt;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 8d8799102d7..334e1325b04 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3942,6 +3942,12 @@ struct gl_constants
*/
GLboolean ForceGLSLAbsSqrt;
+ /**
+ * Forces the GLSL compiler to ignore writes to readonly vars rather than
+ * throwing an error.
+ */
+ GLboolean GLSLIgnoreWriteToReadonlyVar;
+
/**
* Types of variable to default initialized to zero. Supported values are:
* - 0: no zero initialization
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 5c87f6e5677..d692b4f535d 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -1187,6 +1187,8 @@ void st_init_extensions(struct pipe_screen *screen,
consts->AllowGLSLCrossStageInterpolationMismatch = options->allow_glsl_cross_stage_interpolation_mismatch;
+ consts->GLSLIgnoreWriteToReadonlyVar = options->glsl_ignore_write_to_readonly_var;
+
consts->PrimitiveRestartFixedIndex =
screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX);
diff --git a/src/util/driconf.h b/src/util/driconf.h
index dcf19adfc0c..cab2f1b85b9 100644
--- a/src/util/driconf.h
+++ b/src/util/driconf.h
@@ -204,6 +204,10 @@
DRI_CONF_OPT_B(glsl_correct_derivatives_after_discard, def, \
"Implicit and explicit derivatives after a discard behave as if the discard didn't happen")
+#define DRI_CONF_GLSL_IGNORE_WRITE_TO_READONLY_VAR(def) \
+ DRI_CONF_OPT_B(glsl_ignore_write_to_readonly_var, def, \
+ "Forces the GLSL compiler to ignore writes to readonly vars rather than throwing an error")
+
#define DRI_CONF_ALLOW_GLSL_CROSS_STAGE_INTERPOLATION_MISMATCH(def) \
DRI_CONF_OPT_B(allow_glsl_cross_stage_interpolation_mismatch, def, \
"Allow interpolation qualifier mismatch across shader stages")
More information about the mesa-commit
mailing list