1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * Functions for converting tiled data to linear and vice versa.
33 #include "util/u_debug.h"
37 pipe_linear_to_tile(size_t src_stride
, const void *src_ptr
,
38 struct pipe_tile_info
*t
, void *dst_ptr
)
42 size_t bytes
= t
->cols
* t
->block
.size
;
43 char *dst_ptr2
= (char *) dst_ptr
;
45 assert(pipe_linear_check_tile(t
));
47 /* lets write lineary to the tiled buffer */
48 for (y
= 0; y
< t
->tiles_y
; y
++) {
49 for (x
= 0; x
< t
->tiles_x
; x
++) {
50 /* this inner loop could be replace with SSE magic */
51 ptr
= (char*)src_ptr
+ src_stride
* t
->rows
* y
+ bytes
* x
;
52 for (z
= 0; z
< t
->rows
; z
++) {
53 memcpy(dst_ptr2
, ptr
, bytes
);
61 void pipe_linear_from_tile(struct pipe_tile_info
*t
, const void *src_ptr
,
62 size_t dst_stride
, void *dst_ptr
)
66 size_t bytes
= t
->cols
* t
->block
.size
;
67 const char *src_ptr2
= (const char *) src_ptr
;
69 /* lets read lineary from the tiled buffer */
70 for (y
= 0; y
< t
->tiles_y
; y
++) {
71 for (x
= 0; x
< t
->tiles_x
; x
++) {
72 /* this inner loop could be replace with SSE magic */
73 ptr
= (char*)dst_ptr
+ dst_stride
* t
->rows
* y
+ bytes
* x
;
74 for (z
= 0; z
< t
->rows
; z
++) {
75 memcpy(ptr
, src_ptr2
, bytes
);
84 pipe_linear_fill_info(struct pipe_tile_info
*t
,
85 const struct u_linear_format_block
*block
,
86 unsigned tile_width
, unsigned tile_height
,
87 unsigned tiles_x
, unsigned tiles_y
)
91 t
->tile
.width
= tile_width
;
92 t
->tile
.height
= tile_height
;
93 t
->cols
= t
->tile
.width
/ t
->block
.width
;
94 t
->rows
= t
->tile
.height
/ t
->block
.height
;
95 t
->tile
.size
= t
->cols
* t
->rows
* t
->block
.size
;
99 t
->stride
= t
->cols
* t
->tiles_x
* t
->block
.size
;
100 t
->size
= t
->tiles_x
* t
->tiles_y
* t
->tile
.size
;