1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * Texture sampling code generation
30 *
31 * This file is nothing more than ugly glue between three largely independent
32 * entities:
33 * - TGSI -> LLVM translation (i.e., lp_build_tgsi_soa)
34 * - texture sampling code generation (i.e., lp_build_sample_soa)
35 * - LLVM pipe driver
36 *
37 * All interesting code is in the functions mentioned above. There is really
38 * nothing to see here.
39 *
40 * @author Jose Fonseca <[email protected]>
41 */
42
43 #include "pipe/p_defines.h"
44 #include "pipe/p_shader_tokens.h"
45 #include "gallivm/lp_bld_debug.h"
46 #include "gallivm/lp_bld_const.h"
47 #include "gallivm/lp_bld_type.h"
48 #include "gallivm/lp_bld_sample.h"
49 #include "gallivm/lp_bld_tgsi.h"
50 #include "lp_jit.h"
51 #include "lp_tex_sample.h"
52 #include "lp_state_fs.h"
53 #include "lp_debug.h"
54
55
56 #if LP_USE_TEXTURE_CACHE
57 static LLVMValueRef
lp_llvm_texture_cache_ptr(struct gallivm_state * gallivm,LLVMTypeRef thread_data_type,LLVMValueRef thread_data_ptr,unsigned unit)58 lp_llvm_texture_cache_ptr(struct gallivm_state *gallivm,
59 LLVMTypeRef thread_data_type,
60 LLVMValueRef thread_data_ptr,
61 unsigned unit)
62 {
63 /* We use the same cache for all units */
64 (void)unit;
65
66 return lp_jit_thread_data_cache(gallivm, thread_data_type, thread_data_ptr);
67 }
68 #endif
69 struct lp_build_sampler_soa *
lp_llvm_sampler_soa_create(const struct lp_sampler_static_state * static_state,unsigned nr_samplers)70 lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
71 unsigned nr_samplers)
72 {
73 struct lp_build_sampler_soa *sampler;
74
75 sampler = lp_bld_llvm_sampler_soa_create(static_state, nr_samplers);
76
77 #if LP_USE_TEXTURE_CACHE
78 struct lp_sampler_dynamic_state *dynamic_state = lp_build_sampler_soa_dynamic_state(sampler);
79 dynamic_state->cache_ptr = lp_llvm_texture_cache_ptr;
80 #endif
81 return sampler;
82 }
83
84
85