From 59f628a600771e1967c0e94c230e82557a5b1585 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sun, 23 Aug 2009 07:55:29 +0100 Subject: llvmpipe: Pre-declare fetch_texel. --- src/gallium/drivers/llvmpipe/lp_bld_intr.c | 49 ++++++++++++++++++++++-------- src/gallium/drivers/llvmpipe/lp_bld_intr.h | 7 +++++ src/gallium/drivers/llvmpipe/lp_bld_tgsi.h | 1 + src/gallium/drivers/llvmpipe/lp_jit.c | 24 +++++++++++++-- src/gallium/drivers/llvmpipe/lp_state_fs.c | 13 -------- 5 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_bld_intr.c b/src/gallium/drivers/llvmpipe/lp_bld_intr.c index 42fd57fdf0..9895749d56 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_intr.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_intr.c @@ -49,6 +49,37 @@ #include "lp_bld_intr.h" +LLVMValueRef +lp_declare_intrinsic(LLVMModuleRef module, + const char *name, + LLVMTypeRef ret_type, + LLVMTypeRef *arg_types, + unsigned num_args) +{ + LLVMTypeRef function_type; + LLVMValueRef function; + + assert(!LLVMGetNamedFunction(module, name)); + + function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); + function = LLVMAddFunction(module, name, function_type); + + LLVMSetFunctionCallConv(function, LLVMCCallConv); + LLVMSetLinkage(function, LLVMExternalLinkage); + + assert(LLVMIsDeclaration(function)); + + if(name[0] == 'l' && + name[1] == 'l' && + name[2] == 'v' && + name[3] == 'm' && + name[4] == '.') + assert(LLVMGetIntrinsicID(function)); + + return function; +} + + LLVMValueRef lp_build_intrinsic(LLVMBuilderRef builder, const char *name, @@ -59,28 +90,20 @@ lp_build_intrinsic(LLVMBuilderRef builder, LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); LLVMValueRef function; - assert(num_args <= LP_MAX_FUNC_ARGS); - function = LLVMGetNamedFunction(module, name); if(!function) { LLVMTypeRef arg_types[LP_MAX_FUNC_ARGS]; unsigned i; + + assert(num_args <= LP_MAX_FUNC_ARGS); + for(i = 0; i < num_args; ++i) { assert(args[i]); arg_types[i] = LLVMTypeOf(args[i]); } - function = LLVMAddFunction(module, name, LLVMFunctionType(ret_type, arg_types, num_args, 0)); - LLVMSetFunctionCallConv(function, LLVMCCallConv); - LLVMSetLinkage(function, LLVMExternalLinkage); - } - assert(LLVMIsDeclaration(function)); - if(name[0] == 'l' && - name[1] == 'l' && - name[2] == 'v' && - name[3] == 'm' && - name[4] == '.') - assert(LLVMGetIntrinsicID(function)); + function = lp_declare_intrinsic(module, name, ret_type, arg_types, num_args); + } return LLVMBuildCall(builder, function, args, num_args, ""); } diff --git a/src/gallium/drivers/llvmpipe/lp_bld_intr.h b/src/gallium/drivers/llvmpipe/lp_bld_intr.h index 3608988dc4..f813f27074 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_intr.h +++ b/src/gallium/drivers/llvmpipe/lp_bld_intr.h @@ -46,6 +46,13 @@ #define LP_MAX_FUNC_ARGS 32 +LLVMValueRef +lp_declare_intrinsic(LLVMModuleRef module, + const char *name, + LLVMTypeRef ret_type, + LLVMTypeRef *arg_types, + unsigned num_args); + LLVMValueRef lp_build_intrinsic(LLVMBuilderRef builder, const char *name, diff --git a/src/gallium/drivers/llvmpipe/lp_bld_tgsi.h b/src/gallium/drivers/llvmpipe/lp_bld_tgsi.h index 8aaf494d2b..86380a1dca 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_tgsi.h +++ b/src/gallium/drivers/llvmpipe/lp_bld_tgsi.h @@ -39,6 +39,7 @@ struct tgsi_token; +struct tgsi_sampler; union lp_type; struct lp_build_context; struct lp_build_mask_context; diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 0a32c41a6f..39c4df8363 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -37,11 +37,13 @@ #include "util/u_memory.h" #include "lp_screen.h" +#include "lp_bld_intr.h" +#include "lp_bld_tgsi.h" /* for lp_build_tgsi_fetch_texel_soa */ #include "lp_jit.h" static void -lp_jit_init_types(struct llvmpipe_screen *screen) +lp_jit_init_globals(struct llvmpipe_screen *screen) { /* struct lp_jit_context */ { @@ -71,6 +73,24 @@ lp_jit_init_types(struct llvmpipe_screen *screen) screen->context_ptr_type = LLVMPointerType(context_type, 0); } + /* fetch_texel + */ + { + LLVMTypeRef ret_type; + LLVMTypeRef arg_types[3]; + LLVMValueRef fetch_texel; + + ret_type = LLVMVoidType(); + arg_types[0] = LLVMPointerType(LLVMInt8Type(), 0); /* samplers */ + arg_types[1] = LLVMInt32Type(); /* unit */ + arg_types[2] = LLVMPointerType(LLVMVectorType(LLVMFloatType(), 4), 0); /* store */ + + fetch_texel = lp_declare_intrinsic(screen->module, "fetch_texel", + ret_type, arg_types, Elements(arg_types)); + + LLVMAddGlobalMapping(screen->engine, fetch_texel, lp_build_tgsi_fetch_texel_soa); + } + #ifdef DEBUG LLVMDumpModule(screen->module); #endif @@ -115,5 +135,5 @@ lp_jit_screen_init(struct llvmpipe_screen *screen) LLVMAddGVNPass(screen->pass); LLVMAddCFGSimplificationPass(screen->pass); - lp_jit_init_types(screen); + lp_jit_init_globals(screen); } diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index eea332e3e4..e639f9c20f 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -404,7 +404,6 @@ generate_fragment(struct llvmpipe_context *lp, LLVMValueRef fs_out_color[NUM_CHANNELS][LP_MAX_VECTOR_LENGTH]; LLVMValueRef blend_mask; LLVMValueRef blend_in_color[NUM_CHANNELS]; - LLVMValueRef fetch_texel; unsigned num_fs; unsigned i; unsigned chan; @@ -592,18 +591,6 @@ generate_fragment(struct llvmpipe_context *lp, abort(); } - /* Tell where the fetch_texel function is, if the shader refers to it. - * TODO: this should be done elsewhere. - */ - fetch_texel = LLVMGetNamedFunction(screen->module, "fetch_texel"); - if(fetch_texel) { - static boolean first_time = TRUE; - if(first_time) { - LLVMAddGlobalMapping(screen->engine, fetch_texel, lp_build_tgsi_fetch_texel_soa); - first_time = FALSE; - } - } - variant->jit_function = (lp_jit_frag_func)LLVMGetPointerToGlobal(screen->engine, variant->function); #ifdef DEBUG -- cgit v1.2.3