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_geometry_shader(sctx
->blitter
, sctx
->gs_shader
);
61 util_blitter_save_vertex_shader(sctx
->blitter
, sctx
->vs_shader
);
62 util_blitter_save_vertex_elements(sctx
->blitter
, sctx
->vertex_elements
);
63 if (sctx
->queued
.named
.viewport
) {
64 util_blitter_save_viewport(sctx
->blitter
, &sctx
->queued
.named
.viewport
->viewport
);
66 util_blitter_save_vertex_buffer_slot(sctx
->blitter
, sctx
->vertex_buffer
);
67 util_blitter_save_so_targets(sctx
->blitter
, sctx
->b
.streamout
.num_targets
,
68 (struct pipe_stream_output_target
**)sctx
->b
.streamout
.targets
);
70 if (op
& SI_SAVE_FRAMEBUFFER
)
71 util_blitter_save_framebuffer(sctx
->blitter
, &sctx
->framebuffer
.state
);
73 if (op
& SI_SAVE_TEXTURES
) {
74 util_blitter_save_fragment_sampler_states(
75 sctx
->blitter
, sctx
->samplers
[PIPE_SHADER_FRAGMENT
].n_samplers
,
76 (void**)sctx
->samplers
[PIPE_SHADER_FRAGMENT
].samplers
);
78 util_blitter_save_fragment_sampler_views(sctx
->blitter
,
79 util_last_bit(sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.desc
.enabled_mask
&
80 ((1 << NUM_TEX_UNITS
) - 1)),
81 sctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
84 if ((op
& SI_DISABLE_RENDER_COND
) && sctx
->b
.current_render_cond
) {
85 util_blitter_save_render_condition(sctx
->blitter
,
86 sctx
->b
.current_render_cond
,
87 sctx
->b
.current_render_cond_cond
,
88 sctx
->b
.current_render_cond_mode
);
92 static void si_blitter_end(struct pipe_context
*ctx
)
94 struct si_context
*sctx
= (struct si_context
*)ctx
;
95 r600_resume_nontimer_queries(&sctx
->b
);
98 static unsigned u_max_sample(struct pipe_resource
*r
)
100 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
103 static void si_blit_decompress_depth(struct pipe_context
*ctx
,
104 struct r600_texture
*texture
,
105 struct r600_texture
*staging
,
106 unsigned first_level
, unsigned last_level
,
107 unsigned first_layer
, unsigned last_layer
,
108 unsigned first_sample
, unsigned last_sample
)
110 struct si_context
*sctx
= (struct si_context
*)ctx
;
111 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
113 const struct util_format_description
*desc
;
115 struct r600_texture
*flushed_depth_texture
= staging
?
116 staging
: texture
->flushed_depth_texture
;
118 if (!staging
&& !texture
->dirty_level_mask
)
121 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
123 desc
= util_format_description(flushed_depth_texture
->resource
.b
.b
.format
);
124 switch (util_format_has_depth(desc
) | util_format_has_stencil(desc
) << 1) {
126 assert(!"No depth or stencil to uncompress");
129 custom_dsa
= sctx
->custom_dsa_flush_depth_stencil
;
132 custom_dsa
= sctx
->custom_dsa_flush_stencil
;
135 custom_dsa
= sctx
->custom_dsa_flush_depth
;
139 for (level
= first_level
; level
<= last_level
; level
++) {
140 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
143 /* The smaller the mipmap level, the less layers there are
144 * as far as 3D textures are concerned. */
145 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
146 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
148 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
149 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
150 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
152 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
153 surf_tmpl
.u
.tex
.level
= level
;
154 surf_tmpl
.u
.tex
.first_layer
= layer
;
155 surf_tmpl
.u
.tex
.last_layer
= layer
;
157 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
159 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
160 cbsurf
= ctx
->create_surface(ctx
,
161 (struct pipe_resource
*)flushed_depth_texture
, &surf_tmpl
);
163 si_blitter_begin(ctx
, SI_DECOMPRESS
);
164 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
165 custom_dsa
[sample
], depth
);
168 pipe_surface_reference(&zsurf
, NULL
);
169 pipe_surface_reference(&cbsurf
, NULL
);
173 /* The texture will always be dirty if some layers aren't flushed.
174 * I don't think this case can occur though. */
176 first_layer
== 0 && last_layer
== max_layer
&&
177 first_sample
== 0 && last_sample
== max_sample
) {
178 texture
->dirty_level_mask
&= ~(1 << level
);
183 static void si_blit_decompress_depth_in_place(struct si_context
*sctx
,
184 struct r600_texture
*texture
,
185 unsigned first_level
, unsigned last_level
,
186 unsigned first_layer
, unsigned last_layer
)
188 struct pipe_surface
*zsurf
, surf_tmpl
= {{0}};
189 unsigned layer
, max_layer
, checked_last_layer
, level
;
191 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
193 for (level
= first_level
; level
<= last_level
; level
++) {
194 if (!(texture
->dirty_level_mask
& (1 << level
)))
197 surf_tmpl
.u
.tex
.level
= level
;
199 /* The smaller the mipmap level, the less layers there are
200 * as far as 3D textures are concerned. */
201 max_layer
= util_max_layer(&texture
->resource
.b
.b
, level
);
202 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
204 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
205 surf_tmpl
.u
.tex
.first_layer
= layer
;
206 surf_tmpl
.u
.tex
.last_layer
= layer
;
208 zsurf
= sctx
->b
.b
.create_surface(&sctx
->b
.b
, &texture
->resource
.b
.b
, &surf_tmpl
);
210 si_blitter_begin(&sctx
->b
.b
, SI_DECOMPRESS
);
211 util_blitter_custom_depth_stencil(sctx
->blitter
, zsurf
, NULL
, ~0,
212 sctx
->custom_dsa_flush_inplace
,
214 si_blitter_end(&sctx
->b
.b
);
216 pipe_surface_reference(&zsurf
, NULL
);
219 /* The texture will always be dirty if some layers aren't flushed.
220 * I don't think this case occurs often though. */
221 if (first_layer
== 0 && last_layer
== max_layer
) {
222 texture
->dirty_level_mask
&= ~(1 << level
);
227 void si_flush_depth_textures(struct si_context
*sctx
,
228 struct si_textures_info
*textures
)
232 for (i
= 0; i
< textures
->n_views
; ++i
) {
233 struct pipe_sampler_view
*view
;
234 struct r600_texture
*tex
;
236 view
= textures
->views
.views
[i
];
239 tex
= (struct r600_texture
*)view
->texture
;
240 if (!tex
->is_depth
|| tex
->is_flushing_texture
)
243 si_blit_decompress_depth_in_place(sctx
, tex
,
244 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
245 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
249 static void si_blit_decompress_color(struct pipe_context
*ctx
,
250 struct r600_texture
*rtex
,
251 unsigned first_level
, unsigned last_level
,
252 unsigned first_layer
, unsigned last_layer
)
254 struct si_context
*sctx
= (struct si_context
*)ctx
;
255 unsigned layer
, level
, checked_last_layer
, max_layer
;
257 if (!rtex
->dirty_level_mask
)
260 for (level
= first_level
; level
<= last_level
; level
++) {
261 if (!(rtex
->dirty_level_mask
& (1 << level
)))
264 /* The smaller the mipmap level, the less layers there are
265 * as far as 3D textures are concerned. */
266 max_layer
= util_max_layer(&rtex
->resource
.b
.b
, level
);
267 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
269 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
270 struct pipe_surface
*cbsurf
, surf_tmpl
;
272 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
273 surf_tmpl
.u
.tex
.level
= level
;
274 surf_tmpl
.u
.tex
.first_layer
= layer
;
275 surf_tmpl
.u
.tex
.last_layer
= layer
;
276 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
278 si_blitter_begin(ctx
, SI_DECOMPRESS
);
279 util_blitter_custom_color(sctx
->blitter
, cbsurf
,
280 rtex
->fmask
.size
? sctx
->custom_blend_decompress
:
281 sctx
->custom_blend_fastclear
);
284 pipe_surface_reference(&cbsurf
, NULL
);
287 /* The texture will always be dirty if some layers aren't flushed.
288 * I don't think this case occurs often though. */
289 if (first_layer
== 0 && last_layer
== max_layer
) {
290 rtex
->dirty_level_mask
&= ~(1 << level
);
295 void si_decompress_color_textures(struct si_context
*sctx
,
296 struct si_textures_info
*textures
)
299 unsigned mask
= textures
->compressed_colortex_mask
;
302 struct pipe_sampler_view
*view
;
303 struct r600_texture
*tex
;
305 i
= u_bit_scan(&mask
);
307 view
= textures
->views
.views
[i
];
310 tex
= (struct r600_texture
*)view
->texture
;
311 assert(tex
->cmask
.size
|| tex
->fmask
.size
);
313 si_blit_decompress_color(&sctx
->b
.b
, tex
,
314 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
315 0, util_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
319 static void si_clear(struct pipe_context
*ctx
, unsigned buffers
,
320 const union pipe_color_union
*color
,
321 double depth
, unsigned stencil
)
323 struct si_context
*sctx
= (struct si_context
*)ctx
;
324 struct pipe_framebuffer_state
*fb
= &sctx
->framebuffer
.state
;
326 if (buffers
& PIPE_CLEAR_COLOR
) {
327 evergreen_do_fast_color_clear(&sctx
->b
, fb
, &sctx
->framebuffer
.atom
,
331 if (buffers
& PIPE_CLEAR_COLOR
) {
334 /* These buffers cannot use fast clear, make sure to disable expansion. */
335 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
336 struct r600_texture
*tex
;
338 /* If not clearing this buffer, skip. */
339 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
345 tex
= (struct r600_texture
*)fb
->cbufs
[i
]->texture
;
346 if (tex
->fmask
.size
== 0)
347 tex
->dirty_level_mask
&= ~(1 << fb
->cbufs
[i
]->u
.tex
.level
);
351 si_blitter_begin(ctx
, SI_CLEAR
);
352 util_blitter_clear(sctx
->blitter
, fb
->width
, fb
->height
,
353 util_framebuffer_get_num_layers(fb
),
354 buffers
, color
, depth
, stencil
);
358 static void si_clear_render_target(struct pipe_context
*ctx
,
359 struct pipe_surface
*dst
,
360 const union pipe_color_union
*color
,
361 unsigned dstx
, unsigned dsty
,
362 unsigned width
, unsigned height
)
364 struct si_context
*sctx
= (struct si_context
*)ctx
;
366 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
367 util_blitter_clear_render_target(sctx
->blitter
, dst
, color
,
368 dstx
, dsty
, width
, height
);
372 static void si_clear_depth_stencil(struct pipe_context
*ctx
,
373 struct pipe_surface
*dst
,
374 unsigned clear_flags
,
377 unsigned dstx
, unsigned dsty
,
378 unsigned width
, unsigned height
)
380 struct si_context
*sctx
= (struct si_context
*)ctx
;
382 si_blitter_begin(ctx
, SI_CLEAR_SURFACE
);
383 util_blitter_clear_depth_stencil(sctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
384 dstx
, dsty
, width
, height
);
388 /* Helper for decompressing a portion of a color or depth resource before
389 * blitting if any decompression is needed.
390 * The driver doesn't decompress resources automatically while u_blitter is
392 static void si_decompress_subresource(struct pipe_context
*ctx
,
393 struct pipe_resource
*tex
,
395 unsigned first_layer
, unsigned last_layer
)
397 struct si_context
*sctx
= (struct si_context
*)ctx
;
398 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
400 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
401 si_blit_decompress_depth_in_place(sctx
, rtex
,
403 first_layer
, last_layer
);
404 } else if (rtex
->fmask
.size
|| rtex
->cmask
.size
) {
405 si_blit_decompress_color(ctx
, rtex
, level
, level
,
406 first_layer
, last_layer
);
410 struct texture_orig_info
{
420 static void si_compressed_to_blittable(struct pipe_resource
*tex
,
422 struct texture_orig_info
*orig
)
424 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
425 unsigned pixsize
= util_format_get_blocksize(rtex
->resource
.b
.b
.format
);
427 int new_height
, new_width
;
429 orig
->format
= tex
->format
;
430 orig
->width0
= tex
->width0
;
431 orig
->height0
= tex
->height0
;
432 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
433 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
434 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
435 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
438 new_format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
440 new_format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
442 new_width
= util_format_get_nblocksx(tex
->format
, orig
->width0
);
443 new_height
= util_format_get_nblocksy(tex
->format
, orig
->height0
);
445 tex
->width0
= new_width
;
446 tex
->height0
= new_height
;
447 tex
->format
= new_format
;
448 rtex
->surface
.level
[0].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix0_x
);
449 rtex
->surface
.level
[0].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix0_y
);
450 rtex
->surface
.level
[level
].npix_x
= util_format_get_nblocksx(orig
->format
, orig
->npix_x
);
451 rtex
->surface
.level
[level
].npix_y
= util_format_get_nblocksy(orig
->format
, orig
->npix_y
);
453 /* By dividing the dimensions by 4, we effectively decrement
454 * last_level by 2, therefore the last 2 mipmap levels disappear and
455 * aren't blittable. Note that the last 3 mipmap levels (4x4, 2x2,
456 * 1x1) have equal slice sizes, which is an important assumption
459 * In order to make the last 2 mipmap levels blittable, we have to
460 * add the slice size of the last mipmap level to the texture
461 * address, so that even though the hw thinks it reads last_level-2,
462 * it will actually read last_level-1, and if we add the slice size*2,
463 * it will read last_level. That's how this workaround works.
465 if (level
> rtex
->resource
.b
.b
.last_level
-2)
466 rtex
->mipmap_shift
= level
- (rtex
->resource
.b
.b
.last_level
-2);
469 static void si_change_format(struct pipe_resource
*tex
,
471 struct texture_orig_info
*orig
,
472 enum pipe_format format
)
474 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
476 orig
->format
= tex
->format
;
477 orig
->width0
= tex
->width0
;
478 orig
->height0
= tex
->height0
;
479 orig
->npix0_x
= rtex
->surface
.level
[0].npix_x
;
480 orig
->npix0_y
= rtex
->surface
.level
[0].npix_y
;
481 orig
->npix_x
= rtex
->surface
.level
[level
].npix_x
;
482 orig
->npix_y
= rtex
->surface
.level
[level
].npix_y
;
484 tex
->format
= format
;
487 static void si_reset_blittable_to_orig(struct pipe_resource
*tex
,
489 struct texture_orig_info
*orig
)
491 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
493 tex
->format
= orig
->format
;
494 tex
->width0
= orig
->width0
;
495 tex
->height0
= orig
->height0
;
496 rtex
->surface
.level
[0].npix_x
= orig
->npix0_x
;
497 rtex
->surface
.level
[0].npix_y
= orig
->npix0_y
;
498 rtex
->surface
.level
[level
].npix_x
= orig
->npix_x
;
499 rtex
->surface
.level
[level
].npix_y
= orig
->npix_y
;
500 rtex
->mipmap_shift
= 0;
503 static void si_resource_copy_region(struct pipe_context
*ctx
,
504 struct pipe_resource
*dst
,
506 unsigned dstx
, unsigned dsty
, unsigned dstz
,
507 struct pipe_resource
*src
,
509 const struct pipe_box
*src_box
)
511 struct si_context
*sctx
= (struct si_context
*)ctx
;
512 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
513 struct pipe_surface
*dst_view
, dst_templ
;
514 struct pipe_sampler_view src_templ
, *src_view
;
515 struct texture_orig_info orig_info
[2];
516 struct pipe_box sbox
, dstbox
;
517 boolean restore_orig
[2];
519 /* Fallback for buffers. */
520 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
521 si_copy_buffer(sctx
, dst
, src
, dstx
, src_box
->x
, src_box
->width
);
525 memset(orig_info
, 0, sizeof(orig_info
));
527 /* The driver doesn't decompress resources automatically while
528 * u_blitter is rendering. */
529 si_decompress_subresource(ctx
, src
, src_level
,
530 src_box
->z
, src_box
->z
+ src_box
->depth
- 1);
532 restore_orig
[0] = restore_orig
[1] = FALSE
;
534 if (util_format_is_compressed(src
->format
) &&
535 util_format_is_compressed(dst
->format
)) {
536 si_compressed_to_blittable(src
, src_level
, &orig_info
[0]);
537 restore_orig
[0] = TRUE
;
538 sbox
.x
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->x
);
539 sbox
.y
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->y
);
541 sbox
.width
= util_format_get_nblocksx(orig_info
[0].format
, src_box
->width
);
542 sbox
.height
= util_format_get_nblocksy(orig_info
[0].format
, src_box
->height
);
543 sbox
.depth
= src_box
->depth
;
546 si_compressed_to_blittable(dst
, dst_level
, &orig_info
[1]);
547 restore_orig
[1] = TRUE
;
548 /* translate the dst box as well */
549 dstx
= util_format_get_nblocksx(orig_info
[1].format
, dstx
);
550 dsty
= util_format_get_nblocksy(orig_info
[1].format
, dsty
);
551 } else if (!util_blitter_is_copy_supported(sctx
->blitter
, dst
, src
)) {
552 unsigned blocksize
= util_format_get_blocksize(src
->format
);
556 si_change_format(src
, src_level
, &orig_info
[0],
557 PIPE_FORMAT_R8_UNORM
);
558 si_change_format(dst
, dst_level
, &orig_info
[1],
559 PIPE_FORMAT_R8_UNORM
);
562 si_change_format(src
, src_level
, &orig_info
[0],
563 PIPE_FORMAT_R8G8_UNORM
);
564 si_change_format(dst
, dst_level
, &orig_info
[1],
565 PIPE_FORMAT_R8G8_UNORM
);
568 si_change_format(src
, src_level
, &orig_info
[0],
569 PIPE_FORMAT_R8G8B8A8_UNORM
);
570 si_change_format(dst
, dst_level
, &orig_info
[1],
571 PIPE_FORMAT_R8G8B8A8_UNORM
);
574 si_change_format(src
, src_level
, &orig_info
[0],
575 PIPE_FORMAT_R16G16B16A16_UINT
);
576 si_change_format(dst
, dst_level
, &orig_info
[1],
577 PIPE_FORMAT_R16G16B16A16_UINT
);
580 si_change_format(src
, src_level
, &orig_info
[0],
581 PIPE_FORMAT_R32G32B32A32_UINT
);
582 si_change_format(dst
, dst_level
, &orig_info
[1],
583 PIPE_FORMAT_R32G32B32A32_UINT
);
586 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
587 util_format_short_name(src
->format
), blocksize
);
590 restore_orig
[0] = TRUE
;
591 restore_orig
[1] = TRUE
;
594 /* Initialize the surface. */
595 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
596 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
,
597 rdst
->surface
.level
[dst_level
].npix_x
,
598 rdst
->surface
.level
[dst_level
].npix_y
);
600 /* Initialize the sampler view. */
601 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
602 src_view
= ctx
->create_sampler_view(ctx
, src
, &src_templ
);
604 u_box_3d(dstx
, dsty
, dstz
, abs(src_box
->width
), abs(src_box
->height
),
605 abs(src_box
->depth
), &dstbox
);
608 si_blitter_begin(ctx
, SI_COPY
);
609 util_blitter_blit_generic(sctx
->blitter
, dst_view
, &dstbox
,
610 src_view
, src_box
, src
->width0
, src
->height0
,
611 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
);
614 pipe_surface_reference(&dst_view
, NULL
);
615 pipe_sampler_view_reference(&src_view
, NULL
);
618 si_reset_blittable_to_orig(src
, src_level
, &orig_info
[0]);
621 si_reset_blittable_to_orig(dst
, dst_level
, &orig_info
[1]);
624 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
625 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
628 #define REPLACE_FORMAT_SIGN(format,sign) \
629 case PIPE_FORMAT_##format##_##sign##INT: \
630 return PIPE_FORMAT_##format##_##sign##NORM
631 #define REPLACE_FORMAT(format) \
632 REPLACE_FORMAT_SIGN(format, U); \
633 REPLACE_FORMAT_SIGN(format, S)
635 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
637 REPLACE_FORMAT(R8G8
);
638 REPLACE_FORMAT(R8G8B8X8
);
639 REPLACE_FORMAT(R8G8B8A8
);
643 REPLACE_FORMAT(L8A8
);
645 REPLACE_FORMAT(R16G16
);
646 REPLACE_FORMAT(R16G16B16X16
);
647 REPLACE_FORMAT(R16G16B16A16
);
651 REPLACE_FORMAT(L16A16
);
653 #undef REPLACE_FORMAT
654 #undef REPLACE_FORMAT_SIGN
660 static bool do_hardware_msaa_resolve(struct pipe_context
*ctx
,
661 const struct pipe_blit_info
*info
)
663 struct si_context
*sctx
= (struct si_context
*)ctx
;
664 struct r600_texture
*dst
= (struct r600_texture
*)info
->dst
.resource
;
665 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
666 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
667 enum pipe_format format
= int_to_norm_format(info
->dst
.format
);
668 unsigned sample_mask
= ~0;
670 if (info
->src
.resource
->nr_samples
> 1 &&
671 info
->dst
.resource
->nr_samples
<= 1 &&
672 util_max_layer(info
->src
.resource
, 0) == 0 &&
673 util_max_layer(info
->dst
.resource
, info
->dst
.level
) == 0 &&
674 info
->dst
.format
== info
->src
.format
&&
675 !util_format_is_pure_integer(format
) &&
676 !util_format_is_depth_or_stencil(format
) &&
677 !info
->scissor_enable
&&
678 (info
->mask
& PIPE_MASK_RGBA
) == PIPE_MASK_RGBA
&&
679 dst_width
== info
->src
.resource
->width0
&&
680 dst_height
== info
->src
.resource
->height0
&&
681 info
->dst
.box
.x
== 0 &&
682 info
->dst
.box
.y
== 0 &&
683 info
->dst
.box
.width
== dst_width
&&
684 info
->dst
.box
.height
== dst_height
&&
685 info
->dst
.box
.depth
== 1 &&
686 info
->src
.box
.x
== 0 &&
687 info
->src
.box
.y
== 0 &&
688 info
->src
.box
.width
== dst_width
&&
689 info
->src
.box
.height
== dst_height
&&
690 info
->src
.box
.depth
== 1 &&
691 dst
->surface
.level
[info
->dst
.level
].mode
>= RADEON_SURF_MODE_1D
&&
692 !(dst
->surface
.flags
& RADEON_SURF_SCANOUT
)) {
693 si_blitter_begin(ctx
, SI_COLOR_RESOLVE
);
694 util_blitter_custom_resolve_color(sctx
->blitter
,
695 info
->dst
.resource
, info
->dst
.level
,
697 info
->src
.resource
, info
->src
.box
.z
,
698 sample_mask
, sctx
->custom_blend_resolve
,
706 static void si_blit(struct pipe_context
*ctx
,
707 const struct pipe_blit_info
*info
)
709 struct si_context
*sctx
= (struct si_context
*)ctx
;
711 if (do_hardware_msaa_resolve(ctx
, info
)) {
715 assert(util_blitter_is_blit_supported(sctx
->blitter
, info
));
717 /* The driver doesn't decompress resources automatically while
718 * u_blitter is rendering. */
719 si_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
721 info
->src
.box
.z
+ info
->src
.box
.depth
- 1);
723 si_blitter_begin(ctx
, SI_BLIT
);
724 util_blitter_blit(sctx
->blitter
, info
);
728 static void si_flush_resource(struct pipe_context
*ctx
,
729 struct pipe_resource
*res
)
731 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
733 assert(res
->target
!= PIPE_BUFFER
);
735 if (!rtex
->is_depth
&& rtex
->cmask
.size
) {
736 si_blit_decompress_color(ctx
, rtex
, 0, res
->last_level
,
737 0, res
->array_size
- 1);
741 void si_init_blit_functions(struct si_context
*sctx
)
743 sctx
->b
.b
.clear
= si_clear
;
744 sctx
->b
.b
.clear_render_target
= si_clear_render_target
;
745 sctx
->b
.b
.clear_depth_stencil
= si_clear_depth_stencil
;
746 sctx
->b
.b
.resource_copy_region
= si_resource_copy_region
;
747 sctx
->b
.b
.blit
= si_blit
;
748 sctx
->b
.b
.flush_resource
= si_flush_resource
;
749 sctx
->b
.blit_decompress_depth
= si_blit_decompress_depth
;