• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
_mesa_glthread_allocate_command(struct gl_context * ctx,uint16_t cmd_id,int size)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->next_batch;
61    struct marshal_cmd_base *cmd_base;
62 
63    if (unlikely(next->used + size > MARSHAL_MAX_CMD_SIZE)) {
64       _mesa_glthread_flush_batch(ctx);
65       next = glthread->next_batch;
66    }
67 
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;
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
_mesa_glthread_has_non_vbo_vertices_or_indices(const struct gl_context * ctx)81 _mesa_glthread_has_non_vbo_vertices_or_indices(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 ||
88            (vao->UserPointerMask & vao->BufferEnabled));
89 }
90 
91 static inline bool
_mesa_glthread_has_non_vbo_vertices(const struct gl_context * ctx)92 _mesa_glthread_has_non_vbo_vertices(const struct gl_context *ctx)
93 {
94    const struct glthread_state *glthread = &ctx->GLThread;
95    const struct glthread_vao *vao = glthread->CurrentVAO;
96 
97    return ctx->API != API_OPENGL_CORE &&
98           (vao->UserPointerMask & vao->BufferEnabled);
99 }
100 
101 static inline bool
_mesa_glthread_has_non_vbo_vertices_or_indirect(const struct gl_context * ctx)102 _mesa_glthread_has_non_vbo_vertices_or_indirect(const struct gl_context *ctx)
103 {
104    const struct glthread_state *glthread = &ctx->GLThread;
105    const struct glthread_vao *vao = glthread->CurrentVAO;
106 
107    return ctx->API != API_OPENGL_CORE &&
108           (glthread->CurrentDrawIndirectBufferName == 0 ||
109            (vao->UserPointerMask & vao->BufferEnabled));
110 }
111 
112 static inline bool
_mesa_glthread_has_non_vbo_vertices_or_indices_or_indirect(const struct gl_context * ctx)113 _mesa_glthread_has_non_vbo_vertices_or_indices_or_indirect(const struct gl_context *ctx)
114 {
115    const struct glthread_state *glthread = &ctx->GLThread;
116    struct glthread_vao *vao = glthread->CurrentVAO;
117 
118    return ctx->API != API_OPENGL_CORE &&
119           (glthread->CurrentDrawIndirectBufferName == 0 ||
120            vao->CurrentElementBufferName == 0 ||
121            (vao->UserPointerMask & vao->BufferEnabled));
122 }
123 
124 
125 struct _glapi_table *
126 _mesa_create_marshal_table(const struct gl_context *ctx);
127 
128 static inline unsigned
_mesa_buffer_enum_to_count(GLenum buffer)129 _mesa_buffer_enum_to_count(GLenum buffer)
130 {
131    switch (buffer) {
132    case GL_COLOR:
133       return 4;
134    case GL_DEPTH_STENCIL:
135       return 2;
136    case GL_STENCIL:
137    case GL_DEPTH:
138       return 1;
139    default:
140       return 0;
141    }
142 }
143 
144 static inline unsigned
_mesa_tex_param_enum_to_count(GLenum pname)145 _mesa_tex_param_enum_to_count(GLenum pname)
146 {
147    switch (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:
172       return 1;
173    case GL_TEXTURE_CROP_RECT_OES:
174    case GL_TEXTURE_SWIZZLE_RGBA:
175    case GL_TEXTURE_BORDER_COLOR:
176       return 4;
177    default:
178       return 0;
179    }
180 }
181 
182 static inline unsigned
_mesa_fog_enum_to_count(GLenum pname)183 _mesa_fog_enum_to_count(GLenum pname)
184 {
185    switch (pname) {
186    case GL_FOG_MODE:
187    case GL_FOG_DENSITY:
188    case GL_FOG_START:
189    case GL_FOG_END:
190    case GL_FOG_INDEX:
191    case GL_FOG_COORDINATE_SOURCE_EXT:
192    case GL_FOG_DISTANCE_MODE_NV:
193       return 1;
194    case GL_FOG_COLOR:
195       return 4;
196    default:
197       return 0;
198    }
199 }
200 
201 static inline unsigned
_mesa_light_enum_to_count(GLenum pname)202 _mesa_light_enum_to_count(GLenum pname)
203 {
204    switch (pname) {
205    case GL_AMBIENT:
206    case GL_DIFFUSE:
207    case GL_SPECULAR:
208    case GL_POSITION:
209       return 4;
210    case GL_SPOT_DIRECTION:
211       return 3;
212    case GL_SPOT_EXPONENT:
213    case GL_SPOT_CUTOFF:
214    case GL_CONSTANT_ATTENUATION:
215    case GL_LINEAR_ATTENUATION:
216    case GL_QUADRATIC_ATTENUATION:
217       return 1;
218    default:
219       return 0;
220    }
221 }
222 
223 static inline unsigned
_mesa_light_model_enum_to_count(GLenum pname)224 _mesa_light_model_enum_to_count(GLenum pname)
225 {
226    switch (pname) {
227    case GL_LIGHT_MODEL_AMBIENT:
228       return 4;
229    case GL_LIGHT_MODEL_LOCAL_VIEWER:
230    case GL_LIGHT_MODEL_TWO_SIDE:
231    case GL_LIGHT_MODEL_COLOR_CONTROL:
232       return 1;
233    default:
234       return 0;
235    }
236 }
237 
238 static inline unsigned
_mesa_texenv_enum_to_count(GLenum pname)239 _mesa_texenv_enum_to_count(GLenum pname)
240 {
241    switch (pname) {
242    case GL_TEXTURE_ENV_MODE:
243    case GL_COMBINE_RGB:
244    case GL_COMBINE_ALPHA:
245    case GL_SOURCE0_RGB:
246    case GL_SOURCE1_RGB:
247    case GL_SOURCE2_RGB:
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:
261    case GL_RGB_SCALE:
262    case GL_ALPHA_SCALE:
263    case GL_TEXTURE_LOD_BIAS_EXT:
264    case GL_COORD_REPLACE_NV:
265       return 1;
266    case GL_TEXTURE_ENV_COLOR:
267       return 4;
268    default:
269       return 0;
270    }
271 }
272 
273 static inline unsigned
_mesa_texgen_enum_to_count(GLenum pname)274 _mesa_texgen_enum_to_count(GLenum pname)
275 {
276    switch (pname) {
277    case GL_TEXTURE_GEN_MODE:
278       return 1;
279    case GL_OBJECT_PLANE:
280    case GL_EYE_PLANE:
281       return 4;
282    default:
283       return 0;
284    }
285 }
286 
287 static inline unsigned
_mesa_material_enum_to_count(GLenum pname)288 _mesa_material_enum_to_count(GLenum pname)
289 {
290    switch (pname) {
291    case GL_EMISSION:
292    case GL_AMBIENT:
293    case GL_DIFFUSE:
294    case GL_SPECULAR:
295    case GL_AMBIENT_AND_DIFFUSE:
296       return 4;
297    case GL_COLOR_INDEXES:
298       return 3;
299    case GL_SHININESS:
300       return 1;
301    default:
302       return 0;
303    }
304 }
305 
306 static inline unsigned
_mesa_point_param_enum_to_count(GLenum pname)307 _mesa_point_param_enum_to_count(GLenum pname)
308 {
309    switch (pname) {
310    case GL_DISTANCE_ATTENUATION_EXT:
311       return 3;
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:
317       return 1;
318    default:
319       return 0;
320    }
321 }
322 
323 static inline unsigned
_mesa_calllists_enum_to_count(GLenum type)324 _mesa_calllists_enum_to_count(GLenum type)
325 {
326    switch (type) {
327    case GL_BYTE:
328    case GL_UNSIGNED_BYTE:
329       return 1;
330    case GL_SHORT:
331    case GL_UNSIGNED_SHORT:
332    case GL_2_BYTES:
333       return 2;
334    case GL_3_BYTES:
335       return 3;
336    case GL_INT:
337    case GL_UNSIGNED_INT:
338    case GL_FLOAT:
339    case GL_4_BYTES:
340       return 4;
341    default:
342       return 0;
343    }
344 }
345 
346 static inline unsigned
_mesa_patch_param_enum_to_count(GLenum pname)347 _mesa_patch_param_enum_to_count(GLenum pname)
348 {
349    switch (pname) {
350    case GL_PATCH_DEFAULT_OUTER_LEVEL:
351       return 4;
352    case GL_PATCH_DEFAULT_INNER_LEVEL:
353       return 2;
354    default:
355       return 0;
356    }
357 }
358 
359 static inline unsigned
_mesa_memobj_enum_to_count(GLenum pname)360 _mesa_memobj_enum_to_count(GLenum pname)
361 {
362    switch (pname) {
363    case GL_DEDICATED_MEMORY_OBJECT_EXT:
364       return 1;
365    default:
366       return 0;
367    }
368 }
369 
370 static inline unsigned
_mesa_semaphore_enum_to_count(GLenum pname)371 _mesa_semaphore_enum_to_count(GLenum pname)
372 {
373    switch (pname) {
374    /* EXT_semaphore and EXT_semaphore_fd define no parameters */
375    default:
376       return 0;
377    }
378 }
379 
380 static inline gl_vert_attrib
_mesa_array_to_attrib(struct gl_context * ctx,GLenum array)381 _mesa_array_to_attrib(struct gl_context *ctx, GLenum array)
382 {
383    switch (array) {
384    case GL_VERTEX_ARRAY:
385       return VERT_ATTRIB_POS;
386    case GL_NORMAL_ARRAY:
387       return VERT_ATTRIB_NORMAL;
388    case GL_COLOR_ARRAY:
389       return VERT_ATTRIB_COLOR0;
390    case GL_INDEX_ARRAY:
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;
404    default:
405       if (array >= GL_TEXTURE0 && array <= GL_TEXTURE7)
406          return VERT_ATTRIB_TEX(array - GL_TEXTURE0);
407       return VERT_ATTRIB_MAX;
408    }
409 }
410 
411 #endif /* MARSHAL_H */
412