103780ffe63c3be4439d029b1d57f8be411da109
[profile/ivi/mesa.git] / src / gallium / drivers / r300 / r300_blit.c
1 /*
2  * Copyright 2009 Marek Olšák <maraeo@gmail.com>
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 "r300_context.h"
24 #include "r300_emit.h"
25 #include "r300_texture.h"
26
27 #include "util/u_format.h"
28 #include "util/u_pack_color.h"
29 #include "util/u_surface.h"
30
31 enum r300_blitter_op /* bitmask */
32 {
33     R300_STOP_QUERY         = 1,
34     R300_SAVE_TEXTURES      = 2,
35     R300_SAVE_FRAMEBUFFER   = 4,
36     R300_IGNORE_RENDER_COND = 8,
37
38     R300_CLEAR         = R300_STOP_QUERY,
39
40     R300_CLEAR_SURFACE = R300_STOP_QUERY | R300_SAVE_FRAMEBUFFER,
41
42     R300_COPY          = R300_STOP_QUERY | R300_SAVE_FRAMEBUFFER |
43                          R300_SAVE_TEXTURES | R300_IGNORE_RENDER_COND,
44
45     R300_DECOMPRESS    = R300_STOP_QUERY | R300_IGNORE_RENDER_COND,
46 };
47
48 static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op op)
49 {
50     if ((op & R300_STOP_QUERY) && r300->query_current) {
51         r300->blitter_saved_query = r300->query_current;
52         r300_stop_query(r300);
53     }
54
55     /* Yeah we have to save all those states to ensure the blitter operation
56      * is really transparent. The states will be restored by the blitter once
57      * copying is done. */
58     util_blitter_save_blend(r300->blitter, r300->blend_state.state);
59     util_blitter_save_depth_stencil_alpha(r300->blitter, r300->dsa_state.state);
60     util_blitter_save_stencil_ref(r300->blitter, &(r300->stencil_ref));
61     util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state);
62     util_blitter_save_fragment_shader(r300->blitter, r300->fs.state);
63     util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state);
64     util_blitter_save_viewport(r300->blitter, &r300->viewport);
65     util_blitter_save_vertex_elements(r300->blitter, r300->velems);
66     if (r300->vbuf_mgr) {
67         util_blitter_save_vertex_buffers(r300->blitter, r300->vbuf_mgr->nr_vertex_buffers,
68                                          r300->vbuf_mgr->vertex_buffer);
69     } else {
70         util_blitter_save_vertex_buffers(r300->blitter, r300->nr_vertex_buffers,
71                                          r300->vertex_buffer);
72     }
73
74     if (op & R300_SAVE_FRAMEBUFFER) {
75         util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state);
76     }
77
78     if (op & R300_SAVE_TEXTURES) {
79         struct r300_textures_state* state =
80             (struct r300_textures_state*)r300->textures_state.state;
81
82         util_blitter_save_fragment_sampler_states(
83             r300->blitter, state->sampler_state_count,
84             (void**)state->sampler_states);
85
86         util_blitter_save_fragment_sampler_views(
87             r300->blitter, state->sampler_view_count,
88             (struct pipe_sampler_view**)state->sampler_views);
89     }
90
91     if (op & R300_IGNORE_RENDER_COND) {
92         /* Save the flag. */
93         r300->blitter_saved_skip_rendering = r300->skip_rendering+1;
94         r300->skip_rendering = FALSE;
95     } else {
96         r300->blitter_saved_skip_rendering = 0;
97     }
98 }
99
100 static void r300_blitter_end(struct r300_context *r300)
101 {
102     if (r300->blitter_saved_query) {
103         r300_resume_query(r300, r300->blitter_saved_query);
104         r300->blitter_saved_query = NULL;
105     }
106
107     if (r300->blitter_saved_skip_rendering) {
108         /* Restore the flag. */
109         r300->skip_rendering = r300->blitter_saved_skip_rendering-1;
110     }
111 }
112
113 static uint32_t r300_depth_clear_cb_value(enum pipe_format format,
114                                           const float* rgba)
115 {
116     union util_color uc;
117     util_pack_color(rgba, format, &uc);
118
119     if (util_format_get_blocksizebits(format) == 32)
120         return uc.ui;
121     else
122         return uc.us | (uc.us << 16);
123 }
124
125 static boolean r300_cbzb_clear_allowed(struct r300_context *r300,
126                                        unsigned clear_buffers)
127 {
128     struct pipe_framebuffer_state *fb =
129         (struct pipe_framebuffer_state*)r300->fb_state.state;
130
131     /* Only color clear allowed, and only one colorbuffer. */
132     if (clear_buffers != PIPE_CLEAR_COLOR || fb->nr_cbufs != 1)
133         return FALSE;
134
135     return r300_surface(fb->cbufs[0])->cbzb_allowed;
136 }
137
138 static boolean r300_fast_zclear_allowed(struct r300_context *r300)
139 {
140     struct pipe_framebuffer_state *fb =
141         (struct pipe_framebuffer_state*)r300->fb_state.state;
142
143     return r300_resource(fb->zsbuf->texture)->tex.zmask_dwords[fb->zsbuf->u.tex.level] != 0;
144 }
145
146 static boolean r300_hiz_clear_allowed(struct r300_context *r300)
147 {
148     struct pipe_framebuffer_state *fb =
149         (struct pipe_framebuffer_state*)r300->fb_state.state;
150
151     return r300_resource(fb->zsbuf->texture)->tex.hiz_dwords[fb->zsbuf->u.tex.level] != 0;
152 }
153
154 static uint32_t r300_depth_clear_value(enum pipe_format format,
155                                        double depth, unsigned stencil)
156 {
157     switch (format) {
158         case PIPE_FORMAT_Z16_UNORM:
159         case PIPE_FORMAT_X8Z24_UNORM:
160             return util_pack_z(format, depth);
161
162         case PIPE_FORMAT_S8_UINT_Z24_UNORM:
163             return util_pack_z_stencil(format, depth, stencil);
164
165         default:
166             assert(0);
167             return 0;
168     }
169 }
170
171 static uint32_t r300_hiz_clear_value(double depth)
172 {
173     uint32_t r = (uint32_t)(CLAMP(depth, 0, 1) * 255.5);
174     assert(r <= 255);
175     return r | (r << 8) | (r << 16) | (r << 24);
176 }
177
178 /* Clear currently bound buffers. */
179 static void r300_clear(struct pipe_context* pipe,
180                        unsigned buffers,
181                        const union pipe_color_union *color,
182                        double depth,
183                        unsigned stencil)
184 {
185     /* My notes about Zbuffer compression:
186      *
187      * 1) The zbuffer must be micro-tiled and whole microtiles must be
188      *    written if compression is enabled. If microtiling is disabled,
189      *    it locks up.
190      *
191      * 2) There is ZMASK RAM which contains a compressed zbuffer.
192      *    Each dword of the Z Mask contains compression information
193      *    for 16 4x4 pixel tiles, that is 2 bits for each tile.
194      *    On chips with 2 Z pipes, every other dword maps to a different
195      *    pipe. On newer chipsets, there is a new compression mode
196      *    with 8x8 pixel tiles per 2 bits.
197      *
198      * 3) The FASTFILL bit has nothing to do with filling. It only tells hw
199      *    it should look in the ZMASK RAM first before fetching from a real
200      *    zbuffer.
201      *
202      * 4) If a pixel is in a cleared state, ZB_DEPTHCLEARVALUE is returned
203      *    during zbuffer reads instead of the value that is actually stored
204      *    in the zbuffer memory. A pixel is in a cleared state when its ZMASK
205      *    is equal to 0. Therefore, if you clear ZMASK with zeros, you may
206      *    leave the zbuffer memory uninitialized, but then you must enable
207      *    compression, so that the ZMASK RAM is actually used.
208      *
209      * 5) Each 4x4 (or 8x8) tile is automatically decompressed and recompressed
210      *    during zbuffer updates. A special decompressing operation should be
211      *    used to fully decompress a zbuffer, which basically just stores all
212      *    compressed tiles in ZMASK to the zbuffer memory.
213      *
214      * 6) For a 16-bit zbuffer, compression causes a hung with one or
215      *    two samples and should not be used.
216      *
217      * 7) FORCE_COMPRESSED_STENCIL_VALUE should be enabled for stencil clears
218      *    to avoid needless decompression.
219      *
220      * 8) Fastfill must not be used if reading of compressed Z data is disabled
221      *    and writing of compressed Z data is enabled (RD/WR_COMP_ENABLE),
222      *    i.e. it cannot be used to compress the zbuffer.
223      *
224      * 9) ZB_CB_CLEAR does not interact with zbuffer compression in any way.
225      *
226      * - Marek
227      */
228
229     struct r300_context* r300 = r300_context(pipe);
230     struct pipe_framebuffer_state *fb =
231         (struct pipe_framebuffer_state*)r300->fb_state.state;
232     struct r300_hyperz_state *hyperz =
233         (struct r300_hyperz_state*)r300->hyperz_state.state;
234     uint32_t width = fb->width;
235     uint32_t height = fb->height;
236     uint32_t hyperz_dcv = hyperz->zb_depthclearvalue;
237
238     /* Enable fast Z clear.
239      * The zbuffer must be in micro-tiled mode, otherwise it locks up. */
240     if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
241         boolean zmask_clear, hiz_clear;
242
243         zmask_clear = r300_fast_zclear_allowed(r300);
244         hiz_clear = r300_hiz_clear_allowed(r300);
245
246         /* If we need Hyper-Z. */
247         if (zmask_clear || hiz_clear) {
248             r300->num_z_clears++;
249
250             /* Try to obtain the access to Hyper-Z buffers if we don't have one. */
251             if (!r300->hyperz_enabled) {
252                 r300->hyperz_enabled =
253                     r300->rws->cs_request_feature(r300->cs,
254                                                 RADEON_FID_R300_HYPERZ_ACCESS,
255                                                 TRUE);
256                 if (r300->hyperz_enabled) {
257                    /* Need to emit HyperZ buffer regs for the first time. */
258                    r300_mark_fb_state_dirty(r300, R300_CHANGED_HYPERZ_FLAG);
259                 }
260             }
261
262             /* Setup Hyper-Z clears. */
263             if (r300->hyperz_enabled) {
264                 DBG(r300, DBG_HYPERZ, "r300: Clear memory: %s%s\n",
265                     zmask_clear ? "ZMASK " : "", hiz_clear ? "HIZ" : "");
266
267                 if (zmask_clear) {
268                     hyperz_dcv = hyperz->zb_depthclearvalue =
269                         r300_depth_clear_value(fb->zsbuf->format, depth, stencil);
270
271                     r300_mark_atom_dirty(r300, &r300->zmask_clear);
272                     buffers &= ~PIPE_CLEAR_DEPTHSTENCIL;
273                 }
274
275                 if (hiz_clear) {
276                     r300->hiz_clear_value = r300_hiz_clear_value(depth);
277                     r300_mark_atom_dirty(r300, &r300->hiz_clear);
278                 }
279             }
280         }
281     }
282
283     /* Enable CBZB clear. */
284     if (r300_cbzb_clear_allowed(r300, buffers)) {
285         struct r300_surface *surf = r300_surface(fb->cbufs[0]);
286
287         hyperz->zb_depthclearvalue =
288                 r300_depth_clear_cb_value(surf->base.format, color->f);
289
290         width = surf->cbzb_width;
291         height = surf->cbzb_height;
292
293         r300->cbzb_clear = TRUE;
294         r300_mark_fb_state_dirty(r300, R300_CHANGED_HYPERZ_FLAG);
295     }
296
297     /* Clear. */
298     if (buffers) {
299         enum pipe_format cformat = fb->nr_cbufs ? fb->cbufs[0]->format : PIPE_FORMAT_NONE;
300         /* Clear using the blitter. */
301         r300_blitter_begin(r300, R300_CLEAR);
302         util_blitter_clear(r300->blitter,
303                            width,
304                            height,
305                            fb->nr_cbufs,
306                            buffers, cformat, color, depth, stencil);
307         r300_blitter_end(r300);
308     } else if (r300->zmask_clear.dirty || r300->hiz_clear.dirty) {
309         /* Just clear zmask and hiz now, this does not use the standard draw
310          * procedure. */
311         /* Calculate zmask_clear and hiz_clear atom sizes. */
312         unsigned dwords =
313             (r300->zmask_clear.dirty ? r300->zmask_clear.size : 0) +
314             (r300->hiz_clear.dirty ? r300->hiz_clear.size : 0) +
315             r300_get_num_cs_end_dwords(r300);
316
317         /* Reserve CS space. */
318         if (dwords > (RADEON_MAX_CMDBUF_DWORDS - r300->cs->cdw)) {
319             r300_flush(&r300->context, RADEON_FLUSH_ASYNC, NULL);
320         }
321
322         /* Emit clear packets. */
323         if (r300->zmask_clear.dirty) {
324             r300_emit_zmask_clear(r300, r300->zmask_clear.size,
325                                   r300->zmask_clear.state);
326             r300->zmask_clear.dirty = FALSE;
327         }
328         if (r300->hiz_clear.dirty) {
329             r300_emit_hiz_clear(r300, r300->hiz_clear.size,
330                                 r300->hiz_clear.state);
331             r300->hiz_clear.dirty = FALSE;
332         }
333     } else {
334         assert(0);
335     }
336
337     /* Disable CBZB clear. */
338     if (r300->cbzb_clear) {
339         r300->cbzb_clear = FALSE;
340         hyperz->zb_depthclearvalue = hyperz_dcv;
341         r300_mark_fb_state_dirty(r300, R300_CHANGED_HYPERZ_FLAG);
342     }
343
344     /* Enable fastfill and/or hiz.
345      *
346      * If we cleared zmask/hiz, it's in use now. The Hyper-Z state update
347      * looks if zmask/hiz is in use and programs hardware accordingly. */
348     if (r300->zmask_in_use || r300->hiz_in_use) {
349         r300_mark_atom_dirty(r300, &r300->hyperz_state);
350     }
351 }
352
353 /* Clear a region of a color surface to a constant value. */
354 static void r300_clear_render_target(struct pipe_context *pipe,
355                                      struct pipe_surface *dst,
356                                      const union pipe_color_union *color,
357                                      unsigned dstx, unsigned dsty,
358                                      unsigned width, unsigned height)
359 {
360     struct r300_context *r300 = r300_context(pipe);
361
362     r300_blitter_begin(r300, R300_CLEAR_SURFACE);
363     util_blitter_clear_render_target(r300->blitter, dst, color,
364                                      dstx, dsty, width, height);
365     r300_blitter_end(r300);
366 }
367
368 /* Clear a region of a depth stencil surface. */
369 static void r300_clear_depth_stencil(struct pipe_context *pipe,
370                                      struct pipe_surface *dst,
371                                      unsigned clear_flags,
372                                      double depth,
373                                      unsigned stencil,
374                                      unsigned dstx, unsigned dsty,
375                                      unsigned width, unsigned height)
376 {
377     struct r300_context *r300 = r300_context(pipe);
378     struct pipe_framebuffer_state *fb =
379         (struct pipe_framebuffer_state*)r300->fb_state.state;
380
381     if (r300->zmask_in_use && !r300->locked_zbuffer) {
382         if (fb->zsbuf->texture == dst->texture) {
383             r300_decompress_zmask(r300);
384         }
385     }
386
387     /* XXX Do not decompress ZMask of the currently-set zbuffer. */
388     r300_blitter_begin(r300, R300_CLEAR_SURFACE);
389     util_blitter_clear_depth_stencil(r300->blitter, dst, clear_flags, depth, stencil,
390                                      dstx, dsty, width, height);
391     r300_blitter_end(r300);
392 }
393
394 void r300_decompress_zmask(struct r300_context *r300)
395 {
396     struct pipe_framebuffer_state *fb =
397         (struct pipe_framebuffer_state*)r300->fb_state.state;
398
399     if (!r300->zmask_in_use || r300->locked_zbuffer)
400         return;
401
402     r300->zmask_decompress = TRUE;
403     r300_mark_atom_dirty(r300, &r300->hyperz_state);
404
405     r300_blitter_begin(r300, R300_DECOMPRESS);
406     util_blitter_clear_depth_custom(r300->blitter, fb->width, fb->height, 0,
407                                     r300->dsa_decompress_zmask);
408     r300_blitter_end(r300);
409
410     r300->zmask_decompress = FALSE;
411     r300->zmask_in_use = FALSE;
412     r300_mark_atom_dirty(r300, &r300->hyperz_state);
413 }
414
415 void r300_decompress_zmask_locked_unsafe(struct r300_context *r300)
416 {
417     struct pipe_framebuffer_state fb;
418
419     memset(&fb, 0, sizeof(fb));
420     fb.width = r300->locked_zbuffer->width;
421     fb.height = r300->locked_zbuffer->height;
422     fb.zsbuf = r300->locked_zbuffer;
423
424     r300->context.set_framebuffer_state(&r300->context, &fb);
425     r300_decompress_zmask(r300);
426 }
427
428 void r300_decompress_zmask_locked(struct r300_context *r300)
429 {
430     struct pipe_framebuffer_state saved_fb;
431
432     memset(&saved_fb, 0, sizeof(saved_fb));
433     util_copy_framebuffer_state(&saved_fb, r300->fb_state.state);
434     r300_decompress_zmask_locked_unsafe(r300);
435     r300->context.set_framebuffer_state(&r300->context, &saved_fb);
436     util_unreference_framebuffer_state(&saved_fb);
437
438     pipe_surface_reference(&r300->locked_zbuffer, NULL);
439 }
440
441 bool r300_is_blit_supported(enum pipe_format format)
442 {
443     const struct util_format_description *desc =
444         util_format_description(format);
445
446     return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ||
447            desc->layout == UTIL_FORMAT_LAYOUT_S3TC ||
448            desc->layout == UTIL_FORMAT_LAYOUT_RGTC;
449 }
450
451 /* Copy a block of pixels from one surface to another. */
452 static void r300_resource_copy_region(struct pipe_context *pipe,
453                                       struct pipe_resource *dst,
454                                       unsigned dst_level,
455                                       unsigned dstx, unsigned dsty, unsigned dstz,
456                                       struct pipe_resource *src,
457                                       unsigned src_level,
458                                       const struct pipe_box *src_box)
459 {
460     struct pipe_screen *screen = pipe->screen;
461     struct r300_context *r300 = r300_context(pipe);
462     struct pipe_framebuffer_state *fb =
463         (struct pipe_framebuffer_state*)r300->fb_state.state;
464     unsigned src_width0 = r300_resource(src)->tex.width0;
465     unsigned src_height0 = r300_resource(src)->tex.height0;
466     unsigned dst_width0 = r300_resource(dst)->tex.width0;
467     unsigned dst_height0 = r300_resource(dst)->tex.height0;
468     unsigned layout;
469     struct pipe_box box;
470     struct pipe_sampler_view src_templ, *src_view;
471     struct pipe_surface dst_templ, *dst_view;
472
473     /* Fallback for buffers. */
474     if ((dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) ||
475         !r300_is_blit_supported(dst->format)) {
476         util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
477                                   src, src_level, src_box);
478         return;
479     }
480
481     /* The code below changes the texture format so that the copy can be done
482      * on hardware. E.g. depth-stencil surfaces are copied as RGBA
483      * colorbuffers. */
484
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);
487
488     layout = util_format_description(dst_templ.format)->layout;
489
490     /* Handle non-renderable plain formats. */
491     if (layout == UTIL_FORMAT_LAYOUT_PLAIN &&
492         (!screen->is_format_supported(screen, src_templ.format, src->target,
493                                       src->nr_samples,
494                                       PIPE_BIND_SAMPLER_VIEW) ||
495          !screen->is_format_supported(screen, dst_templ.format, dst->target,
496                                       dst->nr_samples,
497                                       PIPE_BIND_RENDER_TARGET))) {
498         switch (util_format_get_blocksize(dst_templ.format)) {
499             case 1:
500                 dst_templ.format = PIPE_FORMAT_I8_UNORM;
501                 break;
502             case 2:
503                 dst_templ.format = PIPE_FORMAT_B4G4R4A4_UNORM;
504                 break;
505             case 4:
506                 dst_templ.format = PIPE_FORMAT_B8G8R8A8_UNORM;
507                 break;
508             case 8:
509                 dst_templ.format = PIPE_FORMAT_R16G16B16A16_UNORM;
510                 break;
511             default:
512                 debug_printf("r300: copy_region: Unhandled format: %s. Falling back to software.\n"
513                              "r300: copy_region: Software fallback doesn't work for tiled textures.\n",
514                              util_format_short_name(dst_templ.format));
515         }
516         src_templ.format = dst_templ.format;
517     }
518
519     /* Handle compressed formats. */
520     if (layout == UTIL_FORMAT_LAYOUT_S3TC ||
521         layout == UTIL_FORMAT_LAYOUT_RGTC) {
522         assert(src_templ.format == dst_templ.format);
523
524         box = *src_box;
525         src_box = &box;
526
527         dst_width0 = align(dst_width0, 4);
528         dst_height0 = align(dst_height0, 4);
529         src_width0 = align(src_width0, 4);
530         src_height0 = align(src_height0, 4);
531         box.width = align(box.width, 4);
532         box.height = align(box.height, 4);
533
534         switch (util_format_get_blocksize(dst_templ.format)) {
535         case 8:
536             /* one 4x4 pixel block has 8 bytes.
537              * we set 1 pixel = 4 bytes ===> 1 block corrensponds to 2 pixels. */
538             dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM;
539             dst_width0 = dst_width0 / 2;
540             src_width0 = src_width0 / 2;
541             dstx /= 2;
542             box.x /= 2;
543             box.width /= 2;
544             break;
545         case 16:
546             /* one 4x4 pixel block has 16 bytes.
547              * we set 1 pixel = 4 bytes ===> 1 block corresponds to 4 pixels. */
548             dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM;
549             break;
550         }
551         src_templ.format = dst_templ.format;
552
553         dst_height0 = dst_height0 / 4;
554         src_height0 = src_height0 / 4;
555         dsty /= 4;
556         box.y /= 4;
557         box.height /= 4;
558     }
559
560     /* Fallback for textures. */
561     if (!screen->is_format_supported(screen, dst_templ.format,
562                                      dst->target, dst->nr_samples,
563                                      PIPE_BIND_RENDER_TARGET) ||
564         !screen->is_format_supported(screen, src_templ.format,
565                                      src->target, src->nr_samples,
566                                      PIPE_BIND_SAMPLER_VIEW)) {
567         assert(0 && "this shouldn't happen, update r300_is_blit_supported");
568         util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
569                                   src, src_level, src_box);
570         return;
571     }
572
573     /* Decompress ZMASK. */
574     if (r300->zmask_in_use && !r300->locked_zbuffer) {
575         if (fb->zsbuf->texture == src ||
576             fb->zsbuf->texture == dst) {
577             r300_decompress_zmask(r300);
578         }
579     }
580
581     dst_view = r300_create_surface_custom(pipe, dst, &dst_templ, dst_width0, dst_height0);
582     src_view = r300_create_sampler_view_custom(pipe, src, &src_templ, src_width0, src_height0);
583
584     r300_blitter_begin(r300, R300_COPY);
585     util_blitter_copy_texture_view(r300->blitter, dst_view, dstx, dsty,
586                                    src_view, src_box,
587                                    src_width0, src_height0);
588     r300_blitter_end(r300);
589
590     pipe_surface_reference(&dst_view, NULL);
591     pipe_sampler_view_reference(&src_view, NULL);
592 }
593
594 void r300_init_blit_functions(struct r300_context *r300)
595 {
596     r300->context.clear = r300_clear;
597     r300->context.clear_render_target = r300_clear_render_target;
598     r300->context.clear_depth_stencil = r300_clear_depth_stencil;
599     r300->context.resource_copy_region = r300_resource_copy_region;
600 }