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
24 /** \file glthread_marshal.h
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
->next_batch
;
61 struct marshal_cmd_base
*cmd_base
;
63 if (unlikely(next
->used
+ size
> MARSHAL_MAX_CMD_SIZE
)) {
64 _mesa_glthread_flush_batch(ctx
);
65 next
= glthread
->next_batch
;
68 const int aligned_size
= align(size
, 8);
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_has_non_vbo_vertices_or_indices(const struct gl_context
*ctx
)
83 const struct glthread_state
*glthread
= &ctx
->GLThread
;
84 struct glthread_vao
*vao
= glthread
->CurrentVAO
;
86 return ctx
->API
!= API_OPENGL_CORE
&&
87 (vao
->CurrentElementBufferName
== 0 ||
88 (vao
->UserPointerMask
& vao
->BufferEnabled
));
92 _mesa_glthread_has_non_vbo_vertices(const struct gl_context
*ctx
)
94 const struct glthread_state
*glthread
= &ctx
->GLThread
;
95 const struct glthread_vao
*vao
= glthread
->CurrentVAO
;
97 return ctx
->API
!= API_OPENGL_CORE
&&
98 (vao
->UserPointerMask
& vao
->BufferEnabled
);
102 _mesa_glthread_has_non_vbo_vertices_or_indirect(const struct gl_context
*ctx
)
104 const struct glthread_state
*glthread
= &ctx
->GLThread
;
105 const struct glthread_vao
*vao
= glthread
->CurrentVAO
;
107 return ctx
->API
!= API_OPENGL_CORE
&&
108 (glthread
->CurrentDrawIndirectBufferName
== 0 ||
109 (vao
->UserPointerMask
& vao
->BufferEnabled
));
113 _mesa_glthread_has_non_vbo_vertices_or_indices_or_indirect(const struct gl_context
*ctx
)
115 const struct glthread_state
*glthread
= &ctx
->GLThread
;
116 struct glthread_vao
*vao
= glthread
->CurrentVAO
;
118 return ctx
->API
!= API_OPENGL_CORE
&&
119 (glthread
->CurrentDrawIndirectBufferName
== 0 ||
120 vao
->CurrentElementBufferName
== 0 ||
121 (vao
->UserPointerMask
& vao
->BufferEnabled
));
125 struct _glapi_table
*
126 _mesa_create_marshal_table(const struct gl_context
*ctx
);
128 static inline unsigned
129 _mesa_buffer_enum_to_count(GLenum buffer
)
134 case GL_DEPTH_STENCIL
:
144 static inline unsigned
145 _mesa_tex_param_enum_to_count(GLenum pname
)
148 case GL_TEXTURE_MIN_FILTER
:
149 case GL_TEXTURE_MAG_FILTER
:
150 case GL_TEXTURE_WRAP_S
:
151 case GL_TEXTURE_WRAP_T
:
152 case GL_TEXTURE_WRAP_R
:
153 case GL_TEXTURE_BASE_LEVEL
:
154 case GL_TEXTURE_MAX_LEVEL
:
155 case GL_GENERATE_MIPMAP_SGIS
:
156 case GL_TEXTURE_COMPARE_MODE_ARB
:
157 case GL_TEXTURE_COMPARE_FUNC_ARB
:
158 case GL_DEPTH_TEXTURE_MODE_ARB
:
159 case GL_DEPTH_STENCIL_TEXTURE_MODE
:
160 case GL_TEXTURE_SRGB_DECODE_EXT
:
161 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
162 case GL_TEXTURE_SWIZZLE_R
:
163 case GL_TEXTURE_SWIZZLE_G
:
164 case GL_TEXTURE_SWIZZLE_B
:
165 case GL_TEXTURE_SWIZZLE_A
:
166 case GL_TEXTURE_MIN_LOD
:
167 case GL_TEXTURE_MAX_LOD
:
168 case GL_TEXTURE_PRIORITY
:
169 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
170 case GL_TEXTURE_LOD_BIAS
:
171 case GL_TEXTURE_TILING_EXT
:
173 case GL_TEXTURE_CROP_RECT_OES
:
174 case GL_TEXTURE_SWIZZLE_RGBA
:
175 case GL_TEXTURE_BORDER_COLOR
:
182 static inline unsigned
183 _mesa_fog_enum_to_count(GLenum pname
)
191 case GL_FOG_COORDINATE_SOURCE_EXT
:
192 case GL_FOG_DISTANCE_MODE_NV
:
201 static inline unsigned
202 _mesa_light_enum_to_count(GLenum pname
)
210 case GL_SPOT_DIRECTION
:
212 case GL_SPOT_EXPONENT
:
214 case GL_CONSTANT_ATTENUATION
:
215 case GL_LINEAR_ATTENUATION
:
216 case GL_QUADRATIC_ATTENUATION
:
223 static inline unsigned
224 _mesa_light_model_enum_to_count(GLenum pname
)
227 case GL_LIGHT_MODEL_AMBIENT
:
229 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
230 case GL_LIGHT_MODEL_TWO_SIDE
:
231 case GL_LIGHT_MODEL_COLOR_CONTROL
:
238 static inline unsigned
239 _mesa_texenv_enum_to_count(GLenum pname
)
242 case GL_TEXTURE_ENV_MODE
:
244 case GL_COMBINE_ALPHA
:
248 case GL_SOURCE3_RGB_NV
:
249 case GL_SOURCE0_ALPHA
:
250 case GL_SOURCE1_ALPHA
:
251 case GL_SOURCE2_ALPHA
:
252 case GL_SOURCE3_ALPHA_NV
:
253 case GL_OPERAND0_RGB
:
254 case GL_OPERAND1_RGB
:
255 case GL_OPERAND2_RGB
:
256 case GL_OPERAND3_RGB_NV
:
257 case GL_OPERAND0_ALPHA
:
258 case GL_OPERAND1_ALPHA
:
259 case GL_OPERAND2_ALPHA
:
260 case GL_OPERAND3_ALPHA_NV
:
263 case GL_TEXTURE_LOD_BIAS_EXT
:
264 case GL_COORD_REPLACE_NV
:
266 case GL_TEXTURE_ENV_COLOR
:
273 static inline unsigned
274 _mesa_texgen_enum_to_count(GLenum pname
)
277 case GL_TEXTURE_GEN_MODE
:
279 case GL_OBJECT_PLANE
:
287 static inline unsigned
288 _mesa_material_enum_to_count(GLenum pname
)
295 case GL_AMBIENT_AND_DIFFUSE
:
297 case GL_COLOR_INDEXES
:
306 static inline unsigned
307 _mesa_point_param_enum_to_count(GLenum pname
)
310 case GL_DISTANCE_ATTENUATION_EXT
:
312 case GL_POINT_SIZE_MIN_EXT
:
313 case GL_POINT_SIZE_MAX_EXT
:
314 case GL_POINT_FADE_THRESHOLD_SIZE_EXT
:
315 case GL_POINT_SPRITE_R_MODE_NV
:
316 case GL_POINT_SPRITE_COORD_ORIGIN
:
323 static inline unsigned
324 _mesa_calllists_enum_to_count(GLenum type
)
328 case GL_UNSIGNED_BYTE
:
331 case GL_UNSIGNED_SHORT
:
337 case GL_UNSIGNED_INT
:
346 static inline unsigned
347 _mesa_patch_param_enum_to_count(GLenum pname
)
350 case GL_PATCH_DEFAULT_OUTER_LEVEL
:
352 case GL_PATCH_DEFAULT_INNER_LEVEL
:
359 static inline unsigned
360 _mesa_memobj_enum_to_count(GLenum pname
)
363 case GL_DEDICATED_MEMORY_OBJECT_EXT
:
370 static inline unsigned
371 _mesa_semaphore_enum_to_count(GLenum pname
)
374 /* EXT_semaphore and EXT_semaphore_fd define no parameters */
380 static inline gl_vert_attrib
381 _mesa_array_to_attrib(struct gl_context
*ctx
, GLenum array
)
384 case GL_VERTEX_ARRAY
:
385 return VERT_ATTRIB_POS
;
386 case GL_NORMAL_ARRAY
:
387 return VERT_ATTRIB_NORMAL
;
389 return VERT_ATTRIB_COLOR0
;
391 return VERT_ATTRIB_COLOR_INDEX
;
392 case GL_TEXTURE_COORD_ARRAY
:
393 return VERT_ATTRIB_TEX(ctx
->GLThread
.ClientActiveTexture
);
394 case GL_EDGE_FLAG_ARRAY
:
395 return VERT_ATTRIB_EDGEFLAG
;
396 case GL_FOG_COORDINATE_ARRAY
:
397 return VERT_ATTRIB_FOG
;
398 case GL_SECONDARY_COLOR_ARRAY
:
399 return VERT_ATTRIB_COLOR1
;
400 case GL_POINT_SIZE_ARRAY_OES
:
401 return VERT_ATTRIB_POINT_SIZE
;
402 case GL_PRIMITIVE_RESTART_NV
:
403 return VERT_ATTRIB_PRIMITIVE_RESTART_NV
;
405 if (array
>= GL_TEXTURE0
&& array
<= GL_TEXTURE7
)
406 return VERT_ATTRIB_TEX(array
- GL_TEXTURE0
);
407 return VERT_ATTRIB_MAX
;
411 #endif /* MARSHAL_H */