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 immediate index data in draw
78 * calls (deprecated and removed in GL core), we just disable threading.
81 _mesa_glthread_is_non_vbo_draw_elements(const struct gl_context
*ctx
)
83 struct glthread_state
*glthread
= ctx
->GLThread
;
85 return ctx
->API
!= API_OPENGL_CORE
&&
86 (glthread
->CurrentVAO
->IndexBufferIsUserPointer
||
87 glthread
->CurrentVAO
->HasUserPointer
);
91 _mesa_glthread_is_non_vbo_draw_arrays(const struct gl_context
*ctx
)
93 struct glthread_state
*glthread
= ctx
->GLThread
;
95 return ctx
->API
!= API_OPENGL_CORE
&& glthread
->CurrentVAO
->HasUserPointer
;
99 _mesa_glthread_is_non_vbo_draw_arrays_indirect(const struct gl_context
*ctx
)
101 struct glthread_state
*glthread
= ctx
->GLThread
;
103 return ctx
->API
!= API_OPENGL_CORE
&&
104 (!glthread
->draw_indirect_buffer_is_vbo
||
105 glthread
->CurrentVAO
->HasUserPointer
);
109 _mesa_glthread_is_non_vbo_draw_elements_indirect(const struct gl_context
*ctx
)
111 struct glthread_state
*glthread
= ctx
->GLThread
;
113 return ctx
->API
!= API_OPENGL_CORE
&&
114 (!glthread
->draw_indirect_buffer_is_vbo
||
115 glthread
->CurrentVAO
->IndexBufferIsUserPointer
||
116 glthread
->CurrentVAO
->HasUserPointer
);
119 #define DEBUG_MARSHAL_PRINT_CALLS 0
122 * This is printed when we have fallen back to a sync. This can happen when
123 * MARSHAL_MAX_CMD_SIZE is exceeded.
126 debug_print_sync_fallback(const char *func
)
128 #if DEBUG_MARSHAL_PRINT_CALLS
129 printf("fallback to sync: %s\n", func
);
135 debug_print_sync(const char *func
)
137 #if DEBUG_MARSHAL_PRINT_CALLS
138 printf("sync: %s\n", func
);
143 debug_print_marshal(const char *func
)
145 #if DEBUG_MARSHAL_PRINT_CALLS
146 printf("marshal: %s\n", func
);
150 struct _glapi_table
*
151 _mesa_create_marshal_table(const struct gl_context
*ctx
);
153 struct marshal_cmd_ShaderSource
;
154 struct marshal_cmd_BindBuffer
;
155 struct marshal_cmd_BufferData
;
156 struct marshal_cmd_BufferSubData
;
157 struct marshal_cmd_NamedBufferData
;
158 struct marshal_cmd_NamedBufferSubData
;
161 _mesa_marshal_ShaderSource(GLuint shader
, GLsizei count
,
162 const GLchar
* const *string
, const GLint
*length
);
165 _mesa_unmarshal_ShaderSource(struct gl_context
*ctx
,
166 const struct marshal_cmd_ShaderSource
*cmd
);
169 _mesa_marshal_BindBuffer(GLenum target
, GLuint buffer
);
172 _mesa_unmarshal_BindBuffer(struct gl_context
*ctx
,
173 const struct marshal_cmd_BindBuffer
*cmd
);
176 _mesa_unmarshal_BufferData(struct gl_context
*ctx
,
177 const struct marshal_cmd_BufferData
*cmd
);
180 _mesa_marshal_BufferData(GLenum target
, GLsizeiptr size
, const GLvoid
* data
,
184 _mesa_unmarshal_BufferSubData(struct gl_context
*ctx
,
185 const struct marshal_cmd_BufferSubData
*cmd
);
188 _mesa_marshal_BufferSubData(GLenum target
, GLintptr offset
, GLsizeiptr size
,
189 const GLvoid
* data
);
192 _mesa_unmarshal_NamedBufferData(struct gl_context
*ctx
,
193 const struct marshal_cmd_NamedBufferData
*cmd
);
196 _mesa_marshal_NamedBufferData(GLuint buffer
, GLsizeiptr size
,
197 const GLvoid
* data
, GLenum usage
);
200 _mesa_unmarshal_NamedBufferSubData(struct gl_context
*ctx
,
201 const struct marshal_cmd_NamedBufferSubData
*cmd
);
204 _mesa_marshal_NamedBufferSubData(GLuint buffer
, GLintptr offset
, GLsizeiptr size
,
205 const GLvoid
* data
);
207 static inline unsigned
208 _mesa_buffer_enum_to_count(GLenum buffer
)
213 case GL_DEPTH_STENCIL
:
223 static inline unsigned
224 _mesa_tex_param_enum_to_count(GLenum pname
)
227 case GL_TEXTURE_MIN_FILTER
:
228 case GL_TEXTURE_MAG_FILTER
:
229 case GL_TEXTURE_WRAP_S
:
230 case GL_TEXTURE_WRAP_T
:
231 case GL_TEXTURE_WRAP_R
:
232 case GL_TEXTURE_BASE_LEVEL
:
233 case GL_TEXTURE_MAX_LEVEL
:
234 case GL_GENERATE_MIPMAP_SGIS
:
235 case GL_TEXTURE_COMPARE_MODE_ARB
:
236 case GL_TEXTURE_COMPARE_FUNC_ARB
:
237 case GL_DEPTH_TEXTURE_MODE_ARB
:
238 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
239 case GL_TEXTURE_SRGB_DECODE_EXT
:
240 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
241 case GL_TEXTURE_SWIZZLE_R
:
242 case GL_TEXTURE_SWIZZLE_G
:
243 case GL_TEXTURE_SWIZZLE_B
:
244 case GL_TEXTURE_SWIZZLE_A
:
245 case GL_TEXTURE_MIN_LOD
:
246 case GL_TEXTURE_MAX_LOD
:
247 case GL_TEXTURE_PRIORITY
:
248 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
249 case GL_TEXTURE_LOD_BIAS
:
250 case GL_TEXTURE_TILING_EXT
:
252 case GL_TEXTURE_CROP_RECT_OES
:
253 case GL_TEXTURE_SWIZZLE_RGBA
:
254 case GL_TEXTURE_BORDER_COLOR
:
261 static inline unsigned
262 _mesa_fog_enum_to_count(GLenum pname
)
270 case GL_FOG_COORDINATE_SOURCE_EXT
:
271 case GL_FOG_DISTANCE_MODE_NV
:
280 static inline unsigned
281 _mesa_light_enum_to_count(GLenum pname
)
289 case GL_SPOT_DIRECTION
:
291 case GL_SPOT_EXPONENT
:
293 case GL_CONSTANT_ATTENUATION
:
294 case GL_LINEAR_ATTENUATION
:
295 case GL_QUADRATIC_ATTENUATION
:
302 static inline unsigned
303 _mesa_light_model_enum_to_count(GLenum pname
)
306 case GL_LIGHT_MODEL_AMBIENT
:
308 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
309 case GL_LIGHT_MODEL_TWO_SIDE
:
310 case GL_LIGHT_MODEL_COLOR_CONTROL
:
317 static inline unsigned
318 _mesa_texenv_enum_to_count(GLenum pname
)
321 case GL_TEXTURE_ENV_MODE
:
323 case GL_COMBINE_ALPHA
:
327 case GL_SOURCE3_RGB_NV
:
328 case GL_SOURCE0_ALPHA
:
329 case GL_SOURCE1_ALPHA
:
330 case GL_SOURCE2_ALPHA
:
331 case GL_SOURCE3_ALPHA_NV
:
332 case GL_OPERAND0_RGB
:
333 case GL_OPERAND1_RGB
:
334 case GL_OPERAND2_RGB
:
335 case GL_OPERAND3_RGB_NV
:
336 case GL_OPERAND0_ALPHA
:
337 case GL_OPERAND1_ALPHA
:
338 case GL_OPERAND2_ALPHA
:
339 case GL_OPERAND3_ALPHA_NV
:
342 case GL_TEXTURE_LOD_BIAS_EXT
:
343 case GL_COORD_REPLACE_NV
:
345 case GL_TEXTURE_ENV_COLOR
:
352 static inline unsigned
353 _mesa_texgen_enum_to_count(GLenum pname
)
356 case GL_TEXTURE_GEN_MODE
:
358 case GL_OBJECT_PLANE
:
366 static inline unsigned
367 _mesa_material_enum_to_count(GLenum pname
)
374 case GL_AMBIENT_AND_DIFFUSE
:
376 case GL_COLOR_INDEXES
:
385 static inline unsigned
386 _mesa_point_param_enum_to_count(GLenum pname
)
389 case GL_DISTANCE_ATTENUATION_EXT
:
391 case GL_POINT_SIZE_MIN_EXT
:
392 case GL_POINT_SIZE_MAX_EXT
:
393 case GL_POINT_FADE_THRESHOLD_SIZE_EXT
:
394 case GL_POINT_SPRITE_R_MODE_NV
:
395 case GL_POINT_SPRITE_COORD_ORIGIN
:
402 static inline unsigned
403 _mesa_calllists_enum_to_count(GLenum type
)
407 case GL_UNSIGNED_BYTE
:
410 case GL_UNSIGNED_SHORT
:
416 case GL_UNSIGNED_INT
:
425 static inline unsigned
426 _mesa_patch_param_enum_to_count(GLenum pname
)
429 case GL_PATCH_DEFAULT_OUTER_LEVEL
:
431 case GL_PATCH_DEFAULT_INNER_LEVEL
:
438 static inline unsigned
439 _mesa_memobj_enum_to_count(GLenum pname
)
442 case GL_DEDICATED_MEMORY_OBJECT_EXT
:
449 static inline unsigned
450 _mesa_semaphore_enum_to_count(GLenum pname
)
453 /* EXT_semaphore and EXT_semaphore_fd define no parameters */
459 #endif /* MARSHAL_H */