nir: handle primitives with adjacency
authorantonino <antonino.maniscalco@collabora.com>
Mon, 13 Feb 2023 11:57:38 +0000 (12:57 +0100)
committerMarge Bot <emma+marge@anholt.net>
Wed, 29 Mar 2023 19:18:39 +0000 (19:18 +0000)
`nir_create_passthrough_gs` can now handle primitives with adjacency where some
vertices need to be skipped.

Fixes: d0342e28b32 ("nir: Add helper to create passthrough GS shader")
Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21238>

src/compiler/nir/nir_passthrough_gs.c

index b13b890..4ba4f2c 100644 (file)
@@ -89,7 +89,25 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options,
       out_vars[num_vars++] = out;
    }
 
-   for (unsigned i = 0; i < vertices; ++i) {
+   unsigned int start_vert = 0;
+   unsigned int end_vert = vertices;
+   unsigned int vert_step = 1;
+   switch (primitive_type) {
+   case PIPE_PRIM_LINES_ADJACENCY:
+   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
+      start_vert = 1;
+      end_vert += 1;
+      break;
+   case PIPE_PRIM_TRIANGLES_ADJACENCY:
+   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
+      end_vert = 5;
+      vert_step = 2;
+      break;
+   default:
+      break;
+   }
+
+   for (unsigned i = start_vert; i < end_vert; i += vert_step) {
       /* Copy inputs to outputs. */
       for (unsigned j = 0; j < num_vars; ++j) {
          /* no need to use copy_var to save a lower pass */