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.
25 #include "util/u_format.h"
26 #include "util/u_surface.h"
28 enum si_blitter_op
/* bitmask */
31 SI_SAVE_FRAMEBUFFER
= 2,
32 SI_DISABLE_RENDER_COND
= 4,
36 SI_CLEAR_SURFACE
= SI_SAVE_FRAMEBUFFER
,
38 SI_COPY
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
39 SI_DISABLE_RENDER_COND
,
41 SI_BLIT
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
,
43 SI_DECOMPRESS
= SI_SAVE_FRAMEBUFFER
| SI_DISABLE_RENDER_COND
,
45 SI_COLOR_RESOLVE
= SI_SAVE_FRAMEBUFFER
48 static void si_blitter_begin(struct pipe_context
*ctx
, enum si_blitter_op op
)
50 struct si_context
*sctx
= (struct si_context
*)ctx
;
52 r600_suspend_nontimer_queries(&sctx
->b
);
54 util_blitter_save_blend(sctx
->blitter
, sctx
->queued
.named
.blend
);
55 util_blitter_save_depth_stencil_alpha(sctx
->blitter
, sctx
->queued
.named
.dsa
);
56 util_blitter_save_stencil_ref(sctx
->blitter
, &sctx
->stencil_ref
);
57 util_blitter_save_rasterizer(sctx
->blitter
, sctx
->queued
.named
.rasterizer
);
58 util_blitter_save_fragment_shader(sctx
->blitter
, sctx
->ps_shader
);
59 util_blitter_save_geometry_shader(sctx
->blitter
, sctx
->gs_shader
);
60 util_blitter_save_tessctrl_shader(sctx
->blitter
, sctx
->tcs_shader
);
61 util_blitter_save_tesseval_shader(sctx
->blitter
, sctx
->tes_shader
);
62 util_blitter_save_vertex_shader(sctx
->blitter
, sctx
->vs_shader
);
63 util_blitter_save_vertex_elements(sctx
->blitter
, sctx
->vertex_elements
);
64 if (sctx
->queued
.named
.sample_mask
) {
65 util_blitter_save_sample_mask(sctx
->blitter
,
66 sctx
->queued
.named
.sample_mask
->sample_mask
);
68 if (sctx
->queued
.named
.viewport
[0]) {
69 util_blitter_save_viewport(sctx
->blitter
, &sctx
->queued
.named
.viewport
[0]->viewport
);
71 util_blitter_save_scissor(sctx
->blitter
, &sctx
->scissors
.states
[0]);
72 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
73 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
74 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
76 if (op
& SI_SAVE_FRAMEBUFFER
)
77 util_blitter_save_framebuffer(sctx
->blitter
, &sctx
->framebuffer
.state
);
79 if (op
& SI_SAVE_TEXTURES
) {
80 util_blitter_save_fragment_sampler_states(
82 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.saved_states
);
84 util_blitter_save_fragment_sampler_views(sctx
->blitter
, 2,
85 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
88 if ((op
& SI_DISABLE_RENDER_COND
) && sctx
->b
.current_render_cond
) {
89 util_blitter_save_render_condition(sctx
->blitter
,
90 sctx
->b
.current_render_cond
,
91 sctx
->b
.current_render_cond_cond
,
92 sctx
->b
.current_render_cond_mode
);
96 static void si_blitter_end(struct pipe_context
*ctx
)
98 struct si_context
*sctx
= (struct si_context
*)ctx
;
99 r600_resume_nontimer_queries(&sctx
->b
);
102 static unsigned u_max_sample(struct pipe_resource
*r
)
104 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
107 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
108 struct r600_texture
*texture
,
109 struct r600_texture
*staging
,
110 unsigned first_level
, unsigned last_level
,
111 unsigned first_layer
, unsigned last_layer
,
112 unsigned first_sample
, unsigned last_sample
)
114 struct si_context
*sctx
= (struct si_context
*)ctx
;
115 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
117 const struct util_format_description
*desc
;
118 struct r600_texture
*flushed_depth_texture
= staging
?
119 staging
: texture
->flushed_depth_texture
;
121 if (!staging
&& !texture
->dirty_level_mask
)
124 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
126 desc
= util_format_description(flushed_depth_texture
->resource
.b
.b
.format
);
128 if (util_format_has_depth(desc
))
129 sctx
->dbcb_depth_copy_enabled
= true;
130 if (util_format_has_stencil(desc
))
131 sctx
->dbcb_stencil_copy_enabled
= true;
133 assert(sctx
->dbcb_depth_copy_enabled
|| sctx
->dbcb_stencil_copy_enabled
);
135 for (level
= first_level
; level
<= last_level
; level
++) {
136 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
139 /* The smaller the mipmap level, the less layers there are
140 * as far as 3D textures are concerned. */
141 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
142 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
144 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
145 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
146 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
148 sctx
->dbcb_copy_sample
= sample
;
149 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
151 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
152 surf_tmpl
.u
.tex
.level
= level
;
153 surf_tmpl
.u
.tex
.first_layer
= layer
;
154 surf_tmpl
.u
.tex
.last_layer
= layer
;
156 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
158 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
159 cbsurf
= ctx
->create_surface(ctx
,
160 (struct pipe_resource
*)flushed_depth_texture
, &surf_tmpl
);
162 si_blitter_begin(ctx
, SI_DECOMPRESS
);
163 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
164 sctx
->custom_dsa_flush
, depth
);
167 pipe_surface_reference(&zsurf
, NULL
);
168 pipe_surface_reference(&cbsurf
, NULL
);
172 /* The texture will always be dirty if some layers aren't flushed.
173 * I don't think this case can occur though. */
175 first_layer
== 0 && last_layer
== max_layer
&&
176 first_sample
== 0 && last_sample
== max_sample
) {
177 texture
->dirty_level_mask
&= ~(1 << level
);
181 sctx
->dbcb_depth_copy_enabled
= false;
182 sctx
->dbcb_stencil_copy_enabled
= false;
183 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
186 static void si_blit_decompress_depth_in_place(struct si_context
*sctx
,
187 struct r600_texture
*texture
,
188 unsigned first_level
, unsigned last_level
,
189 unsigned first_layer
, unsigned last_layer
)
191 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
192 unsigned layer
, max_layer
, checked_last_layer
, level
;
194 sctx
->db_inplace_flush_enabled
= true;
195 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
197 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
199 for (level
= first_level
; level
<= last_level
; level
++) {
200 if (!(texture
->dirty_level_mask
& (1 << level
)))
203 surf_tmpl
.u
.tex
.level
= level
;
205 /* The smaller the mipmap level, the less layers there are
206 * as far as 3D textures are concerned. */
207 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
208 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
210 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
211 surf_tmpl
.u
.tex
.first_layer
= layer
;
212 surf_tmpl
.u
.tex
.last_layer
= layer
;
214 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
216 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
217 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
218 sctx
->custom_dsa_flush
,
220 si_blitter_end(&sctx
->b
.b
);
222 pipe_surface_reference(&zsurf
, NULL
);
225 /* The texture will always be dirty if some layers aren't flushed.
226 * I don't think this case occurs often though. */
227 if (first_layer
== 0 && last_layer
== max_layer
) {
228 texture
->dirty_level_mask
&= ~(1 << level
);
232 sctx
->db_inplace_flush_enabled
= false;
233 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
236 void si_flush_depth_textures(struct si_context
*sctx
,
237 struct si_textures_info
*textures
)
240 unsigned mask
= textures
->depth_texture_mask
;
243 struct pipe_sampler_view
*view
;
244 struct r600_texture
*tex
;
246 i
= u_bit_scan(&mask
);
248 view
= textures
->views
.views
[i
];
251 tex
= (struct r600_texture
*)view
->texture
;
252 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
254 si_blit_decompress_depth_in_place(sctx
, tex
,
255 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
256 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
260 static void si_blit_decompress_color(struct pipe_context
*ctx
,
261 struct r600_texture
*rtex
,
262 unsigned first_level
, unsigned last_level
,
263 unsigned first_layer
, unsigned last_layer
)
265 struct si_context
*sctx
= (struct si_context
*)ctx
;
266 unsigned layer
, level
, checked_last_layer
, max_layer
;
268 if (!rtex
->dirty_level_mask
)
271 for (level
= first_level
; level
<= last_level
; level
++) {
272 if (!(rtex
->dirty_level_mask
& (1 << level
)))
275 /* The smaller the mipmap level, the less layers there are
276 * as far as 3D textures are concerned. */
277 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
278 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
280 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
281 struct pipe_surface
*cbsurf
, surf_tmpl
;
283 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
284 surf_tmpl
.u
.tex
.level
= level
;
285 surf_tmpl
.u
.tex
.first_layer
= layer
;
286 surf_tmpl
.u
.tex
.last_layer
= layer
;
287 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
289 si_blitter_begin(ctx
, SI_DECOMPRESS
);
290 util_blitter_custom_color(sctx
->blitter
, cbsurf
,
291 rtex
->fmask
.size
? sctx
->custom_blend_decompress
:
292 sctx
->custom_blend_fastclear
);
295 pipe_surface_reference(&cbsurf
, NULL
);
298 /* The texture will always be dirty if some layers aren't flushed.
299 * I don't think this case occurs often though. */
300 if (first_layer
== 0 && last_layer
== max_layer
) {
301 rtex
->dirty_level_mask
&= ~(1 << level
);
306 void si_decompress_color_textures(struct si_context
*sctx
,
307 struct si_textures_info
*textures
)
310 unsigned mask
= textures
->compressed_colortex_mask
;
313 struct pipe_sampler_view
*view
;
314 struct r600_texture
*tex
;
316 i
= u_bit_scan(&mask
);
318 view
= textures
->views
.views
[i
];
321 tex
= (struct r600_texture
*)view
->texture
;
322 assert(tex
->cmask
.size
|| tex
->fmask
.size
);
324 si_blit_decompress_color(&sctx
->b
.b
, tex
,
325 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
326 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
330 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
331 const union pipe_color_union
*color
,
332 double depth
, unsigned stencil
)
334 struct si_context
*sctx
= (struct si_context
*)ctx
;
335 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
336 struct pipe_surface
*zsbuf
= fb
->zsbuf
;
337 struct r600_texture
*zstex
=
338 zsbuf
? (struct r600_texture
*)zsbuf
->texture
: NULL
;
340 if (buffers
& PIPE_CLEAR_COLOR
) {
341 evergreen_do_fast_color_clear(&sctx
->b
, fb
, &sctx
->framebuffer
.atom
,
344 return; /* all buffers have been fast cleared */
347 if (buffers
& PIPE_CLEAR_COLOR
) {
350 /* These buffers cannot use fast clear, make sure to disable expansion. */
351 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
352 struct r600_texture
*tex
;
354 /* If not clearing this buffer, skip. */
355 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
361 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
362 if (tex
->fmask
.size
== 0)
363 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
367 if (buffers
& PIPE_CLEAR_DEPTH
&&
368 zstex
&& zstex
->htile_buffer
&&
369 zsbuf
->u
.tex
.level
== 0 &&
370 zsbuf
->u
.tex
.first_layer
== 0 &&
371 zsbuf
->u
.tex
.last_layer
== util_max_layer(&zstex
->resource
.b
.b
, 0)) {
372 /* Need to disable EXPCLEAR temporarily if clearing
374 if (zstex
->depth_cleared
&& zstex
->depth_clear_value
!= depth
) {
375 sctx
->db_depth_disable_expclear
= true;
378 zstex
->depth_clear_value
= depth
;
379 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_DEPTH_CLEAR */
380 sctx
->db_depth_clear
= true;
381 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
384 si_blitter_begin(ctx
, SI_CLEAR
);
385 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
386 util_framebuffer_get_num_layers(fb
),
387 buffers
, color
, depth
, stencil
);
390 if (sctx
->db_depth_clear
) {
391 sctx
->db_depth_clear
= false;
392 sctx
->db_depth_disable_expclear
= false;
393 zstex
->depth_cleared
= true;
394 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
398 static void si_clear_render_target(struct pipe_context
*ctx
,
399 struct pipe_surface
*dst
,
400 const union pipe_color_union
*color
,
401 unsigned dstx
, unsigned dsty
,
402 unsigned width
, unsigned height
)
404 struct si_context
*sctx
= (struct si_context
*)ctx
;
406 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
407 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
408 dstx
, dsty
, width
, height
);
412 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
413 struct pipe_surface
*dst
,
414 unsigned clear_flags
,
417 unsigned dstx
, unsigned dsty
,
418 unsigned width
, unsigned height
)
420 struct si_context
*sctx
= (struct si_context
*)ctx
;
422 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
423 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
424 dstx
, dsty
, width
, height
);
428 /* Helper for decompressing a portion of a color or depth resource before
429 * blitting if any decompression is needed.
430 * The driver doesn't decompress resources automatically while u_blitter is
432 static void si_decompress_subresource(struct pipe_context
*ctx
,
433 struct pipe_resource
*tex
,
435 unsigned first_layer
, unsigned last_layer
)
437 struct si_context
*sctx
= (struct si_context
*)ctx
;
438 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
440 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
441 si_blit_decompress_depth_in_place(sctx
, rtex
,
443 first_layer
, last_layer
);
444 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
) {
445 si_blit_decompress_color(ctx
, rtex
, level
, level
,
446 first_layer
, last_layer
);
450 struct texture_orig_info
{
460 void si_resource_copy_region(struct pipe_context
*ctx
,
461 struct pipe_resource
*dst
,
463 unsigned dstx
, unsigned dsty
, unsigned dstz
,
464 struct pipe_resource
*src
,
466 const struct pipe_box
*src_box
)
468 struct si_context
*sctx
= (struct si_context
*)ctx
;
469 struct pipe_surface
*dst_view
, dst_templ
;
470 struct pipe_sampler_view src_templ
, *src_view
;
471 unsigned dst_width
, dst_height
, src_width0
, src_height0
;
472 unsigned src_force_level
= 0;
473 struct pipe_box sbox
, dstbox
;
475 /* Handle buffers first. */
476 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
477 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
, false);
481 assert(u_max_sample(dst
) == u_max_sample(src
));
483 /* The driver doesn't decompress resources automatically while
484 * u_blitter is rendering. */
485 si_decompress_subresource(ctx
, src
, src_level
,
486 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
488 dst_width
= u_minify(dst
->width0
, dst_level
);
489 dst_height
= u_minify(dst
->height0
, dst_level
);
490 src_width0
= src
->width0
;
491 src_height0
= src
->height0
;
493 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
494 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
496 if (util_format_is_compressed(src
->format
) &&
497 util_format_is_compressed(dst
->format
)) {
498 unsigned blocksize
= util_format_get_blocksize(src
->format
);
501 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
503 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
504 dst_templ
.format
= src_templ
.format
;
506 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
507 dst_height
= util_format_get_nblocksy(dst
->format
, dst_height
);
508 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
509 src_height0
= util_format_get_nblocksy(src
->format
, src_height0
);
511 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
512 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
514 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
515 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
517 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
518 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
519 sbox
.depth
= src_box
->depth
;
522 src_force_level
= src_level
;
523 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
) ||
524 /* also *8_SNORM has precision issues, use UNORM instead */
525 util_format_is_snorm(src
->format
)) {
526 if (util_format_is_subsampled_422(src
->format
)) {
527 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
528 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
530 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
531 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
533 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
536 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
537 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
540 unsigned blocksize
= util_format_get_blocksize(src
->format
);
544 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
545 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
548 dst_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
549 src_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
552 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
553 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
556 dst_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
557 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
560 dst_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
561 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
564 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
565 util_format_short_name(src
->format
), blocksize
);
571 /* Initialize the surface. */
572 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
573 dst_width
, dst_height
);
575 /* Initialize the sampler view. */
576 src_view
= si_create_sampler_view_custom(ctx
, src
, &src_templ
,
577 src_width0
, src_height0
,
580 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
581 abs(src_box
->depth
), &dstbox
);
584 si_blitter_begin(ctx
, SI_COPY
);
585 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
586 src_view
, src_box
, src_width0
, src_height0
,
587 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
591 pipe_surface_reference(&dst_view
, NULL
);
592 pipe_sampler_view_reference(&src_view
, NULL
);
595 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
596 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
599 #define REPLACE_FORMAT_SIGN(format,sign) \
600 case PIPE_FORMAT_##format##_##sign##INT: \
601 return PIPE_FORMAT_##format##_##sign##NORM
602 #define REPLACE_FORMAT(format) \
603 REPLACE_FORMAT_SIGN(format, U); \
604 REPLACE_FORMAT_SIGN(format, S)
606 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
608 REPLACE_FORMAT(R8G8
);
609 REPLACE_FORMAT(R8G8B8X8
);
610 REPLACE_FORMAT(R8G8B8A8
);
614 REPLACE_FORMAT(L8A8
);
616 REPLACE_FORMAT(R16G16
);
617 REPLACE_FORMAT(R16G16B16X16
);
618 REPLACE_FORMAT(R16G16B16A16
);
622 REPLACE_FORMAT(L16A16
);
624 #undef REPLACE_FORMAT
625 #undef REPLACE_FORMAT_SIGN
631 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
632 const struct pipe_blit_info
*info
)
634 struct si_context
*sctx
= (struct si_context
*)ctx
;
635 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
636 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
637 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
638 enum pipe_format format
= int_to_norm_format(info
->dst
.format
);
639 unsigned sample_mask
= ~0;
641 if (info
->src
.resource
->nr_samples
> 1 &&
642 info
->dst
.resource
->nr_samples
<= 1 &&
643 util_max_layer(info
->src
.resource
, 0) == 0 &&
644 util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
645 info
->dst
.format
== info
->src
.format
&&
646 !util_format_is_pure_integer(format
) &&
647 !util_format_is_depth_or_stencil(format
) &&
648 !info
->scissor_enable
&&
649 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
650 dst_width
== info
->src
.resource
->width0
&&
651 dst_height
== info
->src
.resource
->height0
&&
652 info
->dst
.box
.x
== 0 &&
653 info
->dst
.box
.y
== 0 &&
654 info
->dst
.box
.width
== dst_width
&&
655 info
->dst
.box
.height
== dst_height
&&
656 info
->dst
.box
.depth
== 1 &&
657 info
->src
.box
.x
== 0 &&
658 info
->src
.box
.y
== 0 &&
659 info
->src
.box
.width
== dst_width
&&
660 info
->src
.box
.height
== dst_height
&&
661 info
->src
.box
.depth
== 1 &&
662 dst
->surface
.level
[info
->dst
.level
].mode
>= RADEON_SURF_MODE_1D
&&
663 !(dst
->surface
.flags
& RADEON_SURF_SCANOUT
) &&
664 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
) /* dst cannot be fast-cleared */) {
665 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
|
666 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
667 util_blitter_custom_resolve_color(sctx
->blitter
,
668 info
->dst
.resource
, info
->dst
.level
,
670 info
->src
.resource
, info
->src
.box
.z
,
671 sample_mask
, sctx
->custom_blend_resolve
,
679 static void si_blit(struct pipe_context
*ctx
,
680 const struct pipe_blit_info
*info
)
682 struct si_context
*sctx
= (struct si_context
*)ctx
;
684 if (do_hardware_msaa_resolve(ctx
, info
)) {
688 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
690 /* The driver doesn't decompress resources automatically while
691 * u_blitter is rendering. */
692 si_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
694 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
696 if (sctx
->screen
->b
.debug_flags
& DBG_FORCE_DMA
&&
697 util_try_blit_via_copy_region(ctx
, info
))
700 si_blitter_begin(ctx
, SI_BLIT
|
701 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
702 util_blitter_blit(sctx
->blitter
, info
);
706 static void si_flush_resource(struct pipe_context
*ctx
,
707 struct pipe_resource
*res
)
709 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
711 assert(res
->target
!= PIPE_BUFFER
);
713 if (!rtex
->is_depth
&& rtex
->cmask
.size
) {
714 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
715 0, util_max_layer(res
, 0));
719 void si_init_blit_functions(struct si_context
*sctx
)
721 sctx
->b
.b
.clear
= si_clear
;
722 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
723 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
724 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
725 sctx
->b
.b
.blit
= si_blit
;
726 sctx
->b
.b
.flush_resource
= si_flush_resource
;
727 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;