nir: Add a format field to _deref image intrinsics

The rules here are the same as for texture instructions.  The bits on
the intrinsic are the ground truth and are allowed to vary from the
deref a bit as-needed.  If the intrinsic says PIPE_FORMAT_NONE, then we
can look at the variable, if visible, to get format information.  This
means that we need to be careful when we rewrite intrinsics based on the
deref to only override the format from the _deref intrinsic from the
image variable unless the intrinsic is PIPE_FORMAT_NONE.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11849>
This commit is contained in:
Jason Ekstrand 2021-07-12 09:38:38 -05:00 committed by Marge Bot
parent 0b57272af8
commit 393ee837fb
3 changed files with 10 additions and 3 deletions

View file

@ -2420,8 +2420,11 @@ nir_rewrite_image_intrinsic(nir_intrinsic_instr *intrin, nir_ssa_def *src,
nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
nir_variable *var = nir_deref_instr_get_variable(deref);
/* Only update the format if the intrinsic doesn't have one set */
if (nir_intrinsic_format(intrin) == PIPE_FORMAT_NONE)
nir_intrinsic_set_format(intrin, var->data.image.format);
nir_intrinsic_set_access(intrin, access | var->data.access);
nir_intrinsic_set_format(intrin, var->data.image.format);
if (nir_intrinsic_has_src_type(intrin))
nir_intrinsic_set_src_type(intrin, data_type);
if (nir_intrinsic_has_dest_type(intrin))

View file

@ -562,7 +562,7 @@ atomic3("atomic_counter_comp_swap")
# the ARB_shader_image_load_store specification.
def image(name, src_comp=[], extra_indices=[], **kwargs):
intrinsic("image_deref_" + name, src_comp=[-1] + src_comp,
indices=[IMAGE_DIM, IMAGE_ARRAY, ACCESS] + extra_indices, **kwargs)
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
intrinsic("image_" + name, src_comp=[1] + src_comp,
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
intrinsic("bindless_image_" + name, src_comp=[1] + src_comp,

View file

@ -559,9 +559,13 @@ vectorized_intrinsic(nir_intrinsic_instr *intr)
static enum pipe_format
image_intrin_format(nir_intrinsic_instr *instr)
{
if (nir_intrinsic_has_format(instr))
if (nir_intrinsic_format(instr) != PIPE_FORMAT_NONE)
return nir_intrinsic_format(instr);
/* If this not a deref intrinsic, PIPE_FORMAT_NONE is the best we can do */
if (nir_intrinsic_infos[instr->intrinsic].src_components[0] != -1)
return PIPE_FORMAT_NONE;
nir_variable *var = nir_intrinsic_get_var(instr, 0);
if (var == NULL)
return PIPE_FORMAT_COUNT;