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
->streamout
.num_targets
,
62 (struct pipe_stream_output_target
**)rctx
->streamout
.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_sample(struct pipe_resource
*r
)
103 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
106 void r600_blit_decompress_depth(struct pipe_context
*ctx
,
107 struct r600_texture
*texture
,
108 struct r600_texture
*staging
,
109 unsigned first_level
, unsigned last_level
,
110 unsigned first_layer
, unsigned last_layer
,
111 unsigned first_sample
, unsigned last_sample
)
113 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
114 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
115 struct r600_texture
*flushed_depth_texture
= staging
?
116 staging
: texture
->flushed_depth_texture
;
117 const struct util_format_description
*desc
=
118 util_format_description(texture
->resource
.b
.b
.format
);
121 if (!staging
&& !texture
->dirty_level_mask
)
124 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
126 /* XXX Decompressing MSAA depth textures is broken on R6xx.
127 * There is also a hardlock if CMASK and FMASK are not present.
128 * Just skip this until we find out how to fix it. */
129 if (rctx
->chip_class
== R600
&& max_sample
> 0) {
130 texture
->dirty_level_mask
= 0;
134 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
135 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
140 /* Enable decompression in DB_RENDER_CONTROL */
141 rctx
->db_misc_state
.flush_depthstencil_through_cb
= true;
142 rctx
->db_misc_state
.copy_depth
= util_format_has_depth(desc
);
143 rctx
->db_misc_state
.copy_stencil
= util_format_has_stencil(desc
);
144 rctx
->db_misc_state
.copy_sample
= first_sample
;
145 rctx
->db_misc_state
.atom
.dirty
= true;
147 for (level
= first_level
; level
<= last_level
; level
++) {
148 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
151 /* The smaller the mipmap level, the less layers there are
152 * as far as 3D textures are concerned. */
153 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
154 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
156 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
157 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
158 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
160 if (sample
!= rctx
->db_misc_state
.copy_sample
) {
161 rctx
->db_misc_state
.copy_sample
= sample
;
162 rctx
->db_misc_state
.atom
.dirty
= true;
165 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
166 surf_tmpl
.u
.tex
.level
= level
;
167 surf_tmpl
.u
.tex
.first_layer
= layer
;
168 surf_tmpl
.u
.tex
.last_layer
= layer
;
170 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
172 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
173 surf_tmpl
.u
.tex
.level
= level
;
174 surf_tmpl
.u
.tex
.first_layer
= layer
;
175 surf_tmpl
.u
.tex
.last_layer
= layer
;
176 cbsurf
= ctx
->create_surface(ctx
,
177 &flushed_depth_texture
->resource
.b
.b
, &surf_tmpl
);
179 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
180 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
181 rctx
->custom_dsa_flush
, depth
);
182 r600_blitter_end(ctx
);
184 pipe_surface_reference(&zsurf
, NULL
);
185 pipe_surface_reference(&cbsurf
, NULL
);
189 /* The texture will always be dirty if some layers or samples aren't flushed.
190 * I don't think this case occurs often though. */
192 first_layer
== 0 && last_layer
== max_layer
&&
193 first_sample
== 0 && last_sample
== max_sample
) {
194 texture
->dirty_level_mask
&= ~(1 << level
);
198 /* reenable compression in DB_RENDER_CONTROL */
199 rctx
->db_misc_state
.flush_depthstencil_through_cb
= false;
200 rctx
->db_misc_state
.atom
.dirty
= true;
203 static void r600_blit_decompress_depth_in_place(struct r600_context
*rctx
,
204 struct r600_texture
*texture
,
205 unsigned first_level
, unsigned last_level
,
206 unsigned first_layer
, unsigned last_layer
)
208 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
209 unsigned layer
, max_layer
, checked_last_layer
, level
;
211 /* Enable decompression in DB_RENDER_CONTROL */
212 rctx
->db_misc_state
.flush_depthstencil_in_place
= true;
213 rctx
->db_misc_state
.atom
.dirty
= true;
215 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
217 for (level
= first_level
; level
<= last_level
; level
++) {
218 if (!(texture
->dirty_level_mask
& (1 << level
)))
221 surf_tmpl
.u
.tex
.level
= level
;
223 /* The smaller the mipmap level, the less layers there are
224 * as far as 3D textures are concerned. */
225 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
226 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
228 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
229 surf_tmpl
.u
.tex
.first_layer
= layer
;
230 surf_tmpl
.u
.tex
.last_layer
= layer
;
232 zsurf
= rctx
->context
.create_surface(&rctx
->context
, &texture
->resource
.b
.b
, &surf_tmpl
);
234 r600_blitter_begin(&rctx
->context
, R600_DECOMPRESS
);
235 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, NULL
, ~0,
236 rctx
->custom_dsa_flush
, 1.0f
);
237 r600_blitter_end(&rctx
->context
);
239 pipe_surface_reference(&zsurf
, NULL
);
242 /* The texture will always be dirty if some layers or samples aren't flushed.
243 * I don't think this case occurs often though. */
244 if (first_layer
== 0 && last_layer
== max_layer
) {
245 texture
->dirty_level_mask
&= ~(1 << level
);
249 /* Disable decompression in DB_RENDER_CONTROL */
250 rctx
->db_misc_state
.flush_depthstencil_in_place
= false;
251 rctx
->db_misc_state
.atom
.dirty
= true;
254 void r600_decompress_depth_textures(struct r600_context
*rctx
,
255 struct r600_samplerview_state
*textures
)
258 unsigned depth_texture_mask
= textures
->compressed_depthtex_mask
;
260 while (depth_texture_mask
) {
261 struct pipe_sampler_view
*view
;
262 struct r600_texture
*tex
;
264 i
= u_bit_scan(&depth_texture_mask
);
266 view
= &textures
->views
[i
]->base
;
269 tex
= (struct r600_texture
*)view
->texture
;
270 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
272 if (rctx
->chip_class
>= EVERGREEN
||
273 r600_can_read_depth(tex
)) {
274 r600_blit_decompress_depth_in_place(rctx
, tex
,
275 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
276 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
278 r600_blit_decompress_depth(&rctx
->context
, tex
, NULL
,
279 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
280 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
),
281 0, u_max_sample(&tex
->resource
.b
.b
));
286 static void r600_blit_decompress_color(struct pipe_context
*ctx
,
287 struct r600_texture
*rtex
,
288 unsigned first_level
, unsigned last_level
,
289 unsigned first_layer
, unsigned last_layer
)
291 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
292 unsigned layer
, level
, checked_last_layer
, max_layer
;
294 if (!rtex
->dirty_level_mask
)
297 for (level
= first_level
; level
<= last_level
; level
++) {
298 if (!(rtex
->dirty_level_mask
& (1 << level
)))
301 /* The smaller the mipmap level, the less layers there are
302 * as far as 3D textures are concerned. */
303 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
304 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
306 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
307 struct pipe_surface
*cbsurf
, surf_tmpl
;
309 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
310 surf_tmpl
.u
.tex
.level
= level
;
311 surf_tmpl
.u
.tex
.first_layer
= layer
;
312 surf_tmpl
.u
.tex
.last_layer
= layer
;
313 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
315 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
316 util_blitter_custom_color(rctx
->blitter
, cbsurf
, rctx
->custom_blend_decompress
);
317 r600_blitter_end(ctx
);
319 pipe_surface_reference(&cbsurf
, NULL
);
322 /* The texture will always be dirty if some layers aren't flushed.
323 * I don't think this case occurs often though. */
324 if (first_layer
== 0 && last_layer
== max_layer
) {
325 rtex
->dirty_level_mask
&= ~(1 << level
);
330 void r600_decompress_color_textures(struct r600_context
*rctx
,
331 struct r600_samplerview_state
*textures
)
334 unsigned mask
= textures
->compressed_colortex_mask
;
337 struct pipe_sampler_view
*view
;
338 struct r600_texture
*tex
;
340 i
= u_bit_scan(&mask
);
342 view
= &textures
->views
[i
]->base
;
345 tex
= (struct r600_texture
*)view
->texture
;
346 assert(tex
->cmask_size
&& tex
->fmask_size
);
348 r600_blit_decompress_color(&rctx
->context
, tex
,
349 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
350 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
354 /* Helper for decompressing a portion of a color or depth resource before
355 * blitting if any decompression is needed.
356 * The driver doesn't decompress resources automatically while u_blitter is
358 static bool r600_decompress_subresource(struct pipe_context
*ctx
,
359 struct pipe_resource
*tex
,
361 unsigned first_layer
, unsigned last_layer
)
363 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
364 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
366 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
367 if (rctx
->chip_class
>= EVERGREEN
||
368 r600_can_read_depth(rtex
)) {
369 r600_blit_decompress_depth_in_place(rctx
, rtex
,
371 first_layer
, last_layer
);
373 if (!r600_init_flushed_depth_texture(ctx
, tex
, NULL
))
374 return false; /* error */
376 r600_blit_decompress_depth(ctx
, rtex
, NULL
,
378 first_layer
, last_layer
,
379 0, u_max_sample(tex
));
381 } else if (rtex
->fmask_size
&& rtex
->cmask_size
) {
382 r600_blit_decompress_color(ctx
, rtex
, level
, level
,
383 first_layer
, last_layer
);
388 static boolean
is_simple_msaa_resolve(const struct pipe_blit_info
*info
)
390 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
391 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
392 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
393 unsigned dst_tile_mode
= dst
->surface
.level
[info
->dst
.level
].mode
;
395 return info
->dst
.resource
->format
== info
->src
.resource
->format
&&
396 info
->dst
.resource
->format
== info
->dst
.format
&&
397 info
->src
.resource
->format
== info
->src
.format
&&
398 !info
->scissor_enable
&&
399 info
->mask
== PIPE_MASK_RGBA
&&
400 dst_width
== info
->src
.resource
->width0
&&
401 dst_height
== info
->src
.resource
->height0
&&
402 info
->dst
.box
.x
== 0 &&
403 info
->dst
.box
.y
== 0 &&
404 info
->dst
.box
.width
== dst_width
&&
405 info
->dst
.box
.height
== dst_height
&&
406 info
->src
.box
.x
== 0 &&
407 info
->src
.box
.y
== 0 &&
408 info
->src
.box
.width
== dst_width
&&
409 info
->src
.box
.height
== dst_height
&&
410 /* Dst must be tiled. If it's not, we have to use a temporary
411 * resource which is tiled. */
412 dst_tile_mode
>= RADEON_SURF_MODE_1D
;
415 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
416 const union pipe_color_union
*color
,
417 double depth
, unsigned stencil
)
419 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
420 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
.state
;
422 /* if hyperz enabled just clear hyperz */
423 if (fb
->zsbuf
&& (buffers
& PIPE_CLEAR_DEPTH
)) {
424 struct r600_texture
*rtex
;
425 unsigned level
= fb
->zsbuf
->u
.tex
.level
;
427 rtex
= (struct r600_texture
*)fb
->zsbuf
->texture
;
429 /* We can't use hyperz fast clear if each slice of a texture
430 * array are clear to different value. To simplify code just
431 * disable fast clear for texture array.
433 /* Only use htile for first level */
434 if (rtex
->htile
&& !level
&& rtex
->surface
.array_size
== 1) {
435 if (rtex
->depth_clear
!= depth
) {
436 rtex
->depth_clear
= depth
;
437 rctx
->db_state
.atom
.dirty
= true;
439 rctx
->db_misc_state
.htile_clear
= true;
440 rctx
->db_misc_state
.atom
.dirty
= true;
444 r600_blitter_begin(ctx
, R600_CLEAR
);
445 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
446 buffers
, color
, depth
, stencil
);
447 r600_blitter_end(ctx
);
449 /* disable fast clear */
450 if (rctx
->db_misc_state
.htile_clear
) {
451 rctx
->db_misc_state
.htile_clear
= false;
452 rctx
->db_misc_state
.atom
.dirty
= true;
456 static void r600_clear_render_target(struct pipe_context
*ctx
,
457 struct pipe_surface
*dst
,
458 const union pipe_color_union
*color
,
459 unsigned dstx
, unsigned dsty
,
460 unsigned width
, unsigned height
)
462 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
464 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
465 util_blitter_clear_render_target(rctx
->blitter
, dst
, color
,
466 dstx
, dsty
, width
, height
);
467 r600_blitter_end(ctx
);
470 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
471 struct pipe_surface
*dst
,
472 unsigned clear_flags
,
475 unsigned dstx
, unsigned dsty
,
476 unsigned width
, unsigned height
)
478 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
480 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
481 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
482 dstx
, dsty
, width
, height
);
483 r600_blitter_end(ctx
);
486 void r600_copy_buffer(struct pipe_context
*ctx
, struct pipe_resource
*dst
, unsigned dstx
,
487 struct pipe_resource
*src
, const struct pipe_box
*src_box
)
489 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
491 if (rctx
->screen
->has_cp_dma
) {
492 r600_cp_dma_copy_buffer(rctx
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
494 else if (rctx
->screen
->has_streamout
&&
495 /* Require 4-byte alignment. */
496 dstx
% 4 == 0 && src_box
->x
% 4 == 0 && src_box
->width
% 4 == 0) {
497 r600_blitter_begin(ctx
, R600_COPY_BUFFER
);
498 util_blitter_copy_buffer(rctx
->blitter
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
499 r600_blitter_end(ctx
);
501 util_resource_copy_region(ctx
, dst
, 0, dstx
, 0, 0, src
, 0, src_box
);
505 static void r600_clear_buffer(struct pipe_context
*ctx
, struct pipe_resource
*dst
,
506 unsigned offset
, unsigned size
, unsigned char value
)
508 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
511 if (rctx
->screen
->has_cp_dma
&&
512 rctx
->chip_class
>= EVERGREEN
&&
513 offset
% 4 == 0 && size
% 4 == 0) {
514 uint32_t clear_value
= v
| (v
<< 8) | (v
<< 16) | (v
<< 24);
516 evergreen_cp_dma_clear_buffer(rctx
, dst
, offset
, size
, clear_value
);
517 } else if (rctx
->screen
->has_streamout
&& offset
% 4 == 0 && size
% 4 == 0) {
518 union pipe_color_union clear_value
;
520 clear_value
.ui
[0] = v
| (v
<< 8) | (v
<< 16) | (v
<< 24);
522 r600_blitter_begin(ctx
, R600_DISABLE_RENDER_COND
);
523 util_blitter_clear_buffer(rctx
->blitter
, dst
, offset
, size
,
525 r600_blitter_end(ctx
);
527 char *map
= r600_buffer_mmap_sync_with_rings(rctx
, r600_resource(dst
),
528 PIPE_TRANSFER_WRITE
);
529 memset(map
+ offset
, value
, size
);
533 void r600_screen_clear_buffer(struct r600_screen
*rscreen
, struct pipe_resource
*dst
,
534 unsigned offset
, unsigned size
, unsigned char value
)
536 pipe_mutex_lock(rscreen
->aux_context_lock
);
537 r600_clear_buffer(rscreen
->aux_context
, dst
, offset
, size
, value
);
538 rscreen
->aux_context
->flush(rscreen
->aux_context
, NULL
, 0);
539 pipe_mutex_unlock(rscreen
->aux_context_lock
);
542 static bool util_format_is_subsampled_2x1_32bpp(enum pipe_format format
)
544 const struct util_format_description
*desc
= util_format_description(format
);
546 return desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
&&
547 desc
->block
.width
== 2 &&
548 desc
->block
.height
== 1 &&
549 desc
->block
.bits
== 32;
552 static void r600_resource_copy_region(struct pipe_context
*ctx
,
553 struct pipe_resource
*dst
,
555 unsigned dstx
, unsigned dsty
, unsigned dstz
,
556 struct pipe_resource
*src
,
558 const struct pipe_box
*src_box
)
560 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
561 struct pipe_surface
*dst_view
, dst_templ
;
562 struct pipe_sampler_view src_templ
, *src_view
;
563 unsigned dst_width
, dst_height
, src_width0
, src_height0
, src_widthFL
, src_heightFL
;
564 struct pipe_box sbox
, dstbox
;
566 /* Handle buffers first. */
567 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
568 r600_copy_buffer(ctx
, dst
, dstx
, src
, src_box
);
572 assert(u_max_sample(dst
) == u_max_sample(src
));
574 /* The driver doesn't decompress resources automatically while
575 * u_blitter is rendering. */
576 if (!r600_decompress_subresource(ctx
, src
, src_level
,
577 src_box
->z
, src_box
->z
+ src_box
->depth
- 1)) {
581 dst_width
= u_minify(dst
->width0
, dst_level
);
582 dst_height
= u_minify(dst
->height0
, dst_level
);
583 src_width0
= src
->width0
;
584 src_height0
= src
->height0
;
585 src_widthFL
= u_minify(src
->width0
, src_level
);
586 src_heightFL
= u_minify(src
->height0
, src_level
);
588 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
589 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
591 if (util_format_is_compressed(src
->format
)) {
592 unsigned blocksize
= util_format_get_blocksize(src
->format
);
595 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
597 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
598 dst_templ
.format
= src_templ
.format
;
600 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
601 dst_height
= util_format_get_nblocksy(dst
->format
, dst_height
);
602 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
603 src_height0
= util_format_get_nblocksy(src
->format
, src_height0
);
604 src_widthFL
= util_format_get_nblocksx(src
->format
, src_widthFL
);
605 src_heightFL
= util_format_get_nblocksy(src
->format
, src_heightFL
);
607 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
608 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
610 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
611 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
613 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
614 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
615 sbox
.depth
= src_box
->depth
;
617 } else if (!util_blitter_is_copy_supported(rctx
->blitter
, dst
, src
,
619 if (util_format_is_subsampled_2x1_32bpp(src
->format
)) {
621 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
622 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
624 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
625 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
626 src_widthFL
= util_format_get_nblocksx(src
->format
, src_widthFL
);
628 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
631 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
632 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
635 unsigned blocksize
= util_format_get_blocksize(src
->format
);
639 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
640 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
643 dst_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
644 src_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
647 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
648 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
651 dst_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
652 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
655 dst_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
656 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
659 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
660 util_format_short_name(src
->format
), blocksize
);
666 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
, dst_width
, dst_height
);
668 if (rctx
->chip_class
>= EVERGREEN
) {
669 src_view
= evergreen_create_sampler_view_custom(ctx
, src
, &src_templ
,
670 src_width0
, src_height0
);
672 src_view
= r600_create_sampler_view_custom(ctx
, src
, &src_templ
,
673 src_widthFL
, src_heightFL
);
676 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
677 abs(src_box
->depth
), &dstbox
);
680 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
681 util_blitter_blit_generic(rctx
->blitter
, dst_view
, &dstbox
,
682 src_view
, src_box
, src_width0
, src_height0
,
683 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
685 r600_blitter_end(ctx
);
687 pipe_surface_reference(&dst_view
, NULL
);
688 pipe_sampler_view_reference(&src_view
, NULL
);
691 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
692 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
695 #define REPLACE_FORMAT_SIGN(format,sign) \
696 case PIPE_FORMAT_##format##_##sign##INT: \
697 return PIPE_FORMAT_##format##_##sign##NORM
698 #define REPLACE_FORMAT(format) \
699 REPLACE_FORMAT_SIGN(format, U); \
700 REPLACE_FORMAT_SIGN(format, S)
702 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
704 REPLACE_FORMAT(R8G8
);
705 REPLACE_FORMAT(R8G8B8
);
706 REPLACE_FORMAT(R8G8B8A8
);
710 REPLACE_FORMAT(L8A8
);
712 REPLACE_FORMAT(R16G16
);
713 REPLACE_FORMAT(R16G16B16
);
714 REPLACE_FORMAT(R16G16B16A16
);
718 REPLACE_FORMAT(L16A16
);
720 #undef REPLACE_FORMAT
721 #undef REPLACE_FORMAT_SIGN
727 static void r600_msaa_color_resolve(struct pipe_context
*ctx
,
728 const struct pipe_blit_info
*info
)
730 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
731 struct pipe_screen
*screen
= ctx
->screen
;
732 struct pipe_resource
*tmp
, templ
;
733 struct pipe_blit_info blit
;
734 unsigned sample_mask
=
735 rctx
->chip_class
== CAYMAN
? ~0 :
736 ((1ull << MAX2(1, info
->src
.resource
->nr_samples
)) - 1);
738 assert(info
->src
.level
== 0);
739 assert(info
->src
.box
.depth
== 1);
740 assert(info
->dst
.box
.depth
== 1);
742 if (is_simple_msaa_resolve(info
)) {
743 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
744 util_blitter_custom_resolve_color(rctx
->blitter
,
745 info
->dst
.resource
, info
->dst
.level
,
747 info
->src
.resource
, info
->src
.box
.z
,
748 sample_mask
, rctx
->custom_blend_resolve
,
749 int_to_norm_format(info
->dst
.format
));
750 r600_blitter_end(ctx
);
754 /* resolve into a temporary texture, then blit */
755 templ
.target
= PIPE_TEXTURE_2D
;
756 templ
.format
= info
->src
.resource
->format
;
757 templ
.width0
= info
->src
.resource
->width0
;
758 templ
.height0
= info
->src
.resource
->height0
;
760 templ
.array_size
= 1;
761 templ
.last_level
= 0;
762 templ
.nr_samples
= 0;
763 templ
.usage
= PIPE_USAGE_STATIC
;
764 templ
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
765 templ
.flags
= R600_RESOURCE_FLAG_FORCE_TILING
; /* dst must not have a linear layout */
767 tmp
= screen
->resource_create(screen
, &templ
);
770 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
771 util_blitter_custom_resolve_color(rctx
->blitter
,
773 info
->src
.resource
, info
->src
.box
.z
,
774 sample_mask
, rctx
->custom_blend_resolve
,
775 int_to_norm_format(tmp
->format
));
776 r600_blitter_end(ctx
);
780 blit
.src
.resource
= tmp
;
783 r600_blitter_begin(ctx
, R600_BLIT
);
784 util_blitter_blit(rctx
->blitter
, &blit
);
785 r600_blitter_end(ctx
);
787 pipe_resource_reference(&tmp
, NULL
);
790 static void r600_blit(struct pipe_context
*ctx
,
791 const struct pipe_blit_info
*info
)
793 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
795 assert(util_blitter_is_blit_supported(rctx
->blitter
, info
));
797 if (info
->src
.resource
->nr_samples
> 1 &&
798 info
->dst
.resource
->nr_samples
<= 1 &&
799 !util_format_is_depth_or_stencil(info
->src
.resource
->format
) &&
800 !util_format_is_pure_integer(int_to_norm_format(info
->src
.resource
->format
))) {
801 r600_msaa_color_resolve(ctx
, info
);
805 /* The driver doesn't decompress resources automatically while
806 * u_blitter is rendering. */
807 if (!r600_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
809 info
->src
.box
.z
+ info
->src
.box
.depth
- 1)) {
813 r600_blitter_begin(ctx
, R600_BLIT
);
814 util_blitter_blit(rctx
->blitter
, info
);
815 r600_blitter_end(ctx
);
818 void r600_init_blit_functions(struct r600_context
*rctx
)
820 rctx
->context
.clear
= r600_clear
;
821 rctx
->context
.clear_render_target
= r600_clear_render_target
;
822 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
823 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
824 rctx
->context
.blit
= r600_blit
;