• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef LP_BLD_FORMAT_H
29 #define LP_BLD_FORMAT_H
30 
31 
32 /**
33  * @file
34  * Pixel format helpers.
35  */
36 
37 #include "gallivm/lp_bld.h"
38 #include "gallivm/lp_bld_init.h"
39 
40 #include "pipe/p_format.h"
41 
42 struct util_format_description;
43 struct lp_type;
44 struct lp_build_context;
45 
46 
47 #define LP_BUILD_FORMAT_CACHE_DEBUG 0
48 /*
49  * Block cache
50  *
51  * Optional block cache to be used when unpacking big pixel blocks.
52  * Must be a power of 2
53  */
54 
55 #define LP_BUILD_FORMAT_CACHE_SIZE 128
56 
57 /*
58  * Note: cache_data needs 16 byte alignment.
59  */
60 struct lp_build_format_cache
61 {
62    alignas(16) uint32_t cache_data[LP_BUILD_FORMAT_CACHE_SIZE][4][4];
63    uint64_t cache_tags[LP_BUILD_FORMAT_CACHE_SIZE];
64 #if LP_BUILD_FORMAT_CACHE_DEBUG
65    uint64_t cache_access_total;
66    uint64_t cache_access_miss;
67 #endif
68 };
69 
70 
71 enum cache_member {
72    LP_BUILD_FORMAT_CACHE_MEMBER_DATA = 0,
73    LP_BUILD_FORMAT_CACHE_MEMBER_TAGS,
74 #if LP_BUILD_FORMAT_CACHE_DEBUG
75    LP_BUILD_FORMAT_CACHE_MEMBER_ACCESS_TOTAL,
76    LP_BUILD_FORMAT_CACHE_MEMBER_ACCESS_MISS,
77 #endif
78    LP_BUILD_FORMAT_CACHE_MEMBER_COUNT
79 };
80 
81 
82 LLVMTypeRef
83 lp_build_format_cache_type(struct gallivm_state *gallivm);
84 
85 LLVMTypeRef
86 lp_build_format_cache_member_type(struct gallivm_state *gallivm, enum cache_member member);
87 
88 LLVMTypeRef
89 lp_build_format_cache_elem_type(struct gallivm_state *gallivm, enum cache_member member);
90 
91 /*
92  * AoS
93  */
94 
95 LLVMValueRef
96 lp_build_format_swizzle_aos(const struct util_format_description *desc,
97                             struct lp_build_context *bld,
98                             LLVMValueRef unswizzled);
99 
100 LLVMValueRef
101 lp_build_pack_rgba_aos(struct gallivm_state *gallivm,
102                        const struct util_format_description *desc,
103                        LLVMValueRef rgba);
104 
105 LLVMValueRef
106 lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
107                         const struct util_format_description *format_desc,
108                         struct lp_type type,
109                         boolean aligned,
110                         LLVMValueRef base_ptr,
111                         LLVMValueRef offset,
112                         LLVMValueRef i,
113                         LLVMValueRef j,
114                         LLVMValueRef cache);
115 
116 LLVMValueRef
117 lp_build_fetch_rgba_aos_array(struct gallivm_state *gallivm,
118                         const struct util_format_description *format_desc,
119                         struct lp_type type,
120                         LLVMValueRef base_ptr,
121                         LLVMValueRef offset);
122 
123 
124 /*
125  * SoA
126  */
127 
128 void
129 lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
130                             struct lp_build_context *bld,
131                             const LLVMValueRef unswizzled[4],
132                             LLVMValueRef swizzled_out[4]);
133 
134 void
135 lp_build_unpack_rgba_soa(struct gallivm_state *gallivm,
136                          const struct util_format_description *format_desc,
137                          struct lp_type type,
138                          LLVMValueRef packed,
139                          LLVMValueRef rgba_out[4]);
140 
141 void
142 lp_build_rgba8_to_fi32_soa(struct gallivm_state *gallivm,
143                           struct lp_type dst_type,
144                           LLVMValueRef packed,
145                           LLVMValueRef *rgba);
146 
147 void
148 lp_build_fetch_rgba_soa(struct gallivm_state *gallivm,
149                         const struct util_format_description *format_desc,
150                         struct lp_type type,
151                         boolean aligned,
152                         LLVMValueRef base_ptr,
153                         LLVMValueRef offsets,
154                         LLVMValueRef i,
155                         LLVMValueRef j,
156                         LLVMValueRef cache,
157                         LLVMValueRef rgba_out[4]);
158 
159 void
160 lp_build_store_rgba_soa(struct gallivm_state *gallivm,
161                         const struct util_format_description *format_desc,
162                         struct lp_type type,
163                         LLVMValueRef exec_mask,
164                         LLVMValueRef base_ptr,
165                         LLVMValueRef offset,
166                         LLVMValueRef out_of_bounds,
167                         const LLVMValueRef rgba_in[4]);
168 
169 /*
170  * YUV
171  */
172 
173 LLVMValueRef
174 lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm,
175                                    const struct util_format_description *format_desc,
176                                    unsigned n,
177                                    LLVMValueRef base_ptr,
178                                    LLVMValueRef offset,
179                                    LLVMValueRef i,
180                                    LLVMValueRef j);
181 
182 
183 /*
184  * S3TC
185  */
186 
187 LLVMValueRef
188 lp_build_fetch_s3tc_rgba_aos(struct gallivm_state *gallivm,
189                              const struct util_format_description *format_desc,
190                              unsigned n,
191                              LLVMValueRef base_ptr,
192                              LLVMValueRef offset,
193                              LLVMValueRef i,
194                              LLVMValueRef j,
195                              LLVMValueRef cache);
196 
197 /*
198  * RGTC
199  */
200 
201 LLVMValueRef
202 lp_build_fetch_rgtc_rgba_aos(struct gallivm_state *gallivm,
203                              const struct util_format_description *format_desc,
204                              unsigned n,
205                              LLVMValueRef base_ptr,
206                              LLVMValueRef offset,
207                              LLVMValueRef i,
208                              LLVMValueRef j,
209                              LLVMValueRef cache);
210 
211 /*
212  * special float formats
213  */
214 
215 LLVMValueRef
216 lp_build_float_to_smallfloat(struct gallivm_state *gallivm,
217                              struct lp_type i32_type,
218                              LLVMValueRef src,
219                              unsigned mantissa_bits,
220                              unsigned exponent_bits,
221                              unsigned mantissa_start,
222                              boolean has_sign);
223 
224 LLVMValueRef
225 lp_build_smallfloat_to_float(struct gallivm_state *gallivm,
226                              struct lp_type f32_type,
227                              LLVMValueRef src,
228                              unsigned mantissa_bits,
229                              unsigned exponent_bits,
230                              unsigned mantissa_start,
231                              boolean has_sign);
232 
233 LLVMValueRef
234 lp_build_float_to_r11g11b10(struct gallivm_state *gallivm,
235                             const LLVMValueRef *src);
236 
237 void
238 lp_build_r11g11b10_to_float(struct gallivm_state *gallivm,
239                             LLVMValueRef src,
240                             LLVMValueRef *dst);
241 
242 void
243 lp_build_rgb9e5_to_float(struct gallivm_state *gallivm,
244                          LLVMValueRef src,
245                          LLVMValueRef *dst);
246 
247 LLVMValueRef
248 lp_build_float_to_srgb_packed(struct gallivm_state *gallivm,
249                               const struct util_format_description *dst_fmt,
250                               struct lp_type src_type,
251                               LLVMValueRef *src);
252 
253 LLVMValueRef
254 lp_build_srgb_to_linear(struct gallivm_state *gallivm,
255                         struct lp_type src_type,
256                         unsigned chan_bits,
257                         LLVMValueRef src);
258 
259 
260 #endif /* !LP_BLD_FORMAT_H */
261