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"
27 #include "evergreend.h"
29 enum r600_blitter_op
/* bitmask */
31 R600_SAVE_FRAGMENT_STATE
= 1,
32 R600_SAVE_TEXTURES
= 2,
33 R600_SAVE_FRAMEBUFFER
= 4,
34 R600_DISABLE_RENDER_COND
= 8,
36 R600_CLEAR
= R600_SAVE_FRAGMENT_STATE
,
38 R600_CLEAR_SURFACE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
,
40 R600_COPY_BUFFER
= R600_DISABLE_RENDER_COND
,
42 R600_COPY_TEXTURE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_SAVE_TEXTURES
|
43 R600_DISABLE_RENDER_COND
,
45 R600_BLIT
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_SAVE_TEXTURES
,
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
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
->b
);
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_geometry_shader(rctx
->blitter
, rctx
->gs_shader
);
62 util_blitter_save_so_targets(rctx
->blitter
, rctx
->b
.streamout
.num_targets
,
63 (struct pipe_stream_output_target
**)rctx
->b
.streamout
.targets
);
64 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->rasterizer_state
.cso
);
66 if (op
& R600_SAVE_FRAGMENT_STATE
) {
67 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
[0].state
);
68 util_blitter_save_scissor(rctx
->blitter
, &rctx
->scissor
[0].scissor
);
69 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
70 util_blitter_save_blend(rctx
->blitter
, rctx
->blend_state
.cso
);
71 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->dsa_state
.cso
);
72 util_blitter_save_stencil_ref(rctx
->blitter
, &rctx
->stencil_ref
.pipe_state
);
73 util_blitter_save_sample_mask(rctx
->blitter
, rctx
->sample_mask
.sample_mask
);
76 if (op
& R600_SAVE_FRAMEBUFFER
)
77 util_blitter_save_framebuffer(rctx
->blitter
, &rctx
->framebuffer
.state
);
79 if (op
& R600_SAVE_TEXTURES
) {
80 util_blitter_save_fragment_sampler_states(
81 rctx
->blitter
, util_last_bit(rctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.enabled_mask
),
82 (void**)rctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.states
);
84 util_blitter_save_fragment_sampler_views(
85 rctx
->blitter
, util_last_bit(rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.enabled_mask
),
86 (struct pipe_sampler_view
**)rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
89 if ((op
& R600_DISABLE_RENDER_COND
) && rctx
->b
.current_render_cond
) {
90 util_blitter_save_render_condition(rctx
->blitter
,
91 rctx
->b
.current_render_cond
,
92 rctx
->b
.current_render_cond_cond
,
93 rctx
->b
.current_render_cond_mode
);
97 static void r600_blitter_end(struct pipe_context
*ctx
)
99 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
100 r600_resume_nontimer_queries(&rctx
->b
);
103 static unsigned u_max_sample(struct pipe_resource
*r
)
105 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
108 static void r600_blit_decompress_depth(struct pipe_context
*ctx
,
109 struct r600_texture
*texture
,
110 struct r600_texture
*staging
,
111 unsigned first_level
, unsigned last_level
,
112 unsigned first_layer
, unsigned last_layer
,
113 unsigned first_sample
, unsigned last_sample
)
115 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
116 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
117 struct r600_texture
*flushed_depth_texture
= staging
?
118 staging
: texture
->flushed_depth_texture
;
119 const struct util_format_description
*desc
=
120 util_format_description(texture
->resource
.b
.b
.format
);
123 if (!staging
&& !texture
->dirty_level_mask
)
126 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
128 /* XXX Decompressing MSAA depth textures is broken on R6xx.
129 * There is also a hardlock if CMASK and FMASK are not present.
130 * Just skip this until we find out how to fix it. */
131 if (rctx
->b
.chip_class
== R600
&& max_sample
> 0) {
132 texture
->dirty_level_mask
= 0;
136 if (rctx
->b
.family
== CHIP_RV610
|| rctx
->b
.family
== CHIP_RV630
||
137 rctx
->b
.family
== CHIP_RV620
|| rctx
->b
.family
== CHIP_RV635
)
142 /* Enable decompression in DB_RENDER_CONTROL */
143 rctx
->db_misc_state
.flush_depthstencil_through_cb
= true;
144 rctx
->db_misc_state
.copy_depth
= util_format_has_depth(desc
);
145 rctx
->db_misc_state
.copy_stencil
= util_format_has_stencil(desc
);
146 rctx
->db_misc_state
.copy_sample
= first_sample
;
147 rctx
->db_misc_state
.atom
.dirty
= true;
149 for (level
= first_level
; level
<= last_level
; level
++) {
150 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
153 /* The smaller the mipmap level, the less layers there are
154 * as far as 3D textures are concerned. */
155 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
156 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
158 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
159 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
160 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
162 if (sample
!= rctx
->db_misc_state
.copy_sample
) {
163 rctx
->db_misc_state
.copy_sample
= sample
;
164 rctx
->db_misc_state
.atom
.dirty
= true;
167 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
168 surf_tmpl
.u
.tex
.level
= level
;
169 surf_tmpl
.u
.tex
.first_layer
= layer
;
170 surf_tmpl
.u
.tex
.last_layer
= layer
;
172 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
174 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
175 cbsurf
= ctx
->create_surface(ctx
,
176 &flushed_depth_texture
->resource
.b
.b
, &surf_tmpl
);
178 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
179 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
180 rctx
->custom_dsa_flush
, depth
);
181 r600_blitter_end(ctx
);
183 pipe_surface_reference(&zsurf
, NULL
);
184 pipe_surface_reference(&cbsurf
, NULL
);
188 /* The texture will always be dirty if some layers or samples aren't flushed.
189 * I don't think this case occurs often though. */
191 first_layer
== 0 && last_layer
== max_layer
&&
192 first_sample
== 0 && last_sample
== max_sample
) {
193 texture
->dirty_level_mask
&= ~(1 << level
);
197 /* reenable compression in DB_RENDER_CONTROL */
198 rctx
->db_misc_state
.flush_depthstencil_through_cb
= false;
199 rctx
->db_misc_state
.atom
.dirty
= true;
202 static void r600_blit_decompress_depth_in_place(struct r600_context
*rctx
,
203 struct r600_texture
*texture
,
204 unsigned first_level
, unsigned last_level
,
205 unsigned first_layer
, unsigned last_layer
)
207 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
208 unsigned layer
, max_layer
, checked_last_layer
, level
;
210 /* Enable decompression in DB_RENDER_CONTROL */
211 rctx
->db_misc_state
.flush_depthstencil_in_place
= true;
212 rctx
->db_misc_state
.atom
.dirty
= true;
214 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
216 for (level
= first_level
; level
<= last_level
; level
++) {
217 if (!(texture
->dirty_level_mask
& (1 << level
)))
220 surf_tmpl
.u
.tex
.level
= level
;
222 /* The smaller the mipmap level, the less layers there are
223 * as far as 3D textures are concerned. */
224 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
225 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
227 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
228 surf_tmpl
.u
.tex
.first_layer
= layer
;
229 surf_tmpl
.u
.tex
.last_layer
= layer
;
231 zsurf
= rctx
->b
.b
.create_surface(&rctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
233 r600_blitter_begin(&rctx
->b
.b
, R600_DECOMPRESS
);
234 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, NULL
, ~0,
235 rctx
->custom_dsa_flush
, 1.0f
);
236 r600_blitter_end(&rctx
->b
.b
);
238 pipe_surface_reference(&zsurf
, NULL
);
241 /* The texture will always be dirty if some layers or samples aren't flushed.
242 * I don't think this case occurs often though. */
243 if (first_layer
== 0 && last_layer
== max_layer
) {
244 texture
->dirty_level_mask
&= ~(1 << level
);
248 /* Disable decompression in DB_RENDER_CONTROL */
249 rctx
->db_misc_state
.flush_depthstencil_in_place
= false;
250 rctx
->db_misc_state
.atom
.dirty
= true;
253 void r600_decompress_depth_textures(struct r600_context
*rctx
,
254 struct r600_samplerview_state
*textures
)
257 unsigned depth_texture_mask
= textures
->compressed_depthtex_mask
;
259 while (depth_texture_mask
) {
260 struct pipe_sampler_view
*view
;
261 struct r600_texture
*tex
;
263 i
= u_bit_scan(&depth_texture_mask
);
265 view
= &textures
->views
[i
]->base
;
268 tex
= (struct r600_texture
*)view
->texture
;
269 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
271 if (rctx
->b
.chip_class
>= EVERGREEN
||
272 r600_can_read_depth(tex
)) {
273 r600_blit_decompress_depth_in_place(rctx
, tex
,
274 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
275 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
277 r600_blit_decompress_depth(&rctx
->b
.b
, tex
, NULL
,
278 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
279 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
),
280 0, u_max_sample(&tex
->resource
.b
.b
));
285 static void r600_blit_decompress_color(struct pipe_context
*ctx
,
286 struct r600_texture
*rtex
,
287 unsigned first_level
, unsigned last_level
,
288 unsigned first_layer
, unsigned last_layer
)
290 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
291 unsigned layer
, level
, checked_last_layer
, max_layer
;
293 if (!rtex
->dirty_level_mask
)
296 for (level
= first_level
; level
<= last_level
; level
++) {
297 if (!(rtex
->dirty_level_mask
& (1 << level
)))
300 /* The smaller the mipmap level, the less layers there are
301 * as far as 3D textures are concerned. */
302 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
303 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
305 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
306 struct pipe_surface
*cbsurf
, surf_tmpl
;
308 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
309 surf_tmpl
.u
.tex
.level
= level
;
310 surf_tmpl
.u
.tex
.first_layer
= layer
;
311 surf_tmpl
.u
.tex
.last_layer
= layer
;
312 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
314 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
315 util_blitter_custom_color(rctx
->blitter
, cbsurf
,
316 rtex
->fmask
.size
? rctx
->custom_blend_decompress
: rctx
->custom_blend_fastclear
);
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
);
348 r600_blit_decompress_color(&rctx
->b
.b
, 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
->b
.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
->cmask
.size
) {
382 r600_blit_decompress_color(ctx
, rtex
, level
, level
,
383 first_layer
, last_layer
);
388 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
389 const union pipe_color_union
*color
,
390 double depth
, unsigned stencil
)
392 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
393 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
.state
;
395 if (buffers
& PIPE_CLEAR_COLOR
&& rctx
->b
.chip_class
>= EVERGREEN
) {
396 evergreen_do_fast_color_clear(&rctx
->b
, fb
, &rctx
->framebuffer
.atom
,
400 if (buffers
& PIPE_CLEAR_COLOR
) {
403 /* These buffers cannot use fast clear, make sure to disable expansion. */
404 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
405 struct r600_texture
*tex
;
407 /* If not clearing this buffer, skip. */
408 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
414 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
415 if (tex
->fmask
.size
== 0)
416 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
420 /* if hyperz enabled just clear hyperz */
421 if (fb
->zsbuf
&& (buffers
& PIPE_CLEAR_DEPTH
)) {
422 struct r600_texture
*rtex
;
423 unsigned level
= fb
->zsbuf
->u
.tex
.level
;
425 rtex
= (struct r600_texture
*)fb
->zsbuf
->texture
;
427 /* We can't use hyperz fast clear if each slice of a texture
428 * array are clear to different value. To simplify code just
429 * disable fast clear for texture array.
431 /* Only use htile for first level */
432 if (rtex
->htile_buffer
&& !level
&& rtex
->surface
.array_size
== 1) {
433 if (rtex
->depth_clear_value
!= depth
) {
434 rtex
->depth_clear_value
= depth
;
435 rctx
->db_state
.atom
.dirty
= true;
437 rctx
->db_misc_state
.htile_clear
= true;
438 rctx
->db_misc_state
.atom
.dirty
= true;
442 r600_blitter_begin(ctx
, R600_CLEAR
);
443 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
, 1,
444 buffers
, color
, depth
, stencil
);
445 r600_blitter_end(ctx
);
447 /* disable fast clear */
448 if (rctx
->db_misc_state
.htile_clear
) {
449 rctx
->db_misc_state
.htile_clear
= false;
450 rctx
->db_misc_state
.atom
.dirty
= true;
454 static void r600_clear_render_target(struct pipe_context
*ctx
,
455 struct pipe_surface
*dst
,
456 const union pipe_color_union
*color
,
457 unsigned dstx
, unsigned dsty
,
458 unsigned width
, unsigned height
)
460 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
462 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
463 util_blitter_clear_render_target(rctx
->blitter
, dst
, color
,
464 dstx
, dsty
, width
, height
);
465 r600_blitter_end(ctx
);
468 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
469 struct pipe_surface
*dst
,
470 unsigned clear_flags
,
473 unsigned dstx
, unsigned dsty
,
474 unsigned width
, unsigned height
)
476 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
478 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
479 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
480 dstx
, dsty
, width
, height
);
481 r600_blitter_end(ctx
);
484 static void r600_copy_buffer(struct pipe_context
*ctx
, struct pipe_resource
*dst
, unsigned dstx
,
485 struct pipe_resource
*src
, const struct pipe_box
*src_box
)
487 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
489 if (rctx
->screen
->b
.has_cp_dma
) {
490 r600_cp_dma_copy_buffer(rctx
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
492 else if (rctx
->screen
->b
.has_streamout
&&
493 /* Require 4-byte alignment. */
494 dstx
% 4 == 0 && src_box
->x
% 4 == 0 && src_box
->width
% 4 == 0) {
496 r600_blitter_begin(ctx
, R600_COPY_BUFFER
);
497 util_blitter_copy_buffer(rctx
->blitter
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
498 r600_blitter_end(ctx
);
500 util_resource_copy_region(ctx
, dst
, 0, dstx
, 0, 0, src
, 0, src_box
);
503 /* The index buffer (VGT) doesn't seem to see the result of the copying.
504 * Can we somehow flush the index buffer cache? Starting a new IB seems
505 * to do the trick. */
506 if (rctx
->b
.chip_class
<= R700
)
507 rctx
->b
.rings
.gfx
.flush(ctx
, RADEON_FLUSH_ASYNC
, NULL
);
511 * Global buffers are not really resources, they are are actually offsets
512 * into a single global resource (r600_screen::global_pool). The means
513 * they don't have their own cs_buf handle, so they cannot be passed
514 * to r600_copy_buffer() and must be handled separately.
516 * XXX: It should be possible to implement this function using
517 * r600_copy_buffer() by passing the memory_pool resource as both src
518 * and dst and updating dstx and src_box to point to the correct offsets.
519 * This would likely perform better than the current implementation.
521 static void r600_copy_global_buffer(struct pipe_context
*ctx
,
522 struct pipe_resource
*dst
, unsigned
523 dstx
, struct pipe_resource
*src
,
524 const struct pipe_box
*src_box
)
526 struct pipe_box dst_box
; struct pipe_transfer
*src_pxfer
,
529 u_box_1d(dstx
, src_box
->width
, &dst_box
);
530 void *src_ptr
= ctx
->transfer_map(ctx
, src
, 0, PIPE_TRANSFER_READ
,
531 src_box
, &src_pxfer
);
532 void *dst_ptr
= ctx
->transfer_map(ctx
, dst
, 0, PIPE_TRANSFER_WRITE
,
533 &dst_box
, &dst_pxfer
);
534 memcpy(dst_ptr
, src_ptr
, src_box
->width
);
536 ctx
->transfer_unmap(ctx
, src_pxfer
);
537 ctx
->transfer_unmap(ctx
, dst_pxfer
);
540 static void r600_clear_buffer(struct pipe_context
*ctx
, struct pipe_resource
*dst
,
541 unsigned offset
, unsigned size
, unsigned value
)
543 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
545 if (rctx
->screen
->b
.has_cp_dma
&&
546 rctx
->b
.chip_class
>= EVERGREEN
&&
547 offset
% 4 == 0 && size
% 4 == 0) {
548 evergreen_cp_dma_clear_buffer(rctx
, dst
, offset
, size
, value
);
549 } else if (rctx
->screen
->b
.has_streamout
&& offset
% 4 == 0 && size
% 4 == 0) {
550 union pipe_color_union clear_value
;
551 clear_value
.ui
[0] = value
;
553 r600_blitter_begin(ctx
, R600_DISABLE_RENDER_COND
);
554 util_blitter_clear_buffer(rctx
->blitter
, dst
, offset
, size
,
556 r600_blitter_end(ctx
);
558 uint32_t *map
= r600_buffer_map_sync_with_rings(&rctx
->b
, r600_resource(dst
),
559 PIPE_TRANSFER_WRITE
);
561 for (unsigned i
= 0; i
< size
; i
++)
566 static void r600_resource_copy_region(struct pipe_context
*ctx
,
567 struct pipe_resource
*dst
,
569 unsigned dstx
, unsigned dsty
, unsigned dstz
,
570 struct pipe_resource
*src
,
572 const struct pipe_box
*src_box
)
574 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
575 struct pipe_surface
*dst_view
, dst_templ
;
576 struct pipe_sampler_view src_templ
, *src_view
;
577 unsigned dst_width
, dst_height
, src_width0
, src_height0
, src_widthFL
, src_heightFL
;
578 unsigned src_force_level
= 0;
579 struct pipe_box sbox
, dstbox
;
581 /* Handle buffers first. */
582 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
583 if ((src
->bind
& PIPE_BIND_GLOBAL
) ||
584 (dst
->bind
& PIPE_BIND_GLOBAL
)) {
585 r600_copy_global_buffer(ctx
, dst
, dstx
, src
, src_box
);
587 r600_copy_buffer(ctx
, dst
, dstx
, src
, src_box
);
592 assert(u_max_sample(dst
) == u_max_sample(src
));
594 /* The driver doesn't decompress resources automatically while
595 * u_blitter is rendering. */
596 if (!r600_decompress_subresource(ctx
, src
, src_level
,
597 src_box
->z
, src_box
->z
+ src_box
->depth
- 1)) {
601 dst_width
= u_minify(dst
->width0
, dst_level
);
602 dst_height
= u_minify(dst
->height0
, dst_level
);
603 src_width0
= src
->width0
;
604 src_height0
= src
->height0
;
605 src_widthFL
= u_minify(src
->width0
, src_level
);
606 src_heightFL
= u_minify(src
->height0
, src_level
);
608 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
609 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
611 if (util_format_is_compressed(src
->format
)) {
612 unsigned blocksize
= util_format_get_blocksize(src
->format
);
615 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
617 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
618 dst_templ
.format
= src_templ
.format
;
620 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
621 dst_height
= util_format_get_nblocksy(dst
->format
, dst_height
);
622 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
623 src_height0
= util_format_get_nblocksy(src
->format
, src_height0
);
624 src_widthFL
= util_format_get_nblocksx(src
->format
, src_widthFL
);
625 src_heightFL
= util_format_get_nblocksy(src
->format
, src_heightFL
);
627 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
628 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
630 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
631 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
633 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
634 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
635 sbox
.depth
= src_box
->depth
;
638 src_force_level
= src_level
;
639 } else if (!util_blitter_is_copy_supported(rctx
->blitter
, dst
, src
)) {
640 if (util_format_is_subsampled_422(src
->format
)) {
642 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
643 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
645 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
646 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
647 src_widthFL
= util_format_get_nblocksx(src
->format
, src_widthFL
);
649 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
652 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
653 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
656 unsigned blocksize
= util_format_get_blocksize(src
->format
);
660 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
661 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
664 dst_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
665 src_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
668 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
669 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
672 dst_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
673 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
676 dst_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
677 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
680 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
681 util_format_short_name(src
->format
), blocksize
);
687 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
, dst_width
, dst_height
);
689 if (rctx
->b
.chip_class
>= EVERGREEN
) {
690 src_view
= evergreen_create_sampler_view_custom(ctx
, src
, &src_templ
,
691 src_width0
, src_height0
,
694 src_view
= r600_create_sampler_view_custom(ctx
, src
, &src_templ
,
695 src_widthFL
, src_heightFL
);
698 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
699 abs(src_box
->depth
), &dstbox
);
702 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
703 util_blitter_blit_generic(rctx
->blitter
, dst_view
, &dstbox
,
704 src_view
, src_box
, src_width0
, src_height0
,
705 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
);
706 r600_blitter_end(ctx
);
708 pipe_surface_reference(&dst_view
, NULL
);
709 pipe_sampler_view_reference(&src_view
, NULL
);
712 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
713 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
716 #define REPLACE_FORMAT_SIGN(format,sign) \
717 case PIPE_FORMAT_##format##_##sign##INT: \
718 return PIPE_FORMAT_##format##_##sign##NORM
719 #define REPLACE_FORMAT(format) \
720 REPLACE_FORMAT_SIGN(format, U); \
721 REPLACE_FORMAT_SIGN(format, S)
723 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
725 REPLACE_FORMAT(R8G8
);
726 REPLACE_FORMAT(R8G8B8X8
);
727 REPLACE_FORMAT(R8G8B8A8
);
731 REPLACE_FORMAT(L8A8
);
733 REPLACE_FORMAT(R16G16
);
734 REPLACE_FORMAT(R16G16B16X16
);
735 REPLACE_FORMAT(R16G16B16A16
);
739 REPLACE_FORMAT(L16A16
);
741 #undef REPLACE_FORMAT
742 #undef REPLACE_FORMAT_SIGN
748 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
749 const struct pipe_blit_info
*info
)
751 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
752 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
753 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
754 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
755 enum pipe_format format
= int_to_norm_format(info
->dst
.format
);
756 unsigned sample_mask
=
757 rctx
->b
.chip_class
== CAYMAN
? ~0 :
758 ((1ull << MAX2(1, info
->src
.resource
->nr_samples
)) - 1);
760 if (info
->src
.resource
->nr_samples
> 1 &&
761 info
->dst
.resource
->nr_samples
<= 1 &&
762 util_max_layer(info
->src
.resource
, 0) == 0 &&
763 util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
764 info
->dst
.format
== info
->src
.format
&&
765 !util_format_is_pure_integer(format
) &&
766 !util_format_is_depth_or_stencil(format
) &&
767 !info
->scissor_enable
&&
768 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
769 dst_width
== info
->src
.resource
->width0
&&
770 dst_height
== info
->src
.resource
->height0
&&
771 info
->dst
.box
.x
== 0 &&
772 info
->dst
.box
.y
== 0 &&
773 info
->dst
.box
.width
== dst_width
&&
774 info
->dst
.box
.height
== dst_height
&&
775 info
->dst
.box
.depth
== 1 &&
776 info
->src
.box
.x
== 0 &&
777 info
->src
.box
.y
== 0 &&
778 info
->src
.box
.width
== dst_width
&&
779 info
->src
.box
.height
== dst_height
&&
780 info
->src
.box
.depth
== 1 &&
781 dst
->surface
.level
[info
->dst
.level
].mode
>= RADEON_SURF_MODE_1D
&&
782 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
) /* dst cannot be fast-cleared */) {
783 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
|
784 (info
->render_condition_enable
? 0 : R600_DISABLE_RENDER_COND
));
785 util_blitter_custom_resolve_color(rctx
->blitter
,
786 info
->dst
.resource
, info
->dst
.level
,
788 info
->src
.resource
, info
->src
.box
.z
,
789 sample_mask
, rctx
->custom_blend_resolve
,
791 r600_blitter_end(ctx
);
797 static void r600_blit(struct pipe_context
*ctx
,
798 const struct pipe_blit_info
*info
)
800 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
802 if (do_hardware_msaa_resolve(ctx
, info
)) {
806 assert(util_blitter_is_blit_supported(rctx
->blitter
, info
));
808 /* The driver doesn't decompress resources automatically while
809 * u_blitter is rendering. */
810 if (!r600_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
812 info
->src
.box
.z
+ info
->src
.box
.depth
- 1)) {
816 r600_blitter_begin(ctx
, R600_BLIT
|
817 (info
->render_condition_enable
? 0 : R600_DISABLE_RENDER_COND
));
818 util_blitter_blit(rctx
->blitter
, info
);
819 r600_blitter_end(ctx
);
822 static void r600_flush_resource(struct pipe_context
*ctx
,
823 struct pipe_resource
*res
)
825 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
827 assert(res
->target
!= PIPE_BUFFER
);
829 if (!rtex
->is_depth
&& rtex
->cmask
.size
) {
830 r600_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
831 0, res
->array_size
- 1);
835 void r600_init_blit_functions(struct r600_context
*rctx
)
837 rctx
->b
.b
.clear
= r600_clear
;
838 rctx
->b
.b
.clear_render_target
= r600_clear_render_target
;
839 rctx
->b
.b
.clear_depth_stencil
= r600_clear_depth_stencil
;
840 rctx
->b
.b
.resource_copy_region
= r600_resource_copy_region
;
841 rctx
->b
.b
.blit
= r600_blit
;
842 rctx
->b
.b
.flush_resource
= r600_flush_resource
;
843 rctx
->b
.clear_buffer
= r600_clear_buffer
;
844 rctx
->b
.blit_decompress_depth
= r600_blit_decompress_depth
;