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