mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-31 18:30:09 +01:00
nir/opt_access: add basic Vulkan support
This involves determining the variables referenced by intrinsics, setting and using the access qualifier correctly and considering that images and buffers can alias. Signed-off-by: Rhys Perry <pendingchaos02@gmail.com> Reviewed-by: Connor Abbott <cwabbott0@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6483>
This commit is contained in:
parent
d587dc32f3
commit
4dc5659463
3 changed files with 18 additions and 9 deletions
|
|
@ -4875,7 +4875,7 @@ bool nir_opt_comparison_pre_impl(nir_function_impl *impl);
|
|||
|
||||
bool nir_opt_comparison_pre(nir_shader *shader);
|
||||
|
||||
bool nir_opt_access(nir_shader *shader);
|
||||
bool nir_opt_access(nir_shader *shader, bool is_vulkan);
|
||||
bool nir_opt_algebraic(nir_shader *shader);
|
||||
bool nir_opt_algebraic_before_ffma(nir_shader *shader);
|
||||
bool nir_opt_algebraic_late(nir_shader *shader);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@
|
|||
*/
|
||||
|
||||
struct access_state {
|
||||
nir_shader *shader;
|
||||
|
||||
struct set *vars_written;
|
||||
bool images_written;
|
||||
bool buffers_written;
|
||||
|
|
@ -45,7 +47,7 @@ struct access_state {
|
|||
static void
|
||||
gather_intrinsic(struct access_state *state, nir_intrinsic_instr *instr)
|
||||
{
|
||||
nir_variable *var;
|
||||
const nir_variable *var;
|
||||
switch (instr->intrinsic) {
|
||||
case nir_intrinsic_image_deref_store:
|
||||
case nir_intrinsic_image_deref_atomic_add:
|
||||
|
|
@ -108,9 +110,9 @@ gather_intrinsic(struct access_state *state, nir_intrinsic_instr *instr)
|
|||
case nir_intrinsic_deref_atomic_fmin:
|
||||
case nir_intrinsic_deref_atomic_fmax:
|
||||
case nir_intrinsic_deref_atomic_fcomp_swap:
|
||||
var = nir_intrinsic_get_var(instr, 0);
|
||||
if (var->data.mode != nir_var_mem_ssbo)
|
||||
if (!nir_deref_mode_is(nir_src_as_deref(instr->src[0]), nir_var_mem_ssbo))
|
||||
break;
|
||||
var = nir_get_binding_variable(state->shader, nir_chase_binding(instr->src[0]));
|
||||
|
||||
_mesa_set_add(state->vars_written, var);
|
||||
state->buffers_written = true;
|
||||
|
|
@ -159,7 +161,8 @@ update_access(struct access_state *state, nir_intrinsic_instr *instr, bool is_im
|
|||
bool is_memory_readonly = access & ACCESS_NON_WRITEABLE;
|
||||
|
||||
if (instr->intrinsic != nir_intrinsic_bindless_image_load) {
|
||||
const nir_variable *var = nir_intrinsic_get_var(instr, 0);
|
||||
const nir_variable *var = nir_get_binding_variable(
|
||||
state->shader, nir_chase_binding(instr->src[0]));
|
||||
is_memory_readonly |= var->data.access & ACCESS_NON_WRITEABLE;
|
||||
}
|
||||
|
||||
|
|
@ -184,8 +187,7 @@ process_intrinsic(struct access_state *state, nir_intrinsic_instr *instr)
|
|||
nir_intrinsic_image_dim(instr) == GLSL_SAMPLER_DIM_BUF);
|
||||
|
||||
case nir_intrinsic_load_deref: {
|
||||
nir_variable *var = nir_intrinsic_get_var(instr, 0);
|
||||
if (var->data.mode != nir_var_mem_ssbo)
|
||||
if (!nir_deref_mode_is(nir_src_as_deref(instr->src[0]), nir_var_mem_ssbo))
|
||||
return false;
|
||||
|
||||
return update_access(state, instr, false, true);
|
||||
|
|
@ -232,9 +234,10 @@ opt_access_impl(struct access_state *state,
|
|||
}
|
||||
|
||||
bool
|
||||
nir_opt_access(nir_shader *shader)
|
||||
nir_opt_access(nir_shader *shader, bool is_vulkan)
|
||||
{
|
||||
struct access_state state = {
|
||||
.shader = shader,
|
||||
.vars_written = _mesa_pointer_set_create(NULL),
|
||||
};
|
||||
|
||||
|
|
@ -252,6 +255,12 @@ nir_opt_access(nir_shader *shader)
|
|||
}
|
||||
}
|
||||
|
||||
/* In Vulkan, buffers and images can alias. */
|
||||
if (is_vulkan) {
|
||||
state.buffers_written |= state.images_written;
|
||||
state.images_written |= state.buffers_written;
|
||||
}
|
||||
|
||||
nir_foreach_variable_with_modes(var, shader, nir_var_uniform |
|
||||
nir_var_mem_ubo |
|
||||
nir_var_mem_ssbo)
|
||||
|
|
|
|||
|
|
@ -802,7 +802,7 @@ st_link_nir(struct gl_context *ctx,
|
|||
struct gl_linked_shader *shader = linked_shader[i];
|
||||
nir_shader *nir = shader->Program->nir;
|
||||
|
||||
NIR_PASS_V(nir, nir_opt_access);
|
||||
NIR_PASS_V(nir, nir_opt_access, false);
|
||||
|
||||
/* 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue