radeonsi: determine the rasterization primitive type accurately (v2)
authorMarek Olšák <marek.olsak@amd.com>
Tue, 25 Jun 2019 00:54:52 +0000 (20:54 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 3 Jul 2019 19:51:13 +0000 (15:51 -0400)
v2: reworked version to fix bugs and make it more efficient

Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/gallium/drivers/radeonsi/si_pipe.h
src/gallium/drivers/radeonsi/si_shader.h
src/gallium/drivers/radeonsi/si_state_draw.c
src/gallium/drivers/radeonsi/si_state_shaders.c

index 298e63738c47eb44ad94ad4cb2f1341dc44be3c3..01a0ede4126c2cc04d48734b88e5a4df27271ba9 100644 (file)
@@ -1787,6 +1787,18 @@ static inline bool util_prim_is_points_or_lines(unsigned prim)
                               (1 << PIPE_PRIM_POINTS))) != 0;
 }
 
+static inline bool util_rast_prim_is_triangles(unsigned prim)
+{
+       return ((1 << prim) & ((1 << PIPE_PRIM_TRIANGLES) |
+                              (1 << PIPE_PRIM_TRIANGLE_STRIP) |
+                              (1 << PIPE_PRIM_TRIANGLE_FAN) |
+                              (1 << PIPE_PRIM_QUADS) |
+                              (1 << PIPE_PRIM_QUAD_STRIP) |
+                              (1 << PIPE_PRIM_POLYGON) |
+                              (1 << PIPE_PRIM_TRIANGLES_ADJACENCY) |
+                              (1 << PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY)));
+}
+
 /**
  * Return true if there is enough memory in VRAM and GTT for the buffers
  * added so far.
index 2649a7cd5b7496062e72c7fc6e937040f5971544..86d91f29b3c431513c9949db6eea807381db4fb1 100644 (file)
@@ -354,6 +354,7 @@ struct si_shader_selector {
        unsigned        pa_cl_vs_out_cntl;
        ubyte           clipdist_mask;
        ubyte           culldist_mask;
+       unsigned        rast_prim;
 
        /* ES parameters. */
        unsigned        esgs_itemsize; /* vertex stride */
index fdde6b08310ef1a4f7dc0048a9ee733c7bcfd7fc..04bf391524b15916a3b1d0ff90576c76636edbc7 100644 (file)
@@ -1787,15 +1787,18 @@ static void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *i
         * This must be done after si_decompress_textures, which can call
         * draw_vbo recursively, and before si_update_shaders, which uses
         * current_rast_prim for this draw_vbo call. */
-       if (sctx->gs_shader.cso)
-               rast_prim = sctx->gs_shader.cso->gs_output_prim;
-       else if (sctx->tes_shader.cso) {
-               if (sctx->tes_shader.cso->info.properties[TGSI_PROPERTY_TES_POINT_MODE])
-                       rast_prim = PIPE_PRIM_POINTS;
-               else
-                       rast_prim = sctx->tes_shader.cso->info.properties[TGSI_PROPERTY_TES_PRIM_MODE];
-       } else
+       if (sctx->gs_shader.cso) {
+               /* Only possibilities: POINTS, LINE_STRIP, TRIANGLES */
+               rast_prim = sctx->gs_shader.cso->rast_prim;
+       } else if (sctx->tes_shader.cso) {
+               /* Only possibilities: POINTS, LINE_STRIP, TRIANGLES */
+               rast_prim = sctx->tes_shader.cso->rast_prim;
+       } else if (util_rast_prim_is_triangles(prim)) {
+               rast_prim = PIPE_PRIM_TRIANGLES;
+       } else {
+               /* Only possibilities, POINTS, LINE*, RECTANGLES */
                rast_prim = prim;
+       }
 
        if (rast_prim != sctx->current_rast_prim) {
                if (util_prim_is_points_or_lines(sctx->current_rast_prim) !=
index b673c6d73fc7026d8eea64fe1c0614c3245d4157..44abc186d168860e6841cfd3b24144bd69fbaa18 100644 (file)
@@ -2670,6 +2670,12 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
        case PIPE_SHADER_GEOMETRY:
                sel->gs_output_prim =
                        sel->info.properties[TGSI_PROPERTY_GS_OUTPUT_PRIM];
+
+               /* Only possibilities: POINTS, LINE_STRIP, TRIANGLES */
+               sel->rast_prim = sel->gs_output_prim;
+               if (util_rast_prim_is_triangles(sel->rast_prim))
+                       sel->rast_prim = PIPE_PRIM_TRIANGLES;
+
                sel->gs_max_out_vertices =
                        sel->info.properties[TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES];
                sel->gs_num_invocations =
@@ -2738,6 +2744,14 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
                        sel->esgs_itemsize += 4;
 
                assert(((sel->esgs_itemsize / 4) & C_028AAC_ITEMSIZE) == 0);
+
+               /* Only for TES: */
+               if (sel->info.properties[TGSI_PROPERTY_TES_POINT_MODE])
+                       sel->rast_prim = PIPE_PRIM_POINTS;
+               else if (sel->info.properties[TGSI_PROPERTY_TES_PRIM_MODE] == PIPE_PRIM_LINES)
+                       sel->rast_prim = PIPE_PRIM_LINE_STRIP;
+               else
+                       sel->rast_prim = PIPE_PRIM_TRIANGLES;
                break;
 
        case PIPE_SHADER_FRAGMENT: