1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 **************************************************************************/
28 #include "util/u_rect.h"
29 #include "util/u_surface.h"
30 #include "lp_context.h"
32 #include "lp_limits.h"
33 #include "lp_surface.h"
34 #include "lp_texture.h"
38 * Adjust x, y, width, height to lie on tile bounds.
41 adjust_to_tile_bounds(unsigned x
, unsigned y
, unsigned width
, unsigned height
,
42 unsigned *x_tile
, unsigned *y_tile
,
43 unsigned *w_tile
, unsigned *h_tile
)
45 *x_tile
= x
& ~(TILE_SIZE
- 1);
46 *y_tile
= y
& ~(TILE_SIZE
- 1);
47 *w_tile
= ((x
+ width
+ TILE_SIZE
- 1) & ~(TILE_SIZE
- 1)) - *x_tile
;
48 *h_tile
= ((y
+ height
+ TILE_SIZE
- 1) & ~(TILE_SIZE
- 1)) - *y_tile
;
54 lp_resource_copy(struct pipe_context
*pipe
,
55 struct pipe_resource
*dst
, unsigned dst_level
,
56 unsigned dstx
, unsigned dsty
, unsigned dstz
,
57 struct pipe_resource
*src
, unsigned src_level
,
58 const struct pipe_box
*src_box
)
60 /* XXX this used to ignore srcz/dstz
61 * assume it works the same for cube and 3d
63 struct llvmpipe_resource
*src_tex
= llvmpipe_resource(src
);
64 struct llvmpipe_resource
*dst_tex
= llvmpipe_resource(dst
);
65 const enum pipe_format format
= src_tex
->base
.format
;
66 unsigned width
= src_box
->width
;
67 unsigned height
= src_box
->height
;
68 assert(src_box
->depth
== 1);
70 llvmpipe_flush_resource(pipe
,
72 FALSE
, /* read_only */
73 TRUE
, /* cpu_access */
74 FALSE
, /* do_not_block */
77 llvmpipe_flush_resource(pipe
,
78 src
, src_level
, src_box
->z
,
80 TRUE
, /* cpu_access */
81 FALSE
, /* do_not_block */
85 printf("surface copy from %u lvl %u to %u lvl %u: %u,%u,%u to %u,%u,%u %u x %u x %u\n",
86 src_tex->id, src_level, dst_tex->id, dst_level,
87 src_box->x, src_box->y, src_box->z, dstx, dsty, dstz,
88 src_box->width, src_box->height, src_box->depth);
91 /* set src tiles to linear layout */
93 unsigned tx
, ty
, tw
, th
;
96 adjust_to_tile_bounds(src_box
->x
, src_box
->y
, width
, height
,
99 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
100 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
101 (void) llvmpipe_get_texture_tile_linear(src_tex
,
102 src_box
->z
, src_level
,
109 /* set dst tiles to linear layout */
111 unsigned tx
, ty
, tw
, th
;
113 enum lp_texture_usage usage
;
115 adjust_to_tile_bounds(dstx
, dsty
, width
, height
, &tx
, &ty
, &tw
, &th
);
117 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
118 boolean contained_y
= ty
+ y
>= dsty
&&
119 ty
+ y
+ TILE_SIZE
<= dsty
+ height
?
122 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
123 boolean contained_x
= tx
+ x
>= dstx
&&
124 tx
+ x
+ TILE_SIZE
<= dstx
+ width
?
128 * Set the usage mode to WRITE_ALL for the tiles which are
129 * completely contained by the dest rectangle.
131 if (contained_y
&& contained_x
)
132 usage
= LP_TEX_USAGE_WRITE_ALL
;
134 usage
= LP_TEX_USAGE_READ_WRITE
;
136 (void) llvmpipe_get_texture_tile_linear(dst_tex
,
146 const ubyte
*src_linear_ptr
147 = llvmpipe_get_texture_image_address(src_tex
, src_box
->z
,
149 LP_TEX_LAYOUT_LINEAR
);
150 ubyte
*dst_linear_ptr
151 = llvmpipe_get_texture_image_address(dst_tex
, dstz
,
153 LP_TEX_LAYOUT_LINEAR
);
155 if (dst_linear_ptr
&& src_linear_ptr
) {
156 util_copy_rect(dst_linear_ptr
, format
,
157 llvmpipe_resource_stride(&dst_tex
->base
, dst_level
),
161 llvmpipe_resource_stride(&src_tex
->base
, src_level
),
162 src_box
->x
, src_box
->y
);
169 llvmpipe_init_surface_functions(struct llvmpipe_context
*lp
)
171 lp
->pipe
.resource_copy_region
= lp_resource_copy
;
172 lp
->pipe
.clear_render_target
= util_clear_render_target
;
173 lp
->pipe
.clear_depth_stencil
= util_clear_depth_stencil
;