Checkpoint: replacement of TGSI_ATTRIB_x tokens with input/output semantics.
[mesa.git] / src / mesa / pipe / p_context.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef PIPE_CONTEXT_H
29 #define PIPE_CONTEXT_H
30
31 #include "p_state.h"
32 #include "p_compiler.h"
33
34 struct pipe_state_cache;
35 /**
36 * Software pipeline rendering context. Basically a collection of
37 * state setting functions, plus VBO drawing entrypoint.
38 */
39 struct pipe_context {
40 struct pipe_winsys *winsys;
41
42 void (*destroy)( struct pipe_context * );
43
44 /*
45 * Queries
46 */
47 const unsigned *(*supported_formats)(struct pipe_context *pipe,
48 unsigned *numFormats);
49
50 void (*max_texture_size)(struct pipe_context *pipe,
51 unsigned textureType, /* PIPE_TEXTURE_x */
52 unsigned *maxWidth,
53 unsigned *maxHeight,
54 unsigned *maxDepth);
55
56 const char *(*get_name)( struct pipe_context *pipe );
57
58 const char *(*get_vendor)( struct pipe_context *pipe );
59
60 int (*get_param)( struct pipe_context *pipe, int param );
61
62
63 /*
64 * Drawing.
65 * Return false on fallbacks (temporary??)
66 */
67 boolean (*draw_arrays)( struct pipe_context *pipe,
68 unsigned mode, unsigned start, unsigned count);
69
70 boolean (*draw_elements)( struct pipe_context *pipe,
71 struct pipe_buffer_handle *indexBuffer,
72 unsigned indexSize,
73 unsigned mode, unsigned start, unsigned count);
74
75 /** Clear a surface to given value (no scissor; clear whole surface) */
76 void (*clear)(struct pipe_context *pipe, struct pipe_surface *ps,
77 unsigned clearValue);
78
79 /**
80 * Query objects
81 */
82 void (*begin_query)(struct pipe_context *pipe, struct pipe_query_object *q);
83 void (*end_query)(struct pipe_context *pipe, struct pipe_query_object *q);
84 void (*wait_query)(struct pipe_context *pipe, struct pipe_query_object *q);
85
86 /*
87 * State functions
88 */
89 void * (*create_blend_state)(struct pipe_context *,
90 const struct pipe_blend_state *);
91 void (*bind_blend_state)(struct pipe_context *, void *);
92 void (*delete_blend_state)(struct pipe_context *, void *);
93
94 const struct pipe_sampler_state * (*create_sampler_state)(
95 struct pipe_context *,
96 const struct pipe_sampler_state *);
97 void (*bind_sampler_state)(struct pipe_context *,
98 unsigned unit,
99 const struct pipe_sampler_state *);
100 void (*delete_sampler_state)(struct pipe_context *,
101 const struct pipe_sampler_state *);
102
103 void *(*create_rasterizer_state)(struct pipe_context *,
104 const struct pipe_rasterizer_state *);
105 void (*bind_rasterizer_state)(struct pipe_context *, void *);
106 void (*delete_rasterizer_state)(struct pipe_context *, void *);
107
108 const struct pipe_depth_stencil_state * (*create_depth_stencil_state)(
109 struct pipe_context *,
110 const struct pipe_depth_stencil_state *);
111 void (*bind_depth_stencil_state)(struct pipe_context *,
112 const struct pipe_depth_stencil_state *);
113 void (*delete_depth_stencil_state)(struct pipe_context *,
114 const struct pipe_depth_stencil_state *);
115
116 const struct pipe_shader_state * (*create_fs_state)(
117 struct pipe_context *,
118 const struct pipe_shader_state *);
119 void (*bind_fs_state)(struct pipe_context *,
120 const struct pipe_shader_state *);
121 void (*delete_fs_state)(struct pipe_context *,
122 const struct pipe_shader_state *);
123 const struct pipe_shader_state * (*create_vs_state)(
124 struct pipe_context *,
125 const struct pipe_shader_state *);
126 void (*bind_vs_state)(struct pipe_context *,
127 const struct pipe_shader_state *);
128 void (*delete_vs_state)(struct pipe_context *,
129 const struct pipe_shader_state *);
130
131 void (*set_alpha_test_state)( struct pipe_context *,
132 const struct pipe_alpha_test_state * );
133
134 void (*set_blend_color)( struct pipe_context *,
135 const struct pipe_blend_color * );
136
137 void (*set_clip_state)( struct pipe_context *,
138 const struct pipe_clip_state * );
139
140 void (*set_clear_color_state)( struct pipe_context *,
141 const struct pipe_clear_color_state * );
142
143 void (*set_constant_buffer)( struct pipe_context *,
144 uint shader, uint index,
145 const struct pipe_constant_buffer *buf );
146
147 void (*set_feedback_state)( struct pipe_context *,
148 const struct pipe_feedback_state *);
149
150 void (*set_framebuffer_state)( struct pipe_context *,
151 const struct pipe_framebuffer_state * );
152
153 void (*set_polygon_stipple)( struct pipe_context *,
154 const struct pipe_poly_stipple * );
155
156 void (*set_scissor_state)( struct pipe_context *,
157 const struct pipe_scissor_state * );
158
159 void (*set_texture_state)( struct pipe_context *,
160 unsigned unit,
161 struct pipe_mipmap_tree * );
162
163 void (*set_viewport_state)( struct pipe_context *,
164 const struct pipe_viewport_state * );
165
166 /*
167 * Vertex arrays
168 */
169 void (*set_vertex_buffer)( struct pipe_context *,
170 unsigned index,
171 const struct pipe_vertex_buffer * );
172
173 void (*set_vertex_element)( struct pipe_context *,
174 unsigned index,
175 const struct pipe_vertex_element * );
176
177 /*
178 * Vertex feedback
179 */
180 void (*set_feedback_buffer)(struct pipe_context *,
181 unsigned index,
182 const struct pipe_feedback_buffer *);
183
184 /*
185 * Surface functions
186 * This might go away...
187 */
188 struct pipe_surface *(*surface_alloc)(struct pipe_context *pipe,
189 unsigned format);
190
191 struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe,
192 struct pipe_mipmap_tree *texture,
193 unsigned face, unsigned level,
194 unsigned zslice);
195
196 /*
197 * Memory region functions
198 * Some of these may go away...
199 */
200 struct pipe_region *(*region_alloc)(struct pipe_context *pipe,
201 unsigned cpp, unsigned width, unsigned height,
202 unsigned flags);
203
204 void (*region_release)(struct pipe_context *pipe, struct pipe_region **r);
205
206 ubyte *(*region_map)(struct pipe_context *pipe, struct pipe_region *r);
207
208 void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r);
209
210 void (*region_data)(struct pipe_context *pipe,
211 struct pipe_region *dest,
212 unsigned dest_offset,
213 unsigned destx, unsigned desty,
214 const void *src, unsigned src_stride,
215 unsigned srcx, unsigned srcy, unsigned width, unsigned height);
216
217 void (*region_copy)(struct pipe_context *pipe,
218 struct pipe_region *dest,
219 unsigned dest_offset,
220 unsigned destx, unsigned desty,
221 struct pipe_region *src, /* don't make this const -
222 need to map/unmap */
223 unsigned src_offset,
224 unsigned srcx, unsigned srcy, unsigned width, unsigned height);
225
226 void (*region_fill)(struct pipe_context *pipe,
227 struct pipe_region *dst,
228 unsigned dst_offset,
229 unsigned dstx, unsigned dsty,
230 unsigned width, unsigned height,
231 unsigned value);
232
233
234 /*
235 * Texture functions
236 */
237 boolean (*mipmap_tree_layout)( struct pipe_context *pipe,
238 struct pipe_mipmap_tree *mt );
239
240
241 /* Flush rendering:
242 */
243 void (*flush)( struct pipe_context *pipe,
244 unsigned flags );
245 };
246
247
248 /**
249 * Set 'ptr' to point to 'region' and update reference counting.
250 * The old thing pointed to, if any, will be unreferenced first.
251 * 'region' may be NULL.
252 */
253 static INLINE void
254 pipe_region_reference(struct pipe_region **ptr, struct pipe_region *region)
255 {
256 assert(ptr);
257 if (*ptr) {
258 /* unreference the old thing */
259 struct pipe_region *oldReg = *ptr;
260 oldReg->refcount--;
261 assert(oldReg->refcount >= 0);
262 if (oldReg->refcount == 0) {
263 /* free the old region */
264 assert(oldReg->map_refcount == 0);
265 /* XXX dereference the region->buffer */
266 free(oldReg);
267 }
268 *ptr = NULL;
269 }
270 if (region) {
271 /* reference the new thing */
272 region->refcount++;
273 *ptr = region;
274 }
275 }
276
277
278 /**
279 * \sa pipe_region_reference
280 */
281 static INLINE void
282 pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
283 {
284 assert(ptr);
285 if (*ptr) {
286 /* unreference the old thing */
287 struct pipe_surface *oldSurf = *ptr;
288 oldSurf->refcount--;
289 assert(oldSurf->refcount >= 0);
290 if (oldSurf->refcount == 0) {
291 /* free the old region */
292 pipe_region_reference(&oldSurf->region, NULL);
293 free(oldSurf);
294 }
295 *ptr = NULL;
296 }
297 if (surf) {
298 /* reference the new thing */
299 surf->refcount++;
300 *ptr = surf;
301 }
302 }
303
304
305 #endif /* PIPE_CONTEXT_H */