draw: account primitive lengths for all streams.
authorDave Airlie <airlied@redhat.com>
Fri, 19 Jun 2020 05:04:19 +0000 (15:04 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 7 Jul 2020 20:06:05 +0000 (06:06 +1000)
For correct XFB queries all streams must get primitive lengths
recorded. This allocates larger memory for per-stream lengths
and the shader write into them.

Fixes:
GTF-GL41.gtf40.GL3Tests.transform_feedback3.transform_feedback3_streams_queried
GTF-GL41.gtf40.GL3Tests.transform_feedback3.transform_feedback3_streams_overflow

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

src/gallium/auxiliary/draw/draw_gs.c
src/gallium/auxiliary/draw/draw_llvm.c

index f701e82b0561f8772e89b45b78119faa08afa64b..f648a96db7b785f3d564cb081764247458514680 100644 (file)
@@ -380,7 +380,7 @@ llvm_fetch_gs_outputs(struct draw_geometry_shader *shader,
       int num_prims = shader->llvm_emitted_primitives[i + (stream * shader->vector_length)];
       for (j = 0; j < num_prims; ++j) {
          int prim_length =
-            shader->llvm_prim_lengths[j][i];
+            shader->llvm_prim_lengths[j * shader->num_vertex_streams + stream][i];
          shader->stream[stream].primitive_lengths[shader->stream[stream].emitted_primitives + prim_idx] =
             prim_length;
          ++prim_idx;
@@ -645,14 +645,14 @@ int draw_geometry_shader_run(struct draw_geometry_shader *shader,
       if (max_out_prims > shader->max_out_prims) {
          unsigned i;
          if (shader->llvm_prim_lengths) {
-            for (i = 0; i < shader->max_out_prims; ++i) {
+            for (i = 0; i < shader->num_vertex_streams * shader->max_out_prims; ++i) {
                align_free(shader->llvm_prim_lengths[i]);
             }
             FREE(shader->llvm_prim_lengths);
          }
 
-         shader->llvm_prim_lengths = MALLOC(max_out_prims * sizeof(unsigned*));
-         for (i = 0; i < max_out_prims; ++i) {
+         shader->llvm_prim_lengths = MALLOC(shader->num_vertex_streams * max_out_prims * sizeof(unsigned*));
+         for (i = 0; i < shader->num_vertex_streams * max_out_prims; ++i) {
             int vector_size = shader->vector_length * sizeof(unsigned);
             shader->llvm_prim_lengths[i] =
                align_malloc(vector_size, vector_size);
@@ -948,7 +948,7 @@ void draw_delete_geometry_shader(struct draw_context *draw,
 
       if (dgs->llvm_prim_lengths) {
          unsigned i;
-         for (i = 0; i < dgs->max_out_prims; ++i) {
+         for (i = 0; i < dgs->num_vertex_streams * dgs->max_out_prims; ++i) {
             align_free(dgs->llvm_prim_lengths[i]);
          }
          FREE(dgs->llvm_prim_lengths);
index 49abd6434c772dd5d5f083e287af8f96dbc86ace..862c570efbfb52ccab19d3c8399e109ff11cd485 100644 (file)
@@ -1850,6 +1850,8 @@ draw_gs_llvm_end_primitive(const struct lp_build_gs_iface *gs_base,
       LLVMValueRef this_cond = LLVMBuildExtractElement(gallivm->builder, cond, ind, "");
       struct lp_build_if_state ifthen;
       lp_build_if(&ifthen, gallivm, this_cond);
+      prims_emitted = LLVMBuildMul(gallivm->builder, prims_emitted, lp_build_const_int32(gallivm, variant->shader->base.num_vertex_streams), "");
+      prims_emitted = LLVMBuildAdd(gallivm->builder, prims_emitted, lp_build_const_int32(gallivm, stream), "");
       store_ptr = LLVMBuildGEP(builder, prim_lengts_ptr, &prims_emitted, 1, "");
       store_ptr = LLVMBuildLoad(builder, store_ptr, "");
       store_ptr = LLVMBuildGEP(builder, store_ptr, &ind, 1, "");