draw/gs: fix emitting inactive primitives crash
authorDave Airlie <airlied@redhat.com>
Mon, 8 Jun 2020 07:02:11 +0000 (17:02 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 11 Jun 2020 04:40:57 +0000 (14:40 +1000)
Fixes dEQP-GLES31.functional.geometry_shading.emit.line_strip_emit_1_end_1

This test only emits 1 primitive, but the stores don't respect
the current mask, which might only have one lane active, for that single
primitive. Also fix the final emit path to use the emitted_mask
rather than the current execution mask.

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

src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c

index d4e0838bb57de328ba043f547394af801e18548a..9fa9c7b2833ace1b4b2651f0afa11bf25066202c 100644 (file)
@@ -1838,6 +1838,7 @@ draw_gs_llvm_end_primitive(const struct lp_build_gs_iface *gs_base,
       draw_gs_jit_prim_lengths(variant->gallivm, variant->context_ptr);
    unsigned i;
 
+   LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntNE, mask_vec, lp_build_const_int_vec(gallivm, bld->type, 0), "");
    for (i = 0; i < bld->type.length; ++i) {
       LLVMValueRef ind = lp_build_const_int32(gallivm, i);
       LLVMValueRef prims_emitted =
@@ -1846,10 +1847,14 @@ draw_gs_llvm_end_primitive(const struct lp_build_gs_iface *gs_base,
       LLVMValueRef num_vertices =
          LLVMBuildExtractElement(builder, verts_per_prim_vec, ind, "");
 
+      LLVMValueRef this_cond = LLVMBuildExtractElement(gallivm->builder, cond, ind, "");
+      struct lp_build_if_state ifthen;
+      lp_build_if(&ifthen, gallivm, this_cond);
       store_ptr = LLVMBuildGEP(builder, prim_lengts_ptr, &prims_emitted, 1, "");
       store_ptr = LLVMBuildLoad(builder, store_ptr, "");
       store_ptr = LLVMBuildGEP(builder, store_ptr, &ind, 1, "");
       LLVMBuildStore(builder, num_vertices, store_ptr);
+      lp_build_endif(&ifthen);
    }
 }
 
index 09ba52935461434e0fcca6daca4ceee28142b5b2..542fd02565c72dfde64ca863ad84a2f837d3f31d 100644 (file)
@@ -1555,7 +1555,7 @@ end_primitive_masked(struct lp_build_nir_context * bld_base,
    if (stream_id == 0)
       bld->gs_iface->end_primitive(bld->gs_iface, &bld->bld_base.base,
                                    total_emitted_vertices_vec,
-                                   emitted_vertices_vec, emitted_prims_vec, mask_vec(bld_base));
+                                   emitted_vertices_vec, emitted_prims_vec, mask);
    increment_vec_ptr_by_mask(bld_base, bld->emitted_prims_vec_ptr[stream_id],
                              mask);
    clear_uint_vec_ptr_from_mask(bld_base, bld->emitted_vertices_vec_ptr[stream_id],