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 "si_compute.h"
26 #include "util/u_format.h"
27 #include "util/u_surface.h"
29 enum si_blitter_op
/* bitmask */
32 SI_SAVE_FRAMEBUFFER
= 2,
33 SI_SAVE_FRAGMENT_STATE
= 4,
34 SI_DISABLE_RENDER_COND
= 8,
36 SI_CLEAR
= SI_SAVE_FRAGMENT_STATE
,
38 SI_CLEAR_SURFACE
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
,
40 SI_COPY
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
41 SI_SAVE_FRAGMENT_STATE
| SI_DISABLE_RENDER_COND
,
43 SI_BLIT
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
44 SI_SAVE_FRAGMENT_STATE
,
46 SI_DECOMPRESS
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
|
47 SI_DISABLE_RENDER_COND
,
49 SI_COLOR_RESOLVE
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
52 static void si_blitter_begin(struct pipe_context
*ctx
, enum si_blitter_op op
)
54 struct si_context
*sctx
= (struct si_context
*)ctx
;
56 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
57 util_blitter_save_vertex_elements(sctx
->blitter
, sctx
->vertex_elements
);
58 util_blitter_save_vertex_shader(sctx
->blitter
, sctx
->vs_shader
.cso
);
59 util_blitter_save_tessctrl_shader(sctx
->blitter
, sctx
->tcs_shader
.cso
);
60 util_blitter_save_tesseval_shader(sctx
->blitter
, sctx
->tes_shader
.cso
);
61 util_blitter_save_geometry_shader(sctx
->blitter
, sctx
->gs_shader
.cso
);
62 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
63 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
64 util_blitter_save_rasterizer(sctx
->blitter
, sctx
->queued
.named
.rasterizer
);
66 if (op
& SI_SAVE_FRAGMENT_STATE
) {
67 util_blitter_save_blend(sctx
->blitter
, sctx
->queued
.named
.blend
);
68 util_blitter_save_depth_stencil_alpha(sctx
->blitter
, sctx
->queued
.named
.dsa
);
69 util_blitter_save_stencil_ref(sctx
->blitter
, &sctx
->stencil_ref
.state
);
70 util_blitter_save_fragment_shader(sctx
->blitter
, sctx
->ps_shader
.cso
);
71 util_blitter_save_sample_mask(sctx
->blitter
, sctx
->sample_mask
.sample_mask
);
72 util_blitter_save_viewport(sctx
->blitter
, &sctx
->b
.viewports
.states
[0]);
73 util_blitter_save_scissor(sctx
->blitter
, &sctx
->b
.scissors
.states
[0]);
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 (void**)sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.sampler_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
)
89 sctx
->b
.render_cond_force_off
= true;
92 static void si_blitter_end(struct pipe_context
*ctx
)
94 struct si_context
*sctx
= (struct si_context
*)ctx
;
96 sctx
->b
.render_cond_force_off
= false;
99 static unsigned u_max_sample(struct pipe_resource
*r
)
101 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
105 si_blit_dbcb_copy(struct si_context
*sctx
,
106 struct r600_texture
*src
,
107 struct r600_texture
*dst
,
108 unsigned planes
, unsigned level_mask
,
109 unsigned first_layer
, unsigned last_layer
,
110 unsigned first_sample
, unsigned last_sample
)
112 struct pipe_surface surf_tmpl
= {{0}};
113 unsigned layer
, sample
, checked_last_layer
, max_layer
;
114 unsigned fully_copied_levels
= 0;
116 if (planes
& PIPE_MASK_Z
)
117 sctx
->dbcb_depth_copy_enabled
= true;
118 if (planes
& PIPE_MASK_S
)
119 sctx
->dbcb_stencil_copy_enabled
= true;
120 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
122 assert(sctx
->dbcb_depth_copy_enabled
|| sctx
->dbcb_stencil_copy_enabled
);
124 bool old_update_dirtiness
= sctx
->framebuffer
.do_update_surf_dirtiness
;
125 sctx
->decompression_enabled
= true;
126 sctx
->framebuffer
.do_update_surf_dirtiness
= false;
129 unsigned level
= u_bit_scan(&level_mask
);
131 /* The smaller the mipmap level, the less layers there are
132 * as far as 3D textures are concerned. */
133 max_layer
= util_max_layer(&src
->resource
.b
.b
, level
);
134 checked_last_layer
= MIN2(last_layer
, max_layer
);
136 surf_tmpl
.u
.tex
.level
= level
;
138 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
139 struct pipe_surface
*zsurf
, *cbsurf
;
141 surf_tmpl
.format
= src
->resource
.b
.b
.format
;
142 surf_tmpl
.u
.tex
.first_layer
= layer
;
143 surf_tmpl
.u
.tex
.last_layer
= layer
;
145 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &src
->resource
.b
.b
, &surf_tmpl
);
147 surf_tmpl
.format
= dst
->resource
.b
.b
.format
;
148 cbsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &dst
->resource
.b
.b
, &surf_tmpl
);
150 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
151 if (sample
!= sctx
->dbcb_copy_sample
) {
152 sctx
->dbcb_copy_sample
= sample
;
153 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
156 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
157 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
158 sctx
->custom_dsa_flush
, 1.0f
);
159 si_blitter_end(&sctx
->b
.b
);
162 pipe_surface_reference(&zsurf
, NULL
);
163 pipe_surface_reference(&cbsurf
, NULL
);
166 if (first_layer
== 0 && last_layer
>= max_layer
&&
167 first_sample
== 0 && last_sample
>= u_max_sample(&src
->resource
.b
.b
))
168 fully_copied_levels
|= 1u << level
;
171 sctx
->decompression_enabled
= false;
172 sctx
->framebuffer
.do_update_surf_dirtiness
= old_update_dirtiness
;
173 sctx
->dbcb_depth_copy_enabled
= false;
174 sctx
->dbcb_stencil_copy_enabled
= false;
175 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
177 return fully_copied_levels
;
180 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
181 struct r600_texture
*texture
,
182 struct r600_texture
*staging
,
183 unsigned first_level
, unsigned last_level
,
184 unsigned first_layer
, unsigned last_layer
,
185 unsigned first_sample
, unsigned last_sample
)
187 const struct util_format_description
*desc
;
190 assert(staging
!= NULL
&& "use si_blit_decompress_zs_in_place instead");
192 desc
= util_format_description(staging
->resource
.b
.b
.format
);
194 if (util_format_has_depth(desc
))
195 planes
|= PIPE_MASK_Z
;
196 if (util_format_has_stencil(desc
))
197 planes
|= PIPE_MASK_S
;
200 (struct si_context
*)ctx
, texture
, staging
, planes
,
201 u_bit_consecutive(first_level
, last_level
- first_level
+ 1),
202 first_layer
, last_layer
, first_sample
, last_sample
);
205 /* Helper function for si_blit_decompress_zs_in_place.
208 si_blit_decompress_zs_planes_in_place(struct si_context
*sctx
,
209 struct r600_texture
*texture
,
210 unsigned planes
, unsigned level_mask
,
211 unsigned first_layer
, unsigned last_layer
)
213 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
214 unsigned layer
, max_layer
, checked_last_layer
;
215 unsigned fully_decompressed_mask
= 0;
220 if (planes
& PIPE_MASK_S
)
221 sctx
->db_flush_stencil_inplace
= true;
222 if (planes
& PIPE_MASK_Z
)
223 sctx
->db_flush_depth_inplace
= true;
224 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
226 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
228 bool old_update_dirtiness
= sctx
->framebuffer
.do_update_surf_dirtiness
;
229 sctx
->decompression_enabled
= true;
230 sctx
->framebuffer
.do_update_surf_dirtiness
= false;
233 unsigned level
= u_bit_scan(&level_mask
);
235 surf_tmpl
.u
.tex
.level
= level
;
237 /* The smaller the mipmap level, the less layers there are
238 * as far as 3D textures are concerned. */
239 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
240 checked_last_layer
= MIN2(last_layer
, max_layer
);
242 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
243 surf_tmpl
.u
.tex
.first_layer
= layer
;
244 surf_tmpl
.u
.tex
.last_layer
= layer
;
246 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
248 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
249 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
250 sctx
->custom_dsa_flush
,
252 si_blitter_end(&sctx
->b
.b
);
254 pipe_surface_reference(&zsurf
, NULL
);
257 /* The texture will always be dirty if some layers aren't flushed.
258 * I don't think this case occurs often though. */
259 if (first_layer
== 0 && last_layer
>= max_layer
) {
260 fully_decompressed_mask
|= 1u << level
;
264 if (planes
& PIPE_MASK_Z
)
265 texture
->dirty_level_mask
&= ~fully_decompressed_mask
;
266 if (planes
& PIPE_MASK_S
)
267 texture
->stencil_dirty_level_mask
&= ~fully_decompressed_mask
;
269 sctx
->decompression_enabled
= false;
270 sctx
->framebuffer
.do_update_surf_dirtiness
= old_update_dirtiness
;
271 sctx
->db_flush_depth_inplace
= false;
272 sctx
->db_flush_stencil_inplace
= false;
273 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
276 /* Helper function of si_flush_depth_texture: decompress the given levels
277 * of Z and/or S planes in place.
280 si_blit_decompress_zs_in_place(struct si_context
*sctx
,
281 struct r600_texture
*texture
,
282 unsigned levels_z
, unsigned levels_s
,
283 unsigned first_layer
, unsigned last_layer
)
285 unsigned both
= levels_z
& levels_s
;
287 /* First, do combined Z & S decompresses for levels that need it. */
289 si_blit_decompress_zs_planes_in_place(
290 sctx
, texture
, PIPE_MASK_Z
| PIPE_MASK_S
,
292 first_layer
, last_layer
);
297 /* Now do separate Z and S decompresses. */
299 si_blit_decompress_zs_planes_in_place(
300 sctx
, texture
, PIPE_MASK_Z
,
302 first_layer
, last_layer
);
306 si_blit_decompress_zs_planes_in_place(
307 sctx
, texture
, PIPE_MASK_S
,
309 first_layer
, last_layer
);
314 si_decompress_depth(struct si_context
*sctx
,
315 struct r600_texture
*tex
,
316 unsigned required_planes
,
317 unsigned first_level
, unsigned last_level
,
318 unsigned first_layer
, unsigned last_layer
)
320 unsigned inplace_planes
= 0;
321 unsigned copy_planes
= 0;
322 unsigned level_mask
= u_bit_consecutive(first_level
, last_level
- first_level
+ 1);
323 unsigned levels_z
= 0;
324 unsigned levels_s
= 0;
326 if (required_planes
& PIPE_MASK_Z
) {
327 levels_z
= level_mask
& tex
->dirty_level_mask
;
330 if (r600_can_sample_zs(tex
, false))
331 inplace_planes
|= PIPE_MASK_Z
;
333 copy_planes
|= PIPE_MASK_Z
;
336 if (required_planes
& PIPE_MASK_S
) {
337 levels_s
= level_mask
& tex
->stencil_dirty_level_mask
;
340 if (r600_can_sample_zs(tex
, true))
341 inplace_planes
|= PIPE_MASK_S
;
343 copy_planes
|= PIPE_MASK_S
;
347 /* We may have to allocate the flushed texture here when called from
348 * si_decompress_subresource.
351 (tex
->flushed_depth_texture
||
352 r600_init_flushed_depth_texture(&sctx
->b
.b
, &tex
->resource
.b
.b
, NULL
))) {
353 struct r600_texture
*dst
= tex
->flushed_depth_texture
;
354 unsigned fully_copied_levels
;
357 assert(tex
->flushed_depth_texture
);
359 if (util_format_is_depth_and_stencil(dst
->resource
.b
.b
.format
))
360 copy_planes
= PIPE_MASK_Z
| PIPE_MASK_S
;
362 if (copy_planes
& PIPE_MASK_Z
) {
366 if (copy_planes
& PIPE_MASK_S
) {
371 fully_copied_levels
= si_blit_dbcb_copy(
372 sctx
, tex
, dst
, copy_planes
, levels
,
373 first_layer
, last_layer
,
374 0, u_max_sample(&tex
->resource
.b
.b
));
376 if (copy_planes
& PIPE_MASK_Z
)
377 tex
->dirty_level_mask
&= ~fully_copied_levels
;
378 if (copy_planes
& PIPE_MASK_S
)
379 tex
->stencil_dirty_level_mask
&= ~fully_copied_levels
;
382 if (inplace_planes
) {
383 if (!tex
->tc_compatible_htile
) {
384 si_blit_decompress_zs_in_place(
387 first_layer
, last_layer
);
390 /* Only in-place decompression needs to flush DB caches, or
391 * when we don't decompress but TC-compatible planes are dirty.
393 sctx
->b
.flags
|= SI_CONTEXT_FLUSH_AND_INV_DB
|
394 SI_CONTEXT_INV_GLOBAL_L2
|
395 SI_CONTEXT_INV_VMEM_L1
;
397 /* If we flush DB caches for TC-compatible depth, the dirty
398 * state becomes 0 for the whole mipmap tree and all planes.
399 * (there is nothing else to flush)
401 if (tex
->tc_compatible_htile
) {
402 if (r600_can_sample_zs(tex
, false))
403 tex
->dirty_level_mask
= 0;
404 if (r600_can_sample_zs(tex
, true))
405 tex
->stencil_dirty_level_mask
= 0;
411 si_decompress_sampler_depth_textures(struct si_context
*sctx
,
412 struct si_textures_info
*textures
)
415 unsigned mask
= textures
->needs_depth_decompress_mask
;
418 struct pipe_sampler_view
*view
;
419 struct si_sampler_view
*sview
;
420 struct r600_texture
*tex
;
422 i
= u_bit_scan(&mask
);
424 view
= textures
->views
.views
[i
];
426 sview
= (struct si_sampler_view
*)view
;
428 tex
= (struct r600_texture
*)view
->texture
;
429 assert(tex
->db_compatible
);
431 si_decompress_depth(sctx
, tex
,
432 sview
->is_stencil_sampler
? PIPE_MASK_S
: PIPE_MASK_Z
,
433 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
434 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
438 static void si_blit_decompress_color(struct pipe_context
*ctx
,
439 struct r600_texture
*rtex
,
440 unsigned first_level
, unsigned last_level
,
441 unsigned first_layer
, unsigned last_layer
,
442 bool need_dcc_decompress
)
444 struct si_context
*sctx
= (struct si_context
*)ctx
;
446 unsigned layer
, checked_last_layer
, max_layer
;
447 unsigned level_mask
=
448 u_bit_consecutive(first_level
, last_level
- first_level
+ 1);
450 if (!need_dcc_decompress
)
451 level_mask
&= rtex
->dirty_level_mask
;
455 if (rtex
->dcc_offset
&& need_dcc_decompress
) {
456 custom_blend
= sctx
->custom_blend_dcc_decompress
;
458 /* disable levels without DCC */
459 for (int i
= first_level
; i
<= last_level
; i
++) {
460 if (!vi_dcc_enabled(rtex
, i
))
461 level_mask
&= ~(1 << i
);
463 } else if (rtex
->fmask
.size
) {
464 custom_blend
= sctx
->custom_blend_fmask_decompress
;
466 custom_blend
= sctx
->custom_blend_eliminate_fastclear
;
469 bool old_update_dirtiness
= sctx
->framebuffer
.do_update_surf_dirtiness
;
470 sctx
->decompression_enabled
= true;
471 sctx
->framebuffer
.do_update_surf_dirtiness
= false;
474 unsigned level
= u_bit_scan(&level_mask
);
476 /* The smaller the mipmap level, the less layers there are
477 * as far as 3D textures are concerned. */
478 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
479 checked_last_layer
= MIN2(last_layer
, max_layer
);
481 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
482 struct pipe_surface
*cbsurf
, surf_tmpl
;
484 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
485 surf_tmpl
.u
.tex
.level
= level
;
486 surf_tmpl
.u
.tex
.first_layer
= layer
;
487 surf_tmpl
.u
.tex
.last_layer
= layer
;
488 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
490 si_blitter_begin(ctx
, SI_DECOMPRESS
);
491 util_blitter_custom_color(sctx
->blitter
, cbsurf
, custom_blend
);
494 pipe_surface_reference(&cbsurf
, NULL
);
497 /* The texture will always be dirty if some layers aren't flushed.
498 * I don't think this case occurs often though. */
499 if (first_layer
== 0 && last_layer
>= max_layer
) {
500 rtex
->dirty_level_mask
&= ~(1 << level
);
504 sctx
->decompression_enabled
= false;
505 sctx
->framebuffer
.do_update_surf_dirtiness
= old_update_dirtiness
;
509 si_decompress_color_texture(struct si_context
*sctx
, struct r600_texture
*tex
,
510 unsigned first_level
, unsigned last_level
)
512 /* CMASK or DCC can be discarded and we can still end up here. */
513 if (!tex
->cmask
.size
&& !tex
->fmask
.size
&& !tex
->dcc_offset
)
516 si_blit_decompress_color(&sctx
->b
.b
, tex
, first_level
, last_level
, 0,
517 util_max_layer(&tex
->resource
.b
.b
, first_level
),
522 si_decompress_sampler_color_textures(struct si_context
*sctx
,
523 struct si_textures_info
*textures
)
526 unsigned mask
= textures
->needs_color_decompress_mask
;
529 struct pipe_sampler_view
*view
;
530 struct r600_texture
*tex
;
532 i
= u_bit_scan(&mask
);
534 view
= textures
->views
.views
[i
];
537 tex
= (struct r600_texture
*)view
->texture
;
539 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.first_level
,
540 view
->u
.tex
.last_level
);
545 si_decompress_image_color_textures(struct si_context
*sctx
,
546 struct si_images_info
*images
)
549 unsigned mask
= images
->needs_color_decompress_mask
;
552 const struct pipe_image_view
*view
;
553 struct r600_texture
*tex
;
555 i
= u_bit_scan(&mask
);
557 view
= &images
->views
[i
];
558 assert(view
->resource
->target
!= PIPE_BUFFER
);
560 tex
= (struct r600_texture
*)view
->resource
;
562 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.level
,
567 static void si_check_render_feedback_texture(struct si_context
*sctx
,
568 struct r600_texture
*tex
,
569 unsigned first_level
,
571 unsigned first_layer
,
574 bool render_feedback
= false;
576 if (!tex
->dcc_offset
)
579 for (unsigned j
= 0; j
< sctx
->framebuffer
.state
.nr_cbufs
; ++j
) {
580 struct r600_surface
* surf
;
582 if (!sctx
->framebuffer
.state
.cbufs
[j
])
585 surf
= (struct r600_surface
*)sctx
->framebuffer
.state
.cbufs
[j
];
587 if (tex
== (struct r600_texture
*)surf
->base
.texture
&&
588 surf
->base
.u
.tex
.level
>= first_level
&&
589 surf
->base
.u
.tex
.level
<= last_level
&&
590 surf
->base
.u
.tex
.first_layer
<= last_layer
&&
591 surf
->base
.u
.tex
.last_layer
>= first_layer
) {
592 render_feedback
= true;
598 r600_texture_disable_dcc(&sctx
->b
, tex
);
601 static void si_check_render_feedback_textures(struct si_context
*sctx
,
602 struct si_textures_info
*textures
)
604 uint32_t mask
= textures
->views
.enabled_mask
;
607 const struct pipe_sampler_view
*view
;
608 struct r600_texture
*tex
;
610 unsigned i
= u_bit_scan(&mask
);
612 view
= textures
->views
.views
[i
];
613 if(view
->texture
->target
== PIPE_BUFFER
)
616 tex
= (struct r600_texture
*)view
->texture
;
618 si_check_render_feedback_texture(sctx
, tex
,
619 view
->u
.tex
.first_level
,
620 view
->u
.tex
.last_level
,
621 view
->u
.tex
.first_layer
,
622 view
->u
.tex
.last_layer
);
626 static void si_check_render_feedback_images(struct si_context
*sctx
,
627 struct si_images_info
*images
)
629 uint32_t mask
= images
->enabled_mask
;
632 const struct pipe_image_view
*view
;
633 struct r600_texture
*tex
;
635 unsigned i
= u_bit_scan(&mask
);
637 view
= &images
->views
[i
];
638 if (view
->resource
->target
== PIPE_BUFFER
)
641 tex
= (struct r600_texture
*)view
->resource
;
643 si_check_render_feedback_texture(sctx
, tex
,
646 view
->u
.tex
.first_layer
,
647 view
->u
.tex
.last_layer
);
651 static void si_check_render_feedback_resident_textures(struct si_context
*sctx
)
653 util_dynarray_foreach(&sctx
->resident_tex_handles
,
654 struct si_texture_handle
*, tex_handle
) {
655 struct pipe_sampler_view
*view
;
656 struct r600_texture
*tex
;
658 view
= (*tex_handle
)->view
;
659 if (view
->texture
->target
== PIPE_BUFFER
)
662 tex
= (struct r600_texture
*)view
->texture
;
664 si_check_render_feedback_texture(sctx
, tex
,
665 view
->u
.tex
.first_level
,
666 view
->u
.tex
.last_level
,
667 view
->u
.tex
.first_layer
,
668 view
->u
.tex
.last_layer
);
672 static void si_check_render_feedback_resident_images(struct si_context
*sctx
)
674 util_dynarray_foreach(&sctx
->resident_img_handles
,
675 struct si_image_handle
*, img_handle
) {
676 struct pipe_image_view
*view
;
677 struct r600_texture
*tex
;
679 view
= &(*img_handle
)->view
;
680 if (view
->resource
->target
== PIPE_BUFFER
)
683 tex
= (struct r600_texture
*)view
->resource
;
685 si_check_render_feedback_texture(sctx
, tex
,
688 view
->u
.tex
.first_layer
,
689 view
->u
.tex
.last_layer
);
693 static void si_check_render_feedback(struct si_context
*sctx
)
696 if (!sctx
->need_check_render_feedback
)
699 for (int i
= 0; i
< SI_NUM_SHADERS
; ++i
) {
700 si_check_render_feedback_images(sctx
, &sctx
->images
[i
]);
701 si_check_render_feedback_textures(sctx
, &sctx
->samplers
[i
]);
704 si_check_render_feedback_resident_images(sctx
);
705 si_check_render_feedback_resident_textures(sctx
);
707 sctx
->need_check_render_feedback
= false;
710 static void si_decompress_resident_textures(struct si_context
*sctx
)
712 util_dynarray_foreach(&sctx
->resident_tex_needs_color_decompress
,
713 struct si_texture_handle
*, tex_handle
) {
714 struct pipe_sampler_view
*view
= (*tex_handle
)->view
;
715 struct r600_texture
*tex
= (struct r600_texture
*)view
->texture
;
717 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.first_level
,
718 view
->u
.tex
.last_level
);
721 util_dynarray_foreach(&sctx
->resident_tex_needs_depth_decompress
,
722 struct si_texture_handle
*, tex_handle
) {
723 struct pipe_sampler_view
*view
= (*tex_handle
)->view
;
724 struct si_sampler_view
*sview
= (struct si_sampler_view
*)view
;
725 struct r600_texture
*tex
= (struct r600_texture
*)view
->texture
;
727 si_decompress_depth(sctx
, tex
,
728 sview
->is_stencil_sampler
? PIPE_MASK_S
: PIPE_MASK_Z
,
729 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
730 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
734 static void si_decompress_resident_images(struct si_context
*sctx
)
736 util_dynarray_foreach(&sctx
->resident_img_needs_color_decompress
,
737 struct si_image_handle
*, img_handle
) {
738 struct pipe_image_view
*view
= &(*img_handle
)->view
;
739 struct r600_texture
*tex
= (struct r600_texture
*)view
->resource
;
741 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.level
,
746 static void si_decompress_textures(struct si_context
*sctx
, unsigned shader_mask
)
748 unsigned compressed_colortex_counter
, mask
;
750 if (sctx
->blitter
->running
)
753 /* Update the compressed_colortex_mask if necessary. */
754 compressed_colortex_counter
= p_atomic_read(&sctx
->screen
->b
.compressed_colortex_counter
);
755 if (compressed_colortex_counter
!= sctx
->b
.last_compressed_colortex_counter
) {
756 sctx
->b
.last_compressed_colortex_counter
= compressed_colortex_counter
;
757 si_update_needs_color_decompress_masks(sctx
);
760 /* Decompress color & depth textures if needed. */
761 mask
= sctx
->shader_needs_decompress_mask
& shader_mask
;
763 unsigned i
= u_bit_scan(&mask
);
765 if (sctx
->samplers
[i
].needs_depth_decompress_mask
) {
766 si_decompress_sampler_depth_textures(sctx
, &sctx
->samplers
[i
]);
768 if (sctx
->samplers
[i
].needs_color_decompress_mask
) {
769 si_decompress_sampler_color_textures(sctx
, &sctx
->samplers
[i
]);
771 if (sctx
->images
[i
].needs_color_decompress_mask
) {
772 si_decompress_image_color_textures(sctx
, &sctx
->images
[i
]);
776 if (shader_mask
& u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS
)) {
777 if (sctx
->uses_bindless_samplers
)
778 si_decompress_resident_textures(sctx
);
779 if (sctx
->uses_bindless_images
)
780 si_decompress_resident_images(sctx
);
781 } else if (shader_mask
& (1 << PIPE_SHADER_COMPUTE
)) {
782 if (sctx
->cs_shader_state
.program
->uses_bindless_samplers
)
783 si_decompress_resident_textures(sctx
);
784 if (sctx
->cs_shader_state
.program
->uses_bindless_images
)
785 si_decompress_resident_images(sctx
);
788 si_check_render_feedback(sctx
);
791 void si_decompress_graphics_textures(struct si_context
*sctx
)
793 si_decompress_textures(sctx
, u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS
));
796 void si_decompress_compute_textures(struct si_context
*sctx
)
798 si_decompress_textures(sctx
, 1 << PIPE_SHADER_COMPUTE
);
801 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
802 const union pipe_color_union
*color
,
803 double depth
, unsigned stencil
)
805 struct si_context
*sctx
= (struct si_context
*)ctx
;
806 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
807 struct pipe_surface
*zsbuf
= fb
->zsbuf
;
808 struct r600_texture
*zstex
=
809 zsbuf
? (struct r600_texture
*)zsbuf
->texture
: NULL
;
811 if (buffers
& PIPE_CLEAR_COLOR
) {
812 evergreen_do_fast_color_clear(&sctx
->b
, fb
,
813 &sctx
->framebuffer
.atom
, &buffers
,
814 &sctx
->framebuffer
.dirty_cbufs
,
817 return; /* all buffers have been fast cleared */
820 if (buffers
& PIPE_CLEAR_COLOR
) {
823 /* These buffers cannot use fast clear, make sure to disable expansion. */
824 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
825 struct r600_texture
*tex
;
827 /* If not clearing this buffer, skip. */
828 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
834 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
835 if (tex
->fmask
.size
== 0)
836 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
840 if (zstex
&& zstex
->htile_offset
&&
841 zsbuf
->u
.tex
.level
== 0 &&
842 zsbuf
->u
.tex
.first_layer
== 0 &&
843 zsbuf
->u
.tex
.last_layer
== util_max_layer(&zstex
->resource
.b
.b
, 0)) {
844 /* TC-compatible HTILE only supports depth clears to 0 or 1. */
845 if (buffers
& PIPE_CLEAR_DEPTH
&&
846 (!zstex
->tc_compatible_htile
||
847 depth
== 0 || depth
== 1)) {
848 /* Need to disable EXPCLEAR temporarily if clearing
850 if (!zstex
->depth_cleared
|| zstex
->depth_clear_value
!= depth
) {
851 sctx
->db_depth_disable_expclear
= true;
854 zstex
->depth_clear_value
= depth
;
855 sctx
->framebuffer
.dirty_zsbuf
= true;
856 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_DEPTH_CLEAR */
857 sctx
->db_depth_clear
= true;
858 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
861 /* TC-compatible HTILE only supports stencil clears to 0. */
862 if (buffers
& PIPE_CLEAR_STENCIL
&&
863 (!zstex
->tc_compatible_htile
|| stencil
== 0)) {
866 /* Need to disable EXPCLEAR temporarily if clearing
868 if (!zstex
->stencil_cleared
|| zstex
->stencil_clear_value
!= stencil
) {
869 sctx
->db_stencil_disable_expclear
= true;
872 zstex
->stencil_clear_value
= stencil
;
873 sctx
->framebuffer
.dirty_zsbuf
= true;
874 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_STENCIL_CLEAR */
875 sctx
->db_stencil_clear
= true;
876 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
880 si_blitter_begin(ctx
, SI_CLEAR
);
881 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
882 util_framebuffer_get_num_layers(fb
),
883 buffers
, color
, depth
, stencil
);
886 if (sctx
->db_depth_clear
) {
887 sctx
->db_depth_clear
= false;
888 sctx
->db_depth_disable_expclear
= false;
889 zstex
->depth_cleared
= true;
890 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
893 if (sctx
->db_stencil_clear
) {
894 sctx
->db_stencil_clear
= false;
895 sctx
->db_stencil_disable_expclear
= false;
896 zstex
->stencil_cleared
= true;
897 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
901 static void si_clear_render_target(struct pipe_context
*ctx
,
902 struct pipe_surface
*dst
,
903 const union pipe_color_union
*color
,
904 unsigned dstx
, unsigned dsty
,
905 unsigned width
, unsigned height
,
906 bool render_condition_enabled
)
908 struct si_context
*sctx
= (struct si_context
*)ctx
;
910 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
|
911 (render_condition_enabled
? 0 : SI_DISABLE_RENDER_COND
));
912 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
913 dstx
, dsty
, width
, height
);
917 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
918 struct pipe_surface
*dst
,
919 unsigned clear_flags
,
922 unsigned dstx
, unsigned dsty
,
923 unsigned width
, unsigned height
,
924 bool render_condition_enabled
)
926 struct si_context
*sctx
= (struct si_context
*)ctx
;
928 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
|
929 (render_condition_enabled
? 0 : SI_DISABLE_RENDER_COND
));
930 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
931 dstx
, dsty
, width
, height
);
935 /* Helper for decompressing a portion of a color or depth resource before
936 * blitting if any decompression is needed.
937 * The driver doesn't decompress resources automatically while u_blitter is
939 static void si_decompress_subresource(struct pipe_context
*ctx
,
940 struct pipe_resource
*tex
,
941 unsigned planes
, unsigned level
,
942 unsigned first_layer
, unsigned last_layer
)
944 struct si_context
*sctx
= (struct si_context
*)ctx
;
945 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
947 if (rtex
->db_compatible
) {
948 planes
&= PIPE_MASK_Z
| PIPE_MASK_S
;
950 if (!(rtex
->surface
.flags
& RADEON_SURF_SBUFFER
))
951 planes
&= ~PIPE_MASK_S
;
953 si_decompress_depth(sctx
, rtex
, planes
,
955 first_layer
, last_layer
);
956 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
|| rtex
->dcc_offset
) {
957 si_blit_decompress_color(ctx
, rtex
, level
, level
,
958 first_layer
, last_layer
, false);
962 struct texture_orig_info
{
972 void si_resource_copy_region(struct pipe_context
*ctx
,
973 struct pipe_resource
*dst
,
975 unsigned dstx
, unsigned dsty
, unsigned dstz
,
976 struct pipe_resource
*src
,
978 const struct pipe_box
*src_box
)
980 struct si_context
*sctx
= (struct si_context
*)ctx
;
981 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
982 struct pipe_surface
*dst_view
, dst_templ
;
983 struct pipe_sampler_view src_templ
, *src_view
;
984 unsigned dst_width
, dst_height
, src_width0
, src_height0
;
985 unsigned dst_width0
, dst_height0
, src_force_level
= 0;
986 struct pipe_box sbox
, dstbox
;
988 /* Handle buffers first. */
989 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
990 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
, 0);
994 assert(u_max_sample(dst
) == u_max_sample(src
));
996 /* The driver doesn't decompress resources automatically while
997 * u_blitter is rendering. */
998 si_decompress_subresource(ctx
, src
, PIPE_MASK_RGBAZS
, src_level
,
999 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
1001 dst_width
= u_minify(dst
->width0
, dst_level
);
1002 dst_height
= u_minify(dst
->height0
, dst_level
);
1003 dst_width0
= dst
->width0
;
1004 dst_height0
= dst
->height0
;
1005 src_width0
= src
->width0
;
1006 src_height0
= src
->height0
;
1008 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
1009 util_blitter_default_src_texture(sctx
->blitter
, &src_templ
, src
, src_level
);
1011 if (util_format_is_compressed(src
->format
) ||
1012 util_format_is_compressed(dst
->format
)) {
1013 unsigned blocksize
= rsrc
->surface
.bpe
;
1016 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
1018 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
1019 dst_templ
.format
= src_templ
.format
;
1021 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
1022 dst_height
= util_format_get_nblocksy(dst
->format
, dst_height
);
1023 dst_width0
= util_format_get_nblocksx(dst
->format
, dst_width0
);
1024 dst_height0
= util_format_get_nblocksy(dst
->format
, dst_height0
);
1025 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
1026 src_height0
= util_format_get_nblocksy(src
->format
, src_height0
);
1028 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
1029 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
1031 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
1032 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
1033 sbox
.z
= src_box
->z
;
1034 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
1035 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
1036 sbox
.depth
= src_box
->depth
;
1039 src_force_level
= src_level
;
1040 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
)) {
1041 if (util_format_is_subsampled_422(src
->format
)) {
1042 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
1043 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
1045 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
1046 dst_width0
= util_format_get_nblocksx(dst
->format
, dst_width0
);
1047 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
1049 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
1052 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
1053 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
1056 unsigned blocksize
= rsrc
->surface
.bpe
;
1058 switch (blocksize
) {
1060 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
1061 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
1064 dst_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
1065 src_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
1068 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
1069 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
1072 dst_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
1073 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
1076 dst_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
1077 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
1080 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
1081 util_format_short_name(src
->format
), blocksize
);
1087 /* SNORM8 blitting has precision issues on some chips. Use the SINT
1088 * equivalent instead, which doesn't force DCC decompression.
1089 * Note that some chips avoid this issue by using SDMA.
1091 if (util_format_is_snorm8(dst_templ
.format
)) {
1092 switch (dst_templ
.format
) {
1093 case PIPE_FORMAT_R8_SNORM
:
1094 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8_SINT
;
1096 case PIPE_FORMAT_R8G8_SNORM
:
1097 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8G8_SINT
;
1099 case PIPE_FORMAT_R8G8B8X8_SNORM
:
1100 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8G8B8X8_SINT
;
1102 case PIPE_FORMAT_R8G8B8A8_SNORM
:
1103 /* There are no SINT variants for ABGR and XBGR, so we have to use RGBA. */
1104 case PIPE_FORMAT_A8B8G8R8_SNORM
:
1105 case PIPE_FORMAT_X8B8G8R8_SNORM
:
1106 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8G8B8A8_SINT
;
1108 case PIPE_FORMAT_A8_SNORM
:
1109 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_A8_SINT
;
1111 case PIPE_FORMAT_L8_SNORM
:
1112 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_L8_SINT
;
1114 case PIPE_FORMAT_L8A8_SNORM
:
1115 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_L8A8_SINT
;
1117 case PIPE_FORMAT_I8_SNORM
:
1118 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_I8_SINT
;
1120 default:; /* fall through */
1124 vi_disable_dcc_if_incompatible_format(&sctx
->b
, dst
, dst_level
,
1126 vi_disable_dcc_if_incompatible_format(&sctx
->b
, src
, src_level
,
1129 /* Initialize the surface. */
1130 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
1131 dst_width0
, dst_height0
,
1132 dst_width
, dst_height
);
1134 /* Initialize the sampler view. */
1135 src_view
= si_create_sampler_view_custom(ctx
, src
, &src_templ
,
1136 src_width0
, src_height0
,
1139 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
1140 abs(src_box
->depth
), &dstbox
);
1143 si_blitter_begin(ctx
, SI_COPY
);
1144 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
1145 src_view
, src_box
, src_width0
, src_height0
,
1146 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
1148 si_blitter_end(ctx
);
1150 pipe_surface_reference(&dst_view
, NULL
);
1151 pipe_sampler_view_reference(&src_view
, NULL
);
1154 static void si_do_CB_resolve(struct si_context
*sctx
,
1155 const struct pipe_blit_info
*info
,
1156 struct pipe_resource
*dst
,
1157 unsigned dst_level
, unsigned dst_z
,
1158 enum pipe_format format
)
1160 si_blitter_begin(&sctx
->b
.b
, SI_COLOR_RESOLVE
|
1161 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1162 util_blitter_custom_resolve_color(sctx
->blitter
, dst
, dst_level
, dst_z
,
1163 info
->src
.resource
, info
->src
.box
.z
,
1164 ~0, sctx
->custom_blend_resolve
,
1166 si_blitter_end(&sctx
->b
.b
);
1169 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
1170 const struct pipe_blit_info
*info
)
1172 struct si_context
*sctx
= (struct si_context
*)ctx
;
1173 struct r600_texture
*src
= (struct r600_texture
*)info
->src
.resource
;
1174 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
1175 MAYBE_UNUSED
struct r600_texture
*rtmp
;
1176 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
1177 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
1178 enum pipe_format format
= info
->src
.format
;
1179 struct pipe_resource
*tmp
, templ
;
1180 struct pipe_blit_info blit
;
1182 /* Check basic requirements for hw resolve. */
1183 if (!(info
->src
.resource
->nr_samples
> 1 &&
1184 info
->dst
.resource
->nr_samples
<= 1 &&
1185 !util_format_is_pure_integer(format
) &&
1186 !util_format_is_depth_or_stencil(format
) &&
1187 util_max_layer(info
->src
.resource
, 0) == 0))
1190 /* Hardware MSAA resolve doesn't work if SPI format = NORM16_ABGR and
1191 * the format is R16G16. Use R16A16, which does work.
1193 if (format
== PIPE_FORMAT_R16G16_UNORM
)
1194 format
= PIPE_FORMAT_R16A16_UNORM
;
1195 if (format
== PIPE_FORMAT_R16G16_SNORM
)
1196 format
= PIPE_FORMAT_R16A16_SNORM
;
1198 /* Check the remaining requirements for hw resolve. */
1199 if (util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
1200 !info
->scissor_enable
&&
1201 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
1202 util_is_format_compatible(util_format_description(info
->src
.format
),
1203 util_format_description(info
->dst
.format
)) &&
1204 dst_width
== info
->src
.resource
->width0
&&
1205 dst_height
== info
->src
.resource
->height0
&&
1206 info
->dst
.box
.x
== 0 &&
1207 info
->dst
.box
.y
== 0 &&
1208 info
->dst
.box
.width
== dst_width
&&
1209 info
->dst
.box
.height
== dst_height
&&
1210 info
->dst
.box
.depth
== 1 &&
1211 info
->src
.box
.x
== 0 &&
1212 info
->src
.box
.y
== 0 &&
1213 info
->src
.box
.width
== dst_width
&&
1214 info
->src
.box
.height
== dst_height
&&
1215 info
->src
.box
.depth
== 1 &&
1216 !dst
->surface
.is_linear
&&
1217 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
)) { /* dst cannot be fast-cleared */
1218 /* Check the last constraint. */
1219 if (src
->surface
.micro_tile_mode
!= dst
->surface
.micro_tile_mode
) {
1220 /* The next fast clear will switch to this mode to
1221 * get direct hw resolve next time if the mode is
1224 src
->last_msaa_resolve_target_micro_mode
=
1225 dst
->surface
.micro_tile_mode
;
1226 goto resolve_to_temp
;
1229 /* Resolving into a surface with DCC is unsupported. Since
1230 * it's being overwritten anyway, clear it to uncompressed.
1231 * This is still the fastest codepath even with this clear.
1233 if (vi_dcc_enabled(dst
, info
->dst
.level
)) {
1234 /* TODO: Implement per-level DCC clears for GFX9. */
1235 if (sctx
->b
.chip_class
>= GFX9
&&
1236 info
->dst
.resource
->last_level
!= 0)
1237 goto resolve_to_temp
;
1239 vi_dcc_clear_level(&sctx
->b
, dst
, info
->dst
.level
,
1241 dst
->dirty_level_mask
&= ~(1 << info
->dst
.level
);
1244 /* Resolve directly from src to dst. */
1245 si_do_CB_resolve(sctx
, info
, info
->dst
.resource
,
1246 info
->dst
.level
, info
->dst
.box
.z
, format
);
1251 /* Shader-based resolve is VERY SLOW. Instead, resolve into
1252 * a temporary texture and blit.
1254 memset(&templ
, 0, sizeof(templ
));
1255 templ
.target
= PIPE_TEXTURE_2D
;
1256 templ
.format
= info
->src
.resource
->format
;
1257 templ
.width0
= info
->src
.resource
->width0
;
1258 templ
.height0
= info
->src
.resource
->height0
;
1260 templ
.array_size
= 1;
1261 templ
.usage
= PIPE_USAGE_DEFAULT
;
1262 templ
.flags
= R600_RESOURCE_FLAG_FORCE_TILING
|
1263 R600_RESOURCE_FLAG_DISABLE_DCC
;
1265 /* The src and dst microtile modes must be the same. */
1266 if (src
->surface
.micro_tile_mode
== RADEON_MICRO_MODE_DISPLAY
)
1267 templ
.bind
= PIPE_BIND_SCANOUT
;
1271 tmp
= ctx
->screen
->resource_create(ctx
->screen
, &templ
);
1274 rtmp
= (struct r600_texture
*)tmp
;
1276 assert(!rtmp
->surface
.is_linear
);
1277 assert(src
->surface
.micro_tile_mode
== rtmp
->surface
.micro_tile_mode
);
1280 si_do_CB_resolve(sctx
, info
, tmp
, 0, 0, format
);
1284 blit
.src
.resource
= tmp
;
1287 si_blitter_begin(ctx
, SI_BLIT
|
1288 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1289 util_blitter_blit(sctx
->blitter
, &blit
);
1290 si_blitter_end(ctx
);
1292 pipe_resource_reference(&tmp
, NULL
);
1296 static void si_blit(struct pipe_context
*ctx
,
1297 const struct pipe_blit_info
*info
)
1299 struct si_context
*sctx
= (struct si_context
*)ctx
;
1300 struct r600_texture
*rdst
= (struct r600_texture
*)info
->dst
.resource
;
1302 if (do_hardware_msaa_resolve(ctx
, info
)) {
1306 /* Using SDMA for copying to a linear texture in GTT is much faster.
1307 * This improves DRI PRIME performance.
1309 * resource_copy_region can't do this yet, because dma_copy calls it
1310 * on failure (recursion).
1312 if (rdst
->surface
.is_linear
&&
1314 util_can_blit_via_copy_region(info
, false)) {
1315 sctx
->b
.dma_copy(ctx
, info
->dst
.resource
, info
->dst
.level
,
1316 info
->dst
.box
.x
, info
->dst
.box
.y
,
1318 info
->src
.resource
, info
->src
.level
,
1323 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
1325 /* The driver doesn't decompress resources automatically while
1326 * u_blitter is rendering. */
1327 vi_disable_dcc_if_incompatible_format(&sctx
->b
, info
->src
.resource
,
1330 vi_disable_dcc_if_incompatible_format(&sctx
->b
, info
->dst
.resource
,
1333 si_decompress_subresource(ctx
, info
->src
.resource
, info
->mask
,
1336 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
1338 if (sctx
->screen
->b
.debug_flags
& DBG_FORCE_DMA
&&
1339 util_try_blit_via_copy_region(ctx
, info
))
1342 si_blitter_begin(ctx
, SI_BLIT
|
1343 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1344 util_blitter_blit(sctx
->blitter
, info
);
1345 si_blitter_end(ctx
);
1348 static boolean
si_generate_mipmap(struct pipe_context
*ctx
,
1349 struct pipe_resource
*tex
,
1350 enum pipe_format format
,
1351 unsigned base_level
, unsigned last_level
,
1352 unsigned first_layer
, unsigned last_layer
)
1354 struct si_context
*sctx
= (struct si_context
*)ctx
;
1355 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
1357 if (!util_blitter_is_copy_supported(sctx
->blitter
, tex
, tex
))
1360 /* The driver doesn't decompress resources automatically while
1361 * u_blitter is rendering. */
1362 vi_disable_dcc_if_incompatible_format(&sctx
->b
, tex
, base_level
,
1364 si_decompress_subresource(ctx
, tex
, PIPE_MASK_RGBAZS
,
1365 base_level
, first_layer
, last_layer
);
1367 /* Clear dirty_level_mask for the levels that will be overwritten. */
1368 assert(base_level
< last_level
);
1369 rtex
->dirty_level_mask
&= ~u_bit_consecutive(base_level
+ 1,
1370 last_level
- base_level
);
1372 sctx
->generate_mipmap_for_depth
= rtex
->is_depth
;
1374 si_blitter_begin(ctx
, SI_BLIT
| SI_DISABLE_RENDER_COND
);
1375 util_blitter_generate_mipmap(sctx
->blitter
, tex
, format
,
1376 base_level
, last_level
,
1377 first_layer
, last_layer
);
1378 si_blitter_end(ctx
);
1380 sctx
->generate_mipmap_for_depth
= false;
1384 static void si_flush_resource(struct pipe_context
*ctx
,
1385 struct pipe_resource
*res
)
1387 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
1389 assert(res
->target
!= PIPE_BUFFER
);
1390 assert(!rtex
->dcc_separate_buffer
|| rtex
->dcc_gather_statistics
);
1392 /* st/dri calls flush twice per frame (not a bug), this prevents double
1394 if (rtex
->dcc_separate_buffer
&& !rtex
->separate_dcc_dirty
)
1397 if (!rtex
->is_depth
&& (rtex
->cmask
.size
|| rtex
->dcc_offset
)) {
1398 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
1399 0, util_max_layer(res
, 0),
1400 rtex
->dcc_separate_buffer
!= NULL
);
1403 /* Always do the analysis even if DCC is disabled at the moment. */
1404 if (rtex
->dcc_gather_statistics
&& rtex
->separate_dcc_dirty
) {
1405 rtex
->separate_dcc_dirty
= false;
1406 vi_separate_dcc_process_and_reset_stats(ctx
, rtex
);
1410 static void si_decompress_dcc(struct pipe_context
*ctx
,
1411 struct r600_texture
*rtex
)
1413 if (!rtex
->dcc_offset
)
1416 si_blit_decompress_color(ctx
, rtex
, 0, rtex
->resource
.b
.b
.last_level
,
1417 0, util_max_layer(&rtex
->resource
.b
.b
, 0),
1421 static void si_pipe_clear_buffer(struct pipe_context
*ctx
,
1422 struct pipe_resource
*dst
,
1423 unsigned offset
, unsigned size
,
1424 const void *clear_value_ptr
,
1425 int clear_value_size
)
1427 struct si_context
*sctx
= (struct si_context
*)ctx
;
1428 uint32_t dword_value
;
1431 assert(offset
% clear_value_size
== 0);
1432 assert(size
% clear_value_size
== 0);
1434 if (clear_value_size
> 4) {
1435 const uint32_t *u32
= clear_value_ptr
;
1436 bool clear_dword_duplicated
= true;
1438 /* See if we can lower large fills to dword fills. */
1439 for (i
= 1; i
< clear_value_size
/ 4; i
++)
1440 if (u32
[0] != u32
[i
]) {
1441 clear_dword_duplicated
= false;
1445 if (!clear_dword_duplicated
) {
1446 /* Use transform feedback for 64-bit, 96-bit, and
1449 union pipe_color_union clear_value
;
1451 memcpy(&clear_value
, clear_value_ptr
, clear_value_size
);
1452 si_blitter_begin(ctx
, SI_DISABLE_RENDER_COND
);
1453 util_blitter_clear_buffer(sctx
->blitter
, dst
, offset
,
1454 size
, clear_value_size
/ 4,
1456 si_blitter_end(ctx
);
1461 /* Expand the clear value to a dword. */
1462 switch (clear_value_size
) {
1464 dword_value
= *(uint8_t*)clear_value_ptr
;
1465 dword_value
|= (dword_value
<< 8) |
1466 (dword_value
<< 16) |
1467 (dword_value
<< 24);
1470 dword_value
= *(uint16_t*)clear_value_ptr
;
1471 dword_value
|= dword_value
<< 16;
1474 dword_value
= *(uint32_t*)clear_value_ptr
;
1477 sctx
->b
.clear_buffer(ctx
, dst
, offset
, size
, dword_value
,
1478 R600_COHERENCY_SHADER
);
1481 void si_init_blit_functions(struct si_context
*sctx
)
1483 sctx
->b
.b
.clear
= si_clear
;
1484 sctx
->b
.b
.clear_buffer
= si_pipe_clear_buffer
;
1485 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
1486 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
1487 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
1488 sctx
->b
.b
.blit
= si_blit
;
1489 sctx
->b
.b
.flush_resource
= si_flush_resource
;
1490 sctx
->b
.b
.generate_mipmap
= si_generate_mipmap
;
1491 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;
1492 sctx
->b
.decompress_dcc
= si_decompress_dcc
;