2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "util/u_format.h"
26 #include "util/u_surface.h"
28 enum si_blitter_op
/* bitmask */
31 SI_SAVE_FRAMEBUFFER
= 2,
32 SI_DISABLE_RENDER_COND
= 4,
36 SI_CLEAR_SURFACE
= SI_SAVE_FRAMEBUFFER
,
38 SI_COPY
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
|
39 SI_DISABLE_RENDER_COND
,
41 SI_BLIT
= SI_SAVE_FRAMEBUFFER
| SI_SAVE_TEXTURES
,
43 SI_DECOMPRESS
= SI_SAVE_FRAMEBUFFER
| SI_DISABLE_RENDER_COND
,
45 SI_COLOR_RESOLVE
= SI_SAVE_FRAMEBUFFER
48 static void si_blitter_begin(struct pipe_context
*ctx
, enum si_blitter_op op
)
50 struct si_context
*sctx
= (struct si_context
*)ctx
;
52 r600_suspend_nontimer_queries(&sctx
->b
);
54 util_blitter_save_blend(sctx
->blitter
, sctx
->queued
.named
.blend
);
55 util_blitter_save_depth_stencil_alpha(sctx
->blitter
, sctx
->queued
.named
.dsa
);
56 util_blitter_save_stencil_ref(sctx
->blitter
, &sctx
->stencil_ref
);
57 util_blitter_save_rasterizer(sctx
->blitter
, sctx
->queued
.named
.rasterizer
);
58 util_blitter_save_fragment_shader(sctx
->blitter
, sctx
->ps_shader
);
59 util_blitter_save_geometry_shader(sctx
->blitter
, sctx
->gs_shader
);
60 util_blitter_save_tessctrl_shader(sctx
->blitter
, sctx
->tcs_shader
);
61 util_blitter_save_tesseval_shader(sctx
->blitter
, sctx
->tes_shader
);
62 util_blitter_save_vertex_shader(sctx
->blitter
, sctx
->vs_shader
);
63 util_blitter_save_vertex_elements(sctx
->blitter
, sctx
->vertex_elements
);
64 if (sctx
->queued
.named
.sample_mask
) {
65 util_blitter_save_sample_mask(sctx
->blitter
,
66 sctx
->queued
.named
.sample_mask
->sample_mask
);
68 util_blitter_save_viewport(sctx
->blitter
, &sctx
->viewports
.states
[0]);
69 util_blitter_save_scissor(sctx
->blitter
, &sctx
->scissors
.states
[0]);
70 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
71 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
72 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
74 if (op
& SI_SAVE_FRAMEBUFFER
)
75 util_blitter_save_framebuffer(sctx
->blitter
, &sctx
->framebuffer
.state
);
77 if (op
& SI_SAVE_TEXTURES
) {
78 util_blitter_save_fragment_sampler_states(
80 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.saved_states
);
82 util_blitter_save_fragment_sampler_views(sctx
->blitter
, 2,
83 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
86 if ((op
& SI_DISABLE_RENDER_COND
) && sctx
->b
.current_render_cond
) {
87 util_blitter_save_render_condition(sctx
->blitter
,
88 sctx
->b
.current_render_cond
,
89 sctx
->b
.current_render_cond_cond
,
90 sctx
->b
.current_render_cond_mode
);
94 static void si_blitter_end(struct pipe_context
*ctx
)
96 struct si_context
*sctx
= (struct si_context
*)ctx
;
97 r600_resume_nontimer_queries(&sctx
->b
);
100 static unsigned u_max_sample(struct pipe_resource
*r
)
102 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
105 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
106 struct r600_texture
*texture
,
107 struct r600_texture
*staging
,
108 unsigned first_level
, unsigned last_level
,
109 unsigned first_layer
, unsigned last_layer
,
110 unsigned first_sample
, unsigned last_sample
)
112 struct si_context
*sctx
= (struct si_context
*)ctx
;
113 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
115 const struct util_format_description
*desc
;
116 struct r600_texture
*flushed_depth_texture
= staging
?
117 staging
: texture
->flushed_depth_texture
;
119 if (!staging
&& !texture
->dirty_level_mask
)
122 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
124 desc
= util_format_description(flushed_depth_texture
->resource
.b
.b
.format
);
126 if (util_format_has_depth(desc
))
127 sctx
->dbcb_depth_copy_enabled
= true;
128 if (util_format_has_stencil(desc
))
129 sctx
->dbcb_stencil_copy_enabled
= true;
131 assert(sctx
->dbcb_depth_copy_enabled
|| sctx
->dbcb_stencil_copy_enabled
);
133 for (level
= first_level
; level
<= last_level
; level
++) {
134 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
137 /* The smaller the mipmap level, the less layers there are
138 * as far as 3D textures are concerned. */
139 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
140 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
142 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
143 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
144 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
146 sctx
->dbcb_copy_sample
= sample
;
147 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
149 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
150 surf_tmpl
.u
.tex
.level
= level
;
151 surf_tmpl
.u
.tex
.first_layer
= layer
;
152 surf_tmpl
.u
.tex
.last_layer
= layer
;
154 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
156 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
157 cbsurf
= ctx
->create_surface(ctx
,
158 (struct pipe_resource
*)flushed_depth_texture
, &surf_tmpl
);
160 si_blitter_begin(ctx
, SI_DECOMPRESS
);
161 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
162 sctx
->custom_dsa_flush
, depth
);
165 pipe_surface_reference(&zsurf
, NULL
);
166 pipe_surface_reference(&cbsurf
, NULL
);
170 /* The texture will always be dirty if some layers aren't flushed.
171 * I don't think this case can occur though. */
173 first_layer
== 0 && last_layer
== max_layer
&&
174 first_sample
== 0 && last_sample
== max_sample
) {
175 texture
->dirty_level_mask
&= ~(1 << level
);
179 sctx
->dbcb_depth_copy_enabled
= false;
180 sctx
->dbcb_stencil_copy_enabled
= false;
181 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
184 static void si_blit_decompress_depth_in_place(struct si_context
*sctx
,
185 struct r600_texture
*texture
,
186 unsigned first_level
, unsigned last_level
,
187 unsigned first_layer
, unsigned last_layer
)
189 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
190 unsigned layer
, max_layer
, checked_last_layer
, level
;
192 sctx
->db_inplace_flush_enabled
= true;
193 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
195 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
197 for (level
= first_level
; level
<= last_level
; level
++) {
198 if (!(texture
->dirty_level_mask
& (1 << level
)))
201 surf_tmpl
.u
.tex
.level
= level
;
203 /* The smaller the mipmap level, the less layers there are
204 * as far as 3D textures are concerned. */
205 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
206 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
208 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
209 surf_tmpl
.u
.tex
.first_layer
= layer
;
210 surf_tmpl
.u
.tex
.last_layer
= layer
;
212 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
214 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
215 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
216 sctx
->custom_dsa_flush
,
218 si_blitter_end(&sctx
->b
.b
);
220 pipe_surface_reference(&zsurf
, NULL
);
223 /* The texture will always be dirty if some layers aren't flushed.
224 * I don't think this case occurs often though. */
225 if (first_layer
== 0 && last_layer
== max_layer
) {
226 texture
->dirty_level_mask
&= ~(1 << level
);
230 sctx
->db_inplace_flush_enabled
= false;
231 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
234 void si_flush_depth_textures(struct si_context
*sctx
,
235 struct si_textures_info
*textures
)
238 unsigned mask
= textures
->depth_texture_mask
;
241 struct pipe_sampler_view
*view
;
242 struct r600_texture
*tex
;
244 i
= u_bit_scan(&mask
);
246 view
= textures
->views
.views
[i
];
249 tex
= (struct r600_texture
*)view
->texture
;
250 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
252 si_blit_decompress_depth_in_place(sctx
, tex
,
253 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
254 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
258 static void si_blit_decompress_color(struct pipe_context
*ctx
,
259 struct r600_texture
*rtex
,
260 unsigned first_level
, unsigned last_level
,
261 unsigned first_layer
, unsigned last_layer
)
263 struct si_context
*sctx
= (struct si_context
*)ctx
;
264 unsigned layer
, level
, checked_last_layer
, max_layer
;
266 if (!rtex
->dirty_level_mask
)
269 for (level
= first_level
; level
<= last_level
; level
++) {
270 if (!(rtex
->dirty_level_mask
& (1 << level
)))
273 /* The smaller the mipmap level, the less layers there are
274 * as far as 3D textures are concerned. */
275 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
276 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
278 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
279 struct pipe_surface
*cbsurf
, surf_tmpl
;
281 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
282 surf_tmpl
.u
.tex
.level
= level
;
283 surf_tmpl
.u
.tex
.first_layer
= layer
;
284 surf_tmpl
.u
.tex
.last_layer
= layer
;
285 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
287 si_blitter_begin(ctx
, SI_DECOMPRESS
);
288 util_blitter_custom_color(sctx
->blitter
, cbsurf
,
289 rtex
->fmask
.size
? sctx
->custom_blend_decompress
:
290 sctx
->custom_blend_fastclear
);
293 pipe_surface_reference(&cbsurf
, NULL
);
296 /* The texture will always be dirty if some layers aren't flushed.
297 * I don't think this case occurs often though. */
298 if (first_layer
== 0 && last_layer
== max_layer
) {
299 rtex
->dirty_level_mask
&= ~(1 << level
);
304 void si_decompress_color_textures(struct si_context
*sctx
,
305 struct si_textures_info
*textures
)
308 unsigned mask
= textures
->compressed_colortex_mask
;
311 struct pipe_sampler_view
*view
;
312 struct r600_texture
*tex
;
314 i
= u_bit_scan(&mask
);
316 view
= textures
->views
.views
[i
];
319 tex
= (struct r600_texture
*)view
->texture
;
320 assert(tex
->cmask
.size
|| tex
->fmask
.size
);
322 si_blit_decompress_color(&sctx
->b
.b
, tex
,
323 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
324 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
328 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
329 const union pipe_color_union
*color
,
330 double depth
, unsigned stencil
)
332 struct si_context
*sctx
= (struct si_context
*)ctx
;
333 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
334 struct pipe_surface
*zsbuf
= fb
->zsbuf
;
335 struct r600_texture
*zstex
=
336 zsbuf
? (struct r600_texture
*)zsbuf
->texture
: NULL
;
338 if (buffers
& PIPE_CLEAR_COLOR
) {
339 evergreen_do_fast_color_clear(&sctx
->b
, fb
, &sctx
->framebuffer
.atom
,
342 return; /* all buffers have been fast cleared */
345 if (buffers
& PIPE_CLEAR_COLOR
) {
348 /* These buffers cannot use fast clear, make sure to disable expansion. */
349 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
350 struct r600_texture
*tex
;
352 /* If not clearing this buffer, skip. */
353 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
359 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
360 if (tex
->fmask
.size
== 0)
361 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
365 if (buffers
& PIPE_CLEAR_DEPTH
&&
366 zstex
&& zstex
->htile_buffer
&&
367 zsbuf
->u
.tex
.level
== 0 &&
368 zsbuf
->u
.tex
.first_layer
== 0 &&
369 zsbuf
->u
.tex
.last_layer
== util_max_layer(&zstex
->resource
.b
.b
, 0)) {
370 /* Need to disable EXPCLEAR temporarily if clearing
372 if (zstex
->depth_cleared
&& zstex
->depth_clear_value
!= depth
) {
373 sctx
->db_depth_disable_expclear
= true;
376 zstex
->depth_clear_value
= depth
;
377 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
); /* updates DB_DEPTH_CLEAR */
378 sctx
->db_depth_clear
= true;
379 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
382 si_blitter_begin(ctx
, SI_CLEAR
);
383 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
384 util_framebuffer_get_num_layers(fb
),
385 buffers
, color
, depth
, stencil
);
388 if (sctx
->db_depth_clear
) {
389 sctx
->db_depth_clear
= false;
390 sctx
->db_depth_disable_expclear
= false;
391 zstex
->depth_cleared
= true;
392 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
396 static void si_clear_render_target(struct pipe_context
*ctx
,
397 struct pipe_surface
*dst
,
398 const union pipe_color_union
*color
,
399 unsigned dstx
, unsigned dsty
,
400 unsigned width
, unsigned height
)
402 struct si_context
*sctx
= (struct si_context
*)ctx
;
404 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
405 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
406 dstx
, dsty
, width
, height
);
410 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
411 struct pipe_surface
*dst
,
412 unsigned clear_flags
,
415 unsigned dstx
, unsigned dsty
,
416 unsigned width
, unsigned height
)
418 struct si_context
*sctx
= (struct si_context
*)ctx
;
420 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
421 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
422 dstx
, dsty
, width
, height
);
426 /* Helper for decompressing a portion of a color or depth resource before
427 * blitting if any decompression is needed.
428 * The driver doesn't decompress resources automatically while u_blitter is
430 static void si_decompress_subresource(struct pipe_context
*ctx
,
431 struct pipe_resource
*tex
,
433 unsigned first_layer
, unsigned last_layer
)
435 struct si_context
*sctx
= (struct si_context
*)ctx
;
436 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
438 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
439 si_blit_decompress_depth_in_place(sctx
, rtex
,
441 first_layer
, last_layer
);
442 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
) {
443 si_blit_decompress_color(ctx
, rtex
, level
, level
,
444 first_layer
, last_layer
);
448 struct texture_orig_info
{
458 void si_resource_copy_region(struct pipe_context
*ctx
,
459 struct pipe_resource
*dst
,
461 unsigned dstx
, unsigned dsty
, unsigned dstz
,
462 struct pipe_resource
*src
,
464 const struct pipe_box
*src_box
)
466 struct si_context
*sctx
= (struct si_context
*)ctx
;
467 struct pipe_surface
*dst_view
, dst_templ
;
468 struct pipe_sampler_view src_templ
, *src_view
;
469 unsigned dst_width
, dst_height
, src_width0
, src_height0
;
470 unsigned src_force_level
= 0;
471 struct pipe_box sbox
, dstbox
;
473 /* Handle buffers first. */
474 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
475 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
, false);
479 assert(u_max_sample(dst
) == u_max_sample(src
));
481 /* The driver doesn't decompress resources automatically while
482 * u_blitter is rendering. */
483 si_decompress_subresource(ctx
, src
, src_level
,
484 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
486 dst_width
= u_minify(dst
->width0
, dst_level
);
487 dst_height
= u_minify(dst
->height0
, dst_level
);
488 src_width0
= src
->width0
;
489 src_height0
= src
->height0
;
491 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
492 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
494 if (util_format_is_compressed(src
->format
) &&
495 util_format_is_compressed(dst
->format
)) {
496 unsigned blocksize
= util_format_get_blocksize(src
->format
);
499 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
501 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
502 dst_templ
.format
= src_templ
.format
;
504 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
505 dst_height
= util_format_get_nblocksy(dst
->format
, dst_height
);
506 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
507 src_height0
= util_format_get_nblocksy(src
->format
, src_height0
);
509 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
510 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
512 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
513 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
515 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
516 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
517 sbox
.depth
= src_box
->depth
;
520 src_force_level
= src_level
;
521 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
) ||
522 /* also *8_SNORM has precision issues, use UNORM instead */
523 util_format_is_snorm(src
->format
)) {
524 if (util_format_is_subsampled_422(src
->format
)) {
525 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
526 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
528 dst_width
= util_format_get_nblocksx(dst
->format
, dst_width
);
529 src_width0
= util_format_get_nblocksx(src
->format
, src_width0
);
531 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
534 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
535 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
538 unsigned blocksize
= util_format_get_blocksize(src
->format
);
542 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
543 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
546 dst_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
547 src_templ
.format
= PIPE_FORMAT_R8G8_UNORM
;
550 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
551 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
554 dst_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
555 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
;
558 dst_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
559 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
;
562 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
563 util_format_short_name(src
->format
), blocksize
);
569 /* Initialize the surface. */
570 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
571 dst_width
, dst_height
);
573 /* Initialize the sampler view. */
574 src_view
= si_create_sampler_view_custom(ctx
, src
, &src_templ
,
575 src_width0
, src_height0
,
578 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
579 abs(src_box
->depth
), &dstbox
);
582 si_blitter_begin(ctx
, SI_COPY
);
583 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
584 src_view
, src_box
, src_width0
, src_height0
,
585 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
589 pipe_surface_reference(&dst_view
, NULL
);
590 pipe_sampler_view_reference(&src_view
, NULL
);
593 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
594 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
597 #define REPLACE_FORMAT_SIGN(format,sign) \
598 case PIPE_FORMAT_##format##_##sign##INT: \
599 return PIPE_FORMAT_##format##_##sign##NORM
600 #define REPLACE_FORMAT(format) \
601 REPLACE_FORMAT_SIGN(format, U); \
602 REPLACE_FORMAT_SIGN(format, S)
604 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
606 REPLACE_FORMAT(R8G8
);
607 REPLACE_FORMAT(R8G8B8X8
);
608 REPLACE_FORMAT(R8G8B8A8
);
612 REPLACE_FORMAT(L8A8
);
614 REPLACE_FORMAT(R16G16
);
615 REPLACE_FORMAT(R16G16B16X16
);
616 REPLACE_FORMAT(R16G16B16A16
);
620 REPLACE_FORMAT(L16A16
);
622 #undef REPLACE_FORMAT
623 #undef REPLACE_FORMAT_SIGN
629 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
630 const struct pipe_blit_info
*info
)
632 struct si_context
*sctx
= (struct si_context
*)ctx
;
633 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
634 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
635 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
636 enum pipe_format format
= int_to_norm_format(info
->dst
.format
);
637 unsigned sample_mask
= ~0;
639 if (info
->src
.resource
->nr_samples
> 1 &&
640 info
->dst
.resource
->nr_samples
<= 1 &&
641 util_max_layer(info
->src
.resource
, 0) == 0 &&
642 util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
643 info
->dst
.format
== info
->src
.format
&&
644 !util_format_is_pure_integer(format
) &&
645 !util_format_is_depth_or_stencil(format
) &&
646 !info
->scissor_enable
&&
647 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
648 dst_width
== info
->src
.resource
->width0
&&
649 dst_height
== info
->src
.resource
->height0
&&
650 info
->dst
.box
.x
== 0 &&
651 info
->dst
.box
.y
== 0 &&
652 info
->dst
.box
.width
== dst_width
&&
653 info
->dst
.box
.height
== dst_height
&&
654 info
->dst
.box
.depth
== 1 &&
655 info
->src
.box
.x
== 0 &&
656 info
->src
.box
.y
== 0 &&
657 info
->src
.box
.width
== dst_width
&&
658 info
->src
.box
.height
== dst_height
&&
659 info
->src
.box
.depth
== 1 &&
660 dst
->surface
.level
[info
->dst
.level
].mode
>= RADEON_SURF_MODE_1D
&&
661 !(dst
->surface
.flags
& RADEON_SURF_SCANOUT
) &&
662 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
) /* dst cannot be fast-cleared */) {
663 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
|
664 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
665 util_blitter_custom_resolve_color(sctx
->blitter
,
666 info
->dst
.resource
, info
->dst
.level
,
668 info
->src
.resource
, info
->src
.box
.z
,
669 sample_mask
, sctx
->custom_blend_resolve
,
677 static void si_blit(struct pipe_context
*ctx
,
678 const struct pipe_blit_info
*info
)
680 struct si_context
*sctx
= (struct si_context
*)ctx
;
682 if (do_hardware_msaa_resolve(ctx
, info
)) {
686 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
688 /* The driver doesn't decompress resources automatically while
689 * u_blitter is rendering. */
690 si_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
692 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
694 if (sctx
->screen
->b
.debug_flags
& DBG_FORCE_DMA
&&
695 util_try_blit_via_copy_region(ctx
, info
))
698 si_blitter_begin(ctx
, SI_BLIT
|
699 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
700 util_blitter_blit(sctx
->blitter
, info
);
704 static void si_flush_resource(struct pipe_context
*ctx
,
705 struct pipe_resource
*res
)
707 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
709 assert(res
->target
!= PIPE_BUFFER
);
711 if (!rtex
->is_depth
&& rtex
->cmask
.size
) {
712 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
713 0, util_max_layer(res
, 0));
717 void si_init_blit_functions(struct si_context
*sctx
)
719 sctx
->b
.b
.clear
= si_clear
;
720 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
721 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
722 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
723 sctx
->b
.b
.blit
= si_blit
;
724 sctx
->b
.b
.flush_resource
= si_flush_resource
;
725 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;