r300g,util: remove pipe_surface from the util_blitter_copy interface and clean up
[mesa.git] / src / gallium / auxiliary / util / u_blitter.h
1 /**************************************************************************
2 *
3 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 **************************************************************************/
26
27 #ifndef U_BLITTER_H
28 #define U_BLITTER_H
29
30 #include "util/u_memory.h"
31
32 #include "pipe/p_state.h"
33
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 struct pipe_context;
40
41 struct blitter_context
42 {
43 /* Private members, really. */
44 void *saved_blend_state; /**< blend state */
45 void *saved_dsa_state; /**< depth stencil alpha state */
46 void *saved_velem_state; /**< vertex elements state */
47 void *saved_rs_state; /**< rasterizer state */
48 void *saved_fs, *saved_vs; /**< fragment shader, vertex shader */
49
50 struct pipe_framebuffer_state saved_fb_state; /**< framebuffer state */
51 struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */
52 struct pipe_viewport_state saved_viewport;
53 struct pipe_clip_state saved_clip;
54
55 int saved_num_sampler_states;
56 void *saved_sampler_states[PIPE_MAX_SAMPLERS];
57
58 int saved_num_sampler_views;
59 struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS];
60
61 int saved_num_vertex_buffers;
62 struct pipe_vertex_buffer saved_vertex_buffers[PIPE_MAX_ATTRIBS];
63 };
64
65 /**
66 * Create a blitter context.
67 */
68 struct blitter_context *util_blitter_create(struct pipe_context *pipe);
69
70 /**
71 * Destroy a blitter context.
72 */
73 void util_blitter_destroy(struct blitter_context *blitter);
74
75 /*
76 * These CSOs must be saved before any of the following functions is called:
77 * - blend state
78 * - depth stencil alpha state
79 * - rasterizer state
80 * - vertex shader
81 * - fragment shader
82 */
83
84 /**
85 * Clear a specified set of currently bound buffers to specified values.
86 */
87 void util_blitter_clear(struct blitter_context *blitter,
88 unsigned width, unsigned height,
89 unsigned num_cbufs,
90 unsigned clear_buffers,
91 const float *rgba,
92 double depth, unsigned stencil);
93
94 /**
95 * Copy a block of pixels from one surface to another.
96 *
97 * You can copy from any color format to any other color format provided
98 * the former can be sampled and the latter can be rendered to. Otherwise,
99 * a software fallback path is taken and both surfaces must be of the same
100 * format.
101 *
102 * The same holds for depth-stencil formats with the exception that stencil
103 * cannot be copied unless you set ignore_stencil to FALSE. In that case,
104 * a software fallback path is taken and both surfaces must be of the same
105 * format.
106 *
107 * Use pipe_screen->is_format_supported to know your options.
108 *
109 * These states must be saved in the blitter in addition to the state objects
110 * already required to be saved:
111 * - framebuffer state
112 * - fragment sampler states
113 * - fragment sampler textures
114 */
115 void util_blitter_copy_region(struct blitter_context *blitter,
116 struct pipe_resource *dst,
117 struct pipe_subresource subdst,
118 unsigned dstx, unsigned dsty, unsigned dstz,
119 struct pipe_resource *src,
120 struct pipe_subresource subsrc,
121 unsigned srcx, unsigned srcy, unsigned srcz,
122 unsigned width, unsigned height,
123 boolean ignore_stencil);
124
125 /**
126 * Fill a region of a surface with a constant value.
127 *
128 * If the surface cannot be rendered to or it's a depth-stencil format,
129 * a software fallback path is taken.
130 *
131 * These states must be saved in the blitter in addition to the state objects
132 * already required to be saved:
133 * - framebuffer state
134 */
135 void util_blitter_fill_region(struct blitter_context *blitter,
136 struct pipe_resource *dst,
137 struct pipe_subresource subdst,
138 unsigned dstx, unsigned dsty, unsigned dstz,
139 unsigned width, unsigned height,
140 unsigned value);
141
142
143 /* The functions below should be used to save currently bound constant state
144 * objects inside a driver. The objects are automatically restored at the end
145 * of the util_blitter_{clear, fill, copy} functions and then
146 * forgotten.
147 *
148 * CSOs not listed here are not affected by util_blitter. */
149
150 static INLINE
151 void util_blitter_save_blend(struct blitter_context *blitter,
152 void *state)
153 {
154 blitter->saved_blend_state = state;
155 }
156
157 static INLINE
158 void util_blitter_save_depth_stencil_alpha(struct blitter_context *blitter,
159 void *state)
160 {
161 blitter->saved_dsa_state = state;
162 }
163
164 static INLINE
165 void util_blitter_save_vertex_elements(struct blitter_context *blitter,
166 void *state)
167 {
168 blitter->saved_velem_state = state;
169 }
170
171 static INLINE
172 void util_blitter_save_stencil_ref(struct blitter_context *blitter,
173 const struct pipe_stencil_ref *state)
174 {
175 blitter->saved_stencil_ref = *state;
176 }
177
178 static INLINE
179 void util_blitter_save_rasterizer(struct blitter_context *blitter,
180 void *state)
181 {
182 blitter->saved_rs_state = state;
183 }
184
185 static INLINE
186 void util_blitter_save_fragment_shader(struct blitter_context *blitter,
187 void *fs)
188 {
189 blitter->saved_fs = fs;
190 }
191
192 static INLINE
193 void util_blitter_save_vertex_shader(struct blitter_context *blitter,
194 void *vs)
195 {
196 blitter->saved_vs = vs;
197 }
198
199 static INLINE
200 void util_blitter_save_framebuffer(struct blitter_context *blitter,
201 struct pipe_framebuffer_state *state)
202 {
203 blitter->saved_fb_state = *state;
204 }
205
206 static INLINE
207 void util_blitter_save_viewport(struct blitter_context *blitter,
208 struct pipe_viewport_state *state)
209 {
210 blitter->saved_viewport = *state;
211 }
212
213 static INLINE
214 void util_blitter_save_clip(struct blitter_context *blitter,
215 struct pipe_clip_state *state)
216 {
217 blitter->saved_clip = *state;
218 }
219
220 static INLINE
221 void util_blitter_save_fragment_sampler_states(
222 struct blitter_context *blitter,
223 int num_sampler_states,
224 void **sampler_states)
225 {
226 assert(num_sampler_states <= Elements(blitter->saved_sampler_states));
227
228 blitter->saved_num_sampler_states = num_sampler_states;
229 memcpy(blitter->saved_sampler_states, sampler_states,
230 num_sampler_states * sizeof(void *));
231 }
232
233 static INLINE void
234 util_blitter_save_fragment_sampler_views(struct blitter_context *blitter,
235 int num_views,
236 struct pipe_sampler_view **views)
237 {
238 assert(num_views <= Elements(blitter->saved_sampler_views));
239
240 blitter->saved_num_sampler_views = num_views;
241 memcpy(blitter->saved_sampler_views,
242 views,
243 num_views * sizeof(struct pipe_sampler_view *));
244 }
245
246 static INLINE void
247 util_blitter_save_vertex_buffers(struct blitter_context *blitter,
248 int num_vertex_buffers,
249 struct pipe_vertex_buffer *vertex_buffers)
250 {
251 assert(num_vertex_buffers <= Elements(blitter->saved_vertex_buffers));
252
253 blitter->saved_num_vertex_buffers = num_vertex_buffers;
254 memcpy(blitter->saved_vertex_buffers,
255 vertex_buffers,
256 num_vertex_buffers * sizeof(struct pipe_vertex_buffer));
257 }
258
259 #ifdef __cplusplus
260 }
261 #endif
262
263 #endif