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_vertex_shader(sctx
->blitter
, sctx
->vs_shader
);
61 util_blitter_save_vertex_elements(sctx
->blitter
, sctx
->vertex_elements
);
62 if (sctx
->queued
.named
.sample_mask
) {
63 util_blitter_save_sample_mask(sctx
->blitter
,
64 sctx
->queued
.named
.sample_mask
->sample_mask
);
66 if (sctx
->queued
.named
.viewport
) {
67 util_blitter_save_viewport(sctx
->blitter
, &sctx
->queued
.named
.viewport
->viewport
);
69 if (sctx
->queued
.named
.scissor
) {
70 util_blitter_save_scissor(sctx
->blitter
, &sctx
->queued
.named
.scissor
->scissor
);
72 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
73 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
74 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
76 if (op
& SI_SAVE_FRAMEBUFFER
)
77 util_blitter_save_framebuffer(sctx
->blitter
, &sctx
->framebuffer
.state
);
79 if (op
& SI_SAVE_TEXTURES
) {
80 util_blitter_save_fragment_sampler_states(
82 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.saved_states
);
84 util_blitter_save_fragment_sampler_views(sctx
->blitter
, 2,
85 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
88 if ((op
& SI_DISABLE_RENDER_COND
) && sctx
->b
.current_render_cond
) {
89 util_blitter_save_render_condition(sctx
->blitter
,
90 sctx
->b
.current_render_cond
,
91 sctx
->b
.current_render_cond_cond
,
92 sctx
->b
.current_render_cond_mode
);
96 static void si_blitter_end(struct pipe_context
*ctx
)
98 struct si_context
*sctx
= (struct si_context
*)ctx
;
99 r600_resume_nontimer_queries(&sctx
->b
);
102 static unsigned u_max_sample(struct pipe_resource
*r
)
104 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
107 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
108 struct r600_texture
*texture
,
109 struct r600_texture
*staging
,
110 unsigned first_level
, unsigned last_level
,
111 unsigned first_layer
, unsigned last_layer
,
112 unsigned first_sample
, unsigned last_sample
)
114 struct si_context
*sctx
= (struct si_context
*)ctx
;
115 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
117 const struct util_format_description
*desc
;
118 struct r600_texture
*flushed_depth_texture
= staging
?
119 staging
: texture
->flushed_depth_texture
;
121 if (!staging
&& !texture
->dirty_level_mask
)
124 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
126 desc
= util_format_description(flushed_depth_texture
->resource
.b
.b
.format
);
128 if (util_format_has_depth(desc
))
129 sctx
->dbcb_depth_copy_enabled
= true;
130 if (util_format_has_stencil(desc
))
131 sctx
->dbcb_stencil_copy_enabled
= true;
133 assert(sctx
->dbcb_depth_copy_enabled
|| sctx
->dbcb_stencil_copy_enabled
);
135 for (level
= first_level
; level
<= last_level
; level
++) {
136 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
139 /* The smaller the mipmap level, the less layers there are
140 * as far as 3D textures are concerned. */
141 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
142 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
144 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
145 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
146 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
148 sctx
->dbcb_copy_sample
= sample
;
149 sctx
->db_render_state
.dirty
= true;
151 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
152 surf_tmpl
.u
.tex
.level
= level
;
153 surf_tmpl
.u
.tex
.first_layer
= layer
;
154 surf_tmpl
.u
.tex
.last_layer
= layer
;
156 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
158 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
159 cbsurf
= ctx
->create_surface(ctx
,
160 (struct pipe_resource
*)flushed_depth_texture
, &surf_tmpl
);
162 si_blitter_begin(ctx
, SI_DECOMPRESS
);
163 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
164 sctx
->custom_dsa_flush
, depth
);
167 pipe_surface_reference(&zsurf
, NULL
);
168 pipe_surface_reference(&cbsurf
, NULL
);
172 /* The texture will always be dirty if some layers aren't flushed.
173 * I don't think this case can occur though. */
175 first_layer
== 0 && last_layer
== max_layer
&&
176 first_sample
== 0 && last_sample
== max_sample
) {
177 texture
->dirty_level_mask
&= ~(1 << level
);
181 sctx
->dbcb_depth_copy_enabled
= false;
182 sctx
->dbcb_stencil_copy_enabled
= false;
183 sctx
->db_render_state
.dirty
= true;
186 static void si_blit_decompress_depth_in_place(struct si_context
*sctx
,
187 struct r600_texture
*texture
,
188 unsigned first_level
, unsigned last_level
,
189 unsigned first_layer
, unsigned last_layer
)
191 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
192 unsigned layer
, max_layer
, checked_last_layer
, level
;
194 sctx
->db_inplace_flush_enabled
= true;
195 sctx
->db_render_state
.dirty
= true;
197 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
199 for (level
= first_level
; level
<= last_level
; level
++) {
200 if (!(texture
->dirty_level_mask
& (1 << level
)))
203 surf_tmpl
.u
.tex
.level
= level
;
205 /* The smaller the mipmap level, the less layers there are
206 * as far as 3D textures are concerned. */
207 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
208 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
210 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
211 surf_tmpl
.u
.tex
.first_layer
= layer
;
212 surf_tmpl
.u
.tex
.last_layer
= layer
;
214 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
216 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
217 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
218 sctx
->custom_dsa_flush
,
220 si_blitter_end(&sctx
->b
.b
);
222 pipe_surface_reference(&zsurf
, NULL
);
225 /* The texture will always be dirty if some layers aren't flushed.
226 * I don't think this case occurs often though. */
227 if (first_layer
== 0 && last_layer
== max_layer
) {
228 texture
->dirty_level_mask
&= ~(1 << level
);
232 sctx
->db_inplace_flush_enabled
= false;
233 sctx
->db_render_state
.dirty
= true;
236 void si_flush_depth_textures(struct si_context
*sctx
,
237 struct si_textures_info
*textures
)
240 unsigned mask
= textures
->depth_texture_mask
;
243 struct pipe_sampler_view
*view
;
244 struct r600_texture
*tex
;
246 i
= u_bit_scan(&mask
);
248 view
= textures
->views
.views
[i
];
251 tex
= (struct r600_texture
*)view
->texture
;
252 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
254 si_blit_decompress_depth_in_place(sctx
, tex
,
255 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
256 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
260 static void si_blit_decompress_color(struct pipe_context
*ctx
,
261 struct r600_texture
*rtex
,
262 unsigned first_level
, unsigned last_level
,
263 unsigned first_layer
, unsigned last_layer
)
265 struct si_context
*sctx
= (struct si_context
*)ctx
;
266 unsigned layer
, level
, checked_last_layer
, max_layer
;
268 if (!rtex
->dirty_level_mask
)
271 for (level
= first_level
; level
<= last_level
; level
++) {
272 if (!(rtex
->dirty_level_mask
& (1 << level
)))
275 /* The smaller the mipmap level, the less layers there are
276 * as far as 3D textures are concerned. */
277 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
278 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
280 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
281 struct pipe_surface
*cbsurf
, surf_tmpl
;
283 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
284 surf_tmpl
.u
.tex
.level
= level
;
285 surf_tmpl
.u
.tex
.first_layer
= layer
;
286 surf_tmpl
.u
.tex
.last_layer
= layer
;
287 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
289 si_blitter_begin(ctx
, SI_DECOMPRESS
);
290 util_blitter_custom_color(sctx
->blitter
, cbsurf
,
291 rtex
->fmask
.size
? sctx
->custom_blend_decompress
:
292 sctx
->custom_blend_fastclear
);
295 pipe_surface_reference(&cbsurf
, NULL
);
298 /* The texture will always be dirty if some layers aren't flushed.
299 * I don't think this case occurs often though. */
300 if (first_layer
== 0 && last_layer
== max_layer
) {
301 rtex
->dirty_level_mask
&= ~(1 << level
);
306 void si_decompress_color_textures(struct si_context
*sctx
,
307 struct si_textures_info
*textures
)
310 unsigned mask
= textures
->compressed_colortex_mask
;
313 struct pipe_sampler_view
*view
;
314 struct r600_texture
*tex
;
316 i
= u_bit_scan(&mask
);
318 view
= textures
->views
.views
[i
];
321 tex
= (struct r600_texture
*)view
->texture
;
322 assert(tex
->cmask
.size
|| tex
->fmask
.size
);
324 si_blit_decompress_color(&sctx
->b
.b
, tex
,
325 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
326 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
330 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
331 const union pipe_color_union
*color
,
332 double depth
, unsigned stencil
)
334 struct si_context
*sctx
= (struct si_context
*)ctx
;
335 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
336 struct pipe_surface
*zsbuf
= fb
->zsbuf
;
337 struct r600_texture
*zstex
=
338 zsbuf
? (struct r600_texture
*)zsbuf
->texture
: NULL
;
340 if (buffers
& PIPE_CLEAR_COLOR
) {
341 evergreen_do_fast_color_clear(&sctx
->b
, fb
, &sctx
->framebuffer
.atom
,
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 sctx
->framebuffer
.atom
.dirty
= true; /* updates DB_DEPTH_CLEAR */
378 sctx
->db_depth_clear
= true;
379 sctx
->db_render_state
.dirty
= true;
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 sctx
->db_render_state
.dirty
= true;
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 static void si_compressed_to_blittable(struct pipe_resource
*tex
,
460 struct texture_orig_info
*orig
)
462 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
463 unsigned pixsize
= util_format_get_blocksize(rtex
->resource
.b
.b
.format
);
465 int new_height
, new_width
;
467 orig
->format
= tex
->format
;
468 orig
->width0
= tex
->width0
;
469 orig
->height0
= tex
->height0
;
470 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
471 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
472 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
473 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
476 new_format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
478 new_format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
480 new_width
= util_format_get_nblocksx(tex
->format
, orig
->width0
);
481 new_height
= util_format_get_nblocksy(tex
->format
, orig
->height0
);
483 tex
->width0
= new_width
;
484 tex
->height0
= new_height
;
485 tex
->format
= new_format
;
486 rtex
->surface
.level
[0].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix0_x
);
487 rtex
->surface
.level
[0].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix0_y
);
488 rtex
->surface
.level
[level
].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix_x
);
489 rtex
->surface
.level
[level
].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix_y
);
491 /* By dividing the dimensions by 4, we effectively decrement
492 * last_level by 2, therefore the last 2 mipmap levels disappear and
493 * aren't blittable. Note that the last 3 mipmap levels (4x4, 2x2,
494 * 1x1) have equal slice sizes, which is an important assumption
497 * In order to make the last 2 mipmap levels blittable, we have to
498 * add the slice size of the last mipmap level to the texture
499 * address, so that even though the hw thinks it reads last_level-2,
500 * it will actually read last_level-1, and if we add the slice size*2,
501 * it will read last_level. That's how this workaround works.
503 if (level
> rtex
->resource
.b
.b
.last_level
-2)
504 rtex
->mipmap_shift
= level
- (rtex
->resource
.b
.b
.last_level
-2);
507 static void si_change_format(struct pipe_resource
*tex
,
509 struct texture_orig_info
*orig
,
510 enum pipe_format format
)
512 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
514 orig
->format
= tex
->format
;
515 orig
->width0
= tex
->width0
;
516 orig
->height0
= tex
->height0
;
517 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
518 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
519 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
520 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
522 tex
->format
= format
;
525 static void si_reset_blittable_to_orig(struct pipe_resource
*tex
,
527 struct texture_orig_info
*orig
)
529 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
531 tex
->format
= orig
->format
;
532 tex
->width0
= orig
->width0
;
533 tex
->height0
= orig
->height0
;
534 rtex
->surface
.level
[0].npix_x
= orig
->npix0_x
;
535 rtex
->surface
.level
[0].npix_y
= orig
->npix0_y
;
536 rtex
->surface
.level
[level
].npix_x
= orig
->npix_x
;
537 rtex
->surface
.level
[level
].npix_y
= orig
->npix_y
;
538 rtex
->mipmap_shift
= 0;
541 void si_resource_copy_region(struct pipe_context
*ctx
,
542 struct pipe_resource
*dst
,
544 unsigned dstx
, unsigned dsty
, unsigned dstz
,
545 struct pipe_resource
*src
,
547 const struct pipe_box
*src_box
)
549 struct si_context
*sctx
= (struct si_context
*)ctx
;
550 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
551 struct pipe_surface
*dst_view
, dst_templ
;
552 struct pipe_sampler_view src_templ
, *src_view
;
553 struct texture_orig_info orig_info
[2];
554 struct pipe_box sbox
, dstbox
;
555 boolean restore_orig
[2];
557 /* Fallback for buffers. */
558 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
559 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
);
563 memset(orig_info
, 0, sizeof(orig_info
));
565 /* The driver doesn't decompress resources automatically while
566 * u_blitter is rendering. */
567 si_decompress_subresource(ctx
, src
, src_level
,
568 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
570 restore_orig
[0] = restore_orig
[1] = FALSE
;
572 if (util_format_is_compressed(src
->format
) &&
573 util_format_is_compressed(dst
->format
)) {
574 si_compressed_to_blittable(src
, src_level
, &orig_info
[0]);
575 restore_orig
[0] = TRUE
;
576 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
577 sbox
.y
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->y
);
579 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
580 sbox
.height
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->height
);
581 sbox
.depth
= src_box
->depth
;
584 si_compressed_to_blittable(dst
, dst_level
, &orig_info
[1]);
585 restore_orig
[1] = TRUE
;
586 /* translate the dst box as well */
587 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
588 dsty
= util_format_get_nblocksy(orig_info
[1].format
, dsty
);
589 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
)) {
590 if (util_format_is_subsampled_422(src
->format
)) {
592 si_change_format(src
, src_level
, &orig_info
[0],
593 PIPE_FORMAT_R8G8B8A8_UINT
);
594 si_change_format(dst
, dst_level
, &orig_info
[1],
595 PIPE_FORMAT_R8G8B8A8_UINT
);
598 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
599 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
601 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
603 restore_orig
[0] = TRUE
;
604 restore_orig
[1] = TRUE
;
606 unsigned blocksize
= util_format_get_blocksize(src
->format
);
610 si_change_format(src
, src_level
, &orig_info
[0],
611 PIPE_FORMAT_R8_UNORM
);
612 si_change_format(dst
, dst_level
, &orig_info
[1],
613 PIPE_FORMAT_R8_UNORM
);
616 si_change_format(src
, src_level
, &orig_info
[0],
617 PIPE_FORMAT_R8G8_UNORM
);
618 si_change_format(dst
, dst_level
, &orig_info
[1],
619 PIPE_FORMAT_R8G8_UNORM
);
622 si_change_format(src
, src_level
, &orig_info
[0],
623 PIPE_FORMAT_R8G8B8A8_UNORM
);
624 si_change_format(dst
, dst_level
, &orig_info
[1],
625 PIPE_FORMAT_R8G8B8A8_UNORM
);
628 si_change_format(src
, src_level
, &orig_info
[0],
629 PIPE_FORMAT_R16G16B16A16_UINT
);
630 si_change_format(dst
, dst_level
, &orig_info
[1],
631 PIPE_FORMAT_R16G16B16A16_UINT
);
634 si_change_format(src
, src_level
, &orig_info
[0],
635 PIPE_FORMAT_R32G32B32A32_UINT
);
636 si_change_format(dst
, dst_level
, &orig_info
[1],
637 PIPE_FORMAT_R32G32B32A32_UINT
);
640 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
641 util_format_short_name(src
->format
), blocksize
);
644 restore_orig
[0] = TRUE
;
645 restore_orig
[1] = TRUE
;
649 /* Initialize the surface. */
650 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
651 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
652 rdst
->surface
.level
[dst_level
].npix_x
,
653 rdst
->surface
.level
[dst_level
].npix_y
);
655 /* Initialize the sampler view. */
656 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
657 src_view
= ctx
->create_sampler_view(ctx
, src
, &src_templ
);
659 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
660 abs(src_box
->depth
), &dstbox
);
663 si_blitter_begin(ctx
, SI_COPY
);
664 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
665 src_view
, src_box
, src
->width0
, src
->height0
,
666 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
);
669 pipe_surface_reference(&dst_view
, NULL
);
670 pipe_sampler_view_reference(&src_view
, NULL
);
673 si_reset_blittable_to_orig(src
, src_level
, &orig_info
[0]);
676 si_reset_blittable_to_orig(dst
, dst_level
, &orig_info
[1]);
679 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
680 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
683 #define REPLACE_FORMAT_SIGN(format,sign) \
684 case PIPE_FORMAT_##format##_##sign##INT: \
685 return PIPE_FORMAT_##format##_##sign##NORM
686 #define REPLACE_FORMAT(format) \
687 REPLACE_FORMAT_SIGN(format, U); \
688 REPLACE_FORMAT_SIGN(format, S)
690 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
692 REPLACE_FORMAT(R8G8
);
693 REPLACE_FORMAT(R8G8B8X8
);
694 REPLACE_FORMAT(R8G8B8A8
);
698 REPLACE_FORMAT(L8A8
);
700 REPLACE_FORMAT(R16G16
);
701 REPLACE_FORMAT(R16G16B16X16
);
702 REPLACE_FORMAT(R16G16B16A16
);
706 REPLACE_FORMAT(L16A16
);
708 #undef REPLACE_FORMAT
709 #undef REPLACE_FORMAT_SIGN
715 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
716 const struct pipe_blit_info
*info
)
718 struct si_context
*sctx
= (struct si_context
*)ctx
;
719 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
720 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
721 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
722 enum pipe_format format
= int_to_norm_format(info
->dst
.format
);
723 unsigned sample_mask
= ~0;
725 if (info
->src
.resource
->nr_samples
> 1 &&
726 info
->dst
.resource
->nr_samples
<= 1 &&
727 util_max_layer(info
->src
.resource
, 0) == 0 &&
728 util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
729 info
->dst
.format
== info
->src
.format
&&
730 !util_format_is_pure_integer(format
) &&
731 !util_format_is_depth_or_stencil(format
) &&
732 !info
->scissor_enable
&&
733 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
734 dst_width
== info
->src
.resource
->width0
&&
735 dst_height
== info
->src
.resource
->height0
&&
736 info
->dst
.box
.x
== 0 &&
737 info
->dst
.box
.y
== 0 &&
738 info
->dst
.box
.width
== dst_width
&&
739 info
->dst
.box
.height
== dst_height
&&
740 info
->dst
.box
.depth
== 1 &&
741 info
->src
.box
.x
== 0 &&
742 info
->src
.box
.y
== 0 &&
743 info
->src
.box
.width
== dst_width
&&
744 info
->src
.box
.height
== dst_height
&&
745 info
->src
.box
.depth
== 1 &&
746 dst
->surface
.level
[info
->dst
.level
].mode
>= RADEON_SURF_MODE_1D
&&
747 !(dst
->surface
.flags
& RADEON_SURF_SCANOUT
) &&
748 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
) /* dst cannot be fast-cleared */) {
749 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
|
750 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
751 util_blitter_custom_resolve_color(sctx
->blitter
,
752 info
->dst
.resource
, info
->dst
.level
,
754 info
->src
.resource
, info
->src
.box
.z
,
755 sample_mask
, sctx
->custom_blend_resolve
,
763 static void si_blit(struct pipe_context
*ctx
,
764 const struct pipe_blit_info
*info
)
766 struct si_context
*sctx
= (struct si_context
*)ctx
;
768 if (do_hardware_msaa_resolve(ctx
, info
)) {
772 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
774 /* The driver doesn't decompress resources automatically while
775 * u_blitter is rendering. */
776 si_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
778 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
780 if (sctx
->screen
->b
.debug_flags
& DBG_FORCE_DMA
&&
781 util_try_blit_via_copy_region(ctx
, info
))
784 si_blitter_begin(ctx
, SI_BLIT
|
785 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
786 util_blitter_blit(sctx
->blitter
, info
);
790 static void si_flush_resource(struct pipe_context
*ctx
,
791 struct pipe_resource
*res
)
793 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
795 assert(res
->target
!= PIPE_BUFFER
);
797 if (!rtex
->is_depth
&& rtex
->cmask
.size
) {
798 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
799 0, util_max_layer(res
, 0));
803 void si_init_blit_functions(struct si_context
*sctx
)
805 sctx
->b
.b
.clear
= si_clear
;
806 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
807 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
808 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
809 sctx
->b
.b
.blit
= si_blit
;
810 sctx
->b
.b
.flush_resource
= si_flush_resource
;
811 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;