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> (cherry picked from commit4c0a7a169d
)
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
@@ -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);
|
||||
|
@@ -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, "");
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user