Mesa (master): nir/lower_input_attachments: Support loading layer id via gl_ViewIndex

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 19 16:55:20 UTC 2020


Module: Mesa
Branch: master
Commit: c1a6e345739b83cc0ae386f455246caee3e06ffe
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c1a6e345739b83cc0ae386f455246caee3e06ffe

Author: Connor Abbott <cwabbott0 at gmail.com>
Date:   Wed Jul  1 17:29:45 2020 +0200

nir/lower_input_attachments: Support loading layer id via gl_ViewIndex

This is required on adreno when the special multiview mode is switched
on.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5719>

---

 src/compiler/nir/nir.h                         |  1 +
 src/compiler/nir/nir_lower_input_attachments.c | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 6cf704c533b..5804670fb99 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4461,6 +4461,7 @@ bool nir_lower_idiv(nir_shader *shader, enum nir_lower_idiv_path path);
 typedef struct nir_input_attachment_options {
    bool use_fragcoord_sysval;
    bool use_layer_id_sysval;
+   bool use_view_id_for_layer;
 } nir_input_attachment_options;
 
 bool nir_lower_input_attachments(nir_shader *shader,
diff --git a/src/compiler/nir/nir_lower_input_attachments.c b/src/compiler/nir/nir_lower_input_attachments.c
index 8533eb4a1f2..3a3500a0bcd 100644
--- a/src/compiler/nir/nir_lower_input_attachments.c
+++ b/src/compiler/nir/nir_lower_input_attachments.c
@@ -53,17 +53,22 @@ load_frag_coord(const nir_input_attachment_options *options, nir_builder *b)
 static nir_ssa_def *
 load_layer_id(const nir_input_attachment_options *options, nir_builder *b)
 {
-   if (options->use_layer_id_sysval)
-      return nir_load_layer_id(b);
+   if (options->use_layer_id_sysval) {
+      if (options->use_view_id_for_layer)
+         return nir_load_view_index(b);
+      else
+         return nir_load_layer_id(b);
+   }
 
+   gl_varying_slot slot = options->use_view_id_for_layer ?
+      VARYING_SLOT_VIEW_INDEX : VARYING_SLOT_LAYER;
    nir_variable *layer_id =
-      nir_find_variable_with_location(b->shader, nir_var_shader_in,
-                                      VARYING_SLOT_LAYER);
+      nir_find_variable_with_location(b->shader, nir_var_shader_in, slot);
 
    if (layer_id == NULL) {
       layer_id = nir_variable_create(b->shader, nir_var_shader_in,
                                      glsl_int_type(), NULL);
-      layer_id->data.location = VARYING_SLOT_LAYER;
+      layer_id->data.location = slot;
       layer_id->data.interpolation = INTERP_MODE_FLAT;
       layer_id->data.driver_location = b->shader->num_inputs++;
    }



More information about the mesa-commit mailing list