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 /* Fallback for buffers. */
71 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
72 util_resource_copy_region(pipe
, dst
, dst_level
, dstx
, dsty
, dstz
,
73 src
, src_level
, src_box
);
77 llvmpipe_flush_resource(pipe
,
79 FALSE
, /* read_only */
80 TRUE
, /* cpu_access */
81 FALSE
, /* do_not_block */
84 llvmpipe_flush_resource(pipe
,
85 src
, src_level
, src_box
->z
,
87 TRUE
, /* cpu_access */
88 FALSE
, /* do_not_block */
92 printf("surface copy from %u lvl %u to %u lvl %u: %u,%u,%u to %u,%u,%u %u x %u x %u\n",
93 src_tex->id, src_level, dst_tex->id, dst_level,
94 src_box->x, src_box->y, src_box->z, dstx, dsty, dstz,
95 src_box->width, src_box->height, src_box->depth);
98 /* set src tiles to linear layout */
100 unsigned tx
, ty
, tw
, th
;
103 adjust_to_tile_bounds(src_box
->x
, src_box
->y
, width
, height
,
106 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
107 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
108 (void) llvmpipe_get_texture_tile_linear(src_tex
,
109 src_box
->z
, src_level
,
116 /* set dst tiles to linear layout */
118 unsigned tx
, ty
, tw
, th
;
120 enum lp_texture_usage usage
;
122 adjust_to_tile_bounds(dstx
, dsty
, width
, height
, &tx
, &ty
, &tw
, &th
);
124 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
125 boolean contained_y
= ty
+ y
>= dsty
&&
126 ty
+ y
+ TILE_SIZE
<= dsty
+ height
?
129 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
130 boolean contained_x
= tx
+ x
>= dstx
&&
131 tx
+ x
+ TILE_SIZE
<= dstx
+ width
?
135 * Set the usage mode to WRITE_ALL for the tiles which are
136 * completely contained by the dest rectangle.
138 if (contained_y
&& contained_x
)
139 usage
= LP_TEX_USAGE_WRITE_ALL
;
141 usage
= LP_TEX_USAGE_READ_WRITE
;
143 (void) llvmpipe_get_texture_tile_linear(dst_tex
,
153 const ubyte
*src_linear_ptr
154 = llvmpipe_get_texture_image_address(src_tex
, src_box
->z
,
156 LP_TEX_LAYOUT_LINEAR
);
157 ubyte
*dst_linear_ptr
158 = llvmpipe_get_texture_image_address(dst_tex
, dstz
,
160 LP_TEX_LAYOUT_LINEAR
);
162 if (dst_linear_ptr
&& src_linear_ptr
) {
163 util_copy_rect(dst_linear_ptr
, format
,
164 llvmpipe_resource_stride(&dst_tex
->base
, dst_level
),
168 llvmpipe_resource_stride(&src_tex
->base
, src_level
),
169 src_box
->x
, src_box
->y
);
175 static void lp_blit(struct pipe_context
*pipe
,
176 const struct pipe_blit_info
*blit_info
)
178 struct llvmpipe_context
*lp
= llvmpipe_context(pipe
);
179 struct pipe_blit_info info
= *blit_info
;
181 if (info
.src
.resource
->nr_samples
> 1 &&
182 info
.dst
.resource
->nr_samples
<= 1 &&
183 !util_format_is_depth_or_stencil(info
.src
.resource
->format
) &&
184 !util_format_is_pure_integer(info
.src
.resource
->format
)) {
185 debug_printf("llvmpipe: color resolve unimplemented\n");
189 if (util_try_blit_via_copy_region(pipe
, &info
)) {
193 if (info
.mask
& PIPE_MASK_S
) {
194 debug_printf("llvmpipe: cannot blit stencil, skipping\n");
195 info
.mask
&= ~PIPE_MASK_S
;
198 if (!util_blitter_is_blit_supported(lp
->blitter
, &info
)) {
199 debug_printf("llvmpipe: blit unsupported %s -> %s\n",
200 util_format_short_name(info
.src
.resource
->format
),
201 util_format_short_name(info
.dst
.resource
->format
));
205 /* XXX turn off occlusion and streamout queries */
207 util_blitter_save_vertex_buffer_slot(lp
->blitter
, lp
->vertex_buffer
);
208 util_blitter_save_vertex_elements(lp
->blitter
, (void*)lp
->velems
);
209 util_blitter_save_vertex_shader(lp
->blitter
, (void*)lp
->vs
);
210 util_blitter_save_geometry_shader(lp
->blitter
, (void*)lp
->gs
);
211 util_blitter_save_so_targets(lp
->blitter
, lp
->num_so_targets
,
212 (struct pipe_stream_output_target
**)lp
->so_targets
);
213 util_blitter_save_rasterizer(lp
->blitter
, (void*)lp
->rasterizer
);
214 util_blitter_save_viewport(lp
->blitter
, &lp
->viewport
);
215 util_blitter_save_scissor(lp
->blitter
, &lp
->scissor
);
216 util_blitter_save_fragment_shader(lp
->blitter
, lp
->fs
);
217 util_blitter_save_blend(lp
->blitter
, (void*)lp
->blend
);
218 util_blitter_save_depth_stencil_alpha(lp
->blitter
, (void*)lp
->depth_stencil
);
219 util_blitter_save_stencil_ref(lp
->blitter
, &lp
->stencil_ref
);
220 /*util_blitter_save_sample_mask(sp->blitter, lp->sample_mask);*/
221 util_blitter_save_framebuffer(lp
->blitter
, &lp
->framebuffer
);
222 util_blitter_save_fragment_sampler_states(lp
->blitter
,
223 lp
->num_samplers
[PIPE_SHADER_FRAGMENT
],
224 (void**)lp
->samplers
[PIPE_SHADER_FRAGMENT
]);
225 util_blitter_save_fragment_sampler_views(lp
->blitter
,
226 lp
->num_sampler_views
[PIPE_SHADER_FRAGMENT
],
227 lp
->sampler_views
[PIPE_SHADER_FRAGMENT
]);
228 util_blitter_save_render_condition(lp
->blitter
, lp
->render_cond_query
,
229 lp
->render_cond_mode
);
230 util_blitter_blit(lp
->blitter
, &info
);
235 llvmpipe_init_surface_functions(struct llvmpipe_context
*lp
)
237 lp
->pipe
.resource_copy_region
= lp_resource_copy
;
238 lp
->pipe
.clear_render_target
= util_clear_render_target
;
239 lp
->pipe
.clear_depth_stencil
= util_clear_depth_stencil
;
240 lp
->pipe
.blit
= lp_blit
;