gallivm: fix printf hook for cached shaders.

I've noticed this before but never tracked it down, but it's annoying.

The printf hooks would crash with debug shaders when they were loaded
from the cache. This was because nothing was initing the printf hook
in the cached path so the global was never set.

No problems just always creating this afaics.

Fixes: 333ee94285 ("gallivm: rework debug printf hook to use global mapping.")
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17867>
This commit is contained in:
Dave Airlie 2022-08-03 14:50:19 +10:00 committed by Marge Bot
parent f0558c6f1c
commit 4c0a7a169d
3 changed files with 14 additions and 6 deletions

View file

@ -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 <llvm/Config/llvm-config.h>
#include <llvm-c/Analysis.h>
@ -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);

View file

@ -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, "");
}

View file

@ -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,