r600g: rename r600_resource_texture to r600_texture
[mesa.git] / src / gallium / drivers / r600 / r600_blit.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23 #include "r600_pipe.h"
24 #include "util/u_surface.h"
25 #include "util/u_blitter.h"
26 #include "util/u_format.h"
27
28 enum r600_blitter_op /* bitmask */
29 {
30 R600_SAVE_FRAGMENT_STATE = 1,
31 R600_SAVE_TEXTURES = 2,
32 R600_SAVE_FRAMEBUFFER = 4,
33 R600_DISABLE_RENDER_COND = 8,
34
35 R600_CLEAR = R600_SAVE_FRAGMENT_STATE,
36
37 R600_CLEAR_SURFACE = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER,
38
39 R600_COPY_BUFFER = R600_DISABLE_RENDER_COND,
40
41 R600_COPY_TEXTURE = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_SAVE_TEXTURES |
42 R600_DISABLE_RENDER_COND,
43
44 R600_DECOMPRESS = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND,
45
46 R600_COLOR_RESOLVE = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND
47 };
48
49 static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op)
50 {
51 struct r600_context *rctx = (struct r600_context *)ctx;
52
53 r600_suspend_nontimer_queries(rctx);
54
55 util_blitter_save_vertex_buffers(rctx->blitter,
56 util_last_bit(rctx->vertex_buffer_state.enabled_mask),
57 rctx->vertex_buffer_state.vb);
58 util_blitter_save_vertex_elements(rctx->blitter, rctx->vertex_elements);
59 util_blitter_save_vertex_shader(rctx->blitter, rctx->vs_shader);
60 util_blitter_save_so_targets(rctx->blitter, rctx->num_so_targets,
61 (struct pipe_stream_output_target**)rctx->so_targets);
62 util_blitter_save_rasterizer(rctx->blitter, rctx->states[R600_PIPE_STATE_RASTERIZER]);
63
64 if (op & R600_SAVE_FRAGMENT_STATE) {
65 if (rctx->states[R600_PIPE_STATE_VIEWPORT]) {
66 util_blitter_save_viewport(rctx->blitter, &rctx->viewport);
67 }
68 util_blitter_save_fragment_shader(rctx->blitter, rctx->ps_shader);
69 util_blitter_save_blend(rctx->blitter, rctx->states[R600_PIPE_STATE_BLEND]);
70 util_blitter_save_depth_stencil_alpha(rctx->blitter, rctx->states[R600_PIPE_STATE_DSA]);
71 if (rctx->states[R600_PIPE_STATE_STENCIL_REF]) {
72 util_blitter_save_stencil_ref(rctx->blitter, &rctx->stencil_ref);
73 }
74 util_blitter_save_sample_mask(rctx->blitter, rctx->sample_mask.sample_mask);
75 }
76
77 if (op & R600_SAVE_FRAMEBUFFER)
78 util_blitter_save_framebuffer(rctx->blitter, &rctx->framebuffer);
79
80 if (op & R600_SAVE_TEXTURES) {
81 util_blitter_save_fragment_sampler_states(
82 rctx->blitter, rctx->ps_samplers.n_samplers,
83 (void**)rctx->ps_samplers.samplers);
84
85 util_blitter_save_fragment_sampler_views(
86 rctx->blitter, util_last_bit(rctx->ps_samplers.views.enabled_mask),
87 (struct pipe_sampler_view**)rctx->ps_samplers.views.views);
88 }
89
90 if ((op & R600_DISABLE_RENDER_COND) && rctx->current_render_cond) {
91 rctx->saved_render_cond = rctx->current_render_cond;
92 rctx->saved_render_cond_mode = rctx->current_render_cond_mode;
93 rctx->context.render_condition(&rctx->context, NULL, 0);
94 }
95
96 }
97
98 static void r600_blitter_end(struct pipe_context *ctx)
99 {
100 struct r600_context *rctx = (struct r600_context *)ctx;
101 if (rctx->saved_render_cond) {
102 rctx->context.render_condition(&rctx->context,
103 rctx->saved_render_cond,
104 rctx->saved_render_cond_mode);
105 rctx->saved_render_cond = NULL;
106 }
107 r600_resume_nontimer_queries(rctx);
108 }
109
110 static unsigned u_max_layer(struct pipe_resource *r, unsigned level)
111 {
112 switch (r->target) {
113 case PIPE_TEXTURE_CUBE:
114 return 6 - 1;
115 case PIPE_TEXTURE_3D:
116 return u_minify(r->depth0, level) - 1;
117 case PIPE_TEXTURE_1D_ARRAY:
118 case PIPE_TEXTURE_2D_ARRAY:
119 return r->array_size - 1;
120 default:
121 return 0;
122 }
123 }
124
125 static unsigned u_max_sample(struct pipe_resource *r)
126 {
127 return r->nr_samples ? r->nr_samples - 1 : 0;
128 }
129
130 void r600_blit_uncompress_depth(struct pipe_context *ctx,
131 struct r600_texture *texture,
132 struct r600_texture *staging,
133 unsigned first_level, unsigned last_level,
134 unsigned first_layer, unsigned last_layer,
135 unsigned first_sample, unsigned last_sample)
136 {
137 struct r600_context *rctx = (struct r600_context *)ctx;
138 unsigned layer, level, sample, checked_last_layer, max_layer, max_sample;
139 struct r600_texture *flushed_depth_texture = staging ?
140 staging : texture->flushed_depth_texture;
141 const struct util_format_description *desc =
142 util_format_description(texture->resource.b.b.format);
143 float depth;
144
145 if (!staging && !texture->dirty_db_mask)
146 return;
147
148 if (rctx->family == CHIP_RV610 || rctx->family == CHIP_RV630 ||
149 rctx->family == CHIP_RV620 || rctx->family == CHIP_RV635)
150 depth = 0.0f;
151 else
152 depth = 1.0f;
153
154 /* Enable decompression in DB_RENDER_CONTROL */
155 rctx->db_misc_state.flush_depthstencil_through_cb = true;
156 rctx->db_misc_state.copy_depth = util_format_has_depth(desc);
157 rctx->db_misc_state.copy_stencil = util_format_has_stencil(desc);
158 rctx->db_misc_state.copy_sample = first_sample;
159 r600_atom_dirty(rctx, &rctx->db_misc_state.atom);
160
161 max_sample = u_max_sample(&texture->resource.b.b);
162
163 for (level = first_level; level <= last_level; level++) {
164 if (!staging && !(texture->dirty_db_mask & (1 << level)))
165 continue;
166
167 /* The smaller the mipmap level, the less layers there are
168 * as far as 3D textures are concerned. */
169 max_layer = u_max_layer(&texture->resource.b.b, level);
170 checked_last_layer = last_layer < max_layer ? last_layer : max_layer;
171
172 for (layer = first_layer; layer <= checked_last_layer; layer++) {
173 for (sample = first_sample; sample <= last_sample; sample++) {
174 struct pipe_surface *zsurf, *cbsurf, surf_tmpl;
175
176 if (sample != rctx->db_misc_state.copy_sample) {
177 rctx->db_misc_state.copy_sample = sample;
178 r600_atom_dirty(rctx, &rctx->db_misc_state.atom);
179 }
180
181 surf_tmpl.format = texture->resource.b.b.format;
182 surf_tmpl.u.tex.level = level;
183 surf_tmpl.u.tex.first_layer = layer;
184 surf_tmpl.u.tex.last_layer = layer;
185 surf_tmpl.usage = PIPE_BIND_DEPTH_STENCIL;
186
187 zsurf = ctx->create_surface(ctx, &texture->resource.b.b, &surf_tmpl);
188
189 surf_tmpl.format = flushed_depth_texture->resource.b.b.format;
190 surf_tmpl.u.tex.level = level;
191 surf_tmpl.u.tex.first_layer = layer;
192 surf_tmpl.u.tex.last_layer = layer;
193 surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
194 cbsurf = ctx->create_surface(ctx,
195 &flushed_depth_texture->resource.b.b, &surf_tmpl);
196
197 r600_blitter_begin(ctx, R600_DECOMPRESS);
198 util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, 1 << sample,
199 rctx->custom_dsa_flush, depth);
200 r600_blitter_end(ctx);
201
202 pipe_surface_reference(&zsurf, NULL);
203 pipe_surface_reference(&cbsurf, NULL);
204 }
205 }
206
207 /* The texture will always be dirty if some layers or samples aren't flushed.
208 * I don't think this case occurs often though. */
209 if (!staging &&
210 first_layer == 0 && last_layer == max_layer &&
211 first_sample == 0 && last_sample == max_sample) {
212 texture->dirty_db_mask &= ~(1 << level);
213 }
214 }
215
216 /* reenable compression in DB_RENDER_CONTROL */
217 rctx->db_misc_state.flush_depthstencil_through_cb = false;
218 r600_atom_dirty(rctx, &rctx->db_misc_state.atom);
219 }
220
221 void r600_flush_depth_textures(struct r600_context *rctx,
222 struct r600_samplerview_state *textures)
223 {
224 unsigned i;
225 unsigned depth_texture_mask = textures->depth_texture_mask;
226
227 while (depth_texture_mask) {
228 struct pipe_sampler_view *view;
229 struct r600_texture *tex;
230
231 i = u_bit_scan(&depth_texture_mask);
232
233 view = &textures->views[i]->base;
234 assert(view);
235
236 tex = (struct r600_texture *)view->texture;
237 assert(tex->is_depth && !tex->is_flushing_texture);
238
239 r600_blit_uncompress_depth(&rctx->context, tex, NULL,
240 view->u.tex.first_level, view->u.tex.last_level,
241 0, u_max_layer(&tex->resource.b.b, view->u.tex.first_level),
242 0, u_max_sample(&tex->resource.b.b));
243 }
244 }
245
246 static void r600_copy_first_sample(struct pipe_context *ctx,
247 const struct pipe_resolve_info *info)
248 {
249 struct r600_context *rctx = (struct r600_context *)ctx;
250 struct r600_texture *rsrc = (struct r600_texture*)info->src.res;
251 struct pipe_surface *dst_view, dst_templ;
252 struct pipe_sampler_view src_templ, *src_view;
253 struct pipe_box box;
254
255 if (rsrc->is_depth && !rsrc->is_flushing_texture) {
256 if (!r600_init_flushed_depth_texture(ctx, info->src.res, NULL))
257 return; /* error */
258
259 /* Decompress the first sample only. */
260 r600_blit_uncompress_depth(ctx, rsrc, NULL,
261 0, 0,
262 info->src.layer, info->src.layer,
263 0, 0);
264 }
265
266 /* this is correct for upside-down blits too */
267 u_box_2d(info->src.x0,
268 info->src.y0,
269 info->src.x1 - info->src.x0,
270 info->src.y1 - info->src.y0, &box);
271
272 /* Initialize the surface. */
273 util_blitter_default_dst_texture(&dst_templ, info->dst.res,
274 info->dst.level, info->dst.layer, &box);
275 dst_view = ctx->create_surface(ctx, info->dst.res, &dst_templ);
276
277 /* Initialize the sampler view. */
278 util_blitter_default_src_texture(&src_templ, info->src.res, 0);
279 src_view = ctx->create_sampler_view(ctx, info->src.res, &src_templ);
280
281 /* Copy the first sample into dst. */
282 r600_blitter_begin(ctx, R600_COPY_TEXTURE);
283 util_blitter_copy_texture_view(rctx->blitter, dst_view, ~0, info->dst.x0,
284 info->dst.y0, src_view, 0, &box,
285 info->src.res->width0, info->src.res->height0,
286 info->mask);
287 r600_blitter_end(ctx);
288
289 pipe_surface_reference(&dst_view, NULL);
290 pipe_sampler_view_reference(&src_view, NULL);
291 }
292
293 static boolean is_simple_resolve(const struct pipe_resolve_info *info)
294 {
295 unsigned dst_width = u_minify(info->dst.res->width0, info->dst.level);
296 unsigned dst_height = u_minify(info->dst.res->height0, info->dst.level);
297
298 return info->dst.res->format == info->src.res->format &&
299 dst_width == info->src.res->width0 &&
300 dst_height == info->src.res->height0 &&
301 info->dst.x0 == 0 &&
302 info->dst.y0 == 0 &&
303 info->dst.x1 == dst_width &&
304 info->dst.y1 == dst_height &&
305 info->src.x0 == 0 &&
306 info->src.y0 == 0 &&
307 info->src.x1 == dst_width &&
308 info->src.y1 == dst_height;
309 }
310
311 static void r600_color_resolve(struct pipe_context *ctx,
312 const struct pipe_resolve_info *info)
313 {
314 struct r600_context *rctx = (struct r600_context *)ctx;
315 struct pipe_screen *screen = ctx->screen;
316 struct pipe_resource *tmp, templ;
317 struct pipe_box box;
318
319 assert((info->mask & PIPE_MASK_RGBA) == PIPE_MASK_RGBA);
320
321 if (is_simple_resolve(info)) {
322 r600_blitter_begin(ctx, R600_COLOR_RESOLVE);
323 util_blitter_custom_resolve_color(rctx->blitter,
324 info->dst.res, info->dst.level, info->dst.layer,
325 info->src.res, info->src.layer,
326 rctx->custom_blend_resolve);
327 r600_blitter_end(ctx);
328 return;
329 }
330
331 /* resolve into a temporary texture, then blit */
332 templ.target = PIPE_TEXTURE_2D;
333 templ.format = info->src.res->format;
334 templ.width0 = info->src.res->width0;
335 templ.height0 = info->src.res->height0;
336 templ.depth0 = 1;
337 templ.array_size = 1;
338 templ.last_level = 0;
339 templ.nr_samples = 0;
340 templ.usage = PIPE_USAGE_STATIC;
341 templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
342 templ.flags = 0;
343
344 tmp = screen->resource_create(screen, &templ);
345
346 /* XXX use scissor, so that only the needed part of the resource is resolved */
347 r600_blitter_begin(ctx, R600_COLOR_RESOLVE);
348 util_blitter_custom_resolve_color(rctx->blitter,
349 tmp, 0, 0,
350 info->src.res, info->src.layer,
351 rctx->custom_blend_resolve);
352 r600_blitter_end(ctx);
353
354 /* this is correct for upside-down blits too */
355 u_box_2d(info->src.x0,
356 info->src.y0,
357 info->src.x1 - info->src.x0,
358 info->src.y1 - info->src.y0, &box);
359
360 r600_blitter_begin(ctx, R600_COPY_TEXTURE);
361 util_blitter_copy_texture(rctx->blitter, info->dst.res, info->dst.level,
362 ~0, info->dst.x0, info->dst.y0, info->dst.layer,
363 tmp, 0, 0, &box);
364 r600_blitter_end(ctx);
365
366 pipe_resource_reference(&tmp, NULL);
367 }
368
369 static void r600_resource_resolve(struct pipe_context *ctx,
370 const struct pipe_resolve_info *info)
371 {
372 /* make sure we're doing a resolve operation */
373 assert(info->src.res->nr_samples > 1);
374 assert(info->dst.res->nr_samples <= 1);
375
376 /* limitations of multisample resources */
377 assert(info->src.res->last_level == 0);
378 assert(info->src.res->target == PIPE_TEXTURE_2D ||
379 info->src.res->target == PIPE_TEXTURE_2D_ARRAY);
380
381 /* check if the resolve box is valid */
382 assert(info->dst.x0 < info->dst.x1);
383 assert(info->dst.y0 < info->dst.y1);
384
385 /* scaled resolve isn't allowed */
386 assert(abs(info->dst.x0 - info->dst.x1) ==
387 abs(info->src.x0 - info->src.x1));
388 assert(abs(info->dst.y0 - info->dst.y1) ==
389 abs(info->src.y0 - info->src.y1));
390
391 if ((info->mask & PIPE_MASK_ZS) ||
392 util_format_is_pure_integer(info->src.res->format)) {
393 r600_copy_first_sample(ctx, info);
394 } else {
395 r600_color_resolve(ctx, info);
396 }
397 }
398
399 static void r600_clear(struct pipe_context *ctx, unsigned buffers,
400 const union pipe_color_union *color,
401 double depth, unsigned stencil)
402 {
403 struct r600_context *rctx = (struct r600_context *)ctx;
404 struct pipe_framebuffer_state *fb = &rctx->framebuffer;
405
406 r600_blitter_begin(ctx, R600_CLEAR);
407 util_blitter_clear(rctx->blitter, fb->width, fb->height,
408 fb->nr_cbufs, buffers, fb->nr_cbufs ? fb->cbufs[0]->format : PIPE_FORMAT_NONE,
409 color, depth, stencil);
410 r600_blitter_end(ctx);
411 }
412
413 static void r600_clear_render_target(struct pipe_context *ctx,
414 struct pipe_surface *dst,
415 const union pipe_color_union *color,
416 unsigned dstx, unsigned dsty,
417 unsigned width, unsigned height)
418 {
419 struct r600_context *rctx = (struct r600_context *)ctx;
420
421 r600_blitter_begin(ctx, R600_CLEAR_SURFACE);
422 util_blitter_clear_render_target(rctx->blitter, dst, color,
423 dstx, dsty, width, height);
424 r600_blitter_end(ctx);
425 }
426
427 static void r600_clear_depth_stencil(struct pipe_context *ctx,
428 struct pipe_surface *dst,
429 unsigned clear_flags,
430 double depth,
431 unsigned stencil,
432 unsigned dstx, unsigned dsty,
433 unsigned width, unsigned height)
434 {
435 struct r600_context *rctx = (struct r600_context *)ctx;
436
437 r600_blitter_begin(ctx, R600_CLEAR_SURFACE);
438 util_blitter_clear_depth_stencil(rctx->blitter, dst, clear_flags, depth, stencil,
439 dstx, dsty, width, height);
440 r600_blitter_end(ctx);
441 }
442
443 void r600_copy_buffer(struct pipe_context *ctx, struct
444 pipe_resource *dst, unsigned dstx,
445 struct pipe_resource *src, const struct pipe_box *src_box)
446 {
447 struct r600_context *rctx = (struct r600_context*)ctx;
448
449 if (rctx->screen->has_streamout &&
450 /* Require dword alignment. */
451 dstx % 4 == 0 && src_box->x % 4 == 0 && src_box->width % 4 == 0) {
452 r600_blitter_begin(ctx, R600_COPY_BUFFER);
453 util_blitter_copy_buffer(rctx->blitter, dst, dstx, src, src_box->x, src_box->width);
454 r600_blitter_end(ctx);
455 } else {
456 util_resource_copy_region(ctx, dst, 0, dstx, 0, 0, src, 0, src_box);
457 }
458 }
459
460 struct texture_orig_info {
461 unsigned format;
462 unsigned width0;
463 unsigned height0;
464 unsigned npix_x;
465 unsigned npix_y;
466 unsigned npix0_x;
467 unsigned npix0_y;
468 };
469
470 static void r600_compressed_to_blittable(struct pipe_resource *tex,
471 unsigned level,
472 struct texture_orig_info *orig)
473 {
474 struct r600_texture *rtex = (struct r600_texture*)tex;
475 unsigned pixsize = util_format_get_blocksize(rtex->resource.b.b.format);
476 int new_format;
477 int new_height, new_width;
478
479 orig->format = tex->format;
480 orig->width0 = tex->width0;
481 orig->height0 = tex->height0;
482 orig->npix0_x = rtex->surface.level[0].npix_x;
483 orig->npix0_y = rtex->surface.level[0].npix_y;
484 orig->npix_x = rtex->surface.level[level].npix_x;
485 orig->npix_y = rtex->surface.level[level].npix_y;
486
487 if (pixsize == 8)
488 new_format = PIPE_FORMAT_R16G16B16A16_UINT; /* 64-bit block */
489 else
490 new_format = PIPE_FORMAT_R32G32B32A32_UINT; /* 128-bit block */
491
492 new_width = util_format_get_nblocksx(tex->format, orig->width0);
493 new_height = util_format_get_nblocksy(tex->format, orig->height0);
494
495 tex->width0 = new_width;
496 tex->height0 = new_height;
497 tex->format = new_format;
498 rtex->surface.level[0].npix_x = util_format_get_nblocksx(orig->format, orig->npix0_x);
499 rtex->surface.level[0].npix_y = util_format_get_nblocksy(orig->format, orig->npix0_y);
500 rtex->surface.level[level].npix_x = util_format_get_nblocksx(orig->format, orig->npix_x);
501 rtex->surface.level[level].npix_y = util_format_get_nblocksy(orig->format, orig->npix_y);
502 }
503
504 static void r600_change_format(struct pipe_resource *tex,
505 unsigned level,
506 struct texture_orig_info *orig,
507 enum pipe_format format)
508 {
509 struct r600_texture *rtex = (struct r600_texture*)tex;
510
511 orig->format = tex->format;
512 orig->width0 = tex->width0;
513 orig->height0 = tex->height0;
514 orig->npix0_x = rtex->surface.level[0].npix_x;
515 orig->npix0_y = rtex->surface.level[0].npix_y;
516 orig->npix_x = rtex->surface.level[level].npix_x;
517 orig->npix_y = rtex->surface.level[level].npix_y;
518
519 tex->format = format;
520 }
521
522 static void r600_reset_blittable_to_orig(struct pipe_resource *tex,
523 unsigned level,
524 struct texture_orig_info *orig)
525 {
526 struct r600_texture *rtex = (struct r600_texture*)tex;
527
528 tex->format = orig->format;
529 tex->width0 = orig->width0;
530 tex->height0 = orig->height0;
531 rtex->surface.level[0].npix_x = orig->npix0_x;
532 rtex->surface.level[0].npix_y = orig->npix0_y;
533 rtex->surface.level[level].npix_x = orig->npix_x;
534 rtex->surface.level[level].npix_y = orig->npix_y;
535 }
536
537 static void r600_resource_copy_region(struct pipe_context *ctx,
538 struct pipe_resource *dst,
539 unsigned dst_level,
540 unsigned dstx, unsigned dsty, unsigned dstz,
541 struct pipe_resource *src,
542 unsigned src_level,
543 const struct pipe_box *src_box)
544 {
545 struct r600_context *rctx = (struct r600_context *)ctx;
546 struct r600_texture *rsrc = (struct r600_texture*)src;
547 struct texture_orig_info orig_info[2];
548 struct pipe_box sbox;
549 const struct pipe_box *psbox = src_box;
550 boolean restore_orig[2];
551 unsigned last_sample, i;
552
553 memset(orig_info, 0, sizeof(orig_info));
554
555 /* Handle buffers first. */
556 if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
557 r600_copy_buffer(ctx, dst, dstx, src, src_box);
558 return;
559 }
560
561 assert(u_max_sample(dst) == u_max_sample(src));
562 last_sample = u_max_sample(dst);
563
564 /* This must be done before entering u_blitter to avoid recursion. */
565 if (rsrc->is_depth && !rsrc->is_flushing_texture) {
566 if (!r600_init_flushed_depth_texture(ctx, src, NULL))
567 return; /* error */
568
569 r600_blit_uncompress_depth(ctx, rsrc, NULL,
570 src_level, src_level,
571 src_box->z, src_box->z + src_box->depth - 1,
572 0, u_max_sample(src));
573 }
574
575 restore_orig[0] = restore_orig[1] = FALSE;
576
577 if (util_format_is_compressed(src->format) &&
578 util_format_is_compressed(dst->format)) {
579 r600_compressed_to_blittable(src, src_level, &orig_info[0]);
580 restore_orig[0] = TRUE;
581 sbox.x = util_format_get_nblocksx(orig_info[0].format, src_box->x);
582 sbox.y = util_format_get_nblocksy(orig_info[0].format, src_box->y);
583 sbox.z = src_box->z;
584 sbox.width = util_format_get_nblocksx(orig_info[0].format, src_box->width);
585 sbox.height = util_format_get_nblocksy(orig_info[0].format, src_box->height);
586 sbox.depth = src_box->depth;
587 psbox=&sbox;
588
589 r600_compressed_to_blittable(dst, dst_level, &orig_info[1]);
590 restore_orig[1] = TRUE;
591 /* translate the dst box as well */
592 dstx = util_format_get_nblocksx(orig_info[1].format, dstx);
593 dsty = util_format_get_nblocksy(orig_info[1].format, dsty);
594 } else if (!util_blitter_is_copy_supported(rctx->blitter, dst, src,
595 PIPE_MASK_RGBAZS)) {
596 unsigned blocksize = util_format_get_blocksize(src->format);
597
598 switch (blocksize) {
599 case 1:
600 r600_change_format(src, src_level, &orig_info[0],
601 PIPE_FORMAT_R8_UNORM);
602 r600_change_format(dst, dst_level, &orig_info[1],
603 PIPE_FORMAT_R8_UNORM);
604 break;
605 case 4:
606 r600_change_format(src, src_level, &orig_info[0],
607 PIPE_FORMAT_R8G8B8A8_UNORM);
608 r600_change_format(dst, dst_level, &orig_info[1],
609 PIPE_FORMAT_R8G8B8A8_UNORM);
610 break;
611 default:
612 fprintf(stderr, "Unhandled format %s with blocksize %u\n",
613 util_format_short_name(src->format), blocksize);
614 assert(0);
615 }
616 restore_orig[0] = TRUE;
617 restore_orig[1] = TRUE;
618 }
619
620 for (i = 0; i <= last_sample; i++) {
621 r600_blitter_begin(ctx, R600_COPY_TEXTURE);
622 util_blitter_copy_texture(rctx->blitter, dst, dst_level, 1 << i, dstx, dsty, dstz,
623 src, src_level, i, psbox);
624 r600_blitter_end(ctx);
625 }
626
627 if (restore_orig[0])
628 r600_reset_blittable_to_orig(src, src_level, &orig_info[0]);
629
630 if (restore_orig[1])
631 r600_reset_blittable_to_orig(dst, dst_level, &orig_info[1]);
632 }
633
634 void r600_init_blit_functions(struct r600_context *rctx)
635 {
636 rctx->context.clear = r600_clear;
637 rctx->context.clear_render_target = r600_clear_render_target;
638 rctx->context.clear_depth_stencil = r600_clear_depth_stencil;
639 rctx->context.resource_copy_region = r600_resource_copy_region;
640 rctx->context.resource_resolve = r600_resource_resolve;
641 }