draw/clip: fix viewport index for geometry shaders
authorDave Airlie <airlied@redhat.com>
Thu, 2 Jul 2020 05:37:16 +0000 (15:37 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 3 Jul 2020 21:19:08 +0000 (07:19 +1000)
The old code updated the viewport index on the first vertex in
a primitive, however it was picking the first vertex wrong
when used with geometry shaders.

This code has access to the prim info with the primitive lengths
so instead keep track of when a new primitive starts by tracking
the lengths and updating the viewport index then. The prim info
is only valid after a GS or prim assembly, so enable prim assembly
if a vertex shader ever uses viewport index.

This fixes:
piglit arb_viewport_array-render-viewport-2
KHR-GLES31.core.viewport_array.draw_to_single_layer_with_multiple_viewports,Fail
KHR-GLES31.core.viewport_array.draw_mulitple_viewports_with_single_invocation,Fail
KHR-GLES31.core.viewport_array.draw_multiple_layers,Fail
KHR-GLES31.core.viewport_array.depth_range,Fail

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5489>

.gitlab-ci/piglit/quick_gl.txt
src/gallium/auxiliary/draw/draw_cliptest_tmp.h
src/gallium/auxiliary/draw/draw_prim_assembler.c

index bc50f08f0f60a5aad8a1f226c669fe6ea32ed86f..6c9f2d8f56113c6a335a76761d1b159bba0cdceb 100644 (file)
@@ -901,7 +901,6 @@ spec/arb_vertex_program/vp-address-02: skip
 spec/arb_vertex_program/vp-address-04: skip
 spec/arb_vertex_type_2_10_10_10_rev/attrib-p-type-size-match: skip
 spec/arb_viewport_array/display-list: skip
-spec/arb_viewport_array/render-viewport-2: fail
 spec/ati_envmap_bumpmap/ati_envmap_bumpmap-bump: skip
 spec/egl 1.4/egl-blob-cache: skip
 spec/egl 1.4/egl-context-priority: skip
@@ -1681,15 +1680,14 @@ spec/oes_texture_view/rendering-formats/render to gl_rgb8ui as gl_rgb8i: skip
 spec/oes_texture_view/rendering-formats/render to gl_rgb8ui as gl_rgb8ui: skip
 spec/oes_texture_view/texsubimage-layers pbo: skip
 spec/oes_texture_view/texsubimage-levels pbo: skip
-spec/oes_viewport_array/render-viewport-2: fail
 wgl/wgl-multi-context-single-window: skip
 wgl/wgl-multi-window-single-context: skip
 wgl/wgl-sanity: skip
 summary:
        name:  results
        ----  --------
-       pass:    21837
-       fail:      217
+       pass:    21839
+       fail:      215
       crash:        0
        skip:     1446
     timeout:        0
index ba02461db482873f4c15b65bc4e299fc59941707..b7c77bfd85d891776dea17775534dfd36b8d567a 100644 (file)
@@ -49,7 +49,6 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
    int viewport_index = 0;
    int num_written_clipdistance =
       draw_current_shader_num_written_clipdistances(pvs->draw);
-   unsigned verts_per_prim = u_vertices_per_prim(prim_info->prim);
 
    if (uses_vp_idx) {
       viewport_index = u_bitcast_f2u(out->data[viewport_index_output][0]);
@@ -70,16 +69,20 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
    }
 
    assert(pos != -1);
+   unsigned prim_idx = 0, prim_vert_idx = 0;
    for (j = 0; j < info->count; j++) {
       float *position = out->data[pos];
       unsigned mask = 0x0;
 
       if (uses_vp_idx) {
          /* only change the viewport_index for the leading vertex */
-         if (!(j % verts_per_prim)) {
+         if (prim_vert_idx == (prim_info->primitive_lengths[prim_idx])) {
+            prim_idx++;
+            prim_vert_idx = 0;
             viewport_index = u_bitcast_f2u(out->data[viewport_index_output][0]);
             viewport_index = draw_clamp_viewport_idx(viewport_index);
          }
+         prim_vert_idx++;
       }
       float *scale = pvs->draw->viewports[viewport_index].scale;
       float *trans = pvs->draw->viewports[viewport_index].translate;
index c0bc145f38bcce7c605e6f00021614c7df7ab3c4..edaaf0d501f33252249b9aeff347d9bb23759bdf 100644 (file)
@@ -76,6 +76,9 @@ draw_prim_assembler_is_required(const struct draw_context *draw,
                                 const struct draw_prim_info *prim_info,
                                 const struct draw_vertex_info *vert_info)
 {
+   /* viewport index requires primitive boundaries to get correct vertex */
+   if (draw_current_shader_uses_viewport_index(draw))
+      return TRUE;
    switch (prim_info->prim) {
    case PIPE_PRIM_LINES_ADJACENCY:
    case PIPE_PRIM_LINE_STRIP_ADJACENCY: