gallivm: fix stream id fetch
authorRoland Scheidegger <sroland@vmware.com>
Thu, 2 Apr 2020 05:09:50 +0000 (07:09 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 2 Apr 2020 15:53:23 +0000 (15:53 +0000)
Fetching the stream id directly can crash since bld->immediates may not
exist (if there's too many immediates or we use the array due to indirect
accesses). So just call emit_fetch_immediate instead.

v2: fix the swizzle

Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4416>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4416>

src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c

index 0ab1aa1fe0212d228c7bd86f2f8750afe9b44120..67c7cc7b27054b0b4083d9999b9ad2c71c5a1ecb 100644 (file)
@@ -3946,14 +3946,13 @@ emit_vertex(
    LLVMBuilderRef builder = bld->bld_base.base.gallivm->builder;
 
    if (bld->gs_iface->emit_vertex) {
-      uint32_t stream_reg_idx = emit_data->inst->Src[0].Register.Index;
-      uint32_t stream_reg_swiz = emit_data->inst->Src[0].Register.SwizzleX;
-      LLVMValueRef stream_id = bld->immediates[stream_reg_idx][stream_reg_swiz];
+      LLVMValueRef stream_id = emit_fetch_immediate(bld_base, &emit_data->inst->Src[0],
+                                                    TGSI_TYPE_UNSIGNED,
+                                                    emit_data->inst->Src[0].Register.SwizzleX);
       LLVMValueRef mask = mask_vec(bld_base);
       LLVMValueRef total_emitted_vertices_vec =
          LLVMBuildLoad(builder, bld->total_emitted_vertices_vec_ptr, "");
 
-      stream_id = LLVMBuildBitCast(builder, stream_id, bld_base->uint_bld.vec_type, "");
       mask = clamp_mask_to_max_output_vertices(bld, mask,
                                                total_emitted_vertices_vec);
       gather_outputs(bld);