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_blitter.h"
26 #include "util/u_format.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
|
42 SI_DISABLE_RENDER_COND
,
44 SI_DECOMPRESS
= SI_SAVE_FRAMEBUFFER
| SI_DISABLE_RENDER_COND
,
46 SI_COLOR_RESOLVE
= SI_SAVE_FRAMEBUFFER
| SI_DISABLE_RENDER_COND
49 static void si_blitter_begin(struct pipe_context
*ctx
, enum si_blitter_op op
)
51 struct si_context
*sctx
= (struct si_context
*)ctx
;
53 r600_suspend_nontimer_queries(&sctx
->b
);
55 util_blitter_save_blend(sctx
->blitter
, sctx
->queued
.named
.blend
);
56 util_blitter_save_depth_stencil_alpha(sctx
->blitter
, sctx
->queued
.named
.dsa
);
57 util_blitter_save_stencil_ref(sctx
->blitter
, &sctx
->stencil_ref
);
58 util_blitter_save_rasterizer(sctx
->blitter
, sctx
->queued
.named
.rasterizer
);
59 util_blitter_save_fragment_shader(sctx
->blitter
, sctx
->ps_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
.viewport
) {
63 util_blitter_save_viewport(sctx
->blitter
, &sctx
->queued
.named
.viewport
->viewport
);
65 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
66 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
67 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
69 if (op
& SI_SAVE_FRAMEBUFFER
)
70 util_blitter_save_framebuffer(sctx
->blitter
, &sctx
->framebuffer
);
72 if (op
& SI_SAVE_TEXTURES
) {
73 util_blitter_save_fragment_sampler_states(
74 sctx
->blitter
, sctx
->samplers
[PIPE_SHADER_FRAGMENT
].n_samplers
,
75 (void**)sctx
->samplers
[PIPE_SHADER_FRAGMENT
].samplers
);
77 util_blitter_save_fragment_sampler_views(sctx
->blitter
,
78 util_last_bit(sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.desc
.enabled_mask
&
79 ((1 << NUM_TEX_UNITS
) - 1)),
80 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
83 if ((op
& SI_DISABLE_RENDER_COND
) && sctx
->b
.current_render_cond
) {
84 util_blitter_save_render_condition(sctx
->blitter
,
85 sctx
->b
.current_render_cond
,
86 sctx
->b
.current_render_cond_cond
,
87 sctx
->b
.current_render_cond_mode
);
91 static void si_blitter_end(struct pipe_context
*ctx
)
93 struct si_context
*sctx
= (struct si_context
*)ctx
;
94 r600_resume_nontimer_queries(&sctx
->b
);
97 static unsigned u_max_sample(struct pipe_resource
*r
)
99 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
102 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
103 struct r600_texture
*texture
,
104 struct r600_texture
*staging
,
105 unsigned first_level
, unsigned last_level
,
106 unsigned first_layer
, unsigned last_layer
,
107 unsigned first_sample
, unsigned last_sample
)
109 struct si_context
*sctx
= (struct si_context
*)ctx
;
110 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
112 const struct util_format_description
*desc
;
114 struct r600_texture
*flushed_depth_texture
= staging
?
115 staging
: texture
->flushed_depth_texture
;
117 if (!staging
&& !texture
->dirty_level_mask
)
120 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
122 desc
= util_format_description(flushed_depth_texture
->resource
.b
.b
.format
);
123 switch (util_format_has_depth(desc
) | util_format_has_stencil(desc
) << 1) {
125 assert(!"No depth or stencil to uncompress");
128 custom_dsa
= sctx
->custom_dsa_flush_depth_stencil
;
131 custom_dsa
= sctx
->custom_dsa_flush_stencil
;
134 custom_dsa
= sctx
->custom_dsa_flush_depth
;
138 for (level
= first_level
; level
<= last_level
; level
++) {
139 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
142 /* The smaller the mipmap level, the less layers there are
143 * as far as 3D textures are concerned. */
144 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
145 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
147 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
148 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
149 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
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 custom_dsa
[sample
], 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
);
182 static void si_blit_decompress_depth_in_place(struct si_context
*sctx
,
183 struct r600_texture
*texture
,
184 unsigned first_level
, unsigned last_level
,
185 unsigned first_layer
, unsigned last_layer
)
187 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
188 unsigned layer
, max_layer
, checked_last_layer
, level
;
190 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
192 for (level
= first_level
; level
<= last_level
; level
++) {
193 if (!(texture
->dirty_level_mask
& (1 << level
)))
196 surf_tmpl
.u
.tex
.level
= level
;
198 /* The smaller the mipmap level, the less layers there are
199 * as far as 3D textures are concerned. */
200 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
201 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
203 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
204 surf_tmpl
.u
.tex
.first_layer
= layer
;
205 surf_tmpl
.u
.tex
.last_layer
= layer
;
207 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
209 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
210 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
211 sctx
->custom_dsa_flush_inplace
,
213 si_blitter_end(&sctx
->b
.b
);
215 pipe_surface_reference(&zsurf
, NULL
);
218 /* The texture will always be dirty if some layers aren't flushed.
219 * I don't think this case occurs often though. */
220 if (first_layer
== 0 && last_layer
== max_layer
) {
221 texture
->dirty_level_mask
&= ~(1 << level
);
226 void si_flush_depth_textures(struct si_context
*sctx
,
227 struct si_textures_info
*textures
)
231 for (i
= 0; i
< textures
->n_views
; ++i
) {
232 struct pipe_sampler_view
*view
;
233 struct r600_texture
*tex
;
235 view
= textures
->views
.views
[i
];
238 tex
= (struct r600_texture
*)view
->texture
;
239 if (!tex
->is_depth
|| tex
->is_flushing_texture
)
242 si_blit_decompress_depth_in_place(sctx
, tex
,
243 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
244 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
248 static void si_blit_decompress_color(struct pipe_context
*ctx
,
249 struct r600_texture
*rtex
,
250 unsigned first_level
, unsigned last_level
,
251 unsigned first_layer
, unsigned last_layer
)
253 struct si_context
*sctx
= (struct si_context
*)ctx
;
254 unsigned layer
, level
, checked_last_layer
, max_layer
;
256 if (!rtex
->dirty_level_mask
)
259 for (level
= first_level
; level
<= last_level
; level
++) {
260 if (!(rtex
->dirty_level_mask
& (1 << level
)))
263 /* The smaller the mipmap level, the less layers there are
264 * as far as 3D textures are concerned. */
265 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
266 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
268 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
269 struct pipe_surface
*cbsurf
, surf_tmpl
;
271 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
272 surf_tmpl
.u
.tex
.level
= level
;
273 surf_tmpl
.u
.tex
.first_layer
= layer
;
274 surf_tmpl
.u
.tex
.last_layer
= layer
;
275 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
277 si_blitter_begin(ctx
, SI_DECOMPRESS
);
278 util_blitter_custom_color(sctx
->blitter
, cbsurf
,
279 sctx
->custom_blend_decompress
);
282 pipe_surface_reference(&cbsurf
, NULL
);
285 /* The texture will always be dirty if some layers aren't flushed.
286 * I don't think this case occurs often though. */
287 if (first_layer
== 0 && last_layer
== max_layer
) {
288 rtex
->dirty_level_mask
&= ~(1 << level
);
293 void si_decompress_color_textures(struct si_context
*sctx
,
294 struct si_textures_info
*textures
)
297 unsigned mask
= textures
->compressed_colortex_mask
;
300 struct pipe_sampler_view
*view
;
301 struct r600_texture
*tex
;
303 i
= u_bit_scan(&mask
);
305 view
= textures
->views
.views
[i
];
308 tex
= (struct r600_texture
*)view
->texture
;
309 assert(tex
->cmask
.size
|| tex
->fmask
.size
);
311 si_blit_decompress_color(&sctx
->b
.b
, tex
,
312 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
313 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
317 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
318 const union pipe_color_union
*color
,
319 double depth
, unsigned stencil
)
321 struct si_context
*sctx
= (struct si_context
*)ctx
;
322 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
;
324 si_blitter_begin(ctx
, SI_CLEAR
);
325 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
326 util_framebuffer_get_num_layers(fb
),
327 buffers
, color
, depth
, stencil
);
331 static void si_clear_render_target(struct pipe_context
*ctx
,
332 struct pipe_surface
*dst
,
333 const union pipe_color_union
*color
,
334 unsigned dstx
, unsigned dsty
,
335 unsigned width
, unsigned height
)
337 struct si_context
*sctx
= (struct si_context
*)ctx
;
339 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
340 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
341 dstx
, dsty
, width
, height
);
345 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
346 struct pipe_surface
*dst
,
347 unsigned clear_flags
,
350 unsigned dstx
, unsigned dsty
,
351 unsigned width
, unsigned height
)
353 struct si_context
*sctx
= (struct si_context
*)ctx
;
355 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
356 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
357 dstx
, dsty
, width
, height
);
361 /* Helper for decompressing a portion of a color or depth resource before
362 * blitting if any decompression is needed.
363 * The driver doesn't decompress resources automatically while u_blitter is
365 static void si_decompress_subresource(struct pipe_context
*ctx
,
366 struct pipe_resource
*tex
,
368 unsigned first_layer
, unsigned last_layer
)
370 struct si_context
*sctx
= (struct si_context
*)ctx
;
371 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
373 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
374 si_blit_decompress_depth_in_place(sctx
, rtex
,
376 first_layer
, last_layer
);
377 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
) {
378 si_blit_decompress_color(ctx
, rtex
, level
, level
,
379 first_layer
, last_layer
);
383 struct texture_orig_info
{
393 static void si_compressed_to_blittable(struct pipe_resource
*tex
,
395 struct texture_orig_info
*orig
)
397 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
398 unsigned pixsize
= util_format_get_blocksize(rtex
->resource
.b
.b
.format
);
400 int new_height
, new_width
;
402 orig
->format
= tex
->format
;
403 orig
->width0
= tex
->width0
;
404 orig
->height0
= tex
->height0
;
405 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
406 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
407 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
408 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
411 new_format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
413 new_format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
415 new_width
= util_format_get_nblocksx(tex
->format
, orig
->width0
);
416 new_height
= util_format_get_nblocksy(tex
->format
, orig
->height0
);
418 tex
->width0
= new_width
;
419 tex
->height0
= new_height
;
420 tex
->format
= new_format
;
421 rtex
->surface
.level
[0].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix0_x
);
422 rtex
->surface
.level
[0].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix0_y
);
423 rtex
->surface
.level
[level
].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix_x
);
424 rtex
->surface
.level
[level
].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix_y
);
426 /* By dividing the dimensions by 4, we effectively decrement
427 * last_level by 2, therefore the last 2 mipmap levels disappear and
428 * aren't blittable. Note that the last 3 mipmap levels (4x4, 2x2,
429 * 1x1) have equal slice sizes, which is an important assumption
432 * In order to make the last 2 mipmap levels blittable, we have to
433 * add the slice size of the last mipmap level to the texture
434 * address, so that even though the hw thinks it reads last_level-2,
435 * it will actually read last_level-1, and if we add the slice size*2,
436 * it will read last_level. That's how this workaround works.
438 if (level
> rtex
->resource
.b
.b
.last_level
-2)
439 rtex
->mipmap_shift
= level
- (rtex
->resource
.b
.b
.last_level
-2);
442 static void si_change_format(struct pipe_resource
*tex
,
444 struct texture_orig_info
*orig
,
445 enum pipe_format format
)
447 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
449 orig
->format
= tex
->format
;
450 orig
->width0
= tex
->width0
;
451 orig
->height0
= tex
->height0
;
452 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
453 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
454 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
455 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
457 tex
->format
= format
;
460 static void si_reset_blittable_to_orig(struct pipe_resource
*tex
,
462 struct texture_orig_info
*orig
)
464 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
466 tex
->format
= orig
->format
;
467 tex
->width0
= orig
->width0
;
468 tex
->height0
= orig
->height0
;
469 rtex
->surface
.level
[0].npix_x
= orig
->npix0_x
;
470 rtex
->surface
.level
[0].npix_y
= orig
->npix0_y
;
471 rtex
->surface
.level
[level
].npix_x
= orig
->npix_x
;
472 rtex
->surface
.level
[level
].npix_y
= orig
->npix_y
;
473 rtex
->mipmap_shift
= 0;
476 static void si_resource_copy_region(struct pipe_context
*ctx
,
477 struct pipe_resource
*dst
,
479 unsigned dstx
, unsigned dsty
, unsigned dstz
,
480 struct pipe_resource
*src
,
482 const struct pipe_box
*src_box
)
484 struct si_context
*sctx
= (struct si_context
*)ctx
;
485 struct texture_orig_info orig_info
[2];
486 struct pipe_box sbox
;
487 const struct pipe_box
*psbox
= src_box
;
488 boolean restore_orig
[2];
490 /* Fallback for buffers. */
491 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
492 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
);
496 memset(orig_info
, 0, sizeof(orig_info
));
498 /* The driver doesn't decompress resources automatically while
499 * u_blitter is rendering. */
500 si_decompress_subresource(ctx
, src
, src_level
,
501 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
503 restore_orig
[0] = restore_orig
[1] = FALSE
;
505 if (util_format_is_compressed(src
->format
) &&
506 util_format_is_compressed(dst
->format
)) {
507 si_compressed_to_blittable(src
, src_level
, &orig_info
[0]);
508 restore_orig
[0] = TRUE
;
509 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
510 sbox
.y
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->y
);
512 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
513 sbox
.height
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->height
);
514 sbox
.depth
= src_box
->depth
;
517 si_compressed_to_blittable(dst
, dst_level
, &orig_info
[1]);
518 restore_orig
[1] = TRUE
;
519 /* translate the dst box as well */
520 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
521 dsty
= util_format_get_nblocksy(orig_info
[1].format
, dsty
);
522 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
)) {
523 unsigned blocksize
= util_format_get_blocksize(src
->format
);
527 si_change_format(src
, src_level
, &orig_info
[0],
528 PIPE_FORMAT_R8_UNORM
);
529 si_change_format(dst
, dst_level
, &orig_info
[1],
530 PIPE_FORMAT_R8_UNORM
);
533 si_change_format(src
, src_level
, &orig_info
[0],
534 PIPE_FORMAT_R8G8_UNORM
);
535 si_change_format(dst
, dst_level
, &orig_info
[1],
536 PIPE_FORMAT_R8G8_UNORM
);
539 si_change_format(src
, src_level
, &orig_info
[0],
540 PIPE_FORMAT_R8G8B8A8_UNORM
);
541 si_change_format(dst
, dst_level
, &orig_info
[1],
542 PIPE_FORMAT_R8G8B8A8_UNORM
);
545 si_change_format(src
, src_level
, &orig_info
[0],
546 PIPE_FORMAT_R16G16B16A16_UINT
);
547 si_change_format(dst
, dst_level
, &orig_info
[1],
548 PIPE_FORMAT_R16G16B16A16_UINT
);
551 si_change_format(src
, src_level
, &orig_info
[0],
552 PIPE_FORMAT_R32G32B32A32_UINT
);
553 si_change_format(dst
, dst_level
, &orig_info
[1],
554 PIPE_FORMAT_R32G32B32A32_UINT
);
557 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
558 util_format_short_name(src
->format
), blocksize
);
561 restore_orig
[0] = TRUE
;
562 restore_orig
[1] = TRUE
;
565 si_blitter_begin(ctx
, SI_COPY
);
566 util_blitter_copy_texture(sctx
->blitter
, dst
, dst_level
, dstx
, dsty
, dstz
,
567 src
, src_level
, psbox
);
571 si_reset_blittable_to_orig(src
, src_level
, &orig_info
[0]);
574 si_reset_blittable_to_orig(dst
, dst_level
, &orig_info
[1]);
577 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
578 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
581 #define REPLACE_FORMAT_SIGN(format,sign) \
582 case PIPE_FORMAT_##format##_##sign##INT: \
583 return PIPE_FORMAT_##format##_##sign##NORM
584 #define REPLACE_FORMAT(format) \
585 REPLACE_FORMAT_SIGN(format, U); \
586 REPLACE_FORMAT_SIGN(format, S)
588 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
590 REPLACE_FORMAT(R8G8
);
591 REPLACE_FORMAT(R8G8B8X8
);
592 REPLACE_FORMAT(R8G8B8A8
);
596 REPLACE_FORMAT(L8A8
);
598 REPLACE_FORMAT(R16G16
);
599 REPLACE_FORMAT(R16G16B16X16
);
600 REPLACE_FORMAT(R16G16B16A16
);
604 REPLACE_FORMAT(L16A16
);
606 #undef REPLACE_FORMAT
607 #undef REPLACE_FORMAT_SIGN
613 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
614 const struct pipe_blit_info
*info
)
616 struct si_context
*sctx
= (struct si_context
*)ctx
;
617 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
618 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
619 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
620 enum pipe_format format
= int_to_norm_format(info
->dst
.format
);
621 unsigned sample_mask
= ~0;
623 if (info
->src
.resource
->nr_samples
> 1 &&
624 info
->dst
.resource
->nr_samples
<= 1 &&
625 util_max_layer(info
->src
.resource
, 0) == 0 &&
626 util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
627 info
->dst
.format
== info
->src
.format
&&
628 !util_format_is_pure_integer(format
) &&
629 !util_format_is_depth_or_stencil(format
) &&
630 !info
->scissor_enable
&&
631 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
632 dst_width
== info
->src
.resource
->width0
&&
633 dst_height
== info
->src
.resource
->height0
&&
634 info
->dst
.box
.x
== 0 &&
635 info
->dst
.box
.y
== 0 &&
636 info
->dst
.box
.width
== dst_width
&&
637 info
->dst
.box
.height
== dst_height
&&
638 info
->dst
.box
.depth
== 1 &&
639 info
->src
.box
.x
== 0 &&
640 info
->src
.box
.y
== 0 &&
641 info
->src
.box
.width
== dst_width
&&
642 info
->src
.box
.height
== dst_height
&&
643 info
->src
.box
.depth
== 1 &&
644 dst
->surface
.level
[info
->dst
.level
].mode
>= RADEON_SURF_MODE_1D
&&
645 !(dst
->surface
.flags
& RADEON_SURF_SCANOUT
)) {
646 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
);
647 util_blitter_custom_resolve_color(sctx
->blitter
,
648 info
->dst
.resource
, info
->dst
.level
,
650 info
->src
.resource
, info
->src
.box
.z
,
651 sample_mask
, sctx
->custom_blend_resolve
,
659 static void si_blit(struct pipe_context
*ctx
,
660 const struct pipe_blit_info
*info
)
662 struct si_context
*sctx
= (struct si_context
*)ctx
;
664 if (do_hardware_msaa_resolve(ctx
, info
)) {
668 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
670 /* The driver doesn't decompress resources automatically while
671 * u_blitter is rendering. */
672 si_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
674 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
676 si_blitter_begin(ctx
, SI_BLIT
);
677 util_blitter_blit(sctx
->blitter
, info
);
681 static void si_flush_resource(struct pipe_context
*ctx
,
682 struct pipe_resource
*resource
)
686 void si_init_blit_functions(struct si_context
*sctx
)
688 sctx
->b
.b
.clear
= si_clear
;
689 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
690 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
691 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
692 sctx
->b
.b
.blit
= si_blit
;
693 sctx
->b
.b
.flush_resource
= si_flush_resource
;
694 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;