nir/spirv: Add the option to keep ViewIndex as an input
authorConnor Abbott <cwabbott0@gmail.com>
Tue, 30 Jun 2020 11:47:22 +0000 (13:47 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 19 Aug 2020 16:36:43 +0000 (16:36 +0000)
This is necessary for fragment shaders on adreno.

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

src/compiler/spirv/nir_spirv.h
src/compiler/spirv/vtn_variables.c

index 3d6f74e..3cbd026 100644 (file)
@@ -64,6 +64,10 @@ struct spirv_to_nir_options {
     */
    bool frag_coord_is_sysval;
 
+   /* Whether to keep ViewIndex as an input instead of rewriting to a sysval.
+    */
+   bool view_index_is_input;
+
    struct spirv_supported_capabilities caps;
 
    /* Address format for various kinds of pointers. */
index 1cb848a..a7ccafd 100644 (file)
@@ -1436,8 +1436,13 @@ vtn_get_builtin_location(struct vtn_builder *b,
       set_mode_system_value(b, mode);
       break;
    case SpvBuiltInViewIndex:
-      *location = SYSTEM_VALUE_VIEW_INDEX;
-      set_mode_system_value(b, mode);
+      if (b->options && b->options->view_index_is_input) {
+         *location = VARYING_SLOT_VIEW_INDEX;
+         vtn_assert(*mode == nir_var_shader_in);
+      } else {
+         *location = SYSTEM_VALUE_VIEW_INDEX;
+         set_mode_system_value(b, mode);
+      }
       break;
    case SpvBuiltInSubgroupEqMask:
       *location = SYSTEM_VALUE_SUBGROUP_EQ_MASK,