2 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
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:
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
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. */
23 #include "r300_blit.h"
24 #include "r300_context.h"
26 static void r300_blitter_save_states(struct r300_context
* r300
)
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
);
36 /* Clear currently bound buffers. */
37 void r300_clear(struct pipe_context
* pipe
,
43 /* XXX Implement fastfill.
45 * If fastfill is enabled, a few facts should be considered:
47 * 1) Zbuffer must be micro-tiled and whole microtiles must be
50 * 2) ZB_DEPTHCLEARVALUE is used to clear a zbuffer and Z Mask must be
53 * 3) RB3D_COLOR_CLEAR_VALUE is used to clear a colorbuffer and
54 * RB3D_COLOR_CHANNEL_MASK must be equal to 0.
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
64 * 5) For 16-bit integer buffering, compression causes a hung with one or
65 * two samples and should not be used.
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
76 struct r300_context
* r300
= r300_context(pipe
);
77 struct pipe_framebuffer_state
* fb
=
78 (struct pipe_framebuffer_state
*)r300
->fb_state
.state
;
80 r300_blitter_save_states(r300
);
82 util_blitter_clear(r300
->blitter
,
86 buffers
, rgba
, depth
, stencil
);
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
)
97 struct r300_context
* r300
= r300_context(pipe
);
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
);
105 util_blitter_save_fragment_sampler_states(
106 r300
->blitter
, r300
->sampler_count
, (void**)r300
->sampler_states
);
108 util_blitter_save_fragment_sampler_textures(
109 r300
->blitter
, r300
->texture_count
,
110 (struct pipe_texture
**)r300
->textures
);
113 util_blitter_copy(r300
->blitter
,
114 dst
, dstx
, dsty
, src
, srcx
, srcy
, width
, height
, TRUE
);
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
,
124 struct r300_context
* r300
= r300_context(pipe
);
126 r300_blitter_save_states(r300
);
127 util_blitter_save_framebuffer(r300
->blitter
, r300
->fb_state
.state
);
129 util_blitter_fill(r300
->blitter
,
130 dst
, dstx
, dsty
, width
, height
, value
);