glthread: handle buffer unbinding via glDeleteBuffers
[mesa.git] / src / mesa / main / glthread_marshal.h
1 /*
2 * Copyright © 2012 Intel Corporation
3 *
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
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
13 * Software.
14 *
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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /** \file glthread_marshal.h
25 *
26 * Declarations of functions related to marshalling GL calls from a client
27 * thread to a server thread.
28 */
29
30 #ifndef MARSHAL_H
31 #define MARSHAL_H
32
33 #include "main/glthread.h"
34 #include "main/context.h"
35 #include "main/macros.h"
36 #include "marshal_generated.h"
37
38 struct marshal_cmd_base
39 {
40 /**
41 * Type of command. See enum marshal_dispatch_cmd_id.
42 */
43 uint16_t cmd_id;
44
45 /**
46 * Size of command, in multiples of 4 bytes, including cmd_base.
47 */
48 uint16_t cmd_size;
49 };
50
51 typedef void (*_mesa_unmarshal_func)(struct gl_context *ctx, const void *cmd);
52 extern const _mesa_unmarshal_func _mesa_unmarshal_dispatch[NUM_DISPATCH_CMD];
53
54 static inline void *
55 _mesa_glthread_allocate_command(struct gl_context *ctx,
56 uint16_t cmd_id,
57 int size)
58 {
59 struct glthread_state *glthread = &ctx->GLThread;
60 struct glthread_batch *next = &glthread->batches[glthread->next];
61 struct marshal_cmd_base *cmd_base;
62 const int aligned_size = ALIGN(size, 8);
63
64 if (unlikely(next->used + size > MARSHAL_MAX_CMD_SIZE)) {
65 _mesa_glthread_flush_batch(ctx);
66 next = &glthread->batches[glthread->next];
67 }
68
69 cmd_base = (struct marshal_cmd_base *)&next->buffer[next->used];
70 next->used += aligned_size;
71 cmd_base->cmd_id = cmd_id;
72 cmd_base->cmd_size = aligned_size;
73 return cmd_base;
74 }
75
76 /**
77 * Instead of conditionally handling marshaling immediate index data in draw
78 * calls (deprecated and removed in GL core), we just disable threading.
79 */
80 static inline bool
81 _mesa_glthread_is_non_vbo_draw_elements(const struct gl_context *ctx)
82 {
83 const struct glthread_state *glthread = &ctx->GLThread;
84 struct glthread_vao *vao = glthread->CurrentVAO;
85
86 return ctx->API != API_OPENGL_CORE &&
87 (vao->CurrentElementBufferName == 0 || vao->HasUserPointer);
88 }
89
90 static inline bool
91 _mesa_glthread_is_non_vbo_draw_arrays(const struct gl_context *ctx)
92 {
93 const struct glthread_state *glthread = &ctx->GLThread;
94
95 return ctx->API != API_OPENGL_CORE && glthread->CurrentVAO->HasUserPointer;
96 }
97
98 static inline bool
99 _mesa_glthread_is_non_vbo_draw_arrays_indirect(const struct gl_context *ctx)
100 {
101 const struct glthread_state *glthread = &ctx->GLThread;
102
103 return ctx->API != API_OPENGL_CORE &&
104 (glthread->CurrentDrawIndirectBufferName == 0 ||
105 glthread->CurrentVAO->HasUserPointer);
106 }
107
108 static inline bool
109 _mesa_glthread_is_non_vbo_draw_elements_indirect(const struct gl_context *ctx)
110 {
111 const struct glthread_state *glthread = &ctx->GLThread;
112 struct glthread_vao *vao = glthread->CurrentVAO;
113
114 return ctx->API != API_OPENGL_CORE &&
115 (glthread->CurrentDrawIndirectBufferName == 0 ||
116 vao->CurrentElementBufferName == 0 || vao->HasUserPointer);
117 }
118
119
120 struct _glapi_table *
121 _mesa_create_marshal_table(const struct gl_context *ctx);
122
123 static inline unsigned
124 _mesa_buffer_enum_to_count(GLenum buffer)
125 {
126 switch (buffer) {
127 case GL_COLOR:
128 return 4;
129 case GL_DEPTH_STENCIL:
130 return 2;
131 case GL_STENCIL:
132 case GL_DEPTH:
133 return 1;
134 default:
135 return 0;
136 }
137 }
138
139 static inline unsigned
140 _mesa_tex_param_enum_to_count(GLenum pname)
141 {
142 switch (pname) {
143 case GL_TEXTURE_MIN_FILTER:
144 case GL_TEXTURE_MAG_FILTER:
145 case GL_TEXTURE_WRAP_S:
146 case GL_TEXTURE_WRAP_T:
147 case GL_TEXTURE_WRAP_R:
148 case GL_TEXTURE_BASE_LEVEL:
149 case GL_TEXTURE_MAX_LEVEL:
150 case GL_GENERATE_MIPMAP_SGIS:
151 case GL_TEXTURE_COMPARE_MODE_ARB:
152 case GL_TEXTURE_COMPARE_FUNC_ARB:
153 case GL_DEPTH_TEXTURE_MODE_ARB:
154 case GL_DEPTH_STENCIL_TEXTURE_MODE:
155 case GL_TEXTURE_SRGB_DECODE_EXT:
156 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
157 case GL_TEXTURE_SWIZZLE_R:
158 case GL_TEXTURE_SWIZZLE_G:
159 case GL_TEXTURE_SWIZZLE_B:
160 case GL_TEXTURE_SWIZZLE_A:
161 case GL_TEXTURE_MIN_LOD:
162 case GL_TEXTURE_MAX_LOD:
163 case GL_TEXTURE_PRIORITY:
164 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
165 case GL_TEXTURE_LOD_BIAS:
166 case GL_TEXTURE_TILING_EXT:
167 return 1;
168 case GL_TEXTURE_CROP_RECT_OES:
169 case GL_TEXTURE_SWIZZLE_RGBA:
170 case GL_TEXTURE_BORDER_COLOR:
171 return 4;
172 default:
173 return 0;
174 }
175 }
176
177 static inline unsigned
178 _mesa_fog_enum_to_count(GLenum pname)
179 {
180 switch (pname) {
181 case GL_FOG_MODE:
182 case GL_FOG_DENSITY:
183 case GL_FOG_START:
184 case GL_FOG_END:
185 case GL_FOG_INDEX:
186 case GL_FOG_COORDINATE_SOURCE_EXT:
187 case GL_FOG_DISTANCE_MODE_NV:
188 return 1;
189 case GL_FOG_COLOR:
190 return 4;
191 default:
192 return 0;
193 }
194 }
195
196 static inline unsigned
197 _mesa_light_enum_to_count(GLenum pname)
198 {
199 switch (pname) {
200 case GL_AMBIENT:
201 case GL_DIFFUSE:
202 case GL_SPECULAR:
203 case GL_POSITION:
204 return 4;
205 case GL_SPOT_DIRECTION:
206 return 3;
207 case GL_SPOT_EXPONENT:
208 case GL_SPOT_CUTOFF:
209 case GL_CONSTANT_ATTENUATION:
210 case GL_LINEAR_ATTENUATION:
211 case GL_QUADRATIC_ATTENUATION:
212 return 1;
213 default:
214 return 0;
215 }
216 }
217
218 static inline unsigned
219 _mesa_light_model_enum_to_count(GLenum pname)
220 {
221 switch (pname) {
222 case GL_LIGHT_MODEL_AMBIENT:
223 return 4;
224 case GL_LIGHT_MODEL_LOCAL_VIEWER:
225 case GL_LIGHT_MODEL_TWO_SIDE:
226 case GL_LIGHT_MODEL_COLOR_CONTROL:
227 return 1;
228 default:
229 return 0;
230 }
231 }
232
233 static inline unsigned
234 _mesa_texenv_enum_to_count(GLenum pname)
235 {
236 switch (pname) {
237 case GL_TEXTURE_ENV_MODE:
238 case GL_COMBINE_RGB:
239 case GL_COMBINE_ALPHA:
240 case GL_SOURCE0_RGB:
241 case GL_SOURCE1_RGB:
242 case GL_SOURCE2_RGB:
243 case GL_SOURCE3_RGB_NV:
244 case GL_SOURCE0_ALPHA:
245 case GL_SOURCE1_ALPHA:
246 case GL_SOURCE2_ALPHA:
247 case GL_SOURCE3_ALPHA_NV:
248 case GL_OPERAND0_RGB:
249 case GL_OPERAND1_RGB:
250 case GL_OPERAND2_RGB:
251 case GL_OPERAND3_RGB_NV:
252 case GL_OPERAND0_ALPHA:
253 case GL_OPERAND1_ALPHA:
254 case GL_OPERAND2_ALPHA:
255 case GL_OPERAND3_ALPHA_NV:
256 case GL_RGB_SCALE:
257 case GL_ALPHA_SCALE:
258 case GL_TEXTURE_LOD_BIAS_EXT:
259 case GL_COORD_REPLACE_NV:
260 return 1;
261 case GL_TEXTURE_ENV_COLOR:
262 return 4;
263 default:
264 return 0;
265 }
266 }
267
268 static inline unsigned
269 _mesa_texgen_enum_to_count(GLenum pname)
270 {
271 switch (pname) {
272 case GL_TEXTURE_GEN_MODE:
273 return 1;
274 case GL_OBJECT_PLANE:
275 case GL_EYE_PLANE:
276 return 4;
277 default:
278 return 0;
279 }
280 }
281
282 static inline unsigned
283 _mesa_material_enum_to_count(GLenum pname)
284 {
285 switch (pname) {
286 case GL_EMISSION:
287 case GL_AMBIENT:
288 case GL_DIFFUSE:
289 case GL_SPECULAR:
290 case GL_AMBIENT_AND_DIFFUSE:
291 return 4;
292 case GL_COLOR_INDEXES:
293 return 3;
294 case GL_SHININESS:
295 return 1;
296 default:
297 return 0;
298 }
299 }
300
301 static inline unsigned
302 _mesa_point_param_enum_to_count(GLenum pname)
303 {
304 switch (pname) {
305 case GL_DISTANCE_ATTENUATION_EXT:
306 return 3;
307 case GL_POINT_SIZE_MIN_EXT:
308 case GL_POINT_SIZE_MAX_EXT:
309 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
310 case GL_POINT_SPRITE_R_MODE_NV:
311 case GL_POINT_SPRITE_COORD_ORIGIN:
312 return 1;
313 default:
314 return 0;
315 }
316 }
317
318 static inline unsigned
319 _mesa_calllists_enum_to_count(GLenum type)
320 {
321 switch (type) {
322 case GL_BYTE:
323 case GL_UNSIGNED_BYTE:
324 return 1;
325 case GL_SHORT:
326 case GL_UNSIGNED_SHORT:
327 case GL_2_BYTES:
328 return 2;
329 case GL_3_BYTES:
330 return 3;
331 case GL_INT:
332 case GL_UNSIGNED_INT:
333 case GL_FLOAT:
334 case GL_4_BYTES:
335 return 4;
336 default:
337 return 0;
338 }
339 }
340
341 static inline unsigned
342 _mesa_patch_param_enum_to_count(GLenum pname)
343 {
344 switch (pname) {
345 case GL_PATCH_DEFAULT_OUTER_LEVEL:
346 return 4;
347 case GL_PATCH_DEFAULT_INNER_LEVEL:
348 return 2;
349 default:
350 return 0;
351 }
352 }
353
354 static inline unsigned
355 _mesa_memobj_enum_to_count(GLenum pname)
356 {
357 switch (pname) {
358 case GL_DEDICATED_MEMORY_OBJECT_EXT:
359 return 1;
360 default:
361 return 0;
362 }
363 }
364
365 static inline unsigned
366 _mesa_semaphore_enum_to_count(GLenum pname)
367 {
368 switch (pname) {
369 /* EXT_semaphore and EXT_semaphore_fd define no parameters */
370 default:
371 return 0;
372 }
373 }
374
375 #endif /* MARSHAL_H */