st/mesa: Let nir_opt_access() infer non-readable

In issue #3278, Danylo noted that nir_opt_access() could desynchronize
the prog->sh.ImageAccess[] and prog->sh.BindlessImage[].access fields,
which are filled out as part of uniform linking, prior to running this
optimization pass.  Those fields are used to fill out pipe_image_view's
shader_access field, which is used by a lot of drivers these days.

There's an easy solution to this issue however: we can simply call the
pass prior to linking, a few lines earlier.

This lets us infer that images are non-readable, which may let drivers
do additional optimizations.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3278
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19162>
This commit is contained in:
Kenneth Graunke 2022-10-19 03:43:51 -07:00 committed by Marge Bot
parent 45a111c21c
commit 1462a61b5d

View file

@ -762,6 +762,18 @@ st_link_nir(struct gl_context *ctx,
if (num_shaders == 1)
gl_nir_opts(linked_shader[0]->Program->nir);
/* nir_opt_access() needs to run before linking so that ImageAccess[]
* and BindlessImage[].access are filled out with the correct modes.
*/
for (unsigned i = 0; i < num_shaders; i++) {
nir_shader *nir = linked_shader[i]->Program->nir;
nir_opt_access_options opt_access_options;
opt_access_options.is_vulkan = false;
opt_access_options.infer_non_readable = true;
NIR_PASS_V(nir, nir_opt_access, &opt_access_options);
}
if (shader_program->data->spirv) {
static const gl_nir_linker_options opts = {
true /*fill_parameters */
@ -808,14 +820,6 @@ st_link_nir(struct gl_context *ctx,
nir_lower_indirect_derefs(nir, mode, UINT32_MAX);
}
/* don't infer ACCESS_NON_READABLE so that Program->sh.ImageAccess is
* correct: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3278
*/
nir_opt_access_options opt_access_options;
opt_access_options.is_vulkan = false;
opt_access_options.infer_non_readable = false;
NIR_PASS_V(nir, nir_opt_access, &opt_access_options);
/* This needs to run after the initial pass of nir_lower_vars_to_ssa, so
* that the buffer indices are constants in nir where they where
* constants in GLSL. */