From c0c5eed58090733c5aa0f7350f11cdddd0269dc5 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 14 Nov 2022 13:47:02 +1000 Subject: [PATCH] gallivm: add coro malloc hooks earlier and always. This fixes GALLIVM_DEBUG=asm for compute shaders, changing the hooks after dumping causes a segfault because the memory has already been finalised. Just add the hooks always, and before dumping anything. Fixes: f511d2a55337 ("gallivm: rework coroutine malloc/free callouts.") Reviewed-by: Roland Scheidegger Part-of: (cherry picked from commit fb7de303ba7cbdb4237d2ae93011bc2845114d35) --- .pick_status.json | 2 +- src/gallium/auxiliary/draw/draw_llvm.c | 2 -- src/gallium/auxiliary/gallivm/lp_bld_init.c | 4 ++++ src/gallium/drivers/llvmpipe/lp_state_cs.c | 3 --- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 7146170e089..e85c18a7fbc 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -742,7 +742,7 @@ "description": "gallivm: add coro malloc hooks earlier and always.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "f511d2a553377a58b5eea6c6d1170fcc4972237a" }, diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 6809966b4ae..f10b1e1fac6 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -3624,12 +3624,10 @@ draw_tcs_llvm_create_variant(struct draw_llvm *llvm, draw_tcs_llvm_dump_variant_key(&variant->key); } - lp_build_coro_declare_malloc_hooks(variant->gallivm); draw_tcs_llvm_generate(llvm, variant); gallivm_compile_module(variant->gallivm); - lp_build_coro_add_malloc_hooks(variant->gallivm); variant->jit_func = (draw_tcs_jit_func) gallivm_jit_function(variant->gallivm, variant->function); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c index f753550689a..8aae82932c1 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c @@ -36,6 +36,7 @@ #include "lp_bld_debug.h" #include "lp_bld_misc.h" #include "lp_bld_init.h" +#include "lp_bld_coro.h" #include "lp_bld_printf.h" #include @@ -408,6 +409,7 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name, if (!create_pass_manager(gallivm)) goto fail; + lp_build_coro_declare_malloc_hooks(gallivm); return TRUE; fail: @@ -694,6 +696,8 @@ gallivm_compile_module(struct gallivm_state *gallivm) LLVMAddGlobalMapping(gallivm->engine, gallivm->debug_printf_hook, debug_printf); + lp_build_coro_add_malloc_hooks(gallivm); + if (gallivm_debug & GALLIVM_DEBUG_ASM) { LLVMValueRef llvm_func = LLVMGetFirstFunction(gallivm->module); diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c index 111434a69ba..4127737340d 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c @@ -145,8 +145,6 @@ generate_compute(struct llvmpipe_context *lp, } } - lp_build_coro_declare_malloc_hooks(gallivm); - if (variant->gallivm->cache->data_size) return; @@ -812,7 +810,6 @@ generate_variant(struct llvmpipe_context *lp, gallivm_compile_module(variant->gallivm); - lp_build_coro_add_malloc_hooks(variant->gallivm); variant->nr_instrs += lp_build_count_ir_module(variant->gallivm->module); variant->jit_function = (lp_jit_cs_func)gallivm_jit_function(variant->gallivm, variant->function);