Merge branch '7.8'
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_sample.h
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 * @file
30 * Texture sampling.
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 */
34
35 #ifndef LP_BLD_SAMPLE_H
36 #define LP_BLD_SAMPLE_H
37
38
39 #include "gallivm/lp_bld.h"
40
41 struct pipe_resource;
42 struct pipe_sampler_view;
43 struct pipe_sampler_state;
44 struct util_format_description;
45 struct lp_type;
46 struct lp_build_context;
47
48
49 /**
50 * Sampler static state.
51 *
52 * These are the bits of state from pipe_resource and pipe_sampler_state that
53 * are embedded in the generated code.
54 */
55 struct lp_sampler_static_state
56 {
57 /* pipe_sampler_view's state */
58 enum pipe_format format;
59 unsigned swizzle_r:3;
60 unsigned swizzle_g:3;
61 unsigned swizzle_b:3;
62 unsigned swizzle_a:3;
63
64 /* pipe_texture's state */
65 unsigned target:3;
66 unsigned pot_width:1;
67 unsigned pot_height:1;
68 unsigned pot_depth:1;
69
70 /* pipe_sampler_state's state */
71 unsigned wrap_s:3;
72 unsigned wrap_t:3;
73 unsigned wrap_r:3;
74 unsigned min_img_filter:2;
75 unsigned min_mip_filter:2;
76 unsigned mag_img_filter:2;
77 unsigned compare_mode:1;
78 unsigned compare_func:3;
79 unsigned normalized_coords:1;
80 float lod_bias, min_lod, max_lod;
81 float border_color[4];
82 };
83
84
85 /**
86 * Sampler dynamic state.
87 *
88 * These are the bits of state from pipe_resource and pipe_sampler_state that
89 * are computed in runtime.
90 *
91 * There are obtained through callbacks, as we don't want to tie the texture
92 * sampling code generation logic to any particular texture layout or pipe
93 * driver.
94 */
95 struct lp_sampler_dynamic_state
96 {
97
98 /** Obtain the base texture width. */
99 LLVMValueRef
100 (*width)( struct lp_sampler_dynamic_state *state,
101 LLVMBuilderRef builder,
102 unsigned unit);
103
104 /** Obtain the base texture height. */
105 LLVMValueRef
106 (*height)( struct lp_sampler_dynamic_state *state,
107 LLVMBuilderRef builder,
108 unsigned unit);
109
110 /** Obtain the base texture depth. */
111 LLVMValueRef
112 (*depth)( struct lp_sampler_dynamic_state *state,
113 LLVMBuilderRef builder,
114 unsigned unit);
115
116 /** Obtain the number of mipmap levels (minus one). */
117 LLVMValueRef
118 (*last_level)( struct lp_sampler_dynamic_state *state,
119 LLVMBuilderRef builder,
120 unsigned unit);
121
122 LLVMValueRef
123 (*row_stride)( struct lp_sampler_dynamic_state *state,
124 LLVMBuilderRef builder,
125 unsigned unit);
126
127 LLVMValueRef
128 (*img_stride)( struct lp_sampler_dynamic_state *state,
129 LLVMBuilderRef builder,
130 unsigned unit);
131
132 LLVMValueRef
133 (*data_ptr)( struct lp_sampler_dynamic_state *state,
134 LLVMBuilderRef builder,
135 unsigned unit);
136
137 };
138
139
140 /**
141 * Derive the sampler static state.
142 */
143 void
144 lp_sampler_static_state(struct lp_sampler_static_state *state,
145 const struct pipe_sampler_view *view,
146 const struct pipe_sampler_state *sampler);
147
148
149 LLVMValueRef
150 lp_build_gather(LLVMBuilderRef builder,
151 unsigned length,
152 unsigned src_width,
153 unsigned dst_width,
154 LLVMValueRef base_ptr,
155 LLVMValueRef offsets);
156
157
158 LLVMValueRef
159 lp_build_sample_offset(struct lp_build_context *bld,
160 const struct util_format_description *format_desc,
161 LLVMValueRef x,
162 LLVMValueRef y,
163 LLVMValueRef z,
164 LLVMValueRef y_stride,
165 LLVMValueRef z_stride);
166
167
168 void
169 lp_build_sample_soa(LLVMBuilderRef builder,
170 const struct lp_sampler_static_state *static_state,
171 struct lp_sampler_dynamic_state *dynamic_state,
172 struct lp_type fp_type,
173 unsigned unit,
174 unsigned num_coords,
175 const LLVMValueRef *coords,
176 LLVMValueRef lodbias,
177 LLVMValueRef *texel);
178
179
180
181 #endif /* LP_BLD_SAMPLE_H */