draw: fixes for vertex shaders outputting layer or viewport index
authorRoland Scheidegger <sroland@vmware.com>
Tue, 18 Nov 2014 21:46:00 +0000 (22:46 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Wed, 19 Nov 2014 17:35:30 +0000 (18:35 +0100)
Mostly add a couple cases so we don't just check gs for this.
There's only one gotcha, the built-in vp transform in the llvm vs can't
handle it (this would be fixable though non-trivial due to vp index being
non-constant for the SoA outputs, but we don't use it if there's a gs
neither - the whole clip/vp transform integration there is suboptimal).

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
src/gallium/auxiliary/draw/draw_pt_post_vs.c
src/gallium/auxiliary/draw/draw_vs.c
src/gallium/auxiliary/draw/draw_vs.h
src/gallium/auxiliary/tgsi/tgsi_scan.c

index bb8c03c36f9dfe677b3b02ad01fb86f1f7ab0747..f46f8b42038f903b1bda145cd1bebd9891740d2a 100644 (file)
@@ -806,7 +806,7 @@ draw_current_shader_viewport_index_output(const struct draw_context *draw)
 {
    if (draw->gs.geometry_shader)
       return draw->gs.geometry_shader->viewport_index_output;
-   return 0;
+   return draw->vs.vertex_shader->viewport_index_output;
 }
 
 /**
@@ -818,7 +818,7 @@ draw_current_shader_uses_viewport_index(const struct draw_context *draw)
 {
    if (draw->gs.geometry_shader)
       return draw->gs.geometry_shader->info.writes_viewport_index;
-   return FALSE;
+   return draw->vs.vertex_shader->info.writes_viewport_index;
 }
 
 
index 1c2656036630aa557846d603e9d27c5408c4633d..a2e6112009ae4718b5c161555067ce53ee361474 100644 (file)
@@ -1522,8 +1522,12 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant,
    /* If geometry shader is present we need to skip both the viewport
     * transformation and clipping otherwise the inputs to the geometry
     * shader will be incorrect.
+    * The code can't handle vp transform when vs writes vp index neither
+    * (though this would be fixable here, but couldn't just broadcast
+    * the values).
     */
-   const boolean bypass_viewport = key->has_gs || key->bypass_viewport;
+   const boolean bypass_viewport = key->has_gs || key->bypass_viewport ||
+                                   llvm->draw->vs.vertex_shader->info.writes_viewport_index;
    const boolean enable_cliptest = !key->has_gs && (key->clip_xy ||
                                                     key->clip_z  ||
                                                     key->clip_user);
index 49341ffd9fd54eb1fd257be7aed62419cd5edb87..cc837366ae970554ea1570b7109668af96779d6e 100644 (file)
@@ -169,8 +169,7 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
    draw_pt_so_emit_prepare( fpme->so_emit, gs == NULL );
 
    if (!(opt & PT_PIPELINE)) {
-      draw_pt_emit_prepare( fpme->emit,
-                           out_prim,
+      draw_pt_emit_prepare( fpme->emit, out_prim,
                             max_vertices );
 
       *max_vertices = MAX2( *max_vertices, 4096 );
@@ -442,7 +441,8 @@ llvm_pipeline_generic(struct draw_pt_middle_end *middle,
     * will try to access non-existent position output.
     */
    if (draw_current_shader_position_output(draw) != -1) {
-      if ((opt & PT_SHADE) && gshader) {
+      if ((opt & PT_SHADE) && (gshader ||
+                               draw->vs.vertex_shader->info.writes_viewport_index)) {
          clipped = draw_pt_post_vs_run( fpme->post_vs, vert_info, prim_info );
       }
       if (clipped) {
index 9279cd176134afae8b0b14aaf6ec95646a3bf0a2..71a7d3918e920bfcb4d596e4a371d8481a93346f 100644 (file)
@@ -117,7 +117,7 @@ dot4(const float *a, const float *b)
 
 
 boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,
-                            struct draw_vertex_info *info,
+                             struct draw_vertex_info *info,
                              const struct draw_prim_info *prim_info )
 {
    return pvs->run( pvs, info, prim_info );
index dc50870b267f645979da70e1f50147a2bc40d0c0..f24354e9d5164f906f09bc80ba92fe90e5413df0 100644 (file)
@@ -85,7 +85,9 @@ draw_create_vertex_shader(struct draw_context *draw,
                   vs->info.output_semantic_index[i] == 0) {
             found_clipvertex = TRUE;
             vs->clipvertex_output = i;
-         } else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_CLIPDIST) {
+         } else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_VIEWPORT_INDEX)
+            vs->viewport_index_output = i;
+         else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_CLIPDIST) {
             debug_assert(vs->info.output_semantic_index[i] <
                          PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT);
             vs->clipdistance_output[vs->info.output_semantic_index[i]] = i;
index 79dbfb715493ff4958152f563da02338add375c4..1d54e7ef2989f907e952b105364267198dadb5e3 100644 (file)
@@ -110,6 +110,7 @@ struct draw_vertex_shader {
 
    struct tgsi_shader_info info;
    unsigned position_output;
+   unsigned viewport_index_output;
    unsigned edgeflag_output;
    unsigned clipvertex_output;
    unsigned clipdistance_output[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT];
index 42bc61eeb4c4ea0f58608e5ec4416fc132fd6e09..a23bb4067aa005a1ca343cee70561efbd887acf4 100644 (file)
@@ -232,6 +232,12 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
                         info->num_written_culldistance +=
                            util_bitcount(fulldecl->Declaration.UsageMask);
                      }
+                     else if (semName == TGSI_SEMANTIC_VIEWPORT_INDEX) {
+                        info->writes_viewport_index = TRUE;
+                     }
+                     else if (semName == TGSI_SEMANTIC_LAYER) {
+                        info->writes_layer = TRUE;
+                     }
                   }
 
                   if (procType == TGSI_PROCESSOR_FRAGMENT) {
@@ -248,15 +254,6 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
                         info->writes_edgeflag = TRUE;
                      }
                   }
-
-                  if (procType == TGSI_PROCESSOR_GEOMETRY) {
-                     if (semName == TGSI_SEMANTIC_VIEWPORT_INDEX) {
-                        info->writes_viewport_index = TRUE;
-                     }
-                     else if (semName == TGSI_SEMANTIC_LAYER) {
-                        info->writes_layer = TRUE;
-                     }
-                  }
                }
             }
          }