2 * Copyright © 2012 Intel Corporation
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:
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
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
26 * Declarations of functions related to marshalling GL calls from a client
27 * thread to a server thread.
33 #include "main/glthread.h"
34 #include "main/context.h"
35 #include "main/macros.h"
36 #include "marshal_generated.h"
38 struct marshal_cmd_base
41 * Type of command. See enum marshal_dispatch_cmd_id.
46 * Size of command, in multiples of 4 bytes, including cmd_base.
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
];
55 _mesa_glthread_allocate_command(struct gl_context
*ctx
,
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);
64 if (unlikely(next
->used
+ size
> MARSHAL_MAX_CMD_SIZE
)) {
65 _mesa_glthread_flush_batch(ctx
);
66 next
= &glthread
->batches
[glthread
->next
];
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
;
77 * Instead of conditionally handling marshaling previously-bound user vertex
78 * array data in draw calls (deprecated and removed in GL core), we just
79 * disable threading at the point where the user sets a user vertex array.
82 _mesa_glthread_is_non_vbo_vertex_attrib_pointer(const struct gl_context
*ctx
)
84 struct glthread_state
*glthread
= ctx
->GLThread
;
86 return ctx
->API
!= API_OPENGL_CORE
&& !glthread
->vertex_array_is_vbo
;
90 * Instead of conditionally handling marshaling immediate index data in draw
91 * calls (deprecated and removed in GL core), we just disable threading.
94 _mesa_glthread_is_non_vbo_draw_elements(const struct gl_context
*ctx
)
96 struct glthread_state
*glthread
= ctx
->GLThread
;
98 return ctx
->API
!= API_OPENGL_CORE
&& !glthread
->element_array_is_vbo
;
102 _mesa_glthread_is_non_vbo_draw_arrays_indirect(const struct gl_context
*ctx
)
104 struct glthread_state
*glthread
= ctx
->GLThread
;
106 return ctx
->API
!= API_OPENGL_CORE
&&
107 !glthread
->draw_indirect_buffer_is_vbo
;
111 _mesa_glthread_is_non_vbo_draw_elements_indirect(const struct gl_context
*ctx
)
113 struct glthread_state
*glthread
= ctx
->GLThread
;
115 return ctx
->API
!= API_OPENGL_CORE
&&
116 (!glthread
->draw_indirect_buffer_is_vbo
||
117 !glthread
->element_array_is_vbo
);
120 #define DEBUG_MARSHAL_PRINT_CALLS 0
123 * This is printed when we have fallen back to a sync. This can happen when
124 * MARSHAL_MAX_CMD_SIZE is exceeded.
127 debug_print_sync_fallback(const char *func
)
129 #if DEBUG_MARSHAL_PRINT_CALLS
130 printf("fallback to sync: %s\n", func
);
136 debug_print_sync(const char *func
)
138 #if DEBUG_MARSHAL_PRINT_CALLS
139 printf("sync: %s\n", func
);
144 debug_print_marshal(const char *func
)
146 #if DEBUG_MARSHAL_PRINT_CALLS
147 printf("marshal: %s\n", func
);
151 struct _glapi_table
*
152 _mesa_create_marshal_table(const struct gl_context
*ctx
);
156 * Checks whether we're on a compat context for code-generated
157 * glBindVertexArray().
159 * In order to decide whether a draw call uses only VBOs for vertex and index
160 * buffers, we track the current vertex and index buffer bindings by
161 * glBindBuffer(). However, the index buffer binding is stored in the vertex
162 * array as opposed to the context. If we were to accurately track whether
163 * the index buffer was a user pointer ot not, we'd have to track it per
164 * vertex array, which would mean synchronizing with the client thread and
165 * looking into the hash table to find the actual vertex array object. That's
166 * more tracking than we'd like to do in the main thread, if possible.
168 * Instead, just punt for now and disable threading on apps using vertex
169 * arrays and compat contexts. Apps using vertex arrays can probably use a
173 _mesa_glthread_is_compat_bind_vertex_array(const struct gl_context
*ctx
)
175 return ctx
->API
!= API_OPENGL_CORE
;
178 struct marshal_cmd_ShaderSource
;
179 struct marshal_cmd_BindBuffer
;
180 struct marshal_cmd_BufferData
;
181 struct marshal_cmd_BufferSubData
;
182 struct marshal_cmd_NamedBufferData
;
183 struct marshal_cmd_NamedBufferSubData
;
186 _mesa_marshal_ShaderSource(GLuint shader
, GLsizei count
,
187 const GLchar
* const *string
, const GLint
*length
);
190 _mesa_unmarshal_ShaderSource(struct gl_context
*ctx
,
191 const struct marshal_cmd_ShaderSource
*cmd
);
194 _mesa_marshal_BindBuffer(GLenum target
, GLuint buffer
);
197 _mesa_unmarshal_BindBuffer(struct gl_context
*ctx
,
198 const struct marshal_cmd_BindBuffer
*cmd
);
201 _mesa_unmarshal_BufferData(struct gl_context
*ctx
,
202 const struct marshal_cmd_BufferData
*cmd
);
205 _mesa_marshal_BufferData(GLenum target
, GLsizeiptr size
, const GLvoid
* data
,
209 _mesa_unmarshal_BufferSubData(struct gl_context
*ctx
,
210 const struct marshal_cmd_BufferSubData
*cmd
);
213 _mesa_marshal_BufferSubData(GLenum target
, GLintptr offset
, GLsizeiptr size
,
214 const GLvoid
* data
);
217 _mesa_unmarshal_NamedBufferData(struct gl_context
*ctx
,
218 const struct marshal_cmd_NamedBufferData
*cmd
);
221 _mesa_marshal_NamedBufferData(GLuint buffer
, GLsizeiptr size
,
222 const GLvoid
* data
, GLenum usage
);
225 _mesa_unmarshal_NamedBufferSubData(struct gl_context
*ctx
,
226 const struct marshal_cmd_NamedBufferSubData
*cmd
);
229 _mesa_marshal_NamedBufferSubData(GLuint buffer
, GLintptr offset
, GLsizeiptr size
,
230 const GLvoid
* data
);
232 static inline unsigned
233 _mesa_buffer_enum_to_count(GLenum buffer
)
238 case GL_DEPTH_STENCIL
:
248 static inline unsigned
249 _mesa_tex_param_enum_to_count(GLenum pname
)
252 case GL_TEXTURE_MIN_FILTER
:
253 case GL_TEXTURE_MAG_FILTER
:
254 case GL_TEXTURE_WRAP_S
:
255 case GL_TEXTURE_WRAP_T
:
256 case GL_TEXTURE_WRAP_R
:
257 case GL_TEXTURE_BASE_LEVEL
:
258 case GL_TEXTURE_MAX_LEVEL
:
259 case GL_GENERATE_MIPMAP_SGIS
:
260 case GL_TEXTURE_COMPARE_MODE_ARB
:
261 case GL_TEXTURE_COMPARE_FUNC_ARB
:
262 case GL_DEPTH_TEXTURE_MODE_ARB
:
263 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
264 case GL_TEXTURE_SRGB_DECODE_EXT
:
265 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
266 case GL_TEXTURE_SWIZZLE_R
:
267 case GL_TEXTURE_SWIZZLE_G
:
268 case GL_TEXTURE_SWIZZLE_B
:
269 case GL_TEXTURE_SWIZZLE_A
:
270 case GL_TEXTURE_MIN_LOD
:
271 case GL_TEXTURE_MAX_LOD
:
272 case GL_TEXTURE_PRIORITY
:
273 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
274 case GL_TEXTURE_LOD_BIAS
:
275 case GL_TEXTURE_TILING_EXT
:
277 case GL_TEXTURE_CROP_RECT_OES
:
278 case GL_TEXTURE_SWIZZLE_RGBA
:
279 case GL_TEXTURE_BORDER_COLOR
:
286 static inline unsigned
287 _mesa_fog_enum_to_count(GLenum pname
)
295 case GL_FOG_COORDINATE_SOURCE_EXT
:
296 case GL_FOG_DISTANCE_MODE_NV
:
305 static inline unsigned
306 _mesa_light_enum_to_count(GLenum pname
)
314 case GL_SPOT_DIRECTION
:
316 case GL_SPOT_EXPONENT
:
318 case GL_CONSTANT_ATTENUATION
:
319 case GL_LINEAR_ATTENUATION
:
320 case GL_QUADRATIC_ATTENUATION
:
327 static inline unsigned
328 _mesa_light_model_enum_to_count(GLenum pname
)
331 case GL_LIGHT_MODEL_AMBIENT
:
333 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
334 case GL_LIGHT_MODEL_TWO_SIDE
:
335 case GL_LIGHT_MODEL_COLOR_CONTROL
:
342 static inline unsigned
343 _mesa_texenv_enum_to_count(GLenum pname
)
346 case GL_TEXTURE_ENV_MODE
:
348 case GL_COMBINE_ALPHA
:
352 case GL_SOURCE3_RGB_NV
:
353 case GL_SOURCE0_ALPHA
:
354 case GL_SOURCE1_ALPHA
:
355 case GL_SOURCE2_ALPHA
:
356 case GL_SOURCE3_ALPHA_NV
:
357 case GL_OPERAND0_RGB
:
358 case GL_OPERAND1_RGB
:
359 case GL_OPERAND2_RGB
:
360 case GL_OPERAND3_RGB_NV
:
361 case GL_OPERAND0_ALPHA
:
362 case GL_OPERAND1_ALPHA
:
363 case GL_OPERAND2_ALPHA
:
364 case GL_OPERAND3_ALPHA_NV
:
367 case GL_TEXTURE_LOD_BIAS_EXT
:
368 case GL_COORD_REPLACE_NV
:
370 case GL_TEXTURE_ENV_COLOR
:
377 static inline unsigned
378 _mesa_texgen_enum_to_count(GLenum pname
)
381 case GL_TEXTURE_GEN_MODE
:
383 case GL_OBJECT_PLANE
:
391 static inline unsigned
392 _mesa_material_enum_to_count(GLenum pname
)
399 case GL_AMBIENT_AND_DIFFUSE
:
401 case GL_COLOR_INDEXES
:
410 static inline unsigned
411 _mesa_point_param_enum_to_count(GLenum pname
)
414 case GL_DISTANCE_ATTENUATION_EXT
:
416 case GL_POINT_SIZE_MIN_EXT
:
417 case GL_POINT_SIZE_MAX_EXT
:
418 case GL_POINT_FADE_THRESHOLD_SIZE_EXT
:
419 case GL_POINT_SPRITE_R_MODE_NV
:
420 case GL_POINT_SPRITE_COORD_ORIGIN
:
427 static inline unsigned
428 _mesa_calllists_enum_to_count(GLenum type
)
432 case GL_UNSIGNED_BYTE
:
435 case GL_UNSIGNED_SHORT
:
441 case GL_UNSIGNED_INT
:
450 static inline unsigned
451 _mesa_patch_param_enum_to_count(GLenum pname
)
454 case GL_PATCH_DEFAULT_OUTER_LEVEL
:
456 case GL_PATCH_DEFAULT_INNER_LEVEL
:
463 static inline unsigned
464 _mesa_memobj_enum_to_count(GLenum pname
)
467 case GL_DEDICATED_MEMORY_OBJECT_EXT
:
474 static inline unsigned
475 _mesa_semaphore_enum_to_count(GLenum pname
)
478 /* EXT_semaphore and EXT_semaphore_fd define no parameters */
484 #endif /* MARSHAL_H */