diff --git a/.pick_status.json b/.pick_status.json index 421b56bfc56..04649fa6f2d 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -310,7 +310,7 @@ "description": "gallivm: fix printf hook for cached shaders.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "333ee94285ac453b9d75ce93b01bc26e48bf96d7" }, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c index 2ed81d9ae5d..ca50a6debbd 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_printf.h" #include #include @@ -689,8 +690,9 @@ gallivm_compile_module(struct gallivm_state *gallivm) ++gallivm->compiled; - if (gallivm->debug_printf_hook) - LLVMAddGlobalMapping(gallivm->engine, gallivm->debug_printf_hook, debug_printf); + lp_init_printf_hook(gallivm); + LLVMAddGlobalMapping(gallivm->engine, gallivm->debug_printf_hook, debug_printf); + if (gallivm_debug & GALLIVM_DEBUG_ASM) { LLVMValueRef llvm_func = LLVMGetFirstFunction(gallivm->module); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c index 5e08a0c2fe6..6c514838f0e 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c @@ -38,6 +38,13 @@ #include "lp_bld_printf.h" #include "lp_bld_type.h" +void lp_init_printf_hook(struct gallivm_state *gallivm) +{ + if (gallivm->debug_printf_hook) + return; + LLVMTypeRef printf_type = LLVMFunctionType(LLVMInt32TypeInContext(gallivm->context), NULL, 0, 1); + gallivm->debug_printf_hook = LLVMAddFunction(gallivm->module, "debug_printf", printf_type); +} /** * Generates LLVM IR to call debug_printf. @@ -63,10 +70,8 @@ lp_build_print_args(struct gallivm_state* gallivm, args[i] = LLVMBuildFPExt(builder, args[i], LLVMDoubleTypeInContext(context), ""); } - LLVMTypeRef printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1); - if (!gallivm->debug_printf_hook) { - gallivm->debug_printf_hook = LLVMAddFunction(gallivm->module, "debug_printf", printf_type); - } + lp_init_printf_hook(gallivm); + LLVMTypeRef printf_type = LLVMFunctionType(LLVMInt32TypeInContext(gallivm->context), NULL, 0, 1); return LLVMBuildCall2(builder, printf_type, gallivm->debug_printf_hook, args, argcount, ""); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.h b/src/gallium/auxiliary/gallivm/lp_bld_printf.h index 298b4033f08..e0191264f11 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_printf.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.h @@ -36,6 +36,7 @@ extern "C" { #include "lp_bld.h" #include "lp_bld_init.h" +void lp_init_printf_hook(struct gallivm_state *gallivm); LLVMValueRef lp_build_printf(struct gallivm_state *gallivm,