1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2008 VMware, Inc. All rights reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Mipmap generation utility
37 #include "pipe/p_context.h"
38 #include "util/u_debug.h"
39 #include "pipe/p_defines.h"
40 #include "pipe/p_inlines.h"
41 #include "pipe/p_shader_tokens.h"
42 #include "pipe/p_state.h"
44 #include "util/u_format.h"
45 #include "util/u_memory.h"
46 #include "util/u_draw_quad.h"
47 #include "util/u_gen_mipmap.h"
48 #include "util/u_simple_shaders.h"
49 #include "util/u_math.h"
51 #include "cso_cache/cso_context.h"
54 struct gen_mipmap_state
56 struct pipe_context
*pipe
;
57 struct cso_context
*cso
;
59 struct pipe_blend_state blend
;
60 struct pipe_depth_stencil_alpha_state depthstencil
;
61 struct pipe_rasterizer_state rasterizer
;
62 struct pipe_sampler_state sampler
;
67 struct pipe_buffer
*vbuf
; /**< quad vertices */
70 float vertices
[4][2][4]; /**< vertex/texcoords for quad */
82 DTYPE_USHORT_1_5_5_5_REV
,
89 typedef ushort half_float
;
93 float_to_half(float f
)
100 half_to_float(half_float h
)
110 * \name Support macros for do_row and do_row_3d
112 * The macro madness is here for two reasons. First, it compacts the code
113 * slightly. Second, it makes it much easier to adjust the specifics of the
114 * filter to tune the rounding characteristics.
117 #define DECLARE_ROW_POINTERS(t, e) \
118 const t(*rowA)[e] = (const t(*)[e]) srcRowA; \
119 const t(*rowB)[e] = (const t(*)[e]) srcRowB; \
120 const t(*rowC)[e] = (const t(*)[e]) srcRowC; \
121 const t(*rowD)[e] = (const t(*)[e]) srcRowD; \
122 t(*dst)[e] = (t(*)[e]) dstRow
124 #define DECLARE_ROW_POINTERS0(t) \
125 const t *rowA = (const t *) srcRowA; \
126 const t *rowB = (const t *) srcRowB; \
127 const t *rowC = (const t *) srcRowC; \
128 const t *rowD = (const t *) srcRowD; \
129 t *dst = (t *) dstRow
131 #define FILTER_SUM_3D(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \
132 ((unsigned) Aj + (unsigned) Ak \
133 + (unsigned) Bj + (unsigned) Bk \
134 + (unsigned) Cj + (unsigned) Ck \
135 + (unsigned) Dj + (unsigned) Dk \
138 #define FILTER_3D(e) \
140 dst[i][e] = FILTER_SUM_3D(rowA[j][e], rowA[k][e], \
141 rowB[j][e], rowB[k][e], \
142 rowC[j][e], rowC[k][e], \
143 rowD[j][e], rowD[k][e]); \
146 #define FILTER_F_3D(e) \
148 dst[i][e] = (rowA[j][e] + rowA[k][e] \
149 + rowB[j][e] + rowB[k][e] \
150 + rowC[j][e] + rowC[k][e] \
151 + rowD[j][e] + rowD[k][e]) * 0.125F; \
154 #define FILTER_HF_3D(e) \
156 const float aj = half_to_float(rowA[j][e]); \
157 const float ak = half_to_float(rowA[k][e]); \
158 const float bj = half_to_float(rowB[j][e]); \
159 const float bk = half_to_float(rowB[k][e]); \
160 const float cj = half_to_float(rowC[j][e]); \
161 const float ck = half_to_float(rowC[k][e]); \
162 const float dj = half_to_float(rowD[j][e]); \
163 const float dk = half_to_float(rowD[k][e]); \
164 dst[i][e] = float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
171 * Average together two rows of a source image to produce a single new
172 * row in the dest image. It's legal for the two source rows to point
173 * to the same data. The source width must be equal to either the
174 * dest width or two times the dest width.
175 * \param datatype GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT, etc.
176 * \param comps number of components per pixel (1..4)
179 do_row(enum dtype datatype
, uint comps
, int srcWidth
,
180 const void *srcRowA
, const void *srcRowB
,
181 int dstWidth
, void *dstRow
)
183 const uint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
184 const uint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
189 /* This assertion is no longer valid with non-power-of-2 textures
190 assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth);
193 if (datatype
== DTYPE_UBYTE
&& comps
== 4) {
195 const ubyte(*rowA
)[4] = (const ubyte(*)[4]) srcRowA
;
196 const ubyte(*rowB
)[4] = (const ubyte(*)[4]) srcRowB
;
197 ubyte(*dst
)[4] = (ubyte(*)[4]) dstRow
;
198 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
199 i
++, j
+= colStride
, k
+= colStride
) {
200 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
201 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
202 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
203 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
206 else if (datatype
== DTYPE_UBYTE
&& comps
== 3) {
208 const ubyte(*rowA
)[3] = (const ubyte(*)[3]) srcRowA
;
209 const ubyte(*rowB
)[3] = (const ubyte(*)[3]) srcRowB
;
210 ubyte(*dst
)[3] = (ubyte(*)[3]) dstRow
;
211 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
212 i
++, j
+= colStride
, k
+= colStride
) {
213 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
214 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
215 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
218 else if (datatype
== DTYPE_UBYTE
&& comps
== 2) {
220 const ubyte(*rowA
)[2] = (const ubyte(*)[2]) srcRowA
;
221 const ubyte(*rowB
)[2] = (const ubyte(*)[2]) srcRowB
;
222 ubyte(*dst
)[2] = (ubyte(*)[2]) dstRow
;
223 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
224 i
++, j
+= colStride
, k
+= colStride
) {
225 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) >> 2;
226 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) >> 2;
229 else if (datatype
== DTYPE_UBYTE
&& comps
== 1) {
231 const ubyte
*rowA
= (const ubyte
*) srcRowA
;
232 const ubyte
*rowB
= (const ubyte
*) srcRowB
;
233 ubyte
*dst
= (ubyte
*) dstRow
;
234 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
235 i
++, j
+= colStride
, k
+= colStride
) {
236 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) >> 2;
240 else if (datatype
== DTYPE_USHORT
&& comps
== 4) {
242 const ushort(*rowA
)[4] = (const ushort(*)[4]) srcRowA
;
243 const ushort(*rowB
)[4] = (const ushort(*)[4]) srcRowB
;
244 ushort(*dst
)[4] = (ushort(*)[4]) dstRow
;
245 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
246 i
++, j
+= colStride
, k
+= colStride
) {
247 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
248 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
249 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
250 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] + rowB
[j
][3] + rowB
[k
][3]) / 4;
253 else if (datatype
== DTYPE_USHORT
&& comps
== 3) {
255 const ushort(*rowA
)[3] = (const ushort(*)[3]) srcRowA
;
256 const ushort(*rowB
)[3] = (const ushort(*)[3]) srcRowB
;
257 ushort(*dst
)[3] = (ushort(*)[3]) dstRow
;
258 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
259 i
++, j
+= colStride
, k
+= colStride
) {
260 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
261 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
262 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] + rowB
[j
][2] + rowB
[k
][2]) / 4;
265 else if (datatype
== DTYPE_USHORT
&& comps
== 2) {
267 const ushort(*rowA
)[2] = (const ushort(*)[2]) srcRowA
;
268 const ushort(*rowB
)[2] = (const ushort(*)[2]) srcRowB
;
269 ushort(*dst
)[2] = (ushort(*)[2]) dstRow
;
270 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
271 i
++, j
+= colStride
, k
+= colStride
) {
272 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] + rowB
[j
][0] + rowB
[k
][0]) / 4;
273 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] + rowB
[j
][1] + rowB
[k
][1]) / 4;
276 else if (datatype
== DTYPE_USHORT
&& comps
== 1) {
278 const ushort
*rowA
= (const ushort
*) srcRowA
;
279 const ushort
*rowB
= (const ushort
*) srcRowB
;
280 ushort
*dst
= (ushort
*) dstRow
;
281 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
282 i
++, j
+= colStride
, k
+= colStride
) {
283 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) / 4;
287 else if (datatype
== DTYPE_FLOAT
&& comps
== 4) {
289 const float(*rowA
)[4] = (const float(*)[4]) srcRowA
;
290 const float(*rowB
)[4] = (const float(*)[4]) srcRowB
;
291 float(*dst
)[4] = (float(*)[4]) dstRow
;
292 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
293 i
++, j
+= colStride
, k
+= colStride
) {
294 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
295 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
296 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
297 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
298 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
299 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
300 dst
[i
][3] = (rowA
[j
][3] + rowA
[k
][3] +
301 rowB
[j
][3] + rowB
[k
][3]) * 0.25F
;
304 else if (datatype
== DTYPE_FLOAT
&& comps
== 3) {
306 const float(*rowA
)[3] = (const float(*)[3]) srcRowA
;
307 const float(*rowB
)[3] = (const float(*)[3]) srcRowB
;
308 float(*dst
)[3] = (float(*)[3]) dstRow
;
309 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
310 i
++, j
+= colStride
, k
+= colStride
) {
311 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
312 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
313 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
314 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
315 dst
[i
][2] = (rowA
[j
][2] + rowA
[k
][2] +
316 rowB
[j
][2] + rowB
[k
][2]) * 0.25F
;
319 else if (datatype
== DTYPE_FLOAT
&& comps
== 2) {
321 const float(*rowA
)[2] = (const float(*)[2]) srcRowA
;
322 const float(*rowB
)[2] = (const float(*)[2]) srcRowB
;
323 float(*dst
)[2] = (float(*)[2]) dstRow
;
324 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
325 i
++, j
+= colStride
, k
+= colStride
) {
326 dst
[i
][0] = (rowA
[j
][0] + rowA
[k
][0] +
327 rowB
[j
][0] + rowB
[k
][0]) * 0.25F
;
328 dst
[i
][1] = (rowA
[j
][1] + rowA
[k
][1] +
329 rowB
[j
][1] + rowB
[k
][1]) * 0.25F
;
332 else if (datatype
== DTYPE_FLOAT
&& comps
== 1) {
334 const float *rowA
= (const float *) srcRowA
;
335 const float *rowB
= (const float *) srcRowB
;
336 float *dst
= (float *) dstRow
;
337 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
338 i
++, j
+= colStride
, k
+= colStride
) {
339 dst
[i
] = (rowA
[j
] + rowA
[k
] + rowB
[j
] + rowB
[k
]) * 0.25F
;
344 else if (datatype
== HALF_DTYPE_FLOAT
&& comps
== 4) {
346 const half_float(*rowA
)[4] = (const half_float(*)[4]) srcRowA
;
347 const half_float(*rowB
)[4] = (const half_float(*)[4]) srcRowB
;
348 half_float(*dst
)[4] = (half_float(*)[4]) dstRow
;
349 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
350 i
++, j
+= colStride
, k
+= colStride
) {
351 for (comp
= 0; comp
< 4; comp
++) {
352 float aj
, ak
, bj
, bk
;
353 aj
= half_to_float(rowA
[j
][comp
]);
354 ak
= half_to_float(rowA
[k
][comp
]);
355 bj
= half_to_float(rowB
[j
][comp
]);
356 bk
= half_to_float(rowB
[k
][comp
]);
357 dst
[i
][comp
] = float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
361 else if (datatype
== DTYPE_HALF_FLOAT
&& comps
== 3) {
363 const half_float(*rowA
)[3] = (const half_float(*)[3]) srcRowA
;
364 const half_float(*rowB
)[3] = (const half_float(*)[3]) srcRowB
;
365 half_float(*dst
)[3] = (half_float(*)[3]) dstRow
;
366 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
367 i
++, j
+= colStride
, k
+= colStride
) {
368 for (comp
= 0; comp
< 3; comp
++) {
369 float aj
, ak
, bj
, bk
;
370 aj
= half_to_float(rowA
[j
][comp
]);
371 ak
= half_to_float(rowA
[k
][comp
]);
372 bj
= half_to_float(rowB
[j
][comp
]);
373 bk
= half_to_float(rowB
[k
][comp
]);
374 dst
[i
][comp
] = float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
378 else if (datatype
== DTYPE_HALF_FLOAT
&& comps
== 2) {
380 const half_float(*rowA
)[2] = (const half_float(*)[2]) srcRowA
;
381 const half_float(*rowB
)[2] = (const half_float(*)[2]) srcRowB
;
382 half_float(*dst
)[2] = (half_float(*)[2]) dstRow
;
383 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
384 i
++, j
+= colStride
, k
+= colStride
) {
385 for (comp
= 0; comp
< 2; comp
++) {
386 float aj
, ak
, bj
, bk
;
387 aj
= half_to_float(rowA
[j
][comp
]);
388 ak
= half_to_float(rowA
[k
][comp
]);
389 bj
= half_to_float(rowB
[j
][comp
]);
390 bk
= half_to_float(rowB
[k
][comp
]);
391 dst
[i
][comp
] = float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
395 else if (datatype
== DTYPE_HALF_FLOAT
&& comps
== 1) {
397 const half_float
*rowA
= (const half_float
*) srcRowA
;
398 const half_float
*rowB
= (const half_float
*) srcRowB
;
399 half_float
*dst
= (half_float
*) dstRow
;
400 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
401 i
++, j
+= colStride
, k
+= colStride
) {
402 float aj
, ak
, bj
, bk
;
403 aj
= half_to_float(rowA
[j
]);
404 ak
= half_to_float(rowA
[k
]);
405 bj
= half_to_float(rowB
[j
]);
406 bk
= half_to_float(rowB
[k
]);
407 dst
[i
] = float_to_half((aj
+ ak
+ bj
+ bk
) * 0.25F
);
412 else if (datatype
== DTYPE_UINT
&& comps
== 1) {
414 const uint
*rowA
= (const uint
*) srcRowA
;
415 const uint
*rowB
= (const uint
*) srcRowB
;
416 uint
*dst
= (uint
*) dstRow
;
417 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
418 i
++, j
+= colStride
, k
+= colStride
) {
419 dst
[i
] = rowA
[j
] / 4 + rowA
[k
] / 4 + rowB
[j
] / 4 + rowB
[k
] / 4;
423 else if (datatype
== DTYPE_USHORT_5_6_5
&& comps
== 3) {
425 const ushort
*rowA
= (const ushort
*) srcRowA
;
426 const ushort
*rowB
= (const ushort
*) srcRowB
;
427 ushort
*dst
= (ushort
*) dstRow
;
428 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
429 i
++, j
+= colStride
, k
+= colStride
) {
430 const int rowAr0
= rowA
[j
] & 0x1f;
431 const int rowAr1
= rowA
[k
] & 0x1f;
432 const int rowBr0
= rowB
[j
] & 0x1f;
433 const int rowBr1
= rowB
[k
] & 0x1f;
434 const int rowAg0
= (rowA
[j
] >> 5) & 0x3f;
435 const int rowAg1
= (rowA
[k
] >> 5) & 0x3f;
436 const int rowBg0
= (rowB
[j
] >> 5) & 0x3f;
437 const int rowBg1
= (rowB
[k
] >> 5) & 0x3f;
438 const int rowAb0
= (rowA
[j
] >> 11) & 0x1f;
439 const int rowAb1
= (rowA
[k
] >> 11) & 0x1f;
440 const int rowBb0
= (rowB
[j
] >> 11) & 0x1f;
441 const int rowBb1
= (rowB
[k
] >> 11) & 0x1f;
442 const int red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
443 const int green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
444 const int blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
445 dst
[i
] = (blue
<< 11) | (green
<< 5) | red
;
448 else if (datatype
== DTYPE_USHORT_4_4_4_4
&& comps
== 4) {
450 const ushort
*rowA
= (const ushort
*) srcRowA
;
451 const ushort
*rowB
= (const ushort
*) srcRowB
;
452 ushort
*dst
= (ushort
*) dstRow
;
453 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
454 i
++, j
+= colStride
, k
+= colStride
) {
455 const int rowAr0
= rowA
[j
] & 0xf;
456 const int rowAr1
= rowA
[k
] & 0xf;
457 const int rowBr0
= rowB
[j
] & 0xf;
458 const int rowBr1
= rowB
[k
] & 0xf;
459 const int rowAg0
= (rowA
[j
] >> 4) & 0xf;
460 const int rowAg1
= (rowA
[k
] >> 4) & 0xf;
461 const int rowBg0
= (rowB
[j
] >> 4) & 0xf;
462 const int rowBg1
= (rowB
[k
] >> 4) & 0xf;
463 const int rowAb0
= (rowA
[j
] >> 8) & 0xf;
464 const int rowAb1
= (rowA
[k
] >> 8) & 0xf;
465 const int rowBb0
= (rowB
[j
] >> 8) & 0xf;
466 const int rowBb1
= (rowB
[k
] >> 8) & 0xf;
467 const int rowAa0
= (rowA
[j
] >> 12) & 0xf;
468 const int rowAa1
= (rowA
[k
] >> 12) & 0xf;
469 const int rowBa0
= (rowB
[j
] >> 12) & 0xf;
470 const int rowBa1
= (rowB
[k
] >> 12) & 0xf;
471 const int red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
472 const int green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
473 const int blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
474 const int alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
475 dst
[i
] = (alpha
<< 12) | (blue
<< 8) | (green
<< 4) | red
;
478 else if (datatype
== DTYPE_USHORT_1_5_5_5_REV
&& comps
== 4) {
480 const ushort
*rowA
= (const ushort
*) srcRowA
;
481 const ushort
*rowB
= (const ushort
*) srcRowB
;
482 ushort
*dst
= (ushort
*) dstRow
;
483 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
484 i
++, j
+= colStride
, k
+= colStride
) {
485 const int rowAr0
= rowA
[j
] & 0x1f;
486 const int rowAr1
= rowA
[k
] & 0x1f;
487 const int rowBr0
= rowB
[j
] & 0x1f;
488 const int rowBr1
= rowB
[k
] & 0x1f;
489 const int rowAg0
= (rowA
[j
] >> 5) & 0x1f;
490 const int rowAg1
= (rowA
[k
] >> 5) & 0x1f;
491 const int rowBg0
= (rowB
[j
] >> 5) & 0x1f;
492 const int rowBg1
= (rowB
[k
] >> 5) & 0x1f;
493 const int rowAb0
= (rowA
[j
] >> 10) & 0x1f;
494 const int rowAb1
= (rowA
[k
] >> 10) & 0x1f;
495 const int rowBb0
= (rowB
[j
] >> 10) & 0x1f;
496 const int rowBb1
= (rowB
[k
] >> 10) & 0x1f;
497 const int rowAa0
= (rowA
[j
] >> 15) & 0x1;
498 const int rowAa1
= (rowA
[k
] >> 15) & 0x1;
499 const int rowBa0
= (rowB
[j
] >> 15) & 0x1;
500 const int rowBa1
= (rowB
[k
] >> 15) & 0x1;
501 const int red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
502 const int green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
503 const int blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
504 const int alpha
= (rowAa0
+ rowAa1
+ rowBa0
+ rowBa1
) >> 2;
505 dst
[i
] = (alpha
<< 15) | (blue
<< 10) | (green
<< 5) | red
;
508 else if (datatype
== DTYPE_UBYTE_3_3_2
&& comps
== 3) {
510 const ubyte
*rowA
= (const ubyte
*) srcRowA
;
511 const ubyte
*rowB
= (const ubyte
*) srcRowB
;
512 ubyte
*dst
= (ubyte
*) dstRow
;
513 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
514 i
++, j
+= colStride
, k
+= colStride
) {
515 const int rowAr0
= rowA
[j
] & 0x3;
516 const int rowAr1
= rowA
[k
] & 0x3;
517 const int rowBr0
= rowB
[j
] & 0x3;
518 const int rowBr1
= rowB
[k
] & 0x3;
519 const int rowAg0
= (rowA
[j
] >> 2) & 0x7;
520 const int rowAg1
= (rowA
[k
] >> 2) & 0x7;
521 const int rowBg0
= (rowB
[j
] >> 2) & 0x7;
522 const int rowBg1
= (rowB
[k
] >> 2) & 0x7;
523 const int rowAb0
= (rowA
[j
] >> 5) & 0x7;
524 const int rowAb1
= (rowA
[k
] >> 5) & 0x7;
525 const int rowBb0
= (rowB
[j
] >> 5) & 0x7;
526 const int rowBb1
= (rowB
[k
] >> 5) & 0x7;
527 const int red
= (rowAr0
+ rowAr1
+ rowBr0
+ rowBr1
) >> 2;
528 const int green
= (rowAg0
+ rowAg1
+ rowBg0
+ rowBg1
) >> 2;
529 const int blue
= (rowAb0
+ rowAb1
+ rowBb0
+ rowBb1
) >> 2;
530 dst
[i
] = (blue
<< 5) | (green
<< 2) | red
;
534 debug_printf("bad format in do_row()");
540 * Average together four rows of a source image to produce a single new
541 * row in the dest image. It's legal for the two source rows to point
542 * to the same data. The source width must be equal to either the
543 * dest width or two times the dest width.
545 * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT,
547 * \param comps number of components per pixel (1..4)
548 * \param srcWidth Width of a row in the source data
549 * \param srcRowA Pointer to one of the rows of source data
550 * \param srcRowB Pointer to one of the rows of source data
551 * \param srcRowC Pointer to one of the rows of source data
552 * \param srcRowD Pointer to one of the rows of source data
553 * \param dstWidth Width of a row in the destination data
554 * \param srcRowA Pointer to the row of destination data
557 do_row_3D(enum dtype datatype
, uint comps
, int srcWidth
,
558 const void *srcRowA
, const void *srcRowB
,
559 const void *srcRowC
, const void *srcRowD
,
560 int dstWidth
, void *dstRow
)
562 const uint k0
= (srcWidth
== dstWidth
) ? 0 : 1;
563 const uint colStride
= (srcWidth
== dstWidth
) ? 1 : 2;
569 if ((datatype
== DTYPE_UBYTE
) && (comps
== 4)) {
570 DECLARE_ROW_POINTERS(ubyte
, 4);
572 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
573 i
++, j
+= colStride
, k
+= colStride
) {
580 else if ((datatype
== DTYPE_UBYTE
) && (comps
== 3)) {
581 DECLARE_ROW_POINTERS(ubyte
, 3);
583 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
584 i
++, j
+= colStride
, k
+= colStride
) {
590 else if ((datatype
== DTYPE_UBYTE
) && (comps
== 2)) {
591 DECLARE_ROW_POINTERS(ubyte
, 2);
593 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
594 i
++, j
+= colStride
, k
+= colStride
) {
599 else if ((datatype
== DTYPE_UBYTE
) && (comps
== 1)) {
600 DECLARE_ROW_POINTERS(ubyte
, 1);
602 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
603 i
++, j
+= colStride
, k
+= colStride
) {
607 else if ((datatype
== DTYPE_USHORT
) && (comps
== 4)) {
608 DECLARE_ROW_POINTERS(ushort
, 4);
610 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
611 i
++, j
+= colStride
, k
+= colStride
) {
618 else if ((datatype
== DTYPE_USHORT
) && (comps
== 3)) {
619 DECLARE_ROW_POINTERS(ushort
, 3);
621 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
622 i
++, j
+= colStride
, k
+= colStride
) {
628 else if ((datatype
== DTYPE_USHORT
) && (comps
== 2)) {
629 DECLARE_ROW_POINTERS(ushort
, 2);
631 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
632 i
++, j
+= colStride
, k
+= colStride
) {
637 else if ((datatype
== DTYPE_USHORT
) && (comps
== 1)) {
638 DECLARE_ROW_POINTERS(ushort
, 1);
640 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
641 i
++, j
+= colStride
, k
+= colStride
) {
645 else if ((datatype
== DTYPE_FLOAT
) && (comps
== 4)) {
646 DECLARE_ROW_POINTERS(float, 4);
648 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
649 i
++, j
+= colStride
, k
+= colStride
) {
656 else if ((datatype
== DTYPE_FLOAT
) && (comps
== 3)) {
657 DECLARE_ROW_POINTERS(float, 3);
659 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
660 i
++, j
+= colStride
, k
+= colStride
) {
666 else if ((datatype
== DTYPE_FLOAT
) && (comps
== 2)) {
667 DECLARE_ROW_POINTERS(float, 2);
669 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
670 i
++, j
+= colStride
, k
+= colStride
) {
675 else if ((datatype
== DTYPE_FLOAT
) && (comps
== 1)) {
676 DECLARE_ROW_POINTERS(float, 1);
678 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
679 i
++, j
+= colStride
, k
+= colStride
) {
683 else if ((datatype
== DTYPE_HALF_FLOAT
) && (comps
== 4)) {
684 DECLARE_ROW_POINTERS(half_float
, 4);
686 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
687 i
++, j
+= colStride
, k
+= colStride
) {
694 else if ((datatype
== DTYPE_HALF_FLOAT
) && (comps
== 3)) {
695 DECLARE_ROW_POINTERS(half_float
, 4);
697 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
698 i
++, j
+= colStride
, k
+= colStride
) {
704 else if ((datatype
== DTYPE_HALF_FLOAT
) && (comps
== 2)) {
705 DECLARE_ROW_POINTERS(half_float
, 4);
707 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
708 i
++, j
+= colStride
, k
+= colStride
) {
713 else if ((datatype
== DTYPE_HALF_FLOAT
) && (comps
== 1)) {
714 DECLARE_ROW_POINTERS(half_float
, 4);
716 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
717 i
++, j
+= colStride
, k
+= colStride
) {
721 else if ((datatype
== DTYPE_UINT
) && (comps
== 1)) {
722 const uint
*rowA
= (const uint
*) srcRowA
;
723 const uint
*rowB
= (const uint
*) srcRowB
;
724 const uint
*rowC
= (const uint
*) srcRowC
;
725 const uint
*rowD
= (const uint
*) srcRowD
;
726 float *dst
= (float *) dstRow
;
728 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
729 i
++, j
+= colStride
, k
+= colStride
) {
730 const uint64_t tmp
= (((uint64_t) rowA
[j
] + (uint64_t) rowA
[k
])
731 + ((uint64_t) rowB
[j
] + (uint64_t) rowB
[k
])
732 + ((uint64_t) rowC
[j
] + (uint64_t) rowC
[k
])
733 + ((uint64_t) rowD
[j
] + (uint64_t) rowD
[k
]));
734 dst
[i
] = (float)((double) tmp
* 0.125);
737 else if ((datatype
== DTYPE_USHORT_5_6_5
) && (comps
== 3)) {
738 DECLARE_ROW_POINTERS0(ushort
);
740 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
741 i
++, j
+= colStride
, k
+= colStride
) {
742 const int rowAr0
= rowA
[j
] & 0x1f;
743 const int rowAr1
= rowA
[k
] & 0x1f;
744 const int rowBr0
= rowB
[j
] & 0x1f;
745 const int rowBr1
= rowB
[k
] & 0x1f;
746 const int rowCr0
= rowC
[j
] & 0x1f;
747 const int rowCr1
= rowC
[k
] & 0x1f;
748 const int rowDr0
= rowD
[j
] & 0x1f;
749 const int rowDr1
= rowD
[k
] & 0x1f;
750 const int rowAg0
= (rowA
[j
] >> 5) & 0x3f;
751 const int rowAg1
= (rowA
[k
] >> 5) & 0x3f;
752 const int rowBg0
= (rowB
[j
] >> 5) & 0x3f;
753 const int rowBg1
= (rowB
[k
] >> 5) & 0x3f;
754 const int rowCg0
= (rowC
[j
] >> 5) & 0x3f;
755 const int rowCg1
= (rowC
[k
] >> 5) & 0x3f;
756 const int rowDg0
= (rowD
[j
] >> 5) & 0x3f;
757 const int rowDg1
= (rowD
[k
] >> 5) & 0x3f;
758 const int rowAb0
= (rowA
[j
] >> 11) & 0x1f;
759 const int rowAb1
= (rowA
[k
] >> 11) & 0x1f;
760 const int rowBb0
= (rowB
[j
] >> 11) & 0x1f;
761 const int rowBb1
= (rowB
[k
] >> 11) & 0x1f;
762 const int rowCb0
= (rowC
[j
] >> 11) & 0x1f;
763 const int rowCb1
= (rowC
[k
] >> 11) & 0x1f;
764 const int rowDb0
= (rowD
[j
] >> 11) & 0x1f;
765 const int rowDb1
= (rowD
[k
] >> 11) & 0x1f;
766 const int r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
767 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
768 const int g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
769 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
770 const int b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
771 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
772 dst
[i
] = (b
<< 11) | (g
<< 5) | r
;
775 else if ((datatype
== DTYPE_USHORT_4_4_4_4
) && (comps
== 4)) {
776 DECLARE_ROW_POINTERS0(ushort
);
778 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
779 i
++, j
+= colStride
, k
+= colStride
) {
780 const int rowAr0
= rowA
[j
] & 0xf;
781 const int rowAr1
= rowA
[k
] & 0xf;
782 const int rowBr0
= rowB
[j
] & 0xf;
783 const int rowBr1
= rowB
[k
] & 0xf;
784 const int rowCr0
= rowC
[j
] & 0xf;
785 const int rowCr1
= rowC
[k
] & 0xf;
786 const int rowDr0
= rowD
[j
] & 0xf;
787 const int rowDr1
= rowD
[k
] & 0xf;
788 const int rowAg0
= (rowA
[j
] >> 4) & 0xf;
789 const int rowAg1
= (rowA
[k
] >> 4) & 0xf;
790 const int rowBg0
= (rowB
[j
] >> 4) & 0xf;
791 const int rowBg1
= (rowB
[k
] >> 4) & 0xf;
792 const int rowCg0
= (rowC
[j
] >> 4) & 0xf;
793 const int rowCg1
= (rowC
[k
] >> 4) & 0xf;
794 const int rowDg0
= (rowD
[j
] >> 4) & 0xf;
795 const int rowDg1
= (rowD
[k
] >> 4) & 0xf;
796 const int rowAb0
= (rowA
[j
] >> 8) & 0xf;
797 const int rowAb1
= (rowA
[k
] >> 8) & 0xf;
798 const int rowBb0
= (rowB
[j
] >> 8) & 0xf;
799 const int rowBb1
= (rowB
[k
] >> 8) & 0xf;
800 const int rowCb0
= (rowC
[j
] >> 8) & 0xf;
801 const int rowCb1
= (rowC
[k
] >> 8) & 0xf;
802 const int rowDb0
= (rowD
[j
] >> 8) & 0xf;
803 const int rowDb1
= (rowD
[k
] >> 8) & 0xf;
804 const int rowAa0
= (rowA
[j
] >> 12) & 0xf;
805 const int rowAa1
= (rowA
[k
] >> 12) & 0xf;
806 const int rowBa0
= (rowB
[j
] >> 12) & 0xf;
807 const int rowBa1
= (rowB
[k
] >> 12) & 0xf;
808 const int rowCa0
= (rowC
[j
] >> 12) & 0xf;
809 const int rowCa1
= (rowC
[k
] >> 12) & 0xf;
810 const int rowDa0
= (rowD
[j
] >> 12) & 0xf;
811 const int rowDa1
= (rowD
[k
] >> 12) & 0xf;
812 const int r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
813 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
814 const int g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
815 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
816 const int b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
817 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
818 const int a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
819 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
821 dst
[i
] = (a
<< 12) | (b
<< 8) | (g
<< 4) | r
;
824 else if ((datatype
== DTYPE_USHORT_1_5_5_5_REV
) && (comps
== 4)) {
825 DECLARE_ROW_POINTERS0(ushort
);
827 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
828 i
++, j
+= colStride
, k
+= colStride
) {
829 const int rowAr0
= rowA
[j
] & 0x1f;
830 const int rowAr1
= rowA
[k
] & 0x1f;
831 const int rowBr0
= rowB
[j
] & 0x1f;
832 const int rowBr1
= rowB
[k
] & 0x1f;
833 const int rowCr0
= rowC
[j
] & 0x1f;
834 const int rowCr1
= rowC
[k
] & 0x1f;
835 const int rowDr0
= rowD
[j
] & 0x1f;
836 const int rowDr1
= rowD
[k
] & 0x1f;
837 const int rowAg0
= (rowA
[j
] >> 5) & 0x1f;
838 const int rowAg1
= (rowA
[k
] >> 5) & 0x1f;
839 const int rowBg0
= (rowB
[j
] >> 5) & 0x1f;
840 const int rowBg1
= (rowB
[k
] >> 5) & 0x1f;
841 const int rowCg0
= (rowC
[j
] >> 5) & 0x1f;
842 const int rowCg1
= (rowC
[k
] >> 5) & 0x1f;
843 const int rowDg0
= (rowD
[j
] >> 5) & 0x1f;
844 const int rowDg1
= (rowD
[k
] >> 5) & 0x1f;
845 const int rowAb0
= (rowA
[j
] >> 10) & 0x1f;
846 const int rowAb1
= (rowA
[k
] >> 10) & 0x1f;
847 const int rowBb0
= (rowB
[j
] >> 10) & 0x1f;
848 const int rowBb1
= (rowB
[k
] >> 10) & 0x1f;
849 const int rowCb0
= (rowC
[j
] >> 10) & 0x1f;
850 const int rowCb1
= (rowC
[k
] >> 10) & 0x1f;
851 const int rowDb0
= (rowD
[j
] >> 10) & 0x1f;
852 const int rowDb1
= (rowD
[k
] >> 10) & 0x1f;
853 const int rowAa0
= (rowA
[j
] >> 15) & 0x1;
854 const int rowAa1
= (rowA
[k
] >> 15) & 0x1;
855 const int rowBa0
= (rowB
[j
] >> 15) & 0x1;
856 const int rowBa1
= (rowB
[k
] >> 15) & 0x1;
857 const int rowCa0
= (rowC
[j
] >> 15) & 0x1;
858 const int rowCa1
= (rowC
[k
] >> 15) & 0x1;
859 const int rowDa0
= (rowD
[j
] >> 15) & 0x1;
860 const int rowDa1
= (rowD
[k
] >> 15) & 0x1;
861 const int r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
862 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
863 const int g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
864 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
865 const int b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
866 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
867 const int a
= FILTER_SUM_3D(rowAa0
, rowAa1
, rowBa0
, rowBa1
,
868 rowCa0
, rowCa1
, rowDa0
, rowDa1
);
870 dst
[i
] = (a
<< 15) | (b
<< 10) | (g
<< 5) | r
;
873 else if ((datatype
== DTYPE_UBYTE_3_3_2
) && (comps
== 3)) {
874 DECLARE_ROW_POINTERS0(ushort
);
876 for (i
= j
= 0, k
= k0
; i
< (uint
) dstWidth
;
877 i
++, j
+= colStride
, k
+= colStride
) {
878 const int rowAr0
= rowA
[j
] & 0x3;
879 const int rowAr1
= rowA
[k
] & 0x3;
880 const int rowBr0
= rowB
[j
] & 0x3;
881 const int rowBr1
= rowB
[k
] & 0x3;
882 const int rowCr0
= rowC
[j
] & 0x3;
883 const int rowCr1
= rowC
[k
] & 0x3;
884 const int rowDr0
= rowD
[j
] & 0x3;
885 const int rowDr1
= rowD
[k
] & 0x3;
886 const int rowAg0
= (rowA
[j
] >> 2) & 0x7;
887 const int rowAg1
= (rowA
[k
] >> 2) & 0x7;
888 const int rowBg0
= (rowB
[j
] >> 2) & 0x7;
889 const int rowBg1
= (rowB
[k
] >> 2) & 0x7;
890 const int rowCg0
= (rowC
[j
] >> 2) & 0x7;
891 const int rowCg1
= (rowC
[k
] >> 2) & 0x7;
892 const int rowDg0
= (rowD
[j
] >> 2) & 0x7;
893 const int rowDg1
= (rowD
[k
] >> 2) & 0x7;
894 const int rowAb0
= (rowA
[j
] >> 5) & 0x7;
895 const int rowAb1
= (rowA
[k
] >> 5) & 0x7;
896 const int rowBb0
= (rowB
[j
] >> 5) & 0x7;
897 const int rowBb1
= (rowB
[k
] >> 5) & 0x7;
898 const int rowCb0
= (rowC
[j
] >> 5) & 0x7;
899 const int rowCb1
= (rowC
[k
] >> 5) & 0x7;
900 const int rowDb0
= (rowD
[j
] >> 5) & 0x7;
901 const int rowDb1
= (rowD
[k
] >> 5) & 0x7;
902 const int r
= FILTER_SUM_3D(rowAr0
, rowAr1
, rowBr0
, rowBr1
,
903 rowCr0
, rowCr1
, rowDr0
, rowDr1
);
904 const int g
= FILTER_SUM_3D(rowAg0
, rowAg1
, rowBg0
, rowBg1
,
905 rowCg0
, rowCg1
, rowDg0
, rowDg1
);
906 const int b
= FILTER_SUM_3D(rowAb0
, rowAb1
, rowBb0
, rowBb1
,
907 rowCb0
, rowCb1
, rowDb0
, rowDb1
);
908 dst
[i
] = (b
<< 5) | (g
<< 2) | r
;
912 debug_printf("bad format in do_row_3D()");
919 format_to_type_comps(enum pipe_format pformat
,
920 enum dtype
*datatype
, uint
*comps
)
922 /* XXX I think this could be implemented in terms of the pf_*() functions */
924 case PIPE_FORMAT_A8R8G8B8_UNORM
:
925 case PIPE_FORMAT_X8R8G8B8_UNORM
:
926 case PIPE_FORMAT_B8G8R8A8_UNORM
:
927 case PIPE_FORMAT_B8G8R8X8_UNORM
:
928 case PIPE_FORMAT_R8G8B8A8_SRGB
:
929 case PIPE_FORMAT_R8G8B8X8_SRGB
:
930 case PIPE_FORMAT_A8R8G8B8_SRGB
:
931 case PIPE_FORMAT_X8R8G8B8_SRGB
:
932 case PIPE_FORMAT_B8G8R8A8_SRGB
:
933 case PIPE_FORMAT_B8G8R8X8_SRGB
:
934 case PIPE_FORMAT_R8G8B8_SRGB
:
935 *datatype
= DTYPE_UBYTE
;
938 case PIPE_FORMAT_A1R5G5B5_UNORM
:
939 *datatype
= DTYPE_USHORT_1_5_5_5_REV
;
942 case PIPE_FORMAT_A4R4G4B4_UNORM
:
943 *datatype
= DTYPE_USHORT_4_4_4_4
;
946 case PIPE_FORMAT_R5G6B5_UNORM
:
947 *datatype
= DTYPE_USHORT_5_6_5
;
950 case PIPE_FORMAT_L8_UNORM
:
951 case PIPE_FORMAT_L8_SRGB
:
952 case PIPE_FORMAT_A8_UNORM
:
953 case PIPE_FORMAT_I8_UNORM
:
954 *datatype
= DTYPE_UBYTE
;
957 case PIPE_FORMAT_A8L8_UNORM
:
958 case PIPE_FORMAT_A8L8_SRGB
:
959 *datatype
= DTYPE_UBYTE
;
964 *datatype
= DTYPE_UBYTE
;
972 reduce_1d(enum pipe_format pformat
,
973 int srcWidth
, const ubyte
*srcPtr
,
974 int dstWidth
, ubyte
*dstPtr
)
979 format_to_type_comps(pformat
, &datatype
, &comps
);
981 /* we just duplicate the input row, kind of hack, saves code */
982 do_row(datatype
, comps
,
983 srcWidth
, srcPtr
, srcPtr
,
989 * Strides are in bytes. If zero, it'll be computed as width * bpp.
992 reduce_2d(enum pipe_format pformat
,
993 int srcWidth
, int srcHeight
,
994 int srcRowStride
, const ubyte
*srcPtr
,
995 int dstWidth
, int dstHeight
,
996 int dstRowStride
, ubyte
*dstPtr
)
1000 const int bpt
= util_format_get_size(pformat
);
1001 const ubyte
*srcA
, *srcB
;
1005 format_to_type_comps(pformat
, &datatype
, &comps
);
1008 srcRowStride
= bpt
* srcWidth
;
1011 dstRowStride
= bpt
* dstWidth
;
1013 /* Compute src and dst pointers */
1016 srcB
= srcA
+ srcRowStride
;
1021 for (row
= 0; row
< dstHeight
; row
++) {
1022 do_row(datatype
, comps
,
1023 srcWidth
, srcA
, srcB
,
1025 srcA
+= 2 * srcRowStride
;
1026 srcB
+= 2 * srcRowStride
;
1027 dst
+= dstRowStride
;
1033 reduce_3d(enum pipe_format pformat
,
1034 int srcWidth
, int srcHeight
, int srcDepth
,
1035 int srcRowStride
, const ubyte
*srcPtr
,
1036 int dstWidth
, int dstHeight
, int dstDepth
,
1037 int dstRowStride
, ubyte
*dstPtr
)
1039 const int bpt
= util_format_get_size(pformat
);
1040 const int border
= 0;
1042 int bytesPerSrcImage
, bytesPerDstImage
;
1043 int bytesPerSrcRow
, bytesPerDstRow
;
1044 int srcImageOffset
, srcRowOffset
;
1045 enum dtype datatype
;
1048 format_to_type_comps(pformat
, &datatype
, &comps
);
1050 bytesPerSrcImage
= srcWidth
* srcHeight
* bpt
;
1051 bytesPerDstImage
= dstWidth
* dstHeight
* bpt
;
1053 bytesPerSrcRow
= srcWidth
* bpt
;
1054 bytesPerDstRow
= dstWidth
* bpt
;
1056 /* Offset between adjacent src images to be averaged together */
1057 srcImageOffset
= (srcDepth
== dstDepth
) ? 0 : bytesPerSrcImage
;
1059 /* Offset between adjacent src rows to be averaged together */
1060 srcRowOffset
= (srcHeight
== dstHeight
) ? 0 : srcWidth
* bpt
;
1063 * Need to average together up to 8 src pixels for each dest pixel.
1064 * Break that down into 3 operations:
1065 * 1. take two rows from source image and average them together.
1066 * 2. take two rows from next source image and average them together.
1067 * 3. take the two averaged rows and average them for the final dst row.
1071 _mesa_printf("mip3d %d x %d x %d -> %d x %d x %d\n",
1072 srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth);
1075 for (img
= 0; img
< dstDepth
; img
++) {
1076 /* first source image pointer, skipping border */
1077 const ubyte
*imgSrcA
= srcPtr
1078 + (bytesPerSrcImage
+ bytesPerSrcRow
+ border
) * bpt
* border
1079 + img
* (bytesPerSrcImage
+ srcImageOffset
);
1080 /* second source image pointer, skipping border */
1081 const ubyte
*imgSrcB
= imgSrcA
+ srcImageOffset
;
1082 /* address of the dest image, skipping border */
1083 ubyte
*imgDst
= dstPtr
1084 + (bytesPerDstImage
+ bytesPerDstRow
+ border
) * bpt
* border
1085 + img
* bytesPerDstImage
;
1087 /* setup the four source row pointers and the dest row pointer */
1088 const ubyte
*srcImgARowA
= imgSrcA
;
1089 const ubyte
*srcImgARowB
= imgSrcA
+ srcRowOffset
;
1090 const ubyte
*srcImgBRowA
= imgSrcB
;
1091 const ubyte
*srcImgBRowB
= imgSrcB
+ srcRowOffset
;
1092 ubyte
*dstImgRow
= imgDst
;
1094 for (row
= 0; row
< dstHeight
; row
++) {
1095 do_row_3D(datatype
, comps
, srcWidth
,
1096 srcImgARowA
, srcImgARowB
,
1097 srcImgBRowA
, srcImgBRowB
,
1098 dstWidth
, dstImgRow
);
1100 /* advance to next rows */
1101 srcImgARowA
+= bytesPerSrcRow
+ srcRowOffset
;
1102 srcImgARowB
+= bytesPerSrcRow
+ srcRowOffset
;
1103 srcImgBRowA
+= bytesPerSrcRow
+ srcRowOffset
;
1104 srcImgBRowB
+= bytesPerSrcRow
+ srcRowOffset
;
1105 dstImgRow
+= bytesPerDstRow
;
1114 make_1d_mipmap(struct gen_mipmap_state
*ctx
,
1115 struct pipe_texture
*pt
,
1116 uint face
, uint baseLevel
, uint lastLevel
)
1118 struct pipe_context
*pipe
= ctx
->pipe
;
1119 struct pipe_screen
*screen
= pipe
->screen
;
1120 const uint zslice
= 0;
1123 for (dstLevel
= baseLevel
+ 1; dstLevel
<= lastLevel
; dstLevel
++) {
1124 const uint srcLevel
= dstLevel
- 1;
1125 struct pipe_transfer
*srcTrans
, *dstTrans
;
1126 void *srcMap
, *dstMap
;
1128 srcTrans
= screen
->get_tex_transfer(screen
, pt
, face
, srcLevel
, zslice
,
1129 PIPE_TRANSFER_READ
, 0, 0,
1130 u_minify(pt
->width0
, srcLevel
),
1131 u_minify(pt
->height0
, srcLevel
));
1132 dstTrans
= screen
->get_tex_transfer(screen
, pt
, face
, dstLevel
, zslice
,
1133 PIPE_TRANSFER_WRITE
, 0, 0,
1134 u_minify(pt
->width0
, dstLevel
),
1135 u_minify(pt
->height0
, dstLevel
));
1137 srcMap
= (ubyte
*) screen
->transfer_map(screen
, srcTrans
);
1138 dstMap
= (ubyte
*) screen
->transfer_map(screen
, dstTrans
);
1140 reduce_1d(pt
->format
,
1141 srcTrans
->width
, srcMap
,
1142 dstTrans
->width
, dstMap
);
1144 screen
->transfer_unmap(screen
, srcTrans
);
1145 screen
->transfer_unmap(screen
, dstTrans
);
1147 screen
->tex_transfer_destroy(srcTrans
);
1148 screen
->tex_transfer_destroy(dstTrans
);
1154 make_2d_mipmap(struct gen_mipmap_state
*ctx
,
1155 struct pipe_texture
*pt
,
1156 uint face
, uint baseLevel
, uint lastLevel
)
1158 struct pipe_context
*pipe
= ctx
->pipe
;
1159 struct pipe_screen
*screen
= pipe
->screen
;
1160 const uint zslice
= 0;
1163 assert(pt
->block
.width
== 1);
1164 assert(pt
->block
.height
== 1);
1166 for (dstLevel
= baseLevel
+ 1; dstLevel
<= lastLevel
; dstLevel
++) {
1167 const uint srcLevel
= dstLevel
- 1;
1168 struct pipe_transfer
*srcTrans
, *dstTrans
;
1169 ubyte
*srcMap
, *dstMap
;
1171 srcTrans
= screen
->get_tex_transfer(screen
, pt
, face
, srcLevel
, zslice
,
1172 PIPE_TRANSFER_READ
, 0, 0,
1173 u_minify(pt
->width0
, srcLevel
),
1174 u_minify(pt
->height0
, srcLevel
));
1175 dstTrans
= screen
->get_tex_transfer(screen
, pt
, face
, dstLevel
, zslice
,
1176 PIPE_TRANSFER_WRITE
, 0, 0,
1177 u_minify(pt
->width0
, dstLevel
),
1178 u_minify(pt
->height0
, dstLevel
));
1180 srcMap
= (ubyte
*) screen
->transfer_map(screen
, srcTrans
);
1181 dstMap
= (ubyte
*) screen
->transfer_map(screen
, dstTrans
);
1183 reduce_2d(pt
->format
,
1184 srcTrans
->width
, srcTrans
->height
,
1185 srcTrans
->stride
, srcMap
,
1186 dstTrans
->width
, dstTrans
->height
,
1187 dstTrans
->stride
, dstMap
);
1189 screen
->transfer_unmap(screen
, srcTrans
);
1190 screen
->transfer_unmap(screen
, dstTrans
);
1192 screen
->tex_transfer_destroy(srcTrans
);
1193 screen
->tex_transfer_destroy(dstTrans
);
1199 make_3d_mipmap(struct gen_mipmap_state
*ctx
,
1200 struct pipe_texture
*pt
,
1201 uint face
, uint baseLevel
, uint lastLevel
)
1204 struct pipe_context
*pipe
= ctx
->pipe
;
1205 struct pipe_screen
*screen
= pipe
->screen
;
1206 uint dstLevel
, zslice
= 0;
1208 assert(pt
->block
.width
== 1);
1209 assert(pt
->block
.height
== 1);
1211 for (dstLevel
= baseLevel
+ 1; dstLevel
<= lastLevel
; dstLevel
++) {
1212 const uint srcLevel
= dstLevel
- 1;
1213 struct pipe_transfer
*srcTrans
, *dstTrans
;
1214 ubyte
*srcMap
, *dstMap
;
1216 srcTrans
= screen
->get_tex_transfer(screen
, pt
, face
, srcLevel
, zslice
,
1217 PIPE_TRANSFER_READ
, 0, 0,
1218 u_minify(pt
->width0
, srcLevel
),
1219 u_minify(pt
->height0
, srcLevel
));
1220 dstTrans
= screen
->get_tex_transfer(screen
, pt
, face
, dstLevel
, zslice
,
1221 PIPE_TRANSFER_WRITE
, 0, 0,
1222 u_minify(pt
->width0
, dstLevel
),
1223 u_minify(pt
->height0
, dstLevel
));
1225 srcMap
= (ubyte
*) screen
->transfer_map(screen
, srcTrans
);
1226 dstMap
= (ubyte
*) screen
->transfer_map(screen
, dstTrans
);
1228 reduce_3d(pt
->format
,
1229 srcTrans
->width
, srcTrans
->height
,
1230 srcTrans
->stride
, srcMap
,
1231 dstTrans
->width
, dstTrans
->height
,
1232 dstTrans
->stride
, dstMap
);
1234 screen
->transfer_unmap(screen
, srcTrans
);
1235 screen
->transfer_unmap(screen
, dstTrans
);
1237 screen
->tex_transfer_destroy(srcTrans
);
1238 screen
->tex_transfer_destroy(dstTrans
);
1247 fallback_gen_mipmap(struct gen_mipmap_state
*ctx
,
1248 struct pipe_texture
*pt
,
1249 uint face
, uint baseLevel
, uint lastLevel
)
1251 switch (pt
->target
) {
1252 case PIPE_TEXTURE_1D
:
1253 make_1d_mipmap(ctx
, pt
, face
, baseLevel
, lastLevel
);
1255 case PIPE_TEXTURE_2D
:
1256 case PIPE_TEXTURE_CUBE
:
1257 make_2d_mipmap(ctx
, pt
, face
, baseLevel
, lastLevel
);
1259 case PIPE_TEXTURE_3D
:
1260 make_3d_mipmap(ctx
, pt
, face
, baseLevel
, lastLevel
);
1269 * Create a mipmap generation context.
1270 * The idea is to create one of these and re-use it each time we need to
1271 * generate a mipmap.
1273 struct gen_mipmap_state
*
1274 util_create_gen_mipmap(struct pipe_context
*pipe
,
1275 struct cso_context
*cso
)
1277 struct gen_mipmap_state
*ctx
;
1280 ctx
= CALLOC_STRUCT(gen_mipmap_state
);
1287 /* disabled blending/masking */
1288 memset(&ctx
->blend
, 0, sizeof(ctx
->blend
));
1289 ctx
->blend
.colormask
= PIPE_MASK_RGBA
;
1291 /* no-op depth/stencil/alpha */
1292 memset(&ctx
->depthstencil
, 0, sizeof(ctx
->depthstencil
));
1295 memset(&ctx
->rasterizer
, 0, sizeof(ctx
->rasterizer
));
1296 ctx
->rasterizer
.front_winding
= PIPE_WINDING_CW
;
1297 ctx
->rasterizer
.cull_mode
= PIPE_WINDING_NONE
;
1298 ctx
->rasterizer
.bypass_vs_clip_and_viewport
= 1;
1299 ctx
->rasterizer
.gl_rasterization_rules
= 1;
1302 memset(&ctx
->sampler
, 0, sizeof(ctx
->sampler
));
1303 ctx
->sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
1304 ctx
->sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
1305 ctx
->sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
1306 ctx
->sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NEAREST
;
1307 ctx
->sampler
.normalized_coords
= 1;
1309 /* vertex shader - still needed to specify mapping from fragment
1310 * shader input semantics to vertex elements
1313 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
1314 TGSI_SEMANTIC_GENERIC
};
1315 const uint semantic_indexes
[] = { 0, 0 };
1316 ctx
->vs
= util_make_vertex_passthrough_shader(pipe
, 2, semantic_names
,
1320 /* fragment shader */
1321 ctx
->fs
= util_make_fragment_tex_shader(pipe
);
1323 /* vertex data that doesn't change */
1324 for (i
= 0; i
< 4; i
++) {
1325 ctx
->vertices
[i
][0][2] = 0.0f
; /* z */
1326 ctx
->vertices
[i
][0][3] = 1.0f
; /* w */
1327 ctx
->vertices
[i
][1][3] = 1.0f
; /* q */
1330 /* Note: the actual vertex buffer is allocated as needed below */
1337 * Get next "slot" of vertex space in the vertex buffer.
1338 * We're allocating one large vertex buffer and using it piece by piece.
1341 get_next_slot(struct gen_mipmap_state
*ctx
)
1343 const unsigned max_slots
= 4096 / sizeof ctx
->vertices
;
1345 if (ctx
->vbuf_slot
>= max_slots
)
1346 util_gen_mipmap_flush( ctx
);
1349 ctx
->vbuf
= pipe_buffer_create(ctx
->pipe
->screen
,
1351 PIPE_BUFFER_USAGE_VERTEX
,
1352 max_slots
* sizeof ctx
->vertices
);
1355 return ctx
->vbuf_slot
++ * sizeof ctx
->vertices
;
1360 set_vertex_data(struct gen_mipmap_state
*ctx
,
1361 enum pipe_texture_target tex_target
,
1362 uint face
, float width
, float height
)
1366 /* vert[0].position */
1367 ctx
->vertices
[0][0][0] = 0.0f
; /*x*/
1368 ctx
->vertices
[0][0][1] = 0.0f
; /*y*/
1370 /* vert[1].position */
1371 ctx
->vertices
[1][0][0] = width
;
1372 ctx
->vertices
[1][0][1] = 0.0f
;
1374 /* vert[2].position */
1375 ctx
->vertices
[2][0][0] = width
;
1376 ctx
->vertices
[2][0][1] = height
;
1378 /* vert[3].position */
1379 ctx
->vertices
[3][0][0] = 0.0f
;
1380 ctx
->vertices
[3][0][1] = height
;
1382 /* Setup vertex texcoords. This is a little tricky for cube maps. */
1383 if (tex_target
== PIPE_TEXTURE_CUBE
) {
1384 static const float st
[4][2] = {
1385 {0.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 1.0f
}
1390 /* loop over quad verts */
1391 for (i
= 0; i
< 4; i
++) {
1392 /* Compute sc = +/-scale and tc = +/-scale.
1393 * Not +/-1 to avoid cube face selection ambiguity near the edges,
1394 * though that can still sometimes happen with this scale factor...
1396 const float scale
= 0.9999f
;
1397 const float sc
= (2.0f
* st
[i
][0] - 1.0f
) * scale
;
1398 const float tc
= (2.0f
* st
[i
][1] - 1.0f
) * scale
;
1401 case PIPE_TEX_FACE_POS_X
:
1406 case PIPE_TEX_FACE_NEG_X
:
1411 case PIPE_TEX_FACE_POS_Y
:
1416 case PIPE_TEX_FACE_NEG_Y
:
1421 case PIPE_TEX_FACE_POS_Z
:
1426 case PIPE_TEX_FACE_NEG_Z
:
1432 rx
= ry
= rz
= 0.0f
;
1436 ctx
->vertices
[i
][1][0] = rx
; /*s*/
1437 ctx
->vertices
[i
][1][1] = ry
; /*t*/
1438 ctx
->vertices
[i
][1][2] = rz
; /*r*/
1443 ctx
->vertices
[0][1][0] = 0.0f
; /*s*/
1444 ctx
->vertices
[0][1][1] = 0.0f
; /*t*/
1445 ctx
->vertices
[0][1][2] = 0.0f
; /*r*/
1447 ctx
->vertices
[1][1][0] = 1.0f
;
1448 ctx
->vertices
[1][1][1] = 0.0f
;
1449 ctx
->vertices
[1][1][2] = 0.0f
;
1451 ctx
->vertices
[2][1][0] = 1.0f
;
1452 ctx
->vertices
[2][1][1] = 1.0f
;
1453 ctx
->vertices
[2][1][2] = 0.0f
;
1455 ctx
->vertices
[3][1][0] = 0.0f
;
1456 ctx
->vertices
[3][1][1] = 1.0f
;
1457 ctx
->vertices
[3][1][2] = 0.0f
;
1460 offset
= get_next_slot( ctx
);
1462 pipe_buffer_write(ctx
->pipe
->screen
, ctx
->vbuf
,
1463 offset
, sizeof(ctx
->vertices
), ctx
->vertices
);
1471 * Destroy a mipmap generation context
1474 util_destroy_gen_mipmap(struct gen_mipmap_state
*ctx
)
1476 struct pipe_context
*pipe
= ctx
->pipe
;
1478 pipe
->delete_vs_state(pipe
, ctx
->vs
);
1479 pipe
->delete_fs_state(pipe
, ctx
->fs
);
1481 pipe_buffer_reference(&ctx
->vbuf
, NULL
);
1488 /* Release vertex buffer at end of frame to avoid synchronous
1491 void util_gen_mipmap_flush( struct gen_mipmap_state
*ctx
)
1493 pipe_buffer_reference(&ctx
->vbuf
, NULL
);
1499 * Generate mipmap images. It's assumed all needed texture memory is
1500 * already allocated.
1502 * \param pt the texture to generate mipmap levels for
1503 * \param face which cube face to generate mipmaps for (0 for non-cube maps)
1504 * \param baseLevel the first mipmap level to use as a src
1505 * \param lastLevel the last mipmap level to generate
1506 * \param filter the minification filter used to generate mipmap levels with
1507 * \param filter one of PIPE_TEX_FILTER_LINEAR, PIPE_TEX_FILTER_NEAREST
1510 util_gen_mipmap(struct gen_mipmap_state
*ctx
,
1511 struct pipe_texture
*pt
,
1512 uint face
, uint baseLevel
, uint lastLevel
, uint filter
)
1514 struct pipe_context
*pipe
= ctx
->pipe
;
1515 struct pipe_screen
*screen
= pipe
->screen
;
1516 struct pipe_framebuffer_state fb
;
1521 /* The texture object should have room for the levels which we're
1522 * about to generate.
1524 assert(lastLevel
<= pt
->last_level
);
1526 /* If this fails, why are we here? */
1527 assert(lastLevel
> baseLevel
);
1529 assert(filter
== PIPE_TEX_FILTER_LINEAR
||
1530 filter
== PIPE_TEX_FILTER_NEAREST
);
1532 /* check if we can render in the texture's format */
1533 if (!screen
->is_format_supported(screen
, pt
->format
, PIPE_TEXTURE_2D
,
1534 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
1535 fallback_gen_mipmap(ctx
, pt
, face
, baseLevel
, lastLevel
);
1539 /* save state (restored below) */
1540 cso_save_blend(ctx
->cso
);
1541 cso_save_depth_stencil_alpha(ctx
->cso
);
1542 cso_save_rasterizer(ctx
->cso
);
1543 cso_save_samplers(ctx
->cso
);
1544 cso_save_sampler_textures(ctx
->cso
);
1545 cso_save_framebuffer(ctx
->cso
);
1546 cso_save_fragment_shader(ctx
->cso
);
1547 cso_save_vertex_shader(ctx
->cso
);
1549 /* bind our state */
1550 cso_set_blend(ctx
->cso
, &ctx
->blend
);
1551 cso_set_depth_stencil_alpha(ctx
->cso
, &ctx
->depthstencil
);
1552 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
1554 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs
);
1555 cso_set_vertex_shader_handle(ctx
->cso
, ctx
->vs
);
1557 /* init framebuffer state */
1558 memset(&fb
, 0, sizeof(fb
));
1561 /* set min/mag to same filter for faster sw speed */
1562 ctx
->sampler
.mag_img_filter
= filter
;
1563 ctx
->sampler
.min_img_filter
= filter
;
1566 * XXX for small mipmap levels, it may be faster to use the software
1569 for (dstLevel
= baseLevel
+ 1; dstLevel
<= lastLevel
; dstLevel
++) {
1570 const uint srcLevel
= dstLevel
- 1;
1572 struct pipe_surface
*surf
=
1573 screen
->get_tex_surface(screen
, pt
, face
, dstLevel
, zslice
,
1574 PIPE_BUFFER_USAGE_GPU_WRITE
);
1577 * Setup framebuffer / dest surface
1580 fb
.width
= u_minify(pt
->width0
, dstLevel
);
1581 fb
.height
= u_minify(pt
->height0
, dstLevel
);
1582 cso_set_framebuffer(ctx
->cso
, &fb
);
1585 * Setup sampler state
1586 * Note: we should only have to set the min/max LOD clamps to ensure
1587 * we grab texels from the right mipmap level. But some hardware
1588 * has trouble with min clamping so we also set the lod_bias to
1589 * try to work around that.
1591 ctx
->sampler
.min_lod
= ctx
->sampler
.max_lod
= (float) srcLevel
;
1592 ctx
->sampler
.lod_bias
= (float) srcLevel
;
1593 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
1594 cso_single_sampler_done(ctx
->cso
);
1596 cso_set_sampler_textures(ctx
->cso
, 1, &pt
);
1598 /* quad coords in window coords (bypassing vs, clip and viewport) */
1599 offset
= set_vertex_data(ctx
,
1602 (float) u_minify(pt
->width0
, dstLevel
),
1603 (float) u_minify(pt
->height0
, dstLevel
));
1605 util_draw_vertex_buffer(ctx
->pipe
,
1608 PIPE_PRIM_TRIANGLE_FAN
,
1610 2); /* attribs/vert */
1612 pipe
->flush(pipe
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
1614 /* need to signal that the texture has changed _after_ rendering to it */
1615 pipe_surface_reference( &surf
, NULL
);
1618 /* restore state we changed */
1619 cso_restore_blend(ctx
->cso
);
1620 cso_restore_depth_stencil_alpha(ctx
->cso
);
1621 cso_restore_rasterizer(ctx
->cso
);
1622 cso_restore_samplers(ctx
->cso
);
1623 cso_restore_sampler_textures(ctx
->cso
);
1624 cso_restore_framebuffer(ctx
->cso
);
1625 cso_restore_fragment_shader(ctx
->cso
);
1626 cso_restore_vertex_shader(ctx
->cso
);