2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "util/u_format.h"
26 #include "util/u_surface.h"
28 enum si_blitter_op
/* bitmask */
31 SI_SAVE_FRAMEBUFFER
= 2,
32 SI_SAVE_FRAGMENT_STATE
= 4,
33 SI_DISABLE_RENDER_COND
= 8,
35 SI_CLEAR
= SI_SAVE_FRAGMENT_STATE
,
37 SI_CLEAR_SURFACE
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
,
39 SI_COPY
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
40 SI_SAVE_FRAGMENT_STATE
| SI_DISABLE_RENDER_COND
,
42 SI_BLIT
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
43 SI_SAVE_FRAGMENT_STATE
,
45 SI_DECOMPRESS
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
|
46 SI_DISABLE_RENDER_COND
,
48 SI_COLOR_RESOLVE
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_FRAGMENT_STATE
51 static void si_blitter_begin(struct pipe_context
*ctx
, enum si_blitter_op op
)
53 struct si_context
*sctx
= (struct si_context
*)ctx
;
55 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
56 util_blitter_save_vertex_elements(sctx
->blitter
, sctx
->vertex_elements
);
57 util_blitter_save_vertex_shader(sctx
->blitter
, sctx
->vs_shader
.cso
);
58 util_blitter_save_tessctrl_shader(sctx
->blitter
, sctx
->tcs_shader
.cso
);
59 util_blitter_save_tesseval_shader(sctx
->blitter
, sctx
->tes_shader
.cso
);
60 util_blitter_save_geometry_shader(sctx
->blitter
, sctx
->gs_shader
.cso
);
61 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
62 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
63 util_blitter_save_rasterizer(sctx
->blitter
, sctx
->queued
.named
.rasterizer
);
65 if (op
& SI_SAVE_FRAGMENT_STATE
) {
66 util_blitter_save_blend(sctx
->blitter
, sctx
->queued
.named
.blend
);
67 util_blitter_save_depth_stencil_alpha(sctx
->blitter
, sctx
->queued
.named
.dsa
);
68 util_blitter_save_stencil_ref(sctx
->blitter
, &sctx
->stencil_ref
.state
);
69 util_blitter_save_fragment_shader(sctx
->blitter
, sctx
->ps_shader
.cso
);
70 util_blitter_save_sample_mask(sctx
->blitter
, sctx
->sample_mask
.sample_mask
);
71 util_blitter_save_viewport(sctx
->blitter
, &sctx
->b
.viewports
.states
[0]);
72 util_blitter_save_scissor(sctx
->blitter
, &sctx
->b
.scissors
.states
[0]);
75 if (op
& SI_SAVE_FRAMEBUFFER
)
76 util_blitter_save_framebuffer(sctx
->blitter
, &sctx
->framebuffer
.state
);
78 if (op
& SI_SAVE_TEXTURES
) {
79 util_blitter_save_fragment_sampler_states(
81 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.sampler_states
);
83 util_blitter_save_fragment_sampler_views(sctx
->blitter
, 2,
84 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
87 if (op
& SI_DISABLE_RENDER_COND
)
88 sctx
->b
.render_cond_force_off
= true;
91 static void si_blitter_end(struct pipe_context
*ctx
)
93 struct si_context
*sctx
= (struct si_context
*)ctx
;
95 sctx
->b
.render_cond_force_off
= false;
98 static unsigned u_max_sample(struct pipe_resource
*r
)
100 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
104 si_blit_dbcb_copy(struct si_context
*sctx
,
105 struct r600_texture
*src
,
106 struct r600_texture
*dst
,
107 unsigned planes
, unsigned level_mask
,
108 unsigned first_layer
, unsigned last_layer
,
109 unsigned first_sample
, unsigned last_sample
)
111 struct pipe_surface surf_tmpl
= {{0}};
112 unsigned layer
, sample
, checked_last_layer
, max_layer
;
113 unsigned fully_copied_levels
= 0;
115 if (planes
& PIPE_MASK_Z
)
116 sctx
->dbcb_depth_copy_enabled
= true;
117 if (planes
& PIPE_MASK_S
)
118 sctx
->dbcb_stencil_copy_enabled
= true;
119 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
121 assert(sctx
->dbcb_depth_copy_enabled
|| sctx
->dbcb_stencil_copy_enabled
);
124 unsigned level
= u_bit_scan(&level_mask
);
126 /* The smaller the mipmap level, the less layers there are
127 * as far as 3D textures are concerned. */
128 max_layer
= util_max_layer(&src
->resource
.b
.b
, level
);
129 checked_last_layer
= MIN2(last_layer
, max_layer
);
131 surf_tmpl
.u
.tex
.level
= level
;
133 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
134 struct pipe_surface
*zsurf
, *cbsurf
;
136 surf_tmpl
.format
= src
->resource
.b
.b
.format
;
137 surf_tmpl
.u
.tex
.first_layer
= layer
;
138 surf_tmpl
.u
.tex
.last_layer
= layer
;
140 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &src
->resource
.b
.b
, &surf_tmpl
);
142 surf_tmpl
.format
= dst
->resource
.b
.b
.format
;
143 cbsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &dst
->resource
.b
.b
, &surf_tmpl
);
145 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
146 if (sample
!= sctx
->dbcb_copy_sample
) {
147 sctx
->dbcb_copy_sample
= sample
;
148 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
151 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
152 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
153 sctx
->custom_dsa_flush
, 1.0f
);
154 si_blitter_end(&sctx
->b
.b
);
157 pipe_surface_reference(&zsurf
, NULL
);
158 pipe_surface_reference(&cbsurf
, NULL
);
161 if (first_layer
== 0 && last_layer
>= max_layer
&&
162 first_sample
== 0 && last_sample
>= u_max_sample(&src
->resource
.b
.b
))
163 fully_copied_levels
|= 1u << level
;
166 sctx
->dbcb_depth_copy_enabled
= false;
167 sctx
->dbcb_stencil_copy_enabled
= false;
168 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
170 return fully_copied_levels
;
173 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
174 struct r600_texture
*texture
,
175 struct r600_texture
*staging
,
176 unsigned first_level
, unsigned last_level
,
177 unsigned first_layer
, unsigned last_layer
,
178 unsigned first_sample
, unsigned last_sample
)
180 const struct util_format_description
*desc
;
183 assert(staging
!= NULL
&& "use si_blit_decompress_zs_in_place instead");
185 desc
= util_format_description(staging
->resource
.b
.b
.format
);
187 if (util_format_has_depth(desc
))
188 planes
|= PIPE_MASK_Z
;
189 if (util_format_has_stencil(desc
))
190 planes
|= PIPE_MASK_S
;
193 (struct si_context
*)ctx
, texture
, staging
, planes
,
194 u_bit_consecutive(first_level
, last_level
- first_level
+ 1),
195 first_layer
, last_layer
, first_sample
, last_sample
);
198 /* Helper function for si_blit_decompress_zs_in_place.
201 si_blit_decompress_zs_planes_in_place(struct si_context
*sctx
,
202 struct r600_texture
*texture
,
203 unsigned planes
, unsigned level_mask
,
204 unsigned first_layer
, unsigned last_layer
)
206 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
207 unsigned layer
, max_layer
, checked_last_layer
;
208 unsigned fully_decompressed_mask
= 0;
213 if (planes
& PIPE_MASK_S
)
214 sctx
->db_flush_stencil_inplace
= true;
215 if (planes
& PIPE_MASK_Z
)
216 sctx
->db_flush_depth_inplace
= true;
217 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
219 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
222 unsigned level
= u_bit_scan(&level_mask
);
224 surf_tmpl
.u
.tex
.level
= level
;
226 /* The smaller the mipmap level, the less layers there are
227 * as far as 3D textures are concerned. */
228 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
229 checked_last_layer
= MIN2(last_layer
, max_layer
);
231 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
232 surf_tmpl
.u
.tex
.first_layer
= layer
;
233 surf_tmpl
.u
.tex
.last_layer
= layer
;
235 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
237 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
238 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
239 sctx
->custom_dsa_flush
,
241 si_blitter_end(&sctx
->b
.b
);
243 pipe_surface_reference(&zsurf
, NULL
);
246 /* The texture will always be dirty if some layers aren't flushed.
247 * I don't think this case occurs often though. */
248 if (first_layer
== 0 && last_layer
>= max_layer
) {
249 fully_decompressed_mask
|= 1u << level
;
253 if (planes
& PIPE_MASK_Z
)
254 texture
->dirty_level_mask
&= ~fully_decompressed_mask
;
255 if (planes
& PIPE_MASK_S
)
256 texture
->stencil_dirty_level_mask
&= ~fully_decompressed_mask
;
258 sctx
->db_flush_depth_inplace
= false;
259 sctx
->db_flush_stencil_inplace
= false;
260 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
263 /* Helper function of si_flush_depth_texture: decompress the given levels
264 * of Z and/or S planes in place.
267 si_blit_decompress_zs_in_place(struct si_context
*sctx
,
268 struct r600_texture
*texture
,
269 unsigned levels_z
, unsigned levels_s
,
270 unsigned first_layer
, unsigned last_layer
)
272 unsigned both
= levels_z
& levels_s
;
274 /* First, do combined Z & S decompresses for levels that need it. */
276 si_blit_decompress_zs_planes_in_place(
277 sctx
, texture
, PIPE_MASK_Z
| PIPE_MASK_S
,
279 first_layer
, last_layer
);
284 /* Now do separate Z and S decompresses. */
286 si_blit_decompress_zs_planes_in_place(
287 sctx
, texture
, PIPE_MASK_Z
,
289 first_layer
, last_layer
);
293 si_blit_decompress_zs_planes_in_place(
294 sctx
, texture
, PIPE_MASK_S
,
296 first_layer
, last_layer
);
301 si_flush_depth_texture(struct si_context
*sctx
,
302 struct r600_texture
*tex
,
303 unsigned required_planes
,
304 unsigned first_level
, unsigned last_level
,
305 unsigned first_layer
, unsigned last_layer
)
307 unsigned inplace_planes
= 0;
308 unsigned copy_planes
= 0;
309 unsigned level_mask
= u_bit_consecutive(first_level
, last_level
- first_level
+ 1);
310 unsigned levels_z
= 0;
311 unsigned levels_s
= 0;
313 if (required_planes
& PIPE_MASK_Z
) {
314 levels_z
= level_mask
& tex
->dirty_level_mask
;
317 if (r600_can_sample_zs(tex
, false))
318 inplace_planes
|= PIPE_MASK_Z
;
320 copy_planes
|= PIPE_MASK_Z
;
323 if (required_planes
& PIPE_MASK_S
) {
324 levels_s
= level_mask
& tex
->stencil_dirty_level_mask
;
327 if (r600_can_sample_zs(tex
, true))
328 inplace_planes
|= PIPE_MASK_S
;
330 copy_planes
|= PIPE_MASK_S
;
334 assert(!tex
->tc_compatible_htile
|| levels_z
== 0);
336 /* We may have to allocate the flushed texture here when called from
337 * si_decompress_subresource.
340 (tex
->flushed_depth_texture
||
341 r600_init_flushed_depth_texture(&sctx
->b
.b
, &tex
->resource
.b
.b
, NULL
))) {
342 struct r600_texture
*dst
= tex
->flushed_depth_texture
;
343 unsigned fully_copied_levels
;
346 assert(tex
->flushed_depth_texture
);
348 if (util_format_is_depth_and_stencil(dst
->resource
.b
.b
.format
))
349 copy_planes
= PIPE_MASK_Z
| PIPE_MASK_S
;
351 if (copy_planes
& PIPE_MASK_Z
) {
355 if (copy_planes
& PIPE_MASK_S
) {
360 fully_copied_levels
= si_blit_dbcb_copy(
361 sctx
, tex
, dst
, copy_planes
, levels
,
362 first_layer
, last_layer
,
363 0, u_max_sample(&tex
->resource
.b
.b
));
365 if (copy_planes
& PIPE_MASK_Z
)
366 tex
->dirty_level_mask
&= ~fully_copied_levels
;
367 if (copy_planes
& PIPE_MASK_S
)
368 tex
->stencil_dirty_level_mask
&= ~fully_copied_levels
;
371 if (inplace_planes
) {
372 si_blit_decompress_zs_in_place(
375 first_layer
, last_layer
);
380 si_flush_depth_textures(struct si_context
*sctx
,
381 struct si_textures_info
*textures
)
384 unsigned mask
= textures
->depth_texture_mask
;
387 struct pipe_sampler_view
*view
;
388 struct si_sampler_view
*sview
;
389 struct r600_texture
*tex
;
391 i
= u_bit_scan(&mask
);
393 view
= textures
->views
.views
[i
];
395 sview
= (struct si_sampler_view
*)view
;
397 tex
= (struct r600_texture
*)view
->texture
;
398 assert(tex
->db_compatible
);
400 si_flush_depth_texture(
402 sview
->is_stencil_sampler
? PIPE_MASK_S
: PIPE_MASK_Z
,
403 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
404 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
408 static void si_blit_decompress_color(struct pipe_context
*ctx
,
409 struct r600_texture
*rtex
,
410 unsigned first_level
, unsigned last_level
,
411 unsigned first_layer
, unsigned last_layer
,
412 bool need_dcc_decompress
)
414 struct si_context
*sctx
= (struct si_context
*)ctx
;
416 unsigned layer
, checked_last_layer
, max_layer
;
417 unsigned level_mask
=
418 u_bit_consecutive(first_level
, last_level
- first_level
+ 1);
420 if (!need_dcc_decompress
)
421 level_mask
&= rtex
->dirty_level_mask
;
425 if (rtex
->dcc_offset
&& need_dcc_decompress
) {
426 custom_blend
= sctx
->custom_blend_dcc_decompress
;
428 /* disable levels without DCC */
429 for (int i
= first_level
; i
<= last_level
; i
++) {
430 if (!rtex
->dcc_offset
||
431 i
>= rtex
->surface
.num_dcc_levels
)
432 level_mask
&= ~(1 << i
);
434 } else if (rtex
->fmask
.size
) {
435 custom_blend
= sctx
->custom_blend_decompress
;
437 custom_blend
= sctx
->custom_blend_fastclear
;
441 unsigned level
= u_bit_scan(&level_mask
);
443 /* The smaller the mipmap level, the less layers there are
444 * as far as 3D textures are concerned. */
445 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
446 checked_last_layer
= MIN2(last_layer
, max_layer
);
448 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
449 struct pipe_surface
*cbsurf
, surf_tmpl
;
451 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
452 surf_tmpl
.u
.tex
.level
= level
;
453 surf_tmpl
.u
.tex
.first_layer
= layer
;
454 surf_tmpl
.u
.tex
.last_layer
= layer
;
455 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
457 si_blitter_begin(ctx
, SI_DECOMPRESS
);
458 util_blitter_custom_color(sctx
->blitter
, cbsurf
, custom_blend
);
461 pipe_surface_reference(&cbsurf
, NULL
);
464 /* The texture will always be dirty if some layers aren't flushed.
465 * I don't think this case occurs often though. */
466 if (first_layer
== 0 && last_layer
>= max_layer
) {
467 rtex
->dirty_level_mask
&= ~(1 << level
);
473 si_decompress_sampler_color_textures(struct si_context
*sctx
,
474 struct si_textures_info
*textures
)
477 unsigned mask
= textures
->compressed_colortex_mask
;
480 struct pipe_sampler_view
*view
;
481 struct r600_texture
*tex
;
483 i
= u_bit_scan(&mask
);
485 view
= textures
->views
.views
[i
];
488 tex
= (struct r600_texture
*)view
->texture
;
489 assert(tex
->cmask
.size
|| tex
->fmask
.size
|| tex
->dcc_offset
);
491 si_blit_decompress_color(&sctx
->b
.b
, tex
,
492 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
493 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
),
499 si_decompress_image_color_textures(struct si_context
*sctx
,
500 struct si_images_info
*images
)
503 unsigned mask
= images
->compressed_colortex_mask
;
506 const struct pipe_image_view
*view
;
507 struct r600_texture
*tex
;
509 i
= u_bit_scan(&mask
);
511 view
= &images
->views
[i
];
512 assert(view
->resource
->target
!= PIPE_BUFFER
);
514 tex
= (struct r600_texture
*)view
->resource
;
515 if (!tex
->cmask
.size
&& !tex
->fmask
.size
&& !tex
->dcc_offset
)
518 si_blit_decompress_color(&sctx
->b
.b
, tex
,
519 view
->u
.tex
.level
, view
->u
.tex
.level
,
520 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.level
),
525 static void si_check_render_feedback_textures(struct si_context
*sctx
,
526 struct si_textures_info
*textures
)
528 uint32_t mask
= textures
->views
.enabled_mask
;
531 const struct pipe_sampler_view
*view
;
532 struct r600_texture
*tex
;
533 bool render_feedback
= false;
535 unsigned i
= u_bit_scan(&mask
);
537 view
= textures
->views
.views
[i
];
538 if(view
->texture
->target
== PIPE_BUFFER
)
541 tex
= (struct r600_texture
*)view
->texture
;
542 if (!tex
->dcc_offset
)
545 for (unsigned j
= 0; j
< sctx
->framebuffer
.state
.nr_cbufs
; ++j
) {
546 struct r600_surface
* surf
;
548 if (!sctx
->framebuffer
.state
.cbufs
[j
])
551 surf
= (struct r600_surface
*)sctx
->framebuffer
.state
.cbufs
[j
];
553 if (tex
== (struct r600_texture
*)surf
->base
.texture
&&
554 surf
->base
.u
.tex
.level
>= view
->u
.tex
.first_level
&&
555 surf
->base
.u
.tex
.level
<= view
->u
.tex
.last_level
&&
556 surf
->base
.u
.tex
.first_layer
<= view
->u
.tex
.last_layer
&&
557 surf
->base
.u
.tex
.last_layer
>= view
->u
.tex
.first_layer
)
558 render_feedback
= true;
562 r600_texture_disable_dcc(&sctx
->b
, tex
);
566 static void si_check_render_feedback_images(struct si_context
*sctx
,
567 struct si_images_info
*images
)
569 uint32_t mask
= images
->enabled_mask
;
572 const struct pipe_image_view
*view
;
573 struct r600_texture
*tex
;
574 bool render_feedback
= false;
576 unsigned i
= u_bit_scan(&mask
);
578 view
= &images
->views
[i
];
579 if (view
->resource
->target
== PIPE_BUFFER
)
582 tex
= (struct r600_texture
*)view
->resource
;
583 if (!tex
->dcc_offset
)
586 for (unsigned j
= 0; j
< sctx
->framebuffer
.state
.nr_cbufs
; ++j
) {
587 struct r600_surface
* surf
;
589 if (!sctx
->framebuffer
.state
.cbufs
[j
])
592 surf
= (struct r600_surface
*)sctx
->framebuffer
.state
.cbufs
[j
];
594 if (tex
== (struct r600_texture
*)surf
->base
.texture
&&
595 surf
->base
.u
.tex
.level
== view
->u
.tex
.level
&&
596 surf
->base
.u
.tex
.first_layer
<= view
->u
.tex
.last_layer
&&
597 surf
->base
.u
.tex
.last_layer
>= view
->u
.tex
.first_layer
)
598 render_feedback
= true;
602 r600_texture_disable_dcc(&sctx
->b
, tex
);
606 static void si_check_render_feedback(struct si_context
*sctx
)
609 if (!sctx
->need_check_render_feedback
)
612 for (int i
= 0; i
< SI_NUM_SHADERS
; ++i
) {
613 si_check_render_feedback_images(sctx
, &sctx
->images
[i
]);
614 si_check_render_feedback_textures(sctx
, &sctx
->samplers
[i
]);
616 sctx
->need_check_render_feedback
= false;
619 static void si_decompress_textures(struct si_context
*sctx
, int shader_start
,
622 unsigned compressed_colortex_counter
;
624 if (sctx
->blitter
->running
)
627 /* Update the compressed_colortex_mask if necessary. */
628 compressed_colortex_counter
= p_atomic_read(&sctx
->screen
->b
.compressed_colortex_counter
);
629 if (compressed_colortex_counter
!= sctx
->b
.last_compressed_colortex_counter
) {
630 sctx
->b
.last_compressed_colortex_counter
= compressed_colortex_counter
;
631 si_update_compressed_colortex_masks(sctx
);
634 /* Flush depth textures which need to be flushed. */
635 for (int i
= shader_start
; i
< shader_end
; i
++) {
636 if (sctx
->samplers
[i
].depth_texture_mask
) {
637 si_flush_depth_textures(sctx
, &sctx
->samplers
[i
]);
639 if (sctx
->samplers
[i
].compressed_colortex_mask
) {
640 si_decompress_sampler_color_textures(sctx
, &sctx
->samplers
[i
]);
642 if (sctx
->images
[i
].compressed_colortex_mask
) {
643 si_decompress_image_color_textures(sctx
, &sctx
->images
[i
]);
647 si_check_render_feedback(sctx
);
650 void si_decompress_graphics_textures(struct si_context
*sctx
)
652 si_decompress_textures(sctx
, 0, SI_NUM_GRAPHICS_SHADERS
);
655 void si_decompress_compute_textures(struct si_context
*sctx
)
657 si_decompress_textures(sctx
, SI_NUM_GRAPHICS_SHADERS
, SI_NUM_SHADERS
);
660 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
661 const union pipe_color_union
*color
,
662 double depth
, unsigned stencil
)
664 struct si_context
*sctx
= (struct si_context
*)ctx
;
665 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
666 struct pipe_surface
*zsbuf
= fb
->zsbuf
;
667 struct r600_texture
*zstex
=
668 zsbuf
? (struct r600_texture
*)zsbuf
->texture
: NULL
;
670 if (buffers
& PIPE_CLEAR_COLOR
) {
671 evergreen_do_fast_color_clear(&sctx
->b
, fb
,
672 &sctx
->framebuffer
.atom
, &buffers
,
673 &sctx
->framebuffer
.dirty_cbufs
,
676 return; /* all buffers have been fast cleared */
679 if (buffers
& PIPE_CLEAR_COLOR
) {
682 /* These buffers cannot use fast clear, make sure to disable expansion. */
683 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
684 struct r600_texture
*tex
;
686 /* If not clearing this buffer, skip. */
687 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
693 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
694 if (tex
->fmask
.size
== 0)
695 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
699 if (zstex
&& zstex
->htile_buffer
&&
700 zsbuf
->u
.tex
.level
== 0 &&
701 zsbuf
->u
.tex
.first_layer
== 0 &&
702 zsbuf
->u
.tex
.last_layer
== util_max_layer(&zstex
->resource
.b
.b
, 0)) {
703 /* TC-compatible HTILE only supports depth clears to 0 or 1. */
704 if (buffers
& PIPE_CLEAR_DEPTH
&&
705 (!zstex
->tc_compatible_htile
||
706 depth
== 0 || depth
== 1)) {
707 /* Need to disable EXPCLEAR temporarily if clearing
709 if (!zstex
->depth_cleared
|| zstex
->depth_clear_value
!= depth
) {
710 sctx
->db_depth_disable_expclear
= true;
713 zstex
->depth_clear_value
= depth
;
714 sctx
->framebuffer
.dirty_zsbuf
= true;
715 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_DEPTH_CLEAR */
716 sctx
->db_depth_clear
= true;
717 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
720 /* TC-compatible HTILE only supports stencil clears to 0. */
721 if (buffers
& PIPE_CLEAR_STENCIL
&&
722 (!zstex
->tc_compatible_htile
|| stencil
== 0)) {
725 /* Need to disable EXPCLEAR temporarily if clearing
727 if (!zstex
->stencil_cleared
|| zstex
->stencil_clear_value
!= stencil
) {
728 sctx
->db_stencil_disable_expclear
= true;
731 zstex
->stencil_clear_value
= stencil
;
732 sctx
->framebuffer
.dirty_zsbuf
= true;
733 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_STENCIL_CLEAR */
734 sctx
->db_stencil_clear
= true;
735 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
739 si_blitter_begin(ctx
, SI_CLEAR
);
740 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
741 util_framebuffer_get_num_layers(fb
),
742 buffers
, color
, depth
, stencil
);
745 if (sctx
->db_depth_clear
) {
746 sctx
->db_depth_clear
= false;
747 sctx
->db_depth_disable_expclear
= false;
748 zstex
->depth_cleared
= true;
749 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
752 if (sctx
->db_stencil_clear
) {
753 sctx
->db_stencil_clear
= false;
754 sctx
->db_stencil_disable_expclear
= false;
755 zstex
->stencil_cleared
= true;
756 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
760 static void si_clear_render_target(struct pipe_context
*ctx
,
761 struct pipe_surface
*dst
,
762 const union pipe_color_union
*color
,
763 unsigned dstx
, unsigned dsty
,
764 unsigned width
, unsigned height
,
765 bool render_condition_enabled
)
767 struct si_context
*sctx
= (struct si_context
*)ctx
;
769 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
|
770 (render_condition_enabled
? 0 : SI_DISABLE_RENDER_COND
));
771 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
772 dstx
, dsty
, width
, height
);
776 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
777 struct pipe_surface
*dst
,
778 unsigned clear_flags
,
781 unsigned dstx
, unsigned dsty
,
782 unsigned width
, unsigned height
,
783 bool render_condition_enabled
)
785 struct si_context
*sctx
= (struct si_context
*)ctx
;
787 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
|
788 (render_condition_enabled
? 0 : SI_DISABLE_RENDER_COND
));
789 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
790 dstx
, dsty
, width
, height
);
794 /* Helper for decompressing a portion of a color or depth resource before
795 * blitting if any decompression is needed.
796 * The driver doesn't decompress resources automatically while u_blitter is
798 static void si_decompress_subresource(struct pipe_context
*ctx
,
799 struct pipe_resource
*tex
,
800 unsigned planes
, unsigned level
,
801 unsigned first_layer
, unsigned last_layer
)
803 struct si_context
*sctx
= (struct si_context
*)ctx
;
804 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
806 if (rtex
->db_compatible
) {
807 planes
&= PIPE_MASK_Z
| PIPE_MASK_S
;
809 if (!(rtex
->surface
.flags
& RADEON_SURF_SBUFFER
))
810 planes
&= ~PIPE_MASK_S
;
812 si_flush_depth_texture(sctx
, rtex
, planes
,
814 first_layer
, last_layer
);
815 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
|| rtex
->dcc_offset
) {
816 si_blit_decompress_color(ctx
, rtex
, level
, level
,
817 first_layer
, last_layer
, false);
821 struct texture_orig_info
{
831 void si_resource_copy_region(struct pipe_context
*ctx
,
832 struct pipe_resource
*dst
,
834 unsigned dstx
, unsigned dsty
, unsigned dstz
,
835 struct pipe_resource
*src
,
837 const struct pipe_box
*src_box
)
839 struct si_context
*sctx
= (struct si_context
*)ctx
;
840 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
841 struct pipe_surface
*dst_view
, dst_templ
;
842 struct pipe_sampler_view src_templ
, *src_view
;
843 unsigned dst_width
, dst_height
, src_width0
, src_height0
;
844 unsigned src_force_level
= 0;
845 struct pipe_box sbox
, dstbox
;
847 /* Handle buffers first. */
848 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
849 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
);
853 assert(u_max_sample(dst
) == u_max_sample(src
));
855 /* The driver doesn't decompress resources automatically while
856 * u_blitter is rendering. */
857 si_decompress_subresource(ctx
, src
, PIPE_MASK_RGBAZS
, src_level
,
858 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
860 dst_width
= u_minify(dst
->width0
, dst_level
);
861 dst_height
= u_minify(dst
->height0
, dst_level
);
862 src_width0
= src
->width0
;
863 src_height0
= src
->height0
;
865 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
866 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
868 if (util_format_is_compressed(src
->format
) ||
869 util_format_is_compressed(dst
->format
)) {
870 unsigned blocksize
= rsrc
->surface
.bpe
;
873 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
875 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
876 dst_templ
.format
= src_templ
.format
;
878 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
879 dst_height
= util_format_get_nblocksy(dst
->format
, dst_height
);
880 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
881 src_height0
= util_format_get_nblocksy(src
->format
, src_height0
);
883 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
884 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
886 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
887 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
889 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
890 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
891 sbox
.depth
= src_box
->depth
;
894 src_force_level
= src_level
;
895 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
) ||
896 /* also *8_SNORM has precision issues, use UNORM instead */
897 util_format_is_snorm8(src
->format
)) {
898 if (util_format_is_subsampled_422(src
->format
)) {
899 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
900 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
902 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
903 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
905 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
908 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
909 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
912 unsigned blocksize
= rsrc
->surface
.bpe
;
916 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
917 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
920 dst_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
921 src_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
924 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
925 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
928 dst_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
929 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
932 dst_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
933 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
936 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
937 util_format_short_name(src
->format
), blocksize
);
943 /* Initialize the surface. */
944 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
945 dst_width
, dst_height
);
947 /* Initialize the sampler view. */
948 src_view
= si_create_sampler_view_custom(ctx
, src
, &src_templ
,
949 src_width0
, src_height0
,
952 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
953 abs(src_box
->depth
), &dstbox
);
956 si_blitter_begin(ctx
, SI_COPY
);
957 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
958 src_view
, src_box
, src_width0
, src_height0
,
959 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
963 pipe_surface_reference(&dst_view
, NULL
);
964 pipe_sampler_view_reference(&src_view
, NULL
);
967 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
968 const struct pipe_blit_info
*info
)
970 struct si_context
*sctx
= (struct si_context
*)ctx
;
971 struct r600_texture
*src
= (struct r600_texture
*)info
->src
.resource
;
972 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
973 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
974 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
975 enum pipe_format format
= info
->src
.format
;
976 unsigned sample_mask
= ~0;
977 struct pipe_resource
*tmp
, templ
;
978 struct pipe_blit_info blit
;
980 /* Check basic requirements for hw resolve. */
981 if (!(info
->src
.resource
->nr_samples
> 1 &&
982 info
->dst
.resource
->nr_samples
<= 1 &&
983 !util_format_is_pure_integer(format
) &&
984 !util_format_is_depth_or_stencil(format
) &&
985 util_max_layer(info
->src
.resource
, 0) == 0))
988 /* Hardware MSAA resolve doesn't work if SPI format = NORM16_ABGR and
989 * the format is R16G16. Use R16A16, which does work.
991 if (format
== PIPE_FORMAT_R16G16_UNORM
)
992 format
= PIPE_FORMAT_R16A16_UNORM
;
993 if (format
== PIPE_FORMAT_R16G16_SNORM
)
994 format
= PIPE_FORMAT_R16A16_SNORM
;
996 /* Check the remaining requirements for hw resolve. */
997 if (util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
998 !info
->scissor_enable
&&
999 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
1000 util_is_format_compatible(util_format_description(info
->src
.format
),
1001 util_format_description(info
->dst
.format
)) &&
1002 dst_width
== info
->src
.resource
->width0
&&
1003 dst_height
== info
->src
.resource
->height0
&&
1004 info
->dst
.box
.x
== 0 &&
1005 info
->dst
.box
.y
== 0 &&
1006 info
->dst
.box
.width
== dst_width
&&
1007 info
->dst
.box
.height
== dst_height
&&
1008 info
->dst
.box
.depth
== 1 &&
1009 info
->src
.box
.x
== 0 &&
1010 info
->src
.box
.y
== 0 &&
1011 info
->src
.box
.width
== dst_width
&&
1012 info
->src
.box
.height
== dst_height
&&
1013 info
->src
.box
.depth
== 1 &&
1014 !dst
->surface
.is_linear
&&
1015 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
)) { /* dst cannot be fast-cleared */
1016 /* Check the last constraint. */
1017 if (src
->surface
.micro_tile_mode
!= dst
->surface
.micro_tile_mode
) {
1018 /* The next fast clear will switch to this mode to
1019 * get direct hw resolve next time if the mode is
1022 src
->last_msaa_resolve_target_micro_mode
=
1023 dst
->surface
.micro_tile_mode
;
1024 goto resolve_to_temp
;
1027 /* Resolving into a surface with DCC is unsupported. Since
1028 * it's being overwritten anyway, clear it to uncompressed.
1029 * This is still the fastest codepath even with this clear.
1031 if (dst
->dcc_offset
&&
1032 info
->dst
.level
< dst
->surface
.num_dcc_levels
) {
1033 vi_dcc_clear_level(&sctx
->b
, dst
, info
->dst
.level
,
1035 dst
->dirty_level_mask
&= ~(1 << info
->dst
.level
);
1038 /* Resolve directly from src to dst. */
1039 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
|
1040 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1041 util_blitter_custom_resolve_color(sctx
->blitter
,
1042 info
->dst
.resource
, info
->dst
.level
,
1044 info
->src
.resource
, info
->src
.box
.z
,
1045 sample_mask
, sctx
->custom_blend_resolve
,
1047 si_blitter_end(ctx
);
1052 /* Shader-based resolve is VERY SLOW. Instead, resolve into
1053 * a temporary texture and blit.
1055 memset(&templ
, 0, sizeof(templ
));
1056 templ
.target
= PIPE_TEXTURE_2D
;
1057 templ
.format
= info
->src
.resource
->format
;
1058 templ
.width0
= info
->src
.resource
->width0
;
1059 templ
.height0
= info
->src
.resource
->height0
;
1061 templ
.array_size
= 1;
1062 templ
.usage
= PIPE_USAGE_DEFAULT
;
1063 templ
.flags
= R600_RESOURCE_FLAG_FORCE_TILING
|
1064 R600_RESOURCE_FLAG_DISABLE_DCC
;
1066 /* The src and dst microtile modes must be the same. */
1067 if (src
->surface
.micro_tile_mode
== RADEON_MICRO_MODE_DISPLAY
)
1068 templ
.bind
= PIPE_BIND_SCANOUT
;
1072 tmp
= ctx
->screen
->resource_create(ctx
->screen
, &templ
);
1076 assert(src
->surface
.micro_tile_mode
==
1077 ((struct r600_texture
*)tmp
)->surface
.micro_tile_mode
);
1080 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
|
1081 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1082 util_blitter_custom_resolve_color(sctx
->blitter
, tmp
, 0, 0,
1083 info
->src
.resource
, info
->src
.box
.z
,
1084 sample_mask
, sctx
->custom_blend_resolve
,
1086 si_blitter_end(ctx
);
1090 blit
.src
.resource
= tmp
;
1093 si_blitter_begin(ctx
, SI_BLIT
|
1094 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1095 util_blitter_blit(sctx
->blitter
, &blit
);
1096 si_blitter_end(ctx
);
1098 pipe_resource_reference(&tmp
, NULL
);
1102 static void si_blit(struct pipe_context
*ctx
,
1103 const struct pipe_blit_info
*info
)
1105 struct si_context
*sctx
= (struct si_context
*)ctx
;
1106 struct r600_texture
*rdst
= (struct r600_texture
*)info
->dst
.resource
;
1108 if (do_hardware_msaa_resolve(ctx
, info
)) {
1112 /* Using SDMA for copying to a linear texture in GTT is much faster.
1113 * This improves DRI PRIME performance.
1115 * resource_copy_region can't do this yet, because dma_copy calls it
1116 * on failure (recursion).
1118 if (rdst
->surface
.is_linear
&&
1120 util_can_blit_via_copy_region(info
, false)) {
1121 sctx
->b
.dma_copy(ctx
, info
->dst
.resource
, info
->dst
.level
,
1122 info
->dst
.box
.x
, info
->dst
.box
.y
,
1124 info
->src
.resource
, info
->src
.level
,
1129 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
1131 /* The driver doesn't decompress resources automatically while
1132 * u_blitter is rendering. */
1133 vi_dcc_disable_if_incompatible_format(&sctx
->b
, info
->src
.resource
,
1136 vi_dcc_disable_if_incompatible_format(&sctx
->b
, info
->dst
.resource
,
1139 si_decompress_subresource(ctx
, info
->src
.resource
, info
->mask
,
1142 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
1144 if (sctx
->screen
->b
.debug_flags
& DBG_FORCE_DMA
&&
1145 util_try_blit_via_copy_region(ctx
, info
))
1148 si_blitter_begin(ctx
, SI_BLIT
|
1149 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
1150 util_blitter_blit(sctx
->blitter
, info
);
1151 si_blitter_end(ctx
);
1154 static boolean
si_generate_mipmap(struct pipe_context
*ctx
,
1155 struct pipe_resource
*tex
,
1156 enum pipe_format format
,
1157 unsigned base_level
, unsigned last_level
,
1158 unsigned first_layer
, unsigned last_layer
)
1160 struct si_context
*sctx
= (struct si_context
*)ctx
;
1161 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
1163 if (!util_blitter_is_copy_supported(sctx
->blitter
, tex
, tex
))
1166 /* The driver doesn't decompress resources automatically while
1167 * u_blitter is rendering. */
1168 vi_dcc_disable_if_incompatible_format(&sctx
->b
, tex
, base_level
,
1170 si_decompress_subresource(ctx
, tex
, PIPE_MASK_RGBAZS
,
1171 base_level
, first_layer
, last_layer
);
1173 /* Clear dirty_level_mask for the levels that will be overwritten. */
1174 assert(base_level
< last_level
);
1175 rtex
->dirty_level_mask
&= ~u_bit_consecutive(base_level
+ 1,
1176 last_level
- base_level
);
1178 si_blitter_begin(ctx
, SI_BLIT
| SI_DISABLE_RENDER_COND
);
1179 util_blitter_generate_mipmap(sctx
->blitter
, tex
, format
,
1180 base_level
, last_level
,
1181 first_layer
, last_layer
);
1182 si_blitter_end(ctx
);
1186 static void si_flush_resource(struct pipe_context
*ctx
,
1187 struct pipe_resource
*res
)
1189 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
1191 assert(res
->target
!= PIPE_BUFFER
);
1192 assert(!rtex
->dcc_separate_buffer
|| rtex
->dcc_gather_statistics
);
1194 /* st/dri calls flush twice per frame (not a bug), this prevents double
1196 if (rtex
->dcc_separate_buffer
&& !rtex
->separate_dcc_dirty
)
1199 if (!rtex
->is_depth
&& (rtex
->cmask
.size
|| rtex
->dcc_offset
)) {
1200 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
1201 0, util_max_layer(res
, 0),
1202 rtex
->dcc_separate_buffer
!= NULL
);
1205 /* Always do the analysis even if DCC is disabled at the moment. */
1206 if (rtex
->dcc_gather_statistics
&& rtex
->separate_dcc_dirty
) {
1207 rtex
->separate_dcc_dirty
= false;
1208 vi_separate_dcc_process_and_reset_stats(ctx
, rtex
);
1212 static void si_decompress_dcc(struct pipe_context
*ctx
,
1213 struct r600_texture
*rtex
)
1215 if (!rtex
->dcc_offset
)
1218 si_blit_decompress_color(ctx
, rtex
, 0, rtex
->resource
.b
.b
.last_level
,
1219 0, util_max_layer(&rtex
->resource
.b
.b
, 0),
1223 static void si_pipe_clear_buffer(struct pipe_context
*ctx
,
1224 struct pipe_resource
*dst
,
1225 unsigned offset
, unsigned size
,
1226 const void *clear_value_ptr
,
1227 int clear_value_size
)
1229 struct si_context
*sctx
= (struct si_context
*)ctx
;
1230 uint32_t dword_value
;
1233 assert(offset
% clear_value_size
== 0);
1234 assert(size
% clear_value_size
== 0);
1236 if (clear_value_size
> 4) {
1237 const uint32_t *u32
= clear_value_ptr
;
1238 bool clear_dword_duplicated
= true;
1240 /* See if we can lower large fills to dword fills. */
1241 for (i
= 1; i
< clear_value_size
/ 4; i
++)
1242 if (u32
[0] != u32
[i
]) {
1243 clear_dword_duplicated
= false;
1247 if (!clear_dword_duplicated
) {
1248 /* Use transform feedback for 64-bit, 96-bit, and
1251 union pipe_color_union clear_value
;
1253 memcpy(&clear_value
, clear_value_ptr
, clear_value_size
);
1254 si_blitter_begin(ctx
, SI_DISABLE_RENDER_COND
);
1255 util_blitter_clear_buffer(sctx
->blitter
, dst
, offset
,
1256 size
, clear_value_size
/ 4,
1258 si_blitter_end(ctx
);
1263 /* Expand the clear value to a dword. */
1264 switch (clear_value_size
) {
1266 dword_value
= *(uint8_t*)clear_value_ptr
;
1267 dword_value
|= (dword_value
<< 8) |
1268 (dword_value
<< 16) |
1269 (dword_value
<< 24);
1272 dword_value
= *(uint16_t*)clear_value_ptr
;
1273 dword_value
|= dword_value
<< 16;
1276 dword_value
= *(uint32_t*)clear_value_ptr
;
1279 sctx
->b
.clear_buffer(ctx
, dst
, offset
, size
, dword_value
,
1280 R600_COHERENCY_SHADER
);
1283 void si_init_blit_functions(struct si_context
*sctx
)
1285 sctx
->b
.b
.clear
= si_clear
;
1286 sctx
->b
.b
.clear_buffer
= si_pipe_clear_buffer
;
1287 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
1288 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
1289 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
1290 sctx
->b
.b
.blit
= si_blit
;
1291 sctx
->b
.b
.flush_resource
= si_flush_resource
;
1292 sctx
->b
.b
.generate_mipmap
= si_generate_mipmap
;
1293 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;
1294 sctx
->b
.decompress_dcc
= si_decompress_dcc
;