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_log.h"
28 #include "util/u_surface.h"
30 enum si_blitter_op
/* bitmask */
33 SI_SAVE_FRAMEBUFFER
= 2,
34 SI_SAVE_FRAGMENT_STATE
= 4,
35 SI_DISABLE_RENDER_COND
= 8,
37 SI_CLEAR
= SI_SAVE_FRAGMENT_STATE
,
39 SI_CLEAR_SURFACE
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
,
41 SI_COPY
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
42 SI_SAVE_FRAGMENT_STATE
| SI_DISABLE_RENDER_COND
,
44 SI_BLIT
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
45 SI_SAVE_FRAGMENT_STATE
,
47 SI_DECOMPRESS
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
|
48 SI_DISABLE_RENDER_COND
,
50 SI_COLOR_RESOLVE
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
53 static void si_blitter_begin(struct pipe_context
*ctx
, enum si_blitter_op op
)
55 struct si_context
*sctx
= (struct si_context
*)ctx
;
57 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
58 util_blitter_save_vertex_elements(sctx
->blitter
, sctx
->vertex_elements
);
59 util_blitter_save_vertex_shader(sctx
->blitter
, sctx
->vs_shader
.cso
);
60 util_blitter_save_tessctrl_shader(sctx
->blitter
, sctx
->tcs_shader
.cso
);
61 util_blitter_save_tesseval_shader(sctx
->blitter
, sctx
->tes_shader
.cso
);
62 util_blitter_save_geometry_shader(sctx
->blitter
, sctx
->gs_shader
.cso
);
63 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
64 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
65 util_blitter_save_rasterizer(sctx
->blitter
, sctx
->queued
.named
.rasterizer
);
67 if (op
& SI_SAVE_FRAGMENT_STATE
) {
68 util_blitter_save_blend(sctx
->blitter
, sctx
->queued
.named
.blend
);
69 util_blitter_save_depth_stencil_alpha(sctx
->blitter
, sctx
->queued
.named
.dsa
);
70 util_blitter_save_stencil_ref(sctx
->blitter
, &sctx
->stencil_ref
.state
);
71 util_blitter_save_fragment_shader(sctx
->blitter
, sctx
->ps_shader
.cso
);
72 util_blitter_save_sample_mask(sctx
->blitter
, sctx
->sample_mask
.sample_mask
);
73 util_blitter_save_viewport(sctx
->blitter
, &sctx
->b
.viewports
.states
[0]);
74 util_blitter_save_scissor(sctx
->blitter
, &sctx
->b
.scissors
.states
[0]);
77 if (op
& SI_SAVE_FRAMEBUFFER
)
78 util_blitter_save_framebuffer(sctx
->blitter
, &sctx
->framebuffer
.state
);
80 if (op
& SI_SAVE_TEXTURES
) {
81 util_blitter_save_fragment_sampler_states(
83 (void**)sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.sampler_states
);
85 util_blitter_save_fragment_sampler_views(sctx
->blitter
, 2,
86 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
89 if (op
& SI_DISABLE_RENDER_COND
)
90 sctx
->b
.render_cond_force_off
= true;
93 static void si_blitter_end(struct pipe_context
*ctx
)
95 struct si_context
*sctx
= (struct si_context
*)ctx
;
97 sctx
->b
.render_cond_force_off
= false;
100 static unsigned u_max_sample(struct pipe_resource
*r
)
102 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
106 si_blit_dbcb_copy(struct si_context
*sctx
,
107 struct r600_texture
*src
,
108 struct r600_texture
*dst
,
109 unsigned planes
, unsigned level_mask
,
110 unsigned first_layer
, unsigned last_layer
,
111 unsigned first_sample
, unsigned last_sample
)
113 struct pipe_surface surf_tmpl
= {{0}};
114 unsigned layer
, sample
, checked_last_layer
, max_layer
;
115 unsigned fully_copied_levels
= 0;
117 if (planes
& PIPE_MASK_Z
)
118 sctx
->dbcb_depth_copy_enabled
= true;
119 if (planes
& PIPE_MASK_S
)
120 sctx
->dbcb_stencil_copy_enabled
= true;
121 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
123 assert(sctx
->dbcb_depth_copy_enabled
|| sctx
->dbcb_stencil_copy_enabled
);
125 sctx
->decompression_enabled
= true;
128 unsigned level
= u_bit_scan(&level_mask
);
130 /* The smaller the mipmap level, the less layers there are
131 * as far as 3D textures are concerned. */
132 max_layer
= util_max_layer(&src
->resource
.b
.b
, level
);
133 checked_last_layer
= MIN2(last_layer
, max_layer
);
135 surf_tmpl
.u
.tex
.level
= level
;
137 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
138 struct pipe_surface
*zsurf
, *cbsurf
;
140 surf_tmpl
.format
= src
->resource
.b
.b
.format
;
141 surf_tmpl
.u
.tex
.first_layer
= layer
;
142 surf_tmpl
.u
.tex
.last_layer
= layer
;
144 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &src
->resource
.b
.b
, &surf_tmpl
);
146 surf_tmpl
.format
= dst
->resource
.b
.b
.format
;
147 cbsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &dst
->resource
.b
.b
, &surf_tmpl
);
149 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
150 if (sample
!= sctx
->dbcb_copy_sample
) {
151 sctx
->dbcb_copy_sample
= sample
;
152 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
155 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
156 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
157 sctx
->custom_dsa_flush
, 1.0f
);
158 si_blitter_end(&sctx
->b
.b
);
161 pipe_surface_reference(&zsurf
, NULL
);
162 pipe_surface_reference(&cbsurf
, NULL
);
165 if (first_layer
== 0 && last_layer
>= max_layer
&&
166 first_sample
== 0 && last_sample
>= u_max_sample(&src
->resource
.b
.b
))
167 fully_copied_levels
|= 1u << level
;
170 sctx
->decompression_enabled
= false;
171 sctx
->dbcb_depth_copy_enabled
= false;
172 sctx
->dbcb_stencil_copy_enabled
= false;
173 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
175 return fully_copied_levels
;
178 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
179 struct r600_texture
*texture
,
180 struct r600_texture
*staging
,
181 unsigned first_level
, unsigned last_level
,
182 unsigned first_layer
, unsigned last_layer
,
183 unsigned first_sample
, unsigned last_sample
)
185 const struct util_format_description
*desc
;
188 assert(staging
!= NULL
&& "use si_blit_decompress_zs_in_place instead");
190 desc
= util_format_description(staging
->resource
.b
.b
.format
);
192 if (util_format_has_depth(desc
))
193 planes
|= PIPE_MASK_Z
;
194 if (util_format_has_stencil(desc
))
195 planes
|= PIPE_MASK_S
;
198 (struct si_context
*)ctx
, texture
, staging
, planes
,
199 u_bit_consecutive(first_level
, last_level
- first_level
+ 1),
200 first_layer
, last_layer
, first_sample
, last_sample
);
203 /* Helper function for si_blit_decompress_zs_in_place.
206 si_blit_decompress_zs_planes_in_place(struct si_context
*sctx
,
207 struct r600_texture
*texture
,
208 unsigned planes
, unsigned level_mask
,
209 unsigned first_layer
, unsigned last_layer
)
211 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
212 unsigned layer
, max_layer
, checked_last_layer
;
213 unsigned fully_decompressed_mask
= 0;
218 if (planes
& PIPE_MASK_S
)
219 sctx
->db_flush_stencil_inplace
= true;
220 if (planes
& PIPE_MASK_Z
)
221 sctx
->db_flush_depth_inplace
= true;
222 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
224 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
226 sctx
->decompression_enabled
= true;
229 unsigned level
= u_bit_scan(&level_mask
);
231 surf_tmpl
.u
.tex
.level
= level
;
233 /* The smaller the mipmap level, the less layers there are
234 * as far as 3D textures are concerned. */
235 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
236 checked_last_layer
= MIN2(last_layer
, max_layer
);
238 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
239 surf_tmpl
.u
.tex
.first_layer
= layer
;
240 surf_tmpl
.u
.tex
.last_layer
= layer
;
242 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
244 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
245 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
246 sctx
->custom_dsa_flush
,
248 si_blitter_end(&sctx
->b
.b
);
250 pipe_surface_reference(&zsurf
, NULL
);
253 /* The texture will always be dirty if some layers aren't flushed.
254 * I don't think this case occurs often though. */
255 if (first_layer
== 0 && last_layer
>= max_layer
) {
256 fully_decompressed_mask
|= 1u << level
;
260 if (planes
& PIPE_MASK_Z
)
261 texture
->dirty_level_mask
&= ~fully_decompressed_mask
;
262 if (planes
& PIPE_MASK_S
)
263 texture
->stencil_dirty_level_mask
&= ~fully_decompressed_mask
;
265 sctx
->decompression_enabled
= false;
266 sctx
->db_flush_depth_inplace
= false;
267 sctx
->db_flush_stencil_inplace
= false;
268 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
271 /* Helper function of si_flush_depth_texture: decompress the given levels
272 * of Z and/or S planes in place.
275 si_blit_decompress_zs_in_place(struct si_context
*sctx
,
276 struct r600_texture
*texture
,
277 unsigned levels_z
, unsigned levels_s
,
278 unsigned first_layer
, unsigned last_layer
)
280 unsigned both
= levels_z
& levels_s
;
282 /* First, do combined Z & S decompresses for levels that need it. */
284 si_blit_decompress_zs_planes_in_place(
285 sctx
, texture
, PIPE_MASK_Z
| PIPE_MASK_S
,
287 first_layer
, last_layer
);
292 /* Now do separate Z and S decompresses. */
294 si_blit_decompress_zs_planes_in_place(
295 sctx
, texture
, PIPE_MASK_Z
,
297 first_layer
, last_layer
);
301 si_blit_decompress_zs_planes_in_place(
302 sctx
, texture
, PIPE_MASK_S
,
304 first_layer
, last_layer
);
309 si_decompress_depth(struct si_context
*sctx
,
310 struct r600_texture
*tex
,
311 unsigned required_planes
,
312 unsigned first_level
, unsigned last_level
,
313 unsigned first_layer
, unsigned last_layer
)
315 unsigned inplace_planes
= 0;
316 unsigned copy_planes
= 0;
317 unsigned level_mask
= u_bit_consecutive(first_level
, last_level
- first_level
+ 1);
318 unsigned levels_z
= 0;
319 unsigned levels_s
= 0;
321 if (required_planes
& PIPE_MASK_Z
) {
322 levels_z
= level_mask
& tex
->dirty_level_mask
;
325 if (r600_can_sample_zs(tex
, false))
326 inplace_planes
|= PIPE_MASK_Z
;
328 copy_planes
|= PIPE_MASK_Z
;
331 if (required_planes
& PIPE_MASK_S
) {
332 levels_s
= level_mask
& tex
->stencil_dirty_level_mask
;
335 if (r600_can_sample_zs(tex
, true))
336 inplace_planes
|= PIPE_MASK_S
;
338 copy_planes
|= PIPE_MASK_S
;
342 if (unlikely(sctx
->b
.log
))
343 u_log_printf(sctx
->b
.log
,
344 "\n------------------------------------------------\n"
345 "Decompress Depth (levels %u - %u, levels Z: 0x%x S: 0x%x)\n\n",
346 first_level
, last_level
, levels_z
, levels_s
);
348 /* We may have to allocate the flushed texture here when called from
349 * si_decompress_subresource.
352 (tex
->flushed_depth_texture
||
353 r600_init_flushed_depth_texture(&sctx
->b
.b
, &tex
->resource
.b
.b
, NULL
))) {
354 struct r600_texture
*dst
= tex
->flushed_depth_texture
;
355 unsigned fully_copied_levels
;
358 assert(tex
->flushed_depth_texture
);
360 if (util_format_is_depth_and_stencil(dst
->resource
.b
.b
.format
))
361 copy_planes
= PIPE_MASK_Z
| PIPE_MASK_S
;
363 if (copy_planes
& PIPE_MASK_Z
) {
367 if (copy_planes
& PIPE_MASK_S
) {
372 fully_copied_levels
= si_blit_dbcb_copy(
373 sctx
, tex
, dst
, copy_planes
, levels
,
374 first_layer
, last_layer
,
375 0, u_max_sample(&tex
->resource
.b
.b
));
377 if (copy_planes
& PIPE_MASK_Z
)
378 tex
->dirty_level_mask
&= ~fully_copied_levels
;
379 if (copy_planes
& PIPE_MASK_S
)
380 tex
->stencil_dirty_level_mask
&= ~fully_copied_levels
;
383 if (inplace_planes
) {
384 bool tc_compat_htile
= vi_tc_compat_htile_enabled(tex
, first_level
);
386 if (!tc_compat_htile
) {
387 si_blit_decompress_zs_in_place(
390 first_layer
, last_layer
);
393 /* Only in-place decompression needs to flush DB caches, or
394 * when we don't decompress but TC-compatible planes are dirty.
396 si_make_DB_shader_coherent(sctx
, tex
->resource
.b
.b
.nr_samples
,
397 inplace_planes
& PIPE_MASK_S
,
400 if (tc_compat_htile
) {
401 /* Only clear the mask that we are flushing, because
402 * si_make_DB_shader_coherent() can treat depth and
403 * stencil differently.
405 if (inplace_planes
& PIPE_MASK_Z
)
406 tex
->dirty_level_mask
&= ~levels_z
;
407 if (inplace_planes
& PIPE_MASK_S
)
408 tex
->stencil_dirty_level_mask
&= ~levels_s
;
411 /* set_framebuffer_state takes care of coherency for single-sample.
412 * The DB->CB copy uses CB for the final writes.
414 if (copy_planes
&& tex
->resource
.b
.b
.nr_samples
> 1)
415 si_make_CB_shader_coherent(sctx
, tex
->resource
.b
.b
.nr_samples
,
420 si_decompress_sampler_depth_textures(struct si_context
*sctx
,
421 struct si_textures_info
*textures
)
424 unsigned mask
= textures
->needs_depth_decompress_mask
;
427 struct pipe_sampler_view
*view
;
428 struct si_sampler_view
*sview
;
429 struct r600_texture
*tex
;
431 i
= u_bit_scan(&mask
);
433 view
= textures
->views
.views
[i
];
435 sview
= (struct si_sampler_view
*)view
;
437 tex
= (struct r600_texture
*)view
->texture
;
438 assert(tex
->db_compatible
);
440 si_decompress_depth(sctx
, tex
,
441 sview
->is_stencil_sampler
? PIPE_MASK_S
: PIPE_MASK_Z
,
442 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
443 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
447 static void si_blit_decompress_color(struct pipe_context
*ctx
,
448 struct r600_texture
*rtex
,
449 unsigned first_level
, unsigned last_level
,
450 unsigned first_layer
, unsigned last_layer
,
451 bool need_dcc_decompress
)
453 struct si_context
*sctx
= (struct si_context
*)ctx
;
455 unsigned layer
, checked_last_layer
, max_layer
;
456 unsigned level_mask
=
457 u_bit_consecutive(first_level
, last_level
- first_level
+ 1);
459 if (!need_dcc_decompress
)
460 level_mask
&= rtex
->dirty_level_mask
;
464 if (unlikely(sctx
->b
.log
))
465 u_log_printf(sctx
->b
.log
,
466 "\n------------------------------------------------\n"
467 "Decompress Color (levels %u - %u, mask 0x%x)\n\n",
468 first_level
, last_level
, level_mask
);
470 if (rtex
->dcc_offset
&& need_dcc_decompress
) {
471 custom_blend
= sctx
->custom_blend_dcc_decompress
;
473 /* disable levels without DCC */
474 for (int i
= first_level
; i
<= last_level
; i
++) {
475 if (!vi_dcc_enabled(rtex
, i
))
476 level_mask
&= ~(1 << i
);
478 } else if (rtex
->fmask
.size
) {
479 custom_blend
= sctx
->custom_blend_fmask_decompress
;
481 custom_blend
= sctx
->custom_blend_eliminate_fastclear
;
484 sctx
->decompression_enabled
= true;
487 unsigned level
= u_bit_scan(&level_mask
);
489 /* The smaller the mipmap level, the less layers there are
490 * as far as 3D textures are concerned. */
491 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
492 checked_last_layer
= MIN2(last_layer
, max_layer
);
494 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
495 struct pipe_surface
*cbsurf
, surf_tmpl
;
497 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
498 surf_tmpl
.u
.tex
.level
= level
;
499 surf_tmpl
.u
.tex
.first_layer
= layer
;
500 surf_tmpl
.u
.tex
.last_layer
= layer
;
501 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
503 /* Required before and after FMASK and DCC_DECOMPRESS. */
504 if (custom_blend
== sctx
->custom_blend_fmask_decompress
||
505 custom_blend
== sctx
->custom_blend_dcc_decompress
)
506 sctx
->b
.flags
|= SI_CONTEXT_FLUSH_AND_INV_CB
;
508 si_blitter_begin(ctx
, SI_DECOMPRESS
);
509 util_blitter_custom_color(sctx
->blitter
, cbsurf
, custom_blend
);
512 if (custom_blend
== sctx
->custom_blend_fmask_decompress
||
513 custom_blend
== sctx
->custom_blend_dcc_decompress
)
514 sctx
->b
.flags
|= SI_CONTEXT_FLUSH_AND_INV_CB
;
516 pipe_surface_reference(&cbsurf
, NULL
);
519 /* The texture will always be dirty if some layers aren't flushed.
520 * I don't think this case occurs often though. */
521 if (first_layer
== 0 && last_layer
>= max_layer
) {
522 rtex
->dirty_level_mask
&= ~(1 << level
);
526 sctx
->decompression_enabled
= false;
527 si_make_CB_shader_coherent(sctx
, rtex
->resource
.b
.b
.nr_samples
,
528 vi_dcc_enabled(rtex
, first_level
));
532 si_decompress_color_texture(struct si_context
*sctx
, struct r600_texture
*tex
,
533 unsigned first_level
, unsigned last_level
)
535 /* CMASK or DCC can be discarded and we can still end up here. */
536 if (!tex
->cmask
.size
&& !tex
->fmask
.size
&& !tex
->dcc_offset
)
539 si_blit_decompress_color(&sctx
->b
.b
, tex
, first_level
, last_level
, 0,
540 util_max_layer(&tex
->resource
.b
.b
, first_level
),
545 si_decompress_sampler_color_textures(struct si_context
*sctx
,
546 struct si_textures_info
*textures
)
549 unsigned mask
= textures
->needs_color_decompress_mask
;
552 struct pipe_sampler_view
*view
;
553 struct r600_texture
*tex
;
555 i
= u_bit_scan(&mask
);
557 view
= textures
->views
.views
[i
];
560 tex
= (struct r600_texture
*)view
->texture
;
562 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.first_level
,
563 view
->u
.tex
.last_level
);
568 si_decompress_image_color_textures(struct si_context
*sctx
,
569 struct si_images_info
*images
)
572 unsigned mask
= images
->needs_color_decompress_mask
;
575 const struct pipe_image_view
*view
;
576 struct r600_texture
*tex
;
578 i
= u_bit_scan(&mask
);
580 view
= &images
->views
[i
];
581 assert(view
->resource
->target
!= PIPE_BUFFER
);
583 tex
= (struct r600_texture
*)view
->resource
;
585 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.level
,
590 static void si_check_render_feedback_texture(struct si_context
*sctx
,
591 struct r600_texture
*tex
,
592 unsigned first_level
,
594 unsigned first_layer
,
597 bool render_feedback
= false;
599 if (!tex
->dcc_offset
)
602 for (unsigned j
= 0; j
< sctx
->framebuffer
.state
.nr_cbufs
; ++j
) {
603 struct r600_surface
* surf
;
605 if (!sctx
->framebuffer
.state
.cbufs
[j
])
608 surf
= (struct r600_surface
*)sctx
->framebuffer
.state
.cbufs
[j
];
610 if (tex
== (struct r600_texture
*)surf
->base
.texture
&&
611 surf
->base
.u
.tex
.level
>= first_level
&&
612 surf
->base
.u
.tex
.level
<= last_level
&&
613 surf
->base
.u
.tex
.first_layer
<= last_layer
&&
614 surf
->base
.u
.tex
.last_layer
>= first_layer
) {
615 render_feedback
= true;
621 r600_texture_disable_dcc(&sctx
->b
, tex
);
624 static void si_check_render_feedback_textures(struct si_context
*sctx
,
625 struct si_textures_info
*textures
)
627 uint32_t mask
= textures
->views
.enabled_mask
;
630 const struct pipe_sampler_view
*view
;
631 struct r600_texture
*tex
;
633 unsigned i
= u_bit_scan(&mask
);
635 view
= textures
->views
.views
[i
];
636 if(view
->texture
->target
== PIPE_BUFFER
)
639 tex
= (struct r600_texture
*)view
->texture
;
641 si_check_render_feedback_texture(sctx
, tex
,
642 view
->u
.tex
.first_level
,
643 view
->u
.tex
.last_level
,
644 view
->u
.tex
.first_layer
,
645 view
->u
.tex
.last_layer
);
649 static void si_check_render_feedback_images(struct si_context
*sctx
,
650 struct si_images_info
*images
)
652 uint32_t mask
= images
->enabled_mask
;
655 const struct pipe_image_view
*view
;
656 struct r600_texture
*tex
;
658 unsigned i
= u_bit_scan(&mask
);
660 view
= &images
->views
[i
];
661 if (view
->resource
->target
== PIPE_BUFFER
)
664 tex
= (struct r600_texture
*)view
->resource
;
666 si_check_render_feedback_texture(sctx
, tex
,
669 view
->u
.tex
.first_layer
,
670 view
->u
.tex
.last_layer
);
674 static void si_check_render_feedback_resident_textures(struct si_context
*sctx
)
676 util_dynarray_foreach(&sctx
->resident_tex_handles
,
677 struct si_texture_handle
*, tex_handle
) {
678 struct pipe_sampler_view
*view
;
679 struct r600_texture
*tex
;
681 view
= (*tex_handle
)->view
;
682 if (view
->texture
->target
== PIPE_BUFFER
)
685 tex
= (struct r600_texture
*)view
->texture
;
687 si_check_render_feedback_texture(sctx
, tex
,
688 view
->u
.tex
.first_level
,
689 view
->u
.tex
.last_level
,
690 view
->u
.tex
.first_layer
,
691 view
->u
.tex
.last_layer
);
695 static void si_check_render_feedback_resident_images(struct si_context
*sctx
)
697 util_dynarray_foreach(&sctx
->resident_img_handles
,
698 struct si_image_handle
*, img_handle
) {
699 struct pipe_image_view
*view
;
700 struct r600_texture
*tex
;
702 view
= &(*img_handle
)->view
;
703 if (view
->resource
->target
== PIPE_BUFFER
)
706 tex
= (struct r600_texture
*)view
->resource
;
708 si_check_render_feedback_texture(sctx
, tex
,
711 view
->u
.tex
.first_layer
,
712 view
->u
.tex
.last_layer
);
716 static void si_check_render_feedback(struct si_context
*sctx
)
719 if (!sctx
->need_check_render_feedback
)
722 for (int i
= 0; i
< SI_NUM_SHADERS
; ++i
) {
723 si_check_render_feedback_images(sctx
, &sctx
->images
[i
]);
724 si_check_render_feedback_textures(sctx
, &sctx
->samplers
[i
]);
727 si_check_render_feedback_resident_images(sctx
);
728 si_check_render_feedback_resident_textures(sctx
);
730 sctx
->need_check_render_feedback
= false;
733 static void si_decompress_resident_textures(struct si_context
*sctx
)
735 util_dynarray_foreach(&sctx
->resident_tex_needs_color_decompress
,
736 struct si_texture_handle
*, tex_handle
) {
737 struct pipe_sampler_view
*view
= (*tex_handle
)->view
;
738 struct r600_texture
*tex
= (struct r600_texture
*)view
->texture
;
740 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.first_level
,
741 view
->u
.tex
.last_level
);
744 util_dynarray_foreach(&sctx
->resident_tex_needs_depth_decompress
,
745 struct si_texture_handle
*, tex_handle
) {
746 struct pipe_sampler_view
*view
= (*tex_handle
)->view
;
747 struct si_sampler_view
*sview
= (struct si_sampler_view
*)view
;
748 struct r600_texture
*tex
= (struct r600_texture
*)view
->texture
;
750 si_decompress_depth(sctx
, tex
,
751 sview
->is_stencil_sampler
? PIPE_MASK_S
: PIPE_MASK_Z
,
752 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
753 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
757 static void si_decompress_resident_images(struct si_context
*sctx
)
759 util_dynarray_foreach(&sctx
->resident_img_needs_color_decompress
,
760 struct si_image_handle
*, img_handle
) {
761 struct pipe_image_view
*view
= &(*img_handle
)->view
;
762 struct r600_texture
*tex
= (struct r600_texture
*)view
->resource
;
764 si_decompress_color_texture(sctx
, tex
, view
->u
.tex
.level
,
769 static void si_decompress_textures(struct si_context
*sctx
, unsigned shader_mask
)
771 unsigned compressed_colortex_counter
, mask
;
773 if (sctx
->blitter
->running
)
776 /* Update the compressed_colortex_mask if necessary. */
777 compressed_colortex_counter
= p_atomic_read(&sctx
->screen
->b
.compressed_colortex_counter
);
778 if (compressed_colortex_counter
!= sctx
->b
.last_compressed_colortex_counter
) {
779 sctx
->b
.last_compressed_colortex_counter
= compressed_colortex_counter
;
780 si_update_needs_color_decompress_masks(sctx
);
783 /* Decompress color & depth textures if needed. */
784 mask
= sctx
->shader_needs_decompress_mask
& shader_mask
;
786 unsigned i
= u_bit_scan(&mask
);
788 if (sctx
->samplers
[i
].needs_depth_decompress_mask
) {
789 si_decompress_sampler_depth_textures(sctx
, &sctx
->samplers
[i
]);
791 if (sctx
->samplers
[i
].needs_color_decompress_mask
) {
792 si_decompress_sampler_color_textures(sctx
, &sctx
->samplers
[i
]);
794 if (sctx
->images
[i
].needs_color_decompress_mask
) {
795 si_decompress_image_color_textures(sctx
, &sctx
->images
[i
]);
799 if (shader_mask
& u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS
)) {
800 if (sctx
->uses_bindless_samplers
)
801 si_decompress_resident_textures(sctx
);
802 if (sctx
->uses_bindless_images
)
803 si_decompress_resident_images(sctx
);
804 } else if (shader_mask
& (1 << PIPE_SHADER_COMPUTE
)) {
805 if (sctx
->cs_shader_state
.program
->uses_bindless_samplers
)
806 si_decompress_resident_textures(sctx
);
807 if (sctx
->cs_shader_state
.program
->uses_bindless_images
)
808 si_decompress_resident_images(sctx
);
811 si_check_render_feedback(sctx
);
814 void si_decompress_graphics_textures(struct si_context
*sctx
)
816 si_decompress_textures(sctx
, u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS
));
819 void si_decompress_compute_textures(struct si_context
*sctx
)
821 si_decompress_textures(sctx
, 1 << PIPE_SHADER_COMPUTE
);
824 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
825 const union pipe_color_union
*color
,
826 double depth
, unsigned stencil
)
828 struct si_context
*sctx
= (struct si_context
*)ctx
;
829 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
830 struct pipe_surface
*zsbuf
= fb
->zsbuf
;
831 struct r600_texture
*zstex
=
832 zsbuf
? (struct r600_texture
*)zsbuf
->texture
: NULL
;
834 if (buffers
& PIPE_CLEAR_COLOR
) {
835 evergreen_do_fast_color_clear(&sctx
->b
, fb
,
836 &sctx
->framebuffer
.atom
, &buffers
,
837 &sctx
->framebuffer
.dirty_cbufs
,
840 return; /* all buffers have been fast cleared */
843 if (buffers
& PIPE_CLEAR_COLOR
) {
846 /* These buffers cannot use fast clear, make sure to disable expansion. */
847 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
848 struct r600_texture
*tex
;
850 /* If not clearing this buffer, skip. */
851 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
857 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
858 if (tex
->fmask
.size
== 0)
859 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
864 r600_htile_enabled(zstex
, zsbuf
->u
.tex
.level
) &&
865 zsbuf
->u
.tex
.first_layer
== 0 &&
866 zsbuf
->u
.tex
.last_layer
== util_max_layer(&zstex
->resource
.b
.b
, 0)) {
867 /* TC-compatible HTILE only supports depth clears to 0 or 1. */
868 if (buffers
& PIPE_CLEAR_DEPTH
&&
869 (!zstex
->tc_compatible_htile
||
870 depth
== 0 || depth
== 1)) {
871 /* Need to disable EXPCLEAR temporarily if clearing
873 if (!zstex
->depth_cleared
|| zstex
->depth_clear_value
!= depth
) {
874 sctx
->db_depth_disable_expclear
= true;
877 zstex
->depth_clear_value
= depth
;
878 sctx
->framebuffer
.dirty_zsbuf
= true;
879 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_DEPTH_CLEAR */
880 sctx
->db_depth_clear
= true;
881 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
884 /* TC-compatible HTILE only supports stencil clears to 0. */
885 if (buffers
& PIPE_CLEAR_STENCIL
&&
886 (!zstex
->tc_compatible_htile
|| stencil
== 0)) {
889 /* Need to disable EXPCLEAR temporarily if clearing
891 if (!zstex
->stencil_cleared
|| zstex
->stencil_clear_value
!= stencil
) {
892 sctx
->db_stencil_disable_expclear
= true;
895 zstex
->stencil_clear_value
= stencil
;
896 sctx
->framebuffer
.dirty_zsbuf
= true;
897 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_STENCIL_CLEAR */
898 sctx
->db_stencil_clear
= true;
899 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
903 si_blitter_begin(ctx
, SI_CLEAR
);
904 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
905 util_framebuffer_get_num_layers(fb
),
906 buffers
, color
, depth
, stencil
);
909 if (sctx
->db_depth_clear
) {
910 sctx
->db_depth_clear
= false;
911 sctx
->db_depth_disable_expclear
= false;
912 zstex
->depth_cleared
= true;
913 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
916 if (sctx
->db_stencil_clear
) {
917 sctx
->db_stencil_clear
= false;
918 sctx
->db_stencil_disable_expclear
= false;
919 zstex
->stencil_cleared
= true;
920 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
924 static void si_clear_render_target(struct pipe_context
*ctx
,
925 struct pipe_surface
*dst
,
926 const union pipe_color_union
*color
,
927 unsigned dstx
, unsigned dsty
,
928 unsigned width
, unsigned height
,
929 bool render_condition_enabled
)
931 struct si_context
*sctx
= (struct si_context
*)ctx
;
933 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
|
934 (render_condition_enabled
? 0 : SI_DISABLE_RENDER_COND
));
935 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
936 dstx
, dsty
, width
, height
);
940 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
941 struct pipe_surface
*dst
,
942 unsigned clear_flags
,
945 unsigned dstx
, unsigned dsty
,
946 unsigned width
, unsigned height
,
947 bool render_condition_enabled
)
949 struct si_context
*sctx
= (struct si_context
*)ctx
;
951 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
|
952 (render_condition_enabled
? 0 : SI_DISABLE_RENDER_COND
));
953 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
954 dstx
, dsty
, width
, height
);
958 /* Helper for decompressing a portion of a color or depth resource before
959 * blitting if any decompression is needed.
960 * The driver doesn't decompress resources automatically while u_blitter is
962 static void si_decompress_subresource(struct pipe_context
*ctx
,
963 struct pipe_resource
*tex
,
964 unsigned planes
, unsigned level
,
965 unsigned first_layer
, unsigned last_layer
)
967 struct si_context
*sctx
= (struct si_context
*)ctx
;
968 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
970 if (rtex
->db_compatible
) {
971 planes
&= PIPE_MASK_Z
| PIPE_MASK_S
;
973 if (!(rtex
->surface
.flags
& RADEON_SURF_SBUFFER
))
974 planes
&= ~PIPE_MASK_S
;
976 /* If we've rendered into the framebuffer and it's a blitting
977 * source, make sure the decompression pass is invoked
978 * by dirtying the framebuffer.
980 if (sctx
->framebuffer
.state
.zsbuf
&&
981 sctx
->framebuffer
.state
.zsbuf
->u
.tex
.level
== level
&&
982 sctx
->framebuffer
.state
.zsbuf
->texture
== tex
)
983 si_update_fb_dirtiness_after_rendering(sctx
);
985 si_decompress_depth(sctx
, rtex
, planes
,
987 first_layer
, last_layer
);
988 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
|| rtex
->dcc_offset
) {
989 /* If we've rendered into the framebuffer and it's a blitting
990 * source, make sure the decompression pass is invoked
991 * by dirtying the framebuffer.
993 for (unsigned i
= 0; i
< sctx
->framebuffer
.state
.nr_cbufs
; i
++) {
994 if (sctx
->framebuffer
.state
.cbufs
[i
] &&
995 sctx
->framebuffer
.state
.cbufs
[i
]->u
.tex
.level
== level
&&
996 sctx
->framebuffer
.state
.cbufs
[i
]->texture
== tex
) {
997 si_update_fb_dirtiness_after_rendering(sctx
);
1002 si_blit_decompress_color(ctx
, rtex
, level
, level
,
1003 first_layer
, last_layer
, false);
1007 struct texture_orig_info
{
1017 void si_resource_copy_region(struct pipe_context
*ctx
,
1018 struct pipe_resource
*dst
,
1020 unsigned dstx
, unsigned dsty
, unsigned dstz
,
1021 struct pipe_resource
*src
,
1023 const struct pipe_box
*src_box
)
1025 struct si_context
*sctx
= (struct si_context
*)ctx
;
1026 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
1027 struct pipe_surface
*dst_view
, dst_templ
;
1028 struct pipe_sampler_view src_templ
, *src_view
;
1029 unsigned dst_width
, dst_height
, src_width0
, src_height0
;
1030 unsigned dst_width0
, dst_height0
, src_force_level
= 0;
1031 struct pipe_box sbox
, dstbox
;
1033 /* Handle buffers first. */
1034 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
1035 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
, 0);
1039 assert(u_max_sample(dst
) == u_max_sample(src
));
1041 /* The driver doesn't decompress resources automatically while
1042 * u_blitter is rendering. */
1043 si_decompress_subresource(ctx
, src
, PIPE_MASK_RGBAZS
, src_level
,
1044 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
1046 dst_width
= u_minify(dst
->width0
, dst_level
);
1047 dst_height
= u_minify(dst
->height0
, dst_level
);
1048 dst_width0
= dst
->width0
;
1049 dst_height0
= dst
->height0
;
1050 src_width0
= src
->width0
;
1051 src_height0
= src
->height0
;
1053 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
1054 util_blitter_default_src_texture(sctx
->blitter
, &src_templ
, src
, src_level
);
1056 if (util_format_is_compressed(src
->format
) ||
1057 util_format_is_compressed(dst
->format
)) {
1058 unsigned blocksize
= rsrc
->surface
.bpe
;
1061 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
1063 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
1064 dst_templ
.format
= src_templ
.format
;
1066 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
1067 dst_height
= util_format_get_nblocksy(dst
->format
, dst_height
);
1068 dst_width0
= util_format_get_nblocksx(dst
->format
, dst_width0
);
1069 dst_height0
= util_format_get_nblocksy(dst
->format
, dst_height0
);
1070 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
1071 src_height0
= util_format_get_nblocksy(src
->format
, src_height0
);
1073 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
1074 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
1076 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
1077 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
1078 sbox
.z
= src_box
->z
;
1079 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
1080 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
1081 sbox
.depth
= src_box
->depth
;
1084 src_force_level
= src_level
;
1085 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
)) {
1086 if (util_format_is_subsampled_422(src
->format
)) {
1087 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
1088 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
1090 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
1091 dst_width0
= util_format_get_nblocksx(dst
->format
, dst_width0
);
1092 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
1094 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
1097 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
1098 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
1101 unsigned blocksize
= rsrc
->surface
.bpe
;
1103 switch (blocksize
) {
1105 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
1106 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
1109 dst_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
1110 src_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
1113 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
1114 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
1117 dst_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
1118 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
1121 dst_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
1122 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
1125 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
1126 util_format_short_name(src
->format
), blocksize
);
1132 /* SNORM8 blitting has precision issues on some chips. Use the SINT
1133 * equivalent instead, which doesn't force DCC decompression.
1134 * Note that some chips avoid this issue by using SDMA.
1136 if (util_format_is_snorm8(dst_templ
.format
)) {
1137 switch (dst_templ
.format
) {
1138 case PIPE_FORMAT_R8_SNORM
:
1139 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8_SINT
;
1141 case PIPE_FORMAT_R8G8_SNORM
:
1142 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8G8_SINT
;
1144 case PIPE_FORMAT_R8G8B8X8_SNORM
:
1145 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8G8B8X8_SINT
;
1147 case PIPE_FORMAT_R8G8B8A8_SNORM
:
1148 /* There are no SINT variants for ABGR and XBGR, so we have to use RGBA. */
1149 case PIPE_FORMAT_A8B8G8R8_SNORM
:
1150 case PIPE_FORMAT_X8B8G8R8_SNORM
:
1151 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_R8G8B8A8_SINT
;
1153 case PIPE_FORMAT_A8_SNORM
:
1154 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_A8_SINT
;
1156 case PIPE_FORMAT_L8_SNORM
:
1157 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_L8_SINT
;
1159 case PIPE_FORMAT_L8A8_SNORM
:
1160 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_L8A8_SINT
;
1162 case PIPE_FORMAT_I8_SNORM
:
1163 dst_templ
.format
= src_templ
.format
= PIPE_FORMAT_I8_SINT
;
1165 default:; /* fall through */
1169 vi_disable_dcc_if_incompatible_format(&sctx
->b
, dst
, dst_level
,
1171 vi_disable_dcc_if_incompatible_format(&sctx
->b
, src
, src_level
,
1174 /* Initialize the surface. */
1175 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
1176 dst_width0
, dst_height0
,
1177 dst_width
, dst_height
);
1179 /* Initialize the sampler view. */
1180 src_view
= si_create_sampler_view_custom(ctx
, src
, &src_templ
,
1181 src_width0
, src_height0
,
1184 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
1185 abs(src_box
->depth
), &dstbox
);
1188 si_blitter_begin(ctx
, SI_COPY
);
1189 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
1190 src_view
, src_box
, src_width0
, src_height0
,
1191 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
1193 si_blitter_end(ctx
);
1195 pipe_surface_reference(&dst_view
, NULL
);
1196 pipe_sampler_view_reference(&src_view
, NULL
);
1199 static void si_do_CB_resolve(struct si_context
*sctx
,
1200 const struct pipe_blit_info
*info
,
1201 struct pipe_resource
*dst
,
1202 unsigned dst_level
, unsigned dst_z
,
1203 enum pipe_format format
)
1205 /* Required before and after CB_RESOLVE. */
1206 sctx
->b
.flags
|= SI_CONTEXT_FLUSH_AND_INV_CB
;
1208 si_blitter_begin(&sctx
->b
.b
, SI_COLOR_RESOLVE
|
1209 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1210 util_blitter_custom_resolve_color(sctx
->blitter
, dst
, dst_level
, dst_z
,
1211 info
->src
.resource
, info
->src
.box
.z
,
1212 ~0, sctx
->custom_blend_resolve
,
1214 si_blitter_end(&sctx
->b
.b
);
1216 /* Flush caches for possible texturing. */
1217 si_make_CB_shader_coherent(sctx
, 1, false);
1220 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
1221 const struct pipe_blit_info
*info
)
1223 struct si_context
*sctx
= (struct si_context
*)ctx
;
1224 struct r600_texture
*src
= (struct r600_texture
*)info
->src
.resource
;
1225 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
1226 MAYBE_UNUSED
struct r600_texture
*rtmp
;
1227 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
1228 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
1229 enum pipe_format format
= info
->src
.format
;
1230 struct pipe_resource
*tmp
, templ
;
1231 struct pipe_blit_info blit
;
1233 /* Check basic requirements for hw resolve. */
1234 if (!(info
->src
.resource
->nr_samples
> 1 &&
1235 info
->dst
.resource
->nr_samples
<= 1 &&
1236 !util_format_is_pure_integer(format
) &&
1237 !util_format_is_depth_or_stencil(format
) &&
1238 util_max_layer(info
->src
.resource
, 0) == 0))
1241 /* Hardware MSAA resolve doesn't work if SPI format = NORM16_ABGR and
1242 * the format is R16G16. Use R16A16, which does work.
1244 if (format
== PIPE_FORMAT_R16G16_UNORM
)
1245 format
= PIPE_FORMAT_R16A16_UNORM
;
1246 if (format
== PIPE_FORMAT_R16G16_SNORM
)
1247 format
= PIPE_FORMAT_R16A16_SNORM
;
1249 /* Check the remaining requirements for hw resolve. */
1250 if (util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
1251 !info
->scissor_enable
&&
1252 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
1253 util_is_format_compatible(util_format_description(info
->src
.format
),
1254 util_format_description(info
->dst
.format
)) &&
1255 dst_width
== info
->src
.resource
->width0
&&
1256 dst_height
== info
->src
.resource
->height0
&&
1257 info
->dst
.box
.x
== 0 &&
1258 info
->dst
.box
.y
== 0 &&
1259 info
->dst
.box
.width
== dst_width
&&
1260 info
->dst
.box
.height
== dst_height
&&
1261 info
->dst
.box
.depth
== 1 &&
1262 info
->src
.box
.x
== 0 &&
1263 info
->src
.box
.y
== 0 &&
1264 info
->src
.box
.width
== dst_width
&&
1265 info
->src
.box
.height
== dst_height
&&
1266 info
->src
.box
.depth
== 1 &&
1267 !dst
->surface
.is_linear
&&
1268 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
)) { /* dst cannot be fast-cleared */
1269 /* Check the last constraint. */
1270 if (src
->surface
.micro_tile_mode
!= dst
->surface
.micro_tile_mode
) {
1271 /* The next fast clear will switch to this mode to
1272 * get direct hw resolve next time if the mode is
1275 src
->last_msaa_resolve_target_micro_mode
=
1276 dst
->surface
.micro_tile_mode
;
1277 goto resolve_to_temp
;
1280 /* Resolving into a surface with DCC is unsupported. Since
1281 * it's being overwritten anyway, clear it to uncompressed.
1282 * This is still the fastest codepath even with this clear.
1284 if (vi_dcc_enabled(dst
, info
->dst
.level
)) {
1285 /* TODO: Implement per-level DCC clears for GFX9. */
1286 if (sctx
->b
.chip_class
>= GFX9
&&
1287 info
->dst
.resource
->last_level
!= 0)
1288 goto resolve_to_temp
;
1290 vi_dcc_clear_level(&sctx
->b
, dst
, info
->dst
.level
,
1292 dst
->dirty_level_mask
&= ~(1 << info
->dst
.level
);
1295 /* Resolve directly from src to dst. */
1296 si_do_CB_resolve(sctx
, info
, info
->dst
.resource
,
1297 info
->dst
.level
, info
->dst
.box
.z
, format
);
1302 /* Shader-based resolve is VERY SLOW. Instead, resolve into
1303 * a temporary texture and blit.
1305 memset(&templ
, 0, sizeof(templ
));
1306 templ
.target
= PIPE_TEXTURE_2D
;
1307 templ
.format
= info
->src
.resource
->format
;
1308 templ
.width0
= info
->src
.resource
->width0
;
1309 templ
.height0
= info
->src
.resource
->height0
;
1311 templ
.array_size
= 1;
1312 templ
.usage
= PIPE_USAGE_DEFAULT
;
1313 templ
.flags
= R600_RESOURCE_FLAG_FORCE_TILING
|
1314 R600_RESOURCE_FLAG_DISABLE_DCC
;
1316 /* The src and dst microtile modes must be the same. */
1317 if (src
->surface
.micro_tile_mode
== RADEON_MICRO_MODE_DISPLAY
)
1318 templ
.bind
= PIPE_BIND_SCANOUT
;
1322 tmp
= ctx
->screen
->resource_create(ctx
->screen
, &templ
);
1325 rtmp
= (struct r600_texture
*)tmp
;
1327 assert(!rtmp
->surface
.is_linear
);
1328 assert(src
->surface
.micro_tile_mode
== rtmp
->surface
.micro_tile_mode
);
1331 si_do_CB_resolve(sctx
, info
, tmp
, 0, 0, format
);
1335 blit
.src
.resource
= tmp
;
1338 si_blitter_begin(ctx
, SI_BLIT
|
1339 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1340 util_blitter_blit(sctx
->blitter
, &blit
);
1341 si_blitter_end(ctx
);
1343 pipe_resource_reference(&tmp
, NULL
);
1347 static void si_blit(struct pipe_context
*ctx
,
1348 const struct pipe_blit_info
*info
)
1350 struct si_context
*sctx
= (struct si_context
*)ctx
;
1351 struct r600_texture
*rdst
= (struct r600_texture
*)info
->dst
.resource
;
1353 if (do_hardware_msaa_resolve(ctx
, info
)) {
1357 /* Using SDMA for copying to a linear texture in GTT is much faster.
1358 * This improves DRI PRIME performance.
1360 * resource_copy_region can't do this yet, because dma_copy calls it
1361 * on failure (recursion).
1363 if (rdst
->surface
.is_linear
&&
1365 util_can_blit_via_copy_region(info
, false)) {
1366 sctx
->b
.dma_copy(ctx
, info
->dst
.resource
, info
->dst
.level
,
1367 info
->dst
.box
.x
, info
->dst
.box
.y
,
1369 info
->src
.resource
, info
->src
.level
,
1374 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
1376 /* The driver doesn't decompress resources automatically while
1377 * u_blitter is rendering. */
1378 vi_disable_dcc_if_incompatible_format(&sctx
->b
, info
->src
.resource
,
1381 vi_disable_dcc_if_incompatible_format(&sctx
->b
, info
->dst
.resource
,
1384 si_decompress_subresource(ctx
, info
->src
.resource
, info
->mask
,
1387 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
1389 if (sctx
->screen
->b
.debug_flags
& DBG_FORCE_DMA
&&
1390 util_try_blit_via_copy_region(ctx
, info
))
1393 si_blitter_begin(ctx
, SI_BLIT
|
1394 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1395 util_blitter_blit(sctx
->blitter
, info
);
1396 si_blitter_end(ctx
);
1399 static boolean
si_generate_mipmap(struct pipe_context
*ctx
,
1400 struct pipe_resource
*tex
,
1401 enum pipe_format format
,
1402 unsigned base_level
, unsigned last_level
,
1403 unsigned first_layer
, unsigned last_layer
)
1405 struct si_context
*sctx
= (struct si_context
*)ctx
;
1406 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
1408 if (!util_blitter_is_copy_supported(sctx
->blitter
, tex
, tex
))
1411 /* The driver doesn't decompress resources automatically while
1412 * u_blitter is rendering. */
1413 vi_disable_dcc_if_incompatible_format(&sctx
->b
, tex
, base_level
,
1415 si_decompress_subresource(ctx
, tex
, PIPE_MASK_RGBAZS
,
1416 base_level
, first_layer
, last_layer
);
1418 /* Clear dirty_level_mask for the levels that will be overwritten. */
1419 assert(base_level
< last_level
);
1420 rtex
->dirty_level_mask
&= ~u_bit_consecutive(base_level
+ 1,
1421 last_level
- base_level
);
1423 sctx
->generate_mipmap_for_depth
= rtex
->is_depth
;
1425 si_blitter_begin(ctx
, SI_BLIT
| SI_DISABLE_RENDER_COND
);
1426 util_blitter_generate_mipmap(sctx
->blitter
, tex
, format
,
1427 base_level
, last_level
,
1428 first_layer
, last_layer
);
1429 si_blitter_end(ctx
);
1431 sctx
->generate_mipmap_for_depth
= false;
1435 static void si_flush_resource(struct pipe_context
*ctx
,
1436 struct pipe_resource
*res
)
1438 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
1440 assert(res
->target
!= PIPE_BUFFER
);
1441 assert(!rtex
->dcc_separate_buffer
|| rtex
->dcc_gather_statistics
);
1443 /* st/dri calls flush twice per frame (not a bug), this prevents double
1445 if (rtex
->dcc_separate_buffer
&& !rtex
->separate_dcc_dirty
)
1448 if (!rtex
->is_depth
&& (rtex
->cmask
.size
|| rtex
->dcc_offset
)) {
1449 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
1450 0, util_max_layer(res
, 0),
1451 rtex
->dcc_separate_buffer
!= NULL
);
1454 /* Always do the analysis even if DCC is disabled at the moment. */
1455 if (rtex
->dcc_gather_statistics
&& rtex
->separate_dcc_dirty
) {
1456 rtex
->separate_dcc_dirty
= false;
1457 vi_separate_dcc_process_and_reset_stats(ctx
, rtex
);
1461 static void si_decompress_dcc(struct pipe_context
*ctx
,
1462 struct r600_texture
*rtex
)
1464 if (!rtex
->dcc_offset
)
1467 si_blit_decompress_color(ctx
, rtex
, 0, rtex
->resource
.b
.b
.last_level
,
1468 0, util_max_layer(&rtex
->resource
.b
.b
, 0),
1472 static void si_pipe_clear_buffer(struct pipe_context
*ctx
,
1473 struct pipe_resource
*dst
,
1474 unsigned offset
, unsigned size
,
1475 const void *clear_value_ptr
,
1476 int clear_value_size
)
1478 struct si_context
*sctx
= (struct si_context
*)ctx
;
1479 uint32_t dword_value
;
1482 assert(offset
% clear_value_size
== 0);
1483 assert(size
% clear_value_size
== 0);
1485 if (clear_value_size
> 4) {
1486 const uint32_t *u32
= clear_value_ptr
;
1487 bool clear_dword_duplicated
= true;
1489 /* See if we can lower large fills to dword fills. */
1490 for (i
= 1; i
< clear_value_size
/ 4; i
++)
1491 if (u32
[0] != u32
[i
]) {
1492 clear_dword_duplicated
= false;
1496 if (!clear_dword_duplicated
) {
1497 /* Use transform feedback for 64-bit, 96-bit, and
1500 union pipe_color_union clear_value
;
1502 memcpy(&clear_value
, clear_value_ptr
, clear_value_size
);
1503 si_blitter_begin(ctx
, SI_DISABLE_RENDER_COND
);
1504 util_blitter_clear_buffer(sctx
->blitter
, dst
, offset
,
1505 size
, clear_value_size
/ 4,
1507 si_blitter_end(ctx
);
1512 /* Expand the clear value to a dword. */
1513 switch (clear_value_size
) {
1515 dword_value
= *(uint8_t*)clear_value_ptr
;
1516 dword_value
|= (dword_value
<< 8) |
1517 (dword_value
<< 16) |
1518 (dword_value
<< 24);
1521 dword_value
= *(uint16_t*)clear_value_ptr
;
1522 dword_value
|= dword_value
<< 16;
1525 dword_value
= *(uint32_t*)clear_value_ptr
;
1528 sctx
->b
.clear_buffer(ctx
, dst
, offset
, size
, dword_value
,
1529 R600_COHERENCY_SHADER
);
1532 void si_init_blit_functions(struct si_context
*sctx
)
1534 sctx
->b
.b
.clear
= si_clear
;
1535 sctx
->b
.b
.clear_buffer
= si_pipe_clear_buffer
;
1536 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
1537 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
1538 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
1539 sctx
->b
.b
.blit
= si_blit
;
1540 sctx
->b
.b
.flush_resource
= si_flush_resource
;
1541 sctx
->b
.b
.generate_mipmap
= si_generate_mipmap
;
1542 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;
1543 sctx
->b
.decompress_dcc
= si_decompress_dcc
;