pan/bi: Lower gl_VertexID in NIR
authorAlyssa Rosenzweig <alyssa@collabora.com>
Mon, 6 Feb 2023 15:49:54 +0000 (10:49 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 23 Mar 2023 23:53:45 +0000 (23:53 +0000)
This gets rid of the hidden gl_BaseVertex system value which violates Ekstrand's
rule.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20906>

src/panfrost/compiler/bifrost_compile.c
src/panfrost/compiler/bifrost_compile.h
src/panfrost/lib/pan_shader.c

index 61026c2..8a4b0eb 100644 (file)
@@ -1837,26 +1837,14 @@ bi_emit_intrinsic(bi_builder *b, nir_intrinsic_instr *instr)
       break;
 
    /* It appears vertex_id is zero-based with Bifrost geometry flows, but
-    * not with Valhall's memory-allocation IDVS geometry flow. Ostensibly
-    * we support the legacy geometry flow even on Valhall, so
-    * vertex_id_zero_based isn't a machine property for us. Don't set it,
-    * and lower here if needed.
+    * not with Valhall's memory-allocation IDVS geometry flow. We only support
+    * the new flow on Valhall so this is lowered in NIR.
     */
    case nir_intrinsic_load_vertex_id:
-      if (b->shader->malloc_idvs) {
-         bi_mov_i32_to(b, dst, bi_vertex_id(b));
-      } else {
-         bi_index first =
-            bi_load_sysval(b, PAN_SYSVAL_VERTEX_INSTANCE_OFFSETS, 1, 0);
-
-         bi_iadd_u32_to(b, dst, bi_vertex_id(b), first, false);
-      }
-
-      break;
-
-   /* We only use in our transform feedback lowering */
    case nir_intrinsic_load_vertex_id_zero_base:
-      assert(b->shader->nir->info.has_transform_feedback_varyings);
+      assert(b->shader->malloc_idvs ==
+             (instr->intrinsic == nir_intrinsic_load_vertex_id));
+
       bi_mov_i32_to(b, dst, bi_vertex_id(b));
       break;
 
index 86f966f..bcb1c83 100644 (file)
@@ -55,6 +55,12 @@ void bifrost_compile_shader_nir(nir_shader *nir,
       .lower_insert_byte = true,                                               \
       .lower_rotate = true,                                                    \
                                                                                \
+      /* Vertex ID is zero based in the traditional geometry flows, but not in \
+       * the memory-allocated IDVS flow introduced and used exclusively in     \
+       * Valhall. So this is a machine property for us.                        \
+       */                                                                      \
+      .vertex_id_zero_based = (arch <= 7),                                     \
+                                                                               \
       .lower_pack_half_2x16 = true,                                            \
       .lower_pack_unorm_2x16 = true,                                           \
       .lower_pack_snorm_2x16 = true,                                           \
@@ -97,5 +103,6 @@ void bifrost_compile_shader_nir(nir_shader *nir,
    };
 
 DEFINE_OPTIONS(6);
+DEFINE_OPTIONS(9);
 
 #endif
index 1fe8491..eb683de 100644 (file)
@@ -35,7 +35,9 @@
 const nir_shader_compiler_options *
 GENX(pan_shader_get_compiler_options)(void)
 {
-#if PAN_ARCH >= 6
+#if PAN_ARCH >= 9
+   return &bifrost_nir_options_v9;
+#elif PAN_ARCH >= 6
    return &bifrost_nir_options_v6;
 #else
    return &midgard_nir_options;