nir/lower_input_attachments: Support loading layer id via gl_ViewIndex
authorConnor Abbott <cwabbott0@gmail.com>
Wed, 1 Jul 2020 15:29:45 +0000 (17:29 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 19 Aug 2020 16:36:43 +0000 (16:36 +0000)
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
src/compiler/nir/nir_lower_input_attachments.c

index 6cf704c533bc865f7d7dea9bb8637897e744f6ac..5804670fb9902ee31b6bb087043b945dab97a692 100644 (file)
@@ -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,
index 8533eb4a1f2fde3f005f19b9716914929de3c368..3a3500a0bcd13d6ab44ea7754c6d6bf48b3d9ff0 100644 (file)
@@ -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++;
    }