Merge branch 'master' into opengl-es-v2
[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_blit.h"
24 #include "r300_context.h"
25
26 #include "util/u_rect.h"
27
28 static void r300_blitter_save_states(struct r300_context* r300)
29 {
30 util_blitter_save_blend(r300->blitter, r300->blend_state.state);
31 util_blitter_save_depth_stencil_alpha(r300->blitter, r300->dsa_state.state);
32 util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state);
33 util_blitter_save_fragment_shader(r300->blitter, r300->fs);
34 util_blitter_save_vertex_shader(r300->blitter, r300->vs);
35 }
36
37 /* Clear currently bound buffers. */
38 void r300_clear(struct pipe_context* pipe,
39 unsigned buffers,
40 const float* rgba,
41 double depth,
42 unsigned stencil)
43 {
44 /* XXX Implement fastfill.
45 *
46 * If fastfill is enabled, a few facts should be considered:
47 *
48 * 1) Zbuffer must be micro-tiled and whole microtiles must be
49 * written.
50 *
51 * 2) ZB_DEPTHCLEARVALUE is used to clear a zbuffer and Z Mask must be
52 * equal to 0.
53 *
54 * 3) RB3D_COLOR_CLEAR_VALUE is used to clear a colorbuffer and
55 * RB3D_COLOR_CHANNEL_MASK must be equal to 0.
56 *
57 * 4) ZB_CB_CLEAR can be used to make the ZB units help in clearing
58 * the colorbuffer. The color clear value is supplied through both
59 * RB3D_COLOR_CLEAR_VALUE and ZB_DEPTHCLEARVALUE, and the colorbuffer
60 * must be set in ZB_DEPTHOFFSET and ZB_DEPTHPITCH in addition to
61 * RB3D_COLOROFFSET and RB3D_COLORPITCH. It's obvious that the zbuffer
62 * will not be cleared and multiple render targets cannot be cleared
63 * this way either.
64 *
65 * 5) For 16-bit integer buffering, compression causes a hung with one or
66 * two samples and should not be used.
67 *
68 * 6) Fastfill must not be used if reading of compressed Z data is disabled
69 * and writing of compressed Z data is enabled (RD/WR_COMP_ENABLE),
70 * i.e. it cannot be used to compress the zbuffer.
71 * (what the hell does that mean and how does it fit in clearing
72 * the buffers?)
73 *
74 * - Marek
75 */
76
77 struct r300_context* r300 = r300_context(pipe);
78
79 r300_blitter_save_states(r300);
80
81 util_blitter_clear(r300->blitter,
82 r300->framebuffer_state.width,
83 r300->framebuffer_state.height,
84 r300->framebuffer_state.nr_cbufs,
85 buffers, rgba, depth, stencil);
86 }
87
88 /* Copy a block of pixels from one surface to another. */
89 void r300_surface_copy(struct pipe_context* pipe,
90 struct pipe_surface* dst,
91 unsigned dstx, unsigned dsty,
92 struct pipe_surface* src,
93 unsigned srcx, unsigned srcy,
94 unsigned width, unsigned height)
95 {
96 struct r300_context* r300 = r300_context(pipe);
97
98 /* Yeah we have to save all those states to ensure this blitter operation
99 * is really transparent. The states will be restored by the blitter once
100 * copying is done. */
101 r300_blitter_save_states(r300);
102 util_blitter_save_framebuffer(r300->blitter, &r300->framebuffer_state);
103
104 util_blitter_save_fragment_sampler_states(
105 r300->blitter, r300->sampler_count, (void**)r300->sampler_states);
106
107 util_blitter_save_fragment_sampler_textures(
108 r300->blitter, r300->texture_count,
109 (struct pipe_texture**)r300->textures);
110
111 /* Do a copy */
112 util_blitter_copy(r300->blitter,
113 dst, dstx, dsty, src, srcx, srcy, width, height, TRUE);
114 }
115
116 /* Fill a region of a surface with a constant value. */
117 void r300_surface_fill(struct pipe_context* pipe,
118 struct pipe_surface* dst,
119 unsigned dstx, unsigned dsty,
120 unsigned width, unsigned height,
121 unsigned value)
122 {
123 struct r300_context* r300 = r300_context(pipe);
124
125 r300_blitter_save_states(r300);
126 util_blitter_save_framebuffer(r300->blitter, &r300->framebuffer_state);
127
128 util_blitter_fill(r300->blitter,
129 dst, dstx, dsty, width, height, value);
130 }