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