1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/**
29bf215546Sopenharmony_ci * RGBA/float tile get/put functions.
30bf215546Sopenharmony_ci * Usable both by drivers and gallium frontends.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "pipe/p_defines.h"
35bf215546Sopenharmony_ci#include "util/u_inlines.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "util/format/u_format.h"
38bf215546Sopenharmony_ci#include "util/format/u_format_bptc.h"
39bf215546Sopenharmony_ci#include "util/u_math.h"
40bf215546Sopenharmony_ci#include "util/u_memory.h"
41bf215546Sopenharmony_ci#include "util/u_surface.h"
42bf215546Sopenharmony_ci#include "util/u_tile.h"
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci/**
46bf215546Sopenharmony_ci * Move raw block of pixels from transfer object to user memory.
47bf215546Sopenharmony_ci */
48bf215546Sopenharmony_civoid
49bf215546Sopenharmony_cipipe_get_tile_raw(struct pipe_transfer *pt,
50bf215546Sopenharmony_ci                  const void *src,
51bf215546Sopenharmony_ci                  uint x, uint y, uint w, uint h,
52bf215546Sopenharmony_ci                  void *dst, int dst_stride)
53bf215546Sopenharmony_ci{
54bf215546Sopenharmony_ci   if (dst_stride == 0)
55bf215546Sopenharmony_ci      dst_stride = util_format_get_stride(pt->resource->format, w);
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   if (u_clip_tile(x, y, &w, &h, &pt->box))
58bf215546Sopenharmony_ci      return;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci   util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
61bf215546Sopenharmony_ci}
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci/**
65bf215546Sopenharmony_ci * Move raw block of pixels from user memory to transfer object.
66bf215546Sopenharmony_ci */
67bf215546Sopenharmony_civoid
68bf215546Sopenharmony_cipipe_put_tile_raw(struct pipe_transfer *pt,
69bf215546Sopenharmony_ci                  void *dst,
70bf215546Sopenharmony_ci                  uint x, uint y, uint w, uint h,
71bf215546Sopenharmony_ci                  const void *src, int src_stride)
72bf215546Sopenharmony_ci{
73bf215546Sopenharmony_ci   enum pipe_format format = pt->resource->format;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   if (src_stride == 0)
76bf215546Sopenharmony_ci      src_stride = util_format_get_stride(format, w);
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   if (u_clip_tile(x, y, &w, &h, &pt->box))
79bf215546Sopenharmony_ci      return;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   util_copy_rect(dst, format, pt->stride, x, y, w, h, src, src_stride, 0, 0);
82bf215546Sopenharmony_ci}
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci/** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
88bf215546Sopenharmony_ci#define SHORT_TO_FLOAT(S)   ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci#define UNCLAMPED_FLOAT_TO_SHORT(us, f)  \
91bf215546Sopenharmony_ci   us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci/*** PIPE_FORMAT_Z16_UNORM ***/
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci/**
98bf215546Sopenharmony_ci * Return each Z value as four floats in [0,1].
99bf215546Sopenharmony_ci */
100bf215546Sopenharmony_cistatic void
101bf215546Sopenharmony_ciz16_get_tile_rgba(const ushort *src,
102bf215546Sopenharmony_ci                  unsigned w, unsigned h,
103bf215546Sopenharmony_ci                  float *p,
104bf215546Sopenharmony_ci                  unsigned dst_stride)
105bf215546Sopenharmony_ci{
106bf215546Sopenharmony_ci   const float scale = 1.0f / 65535.0f;
107bf215546Sopenharmony_ci   unsigned i, j;
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
110bf215546Sopenharmony_ci      float *pRow = p;
111bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
112bf215546Sopenharmony_ci         pRow[0] =
113bf215546Sopenharmony_ci         pRow[1] =
114bf215546Sopenharmony_ci         pRow[2] =
115bf215546Sopenharmony_ci         pRow[3] = *src++ * scale;
116bf215546Sopenharmony_ci      }
117bf215546Sopenharmony_ci      p += dst_stride;
118bf215546Sopenharmony_ci   }
119bf215546Sopenharmony_ci}
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci/*** PIPE_FORMAT_Z32_UNORM ***/
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ci/**
127bf215546Sopenharmony_ci * Return each Z value as four floats in [0,1].
128bf215546Sopenharmony_ci */
129bf215546Sopenharmony_cistatic void
130bf215546Sopenharmony_ciz32_get_tile_rgba(const unsigned *src,
131bf215546Sopenharmony_ci                  unsigned w, unsigned h,
132bf215546Sopenharmony_ci                  float *p,
133bf215546Sopenharmony_ci                  unsigned dst_stride)
134bf215546Sopenharmony_ci{
135bf215546Sopenharmony_ci   const double scale = 1.0 / (double) 0xffffffff;
136bf215546Sopenharmony_ci   unsigned i, j;
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
139bf215546Sopenharmony_ci      float *pRow = p;
140bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
141bf215546Sopenharmony_ci         pRow[0] =
142bf215546Sopenharmony_ci         pRow[1] =
143bf215546Sopenharmony_ci         pRow[2] =
144bf215546Sopenharmony_ci         pRow[3] = (float) (*src++ * scale);
145bf215546Sopenharmony_ci      }
146bf215546Sopenharmony_ci      p += dst_stride;
147bf215546Sopenharmony_ci   }
148bf215546Sopenharmony_ci}
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_ci/*** PIPE_FORMAT_Z24_UNORM_S8_UINT ***/
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci/**
154bf215546Sopenharmony_ci * Return Z component as four float in [0,1].  Stencil part ignored.
155bf215546Sopenharmony_ci */
156bf215546Sopenharmony_cistatic void
157bf215546Sopenharmony_cis8z24_get_tile_rgba(const unsigned *src,
158bf215546Sopenharmony_ci                    unsigned w, unsigned h,
159bf215546Sopenharmony_ci                    float *p,
160bf215546Sopenharmony_ci                    unsigned dst_stride)
161bf215546Sopenharmony_ci{
162bf215546Sopenharmony_ci   const double scale = 1.0 / ((1 << 24) - 1);
163bf215546Sopenharmony_ci   unsigned i, j;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
166bf215546Sopenharmony_ci      float *pRow = p;
167bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
168bf215546Sopenharmony_ci         pRow[0] =
169bf215546Sopenharmony_ci         pRow[1] =
170bf215546Sopenharmony_ci         pRow[2] =
171bf215546Sopenharmony_ci         pRow[3] = (float) (scale * (*src++ & 0xffffff));
172bf215546Sopenharmony_ci      }
173bf215546Sopenharmony_ci      p += dst_stride;
174bf215546Sopenharmony_ci   }
175bf215546Sopenharmony_ci}
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ci/*** PIPE_FORMAT_S8_UINT_Z24_UNORM ***/
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci/**
181bf215546Sopenharmony_ci * Return Z component as four float in [0,1].  Stencil part ignored.
182bf215546Sopenharmony_ci */
183bf215546Sopenharmony_cistatic void
184bf215546Sopenharmony_ciz24s8_get_tile_rgba(const unsigned *src,
185bf215546Sopenharmony_ci                    unsigned w, unsigned h,
186bf215546Sopenharmony_ci                    float *p,
187bf215546Sopenharmony_ci                    unsigned dst_stride)
188bf215546Sopenharmony_ci{
189bf215546Sopenharmony_ci   const double scale = 1.0 / ((1 << 24) - 1);
190bf215546Sopenharmony_ci   unsigned i, j;
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
193bf215546Sopenharmony_ci      float *pRow = p;
194bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
195bf215546Sopenharmony_ci         pRow[0] =
196bf215546Sopenharmony_ci         pRow[1] =
197bf215546Sopenharmony_ci         pRow[2] =
198bf215546Sopenharmony_ci         pRow[3] = (float) (scale * (*src++ >> 8));
199bf215546Sopenharmony_ci      }
200bf215546Sopenharmony_ci      p += dst_stride;
201bf215546Sopenharmony_ci   }
202bf215546Sopenharmony_ci}
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci/*** PIPE_FORMAT_S8X24_UINT ***/
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci/**
207bf215546Sopenharmony_ci * Return S component as four uint32_t in [0..255].  Z part ignored.
208bf215546Sopenharmony_ci */
209bf215546Sopenharmony_cistatic void
210bf215546Sopenharmony_cis8x24_get_tile_rgba(const unsigned *src,
211bf215546Sopenharmony_ci                    unsigned w, unsigned h,
212bf215546Sopenharmony_ci                    float *p,
213bf215546Sopenharmony_ci                    unsigned dst_stride)
214bf215546Sopenharmony_ci{
215bf215546Sopenharmony_ci   unsigned i, j;
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
218bf215546Sopenharmony_ci      uint32_t *pRow = (uint32_t *)p;
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
221bf215546Sopenharmony_ci         pRow[0] =
222bf215546Sopenharmony_ci         pRow[1] =
223bf215546Sopenharmony_ci         pRow[2] =
224bf215546Sopenharmony_ci         pRow[3] = ((*src++ >> 24) & 0xff);
225bf215546Sopenharmony_ci      }
226bf215546Sopenharmony_ci
227bf215546Sopenharmony_ci      p += dst_stride;
228bf215546Sopenharmony_ci   }
229bf215546Sopenharmony_ci}
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_ci/*** PIPE_FORMAT_X24S8_UINT ***/
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci/**
234bf215546Sopenharmony_ci * Return S component as four uint32_t in [0..255].  Z part ignored.
235bf215546Sopenharmony_ci */
236bf215546Sopenharmony_cistatic void
237bf215546Sopenharmony_cix24s8_get_tile_rgba(const unsigned *src,
238bf215546Sopenharmony_ci                    unsigned w, unsigned h,
239bf215546Sopenharmony_ci                    float *p,
240bf215546Sopenharmony_ci                    unsigned dst_stride)
241bf215546Sopenharmony_ci{
242bf215546Sopenharmony_ci   unsigned i, j;
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
245bf215546Sopenharmony_ci      uint32_t *pRow = (uint32_t *)p;
246bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
247bf215546Sopenharmony_ci         pRow[0] =
248bf215546Sopenharmony_ci         pRow[1] =
249bf215546Sopenharmony_ci         pRow[2] =
250bf215546Sopenharmony_ci         pRow[3] = (*src++ & 0xff);
251bf215546Sopenharmony_ci      }
252bf215546Sopenharmony_ci      p += dst_stride;
253bf215546Sopenharmony_ci   }
254bf215546Sopenharmony_ci}
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_ci/**
258bf215546Sopenharmony_ci * Return S component as four uint32_t in [0..255].  Z part ignored.
259bf215546Sopenharmony_ci */
260bf215546Sopenharmony_cistatic void
261bf215546Sopenharmony_cis8_get_tile_rgba(const unsigned char *src,
262bf215546Sopenharmony_ci		 unsigned w, unsigned h,
263bf215546Sopenharmony_ci		 float *p,
264bf215546Sopenharmony_ci		 unsigned dst_stride)
265bf215546Sopenharmony_ci{
266bf215546Sopenharmony_ci   unsigned i, j;
267bf215546Sopenharmony_ci
268bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
269bf215546Sopenharmony_ci      uint32_t *pRow = (uint32_t *)p;
270bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
271bf215546Sopenharmony_ci         pRow[0] =
272bf215546Sopenharmony_ci         pRow[1] =
273bf215546Sopenharmony_ci         pRow[2] =
274bf215546Sopenharmony_ci         pRow[3] = (*src++ & 0xff);
275bf215546Sopenharmony_ci      }
276bf215546Sopenharmony_ci      p += dst_stride;
277bf215546Sopenharmony_ci   }
278bf215546Sopenharmony_ci}
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci/*** PIPE_FORMAT_Z32_FLOAT ***/
281bf215546Sopenharmony_ci
282bf215546Sopenharmony_ci/**
283bf215546Sopenharmony_ci * Return each Z value as four floats in [0,1].
284bf215546Sopenharmony_ci */
285bf215546Sopenharmony_cistatic void
286bf215546Sopenharmony_ciz32f_get_tile_rgba(const float *src,
287bf215546Sopenharmony_ci                   unsigned w, unsigned h,
288bf215546Sopenharmony_ci                   float *p,
289bf215546Sopenharmony_ci                   unsigned dst_stride)
290bf215546Sopenharmony_ci{
291bf215546Sopenharmony_ci   unsigned i, j;
292bf215546Sopenharmony_ci
293bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
294bf215546Sopenharmony_ci      float *pRow = p;
295bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
296bf215546Sopenharmony_ci         pRow[0] =
297bf215546Sopenharmony_ci         pRow[1] =
298bf215546Sopenharmony_ci         pRow[2] =
299bf215546Sopenharmony_ci         pRow[3] = *src++;
300bf215546Sopenharmony_ci      }
301bf215546Sopenharmony_ci      p += dst_stride;
302bf215546Sopenharmony_ci   }
303bf215546Sopenharmony_ci}
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci/*** PIPE_FORMAT_Z32_FLOAT_S8X24_UINT ***/
306bf215546Sopenharmony_ci
307bf215546Sopenharmony_ci/**
308bf215546Sopenharmony_ci * Return each Z value as four floats in [0,1].
309bf215546Sopenharmony_ci */
310bf215546Sopenharmony_cistatic void
311bf215546Sopenharmony_ciz32f_x24s8_get_tile_rgba(const float *src,
312bf215546Sopenharmony_ci                         unsigned w, unsigned h,
313bf215546Sopenharmony_ci                         float *p,
314bf215546Sopenharmony_ci                         unsigned dst_stride)
315bf215546Sopenharmony_ci{
316bf215546Sopenharmony_ci   unsigned i, j;
317bf215546Sopenharmony_ci
318bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
319bf215546Sopenharmony_ci      float *pRow = p;
320bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
321bf215546Sopenharmony_ci         pRow[0] =
322bf215546Sopenharmony_ci         pRow[1] =
323bf215546Sopenharmony_ci         pRow[2] =
324bf215546Sopenharmony_ci         pRow[3] = *src;
325bf215546Sopenharmony_ci         src += 2;
326bf215546Sopenharmony_ci      }
327bf215546Sopenharmony_ci      p += dst_stride;
328bf215546Sopenharmony_ci   }
329bf215546Sopenharmony_ci}
330bf215546Sopenharmony_ci
331bf215546Sopenharmony_ci/*** PIPE_FORMAT_X32_S8X24_UINT ***/
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci/**
334bf215546Sopenharmony_ci * Return S component as four uint32_t in [0..255].  Z part ignored.
335bf215546Sopenharmony_ci */
336bf215546Sopenharmony_cistatic void
337bf215546Sopenharmony_cix32_s8_get_tile_rgba(const unsigned *src,
338bf215546Sopenharmony_ci                     unsigned w, unsigned h,
339bf215546Sopenharmony_ci                     float *p,
340bf215546Sopenharmony_ci                     unsigned dst_stride)
341bf215546Sopenharmony_ci{
342bf215546Sopenharmony_ci   unsigned i, j;
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   for (i = 0; i < h; i++) {
345bf215546Sopenharmony_ci      uint32_t *pRow = (uint32_t *)p;
346bf215546Sopenharmony_ci      for (j = 0; j < w; j++, pRow += 4) {
347bf215546Sopenharmony_ci         src++;
348bf215546Sopenharmony_ci         pRow[0] =
349bf215546Sopenharmony_ci         pRow[1] =
350bf215546Sopenharmony_ci         pRow[2] =
351bf215546Sopenharmony_ci         pRow[3] = (*src++ & 0xff);
352bf215546Sopenharmony_ci      }
353bf215546Sopenharmony_ci      p += dst_stride;
354bf215546Sopenharmony_ci   }
355bf215546Sopenharmony_ci}
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_civoid
358bf215546Sopenharmony_cipipe_put_tile_rgba(struct pipe_transfer *pt,
359bf215546Sopenharmony_ci                   void *dst,
360bf215546Sopenharmony_ci                   uint x, uint y, uint w, uint h,
361bf215546Sopenharmony_ci                   enum pipe_format format, const void *p)
362bf215546Sopenharmony_ci{
363bf215546Sopenharmony_ci   unsigned src_stride = w * 4;
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci   if (u_clip_tile(x, y, &w, &h, &pt->box))
366bf215546Sopenharmony_ci      return;
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_ci   /* While we do generate RGBA tiles for z/s for softpipe's texture fetch
369bf215546Sopenharmony_ci    * path, we never have to store from "RGBA" to Z/S.
370bf215546Sopenharmony_ci    */
371bf215546Sopenharmony_ci   if (util_format_is_depth_or_stencil(format))
372bf215546Sopenharmony_ci      return;
373bf215546Sopenharmony_ci
374bf215546Sopenharmony_ci   util_format_write_4(format,
375bf215546Sopenharmony_ci                       p, src_stride * sizeof(float),
376bf215546Sopenharmony_ci                       dst, pt->stride,
377bf215546Sopenharmony_ci                       x, y, w, h);
378bf215546Sopenharmony_ci}
379bf215546Sopenharmony_ci
380bf215546Sopenharmony_civoid
381bf215546Sopenharmony_cipipe_get_tile_rgba(struct pipe_transfer *pt,
382bf215546Sopenharmony_ci                   const void *src,
383bf215546Sopenharmony_ci                   uint x, uint y, uint w, uint h,
384bf215546Sopenharmony_ci                   enum pipe_format format,
385bf215546Sopenharmony_ci                   void *dst)
386bf215546Sopenharmony_ci{
387bf215546Sopenharmony_ci   unsigned dst_stride = w * 4;
388bf215546Sopenharmony_ci   void *packed;
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci   if (u_clip_tile(x, y, &w, &h, &pt->box)) {
391bf215546Sopenharmony_ci      return;
392bf215546Sopenharmony_ci   }
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci   packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
395bf215546Sopenharmony_ci   if (!packed) {
396bf215546Sopenharmony_ci      return;
397bf215546Sopenharmony_ci   }
398bf215546Sopenharmony_ci
399bf215546Sopenharmony_ci   if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
400bf215546Sopenharmony_ci      assert((x & 1) == 0);
401bf215546Sopenharmony_ci   }
402bf215546Sopenharmony_ci
403bf215546Sopenharmony_ci   pipe_get_tile_raw(pt, src, x, y, w, h, packed, 0);
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci   switch (format) {
406bf215546Sopenharmony_ci   case PIPE_FORMAT_Z16_UNORM:
407bf215546Sopenharmony_ci      z16_get_tile_rgba((ushort *) packed, w, h, dst, dst_stride);
408bf215546Sopenharmony_ci      break;
409bf215546Sopenharmony_ci   case PIPE_FORMAT_Z32_UNORM:
410bf215546Sopenharmony_ci      z32_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
411bf215546Sopenharmony_ci      break;
412bf215546Sopenharmony_ci   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
413bf215546Sopenharmony_ci   case PIPE_FORMAT_Z24X8_UNORM:
414bf215546Sopenharmony_ci      s8z24_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
415bf215546Sopenharmony_ci      break;
416bf215546Sopenharmony_ci   case PIPE_FORMAT_S8_UINT:
417bf215546Sopenharmony_ci      s8_get_tile_rgba((unsigned char *) packed, w, h, dst, dst_stride);
418bf215546Sopenharmony_ci      break;
419bf215546Sopenharmony_ci   case PIPE_FORMAT_X24S8_UINT:
420bf215546Sopenharmony_ci      s8x24_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
421bf215546Sopenharmony_ci      break;
422bf215546Sopenharmony_ci   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
423bf215546Sopenharmony_ci   case PIPE_FORMAT_X8Z24_UNORM:
424bf215546Sopenharmony_ci      z24s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
425bf215546Sopenharmony_ci      break;
426bf215546Sopenharmony_ci   case PIPE_FORMAT_S8X24_UINT:
427bf215546Sopenharmony_ci      x24s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
428bf215546Sopenharmony_ci      break;
429bf215546Sopenharmony_ci   case PIPE_FORMAT_Z32_FLOAT:
430bf215546Sopenharmony_ci      z32f_get_tile_rgba((float *) packed, w, h, dst, dst_stride);
431bf215546Sopenharmony_ci      break;
432bf215546Sopenharmony_ci   case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
433bf215546Sopenharmony_ci      z32f_x24s8_get_tile_rgba((float *) packed, w, h, dst, dst_stride);
434bf215546Sopenharmony_ci      break;
435bf215546Sopenharmony_ci   case PIPE_FORMAT_X32_S8X24_UINT:
436bf215546Sopenharmony_ci      x32_s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
437bf215546Sopenharmony_ci      break;
438bf215546Sopenharmony_ci   default:
439bf215546Sopenharmony_ci      util_format_read_4(format,
440bf215546Sopenharmony_ci                         dst, dst_stride * sizeof(float),
441bf215546Sopenharmony_ci                         packed, util_format_get_stride(format, w),
442bf215546Sopenharmony_ci                         0, 0, w, h);
443bf215546Sopenharmony_ci   }
444bf215546Sopenharmony_ci
445bf215546Sopenharmony_ci   FREE(packed);
446bf215546Sopenharmony_ci}
447