draw/so: Fix stream output with geometry shaders
authorZack Rusin <zackr@vmware.com>
Tue, 12 Mar 2013 20:41:35 +0000 (13:41 -0700)
committerZack Rusin <zackr@vmware.com>
Tue, 12 Mar 2013 23:22:26 +0000 (16:22 -0700)
If geometry shader is present its stream output info should
be used instead of the vs and we shouldn't use the pre-clipped
corrdinates.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
src/gallium/auxiliary/draw/draw_pt_so_emit.c

index 5fc94364b4ee1b351c2d3c9eed13ff7271909a51..288b5242ae8769215c713e098d49c17dcbf9dafd 100644 (file)
@@ -102,7 +102,7 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
                            (boolean)draw->rasterizer->gl_rasterization_rules,
                            (draw->vs.edgeflag_output ? TRUE : FALSE) );
 
-   draw_pt_so_emit_prepare( fpme->so_emit, TRUE );
+   draw_pt_so_emit_prepare( fpme->so_emit, gs == NULL );
 
    if (!(opt & PT_PIPELINE)) {
       draw_pt_emit_prepare( fpme->emit,
index 13d8470e4ecb900e093155e6c5f9e86097f87e8d..64ed5441e7c8615e30bd6acff4af06e8a4471ab0 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "draw/draw_private.h"
 #include "draw/draw_vs.h"
+#include "draw/draw_gs.h"
 #include "draw/draw_context.h"
 #include "draw/draw_vbuf.h"
 #include "draw/draw_vertex.h"
@@ -51,13 +52,37 @@ struct pt_so_emit {
    unsigned generated_primitives;
 };
 
+static const struct pipe_stream_output_info *
+draw_so_info(const struct draw_context *draw)
+{
+   const struct pipe_stream_output_info *state = NULL;
+
+   if (draw->gs.geometry_shader) {
+      state = &draw->gs.geometry_shader->state.stream_output;
+   } else {
+      state = &draw->vs.vertex_shader->state.stream_output;
+   }
+
+   return state;
+}
+
+static INLINE boolean
+draw_has_so(const struct draw_context *draw)
+{
+   const struct pipe_stream_output_info *state = draw_so_info(draw);
+
+   if (state && state->num_outputs > 0)
+      return TRUE;
+
+   return FALSE;
+}
 
 void draw_pt_so_emit_prepare(struct pt_so_emit *emit, boolean use_pre_clip_pos)
 {
    struct draw_context *draw = emit->draw;
 
    emit->use_pre_clip_pos = use_pre_clip_pos;
-   emit->has_so = (draw->vs.vertex_shader->state.stream_output.num_outputs > 0);
+   emit->has_so = draw_has_so(draw);
    if (use_pre_clip_pos)
       emit->pos_idx = draw_current_shader_position_output(draw);
 
@@ -92,8 +117,7 @@ static void so_emit_prim(struct pt_so_emit *so,
    struct draw_context *draw = so->draw;
    const float (*input_ptr)[4];
    const float (*pcp_ptr)[4] = NULL;
-   const struct pipe_stream_output_info *state =
-      &draw->vs.vertex_shader->state.stream_output;
+   const struct pipe_stream_output_info *state = draw_so_info(draw);
    float *buffer;
    int buffer_total_bytes[PIPE_MAX_SO_BUFFERS];
 
@@ -125,9 +149,8 @@ static void so_emit_prim(struct pt_so_emit *so,
    for (i = 0; i < num_vertices; ++i) {
       const float (*input)[4];
       const float (*pre_clip_pos)[4];
-      unsigned total_written_compos = 0;
       int ob;
-      /*debug_printf("%d) vertex index = %d (prim idx = %d)\n", i, indices[i], prim_idx);*/
+
       input = (const float (*)[4])(
          (const char *)input_ptr + (indices[i] * input_vertex_stride));
 
@@ -145,11 +168,11 @@ static void so_emit_prim(struct pt_so_emit *so,
          buffer = (float *)((char *)draw->so.targets[ob]->mapping +
                             draw->so.targets[ob]->target.buffer_offset +
                             draw->so.targets[ob]->internal_offset) + state->output[slot].dst_offset;
+         
          if (idx == so->pos_idx && pcp_ptr)
-            memcpy(buffer, &pre_clip_pos[start_comp], num_comps * sizeof(float));
+            memcpy(buffer, &pre_clip_pos[idx][start_comp], num_comps * sizeof(float));
          else
             memcpy(buffer, &input[idx][start_comp], num_comps * sizeof(float));
-         total_written_compos += num_comps;
       }
       for (ob = 0; ob < draw->so.num_targets; ++ob)
          draw->so.targets[ob]->internal_offset += state->stride[ob] * sizeof(float);