Rework of shader constant buffers.
[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
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
61
62 /*
63 * Drawing.
64 * Return false on fallbacks (temporary??)
65 */
66 boolean (*draw_arrays)( struct pipe_context *pipe,
67 unsigned mode, unsigned start, unsigned count);
68
69 boolean (*draw_elements)( struct pipe_context *pipe,
70 struct pipe_buffer_handle *indexBuffer,
71 unsigned indexSize,
72 unsigned mode, unsigned start, unsigned count);
73
74 /** Clear a surface to given value (no scissor; clear whole surface) */
75 void (*clear)(struct pipe_context *pipe, struct pipe_surface *ps,
76 unsigned clearValue);
77
78 /** occlusion counting (XXX this may be temporary - we should probably
79 * have generic query objects with begin/end methods)
80 */
81 void (*reset_occlusion_counter)(struct pipe_context *pipe);
82 unsigned (*get_occlusion_counter)(struct pipe_context *pipe);
83
84 /*
85 * State functions
86 */
87 void (*set_alpha_test_state)( struct pipe_context *,
88 const struct pipe_alpha_test_state * );
89
90 void (*set_blend_state)( struct pipe_context *,
91 const struct pipe_blend_state * );
92
93 void (*set_blend_color)( struct pipe_context *,
94 const struct pipe_blend_color * );
95
96 void (*set_clip_state)( struct pipe_context *,
97 const struct pipe_clip_state * );
98
99 void (*set_clear_color_state)( struct pipe_context *,
100 const struct pipe_clear_color_state * );
101
102 void (*set_constant_buffer)( struct pipe_context *,
103 uint shader, uint index,
104 const struct pipe_constant_buffer *buf );
105
106 void (*set_depth_state)( struct pipe_context *,
107 const struct pipe_depth_state * );
108
109 void (*set_framebuffer_state)( struct pipe_context *,
110 const struct pipe_framebuffer_state * );
111
112 void (*set_fs_state)( struct pipe_context *,
113 const struct pipe_shader_state * );
114
115 void (*set_vs_state)( struct pipe_context *,
116 const struct pipe_shader_state * );
117
118 void (*set_polygon_stipple)( struct pipe_context *,
119 const struct pipe_poly_stipple * );
120
121 void (*set_setup_state)( struct pipe_context *,
122 const struct pipe_setup_state * );
123
124 void (*set_scissor_state)( struct pipe_context *,
125 const struct pipe_scissor_state * );
126
127 void (*set_stencil_state)( struct pipe_context *,
128 const struct pipe_stencil_state * );
129
130 void (*set_sampler_state)( struct pipe_context *,
131 unsigned unit,
132 const struct pipe_sampler_state * );
133
134 void (*set_texture_state)( struct pipe_context *,
135 unsigned unit,
136 struct pipe_mipmap_tree * );
137
138 void (*set_viewport_state)( struct pipe_context *,
139 const struct pipe_viewport_state * );
140
141 void (*set_vertex_buffer)( struct pipe_context *,
142 unsigned index,
143 const struct pipe_vertex_buffer * );
144
145 void (*set_vertex_element)( struct pipe_context *,
146 unsigned index,
147 const struct pipe_vertex_element * );
148
149
150 /*
151 * Surface functions
152 * This might go away...
153 */
154 struct pipe_surface *(*surface_alloc)(struct pipe_context *pipe,
155 unsigned format);
156
157 struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe,
158 struct pipe_mipmap_tree *texture,
159 unsigned face, unsigned level,
160 unsigned zslice);
161
162 /*
163 * Memory region functions
164 * Some of these may go away...
165 */
166 struct pipe_region *(*region_alloc)(struct pipe_context *pipe,
167 unsigned cpp, unsigned width, unsigned height,
168 unsigned flags);
169
170 void (*region_release)(struct pipe_context *pipe, struct pipe_region **r);
171
172 void (*region_idle)(struct pipe_context *pipe, struct pipe_region *region);
173
174 ubyte *(*region_map)(struct pipe_context *pipe, struct pipe_region *r);
175
176 void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r);
177
178 void (*region_data)(struct pipe_context *pipe,
179 struct pipe_region *dest,
180 unsigned dest_offset,
181 unsigned destx, unsigned desty,
182 const void *src, unsigned src_stride,
183 unsigned srcx, unsigned srcy, unsigned width, unsigned height);
184
185 void (*region_copy)(struct pipe_context *pipe,
186 struct pipe_region *dest,
187 unsigned dest_offset,
188 unsigned destx, unsigned desty,
189 struct pipe_region *src, /* don't make this const -
190 need to map/unmap */
191 unsigned src_offset,
192 unsigned srcx, unsigned srcy, unsigned width, unsigned height);
193
194 void (*region_fill)(struct pipe_context *pipe,
195 struct pipe_region *dst,
196 unsigned dst_offset,
197 unsigned dstx, unsigned dsty,
198 unsigned width, unsigned height,
199 unsigned value);
200
201
202 /*
203 * Texture functions
204 */
205 boolean (*mipmap_tree_layout)( struct pipe_context *pipe,
206 struct pipe_mipmap_tree *mt );
207
208
209 /* Flush rendering:
210 */
211 void (*flush)( struct pipe_context *pipe,
212 unsigned flags );
213 };
214
215
216
217 static INLINE void
218 pipe_region_reference(struct pipe_region **dst, struct pipe_region *src)
219 {
220 assert(*dst == NULL);
221 if (src) {
222 src->refcount++;
223 *dst = src;
224 }
225 }
226
227
228 static INLINE void
229 pipe_surface_reference(struct pipe_surface **dst, struct pipe_surface *src)
230 {
231 assert(*dst == NULL);
232 if (src) {
233 src->refcount++;
234 *dst = src;
235 }
236 }
237
238 static INLINE void
239 pipe_surface_unreference(struct pipe_surface **ps)
240 {
241 assert(*ps);
242 (*ps)->refcount--;
243 if ((*ps)->refcount <= 0) {
244 /* XXX need a proper surface->free method */
245 free(*ps);
246 }
247 *ps = NULL;
248 }
249
250
251 #endif /* PIPE_CONTEXT_H */