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_elements
);
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
->states
[R600_PIPE_STATE_RASTERIZER
]);
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
);
70 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
71 util_blitter_save_blend(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_BLEND
]);
72 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_DSA
]);
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
;
256 assert(rctx
->chip_class
!= CAYMAN
);
258 if (!rtex
->dirty_level_mask
)
261 for (level
= first_level
; level
<= last_level
; level
++) {
262 if (!(rtex
->dirty_level_mask
& (1 << level
)))
265 /* The smaller the mipmap level, the less layers there are
266 * as far as 3D textures are concerned. */
267 max_layer
= u_max_layer(&rtex
->resource
.b
.b
, level
);
268 checked_last_layer
= last_layer
< max_layer
? last_layer
: max_layer
;
270 for (layer
= first_layer
; layer
<= checked_last_layer
; layer
++) {
271 struct pipe_surface
*cbsurf
, surf_tmpl
;
273 surf_tmpl
.format
= rtex
->resource
.b
.b
.format
;
274 surf_tmpl
.u
.tex
.level
= level
;
275 surf_tmpl
.u
.tex
.first_layer
= layer
;
276 surf_tmpl
.u
.tex
.last_layer
= layer
;
277 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
278 cbsurf
= ctx
->create_surface(ctx
, &rtex
->resource
.b
.b
, &surf_tmpl
);
280 r600_blitter_begin(ctx
, R600_DECOMPRESS
);
281 util_blitter_custom_color(rctx
->blitter
, cbsurf
,
282 rctx
->custom_blend_decompress
);
283 r600_blitter_end(ctx
);
285 pipe_surface_reference(&cbsurf
, NULL
);
288 /* The texture will always be dirty if some layers or samples aren't flushed.
289 * I don't think this case occurs often though. */
290 if (first_layer
== 0 && last_layer
== max_layer
) {
291 rtex
->dirty_level_mask
&= ~(1 << level
);
296 void r600_decompress_color_textures(struct r600_context
*rctx
,
297 struct r600_samplerview_state
*textures
)
300 unsigned mask
= textures
->compressed_colortex_mask
;
302 /* Cayman cannot decompress an MSAA colorbuffer,
303 * but it can read it compressed, so skip this. */
304 assert(rctx
->chip_class
!= CAYMAN
);
305 if (rctx
->chip_class
== CAYMAN
) {
310 struct pipe_sampler_view
*view
;
311 struct r600_texture
*tex
;
313 i
= u_bit_scan(&mask
);
315 view
= &textures
->views
[i
]->base
;
318 tex
= (struct r600_texture
*)view
->texture
;
319 assert(tex
->cmask_size
&& tex
->fmask_size
);
321 r600_blit_decompress_color(&rctx
->context
, tex
,
322 view
->u
.tex
.first_level
, view
->u
.tex
.last_level
,
323 0, u_max_layer(&tex
->resource
.b
.b
, view
->u
.tex
.first_level
));
327 /* Helper for decompressing a portion of a color or depth resource before
328 * blitting if any decompression is needed.
329 * The driver doesn't decompress resources automatically while u_blitter is
331 static bool r600_decompress_subresource(struct pipe_context
*ctx
,
332 struct pipe_resource
*tex
,
334 unsigned first_layer
, unsigned last_layer
)
336 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
337 struct r600_texture
*rtex
= (struct r600_texture
*)tex
;
339 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
340 if (!r600_init_flushed_depth_texture(ctx
, tex
, NULL
))
341 return false; /* error */
343 r600_blit_decompress_depth(ctx
, rtex
, NULL
,
345 first_layer
, last_layer
,
346 0, u_max_sample(tex
));
347 } else if (rctx
->chip_class
!= CAYMAN
&& rtex
->fmask_size
&& rtex
->cmask_size
) {
348 r600_blit_decompress_color(ctx
, rtex
, level
, level
,
349 first_layer
, last_layer
);
354 static boolean
is_simple_msaa_resolve(const struct pipe_blit_info
*info
)
356 unsigned dst_width
= u_minify(info
->dst
.resource
->width0
, info
->dst
.level
);
357 unsigned dst_height
= u_minify(info
->dst
.resource
->height0
, info
->dst
.level
);
359 return info
->dst
.resource
->format
== info
->src
.resource
->format
&&
360 info
->dst
.resource
->format
== info
->dst
.format
&&
361 info
->src
.resource
->format
== info
->src
.format
&&
362 !info
->scissor_enable
&&
363 info
->mask
== PIPE_MASK_RGBA
&&
364 dst_width
== info
->src
.resource
->width0
&&
365 dst_height
== info
->src
.resource
->height0
&&
366 info
->dst
.box
.x
== 0 &&
367 info
->dst
.box
.y
== 0 &&
368 info
->dst
.box
.width
== dst_width
&&
369 info
->dst
.box
.height
== dst_height
&&
370 info
->src
.box
.x
== 0 &&
371 info
->src
.box
.y
== 0 &&
372 info
->src
.box
.width
== dst_width
&&
373 info
->src
.box
.height
== dst_height
;
376 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
377 const union pipe_color_union
*color
,
378 double depth
, unsigned stencil
)
380 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
381 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
.state
;
383 r600_blitter_begin(ctx
, R600_CLEAR
);
384 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
385 fb
->nr_cbufs
, buffers
, fb
->nr_cbufs
? fb
->cbufs
[0]->format
: PIPE_FORMAT_NONE
,
386 color
, depth
, stencil
);
387 r600_blitter_end(ctx
);
390 static void r600_clear_render_target(struct pipe_context
*ctx
,
391 struct pipe_surface
*dst
,
392 const union pipe_color_union
*color
,
393 unsigned dstx
, unsigned dsty
,
394 unsigned width
, unsigned height
)
396 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
398 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
399 util_blitter_clear_render_target(rctx
->blitter
, dst
, color
,
400 dstx
, dsty
, width
, height
);
401 r600_blitter_end(ctx
);
404 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
405 struct pipe_surface
*dst
,
406 unsigned clear_flags
,
409 unsigned dstx
, unsigned dsty
,
410 unsigned width
, unsigned height
)
412 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
414 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
415 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
416 dstx
, dsty
, width
, height
);
417 r600_blitter_end(ctx
);
420 void r600_copy_buffer(struct pipe_context
*ctx
, struct
421 pipe_resource
*dst
, unsigned dstx
,
422 struct pipe_resource
*src
, const struct pipe_box
*src_box
)
424 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
426 if (rctx
->screen
->has_streamout
&&
427 /* Require dword alignment. */
428 dstx
% 4 == 0 && src_box
->x
% 4 == 0 && src_box
->width
% 4 == 0) {
429 r600_blitter_begin(ctx
, R600_COPY_BUFFER
);
430 util_blitter_copy_buffer(rctx
->blitter
, dst
, dstx
, src
, src_box
->x
, src_box
->width
);
431 r600_blitter_end(ctx
);
433 util_resource_copy_region(ctx
, dst
, 0, dstx
, 0, 0, src
, 0, src_box
);
437 static bool util_format_is_subsampled_2x1_32bpp(enum pipe_format format
)
439 const struct util_format_description
*desc
= util_format_description(format
);
441 return desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
&&
442 desc
->block
.width
== 2 &&
443 desc
->block
.height
== 1 &&
444 desc
->block
.bits
== 32;
447 static void r600_resource_copy_region(struct pipe_context
*ctx
,
448 struct pipe_resource
*dst
,
450 unsigned dstx
, unsigned dsty
, unsigned dstz
,
451 struct pipe_resource
*src
,
453 const struct pipe_box
*src_box
)
455 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
456 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
457 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
458 struct pipe_surface
*dst_view
, dst_templ
;
459 struct pipe_sampler_view src_templ
, *src_view
;
460 unsigned dst_width
, dst_height
, src_width0
, src_height0
, src_widthFL
, src_heightFL
;
461 struct pipe_box sbox
;
463 /* Handle buffers first. */
464 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
465 r600_copy_buffer(ctx
, dst
, dstx
, src
, src_box
);
469 assert(u_max_sample(dst
) == u_max_sample(src
));
471 /* The driver doesn't decompress resources automatically while
472 * u_blitter is rendering. */
473 if (!r600_decompress_subresource(ctx
, src
, src_level
,
474 src_box
->z
, src_box
->z
+ src_box
->depth
- 1)) {
478 dst_width
= rdst
->surface
.level
[dst_level
].npix_x
;
479 dst_height
= rdst
->surface
.level
[dst_level
].npix_y
;
480 src_width0
= src
->width0
;
481 src_height0
= src
->height0
;
482 src_widthFL
= rsrc
->surface
.level
[src_level
].npix_x
;
483 src_heightFL
= rsrc
->surface
.level
[src_level
].npix_y
;
485 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
, src_box
);
486 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
488 if (util_format_is_compressed(src
->format
)) {
489 unsigned blocksize
= util_format_get_blocksize(src
->format
);
492 src_templ
.format
= PIPE_FORMAT_R16G16B16A16_UINT
; /* 64-bit block */
494 src_templ
.format
= PIPE_FORMAT_R32G32B32A32_UINT
; /* 128-bit block */
495 dst_templ
.format
= src_templ
.format
;
497 dst_width
= util_format_get_nblocksx(dst
->format
, rdst
->surface
.level
[dst_level
].npix_x
);
498 dst_height
= util_format_get_nblocksy(dst
->format
, rdst
->surface
.level
[dst_level
].npix_y
);
499 src_width0
= util_format_get_nblocksx(src
->format
, src
->width0
);
500 src_height0
= util_format_get_nblocksy(src
->format
, src
->height0
);
501 src_widthFL
= util_format_get_nblocksx(src
->format
, rsrc
->surface
.level
[src_level
].npix_x
);
502 src_heightFL
= util_format_get_nblocksy(src
->format
, rsrc
->surface
.level
[src_level
].npix_y
);
504 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
505 dsty
= util_format_get_nblocksy(dst
->format
, dsty
);
507 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
508 sbox
.y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
510 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
511 sbox
.height
= util_format_get_nblocksy(src
->format
, src_box
->height
);
512 sbox
.depth
= src_box
->depth
;
514 } else if (!util_blitter_is_copy_supported(rctx
->blitter
, dst
, src
,
516 if (util_format_is_subsampled_2x1_32bpp(src
->format
)) {
518 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
519 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UINT
;
521 dst_width
= util_format_get_nblocksx(dst
->format
, rdst
->surface
.level
[dst_level
].npix_x
);
522 src_width0
= util_format_get_nblocksx(src
->format
, src
->width0
);
523 src_widthFL
= util_format_get_nblocksx(src
->format
, rsrc
->surface
.level
[src_level
].npix_x
);
525 dstx
= util_format_get_nblocksx(dst
->format
, dstx
);
528 sbox
.x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
529 sbox
.width
= util_format_get_nblocksx(src
->format
, src_box
->width
);
532 unsigned blocksize
= util_format_get_blocksize(src
->format
);
536 dst_templ
.format
= PIPE_FORMAT_R8_UNORM
;
537 src_templ
.format
= PIPE_FORMAT_R8_UNORM
;
540 dst_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
541 src_templ
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
544 fprintf(stderr
, "Unhandled format %s with blocksize %u\n",
545 util_format_short_name(src
->format
), blocksize
);
551 dst_view
= r600_create_surface_custom(ctx
, dst
, &dst_templ
, dst_width
, dst_height
);
553 if (rctx
->chip_class
>= EVERGREEN
) {
554 src_view
= evergreen_create_sampler_view_custom(ctx
, src
, &src_templ
,
555 src_width0
, src_height0
);
557 src_view
= r600_create_sampler_view_custom(ctx
, src
, &src_templ
,
558 src_widthFL
, src_heightFL
);
562 /* XXX Multisample texturing is unimplemented on Cayman. In the meantime,
563 * copy only the first sample (which is the only one that is uncompressed
564 * and therefore doesn't return garbage). */
565 r600_blitter_begin(ctx
, R600_COPY_TEXTURE
);
566 util_blitter_blit_generic(rctx
->blitter
, dst_view
, dstx
, dsty
,
567 abs(src_box
->width
), abs(src_box
->height
),
568 src_view
, src_box
, src_width0
, src_height0
,
569 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
570 rctx
->chip_class
!= CAYMAN
);
571 r600_blitter_end(ctx
);
573 pipe_surface_reference(&dst_view
, NULL
);
574 pipe_sampler_view_reference(&src_view
, NULL
);
577 static void r600_msaa_color_resolve(struct pipe_context
*ctx
,
578 const struct pipe_blit_info
*info
)
580 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
581 struct pipe_screen
*screen
= ctx
->screen
;
582 struct pipe_resource
*tmp
, templ
;
583 struct pipe_blit_info blit
;
584 unsigned sample_mask
=
585 rctx
->chip_class
== CAYMAN
? ~0 :
586 ((1ull << MAX2(1, info
->src
.resource
->nr_samples
)) - 1);
588 assert(info
->src
.level
== 0);
589 assert(info
->src
.box
.depth
== 1);
590 assert(info
->dst
.box
.depth
== 1);
592 if (is_simple_msaa_resolve(info
)) {
593 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
594 util_blitter_custom_resolve_color(rctx
->blitter
,
595 info
->dst
.resource
, info
->dst
.level
,
597 info
->src
.resource
, info
->src
.box
.z
,
598 sample_mask
, rctx
->custom_blend_resolve
);
599 r600_blitter_end(ctx
);
603 /* resolve into a temporary texture, then blit */
604 templ
.target
= PIPE_TEXTURE_2D
;
605 templ
.format
= info
->src
.resource
->format
;
606 templ
.width0
= info
->src
.resource
->width0
;
607 templ
.height0
= info
->src
.resource
->height0
;
609 templ
.array_size
= 1;
610 templ
.last_level
= 0;
611 templ
.nr_samples
= 0;
612 templ
.usage
= PIPE_USAGE_STATIC
;
613 templ
.bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
616 tmp
= screen
->resource_create(screen
, &templ
);
619 r600_blitter_begin(ctx
, R600_COLOR_RESOLVE
);
620 util_blitter_custom_resolve_color(rctx
->blitter
,
622 info
->src
.resource
, info
->src
.box
.z
,
623 sample_mask
, rctx
->custom_blend_resolve
);
624 r600_blitter_end(ctx
);
628 blit
.src
.resource
= tmp
;
631 r600_blitter_begin(ctx
, R600_BLIT
);
632 util_blitter_blit(rctx
->blitter
, &blit
);
633 r600_blitter_end(ctx
);
635 pipe_resource_reference(&tmp
, NULL
);
638 static void r600_blit(struct pipe_context
*ctx
,
639 const struct pipe_blit_info
*info
)
641 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
643 assert(util_blitter_is_blit_supported(rctx
->blitter
, info
));
645 if (info
->src
.resource
->nr_samples
> 1 &&
646 info
->dst
.resource
->nr_samples
<= 1 &&
647 !util_format_is_depth_or_stencil(info
->src
.resource
->format
) &&
648 !util_format_is_pure_integer(info
->src
.resource
->format
)) {
649 r600_msaa_color_resolve(ctx
, info
);
653 /* The driver doesn't decompress resources automatically while
654 * u_blitter is rendering. */
655 if (!r600_decompress_subresource(ctx
, info
->src
.resource
, info
->src
.level
,
657 info
->src
.box
.z
+ info
->src
.box
.depth
- 1)) {
661 r600_blitter_begin(ctx
, R600_BLIT
);
662 util_blitter_blit(rctx
->blitter
, info
);
663 r600_blitter_end(ctx
);
666 void r600_init_blit_functions(struct r600_context
*rctx
)
668 rctx
->context
.clear
= r600_clear
;
669 rctx
->context
.clear_render_target
= r600_clear_render_target
;
670 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
671 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
672 rctx
->context
.blit
= r600_blit
;