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.
23 #include "r600_pipe.h"
24 #include "util/u_surface.h"
25 #include "util/u_blitter.h"
26 #include "util/u_format.h"
28 enum r600_blitter_op
/* bitmask */
30 R600_SAVE_FRAGMENT_STATE
= 1,
31 R600_SAVE_TEXTURES
= 2,
32 R600_SAVE_FRAMEBUFFER
= 4,
33 R600_DISABLE_RENDER_COND
= 8,
35 R600_CLEAR
= R600_SAVE_FRAGMENT_STATE
,
37 R600_CLEAR_SURFACE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
,
39 R600_COPY_BUFFER
= R600_DISABLE_RENDER_COND
,
41 R600_COPY_TEXTURE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_SAVE_TEXTURES
|
42 R600_DISABLE_RENDER_COND
,
44 R600_BLIT
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_SAVE_TEXTURES
|
45 R600_DISABLE_RENDER_COND
,
47 R600_DECOMPRESS
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_DISABLE_RENDER_COND
,
49 R600_COLOR_RESOLVE
= R600_SAVE_FRAGMENT_STATE
| R600_SAVE_FRAMEBUFFER
| R600_DISABLE_RENDER_COND
52 static void r600_blitter_begin(struct pipe_context
*ctx
, enum r600_blitter_op op
)
54 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
56 r600_suspend_nontimer_queries(rctx
);
58 util_blitter_save_vertex_buffers(rctx
->blitter
,
59 util_last_bit(rctx
->vertex_buffer_state
.enabled_mask
),
60 rctx
->vertex_buffer_state
.vb
);
61 util_blitter_save_vertex_elements(rctx
->blitter
, rctx
->vertex_fetch_shader
.cso
);
62 util_blitter_save_vertex_shader(rctx
->blitter
, rctx
->vs_shader
);
63 util_blitter_save_so_targets(rctx
->blitter
, rctx
->num_so_targets
,
64 (struct pipe_stream_output_target
**)rctx
->so_targets
);
65 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->rasterizer_state
.cso
);
67 if (op
& R600_SAVE_FRAGMENT_STATE
) {
68 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
.state
);
69 util_blitter_save_scissor(rctx
->blitter
, &rctx
->scissor
.scissor
);
70 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
71 util_blitter_save_blend(rctx
->blitter
, rctx
->blend_state
.cso
);
72 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->dsa_state
.cso
);
73 util_blitter_save_stencil_ref(rctx
->blitter
, &rctx
->stencil_ref
.pipe_state
);
74 util_blitter_save_sample_mask(rctx
->blitter
, rctx
->sample_mask
.sample_mask
);
77 if (op
& R600_SAVE_FRAMEBUFFER
)
78 util_blitter_save_framebuffer(rctx
->blitter
, &rctx
->framebuffer
.state
);
80 if (op
& R600_SAVE_TEXTURES
) {
81 util_blitter_save_fragment_sampler_states(
82 rctx
->blitter
, util_last_bit(rctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.enabled_mask
),
83 (void**)rctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.states
);
85 util_blitter_save_fragment_sampler_views(
86 rctx
->blitter
, util_last_bit(rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.enabled_mask
),
87 (struct pipe_sampler_view
**)rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.views
);
90 if ((op
& R600_DISABLE_RENDER_COND
) && rctx
->current_render_cond
) {
91 util_blitter_save_render_condition(rctx
->blitter
,
92 rctx
->current_render_cond
,
93 rctx
->current_render_cond_mode
);
97 static void r600_blitter_end(struct pipe_context
*ctx
)
99 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
100 r600_resume_nontimer_queries(rctx
);
103 static unsigned u_max_layer(struct pipe_resource
*r
, unsigned level
)
106 case PIPE_TEXTURE_CUBE
:
108 case PIPE_TEXTURE_3D
:
109 return u_minify(r
->depth0
, level
) - 1;
110 case PIPE_TEXTURE_1D_ARRAY
:
111 case PIPE_TEXTURE_2D_ARRAY
:
112 return r
->array_size
- 1;
118 static unsigned u_max_sample(struct pipe_resource
*r
)
120 return r
->nr_samples
? r
->nr_samples
- 1 : 0;
123 void r600_blit_decompress_depth(struct pipe_context
*ctx
,
124 struct r600_texture
*texture
,
125 struct r600_texture
*staging
,
126 unsigned first_level
, unsigned last_level
,
127 unsigned first_layer
, unsigned last_layer
,
128 unsigned first_sample
, unsigned last_sample
)
130 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
131 unsigned layer
, level
, sample
, checked_last_layer
, max_layer
, max_sample
;
132 struct r600_texture
*flushed_depth_texture
= staging
?
133 staging
: texture
->flushed_depth_texture
;
134 const struct util_format_description
*desc
=
135 util_format_description(texture
->resource
.b
.b
.format
);
138 if (!staging
&& !texture
->dirty_level_mask
)
141 max_sample
= u_max_sample(&texture
->resource
.b
.b
);
143 /* XXX Decompressing MSAA depth textures is broken on R6xx.
144 * There is also a hardlock if CMASK and FMASK are not present.
145 * Just skip this until we find out how to fix it. */
146 if (rctx
->chip_class
== R600
&& max_sample
> 0) {
147 texture
->dirty_level_mask
= 0;
151 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
152 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
157 /* Enable decompression in DB_RENDER_CONTROL */
158 rctx
->db_misc_state
.flush_depthstencil_through_cb
= true;
159 rctx
->db_misc_state
.copy_depth
= util_format_has_depth(desc
);
160 rctx
->db_misc_state
.copy_stencil
= util_format_has_stencil(desc
);
161 rctx
->db_misc_state
.copy_sample
= first_sample
;
162 rctx
->db_misc_state
.atom
.dirty
= true;
165 for (level
= first_level
; level
<= last_level
; level
++) {
166 if (!staging
&& !(texture
->dirty_level_mask
& (1 << level
)))
169 /* The smaller the mipmap level, the less layers there are
170 * as far as 3D textures are concerned. */
171 max_layer
= u_max_layer(&texture
->resource
.b
.b
, level
);
172 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
174 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
175 for (sample
= first_sample
; sample
<= last_sample
; sample
++) {
176 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
178 if (sample
!= rctx
->db_misc_state
.copy_sample
) {
179 rctx
->db_misc_state
.copy_sample
= sample
;
180 rctx
->db_misc_state
.atom
.dirty
= true;
183 surf_tmpl
.format
= texture
->resource
.b
.b
.format
;
184 surf_tmpl
.u
.tex
.level
= level
;
185 surf_tmpl
.u
.tex
.first_layer
= layer
;
186 surf_tmpl
.u
.tex
.last_layer
= layer
;
187 surf_tmpl
.usage
= PIPE_BIND_DEPTH_STENCIL
;
189 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.b
.b
, &surf_tmpl
);
191 surf_tmpl
.format
= flushed_depth_texture
->resource
.b
.b
.format
;
192 surf_tmpl
.u
.tex
.level
= level
;
193 surf_tmpl
.u
.tex
.first_layer
= layer
;
194 surf_tmpl
.u
.tex
.last_layer
= layer
;
195 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
196 cbsurf
= ctx
->create_surface(ctx
,
197 &flushed_depth_texture
->resource
.b
.b
, &surf_tmpl
);
199 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
200 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, 1 << sample
,
201 rctx
->custom_dsa_flush
, depth
);
202 r600_blitter_end(ctx
);
204 pipe_surface_reference(&zsurf
, NULL
);
205 pipe_surface_reference(&cbsurf
, NULL
);
209 /* The texture will always be dirty if some layers or samples aren't flushed.
210 * I don't think this case occurs often though. */
212 first_layer
== 0 && last_layer
== max_layer
&&
213 first_sample
== 0 && last_sample
== max_sample
) {
214 texture
->dirty_level_mask
&= ~(1 << level
);
218 /* reenable compression in DB_RENDER_CONTROL */
219 rctx
->db_misc_state
.flush_depthstencil_through_cb
= false;
220 rctx
->db_misc_state
.atom
.dirty
= true;
223 void r600_decompress_depth_textures(struct r600_context
*rctx
,
224 struct r600_samplerview_state
*textures
)
227 unsigned depth_texture_mask
= textures
->compressed_depthtex_mask
;
229 while (depth_texture_mask
) {
230 struct pipe_sampler_view
*view
;
231 struct r600_texture
*tex
;
233 i
= u_bit_scan(&depth_texture_mask
);
235 view
= &textures
->views
[i
]->base
;
238 tex
= (struct r600_texture
*)view
->texture
;
239 assert(tex
->is_depth
&& !tex
->is_flushing_texture
);
241 r600_blit_decompress_depth(&rctx
->context
, tex
, NULL
,
242 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
243 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
),
244 0, u_max_sample(&tex
->resource
.b
.b
));
248 static void r600_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 r600_context
*rctx
= (struct r600_context
*)ctx
;
254 unsigned layer
, level
, checked_last_layer
, max_layer
;
255 void *blend_decompress
;
257 if (!rtex
->dirty_level_mask
)
260 switch (rctx
->screen
->msaa_texture_support
) {
261 case MSAA_TEXTURE_DECOMPRESSED
:
262 blend_decompress
= rctx
->custom_blend_decompress
;
264 case MSAA_TEXTURE_COMPRESSED
:
265 /* XXX the 2x and 4x cases are broken. */
266 if (rtex
->resource
.b
.b
.nr_samples
== 8)
267 blend_decompress
= rctx
->custom_blend_fmask_decompress
;
269 blend_decompress
= rctx
->custom_blend_decompress
;
271 case MSAA_TEXTURE_SAMPLE_ZERO
:
274 rtex
->dirty_level_mask
= 0;
278 for (level
= first_level
; level
<= last_level
; level
++) {
279 if (!(rtex
->dirty_level_mask
& (1 << level
)))
282 /* The smaller the mipmap level, the less layers there are
283 * as far as 3D textures are concerned. */
284 max_layer
= u_max_layer(&rtex
->resource
.b
.b
, level
);
285 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
287 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
288 struct pipe_surface
*cbsurf
, surf_tmpl
;
290 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
291 surf_tmpl
.u
.tex
.level
= level
;
292 surf_tmpl
.u
.tex
.first_layer
= layer
;
293 surf_tmpl
.u
.tex
.last_layer
= layer
;
294 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
295 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
297 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
298 util_blitter_custom_color(rctx
->blitter
, cbsurf
, blend_decompress
);
299 r600_blitter_end(ctx
);
301 pipe_surface_reference(&cbsurf
, NULL
);
304 /* The texture will always be dirty if some layers or samples aren't flushed.
305 * I don't think this case occurs often though. */
306 if (first_layer
== 0 && last_layer
== max_layer
) {
307 rtex
->dirty_level_mask
&= ~(1 << level
);
312 void r600_decompress_color_textures(struct r600_context
*rctx
,
313 struct r600_samplerview_state
*textures
)
316 unsigned mask
= textures
->compressed_colortex_mask
;
319 struct pipe_sampler_view
*view
;
320 struct r600_texture
*tex
;
322 i
= u_bit_scan(&mask
);
324 view
= &textures
->views
[i
]->base
;
327 tex
= (struct r600_texture
*)view
->texture
;
328 assert(tex
->cmask_size
&& tex
->fmask_size
);
330 r600_blit_decompress_color(&rctx
->context
, tex
,
331 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
332 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
336 /* Helper for decompressing a portion of a color or depth resource before
337 * blitting if any decompression is needed.
338 * The driver doesn't decompress resources automatically while u_blitter is
340 static bool r600_decompress_subresource(struct pipe_context
*ctx
,
341 struct pipe_resource
*tex
,
343 unsigned first_layer
, unsigned last_layer
)
345 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
347 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
348 if (!r600_init_flushed_depth_texture(ctx
, tex
, NULL
))
349 return false; /* error */
351 r600_blit_decompress_depth(ctx
, rtex
, NULL
,
353 first_layer
, last_layer
,
354 0, u_max_sample(tex
));
355 } else if (rtex
->fmask_size
&& rtex
->cmask_size
) {
356 r600_blit_decompress_color(ctx
, rtex
, level
, level
,
357 first_layer
, last_layer
);
362 static boolean
is_simple_msaa_resolve(const struct pipe_blit_info
*info
)
364 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
365 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
367 return info
->dst
.resource
->format
== info
->src
.resource
->format
&&
368 info
->dst
.resource
->format
== info
->dst
.format
&&
369 info
->src
.resource
->format
== info
->src
.format
&&
370 !info
->scissor_enable
&&
371 info
->mask
== PIPE_MASK_RGBA
&&
372 dst_width
== info
->src
.resource
->width0
&&
373 dst_height
== info
->src
.resource
->height0
&&
374 info
->dst
.box
.x
== 0 &&
375 info
->dst
.box
.y
== 0 &&
376 info
->dst
.box
.width
== dst_width
&&
377 info
->dst
.box
.height
== dst_height
&&
378 info
->src
.box
.x
== 0 &&
379 info
->src
.box
.y
== 0 &&
380 info
->src
.box
.width
== dst_width
&&
381 info
->src
.box
.height
== dst_height
;
384 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
385 const union pipe_color_union
*color
,
386 double depth
, unsigned stencil
)
388 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
389 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
.state
;
391 r600_blitter_begin(ctx
, R600_CLEAR
);
392 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
393 fb
->nr_cbufs
, buffers
, fb
->nr_cbufs
? fb
->cbufs
[0]->format
: PIPE_FORMAT_NONE
,
394 color
, depth
, stencil
);
395 r600_blitter_end(ctx
);
398 static void r600_clear_render_target(struct pipe_context
*ctx
,
399 struct pipe_surface
*dst
,
400 const union pipe_color_union
*color
,
401 unsigned dstx
, unsigned dsty
,
402 unsigned width
, unsigned height
)
404 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
406 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
407 util_blitter_clear_render_target(rctx
->blitter
, dst
, color
,
408 dstx
, dsty
, width
, height
);
409 r600_blitter_end(ctx
);
412 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
413 struct pipe_surface
*dst
,
414 unsigned clear_flags
,
417 unsigned dstx
, unsigned dsty
,
418 unsigned width
, unsigned height
)
420 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
422 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
423 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
424 dstx
, dsty
, width
, height
);
425 r600_blitter_end(ctx
);
428 void r600_copy_buffer(struct pipe_context
*ctx
, struct
429 pipe_resource
*dst
, unsigned dstx
,
430 struct pipe_resource
*src
, const struct pipe_box
*src_box
)
432 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
434 if (rctx
->screen
->has_streamout
&&
435 /* Require dword alignment. */
436 dstx
% 4 == 0 && src_box
->x
% 4 == 0 && src_box
->width
% 4 == 0) {
437 r600_blitter_begin(ctx
, R600_COPY_BUFFER
);
438 util_blitter_copy_buffer(rctx
->blitter
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
439 r600_blitter_end(ctx
);
441 util_resource_copy_region(ctx
, dst
, 0, dstx
, 0, 0, src
, 0, src_box
);
445 static bool util_format_is_subsampled_2x1_32bpp(enum pipe_format format
)
447 const struct util_format_description
*desc
= util_format_description(format
);
449 return desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
&&
450 desc
->block
.width
== 2 &&
451 desc
->block
.height
== 1 &&
452 desc
->block
.bits
== 32;
455 static void r600_resource_copy_region(struct pipe_context
*ctx
,
456 struct pipe_resource
*dst
,
458 unsigned dstx
, unsigned dsty
, unsigned dstz
,
459 struct pipe_resource
*src
,
461 const struct pipe_box
*src_box
)
463 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
464 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
465 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
466 struct pipe_surface
*dst_view
, dst_templ
;
467 struct pipe_sampler_view src_templ
, *src_view
;
468 unsigned dst_width
, dst_height
, src_width0
, src_height0
, src_widthFL
, src_heightFL
;
469 struct pipe_box sbox
;
470 bool copy_all_samples
;
472 /* Handle buffers first. */
473 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
474 r600_copy_buffer(ctx
, dst
, dstx
, src
, src_box
);
478 assert(u_max_sample(dst
) == u_max_sample(src
));
480 /* The driver doesn't decompress resources automatically while
481 * u_blitter is rendering. */
482 if (!r600_decompress_subresource(ctx
, src
, src_level
,
483 src_box
->z
, src_box
->z
+ src_box
->depth
- 1)) {
487 dst_width
= rdst
->surface
.level
[dst_level
].npix_x
;
488 dst_height
= rdst
->surface
.level
[dst_level
].npix_y
;
489 src_width0
= src
->width0
;
490 src_height0
= src
->height0
;
491 src_widthFL
= rsrc
->surface
.level
[src_level
].npix_x
;
492 src_heightFL
= rsrc
->surface
.level
[src_level
].npix_y
;
494 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
, src_box
);
495 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
497 if (util_format_is_compressed(src
->format
)) {
498 unsigned blocksize
= util_format_get_blocksize(src
->format
);
501 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
503 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
504 dst_templ
.format
= src_templ
.format
;
506 dst_width
= util_format_get_nblocksx(dst
->format
, rdst
->surface
.level
[dst_level
].npix_x
);
507 dst_height
= util_format_get_nblocksy(dst
->format
, rdst
->surface
.level
[dst_level
].npix_y
);
508 src_width0
= util_format_get_nblocksx(src
->format
, src
->width0
);
509 src_height0
= util_format_get_nblocksy(src
->format
, src
->height0
);
510 src_widthFL
= util_format_get_nblocksx(src
->format
, rsrc
->surface
.level
[src_level
].npix_x
);
511 src_heightFL
= util_format_get_nblocksy(src
->format
, rsrc
->surface
.level
[src_level
].npix_y
);
513 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
514 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
516 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
517 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
519 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
520 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
521 sbox
.depth
= src_box
->depth
;
523 } else if (!util_blitter_is_copy_supported(rctx
->blitter
, dst
, src
,
525 if (util_format_is_subsampled_2x1_32bpp(src
->format
)) {
527 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
528 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
530 dst_width
= util_format_get_nblocksx(dst
->format
, rdst
->surface
.level
[dst_level
].npix_x
);
531 src_width0
= util_format_get_nblocksx(src
->format
, src
->width0
);
532 src_widthFL
= util_format_get_nblocksx(src
->format
, rsrc
->surface
.level
[src_level
].npix_x
);
534 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
537 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
538 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
541 unsigned blocksize
= util_format_get_blocksize(src
->format
);
545 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
546 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
549 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
550 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
553 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
554 util_format_short_name(src
->format
), blocksize
);
560 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
, dst_width
, dst_height
);
562 if (rctx
->chip_class
>= EVERGREEN
) {
563 src_view
= evergreen_create_sampler_view_custom(ctx
, src
, &src_templ
,
564 src_width0
, src_height0
);
566 src_view
= r600_create_sampler_view_custom(ctx
, src
, &src_templ
,
567 src_widthFL
, src_heightFL
);
570 copy_all_samples
= rctx
->screen
->msaa_texture_support
!= MSAA_TEXTURE_SAMPLE_ZERO
;
573 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
574 util_blitter_blit_generic(rctx
->blitter
, dst_view
, dstx
, dsty
,
575 abs(src_box
->width
), abs(src_box
->height
),
576 src_view
, src_box
, src_width0
, src_height0
,
577 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
579 r600_blitter_end(ctx
);
581 pipe_surface_reference(&dst_view
, NULL
);
582 pipe_sampler_view_reference(&src_view
, NULL
);
585 /* For MSAA integer resolving to work, we change the format to NORM using this function. */
586 static enum pipe_format
int_to_norm_format(enum pipe_format format
)
589 #define REPLACE_FORMAT_SIGN(format,sign) \
590 case PIPE_FORMAT_##format##_##sign##INT: \
591 return PIPE_FORMAT_##format##_##sign##NORM
592 #define REPLACE_FORMAT(format) \
593 REPLACE_FORMAT_SIGN(format, U); \
594 REPLACE_FORMAT_SIGN(format, S)
596 REPLACE_FORMAT_SIGN(B10G10R10A2
, U
);
598 REPLACE_FORMAT(R8G8
);
599 REPLACE_FORMAT(R8G8B8
);
600 REPLACE_FORMAT(R8G8B8A8
);
604 REPLACE_FORMAT(L8A8
);
606 REPLACE_FORMAT(R16G16
);
607 REPLACE_FORMAT(R16G16B16
);
608 REPLACE_FORMAT(R16G16B16A16
);
612 REPLACE_FORMAT(L16A16
);
614 #undef REPLACE_FORMAT
615 #undef REPLACE_FORMAT_SIGN
621 static void r600_msaa_color_resolve(struct pipe_context
*ctx
,
622 const struct pipe_blit_info
*info
)
624 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
625 struct pipe_screen
*screen
= ctx
->screen
;
626 struct pipe_resource
*tmp
, templ
;
627 struct pipe_blit_info blit
;
628 unsigned sample_mask
=
629 rctx
->chip_class
== CAYMAN
? ~0 :
630 ((1ull << MAX2(1, info
->src
.resource
->nr_samples
)) - 1);
632 assert(info
->src
.level
== 0);
633 assert(info
->src
.box
.depth
== 1);
634 assert(info
->dst
.box
.depth
== 1);
636 if (is_simple_msaa_resolve(info
)) {
637 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
638 util_blitter_custom_resolve_color(rctx
->blitter
,
639 info
->dst
.resource
, info
->dst
.level
,
641 info
->src
.resource
, info
->src
.box
.z
,
642 sample_mask
, rctx
->custom_blend_resolve
,
643 int_to_norm_format(info
->dst
.format
));
644 r600_blitter_end(ctx
);
648 /* resolve into a temporary texture, then blit */
649 templ
.target
= PIPE_TEXTURE_2D
;
650 templ
.format
= info
->src
.resource
->format
;
651 templ
.width0
= info
->src
.resource
->width0
;
652 templ
.height0
= info
->src
.resource
->height0
;
654 templ
.array_size
= 1;
655 templ
.last_level
= 0;
656 templ
.nr_samples
= 0;
657 templ
.usage
= PIPE_USAGE_STATIC
;
658 templ
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
661 tmp
= screen
->resource_create(screen
, &templ
);
664 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
665 util_blitter_custom_resolve_color(rctx
->blitter
,
667 info
->src
.resource
, info
->src
.box
.z
,
668 sample_mask
, rctx
->custom_blend_resolve
,
669 int_to_norm_format(tmp
->format
));
670 r600_blitter_end(ctx
);
674 blit
.src
.resource
= tmp
;
677 r600_blitter_begin(ctx
, R600_BLIT
);
678 util_blitter_blit(rctx
->blitter
, &blit
);
679 r600_blitter_end(ctx
);
681 pipe_resource_reference(&tmp
, NULL
);
684 static void r600_blit(struct pipe_context
*ctx
,
685 const struct pipe_blit_info
*info
)
687 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
689 assert(util_blitter_is_blit_supported(rctx
->blitter
, info
));
691 if (info
->src
.resource
->nr_samples
> 1 &&
692 info
->dst
.resource
->nr_samples
<= 1 &&
693 !util_format_is_depth_or_stencil(info
->src
.resource
->format
) &&
694 !util_format_is_pure_integer(int_to_norm_format(info
->src
.resource
->format
))) {
695 r600_msaa_color_resolve(ctx
, info
);
699 /* The driver doesn't decompress resources automatically while
700 * u_blitter is rendering. */
701 if (!r600_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
703 info
->src
.box
.z
+ info
->src
.box
.depth
- 1)) {
707 r600_blitter_begin(ctx
, R600_BLIT
);
708 util_blitter_blit(rctx
->blitter
, info
);
709 r600_blitter_end(ctx
);
712 void r600_init_blit_functions(struct r600_context
*rctx
)
714 rctx
->context
.clear
= r600_clear
;
715 rctx
->context
.clear_render_target
= r600_clear_render_target
;
716 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
717 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
718 rctx
->context
.blit
= r600_blit
;