Mesa (review/nir-image-intrin-indices): nir: Add a format field to _deref image intrinsics

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 13 13:49:39 UTC 2021


Module: Mesa
Branch: review/nir-image-intrin-indices
Commit: 9b428649a80ebeef7348c615653de7b66987ea11
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9b428649a80ebeef7348c615653de7b66987ea11

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Mon Jul 12 09:38:38 2021 -0500

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.

---

 src/compiler/nir/nir.c             | 5 ++++-
 src/compiler/nir/nir_intrinsics.py | 2 +-
 src/compiler/nir/nir_validate.c    | 6 +++++-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 0fcb4d8ba8b..79d03a7e9bb 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -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))
diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py
index 46413badff1..bb79257e38d 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -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,
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 825a46a5999..64af1e86078 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -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;



More information about the mesa-commit mailing list