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_decompress_depth(struct pipe_context
*ctx
,
131 struct r600_texture
*texture
,
132 struct r600_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_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_level_mask
)
148 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
150 /* XXX Decompressing MSAA depth textures is broken on R6xx.
151 * There is also a hardlock if CMASK and FMASK are not present.
152 * Just skip this until we find out how to fix it. */
153 if (rctx
->chip_class
== R600
&& max_sample
> 0) {
154 texture
->dirty_level_mask
= 0;
158 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
159 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
164 /* Enable decompression in DB_RENDER_CONTROL */
165 rctx
->db_misc_state
.flush_depthstencil_through_cb
= true;
166 rctx
->db_misc_state
.copy_depth
= util_format_has_depth(desc
);
167 rctx
->db_misc_state
.copy_stencil
= util_format_has_stencil(desc
);
168 rctx
->db_misc_state
.copy_sample
= first_sample
;
169 r600_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
172 for (level
= first_level
; level
<= last_level
; level
++) {
173 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
176 /* The smaller the mipmap level, the less layers there are
177 * as far as 3D textures are concerned. */
178 max_layer
= u_max_layer(&texture
->resource
.b
.b
, level
);
179 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
181 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
182 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
183 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
185 if (sample
!= rctx
->db_misc_state
.copy_sample
) {
186 rctx
->db_misc_state
.copy_sample
= sample
;
187 r600_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
190 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
191 surf_tmpl
.u
.tex
.level
= level
;
192 surf_tmpl
.u
.tex
.first_layer
= layer
;
193 surf_tmpl
.u
.tex
.last_layer
= layer
;
194 surf_tmpl
.usage
= PIPE_BIND_DEPTH_STENCIL
;
196 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
198 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
199 surf_tmpl
.u
.tex
.level
= level
;
200 surf_tmpl
.u
.tex
.first_layer
= layer
;
201 surf_tmpl
.u
.tex
.last_layer
= layer
;
202 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
203 cbsurf
= ctx
->create_surface(ctx
,
204 &flushed_depth_texture
->resource
.b
.b
, &surf_tmpl
);
206 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
207 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
208 rctx
->custom_dsa_flush
, depth
);
209 r600_blitter_end(ctx
);
211 pipe_surface_reference(&zsurf
, NULL
);
212 pipe_surface_reference(&cbsurf
, NULL
);
216 /* The texture will always be dirty if some layers or samples aren't flushed.
217 * I don't think this case occurs often though. */
219 first_layer
== 0 && last_layer
== max_layer
&&
220 first_sample
== 0 && last_sample
== max_sample
) {
221 texture
->dirty_level_mask
&= ~(1 << level
);
225 /* reenable compression in DB_RENDER_CONTROL */
226 rctx
->db_misc_state
.flush_depthstencil_through_cb
= false;
227 r600_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
230 void r600_decompress_depth_textures(struct r600_context
*rctx
,
231 struct r600_samplerview_state
*textures
)
234 unsigned depth_texture_mask
= textures
->compressed_depthtex_mask
;
236 while (depth_texture_mask
) {
237 struct pipe_sampler_view
*view
;
238 struct r600_texture
*tex
;
240 i
= u_bit_scan(&depth_texture_mask
);
242 view
= &textures
->views
[i
]->base
;
245 tex
= (struct r600_texture
*)view
->texture
;
246 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
248 r600_blit_decompress_depth(&rctx
->context
, tex
, NULL
,
249 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
250 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
),
251 0, u_max_sample(&tex
->resource
.b
.b
));
255 static void r600_blit_decompress_color(struct pipe_context
*ctx
,
256 struct r600_texture
*rtex
,
257 unsigned first_level
, unsigned last_level
,
258 unsigned first_layer
, unsigned last_layer
)
260 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
261 unsigned layer
, level
, checked_last_layer
, max_layer
;
263 if (!rtex
->dirty_level_mask
)
266 for (level
= first_level
; level
<= last_level
; level
++) {
267 if (!(rtex
->dirty_level_mask
& (1 << level
)))
270 /* The smaller the mipmap level, the less layers there are
271 * as far as 3D textures are concerned. */
272 max_layer
= u_max_layer(&rtex
->resource
.b
.b
, level
);
273 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
275 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
276 struct pipe_surface
*cbsurf
, surf_tmpl
;
278 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
279 surf_tmpl
.u
.tex
.level
= level
;
280 surf_tmpl
.u
.tex
.first_layer
= layer
;
281 surf_tmpl
.u
.tex
.last_layer
= layer
;
282 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
283 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
285 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
286 util_blitter_custom_color(rctx
->blitter
, cbsurf
,
287 rctx
->custom_blend_decompress
);
288 r600_blitter_end(ctx
);
290 pipe_surface_reference(&cbsurf
, NULL
);
293 /* The texture will always be dirty if some layers or samples aren't flushed.
294 * I don't think this case occurs often though. */
295 if (first_layer
== 0 && last_layer
== max_layer
) {
296 rtex
->dirty_level_mask
&= ~(1 << level
);
301 void r600_decompress_color_textures(struct r600_context
*rctx
,
302 struct r600_samplerview_state
*textures
)
305 unsigned mask
= textures
->compressed_colortex_mask
;
308 struct pipe_sampler_view
*view
;
309 struct r600_texture
*tex
;
311 i
= u_bit_scan(&mask
);
313 view
= &textures
->views
[i
]->base
;
316 tex
= (struct r600_texture
*)view
->texture
;
317 assert(tex
->cmask_size
&& tex
->fmask_size
);
319 r600_blit_decompress_color(&rctx
->context
, tex
,
320 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
321 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
325 static void r600_copy_first_sample(struct pipe_context
*ctx
,
326 const struct pipe_resolve_info
*info
)
328 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
329 struct r600_texture
*rsrc
= (struct r600_texture
*)info
->src
.res
;
330 struct pipe_surface
*dst_view
, dst_templ
;
331 struct pipe_sampler_view src_templ
, *src_view
;
334 if (rsrc
->is_depth
&& !rsrc
->is_flushing_texture
) {
335 if (!r600_init_flushed_depth_texture(ctx
, info
->src
.res
, NULL
))
338 /* Decompress the first sample only. */
339 r600_blit_decompress_depth(ctx
, rsrc
, NULL
,
341 info
->src
.layer
, info
->src
.layer
,
344 if (rsrc
->fmask_size
&& rsrc
->cmask_size
) {
345 r600_blit_decompress_color(ctx
, rsrc
,
347 info
->src
.layer
, info
->src
.layer
);
350 /* this is correct for upside-down blits too */
351 u_box_2d(info
->src
.x0
,
353 info
->src
.x1
- info
->src
.x0
,
354 info
->src
.y1
- info
->src
.y0
, &box
);
356 /* Initialize the surface. */
357 util_blitter_default_dst_texture(&dst_templ
, info
->dst
.res
,
358 info
->dst
.level
, info
->dst
.layer
, &box
);
359 dst_view
= ctx
->create_surface(ctx
, info
->dst
.res
, &dst_templ
);
361 /* Initialize the sampler view. */
362 util_blitter_default_src_texture(&src_templ
, info
->src
.res
, 0);
363 src_view
= ctx
->create_sampler_view(ctx
, info
->src
.res
, &src_templ
);
365 /* Copy the first sample into dst. */
366 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
367 util_blitter_copy_texture_view(rctx
->blitter
, dst_view
, ~0, info
->dst
.x0
,
368 info
->dst
.y0
, src_view
, 0, &box
,
369 info
->src
.res
->width0
, info
->src
.res
->height0
,
371 r600_blitter_end(ctx
);
373 pipe_surface_reference(&dst_view
, NULL
);
374 pipe_sampler_view_reference(&src_view
, NULL
);
377 static boolean
is_simple_resolve(const struct pipe_resolve_info
*info
)
379 unsigned dst_width
= u_minify(info
->dst
.res
->width0
, info
->dst
.level
);
380 unsigned dst_height
= u_minify(info
->dst
.res
->height0
, info
->dst
.level
);
382 return info
->dst
.res
->format
== info
->src
.res
->format
&&
383 dst_width
== info
->src
.res
->width0
&&
384 dst_height
== info
->src
.res
->height0
&&
387 info
->dst
.x1
== dst_width
&&
388 info
->dst
.y1
== dst_height
&&
391 info
->src
.x1
== dst_width
&&
392 info
->src
.y1
== dst_height
;
395 static void r600_color_resolve(struct pipe_context
*ctx
,
396 const struct pipe_resolve_info
*info
)
398 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
399 struct pipe_screen
*screen
= ctx
->screen
;
400 struct pipe_resource
*tmp
, templ
;
403 assert((info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
);
405 if (is_simple_resolve(info
)) {
406 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
407 util_blitter_custom_resolve_color(rctx
->blitter
,
408 info
->dst
.res
, info
->dst
.level
, info
->dst
.layer
,
409 info
->src
.res
, info
->src
.layer
,
410 rctx
->custom_blend_resolve
);
411 r600_blitter_end(ctx
);
415 /* resolve into a temporary texture, then blit */
416 templ
.target
= PIPE_TEXTURE_2D
;
417 templ
.format
= info
->src
.res
->format
;
418 templ
.width0
= info
->src
.res
->width0
;
419 templ
.height0
= info
->src
.res
->height0
;
421 templ
.array_size
= 1;
422 templ
.last_level
= 0;
423 templ
.nr_samples
= 0;
424 templ
.usage
= PIPE_USAGE_STATIC
;
425 templ
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
428 tmp
= screen
->resource_create(screen
, &templ
);
430 /* XXX use scissor, so that only the needed part of the resource is resolved */
431 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
432 util_blitter_custom_resolve_color(rctx
->blitter
,
434 info
->src
.res
, info
->src
.layer
,
435 rctx
->custom_blend_resolve
);
436 r600_blitter_end(ctx
);
438 /* this is correct for upside-down blits too */
439 u_box_2d(info
->src
.x0
,
441 info
->src
.x1
- info
->src
.x0
,
442 info
->src
.y1
- info
->src
.y0
, &box
);
444 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
445 util_blitter_copy_texture(rctx
->blitter
, info
->dst
.res
, info
->dst
.level
,
446 ~0, info
->dst
.x0
, info
->dst
.y0
, info
->dst
.layer
,
448 r600_blitter_end(ctx
);
450 pipe_resource_reference(&tmp
, NULL
);
453 static void r600_resource_resolve(struct pipe_context
*ctx
,
454 const struct pipe_resolve_info
*info
)
456 /* make sure we're doing a resolve operation */
457 assert(info
->src
.res
->nr_samples
> 1);
458 assert(info
->dst
.res
->nr_samples
<= 1);
460 /* limitations of multisample resources */
461 assert(info
->src
.res
->last_level
== 0);
462 assert(info
->src
.res
->target
== PIPE_TEXTURE_2D
||
463 info
->src
.res
->target
== PIPE_TEXTURE_2D_ARRAY
);
465 /* check if the resolve box is valid */
466 assert(info
->dst
.x0
< info
->dst
.x1
);
467 assert(info
->dst
.y0
< info
->dst
.y1
);
469 /* scaled resolve isn't allowed */
470 assert(abs(info
->dst
.x0
- info
->dst
.x1
) ==
471 abs(info
->src
.x0
- info
->src
.x1
));
472 assert(abs(info
->dst
.y0
- info
->dst
.y1
) ==
473 abs(info
->src
.y0
- info
->src
.y1
));
475 if ((info
->mask
& PIPE_MASK_ZS
) ||
476 util_format_is_pure_integer(info
->src
.res
->format
)) {
477 r600_copy_first_sample(ctx
, info
);
479 r600_color_resolve(ctx
, info
);
483 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
484 const union pipe_color_union
*color
,
485 double depth
, unsigned stencil
)
487 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
488 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
490 r600_blitter_begin(ctx
, R600_CLEAR
);
491 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
492 fb
->nr_cbufs
, buffers
, fb
->nr_cbufs
? fb
->cbufs
[0]->format
: PIPE_FORMAT_NONE
,
493 color
, depth
, stencil
);
494 r600_blitter_end(ctx
);
497 static void r600_clear_render_target(struct pipe_context
*ctx
,
498 struct pipe_surface
*dst
,
499 const union pipe_color_union
*color
,
500 unsigned dstx
, unsigned dsty
,
501 unsigned width
, unsigned height
)
503 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
505 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
506 util_blitter_clear_render_target(rctx
->blitter
, dst
, color
,
507 dstx
, dsty
, width
, height
);
508 r600_blitter_end(ctx
);
511 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
512 struct pipe_surface
*dst
,
513 unsigned clear_flags
,
516 unsigned dstx
, unsigned dsty
,
517 unsigned width
, unsigned height
)
519 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
521 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
522 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
523 dstx
, dsty
, width
, height
);
524 r600_blitter_end(ctx
);
527 void r600_copy_buffer(struct pipe_context
*ctx
, struct
528 pipe_resource
*dst
, unsigned dstx
,
529 struct pipe_resource
*src
, const struct pipe_box
*src_box
)
531 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
533 if (rctx
->screen
->has_streamout
&&
534 /* Require dword alignment. */
535 dstx
% 4 == 0 && src_box
->x
% 4 == 0 && src_box
->width
% 4 == 0) {
536 r600_blitter_begin(ctx
, R600_COPY_BUFFER
);
537 util_blitter_copy_buffer(rctx
->blitter
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
538 r600_blitter_end(ctx
);
540 util_resource_copy_region(ctx
, dst
, 0, dstx
, 0, 0, src
, 0, src_box
);
544 struct texture_orig_info
{
554 static void r600_compressed_to_blittable(struct pipe_resource
*tex
,
556 struct texture_orig_info
*orig
)
558 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
559 unsigned pixsize
= util_format_get_blocksize(rtex
->resource
.b
.b
.format
);
561 int new_height
, new_width
;
563 orig
->format
= tex
->format
;
564 orig
->width0
= tex
->width0
;
565 orig
->height0
= tex
->height0
;
566 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
567 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
568 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
569 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
572 new_format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
574 new_format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
576 new_width
= util_format_get_nblocksx(tex
->format
, orig
->width0
);
577 new_height
= util_format_get_nblocksy(tex
->format
, orig
->height0
);
579 tex
->width0
= new_width
;
580 tex
->height0
= new_height
;
581 tex
->format
= new_format
;
582 rtex
->surface
.level
[0].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix0_x
);
583 rtex
->surface
.level
[0].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix0_y
);
584 rtex
->surface
.level
[level
].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix_x
);
585 rtex
->surface
.level
[level
].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix_y
);
588 static void r600_subsampled_2x1_32bpp_to_blittable(struct pipe_resource
*tex
,
590 struct texture_orig_info
*orig
)
592 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
594 orig
->format
= tex
->format
;
595 orig
->width0
= tex
->width0
;
596 orig
->height0
= tex
->height0
;
597 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
598 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
599 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
600 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
602 tex
->width0
= util_format_get_nblocksx(orig
->format
, orig
->width0
);
603 tex
->format
= PIPE_FORMAT_R8G8B8A8_UINT
;
604 rtex
->surface
.level
[0].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix0_x
);
605 rtex
->surface
.level
[level
].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix_x
);
608 static void r600_change_format(struct pipe_resource
*tex
,
610 struct texture_orig_info
*orig
,
611 enum pipe_format format
)
613 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
615 orig
->format
= tex
->format
;
616 orig
->width0
= tex
->width0
;
617 orig
->height0
= tex
->height0
;
618 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
619 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
620 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
621 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
623 tex
->format
= format
;
626 static void r600_reset_blittable_to_orig(struct pipe_resource
*tex
,
628 struct texture_orig_info
*orig
)
630 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
632 tex
->format
= orig
->format
;
633 tex
->width0
= orig
->width0
;
634 tex
->height0
= orig
->height0
;
635 rtex
->surface
.level
[0].npix_x
= orig
->npix0_x
;
636 rtex
->surface
.level
[0].npix_y
= orig
->npix0_y
;
637 rtex
->surface
.level
[level
].npix_x
= orig
->npix_x
;
638 rtex
->surface
.level
[level
].npix_y
= orig
->npix_y
;
641 static bool util_format_is_subsampled_2x1_32bpp(enum pipe_format format
)
643 const struct util_format_description
*desc
= util_format_description(format
);
645 return desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
&&
646 desc
->block
.width
== 2 &&
647 desc
->block
.height
== 1 &&
648 desc
->block
.bits
== 32;
651 static void r600_resource_copy_region(struct pipe_context
*ctx
,
652 struct pipe_resource
*dst
,
654 unsigned dstx
, unsigned dsty
, unsigned dstz
,
655 struct pipe_resource
*src
,
657 const struct pipe_box
*src_box
)
659 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
660 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
661 struct texture_orig_info orig_info
[2];
662 struct pipe_box sbox
;
663 const struct pipe_box
*psbox
= src_box
;
664 boolean restore_orig
[2];
665 unsigned last_sample
, i
;
667 memset(orig_info
, 0, sizeof(orig_info
));
669 /* Handle buffers first. */
670 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
671 r600_copy_buffer(ctx
, dst
, dstx
, src
, src_box
);
675 assert(u_max_sample(dst
) == u_max_sample(src
));
676 last_sample
= u_max_sample(dst
);
678 /* This must be done before entering u_blitter to avoid recursion. */
679 if (rsrc
->is_depth
&& !rsrc
->is_flushing_texture
) {
680 if (!r600_init_flushed_depth_texture(ctx
, src
, NULL
))
683 r600_blit_decompress_depth(ctx
, rsrc
, NULL
,
684 src_level
, src_level
,
685 src_box
->z
, src_box
->z
+ src_box
->depth
- 1,
686 0, u_max_sample(src
));
688 if (rsrc
->fmask_size
&& rsrc
->cmask_size
) {
689 r600_blit_decompress_color(ctx
, rsrc
, src_level
, src_level
,
690 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
693 restore_orig
[0] = restore_orig
[1] = FALSE
;
695 if (util_format_is_compressed(src
->format
) &&
696 util_format_is_compressed(dst
->format
)) {
697 r600_compressed_to_blittable(src
, src_level
, &orig_info
[0]);
698 restore_orig
[0] = TRUE
;
699 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
700 sbox
.y
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->y
);
702 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
703 sbox
.height
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->height
);
704 sbox
.depth
= src_box
->depth
;
707 r600_compressed_to_blittable(dst
, dst_level
, &orig_info
[1]);
708 restore_orig
[1] = TRUE
;
709 /* translate the dst box as well */
710 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
711 dsty
= util_format_get_nblocksy(orig_info
[1].format
, dsty
);
712 } else if (!util_blitter_is_copy_supported(rctx
->blitter
, dst
, src
,
714 if (util_format_is_subsampled_2x1_32bpp(src
->format
) &&
715 util_format_is_subsampled_2x1_32bpp(dst
->format
)) {
716 r600_subsampled_2x1_32bpp_to_blittable(src
, src_level
, &orig_info
[0]);
717 r600_subsampled_2x1_32bpp_to_blittable(dst
, dst_level
, &orig_info
[1]);
720 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
721 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
724 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
726 unsigned blocksize
= util_format_get_blocksize(src
->format
);
730 r600_change_format(src
, src_level
, &orig_info
[0],
731 PIPE_FORMAT_R8_UNORM
);
732 r600_change_format(dst
, dst_level
, &orig_info
[1],
733 PIPE_FORMAT_R8_UNORM
);
736 r600_change_format(src
, src_level
, &orig_info
[0],
737 PIPE_FORMAT_R8G8B8A8_UNORM
);
738 r600_change_format(dst
, dst_level
, &orig_info
[1],
739 PIPE_FORMAT_R8G8B8A8_UNORM
);
742 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
743 util_format_short_name(src
->format
), blocksize
);
747 restore_orig
[0] = TRUE
;
748 restore_orig
[1] = TRUE
;
751 for (i
= 0; i
<= last_sample
; i
++) {
752 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
753 util_blitter_copy_texture(rctx
->blitter
, dst
, dst_level
, 1 << i
, dstx
, dsty
, dstz
,
754 src
, src_level
, i
, psbox
);
755 r600_blitter_end(ctx
);
759 r600_reset_blittable_to_orig(src
, src_level
, &orig_info
[0]);
762 r600_reset_blittable_to_orig(dst
, dst_level
, &orig_info
[1]);
765 void r600_init_blit_functions(struct r600_context
*rctx
)
767 rctx
->context
.clear
= r600_clear
;
768 rctx
->context
.clear_render_target
= r600_clear_render_target
;
769 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
770 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
771 rctx
->context
.resource_resolve
= r600_resource_resolve
;