glthread: clean up debug_print_sync code
[mesa.git] / src / mesa / main / 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 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 struct glthread_state *glthread = ctx->GLThread;
84
85 return ctx->API != API_OPENGL_CORE &&
86 (glthread->CurrentVAO->IndexBufferIsUserPointer ||
87 glthread->CurrentVAO->HasUserPointer);
88 }
89
90 static inline bool
91 _mesa_glthread_is_non_vbo_draw_arrays(const struct gl_context *ctx)
92 {
93 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 struct glthread_state *glthread = ctx->GLThread;
102
103 return ctx->API != API_OPENGL_CORE &&
104 (!glthread->draw_indirect_buffer_is_vbo ||
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 struct glthread_state *glthread = ctx->GLThread;
112
113 return ctx->API != API_OPENGL_CORE &&
114 (!glthread->draw_indirect_buffer_is_vbo ||
115 glthread->CurrentVAO->IndexBufferIsUserPointer ||
116 glthread->CurrentVAO->HasUserPointer);
117 }
118
119
120 struct _glapi_table *
121 _mesa_create_marshal_table(const struct gl_context *ctx);
122
123 struct marshal_cmd_ShaderSource;
124 struct marshal_cmd_BufferData;
125 struct marshal_cmd_BufferSubData;
126
127 void GLAPIENTRY
128 _mesa_marshal_ShaderSource(GLuint shader, GLsizei count,
129 const GLchar * const *string, const GLint *length);
130
131 void
132 _mesa_unmarshal_ShaderSource(struct gl_context *ctx,
133 const struct marshal_cmd_ShaderSource *cmd);
134
135 void
136 _mesa_glthread_BindBuffer(struct gl_context *ctx, GLenum target, GLuint buffer);
137
138 void
139 _mesa_unmarshal_BufferData(struct gl_context *ctx,
140 const struct marshal_cmd_BufferData *cmd);
141
142 void
143 _mesa_unmarshal_NamedBufferData(struct gl_context *ctx,
144 const struct marshal_cmd_BufferData *cmd);
145
146 void
147 _mesa_unmarshal_NamedBufferDataEXT(struct gl_context *ctx,
148 const struct marshal_cmd_BufferData *cmd);
149
150 void GLAPIENTRY
151 _mesa_marshal_BufferData(GLenum target, GLsizeiptr size, const GLvoid * data,
152 GLenum usage);
153
154 void GLAPIENTRY
155 _mesa_marshal_NamedBufferData(GLuint buffer, GLsizeiptr size,
156 const GLvoid * data, GLenum usage);
157
158 void GLAPIENTRY
159 _mesa_marshal_NamedBufferDataEXT(GLuint buffer, GLsizeiptr size,
160 const GLvoid *data, GLenum usage);
161
162 void
163 _mesa_unmarshal_BufferSubData(struct gl_context *ctx,
164 const struct marshal_cmd_BufferSubData *cmd);
165
166 void
167 _mesa_unmarshal_NamedBufferSubData(struct gl_context *ctx,
168 const struct marshal_cmd_BufferSubData *cmd);
169
170 void
171 _mesa_unmarshal_NamedBufferSubDataEXT(struct gl_context *ctx,
172 const struct marshal_cmd_BufferSubData *cmd);
173
174 void GLAPIENTRY
175 _mesa_marshal_BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size,
176 const GLvoid * data);
177
178 void GLAPIENTRY
179 _mesa_marshal_NamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size,
180 const GLvoid * data);
181
182 void GLAPIENTRY
183 _mesa_marshal_NamedBufferSubDataEXT(GLuint buffer, GLintptr offset,
184 GLsizeiptr size, const GLvoid * data);
185
186 static inline unsigned
187 _mesa_buffer_enum_to_count(GLenum buffer)
188 {
189 switch (buffer) {
190 case GL_COLOR:
191 return 4;
192 case GL_DEPTH_STENCIL:
193 return 2;
194 case GL_STENCIL:
195 case GL_DEPTH:
196 return 1;
197 default:
198 return 0;
199 }
200 }
201
202 static inline unsigned
203 _mesa_tex_param_enum_to_count(GLenum pname)
204 {
205 switch (pname) {
206 case GL_TEXTURE_MIN_FILTER:
207 case GL_TEXTURE_MAG_FILTER:
208 case GL_TEXTURE_WRAP_S:
209 case GL_TEXTURE_WRAP_T:
210 case GL_TEXTURE_WRAP_R:
211 case GL_TEXTURE_BASE_LEVEL:
212 case GL_TEXTURE_MAX_LEVEL:
213 case GL_GENERATE_MIPMAP_SGIS:
214 case GL_TEXTURE_COMPARE_MODE_ARB:
215 case GL_TEXTURE_COMPARE_FUNC_ARB:
216 case GL_DEPTH_TEXTURE_MODE_ARB:
217 case GL_DEPTH_STENCIL_TEXTURE_MODE:
218 case GL_TEXTURE_SRGB_DECODE_EXT:
219 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
220 case GL_TEXTURE_SWIZZLE_R:
221 case GL_TEXTURE_SWIZZLE_G:
222 case GL_TEXTURE_SWIZZLE_B:
223 case GL_TEXTURE_SWIZZLE_A:
224 case GL_TEXTURE_MIN_LOD:
225 case GL_TEXTURE_MAX_LOD:
226 case GL_TEXTURE_PRIORITY:
227 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
228 case GL_TEXTURE_LOD_BIAS:
229 case GL_TEXTURE_TILING_EXT:
230 return 1;
231 case GL_TEXTURE_CROP_RECT_OES:
232 case GL_TEXTURE_SWIZZLE_RGBA:
233 case GL_TEXTURE_BORDER_COLOR:
234 return 4;
235 default:
236 return 0;
237 }
238 }
239
240 static inline unsigned
241 _mesa_fog_enum_to_count(GLenum pname)
242 {
243 switch (pname) {
244 case GL_FOG_MODE:
245 case GL_FOG_DENSITY:
246 case GL_FOG_START:
247 case GL_FOG_END:
248 case GL_FOG_INDEX:
249 case GL_FOG_COORDINATE_SOURCE_EXT:
250 case GL_FOG_DISTANCE_MODE_NV:
251 return 1;
252 case GL_FOG_COLOR:
253 return 4;
254 default:
255 return 0;
256 }
257 }
258
259 static inline unsigned
260 _mesa_light_enum_to_count(GLenum pname)
261 {
262 switch (pname) {
263 case GL_AMBIENT:
264 case GL_DIFFUSE:
265 case GL_SPECULAR:
266 case GL_POSITION:
267 return 4;
268 case GL_SPOT_DIRECTION:
269 return 3;
270 case GL_SPOT_EXPONENT:
271 case GL_SPOT_CUTOFF:
272 case GL_CONSTANT_ATTENUATION:
273 case GL_LINEAR_ATTENUATION:
274 case GL_QUADRATIC_ATTENUATION:
275 return 1;
276 default:
277 return 0;
278 }
279 }
280
281 static inline unsigned
282 _mesa_light_model_enum_to_count(GLenum pname)
283 {
284 switch (pname) {
285 case GL_LIGHT_MODEL_AMBIENT:
286 return 4;
287 case GL_LIGHT_MODEL_LOCAL_VIEWER:
288 case GL_LIGHT_MODEL_TWO_SIDE:
289 case GL_LIGHT_MODEL_COLOR_CONTROL:
290 return 1;
291 default:
292 return 0;
293 }
294 }
295
296 static inline unsigned
297 _mesa_texenv_enum_to_count(GLenum pname)
298 {
299 switch (pname) {
300 case GL_TEXTURE_ENV_MODE:
301 case GL_COMBINE_RGB:
302 case GL_COMBINE_ALPHA:
303 case GL_SOURCE0_RGB:
304 case GL_SOURCE1_RGB:
305 case GL_SOURCE2_RGB:
306 case GL_SOURCE3_RGB_NV:
307 case GL_SOURCE0_ALPHA:
308 case GL_SOURCE1_ALPHA:
309 case GL_SOURCE2_ALPHA:
310 case GL_SOURCE3_ALPHA_NV:
311 case GL_OPERAND0_RGB:
312 case GL_OPERAND1_RGB:
313 case GL_OPERAND2_RGB:
314 case GL_OPERAND3_RGB_NV:
315 case GL_OPERAND0_ALPHA:
316 case GL_OPERAND1_ALPHA:
317 case GL_OPERAND2_ALPHA:
318 case GL_OPERAND3_ALPHA_NV:
319 case GL_RGB_SCALE:
320 case GL_ALPHA_SCALE:
321 case GL_TEXTURE_LOD_BIAS_EXT:
322 case GL_COORD_REPLACE_NV:
323 return 1;
324 case GL_TEXTURE_ENV_COLOR:
325 return 4;
326 default:
327 return 0;
328 }
329 }
330
331 static inline unsigned
332 _mesa_texgen_enum_to_count(GLenum pname)
333 {
334 switch (pname) {
335 case GL_TEXTURE_GEN_MODE:
336 return 1;
337 case GL_OBJECT_PLANE:
338 case GL_EYE_PLANE:
339 return 4;
340 default:
341 return 0;
342 }
343 }
344
345 static inline unsigned
346 _mesa_material_enum_to_count(GLenum pname)
347 {
348 switch (pname) {
349 case GL_EMISSION:
350 case GL_AMBIENT:
351 case GL_DIFFUSE:
352 case GL_SPECULAR:
353 case GL_AMBIENT_AND_DIFFUSE:
354 return 4;
355 case GL_COLOR_INDEXES:
356 return 3;
357 case GL_SHININESS:
358 return 1;
359 default:
360 return 0;
361 }
362 }
363
364 static inline unsigned
365 _mesa_point_param_enum_to_count(GLenum pname)
366 {
367 switch (pname) {
368 case GL_DISTANCE_ATTENUATION_EXT:
369 return 3;
370 case GL_POINT_SIZE_MIN_EXT:
371 case GL_POINT_SIZE_MAX_EXT:
372 case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
373 case GL_POINT_SPRITE_R_MODE_NV:
374 case GL_POINT_SPRITE_COORD_ORIGIN:
375 return 1;
376 default:
377 return 0;
378 }
379 }
380
381 static inline unsigned
382 _mesa_calllists_enum_to_count(GLenum type)
383 {
384 switch (type) {
385 case GL_BYTE:
386 case GL_UNSIGNED_BYTE:
387 return 1;
388 case GL_SHORT:
389 case GL_UNSIGNED_SHORT:
390 case GL_2_BYTES:
391 return 2;
392 case GL_3_BYTES:
393 return 3;
394 case GL_INT:
395 case GL_UNSIGNED_INT:
396 case GL_FLOAT:
397 case GL_4_BYTES:
398 return 4;
399 default:
400 return 0;
401 }
402 }
403
404 static inline unsigned
405 _mesa_patch_param_enum_to_count(GLenum pname)
406 {
407 switch (pname) {
408 case GL_PATCH_DEFAULT_OUTER_LEVEL:
409 return 4;
410 case GL_PATCH_DEFAULT_INNER_LEVEL:
411 return 2;
412 default:
413 return 0;
414 }
415 }
416
417 static inline unsigned
418 _mesa_memobj_enum_to_count(GLenum pname)
419 {
420 switch (pname) {
421 case GL_DEDICATED_MEMORY_OBJECT_EXT:
422 return 1;
423 default:
424 return 0;
425 }
426 }
427
428 static inline unsigned
429 _mesa_semaphore_enum_to_count(GLenum pname)
430 {
431 switch (pname) {
432 /* EXT_semaphore and EXT_semaphore_fd define no parameters */
433 default:
434 return 0;
435 }
436 }
437
438 #endif /* MARSHAL_H */