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_BLIT
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_SAVE_TEXTURES
|
45 R600_DISABLE_RENDER_COND
,
47 R600_DECOMPRESS
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_DISABLE_RENDER_COND
,
49 R600_COLOR_RESOLVE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_DISABLE_RENDER_COND
52 static void r600_blitter_begin(struct pipe_context
*ctx
, enum r600_blitter_op op
)
54 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
56 r600_suspend_nontimer_queries(rctx
);
58 util_blitter_save_vertex_buffer_slot(rctx
->blitter
, rctx
->vertex_buffer_state
.vb
);
59 util_blitter_save_vertex_elements(rctx
->blitter
, rctx
->vertex_fetch_shader
.cso
);
60 util_blitter_save_vertex_shader(rctx
->blitter
, rctx
->vs_shader
);
61 util_blitter_save_so_targets(rctx
->blitter
, rctx
->num_so_targets
,
62 (struct pipe_stream_output_target
**)rctx
->so_targets
);
63 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->rasterizer_state
.cso
);
65 if (op
& R600_SAVE_FRAGMENT_STATE
) {
66 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
.state
);
67 util_blitter_save_scissor(rctx
->blitter
, &rctx
->scissor
.scissor
);
68 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
69 util_blitter_save_blend(rctx
->blitter
, rctx
->blend_state
.cso
);
70 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->dsa_state
.cso
);
71 util_blitter_save_stencil_ref(rctx
->blitter
, &rctx
->stencil_ref
.pipe_state
);
72 util_blitter_save_sample_mask(rctx
->blitter
, rctx
->sample_mask
.sample_mask
);
75 if (op
& R600_SAVE_FRAMEBUFFER
)
76 util_blitter_save_framebuffer(rctx
->blitter
, &rctx
->framebuffer
.state
);
78 if (op
& R600_SAVE_TEXTURES
) {
79 util_blitter_save_fragment_sampler_states(
80 rctx
->blitter
, util_last_bit(rctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.enabled_mask
),
81 (void**)rctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.states
);
83 util_blitter_save_fragment_sampler_views(
84 rctx
->blitter
, util_last_bit(rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.enabled_mask
),
85 (struct pipe_sampler_view
**)rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
88 if ((op
& R600_DISABLE_RENDER_COND
) && rctx
->current_render_cond
) {
89 util_blitter_save_render_condition(rctx
->blitter
,
90 rctx
->current_render_cond
,
91 rctx
->current_render_cond_mode
);
95 static void r600_blitter_end(struct pipe_context
*ctx
)
97 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
98 r600_resume_nontimer_queries(rctx
);
101 static unsigned u_max_layer(struct pipe_resource
*r
, unsigned level
)
104 case PIPE_TEXTURE_CUBE
:
106 case PIPE_TEXTURE_3D
:
107 return u_minify(r
->depth0
, level
) - 1;
108 case PIPE_TEXTURE_1D_ARRAY
:
109 case PIPE_TEXTURE_2D_ARRAY
:
110 case PIPE_TEXTURE_CUBE_ARRAY
:
111 return r
->array_size
- 1;
117 static unsigned u_max_sample(struct pipe_resource
*r
)
119 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
122 void r600_blit_decompress_depth(struct pipe_context
*ctx
,
123 struct r600_texture
*texture
,
124 struct r600_texture
*staging
,
125 unsigned first_level
, unsigned last_level
,
126 unsigned first_layer
, unsigned last_layer
,
127 unsigned first_sample
, unsigned last_sample
)
129 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
130 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
131 struct r600_texture
*flushed_depth_texture
= staging
?
132 staging
: texture
->flushed_depth_texture
;
133 const struct util_format_description
*desc
=
134 util_format_description(texture
->resource
.b
.b
.format
);
137 if (!staging
&& !texture
->dirty_level_mask
)
140 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
142 /* XXX Decompressing MSAA depth textures is broken on R6xx.
143 * There is also a hardlock if CMASK and FMASK are not present.
144 * Just skip this until we find out how to fix it. */
145 if (rctx
->chip_class
== R600
&& max_sample
> 0) {
146 texture
->dirty_level_mask
= 0;
150 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
151 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
156 /* Enable decompression in DB_RENDER_CONTROL */
157 rctx
->db_misc_state
.flush_depthstencil_through_cb
= true;
158 rctx
->db_misc_state
.copy_depth
= util_format_has_depth(desc
);
159 rctx
->db_misc_state
.copy_stencil
= util_format_has_stencil(desc
);
160 rctx
->db_misc_state
.copy_sample
= first_sample
;
161 rctx
->db_misc_state
.atom
.dirty
= true;
163 for (level
= first_level
; level
<= last_level
; level
++) {
164 if (!staging
&& !(texture
->dirty_level_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 rctx
->db_misc_state
.atom
.dirty
= true;
181 surf_tmpl
.format
= texture
->resource
.b
.b
.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
->resource
.b
.b
.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_level_mask
&= ~(1 << level
);
216 /* reenable compression in DB_RENDER_CONTROL */
217 rctx
->db_misc_state
.flush_depthstencil_through_cb
= false;
218 rctx
->db_misc_state
.atom
.dirty
= true;
221 static void r600_blit_decompress_depth_in_place(struct r600_context
*rctx
,
222 struct r600_texture
*texture
,
223 unsigned first_level
, unsigned last_level
,
224 unsigned first_layer
, unsigned last_layer
)
226 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
227 unsigned layer
, max_layer
, checked_last_layer
, level
;
229 /* Enable decompression in DB_RENDER_CONTROL */
230 rctx
->db_misc_state
.flush_depthstencil_in_place
= true;
231 rctx
->db_misc_state
.atom
.dirty
= true;
233 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
234 surf_tmpl
.usage
= PIPE_BIND_DEPTH_STENCIL
;
236 for (level
= first_level
; level
<= last_level
; level
++) {
237 if (!(texture
->dirty_level_mask
& (1 << level
)))
240 surf_tmpl
.u
.tex
.level
= level
;
242 /* The smaller the mipmap level, the less layers there are
243 * as far as 3D textures are concerned. */
244 max_layer
= u_max_layer(&texture
->resource
.b
.b
, level
);
245 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
247 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
248 surf_tmpl
.u
.tex
.first_layer
= layer
;
249 surf_tmpl
.u
.tex
.last_layer
= layer
;
251 zsurf
= rctx
->context
.create_surface(&rctx
->context
, &texture
->resource
.b
.b
, &surf_tmpl
);
253 r600_blitter_begin(&rctx
->context
, R600_DECOMPRESS
);
254 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, NULL
, ~0,
255 rctx
->custom_dsa_flush
, 1.0f
);
256 r600_blitter_end(&rctx
->context
);
258 pipe_surface_reference(&zsurf
, NULL
);
261 /* The texture will always be dirty if some layers or samples aren't flushed.
262 * I don't think this case occurs often though. */
263 if (first_layer
== 0 && last_layer
== max_layer
) {
264 texture
->dirty_level_mask
&= ~(1 << level
);
268 /* Disable decompression in DB_RENDER_CONTROL */
269 rctx
->db_misc_state
.flush_depthstencil_in_place
= false;
270 rctx
->db_misc_state
.atom
.dirty
= true;
273 void r600_decompress_depth_textures(struct r600_context
*rctx
,
274 struct r600_samplerview_state
*textures
)
277 unsigned depth_texture_mask
= textures
->compressed_depthtex_mask
;
279 while (depth_texture_mask
) {
280 struct pipe_sampler_view
*view
;
281 struct r600_texture
*tex
;
283 i
= u_bit_scan(&depth_texture_mask
);
285 view
= &textures
->views
[i
]->base
;
288 tex
= (struct r600_texture
*)view
->texture
;
289 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
291 if (rctx
->chip_class
>= EVERGREEN
||
292 r600_can_read_depth(tex
)) {
293 r600_blit_decompress_depth_in_place(rctx
, tex
,
294 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
295 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
297 r600_blit_decompress_depth(&rctx
->context
, tex
, NULL
,
298 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
299 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
),
300 0, u_max_sample(&tex
->resource
.b
.b
));
305 static void r600_blit_decompress_color(struct pipe_context
*ctx
,
306 struct r600_texture
*rtex
,
307 unsigned first_level
, unsigned last_level
,
308 unsigned first_layer
, unsigned last_layer
)
310 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
311 unsigned layer
, level
, checked_last_layer
, max_layer
;
312 void *blend_decompress
;
314 if (!rtex
->dirty_level_mask
)
317 switch (rctx
->screen
->msaa_texture_support
) {
318 case MSAA_TEXTURE_DECOMPRESSED
:
319 blend_decompress
= rctx
->custom_blend_decompress
;
321 case MSAA_TEXTURE_COMPRESSED
:
322 /* XXX the 2x and 4x cases are broken. */
323 if (rtex
->resource
.b
.b
.nr_samples
== 8)
324 blend_decompress
= rctx
->custom_blend_fmask_decompress
;
326 blend_decompress
= rctx
->custom_blend_decompress
;
328 case MSAA_TEXTURE_SAMPLE_ZERO
:
331 rtex
->dirty_level_mask
= 0;
335 for (level
= first_level
; level
<= last_level
; level
++) {
336 if (!(rtex
->dirty_level_mask
& (1 << level
)))
339 /* The smaller the mipmap level, the less layers there are
340 * as far as 3D textures are concerned. */
341 max_layer
= u_max_layer(&rtex
->resource
.b
.b
, level
);
342 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
344 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
345 struct pipe_surface
*cbsurf
, surf_tmpl
;
347 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
348 surf_tmpl
.u
.tex
.level
= level
;
349 surf_tmpl
.u
.tex
.first_layer
= layer
;
350 surf_tmpl
.u
.tex
.last_layer
= layer
;
351 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
352 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
354 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
355 util_blitter_custom_color(rctx
->blitter
, cbsurf
, blend_decompress
);
356 r600_blitter_end(ctx
);
358 pipe_surface_reference(&cbsurf
, NULL
);
361 /* The texture will always be dirty if some layers aren't flushed.
362 * I don't think this case occurs often though. */
363 if (first_layer
== 0 && last_layer
== max_layer
) {
364 rtex
->dirty_level_mask
&= ~(1 << level
);
369 void r600_decompress_color_textures(struct r600_context
*rctx
,
370 struct r600_samplerview_state
*textures
)
373 unsigned mask
= textures
->compressed_colortex_mask
;
376 struct pipe_sampler_view
*view
;
377 struct r600_texture
*tex
;
379 i
= u_bit_scan(&mask
);
381 view
= &textures
->views
[i
]->base
;
384 tex
= (struct r600_texture
*)view
->texture
;
385 assert(tex
->cmask_size
&& tex
->fmask_size
);
387 r600_blit_decompress_color(&rctx
->context
, tex
,
388 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
389 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
393 /* Helper for decompressing a portion of a color or depth resource before
394 * blitting if any decompression is needed.
395 * The driver doesn't decompress resources automatically while u_blitter is
397 static bool r600_decompress_subresource(struct pipe_context
*ctx
,
398 struct pipe_resource
*tex
,
400 unsigned first_layer
, unsigned last_layer
)
402 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
403 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
405 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
406 if (rctx
->chip_class
>= EVERGREEN
||
407 r600_can_read_depth(rtex
)) {
408 r600_blit_decompress_depth_in_place(rctx
, rtex
,
410 first_layer
, last_layer
);
412 if (!r600_init_flushed_depth_texture(ctx
, tex
, NULL
))
413 return false; /* error */
415 r600_blit_decompress_depth(ctx
, rtex
, NULL
,
417 first_layer
, last_layer
,
418 0, u_max_sample(tex
));
420 } else if (rtex
->fmask_size
&& rtex
->cmask_size
) {
421 r600_blit_decompress_color(ctx
, rtex
, level
, level
,
422 first_layer
, last_layer
);
427 static boolean
is_simple_msaa_resolve(const struct pipe_blit_info
*info
)
429 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
430 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
432 return info
->dst
.resource
->format
== info
->src
.resource
->format
&&
433 info
->dst
.resource
->format
== info
->dst
.format
&&
434 info
->src
.resource
->format
== info
->src
.format
&&
435 !info
->scissor_enable
&&
436 info
->mask
== PIPE_MASK_RGBA
&&
437 dst_width
== info
->src
.resource
->width0
&&
438 dst_height
== info
->src
.resource
->height0
&&
439 info
->dst
.box
.x
== 0 &&
440 info
->dst
.box
.y
== 0 &&
441 info
->dst
.box
.width
== dst_width
&&
442 info
->dst
.box
.height
== dst_height
&&
443 info
->src
.box
.x
== 0 &&
444 info
->src
.box
.y
== 0 &&
445 info
->src
.box
.width
== dst_width
&&
446 info
->src
.box
.height
== dst_height
;
449 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
450 const union pipe_color_union
*color
,
451 double depth
, unsigned stencil
)
453 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
454 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
.state
;
456 r600_blitter_begin(ctx
, R600_CLEAR
);
457 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
458 fb
->nr_cbufs
, buffers
, fb
->nr_cbufs
? fb
->cbufs
[0]->format
: PIPE_FORMAT_NONE
,
459 color
, depth
, stencil
);
460 r600_blitter_end(ctx
);
463 static void r600_clear_render_target(struct pipe_context
*ctx
,
464 struct pipe_surface
*dst
,
465 const union pipe_color_union
*color
,
466 unsigned dstx
, unsigned dsty
,
467 unsigned width
, unsigned height
)
469 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
471 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
472 util_blitter_clear_render_target(rctx
->blitter
, dst
, color
,
473 dstx
, dsty
, width
, height
);
474 r600_blitter_end(ctx
);
477 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
478 struct pipe_surface
*dst
,
479 unsigned clear_flags
,
482 unsigned dstx
, unsigned dsty
,
483 unsigned width
, unsigned height
)
485 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
487 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
488 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
489 dstx
, dsty
, width
, height
);
490 r600_blitter_end(ctx
);
493 void r600_copy_buffer(struct pipe_context
*ctx
, struct
494 pipe_resource
*dst
, unsigned dstx
,
495 struct pipe_resource
*src
, const struct pipe_box
*src_box
)
497 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
499 if (rctx
->screen
->has_streamout
&&
500 /* Require dword alignment. */
501 dstx
% 4 == 0 && src_box
->x
% 4 == 0 && src_box
->width
% 4 == 0) {
502 r600_blitter_begin(ctx
, R600_COPY_BUFFER
);
503 util_blitter_copy_buffer(rctx
->blitter
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
504 r600_blitter_end(ctx
);
506 util_resource_copy_region(ctx
, dst
, 0, dstx
, 0, 0, src
, 0, src_box
);
510 static bool util_format_is_subsampled_2x1_32bpp(enum pipe_format format
)
512 const struct util_format_description
*desc
= util_format_description(format
);
514 return desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
&&
515 desc
->block
.width
== 2 &&
516 desc
->block
.height
== 1 &&
517 desc
->block
.bits
== 32;
520 static void r600_resource_copy_region(struct pipe_context
*ctx
,
521 struct pipe_resource
*dst
,
523 unsigned dstx
, unsigned dsty
, unsigned dstz
,
524 struct pipe_resource
*src
,
526 const struct pipe_box
*src_box
)
528 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
529 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
530 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
531 struct pipe_surface
*dst_view
, dst_templ
;
532 struct pipe_sampler_view src_templ
, *src_view
;
533 unsigned dst_width
, dst_height
, src_width0
, src_height0
, src_widthFL
, src_heightFL
;
534 struct pipe_box sbox
;
535 bool copy_all_samples
;
537 /* Handle buffers first. */
538 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
539 r600_copy_buffer(ctx
, dst
, dstx
, src
, src_box
);
543 assert(u_max_sample(dst
) == u_max_sample(src
));
545 /* The driver doesn't decompress resources automatically while
546 * u_blitter is rendering. */
547 if (!r600_decompress_subresource(ctx
, src
, src_level
,
548 src_box
->z
, src_box
->z
+ src_box
->depth
- 1)) {
552 dst_width
= rdst
->surface
.level
[dst_level
].npix_x
;
553 dst_height
= rdst
->surface
.level
[dst_level
].npix_y
;
554 src_width0
= src
->width0
;
555 src_height0
= src
->height0
;
556 src_widthFL
= rsrc
->surface
.level
[src_level
].npix_x
;
557 src_heightFL
= rsrc
->surface
.level
[src_level
].npix_y
;
559 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
, src_box
);
560 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
562 if (util_format_is_compressed(src
->format
)) {
563 unsigned blocksize
= util_format_get_blocksize(src
->format
);
566 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
568 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
569 dst_templ
.format
= src_templ
.format
;
571 dst_width
= util_format_get_nblocksx(dst
->format
, rdst
->surface
.level
[dst_level
].npix_x
);
572 dst_height
= util_format_get_nblocksy(dst
->format
, rdst
->surface
.level
[dst_level
].npix_y
);
573 src_width0
= util_format_get_nblocksx(src
->format
, src
->width0
);
574 src_height0
= util_format_get_nblocksy(src
->format
, src
->height0
);
575 src_widthFL
= util_format_get_nblocksx(src
->format
, rsrc
->surface
.level
[src_level
].npix_x
);
576 src_heightFL
= util_format_get_nblocksy(src
->format
, rsrc
->surface
.level
[src_level
].npix_y
);
578 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
579 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
581 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
582 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
584 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
585 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
586 sbox
.depth
= src_box
->depth
;
588 } else if (!util_blitter_is_copy_supported(rctx
->blitter
, dst
, src
,
590 if (util_format_is_subsampled_2x1_32bpp(src
->format
)) {
592 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
593 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
595 dst_width
= util_format_get_nblocksx(dst
->format
, rdst
->surface
.level
[dst_level
].npix_x
);
596 src_width0
= util_format_get_nblocksx(src
->format
, src
->width0
);
597 src_widthFL
= util_format_get_nblocksx(src
->format
, rsrc
->surface
.level
[src_level
].npix_x
);
599 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
602 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
603 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
606 unsigned blocksize
= util_format_get_blocksize(src
->format
);
610 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
611 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
614 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
615 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
618 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
619 util_format_short_name(src
->format
), blocksize
);
625 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
, dst_width
, dst_height
);
627 if (rctx
->chip_class
>= EVERGREEN
) {
628 src_view
= evergreen_create_sampler_view_custom(ctx
, src
, &src_templ
,
629 src_width0
, src_height0
);
631 src_view
= r600_create_sampler_view_custom(ctx
, src
, &src_templ
,
632 src_widthFL
, src_heightFL
);
635 copy_all_samples
= rctx
->screen
->msaa_texture_support
!= MSAA_TEXTURE_SAMPLE_ZERO
;
638 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
639 util_blitter_blit_generic(rctx
->blitter
, dst_view
, dstx
, dsty
,
640 abs(src_box
->width
), abs(src_box
->height
),
641 src_view
, src_box
, src_width0
, src_height0
,
642 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
644 r600_blitter_end(ctx
);
646 pipe_surface_reference(&dst_view
, NULL
);
647 pipe_sampler_view_reference(&src_view
, NULL
);
650 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
651 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
654 #define REPLACE_FORMAT_SIGN(format,sign) \
655 case PIPE_FORMAT_##format##_##sign##INT: \
656 return PIPE_FORMAT_##format##_##sign##NORM
657 #define REPLACE_FORMAT(format) \
658 REPLACE_FORMAT_SIGN(format, U); \
659 REPLACE_FORMAT_SIGN(format, S)
661 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
663 REPLACE_FORMAT(R8G8
);
664 REPLACE_FORMAT(R8G8B8
);
665 REPLACE_FORMAT(R8G8B8A8
);
669 REPLACE_FORMAT(L8A8
);
671 REPLACE_FORMAT(R16G16
);
672 REPLACE_FORMAT(R16G16B16
);
673 REPLACE_FORMAT(R16G16B16A16
);
677 REPLACE_FORMAT(L16A16
);
679 #undef REPLACE_FORMAT
680 #undef REPLACE_FORMAT_SIGN
686 static void r600_msaa_color_resolve(struct pipe_context
*ctx
,
687 const struct pipe_blit_info
*info
)
689 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
690 struct pipe_screen
*screen
= ctx
->screen
;
691 struct pipe_resource
*tmp
, templ
;
692 struct pipe_blit_info blit
;
693 unsigned sample_mask
=
694 rctx
->chip_class
== CAYMAN
? ~0 :
695 ((1ull << MAX2(1, info
->src
.resource
->nr_samples
)) - 1);
697 assert(info
->src
.level
== 0);
698 assert(info
->src
.box
.depth
== 1);
699 assert(info
->dst
.box
.depth
== 1);
701 if (is_simple_msaa_resolve(info
)) {
702 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
703 util_blitter_custom_resolve_color(rctx
->blitter
,
704 info
->dst
.resource
, info
->dst
.level
,
706 info
->src
.resource
, info
->src
.box
.z
,
707 sample_mask
, rctx
->custom_blend_resolve
,
708 int_to_norm_format(info
->dst
.format
));
709 r600_blitter_end(ctx
);
713 /* resolve into a temporary texture, then blit */
714 templ
.target
= PIPE_TEXTURE_2D
;
715 templ
.format
= info
->src
.resource
->format
;
716 templ
.width0
= info
->src
.resource
->width0
;
717 templ
.height0
= info
->src
.resource
->height0
;
719 templ
.array_size
= 1;
720 templ
.last_level
= 0;
721 templ
.nr_samples
= 0;
722 templ
.usage
= PIPE_USAGE_STATIC
;
723 templ
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
726 tmp
= screen
->resource_create(screen
, &templ
);
729 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
730 util_blitter_custom_resolve_color(rctx
->blitter
,
732 info
->src
.resource
, info
->src
.box
.z
,
733 sample_mask
, rctx
->custom_blend_resolve
,
734 int_to_norm_format(tmp
->format
));
735 r600_blitter_end(ctx
);
739 blit
.src
.resource
= tmp
;
742 r600_blitter_begin(ctx
, R600_BLIT
);
743 util_blitter_blit(rctx
->blitter
, &blit
);
744 r600_blitter_end(ctx
);
746 pipe_resource_reference(&tmp
, NULL
);
749 static void r600_blit(struct pipe_context
*ctx
,
750 const struct pipe_blit_info
*info
)
752 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
754 assert(util_blitter_is_blit_supported(rctx
->blitter
, info
));
756 if (info
->src
.resource
->nr_samples
> 1 &&
757 info
->dst
.resource
->nr_samples
<= 1 &&
758 !util_format_is_depth_or_stencil(info
->src
.resource
->format
) &&
759 !util_format_is_pure_integer(int_to_norm_format(info
->src
.resource
->format
))) {
760 r600_msaa_color_resolve(ctx
, info
);
764 /* The driver doesn't decompress resources automatically while
765 * u_blitter is rendering. */
766 if (!r600_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
768 info
->src
.box
.z
+ info
->src
.box
.depth
- 1)) {
772 r600_blitter_begin(ctx
, R600_BLIT
);
773 util_blitter_blit(rctx
->blitter
, info
);
774 r600_blitter_end(ctx
);
777 void r600_init_blit_functions(struct r600_context
*rctx
)
779 rctx
->context
.clear
= r600_clear
;
780 rctx
->context
.clear_render_target
= r600_clear_render_target
;
781 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
782 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
783 rctx
->context
.blit
= r600_blit
;