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
.state
);
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) For 16-bit integer buffering, compression causes a hung with one or
60 * two samples and should not be used.
62 * 4) Fastfill must not be used if reading of compressed Z data is disabled
63 * and writing of compressed Z data is enabled (RD/WR_COMP_ENABLE),
64 * i.e. it cannot be used to compress the zbuffer.
65 * (what the hell does that mean and how does it fit in clearing
71 struct r300_context
* r300
= r300_context(pipe
);
72 struct pipe_framebuffer_state
* fb
=
73 (struct pipe_framebuffer_state
*)r300
->fb_state
.state
;
75 r300_blitter_save_states(r300
);
77 util_blitter_clear(r300
->blitter
,
81 buffers
, rgba
, depth
, stencil
);
84 /* Copy a block of pixels from one surface to another using HW. */
85 static void r300_hw_copy(struct pipe_context
* pipe
,
86 struct pipe_surface
* dst
,
87 unsigned dstx
, unsigned dsty
,
88 struct pipe_surface
* src
,
89 unsigned srcx
, unsigned srcy
,
90 unsigned width
, unsigned height
)
92 struct r300_context
* r300
= r300_context(pipe
);
93 struct r300_textures_state
* state
=
94 (struct r300_textures_state
*)r300
->textures_state
.state
;
96 /* Yeah we have to save all those states to ensure this blitter operation
97 * is really transparent. The states will be restored by the blitter once
99 r300_blitter_save_states(r300
);
100 util_blitter_save_framebuffer(r300
->blitter
, r300
->fb_state
.state
);
102 util_blitter_save_fragment_sampler_states(
103 r300
->blitter
, state
->sampler_state_count
,
104 (void**)state
->sampler_states
);
106 util_blitter_save_fragment_sampler_views(
107 r300
->blitter
, state
->sampler_view_count
,
108 (struct pipe_sampler_view
**)state
->sampler_views
);
111 util_blitter_copy(r300
->blitter
,
112 dst
, dstx
, dsty
, src
, srcx
, srcy
, width
, height
, TRUE
);
115 /* Copy a block of pixels from one surface to another. */
116 void r300_surface_copy(struct pipe_context
* pipe
,
117 struct pipe_surface
* dst
,
118 unsigned dstx
, unsigned dsty
,
119 struct pipe_surface
* src
,
120 unsigned srcx
, unsigned srcy
,
121 unsigned width
, unsigned height
)
123 enum pipe_format old_format
= dst
->texture
->format
;
124 enum pipe_format new_format
= old_format
;
126 assert(dst
->texture
->format
== src
->texture
->format
);
128 if (!pipe
->screen
->is_format_supported(pipe
->screen
,
129 old_format
, src
->texture
->target
,
130 PIPE_BIND_RENDER_TARGET
|
131 PIPE_BIND_SAMPLER_VIEW
, 0)) {
132 switch (util_format_get_blocksize(old_format
)) {
134 new_format
= PIPE_FORMAT_I8_UNORM
;
137 new_format
= PIPE_FORMAT_B4G4R4A4_UNORM
;
140 new_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
143 new_format
= PIPE_FORMAT_R16G16B16A16_UNORM
;
146 debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n"
147 "r300: surface_copy: Software fallback doesn't work for tiled textures.\n",
148 util_format_name(old_format
));
152 if (old_format
!= new_format
) {
153 dst
->format
= new_format
;
154 src
->format
= new_format
;
156 r300_texture_reinterpret_format(pipe
->screen
,
157 dst
->texture
, new_format
);
158 r300_texture_reinterpret_format(pipe
->screen
,
159 src
->texture
, new_format
);
162 r300_hw_copy(pipe
, dst
, dstx
, dsty
, src
, srcx
, srcy
, width
, height
);
164 if (old_format
!= new_format
) {
165 dst
->format
= old_format
;
166 src
->format
= old_format
;
168 r300_texture_reinterpret_format(pipe
->screen
,
169 dst
->texture
, old_format
);
170 r300_texture_reinterpret_format(pipe
->screen
,
171 src
->texture
, old_format
);
175 /* Fill a region of a surface with a constant value. */
176 void r300_surface_fill(struct pipe_context
* pipe
,
177 struct pipe_surface
* dst
,
178 unsigned dstx
, unsigned dsty
,
179 unsigned width
, unsigned height
,
182 struct r300_context
* r300
= r300_context(pipe
);
184 r300_blitter_save_states(r300
);
185 util_blitter_save_framebuffer(r300
->blitter
, r300
->fb_state
.state
);
187 util_blitter_fill(r300
->blitter
,
188 dst
, dstx
, dsty
, width
, height
, value
);