2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #include "r600_pipe.h"
24 #include "util/u_surface.h"
25 #include "util/u_blitter.h"
26 #include "util/u_format.h"
28 enum r600_blitter_op
/* bitmask */
30 R600_SAVE_FRAGMENT_STATE
= 1,
31 R600_SAVE_TEXTURES
= 2,
32 R600_SAVE_FRAMEBUFFER
= 4,
33 R600_DISABLE_RENDER_COND
= 8,
35 R600_CLEAR
= R600_SAVE_FRAGMENT_STATE
,
37 R600_CLEAR_SURFACE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
,
39 R600_COPY_BUFFER
= R600_DISABLE_RENDER_COND
,
41 R600_COPY_TEXTURE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_SAVE_TEXTURES
|
42 R600_DISABLE_RENDER_COND
,
44 R600_DECOMPRESS
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_DISABLE_RENDER_COND
,
46 R600_COLOR_RESOLVE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_DISABLE_RENDER_COND
49 static void r600_blitter_begin(struct pipe_context
*ctx
, enum r600_blitter_op op
)
51 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
53 r600_suspend_nontimer_queries(rctx
);
55 util_blitter_save_vertex_buffers(rctx
->blitter
,
56 util_last_bit(rctx
->vertex_buffer_state
.enabled_mask
),
57 rctx
->vertex_buffer_state
.vb
);
58 util_blitter_save_vertex_elements(rctx
->blitter
, rctx
->vertex_elements
);
59 util_blitter_save_vertex_shader(rctx
->blitter
, rctx
->vs_shader
);
60 util_blitter_save_so_targets(rctx
->blitter
, rctx
->num_so_targets
,
61 (struct pipe_stream_output_target
**)rctx
->so_targets
);
62 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_RASTERIZER
]);
64 if (op
& R600_SAVE_FRAGMENT_STATE
) {
65 if (rctx
->states
[R600_PIPE_STATE_VIEWPORT
]) {
66 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
);
68 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
69 util_blitter_save_blend(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_BLEND
]);
70 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_DSA
]);
71 if (rctx
->states
[R600_PIPE_STATE_STENCIL_REF
]) {
72 util_blitter_save_stencil_ref(rctx
->blitter
, &rctx
->stencil_ref
);
74 util_blitter_save_sample_mask(rctx
->blitter
, rctx
->sample_mask
.sample_mask
);
77 if (op
& R600_SAVE_FRAMEBUFFER
)
78 util_blitter_save_framebuffer(rctx
->blitter
, &rctx
->framebuffer
);
80 if (op
& R600_SAVE_TEXTURES
) {
81 util_blitter_save_fragment_sampler_states(
82 rctx
->blitter
, rctx
->ps_samplers
.n_samplers
,
83 (void**)rctx
->ps_samplers
.samplers
);
85 util_blitter_save_fragment_sampler_views(
86 rctx
->blitter
, util_last_bit(rctx
->ps_samplers
.views
.enabled_mask
),
87 (struct pipe_sampler_view
**)rctx
->ps_samplers
.views
.views
);
90 if ((op
& R600_DISABLE_RENDER_COND
) && rctx
->current_render_cond
) {
91 rctx
->saved_render_cond
= rctx
->current_render_cond
;
92 rctx
->saved_render_cond_mode
= rctx
->current_render_cond_mode
;
93 rctx
->context
.render_condition(&rctx
->context
, NULL
, 0);
98 static void r600_blitter_end(struct pipe_context
*ctx
)
100 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
101 if (rctx
->saved_render_cond
) {
102 rctx
->context
.render_condition(&rctx
->context
,
103 rctx
->saved_render_cond
,
104 rctx
->saved_render_cond_mode
);
105 rctx
->saved_render_cond
= NULL
;
107 r600_resume_nontimer_queries(rctx
);
110 static unsigned u_max_layer(struct pipe_resource
*r
, unsigned level
)
113 case PIPE_TEXTURE_CUBE
:
115 case PIPE_TEXTURE_3D
:
116 return u_minify(r
->depth0
, level
) - 1;
117 case PIPE_TEXTURE_1D_ARRAY
:
118 case PIPE_TEXTURE_2D_ARRAY
:
119 return r
->array_size
- 1;
125 static unsigned u_max_sample(struct pipe_resource
*r
)
127 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
130 void r600_blit_uncompress_depth(struct pipe_context
*ctx
,
131 struct r600_resource_texture
*texture
,
132 struct r600_resource_texture
*staging
,
133 unsigned first_level
, unsigned last_level
,
134 unsigned first_layer
, unsigned last_layer
,
135 unsigned first_sample
, unsigned last_sample
)
137 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
139 struct r600_resource_texture
*flushed_depth_texture
= staging
?
140 staging
: texture
->flushed_depth_texture
;
141 const struct util_format_description
*desc
=
142 util_format_description(texture
->resource
.b
.b
.format
);
145 if (!staging
&& !texture
->dirty_db_mask
)
148 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
149 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
154 /* Enable decompression in DB_RENDER_CONTROL */
155 rctx
->db_misc_state
.flush_depthstencil_through_cb
= true;
156 rctx
->db_misc_state
.copy_depth
= util_format_has_depth(desc
);
157 rctx
->db_misc_state
.copy_stencil
= util_format_has_stencil(desc
);
158 rctx
->db_misc_state
.copy_sample
= first_sample
;
159 r600_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
161 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
163 for (level
= first_level
; level
<= last_level
; level
++) {
164 if (!staging
&& !(texture
->dirty_db_mask
& (1 << level
)))
167 /* The smaller the mipmap level, the less layers there are
168 * as far as 3D textures are concerned. */
169 max_layer
= u_max_layer(&texture
->resource
.b
.b
, level
);
170 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
172 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
173 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
174 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
176 if (sample
!= rctx
->db_misc_state
.copy_sample
) {
177 rctx
->db_misc_state
.copy_sample
= sample
;
178 r600_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
181 surf_tmpl
.format
= texture
->real_format
;
182 surf_tmpl
.u
.tex
.level
= level
;
183 surf_tmpl
.u
.tex
.first_layer
= layer
;
184 surf_tmpl
.u
.tex
.last_layer
= layer
;
185 surf_tmpl
.usage
= PIPE_BIND_DEPTH_STENCIL
;
187 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
189 surf_tmpl
.format
= flushed_depth_texture
->real_format
;
190 surf_tmpl
.u
.tex
.level
= level
;
191 surf_tmpl
.u
.tex
.first_layer
= layer
;
192 surf_tmpl
.u
.tex
.last_layer
= layer
;
193 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
194 cbsurf
= ctx
->create_surface(ctx
,
195 &flushed_depth_texture
->resource
.b
.b
, &surf_tmpl
);
197 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
198 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
199 rctx
->custom_dsa_flush
, depth
);
200 r600_blitter_end(ctx
);
202 pipe_surface_reference(&zsurf
, NULL
);
203 pipe_surface_reference(&cbsurf
, NULL
);
207 /* The texture will always be dirty if some layers or samples aren't flushed.
208 * I don't think this case occurs often though. */
210 first_layer
== 0 && last_layer
== max_layer
&&
211 first_sample
== 0 && last_sample
== max_sample
) {
212 texture
->dirty_db_mask
&= ~(1 << level
);
216 /* reenable compression in DB_RENDER_CONTROL */
217 rctx
->db_misc_state
.flush_depthstencil_through_cb
= false;
218 r600_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
221 void r600_flush_depth_textures(struct r600_context
*rctx
,
222 struct r600_samplerview_state
*textures
)
225 unsigned depth_texture_mask
= textures
->depth_texture_mask
;
227 while (depth_texture_mask
) {
228 struct pipe_sampler_view
*view
;
229 struct r600_resource_texture
*tex
;
231 i
= u_bit_scan(&depth_texture_mask
);
233 view
= &textures
->views
[i
]->base
;
236 tex
= (struct r600_resource_texture
*)view
->texture
;
237 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
239 r600_blit_uncompress_depth(&rctx
->context
, tex
, NULL
,
240 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
241 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
),
242 0, u_max_sample(&tex
->resource
.b
.b
));
246 static void r600_copy_first_sample(struct pipe_context
*ctx
,
247 const struct pipe_resolve_info
*info
)
249 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
250 struct r600_resource_texture
*rsrc
= (struct r600_resource_texture
*)info
->src
.res
;
251 struct pipe_surface
*dst_view
, dst_templ
;
252 struct pipe_sampler_view src_templ
, *src_view
;
255 if (rsrc
->is_depth
&& !rsrc
->is_flushing_texture
) {
256 if (!r600_init_flushed_depth_texture(ctx
, info
->src
.res
, NULL
))
259 /* Decompress the first sample only. */
260 r600_blit_uncompress_depth(ctx
, rsrc
, NULL
,
262 info
->src
.layer
, info
->src
.layer
,
266 /* this is correct for upside-down blits too */
267 u_box_2d(info
->src
.x0
,
269 info
->src
.x1
- info
->src
.x0
,
270 info
->src
.y1
- info
->src
.y0
, &box
);
272 /* Initialize the surface. */
273 util_blitter_default_dst_texture(&dst_templ
, info
->dst
.res
,
274 info
->dst
.level
, info
->dst
.layer
, &box
);
275 dst_view
= ctx
->create_surface(ctx
, info
->dst
.res
, &dst_templ
);
277 /* Initialize the sampler view. */
278 util_blitter_default_src_texture(&src_templ
, info
->src
.res
, 0);
279 src_view
= ctx
->create_sampler_view(ctx
, info
->src
.res
, &src_templ
);
281 /* Copy the first sample into dst. */
282 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
283 util_blitter_copy_texture_view(rctx
->blitter
, dst_view
, ~0, info
->dst
.x0
,
284 info
->dst
.y0
, src_view
, 0, &box
,
285 info
->src
.res
->width0
, info
->src
.res
->height0
,
287 r600_blitter_end(ctx
);
289 pipe_surface_reference(&dst_view
, NULL
);
290 pipe_sampler_view_reference(&src_view
, NULL
);
293 static boolean
is_simple_resolve(const struct pipe_resolve_info
*info
)
295 unsigned dst_width
= u_minify(info
->dst
.res
->width0
, info
->dst
.level
);
296 unsigned dst_height
= u_minify(info
->dst
.res
->height0
, info
->dst
.level
);
298 return info
->dst
.res
->format
== info
->src
.res
->format
&&
299 dst_width
== info
->src
.res
->width0
&&
300 dst_height
== info
->src
.res
->height0
&&
303 info
->dst
.x1
== dst_width
&&
304 info
->dst
.y1
== dst_height
&&
307 info
->src
.x1
== dst_width
&&
308 info
->src
.y1
== dst_height
;
311 static void r600_color_resolve(struct pipe_context
*ctx
,
312 const struct pipe_resolve_info
*info
)
314 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
315 struct pipe_screen
*screen
= ctx
->screen
;
316 struct pipe_resource
*tmp
, templ
;
319 assert((info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
);
321 if (is_simple_resolve(info
)) {
322 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
323 util_blitter_resolve_color_custom(rctx
->blitter
,
324 info
->dst
.res
, info
->dst
.level
, info
->dst
.layer
,
325 info
->src
.res
, info
->src
.layer
,
326 rctx
->custom_blend_resolve
);
327 r600_blitter_end(ctx
);
331 /* resolve into a temporary texture, then blit */
332 templ
.target
= PIPE_TEXTURE_2D
;
333 templ
.format
= info
->src
.res
->format
;
334 templ
.width0
= info
->src
.res
->width0
;
335 templ
.height0
= info
->src
.res
->height0
;
337 templ
.array_size
= 1;
338 templ
.last_level
= 0;
339 templ
.nr_samples
= 0;
340 templ
.usage
= PIPE_USAGE_STATIC
;
341 templ
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
344 tmp
= screen
->resource_create(screen
, &templ
);
346 /* XXX use scissor, so that only the needed part of the resource is resolved */
347 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
348 util_blitter_resolve_color_custom(rctx
->blitter
,
350 info
->src
.res
, info
->src
.layer
,
351 rctx
->custom_blend_resolve
);
352 r600_blitter_end(ctx
);
354 /* this is correct for upside-down blits too */
355 u_box_2d(info
->src
.x0
,
357 info
->src
.x1
- info
->src
.x0
,
358 info
->src
.y1
- info
->src
.y0
, &box
);
360 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
361 util_blitter_copy_texture(rctx
->blitter
, info
->dst
.res
, info
->dst
.level
,
362 ~0, info
->dst
.x0
, info
->dst
.y0
, info
->dst
.layer
,
364 r600_blitter_end(ctx
);
366 pipe_resource_reference(&tmp
, NULL
);
369 static void r600_resource_resolve(struct pipe_context
*ctx
,
370 const struct pipe_resolve_info
*info
)
372 /* make sure we're doing a resolve operation */
373 assert(info
->src
.res
->nr_samples
> 1);
374 assert(info
->dst
.res
->nr_samples
<= 1);
376 /* limitations of multisample resources */
377 assert(info
->src
.res
->last_level
== 0);
378 assert(info
->src
.res
->target
== PIPE_TEXTURE_2D
||
379 info
->src
.res
->target
== PIPE_TEXTURE_2D_ARRAY
);
381 /* check if the resolve box is valid */
382 assert(info
->dst
.x0
< info
->dst
.x1
);
383 assert(info
->dst
.y0
< info
->dst
.y1
);
385 /* scaled resolve isn't allowed */
386 assert(abs(info
->dst
.x0
- info
->dst
.x1
) ==
387 abs(info
->src
.x0
- info
->src
.x1
));
388 assert(abs(info
->dst
.y0
- info
->dst
.y1
) ==
389 abs(info
->src
.y0
- info
->src
.y1
));
391 if ((info
->mask
& PIPE_MASK_ZS
) ||
392 util_format_is_pure_integer(info
->src
.res
->format
)) {
393 r600_copy_first_sample(ctx
, info
);
395 r600_color_resolve(ctx
, info
);
399 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
400 const union pipe_color_union
*color
,
401 double depth
, unsigned stencil
)
403 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
404 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
406 r600_blitter_begin(ctx
, R600_CLEAR
);
407 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
408 fb
->nr_cbufs
, buffers
, fb
->nr_cbufs
? fb
->cbufs
[0]->format
: PIPE_FORMAT_NONE
,
409 color
, depth
, stencil
);
410 r600_blitter_end(ctx
);
413 static void r600_clear_render_target(struct pipe_context
*ctx
,
414 struct pipe_surface
*dst
,
415 const union pipe_color_union
*color
,
416 unsigned dstx
, unsigned dsty
,
417 unsigned width
, unsigned height
)
419 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
421 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
422 util_blitter_clear_render_target(rctx
->blitter
, dst
, color
,
423 dstx
, dsty
, width
, height
);
424 r600_blitter_end(ctx
);
427 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
428 struct pipe_surface
*dst
,
429 unsigned clear_flags
,
432 unsigned dstx
, unsigned dsty
,
433 unsigned width
, unsigned height
)
435 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
437 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
438 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
439 dstx
, dsty
, width
, height
);
440 r600_blitter_end(ctx
);
443 void r600_copy_buffer(struct pipe_context
*ctx
, struct
444 pipe_resource
*dst
, unsigned dstx
,
445 struct pipe_resource
*src
, const struct pipe_box
*src_box
)
447 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
449 if (rctx
->screen
->has_streamout
&&
450 /* Require dword alignment. */
451 dstx
% 4 == 0 && src_box
->x
% 4 == 0 && src_box
->width
% 4 == 0) {
452 r600_blitter_begin(ctx
, R600_COPY_BUFFER
);
453 util_blitter_copy_buffer(rctx
->blitter
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
454 r600_blitter_end(ctx
);
456 util_resource_copy_region(ctx
, dst
, 0, dstx
, 0, 0, src
, 0, src_box
);
460 struct texture_orig_info
{
470 static void r600_compressed_to_blittable(struct pipe_resource
*tex
,
472 struct texture_orig_info
*orig
)
474 struct r600_resource_texture
*rtex
= (struct r600_resource_texture
*)tex
;
475 unsigned pixsize
= util_format_get_blocksize(rtex
->real_format
);
477 int new_height
, new_width
;
479 orig
->format
= tex
->format
;
480 orig
->width0
= tex
->width0
;
481 orig
->height0
= tex
->height0
;
482 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
483 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
484 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
485 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
488 new_format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
490 new_format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
492 new_width
= util_format_get_nblocksx(tex
->format
, orig
->width0
);
493 new_height
= util_format_get_nblocksy(tex
->format
, orig
->height0
);
495 tex
->width0
= new_width
;
496 tex
->height0
= new_height
;
497 tex
->format
= new_format
;
498 rtex
->surface
.level
[0].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix0_x
);
499 rtex
->surface
.level
[0].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix0_y
);
500 rtex
->surface
.level
[level
].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix_x
);
501 rtex
->surface
.level
[level
].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix_y
);
504 static void r600_change_format(struct pipe_resource
*tex
,
506 struct texture_orig_info
*orig
,
507 enum pipe_format format
)
509 struct r600_resource_texture
*rtex
= (struct r600_resource_texture
*)tex
;
511 orig
->format
= tex
->format
;
512 orig
->width0
= tex
->width0
;
513 orig
->height0
= tex
->height0
;
514 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
515 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
516 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
517 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
519 tex
->format
= format
;
522 static void r600_reset_blittable_to_orig(struct pipe_resource
*tex
,
524 struct texture_orig_info
*orig
)
526 struct r600_resource_texture
*rtex
= (struct r600_resource_texture
*)tex
;
528 tex
->format
= orig
->format
;
529 tex
->width0
= orig
->width0
;
530 tex
->height0
= orig
->height0
;
531 rtex
->surface
.level
[0].npix_x
= orig
->npix0_x
;
532 rtex
->surface
.level
[0].npix_y
= orig
->npix0_y
;
533 rtex
->surface
.level
[level
].npix_x
= orig
->npix_x
;
534 rtex
->surface
.level
[level
].npix_y
= orig
->npix_y
;
537 static void r600_resource_copy_region(struct pipe_context
*ctx
,
538 struct pipe_resource
*dst
,
540 unsigned dstx
, unsigned dsty
, unsigned dstz
,
541 struct pipe_resource
*src
,
543 const struct pipe_box
*src_box
)
545 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
546 struct r600_resource_texture
*rsrc
= (struct r600_resource_texture
*)src
;
547 struct texture_orig_info orig_info
[2];
548 struct pipe_box sbox
;
549 const struct pipe_box
*psbox
= src_box
;
550 boolean restore_orig
[2];
552 memset(orig_info
, 0, sizeof(orig_info
));
554 /* Handle buffers first. */
555 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
556 r600_copy_buffer(ctx
, dst
, dstx
, src
, src_box
);
560 /* This must be done before entering u_blitter to avoid recursion. */
561 if (rsrc
->is_depth
&& !rsrc
->is_flushing_texture
) {
562 if (!r600_init_flushed_depth_texture(ctx
, src
, NULL
))
565 r600_blit_uncompress_depth(ctx
, rsrc
, NULL
,
566 src_level
, src_level
,
567 src_box
->z
, src_box
->z
+ src_box
->depth
- 1,
568 0, u_max_sample(src
));
571 restore_orig
[0] = restore_orig
[1] = FALSE
;
573 if (util_format_is_compressed(src
->format
) &&
574 util_format_is_compressed(dst
->format
)) {
575 r600_compressed_to_blittable(src
, src_level
, &orig_info
[0]);
576 restore_orig
[0] = TRUE
;
577 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
578 sbox
.y
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->y
);
580 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
581 sbox
.height
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->height
);
582 sbox
.depth
= src_box
->depth
;
585 r600_compressed_to_blittable(dst
, dst_level
, &orig_info
[1]);
586 restore_orig
[1] = TRUE
;
587 /* translate the dst box as well */
588 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
589 dsty
= util_format_get_nblocksy(orig_info
[1].format
, dsty
);
590 } else if (!util_blitter_is_copy_supported(rctx
->blitter
, dst
, src
,
592 unsigned blocksize
= util_format_get_blocksize(src
->format
);
596 r600_change_format(src
, src_level
, &orig_info
[0],
597 PIPE_FORMAT_R8_UNORM
);
598 r600_change_format(dst
, dst_level
, &orig_info
[1],
599 PIPE_FORMAT_R8_UNORM
);
602 r600_change_format(src
, src_level
, &orig_info
[0],
603 PIPE_FORMAT_R8G8B8A8_UNORM
);
604 r600_change_format(dst
, dst_level
, &orig_info
[1],
605 PIPE_FORMAT_R8G8B8A8_UNORM
);
608 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
609 util_format_short_name(src
->format
), blocksize
);
612 restore_orig
[0] = TRUE
;
613 restore_orig
[1] = TRUE
;
616 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
617 util_blitter_copy_texture(rctx
->blitter
, dst
, dst_level
, ~0, dstx
, dsty
, dstz
,
618 src
, src_level
, 0, psbox
);
619 r600_blitter_end(ctx
);
622 r600_reset_blittable_to_orig(src
, src_level
, &orig_info
[0]);
625 r600_reset_blittable_to_orig(dst
, dst_level
, &orig_info
[1]);
628 void r600_init_blit_functions(struct r600_context
*rctx
)
630 rctx
->context
.clear
= r600_clear
;
631 rctx
->context
.clear_render_target
= r600_clear_render_target
;
632 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
633 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
634 rctx
->context
.resource_resolve
= r600_resource_resolve
;