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
,
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
.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
.state
);
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 rtex
->fmask
.size
? sctx
->custom_blend_decompress
:
280 sctx
->custom_blend_fastclear
);
283 pipe_surface_reference(&cbsurf
, NULL
);
286 /* The texture will always be dirty if some layers aren't flushed.
287 * I don't think this case occurs often though. */
288 if (first_layer
== 0 && last_layer
== max_layer
) {
289 rtex
->dirty_level_mask
&= ~(1 << level
);
294 void si_decompress_color_textures(struct si_context
*sctx
,
295 struct si_textures_info
*textures
)
298 unsigned mask
= textures
->compressed_colortex_mask
;
301 struct pipe_sampler_view
*view
;
302 struct r600_texture
*tex
;
304 i
= u_bit_scan(&mask
);
306 view
= textures
->views
.views
[i
];
309 tex
= (struct r600_texture
*)view
->texture
;
310 assert(tex
->cmask
.size
|| tex
->fmask
.size
);
312 si_blit_decompress_color(&sctx
->b
.b
, tex
,
313 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
314 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
318 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
319 const union pipe_color_union
*color
,
320 double depth
, unsigned stencil
)
322 struct si_context
*sctx
= (struct si_context
*)ctx
;
323 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
325 if (buffers
& PIPE_CLEAR_COLOR
) {
326 evergreen_do_fast_color_clear(&sctx
->b
, fb
, &sctx
->framebuffer
.atom
,
330 if (buffers
& PIPE_CLEAR_COLOR
) {
333 /* These buffers cannot use fast clear, make sure to disable expansion. */
334 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
335 struct r600_texture
*tex
;
337 /* If not clearing this buffer, skip. */
338 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
344 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
345 if (tex
->fmask
.size
== 0)
346 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
350 si_blitter_begin(ctx
, SI_CLEAR
);
351 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
352 util_framebuffer_get_num_layers(fb
),
353 buffers
, color
, depth
, stencil
);
357 static void si_clear_render_target(struct pipe_context
*ctx
,
358 struct pipe_surface
*dst
,
359 const union pipe_color_union
*color
,
360 unsigned dstx
, unsigned dsty
,
361 unsigned width
, unsigned height
)
363 struct si_context
*sctx
= (struct si_context
*)ctx
;
365 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
366 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
367 dstx
, dsty
, width
, height
);
371 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
372 struct pipe_surface
*dst
,
373 unsigned clear_flags
,
376 unsigned dstx
, unsigned dsty
,
377 unsigned width
, unsigned height
)
379 struct si_context
*sctx
= (struct si_context
*)ctx
;
381 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
382 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
383 dstx
, dsty
, width
, height
);
387 /* Helper for decompressing a portion of a color or depth resource before
388 * blitting if any decompression is needed.
389 * The driver doesn't decompress resources automatically while u_blitter is
391 static void si_decompress_subresource(struct pipe_context
*ctx
,
392 struct pipe_resource
*tex
,
394 unsigned first_layer
, unsigned last_layer
)
396 struct si_context
*sctx
= (struct si_context
*)ctx
;
397 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
399 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
400 si_blit_decompress_depth_in_place(sctx
, rtex
,
402 first_layer
, last_layer
);
403 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
) {
404 si_blit_decompress_color(ctx
, rtex
, level
, level
,
405 first_layer
, last_layer
);
409 struct texture_orig_info
{
419 static void si_compressed_to_blittable(struct pipe_resource
*tex
,
421 struct texture_orig_info
*orig
)
423 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
424 unsigned pixsize
= util_format_get_blocksize(rtex
->resource
.b
.b
.format
);
426 int new_height
, new_width
;
428 orig
->format
= tex
->format
;
429 orig
->width0
= tex
->width0
;
430 orig
->height0
= tex
->height0
;
431 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
432 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
433 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
434 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
437 new_format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
439 new_format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
441 new_width
= util_format_get_nblocksx(tex
->format
, orig
->width0
);
442 new_height
= util_format_get_nblocksy(tex
->format
, orig
->height0
);
444 tex
->width0
= new_width
;
445 tex
->height0
= new_height
;
446 tex
->format
= new_format
;
447 rtex
->surface
.level
[0].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix0_x
);
448 rtex
->surface
.level
[0].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix0_y
);
449 rtex
->surface
.level
[level
].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix_x
);
450 rtex
->surface
.level
[level
].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix_y
);
452 /* By dividing the dimensions by 4, we effectively decrement
453 * last_level by 2, therefore the last 2 mipmap levels disappear and
454 * aren't blittable. Note that the last 3 mipmap levels (4x4, 2x2,
455 * 1x1) have equal slice sizes, which is an important assumption
458 * In order to make the last 2 mipmap levels blittable, we have to
459 * add the slice size of the last mipmap level to the texture
460 * address, so that even though the hw thinks it reads last_level-2,
461 * it will actually read last_level-1, and if we add the slice size*2,
462 * it will read last_level. That's how this workaround works.
464 if (level
> rtex
->resource
.b
.b
.last_level
-2)
465 rtex
->mipmap_shift
= level
- (rtex
->resource
.b
.b
.last_level
-2);
468 static void si_change_format(struct pipe_resource
*tex
,
470 struct texture_orig_info
*orig
,
471 enum pipe_format format
)
473 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
475 orig
->format
= tex
->format
;
476 orig
->width0
= tex
->width0
;
477 orig
->height0
= tex
->height0
;
478 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
479 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
480 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
481 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
483 tex
->format
= format
;
486 static void si_reset_blittable_to_orig(struct pipe_resource
*tex
,
488 struct texture_orig_info
*orig
)
490 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
492 tex
->format
= orig
->format
;
493 tex
->width0
= orig
->width0
;
494 tex
->height0
= orig
->height0
;
495 rtex
->surface
.level
[0].npix_x
= orig
->npix0_x
;
496 rtex
->surface
.level
[0].npix_y
= orig
->npix0_y
;
497 rtex
->surface
.level
[level
].npix_x
= orig
->npix_x
;
498 rtex
->surface
.level
[level
].npix_y
= orig
->npix_y
;
499 rtex
->mipmap_shift
= 0;
502 static void si_resource_copy_region(struct pipe_context
*ctx
,
503 struct pipe_resource
*dst
,
505 unsigned dstx
, unsigned dsty
, unsigned dstz
,
506 struct pipe_resource
*src
,
508 const struct pipe_box
*src_box
)
510 struct si_context
*sctx
= (struct si_context
*)ctx
;
511 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
512 struct pipe_surface
*dst_view
, dst_templ
;
513 struct pipe_sampler_view src_templ
, *src_view
;
514 struct texture_orig_info orig_info
[2];
515 struct pipe_box sbox
, dstbox
;
516 boolean restore_orig
[2];
518 /* Fallback for buffers. */
519 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
520 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
);
524 memset(orig_info
, 0, sizeof(orig_info
));
526 /* The driver doesn't decompress resources automatically while
527 * u_blitter is rendering. */
528 si_decompress_subresource(ctx
, src
, src_level
,
529 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
531 restore_orig
[0] = restore_orig
[1] = FALSE
;
533 if (util_format_is_compressed(src
->format
) &&
534 util_format_is_compressed(dst
->format
)) {
535 si_compressed_to_blittable(src
, src_level
, &orig_info
[0]);
536 restore_orig
[0] = TRUE
;
537 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
538 sbox
.y
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->y
);
540 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
541 sbox
.height
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->height
);
542 sbox
.depth
= src_box
->depth
;
545 si_compressed_to_blittable(dst
, dst_level
, &orig_info
[1]);
546 restore_orig
[1] = TRUE
;
547 /* translate the dst box as well */
548 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
549 dsty
= util_format_get_nblocksy(orig_info
[1].format
, dsty
);
550 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
)) {
551 if (util_format_is_subsampled_422(src
->format
)) {
553 si_change_format(src
, src_level
, &orig_info
[0],
554 PIPE_FORMAT_R8G8B8A8_UINT
);
555 si_change_format(dst
, dst_level
, &orig_info
[1],
556 PIPE_FORMAT_R8G8B8A8_UINT
);
559 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
560 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
562 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
564 restore_orig
[0] = TRUE
;
565 restore_orig
[1] = TRUE
;
567 unsigned blocksize
= util_format_get_blocksize(src
->format
);
571 si_change_format(src
, src_level
, &orig_info
[0],
572 PIPE_FORMAT_R8_UNORM
);
573 si_change_format(dst
, dst_level
, &orig_info
[1],
574 PIPE_FORMAT_R8_UNORM
);
577 si_change_format(src
, src_level
, &orig_info
[0],
578 PIPE_FORMAT_R8G8_UNORM
);
579 si_change_format(dst
, dst_level
, &orig_info
[1],
580 PIPE_FORMAT_R8G8_UNORM
);
583 si_change_format(src
, src_level
, &orig_info
[0],
584 PIPE_FORMAT_R8G8B8A8_UNORM
);
585 si_change_format(dst
, dst_level
, &orig_info
[1],
586 PIPE_FORMAT_R8G8B8A8_UNORM
);
589 si_change_format(src
, src_level
, &orig_info
[0],
590 PIPE_FORMAT_R16G16B16A16_UINT
);
591 si_change_format(dst
, dst_level
, &orig_info
[1],
592 PIPE_FORMAT_R16G16B16A16_UINT
);
595 si_change_format(src
, src_level
, &orig_info
[0],
596 PIPE_FORMAT_R32G32B32A32_UINT
);
597 si_change_format(dst
, dst_level
, &orig_info
[1],
598 PIPE_FORMAT_R32G32B32A32_UINT
);
601 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
602 util_format_short_name(src
->format
), blocksize
);
605 restore_orig
[0] = TRUE
;
606 restore_orig
[1] = TRUE
;
610 /* Initialize the surface. */
611 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
612 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
613 rdst
->surface
.level
[dst_level
].npix_x
,
614 rdst
->surface
.level
[dst_level
].npix_y
);
616 /* Initialize the sampler view. */
617 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
618 src_view
= ctx
->create_sampler_view(ctx
, src
, &src_templ
);
620 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
621 abs(src_box
->depth
), &dstbox
);
624 si_blitter_begin(ctx
, SI_COPY
);
625 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
626 src_view
, src_box
, src
->width0
, src
->height0
,
627 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
);
630 pipe_surface_reference(&dst_view
, NULL
);
631 pipe_sampler_view_reference(&src_view
, NULL
);
634 si_reset_blittable_to_orig(src
, src_level
, &orig_info
[0]);
637 si_reset_blittable_to_orig(dst
, dst_level
, &orig_info
[1]);
640 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
641 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
644 #define REPLACE_FORMAT_SIGN(format,sign) \
645 case PIPE_FORMAT_##format##_##sign##INT: \
646 return PIPE_FORMAT_##format##_##sign##NORM
647 #define REPLACE_FORMAT(format) \
648 REPLACE_FORMAT_SIGN(format, U); \
649 REPLACE_FORMAT_SIGN(format, S)
651 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
653 REPLACE_FORMAT(R8G8
);
654 REPLACE_FORMAT(R8G8B8X8
);
655 REPLACE_FORMAT(R8G8B8A8
);
659 REPLACE_FORMAT(L8A8
);
661 REPLACE_FORMAT(R16G16
);
662 REPLACE_FORMAT(R16G16B16X16
);
663 REPLACE_FORMAT(R16G16B16A16
);
667 REPLACE_FORMAT(L16A16
);
669 #undef REPLACE_FORMAT
670 #undef REPLACE_FORMAT_SIGN
676 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
677 const struct pipe_blit_info
*info
)
679 struct si_context
*sctx
= (struct si_context
*)ctx
;
680 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
681 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
682 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
683 enum pipe_format format
= int_to_norm_format(info
->dst
.format
);
684 unsigned sample_mask
= ~0;
686 if (info
->src
.resource
->nr_samples
> 1 &&
687 info
->dst
.resource
->nr_samples
<= 1 &&
688 util_max_layer(info
->src
.resource
, 0) == 0 &&
689 util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
690 info
->dst
.format
== info
->src
.format
&&
691 !util_format_is_pure_integer(format
) &&
692 !util_format_is_depth_or_stencil(format
) &&
693 !info
->scissor_enable
&&
694 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
695 dst_width
== info
->src
.resource
->width0
&&
696 dst_height
== info
->src
.resource
->height0
&&
697 info
->dst
.box
.x
== 0 &&
698 info
->dst
.box
.y
== 0 &&
699 info
->dst
.box
.width
== dst_width
&&
700 info
->dst
.box
.height
== dst_height
&&
701 info
->dst
.box
.depth
== 1 &&
702 info
->src
.box
.x
== 0 &&
703 info
->src
.box
.y
== 0 &&
704 info
->src
.box
.width
== dst_width
&&
705 info
->src
.box
.height
== dst_height
&&
706 info
->src
.box
.depth
== 1 &&
707 dst
->surface
.level
[info
->dst
.level
].mode
>= RADEON_SURF_MODE_1D
&&
708 !(dst
->surface
.flags
& RADEON_SURF_SCANOUT
) &&
709 (!dst
->cmask
.size
|| !dst
->dirty_level_mask
) /* dst cannot be fast-cleared */) {
710 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
|
711 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
712 util_blitter_custom_resolve_color(sctx
->blitter
,
713 info
->dst
.resource
, info
->dst
.level
,
715 info
->src
.resource
, info
->src
.box
.z
,
716 sample_mask
, sctx
->custom_blend_resolve
,
724 static void si_blit(struct pipe_context
*ctx
,
725 const struct pipe_blit_info
*info
)
727 struct si_context
*sctx
= (struct si_context
*)ctx
;
729 if (do_hardware_msaa_resolve(ctx
, info
)) {
733 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
735 /* The driver doesn't decompress resources automatically while
736 * u_blitter is rendering. */
737 si_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
739 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
741 si_blitter_begin(ctx
, SI_BLIT
|
742 (info
->render_condition_enable
? 0 : SI_DISABLE_RENDER_COND
));
743 util_blitter_blit(sctx
->blitter
, info
);
747 static void si_flush_resource(struct pipe_context
*ctx
,
748 struct pipe_resource
*res
)
750 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
752 assert(res
->target
!= PIPE_BUFFER
);
754 if (!rtex
->is_depth
&& rtex
->cmask
.size
) {
755 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
756 0, res
->array_size
- 1);
760 void si_init_blit_functions(struct si_context
*sctx
)
762 sctx
->b
.b
.clear
= si_clear
;
763 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
764 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
765 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
766 sctx
->b
.b
.blit
= si_blit
;
767 sctx
->b
.b
.flush_resource
= si_flush_resource
;
768 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;