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
);
40 /* XXX this crashes the driver
41 util_blitter_save_vertex_buffers(r300->blitter, r300->vertex_buffer_count,
42 r300->vertex_buffer); */
45 /* Clear currently bound buffers. */
46 void r300_clear(struct pipe_context
* pipe
,
52 /* XXX Implement fastfill.
54 * If fastfill is enabled, a few facts should be considered:
56 * 1) Zbuffer must be micro-tiled and whole microtiles must be
59 * 2) ZB_DEPTHCLEARVALUE is used to clear a zbuffer and Z Mask must be
62 * 3) For 16-bit integer buffering, compression causes a hung with one or
63 * two samples and should not be used.
65 * 4) Fastfill must not be used if reading of compressed Z data is disabled
66 * and writing of compressed Z data is enabled (RD/WR_COMP_ENABLE),
67 * i.e. it cannot be used to compress the zbuffer.
68 * (what the hell does that mean and how does it fit in clearing
74 struct r300_context
* r300
= r300_context(pipe
);
75 struct pipe_framebuffer_state
* fb
=
76 (struct pipe_framebuffer_state
*)r300
->fb_state
.state
;
78 r300_blitter_save_states(r300
);
80 util_blitter_clear(r300
->blitter
,
84 buffers
, rgba
, depth
, stencil
);
87 /* Copy a block of pixels from one surface to another using HW. */
88 static void r300_hw_copy(struct pipe_context
* pipe
,
89 struct pipe_surface
* dst
,
90 unsigned dstx
, unsigned dsty
,
91 struct pipe_surface
* src
,
92 unsigned srcx
, unsigned srcy
,
93 unsigned width
, unsigned height
)
95 struct r300_context
* r300
= r300_context(pipe
);
96 struct r300_textures_state
* state
=
97 (struct r300_textures_state
*)r300
->textures_state
.state
;
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
, state
->sampler_state_count
,
107 (void**)state
->sampler_states
);
109 util_blitter_save_fragment_sampler_views(
110 r300
->blitter
, state
->sampler_view_count
,
111 (struct pipe_sampler_view
**)state
->sampler_views
);
114 util_blitter_copy(r300
->blitter
,
115 dst
, dstx
, dsty
, src
, srcx
, srcy
, width
, height
, TRUE
);
118 /* Copy a block of pixels from one surface to another. */
119 void r300_surface_copy(struct pipe_context
* pipe
,
120 struct pipe_surface
* dst
,
121 unsigned dstx
, unsigned dsty
,
122 struct pipe_surface
* src
,
123 unsigned srcx
, unsigned srcy
,
124 unsigned width
, unsigned height
)
126 enum pipe_format old_format
= dst
->texture
->format
;
127 enum pipe_format new_format
= old_format
;
129 if (dst
->texture
->format
!= src
->texture
->format
) {
130 debug_printf("r300: Implementation error: Format mismatch in %s\n"
131 " : src: %s dst: %s\n", __FUNCTION__
,
132 util_format_name(src
->texture
->format
),
133 util_format_name(dst
->texture
->format
));
137 if (!pipe
->screen
->is_format_supported(pipe
->screen
,
138 old_format
, src
->texture
->target
,
139 PIPE_BIND_RENDER_TARGET
|
140 PIPE_BIND_SAMPLER_VIEW
, 0)) {
141 switch (util_format_get_blocksize(old_format
)) {
143 new_format
= PIPE_FORMAT_I8_UNORM
;
146 new_format
= PIPE_FORMAT_B4G4R4A4_UNORM
;
149 new_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
152 new_format
= PIPE_FORMAT_R16G16B16A16_UNORM
;
155 debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n"
156 "r300: surface_copy: Software fallback doesn't work for tiled textures.\n",
157 util_format_name(old_format
));
161 if (old_format
!= new_format
) {
162 dst
->format
= new_format
;
163 src
->format
= new_format
;
165 r300_texture_reinterpret_format(pipe
->screen
,
166 dst
->texture
, new_format
);
167 r300_texture_reinterpret_format(pipe
->screen
,
168 src
->texture
, new_format
);
171 r300_hw_copy(pipe
, dst
, dstx
, dsty
, src
, srcx
, srcy
, width
, height
);
173 if (old_format
!= new_format
) {
174 dst
->format
= old_format
;
175 src
->format
= old_format
;
177 r300_texture_reinterpret_format(pipe
->screen
,
178 dst
->texture
, old_format
);
179 r300_texture_reinterpret_format(pipe
->screen
,
180 src
->texture
, old_format
);
184 /* Fill a region of a surface with a constant value. */
185 void r300_surface_fill(struct pipe_context
* pipe
,
186 struct pipe_surface
* dst
,
187 unsigned dstx
, unsigned dsty
,
188 unsigned width
, unsigned height
,
191 struct r300_context
* r300
= r300_context(pipe
);
193 r300_blitter_save_states(r300
);
194 util_blitter_save_framebuffer(r300
->blitter
, r300
->fb_state
.state
);
196 util_blitter_fill(r300
->blitter
,
197 dst
, dstx
, dsty
, width
, height
, value
);