util/format: Add VK_FORMAT_D16_UNORM_S8_UINT.
[mesa.git] / src / util / format / u_format_zs.c
1 /**************************************************************************
2 *
3 * Copyright 2010 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 **************************************************************************/
27
28
29 #include "util/format/u_format_zs.h"
30 #include "util/u_math.h"
31
32
33 /*
34 * z32_unorm conversion functions
35 */
36
37 static inline uint16_t
38 z32_unorm_to_z16_unorm(uint32_t z)
39 {
40 /* z * 0xffff / 0xffffffff */
41 return z >> 16;
42 }
43
44 static inline uint32_t
45 z16_unorm_to_z32_unorm(uint16_t z)
46 {
47 /* z * 0xffffffff / 0xffff */
48 return ((uint32_t)z << 16) | z;
49 }
50
51 static inline uint32_t
52 z32_unorm_to_z24_unorm(uint32_t z)
53 {
54 /* z * 0xffffff / 0xffffffff */
55 return z >> 8;
56 }
57
58 static inline uint32_t
59 z24_unorm_to_z32_unorm(uint32_t z)
60 {
61 /* z * 0xffffffff / 0xffffff */
62 return (z << 8) | (z >> 16);
63 }
64
65
66 /*
67 * z32_float conversion functions
68 */
69
70 static inline uint16_t
71 z32_float_to_z16_unorm(float z)
72 {
73 const float scale = 0xffff;
74 return (uint16_t)(z * scale + 0.5f);
75 }
76
77 static inline float
78 z16_unorm_to_z32_float(uint16_t z)
79 {
80 const float scale = 1.0 / 0xffff;
81 return (float)(z * scale);
82 }
83
84 static inline uint32_t
85 z32_float_to_z24_unorm(float z)
86 {
87 const double scale = 0xffffff;
88 return (uint32_t)(z * scale) & 0xffffff;
89 }
90
91 static inline float
92 z24_unorm_to_z32_float(uint32_t z)
93 {
94 const double scale = 1.0 / 0xffffff;
95 return (float)(z * scale);
96 }
97
98 static inline uint32_t
99 z32_float_to_z32_unorm(float z)
100 {
101 const double scale = 0xffffffff;
102 return (uint32_t)(z * scale);
103 }
104
105 static inline float
106 z32_unorm_to_z32_float(uint32_t z)
107 {
108 const double scale = 1.0 / 0xffffffff;
109 return (float)(z * scale);
110 }
111
112
113 void
114 util_format_s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
115 const uint8_t *src_row, unsigned src_stride,
116 unsigned width, unsigned height)
117 {
118 unsigned y;
119 for(y = 0; y < height; ++y) {
120 memcpy(dst_row, src_row, width);
121 src_row += src_stride/sizeof(*src_row);
122 dst_row += dst_stride/sizeof(*dst_row);
123 }
124 }
125
126 void
127 util_format_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
128 const uint8_t *src_row, unsigned src_stride,
129 unsigned width, unsigned height)
130 {
131 unsigned y;
132 for(y = 0; y < height; ++y) {
133 memcpy(dst_row, src_row, width);
134 src_row += src_stride/sizeof(*src_row);
135 dst_row += dst_stride/sizeof(*dst_row);
136 }
137 }
138
139 void
140 util_format_z16_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
141 const uint8_t *src_row, unsigned src_stride,
142 unsigned width, unsigned height)
143 {
144 unsigned x, y;
145 for(y = 0; y < height; ++y) {
146 float *dst = dst_row;
147 const uint16_t *src = (const uint16_t *)src_row;
148 for(x = 0; x < width; ++x) {
149 uint16_t value = util_cpu_to_le16(*src++);
150 *dst++ = z16_unorm_to_z32_float(value);
151 }
152 src_row += src_stride/sizeof(*src_row);
153 dst_row += dst_stride/sizeof(*dst_row);
154 }
155 }
156
157 void
158 util_format_z16_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
159 const float *src_row, unsigned src_stride,
160 unsigned width, unsigned height)
161 {
162 unsigned x, y;
163 for(y = 0; y < height; ++y) {
164 const float *src = src_row;
165 uint16_t *dst = (uint16_t *)dst_row;
166 for(x = 0; x < width; ++x) {
167 uint16_t value;
168 value = z32_float_to_z16_unorm(*src++);
169 *dst++ = util_le16_to_cpu(value);
170 }
171 dst_row += dst_stride/sizeof(*dst_row);
172 src_row += src_stride/sizeof(*src_row);
173 }
174 }
175
176 void
177 util_format_z16_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
178 const uint8_t *src_row, unsigned src_stride,
179 unsigned width, unsigned height)
180 {
181 unsigned x, y;
182 for(y = 0; y < height; ++y) {
183 uint32_t *dst = dst_row;
184 const uint16_t *src = (const uint16_t *)src_row;
185 for(x = 0; x < width; ++x) {
186 uint16_t value = util_cpu_to_le16(*src++);
187 *dst++ = z16_unorm_to_z32_unorm(value);
188 }
189 src_row += src_stride/sizeof(*src_row);
190 dst_row += dst_stride/sizeof(*dst_row);
191 }
192 }
193
194 void
195 util_format_z16_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
196 const uint32_t *src_row, unsigned src_stride,
197 unsigned width, unsigned height)
198 {
199 unsigned x, y;
200 for(y = 0; y < height; ++y) {
201 const uint32_t *src = src_row;
202 uint16_t *dst = (uint16_t *)dst_row;
203 for(x = 0; x < width; ++x) {
204 uint16_t value;
205 value = z32_unorm_to_z16_unorm(*src++);
206 *dst++ = util_le16_to_cpu(value);
207 }
208 dst_row += dst_stride/sizeof(*dst_row);
209 src_row += src_stride/sizeof(*src_row);
210 }
211 }
212
213 void
214 util_format_z32_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
215 const uint8_t *src_row, unsigned src_stride,
216 unsigned width, unsigned height)
217 {
218 unsigned x, y;
219 for(y = 0; y < height; ++y) {
220 float *dst = dst_row;
221 const uint32_t *src = (const uint32_t *)src_row;
222 for(x = 0; x < width; ++x) {
223 uint32_t value = util_cpu_to_le32(*src++);
224 *dst++ = z32_unorm_to_z32_float(value);
225 }
226 src_row += src_stride/sizeof(*src_row);
227 dst_row += dst_stride/sizeof(*dst_row);
228 }
229 }
230
231 void
232 util_format_z32_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
233 const float *src_row, unsigned src_stride,
234 unsigned width, unsigned height)
235 {
236 unsigned x, y;
237 for(y = 0; y < height; ++y) {
238 const float *src = src_row;
239 uint32_t *dst = (uint32_t *)dst_row;
240 for(x = 0; x < width; ++x) {
241 uint32_t value;
242 value = z32_float_to_z32_unorm(*src++);
243 *dst++ = util_le32_to_cpu(value);
244 }
245 dst_row += dst_stride/sizeof(*dst_row);
246 src_row += src_stride/sizeof(*src_row);
247 }
248 }
249
250 void
251 util_format_z32_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
252 const uint8_t *src_row, unsigned src_stride,
253 unsigned width, unsigned height)
254 {
255 unsigned y;
256 for(y = 0; y < height; ++y) {
257 memcpy(dst_row, src_row, width * 4);
258 src_row += src_stride/sizeof(*src_row);
259 dst_row += dst_stride/sizeof(*dst_row);
260 }
261 }
262
263 void
264 util_format_z32_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
265 const uint32_t *src_row, unsigned src_stride,
266 unsigned width, unsigned height)
267 {
268 unsigned y;
269 for(y = 0; y < height; ++y) {
270 memcpy(dst_row, src_row, width * 4);
271 src_row += src_stride/sizeof(*src_row);
272 dst_row += dst_stride/sizeof(*dst_row);
273 }
274 }
275
276 void
277 util_format_z32_float_unpack_z_float(float *dst_row, unsigned dst_stride,
278 const uint8_t *src_row, unsigned src_stride,
279 unsigned width, unsigned height)
280 {
281 unsigned y;
282 for(y = 0; y < height; ++y) {
283 memcpy(dst_row, src_row, width * 4);
284 src_row += src_stride/sizeof(*src_row);
285 dst_row += dst_stride/sizeof(*dst_row);
286 }
287 }
288
289 void
290 util_format_z32_float_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
291 const float *src_row, unsigned src_stride,
292 unsigned width, unsigned height)
293 {
294 unsigned y;
295 for(y = 0; y < height; ++y) {
296 memcpy(dst_row, src_row, width * 4);
297 src_row += src_stride/sizeof(*src_row);
298 dst_row += dst_stride/sizeof(*dst_row);
299 }
300 }
301
302 void
303 util_format_z32_float_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
304 const uint8_t *src_row, unsigned src_stride,
305 unsigned width, unsigned height)
306 {
307 unsigned x, y;
308 for(y = 0; y < height; ++y) {
309 uint32_t *dst = dst_row;
310 const float *src = (const float *)src_row;
311 for(x = 0; x < width; ++x) {
312 *dst++ = z32_float_to_z32_unorm(*src++);
313 }
314 src_row += src_stride/sizeof(*src_row);
315 dst_row += dst_stride/sizeof(*dst_row);
316 }
317 }
318
319 void
320 util_format_z32_float_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
321 const uint32_t *src_row, unsigned src_stride,
322 unsigned width, unsigned height)
323 {
324 unsigned x, y;
325 for(y = 0; y < height; ++y) {
326 const uint32_t *src = src_row;
327 float *dst = (float *)dst_row;
328 for(x = 0; x < width; ++x) {
329 *dst++ = z32_unorm_to_z32_float(*src++);
330 }
331 dst_row += dst_stride/sizeof(*dst_row);
332 src_row += src_stride/sizeof(*src_row);
333 }
334 }
335
336 void
337 util_format_z16_unorm_s8_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
338 const uint8_t *src_row, unsigned src_stride,
339 unsigned width, unsigned height)
340 {
341 unreachable("z16_s8 packing/unpacking is not implemented.");
342 }
343
344 void
345 util_format_z16_unorm_s8_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
346 const float *src_row, unsigned src_stride,
347 unsigned width, unsigned height)
348 {
349 unreachable("z16_s8 packing/unpacking is not implemented.");
350 }
351
352 void
353 util_format_z16_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
354 const uint8_t *src_row, unsigned src_stride,
355 unsigned width, unsigned height)
356 {
357 unreachable("z16_s8 packing/unpacking is not implemented.");
358 }
359
360 void
361 util_format_z16_unorm_s8_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
362 const uint32_t *src_row, unsigned src_stride,
363 unsigned width, unsigned height)
364 {
365 unreachable("z16_s8 packing/unpacking is not implemented.");
366 }
367
368 void
369 util_format_z16_unorm_s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
370 const uint8_t *src_row, unsigned src_stride,
371 unsigned width, unsigned height)
372 {
373 unreachable("z16_s8 packing/unpacking is not implemented.");
374 }
375
376 void
377 util_format_z16_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
378 const uint8_t *src_row, unsigned src_stride,
379 unsigned width, unsigned height)
380 {
381 unreachable("z16_s8 packing/unpacking is not implemented.");
382 }
383
384 void
385 util_format_z24_unorm_s8_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
386 const uint8_t *src_row, unsigned src_stride,
387 unsigned width, unsigned height)
388 {
389 unsigned x, y;
390 for(y = 0; y < height; ++y) {
391 float *dst = dst_row;
392 const uint32_t *src = (const uint32_t *)src_row;
393 for(x = 0; x < width; ++x) {
394 uint32_t value = util_cpu_to_le32(*src++);
395 *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
396 }
397 src_row += src_stride/sizeof(*src_row);
398 dst_row += dst_stride/sizeof(*dst_row);
399 }
400 }
401
402 void
403 util_format_z24_unorm_s8_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
404 const float *src_row, unsigned src_stride,
405 unsigned width, unsigned height)
406 {
407 unsigned x, y;
408 for(y = 0; y < height; ++y) {
409 const float *src = src_row;
410 uint32_t *dst = (uint32_t *)dst_row;
411 for(x = 0; x < width; ++x) {
412 uint32_t value = util_le32_to_cpu(*dst);
413 value &= 0xff000000;
414 value |= z32_float_to_z24_unorm(*src++);
415 *dst++ = util_cpu_to_le32(value);
416 }
417 dst_row += dst_stride/sizeof(*dst_row);
418 src_row += src_stride/sizeof(*src_row);
419 }
420 }
421
422 void
423 util_format_z24_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
424 const uint8_t *src_row, unsigned src_stride,
425 unsigned width, unsigned height)
426 {
427 unsigned x, y;
428 for(y = 0; y < height; ++y) {
429 uint32_t *dst = dst_row;
430 const uint32_t *src = (const uint32_t *)src_row;
431 for(x = 0; x < width; ++x) {
432 uint32_t value = util_cpu_to_le32(*src++);
433 *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
434 }
435 src_row += src_stride/sizeof(*src_row);
436 dst_row += dst_stride/sizeof(*dst_row);
437 }
438 }
439
440 void
441 util_format_z24_unorm_s8_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
442 const uint32_t *src_row, unsigned src_stride,
443 unsigned width, unsigned height)
444 {
445 unsigned x, y;
446 for(y = 0; y < height; ++y) {
447 const uint32_t *src = src_row;
448 uint32_t *dst = (uint32_t *)dst_row;
449 for(x = 0; x < width; ++x) {
450 uint32_t value = util_le32_to_cpu(*dst);
451 value &= 0xff000000;
452 value |= z32_unorm_to_z24_unorm(*src++);
453 *dst++ = util_cpu_to_le32(value);
454 }
455 dst_row += dst_stride/sizeof(*dst_row);
456 src_row += src_stride/sizeof(*src_row);
457 }
458 }
459
460 void
461 util_format_z24_unorm_s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
462 const uint8_t *src_row, unsigned src_stride,
463 unsigned width, unsigned height)
464 {
465 unsigned x, y;
466 for(y = 0; y < height; ++y) {
467 uint8_t *dst = dst_row;
468 const uint32_t *src = (const uint32_t *)src_row;
469 for(x = 0; x < width; ++x) {
470 uint32_t value = util_cpu_to_le32(*src++);
471 *dst++ = value >> 24;
472 }
473 src_row += src_stride/sizeof(*src_row);
474 dst_row += dst_stride/sizeof(*dst_row);
475 }
476 }
477
478 void
479 util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
480 const uint8_t *src_row, unsigned src_stride,
481 unsigned width, unsigned height)
482 {
483 unsigned x, y;
484 for(y = 0; y < height; ++y) {
485 const uint8_t *src = src_row;
486 uint32_t *dst = (uint32_t *)dst_row;
487 for(x = 0; x < width; ++x) {
488 uint32_t value = util_le32_to_cpu(*dst);
489 value &= 0x00ffffff;
490 value |= (uint32_t)*src++ << 24;
491 *dst++ = util_cpu_to_le32(value);
492 }
493 dst_row += dst_stride/sizeof(*dst_row);
494 src_row += src_stride/sizeof(*src_row);
495 }
496 }
497
498 void
499 util_format_z24_unorm_s8_uint_pack_separate(uint8_t *dst_row, unsigned dst_stride,
500 const uint32_t *z_src_row, unsigned z_src_stride,
501 const uint8_t *s_src_row, unsigned s_src_stride,
502 unsigned width, unsigned height)
503 {
504 unsigned x, y;
505 for (y = 0; y < height; ++y) {
506 const uint32_t *z_src = z_src_row;
507 const uint8_t *s_src = s_src_row;
508 uint32_t *dst = (uint32_t *)dst_row;
509 for (x = 0; x < width; ++x) {
510 *dst++ = (*z_src++ & 0x00ffffff) | ((uint32_t)*s_src++ << 24);
511 }
512 dst_row += dst_stride / sizeof(*dst_row);
513 z_src_row += z_src_stride / sizeof(*z_src_row);
514 s_src_row += s_src_stride / sizeof(*s_src_row);
515 }
516 }
517
518 void
519 util_format_s8_uint_z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
520 const uint8_t *src_row, unsigned src_stride,
521 unsigned width, unsigned height)
522 {
523 unsigned x, y;
524 for(y = 0; y < height; ++y) {
525 float *dst = dst_row;
526 const uint32_t *src = (const uint32_t *)src_row;
527 for(x = 0; x < width; ++x) {
528 uint32_t value = util_cpu_to_le32(*src++);
529 *dst++ = z24_unorm_to_z32_float(value >> 8);
530 }
531 src_row += src_stride/sizeof(*src_row);
532 dst_row += dst_stride/sizeof(*dst_row);
533 }
534 }
535
536 void
537 util_format_s8_uint_z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
538 const float *src_row, unsigned src_stride,
539 unsigned width, unsigned height)
540 {
541 unsigned x, y;
542 for(y = 0; y < height; ++y) {
543 const float *src = src_row;
544 uint32_t *dst = (uint32_t *)dst_row;
545 for(x = 0; x < width; ++x) {
546 uint32_t value = util_le32_to_cpu(*dst);
547 value &= 0x000000ff;
548 value |= z32_float_to_z24_unorm(*src++) << 8;
549 *dst++ = util_cpu_to_le32(value);
550 }
551 dst_row += dst_stride/sizeof(*dst_row);
552 src_row += src_stride/sizeof(*src_row);
553 }
554 }
555
556 void
557 util_format_s8_uint_z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
558 const uint8_t *src_row, unsigned src_stride,
559 unsigned width, unsigned height)
560 {
561 unsigned x, y;
562 for(y = 0; y < height; ++y) {
563 uint32_t *dst = dst_row;
564 const uint32_t *src = (const uint32_t *)src_row;
565 for(x = 0; x < width; ++x) {
566 uint32_t value = util_cpu_to_le32(*src++);
567 *dst++ = z24_unorm_to_z32_unorm(value >> 8);
568 }
569 src_row += src_stride/sizeof(*src_row);
570 dst_row += dst_stride/sizeof(*dst_row);
571 }
572 }
573
574 void
575 util_format_s8_uint_z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
576 const uint32_t *src_row, unsigned src_stride,
577 unsigned width, unsigned height)
578 {
579 unsigned x, y;
580 for(y = 0; y < height; ++y) {
581 const uint32_t *src = src_row;
582 uint32_t *dst = (uint32_t *)dst_row;
583 for(x = 0; x < width; ++x) {
584 uint32_t value = util_le32_to_cpu(*dst);
585 value &= 0x000000ff;
586 value |= *src++ & 0xffffff00;
587 *dst++ = util_cpu_to_le32(value);
588 }
589 dst_row += dst_stride/sizeof(*dst_row);
590 src_row += src_stride/sizeof(*src_row);
591 }
592 }
593
594 void
595 util_format_s8_uint_z24_unorm_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
596 const uint8_t *src_row, unsigned src_stride,
597 unsigned width, unsigned height)
598 {
599 unsigned x, y;
600 for(y = 0; y < height; ++y) {
601 uint8_t *dst = dst_row;
602 const uint32_t *src = (const uint32_t *)src_row;
603 for(x = 0; x < width; ++x) {
604 uint32_t value = util_cpu_to_le32(*src++);
605 *dst++ = value & 0xff;
606 }
607 src_row += src_stride/sizeof(*src_row);
608 dst_row += dst_stride/sizeof(*dst_row);
609 }
610 }
611
612 void
613 util_format_s8_uint_z24_unorm_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
614 const uint8_t *src_row, unsigned src_stride,
615 unsigned width, unsigned height)
616 {
617 unsigned x, y;
618 for(y = 0; y < height; ++y) {
619 const uint8_t *src = src_row;
620 uint32_t *dst = (uint32_t *)dst_row;
621 for(x = 0; x < width; ++x) {
622 uint32_t value = util_le32_to_cpu(*dst);
623 value &= 0xffffff00;
624 value |= *src++;
625 *dst++ = util_cpu_to_le32(value);
626 }
627 dst_row += dst_stride/sizeof(*dst_row);
628 src_row += src_stride/sizeof(*src_row);
629 }
630 }
631
632 void
633 util_format_z24x8_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
634 const uint8_t *src_row, unsigned src_stride,
635 unsigned width, unsigned height)
636 {
637 unsigned x, y;
638 for(y = 0; y < height; ++y) {
639 float *dst = dst_row;
640 const uint32_t *src = (const uint32_t *)src_row;
641 for(x = 0; x < width; ++x) {
642 uint32_t value = util_cpu_to_le32(*src++);
643 *dst++ = z24_unorm_to_z32_float(value & 0xffffff);
644 }
645 src_row += src_stride/sizeof(*src_row);
646 dst_row += dst_stride/sizeof(*dst_row);
647 }
648 }
649
650 void
651 util_format_z24x8_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
652 const float *src_row, unsigned src_stride,
653 unsigned width, unsigned height)
654 {
655 unsigned x, y;
656 for(y = 0; y < height; ++y) {
657 const float *src = src_row;
658 uint32_t *dst = (uint32_t *)dst_row;
659 for(x = 0; x < width; ++x) {
660 uint32_t value;
661 value = z32_float_to_z24_unorm(*src++);
662 *dst++ = util_le32_to_cpu(value);
663 }
664 dst_row += dst_stride/sizeof(*dst_row);
665 src_row += src_stride/sizeof(*src_row);
666 }
667 }
668
669 void
670 util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
671 const uint8_t *src_row, unsigned src_stride,
672 unsigned width, unsigned height)
673 {
674 unsigned x, y;
675 for(y = 0; y < height; ++y) {
676 uint32_t *dst = dst_row;
677 const uint32_t *src = (const uint32_t *)src_row;
678 for(x = 0; x < width; ++x) {
679 uint32_t value = util_cpu_to_le32(*src++);
680 *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff);
681 }
682 src_row += src_stride/sizeof(*src_row);
683 dst_row += dst_stride/sizeof(*dst_row);
684 }
685 }
686
687 void
688 util_format_z24x8_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
689 const uint32_t *src_row, unsigned src_stride,
690 unsigned width, unsigned height)
691 {
692 unsigned x, y;
693 for(y = 0; y < height; ++y) {
694 const uint32_t *src = src_row;
695 uint32_t *dst = (uint32_t *)dst_row;
696 for(x = 0; x < width; ++x) {
697 uint32_t value;
698 value = z32_unorm_to_z24_unorm(*src++);
699 *dst++ = util_cpu_to_le32(value);
700 }
701 dst_row += dst_stride/sizeof(*dst_row);
702 src_row += src_stride/sizeof(*src_row);
703 }
704 }
705
706 void
707 util_format_x8z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride,
708 const uint8_t *src_row, unsigned src_stride,
709 unsigned width, unsigned height)
710 {
711 unsigned x, y;
712 for(y = 0; y < height; ++y) {
713 float *dst = dst_row;
714 const uint32_t *src = (uint32_t *)src_row;
715 for(x = 0; x < width; ++x) {
716 uint32_t value = util_cpu_to_le32(*src++);
717 *dst++ = z24_unorm_to_z32_float(value >> 8);
718 }
719 src_row += src_stride/sizeof(*src_row);
720 dst_row += dst_stride/sizeof(*dst_row);
721 }
722 }
723
724 void
725 util_format_x8z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
726 const float *src_row, unsigned src_stride,
727 unsigned width, unsigned height)
728 {
729 unsigned x, y;
730 for(y = 0; y < height; ++y) {
731 const float *src = src_row;
732 uint32_t *dst = (uint32_t *)dst_row;
733 for(x = 0; x < width; ++x) {
734 uint32_t value;
735 value = z32_float_to_z24_unorm(*src++) << 8;
736 *dst++ = util_cpu_to_le32(value);
737 }
738 dst_row += dst_stride/sizeof(*dst_row);
739 src_row += src_stride/sizeof(*src_row);
740 }
741 }
742
743 void
744 util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
745 const uint8_t *src_row, unsigned src_stride,
746 unsigned width, unsigned height)
747 {
748 unsigned x, y;
749 for(y = 0; y < height; ++y) {
750 uint32_t *dst = dst_row;
751 const uint32_t *src = (const uint32_t *)src_row;
752 for(x = 0; x < width; ++x) {
753 uint32_t value = util_cpu_to_le32(*src++);
754 *dst++ = z24_unorm_to_z32_unorm(value >> 8);
755 }
756 src_row += src_stride/sizeof(*src_row);
757 dst_row += dst_stride/sizeof(*dst_row);
758 }
759 }
760
761 void
762 util_format_x8z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
763 const uint32_t *src_row, unsigned src_stride,
764 unsigned width, unsigned height)
765 {
766 unsigned x, y;
767 for(y = 0; y < height; ++y) {
768 const uint32_t *src = src_row;
769 uint32_t *dst = (uint32_t *)dst_row;
770 for(x = 0; x < width; ++x) {
771 uint32_t value;
772 value = z32_unorm_to_z24_unorm(*src++) << 8;
773 *dst++ = util_cpu_to_le32(value);
774 }
775 dst_row += dst_stride/sizeof(*dst_row);
776 src_row += src_stride/sizeof(*src_row);
777 }
778 }
779
780 void
781 util_format_z32_float_s8x24_uint_unpack_z_float(float *dst_row, unsigned dst_stride,
782 const uint8_t *src_row, unsigned src_stride,
783 unsigned width, unsigned height)
784 {
785 unsigned x, y;
786 for(y = 0; y < height; ++y) {
787 float *dst = dst_row;
788 const float *src = (const float *)src_row;
789 for(x = 0; x < width; ++x) {
790 *dst = *src;
791 src += 2;
792 dst += 1;
793 }
794 src_row += src_stride/sizeof(*src_row);
795 dst_row += dst_stride/sizeof(*dst_row);
796 }
797 }
798
799 void
800 util_format_z32_float_s8x24_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride,
801 const float *src_row, unsigned src_stride,
802 unsigned width, unsigned height)
803 {
804 unsigned x, y;
805 for(y = 0; y < height; ++y) {
806 const float *src = src_row;
807 float *dst = (float *)dst_row;
808 for(x = 0; x < width; ++x) {
809 *dst = *src;
810 src += 1;
811 dst += 2;
812 }
813 dst_row += dst_stride/sizeof(*dst_row);
814 src_row += src_stride/sizeof(*src_row);
815 }
816 }
817
818 void
819 util_format_z32_float_s8x24_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
820 const uint8_t *src_row, unsigned src_stride,
821 unsigned width, unsigned height)
822 {
823 unsigned x, y;
824 for(y = 0; y < height; ++y) {
825 uint32_t *dst = dst_row;
826 const float *src = (const float *)src_row;
827 for(x = 0; x < width; ++x) {
828 *dst = z32_float_to_z32_unorm(*src);
829 src += 2;
830 dst += 1;
831 }
832 src_row += src_stride/sizeof(*src_row);
833 dst_row += dst_stride/sizeof(*dst_row);
834 }
835 }
836
837 void
838 util_format_z32_float_s8x24_uint_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride,
839 const uint32_t *src_row, unsigned src_stride,
840 unsigned width, unsigned height)
841 {
842 unsigned x, y;
843 for(y = 0; y < height; ++y) {
844 const uint32_t *src = src_row;
845 float *dst = (float *)dst_row;
846 for(x = 0; x < width; ++x) {
847 *dst++ = z32_unorm_to_z32_float(*src++);
848 }
849 dst_row += dst_stride/sizeof(*dst_row);
850 src_row += src_stride/sizeof(*src_row);
851 }
852 }
853
854 void
855 util_format_z32_float_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
856 const uint8_t *src_row, unsigned src_stride,
857 unsigned width, unsigned height)
858 {
859 unsigned x, y;
860 for(y = 0; y < height; ++y) {
861 uint8_t *dst = dst_row;
862 const uint8_t *src = src_row + 4;
863 for(x = 0; x < width; ++x) {
864 *dst = *src;
865 src += 8;
866 dst += 1;
867 }
868 src_row += src_stride/sizeof(*src_row);
869 dst_row += dst_stride/sizeof(*dst_row);
870 }
871 }
872
873 void
874 util_format_z32_float_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
875 const uint8_t *src_row, unsigned src_stride,
876 unsigned width, unsigned height)
877 {
878 unsigned x, y;
879 for(y = 0; y < height; ++y) {
880 const uint8_t *src = src_row;
881 uint32_t *dst = ((uint32_t *)dst_row) + 1;
882 for(x = 0; x < width; ++x) {
883 *dst = util_cpu_to_le32(*src);
884 src += 1;
885 dst += 2;
886 }
887 dst_row += dst_stride/sizeof(*dst_row);
888 src_row += src_stride/sizeof(*src_row);
889 }
890 }
891
892
893 void
894 util_format_x24s8_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
895 {
896 util_format_z24_unorm_s8_uint_unpack_s_8uint(dst_row, dst_stride,
897 src_row, src_stride,
898 width, height);
899 }
900
901 void
902 util_format_x24s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
903 {
904 util_format_z24_unorm_s8_uint_pack_s_8uint(dst_row, dst_stride,
905 src_row, src_stride,
906 width, height);
907 }
908
909 void
910 util_format_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
911 {
912 util_format_s8_uint_z24_unorm_unpack_s_8uint(dst_row, dst_stride,
913 src_row, src_stride,
914 width, height);
915 }
916
917 void
918 util_format_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
919 {
920 util_format_s8_uint_z24_unorm_pack_s_8uint(dst_row, dst_stride,
921 src_row, src_stride,
922 width, height);
923 }
924
925 void
926 util_format_x32_s8x24_uint_unpack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
927 const uint8_t *src_row, unsigned src_stride,
928 unsigned width, unsigned height)
929 {
930 util_format_z32_float_s8x24_uint_unpack_s_8uint(dst_row, dst_stride,
931 src_row, src_stride,
932 width, height);
933
934 }
935
936 void
937 util_format_x32_s8x24_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride,
938 const uint8_t *src_row, unsigned src_stride,
939 unsigned width, unsigned height)
940 {
941 util_format_z32_float_s8x24_uint_pack_s_8uint(dst_row, dst_stride,
942 src_row, src_stride,
943 width, height);
944 }