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"
25 #include "r300_texture.h"
27 #include "util/u_format.h"
29 static void r300_blitter_save_states(struct r300_context
* r300
)
31 util_blitter_save_blend(r300
->blitter
, r300
->blend_state
.state
);
32 util_blitter_save_depth_stencil_alpha(r300
->blitter
, r300
->dsa_state
.state
);
33 util_blitter_save_stencil_ref(r300
->blitter
, &(r300
->stencil_ref
));
34 util_blitter_save_rasterizer(r300
->blitter
, r300
->rs_state
.state
);
35 util_blitter_save_fragment_shader(r300
->blitter
, r300
->fs
);
36 util_blitter_save_vertex_shader(r300
->blitter
, r300
->vs_state
.state
);
37 util_blitter_save_viewport(r300
->blitter
, &r300
->viewport
);
38 util_blitter_save_clip(r300
->blitter
, &r300
->clip
);
39 util_blitter_save_vertex_elements(r300
->blitter
, r300
->velems
);
42 /* Clear currently bound buffers. */
43 void r300_clear(struct pipe_context
* pipe
,
49 /* XXX Implement fastfill.
51 * If fastfill is enabled, a few facts should be considered:
53 * 1) Zbuffer must be micro-tiled and whole microtiles must be
56 * 2) ZB_DEPTHCLEARVALUE is used to clear a zbuffer and Z Mask must be
59 * 3) RB3D_COLOR_CLEAR_VALUE is used to clear a colorbuffer and
60 * RB3D_COLOR_CHANNEL_MASK must be equal to 0.
62 * 4) ZB_CB_CLEAR can be used to make the ZB units help in clearing
63 * the colorbuffer. The color clear value is supplied through both
64 * RB3D_COLOR_CLEAR_VALUE and ZB_DEPTHCLEARVALUE, and the colorbuffer
65 * must be set in ZB_DEPTHOFFSET and ZB_DEPTHPITCH in addition to
66 * RB3D_COLOROFFSET and RB3D_COLORPITCH. It's obvious that the zbuffer
67 * will not be cleared and multiple render targets cannot be cleared
70 * 5) For 16-bit integer buffering, compression causes a hung with one or
71 * two samples and should not be used.
73 * 6) Fastfill must not be used if reading of compressed Z data is disabled
74 * and writing of compressed Z data is enabled (RD/WR_COMP_ENABLE),
75 * i.e. it cannot be used to compress the zbuffer.
76 * (what the hell does that mean and how does it fit in clearing
82 struct r300_context
* r300
= r300_context(pipe
);
83 struct pipe_framebuffer_state
* fb
=
84 (struct pipe_framebuffer_state
*)r300
->fb_state
.state
;
86 r300_blitter_save_states(r300
);
88 util_blitter_clear(r300
->blitter
,
92 buffers
, rgba
, depth
, stencil
);
95 /* Copy a block of pixels from one surface to another using HW. */
96 static void r300_hw_copy(struct pipe_context
* pipe
,
97 struct pipe_surface
* dst
,
98 unsigned dstx
, unsigned dsty
,
99 struct pipe_surface
* src
,
100 unsigned srcx
, unsigned srcy
,
101 unsigned width
, unsigned height
)
103 struct r300_context
* r300
= r300_context(pipe
);
104 struct r300_textures_state
* state
=
105 (struct r300_textures_state
*)r300
->textures_state
.state
;
107 /* Yeah we have to save all those states to ensure this blitter operation
108 * is really transparent. The states will be restored by the blitter once
109 * copying is done. */
110 r300_blitter_save_states(r300
);
111 util_blitter_save_framebuffer(r300
->blitter
, r300
->fb_state
.state
);
113 util_blitter_save_fragment_sampler_states(
114 r300
->blitter
, state
->sampler_count
, (void**)state
->sampler_states
);
116 util_blitter_save_fragment_sampler_views(
117 r300
->blitter
, state
->texture_count
,
118 state
->fragment_sampler_views
);
121 util_blitter_copy(r300
->blitter
,
122 dst
, dstx
, dsty
, src
, srcx
, srcy
, width
, height
, TRUE
);
125 /* Copy a block of pixels from one surface to another. */
126 void r300_surface_copy(struct pipe_context
* pipe
,
127 struct pipe_surface
* dst
,
128 unsigned dstx
, unsigned dsty
,
129 struct pipe_surface
* src
,
130 unsigned srcx
, unsigned srcy
,
131 unsigned width
, unsigned height
)
133 enum pipe_format old_format
= dst
->texture
->format
;
134 enum pipe_format new_format
= old_format
;
136 assert(dst
->texture
->format
== src
->texture
->format
);
138 if (!pipe
->screen
->is_format_supported(pipe
->screen
,
139 old_format
, src
->texture
->target
,
140 PIPE_TEXTURE_USAGE_RENDER_TARGET
|
141 PIPE_TEXTURE_USAGE_SAMPLER
, 0)) {
142 switch (util_format_get_blocksize(old_format
)) {
144 new_format
= PIPE_FORMAT_I8_UNORM
;
147 new_format
= PIPE_FORMAT_B4G4R4A4_UNORM
;
150 new_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
153 debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n"
154 "r300: surface_copy: Software fallback doesn't work for tiled textures.\n",
155 util_format_name(old_format
));
159 if (old_format
!= new_format
) {
160 dst
->format
= new_format
;
161 src
->format
= new_format
;
163 r300_texture_reinterpret_format(pipe
->screen
,
164 dst
->texture
, new_format
);
165 r300_texture_reinterpret_format(pipe
->screen
,
166 src
->texture
, new_format
);
169 r300_hw_copy(pipe
, dst
, dstx
, dsty
, src
, srcx
, srcy
, width
, height
);
171 if (old_format
!= new_format
) {
172 dst
->format
= old_format
;
173 src
->format
= old_format
;
175 r300_texture_reinterpret_format(pipe
->screen
,
176 dst
->texture
, old_format
);
177 r300_texture_reinterpret_format(pipe
->screen
,
178 src
->texture
, old_format
);
182 /* Fill a region of a surface with a constant value. */
183 void r300_surface_fill(struct pipe_context
* pipe
,
184 struct pipe_surface
* dst
,
185 unsigned dstx
, unsigned dsty
,
186 unsigned width
, unsigned height
,
189 struct r300_context
* r300
= r300_context(pipe
);
191 r300_blitter_save_states(r300
);
192 util_blitter_save_framebuffer(r300
->blitter
, r300
->fb_state
.state
);
194 util_blitter_fill(r300
->blitter
,
195 dst
, dstx
, dsty
, width
, height
, value
);