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
27 /* The size of one batch and the maximum size of one call.
29 * This should be as low as possible, so that:
30 * - multiple synchronizations within a frame don't slow us down much
31 * - a smaller number of calls per frame can still get decent parallelism
32 * - the memory footprint of the queue is low, and with that comes a lower
33 * chance of experiencing CPU cache thrashing
34 * but it should be high enough so that u_queue overhead remains negligible.
36 #define MARSHAL_MAX_CMD_SIZE (8 * 1024)
38 /* The number of batch slots in memory.
40 * One batch is being executed, one batch is being filled, the rest are
41 * waiting batches. There must be at least 1 slot for a waiting batch,
42 * so the minimum number of batches is 3.
44 #define MARSHAL_MAX_BATCHES 8
46 /* Special value for glEnableClientState(GL_PRIMITIVE_RESTART_NV). */
47 #define VERT_ATTRIB_PRIMITIVE_RESTART_NV -1
51 #include "util/u_queue.h"
53 #include "compiler/shader_enums.h"
54 #include "main/config.h"
57 struct gl_buffer_object
;
58 struct _mesa_HashTable
;
60 struct glthread_attrib_binding
{
61 struct gl_buffer_object
*buffer
; /**< where non-VBO data was uploaded */
62 int offset
; /**< offset to uploaded non-VBO data */
63 const void *original_pointer
; /**< restore this pointer after the draw */
68 GLuint CurrentElementBufferName
;
69 GLbitfield UserEnabled
; /**< Vertex attribs enabled by the user. */
70 GLbitfield Enabled
; /**< UserEnabled with POS vs GENERIC0 aliasing resolved. */
71 GLbitfield BufferEnabled
; /**< "Enabled" converted to buffer bindings. */
72 GLbitfield BufferInterleaved
; /**< Bitmask of buffers used by multiple attribs. */
73 GLbitfield UserPointerMask
; /**< Bitmask of buffer bindings. */
74 GLbitfield NonZeroDivisorMask
; /**< Bitmask of buffer bindings. */
79 GLuint RelativeOffset
;
80 GLuint BufferIndex
; /**< Referring to Attrib[BufferIndex]. */
82 /* Per buffer binding: */
85 int EnabledAttribCount
; /**< Number of enabled attribs using this buffer. */
87 } Attrib
[VERT_ATTRIB_MAX
];
90 /** A single batch of commands queued up for execution. */
93 /** Batch fence for waiting for the execution to finish. */
94 struct util_queue_fence fence
;
96 /** The worker thread will access the context with this. */
97 struct gl_context
*ctx
;
99 /** Amount of data used by batch commands, in bytes. */
102 /** Data contained in the command buffer. */
106 __attribute__((aligned(8)))
108 uint8_t buffer
[MARSHAL_MAX_CMD_SIZE
];
111 struct glthread_client_attrib
{
112 struct glthread_vao VAO
;
113 GLuint CurrentArrayBufferName
;
114 int ClientActiveTexture
;
116 bool PrimitiveRestart
;
117 bool PrimitiveRestartFixedIndex
;
119 /** Whether this element of the client attrib stack contains saved state. */
123 struct glthread_state
125 /** Multithreaded queue. */
126 struct util_queue queue
;
128 /** This is sent to the driver for framebuffer overlay / HUD. */
129 struct util_queue_monitoring stats
;
131 /** Whether GLThread is enabled. */
134 /** Whether GLThread is inside a display list generation. */
137 /** The ring of batches in memory. */
138 struct glthread_batch batches
[MARSHAL_MAX_BATCHES
];
140 /** Pointer to the batch currently being filled. */
141 struct glthread_batch
*next_batch
;
143 /** Index of the last submitted batch. */
146 /** Index of the batch being filled and about to be submitted. */
149 /** Upload buffer. */
150 struct gl_buffer_object
*upload_buffer
;
152 unsigned upload_offset
;
153 int upload_buffer_private_refcount
;
156 GLboolean SupportsBufferUploads
;
157 GLboolean SupportsNonVBOUploads
;
159 /** Primitive restart state. */
160 bool PrimitiveRestart
;
161 bool PrimitiveRestartFixedIndex
;
162 bool _PrimitiveRestart
;
164 GLuint _RestartIndex
[4]; /**< Restart index for index_size = 1,2,4. */
166 /** Vertex Array objects tracked by glthread independently of Mesa. */
167 struct _mesa_HashTable
*VAOs
;
168 struct glthread_vao
*CurrentVAO
;
169 struct glthread_vao
*LastLookedUpVAO
;
170 struct glthread_vao DefaultVAO
;
171 struct glthread_client_attrib ClientAttribStack
[MAX_CLIENT_ATTRIB_STACK_DEPTH
];
172 int ClientAttribStackTop
;
173 int ClientActiveTexture
;
175 /** Currently-bound buffer object IDs. */
176 GLuint CurrentArrayBufferName
;
177 GLuint CurrentDrawIndirectBufferName
;
180 void _mesa_glthread_init(struct gl_context
*ctx
);
181 void _mesa_glthread_destroy(struct gl_context
*ctx
);
183 void _mesa_glthread_restore_dispatch(struct gl_context
*ctx
, const char *func
);
184 void _mesa_glthread_disable(struct gl_context
*ctx
, const char *func
);
185 void _mesa_glthread_flush_batch(struct gl_context
*ctx
);
186 void _mesa_glthread_finish(struct gl_context
*ctx
);
187 void _mesa_glthread_finish_before(struct gl_context
*ctx
, const char *func
);
188 void _mesa_glthread_upload(struct gl_context
*ctx
, const void *data
,
189 GLsizeiptr size
, unsigned *out_offset
,
190 struct gl_buffer_object
**out_buffer
,
192 void _mesa_glthread_reset_vao(struct glthread_vao
*vao
);
194 void _mesa_glthread_BindBuffer(struct gl_context
*ctx
, GLenum target
,
196 void _mesa_glthread_DeleteBuffers(struct gl_context
*ctx
, GLsizei n
,
197 const GLuint
*buffers
);
199 void _mesa_glthread_BindVertexArray(struct gl_context
*ctx
, GLuint id
);
200 void _mesa_glthread_DeleteVertexArrays(struct gl_context
*ctx
,
201 GLsizei n
, const GLuint
*ids
);
202 void _mesa_glthread_GenVertexArrays(struct gl_context
*ctx
,
203 GLsizei n
, GLuint
*arrays
);
204 void _mesa_glthread_set_prim_restart(struct gl_context
*ctx
, GLenum cap
,
206 void _mesa_glthread_PrimitiveRestartIndex(struct gl_context
*ctx
, GLuint index
);
207 void _mesa_glthread_ClientState(struct gl_context
*ctx
, GLuint
*vaobj
,
208 gl_vert_attrib attrib
, bool enable
);
209 void _mesa_glthread_AttribDivisor(struct gl_context
*ctx
, const GLuint
*vaobj
,
210 gl_vert_attrib attrib
, GLuint divisor
);
211 void _mesa_glthread_AttribPointer(struct gl_context
*ctx
, gl_vert_attrib attrib
,
212 GLint size
, GLenum type
, GLsizei stride
,
213 const void *pointer
);
214 void _mesa_glthread_DSAAttribPointer(struct gl_context
*ctx
, GLuint vao
,
215 GLuint buffer
, gl_vert_attrib attrib
,
216 GLint size
, GLenum type
, GLsizei stride
,
218 void _mesa_glthread_AttribFormat(struct gl_context
*ctx
, GLuint attribindex
,
219 GLint size
, GLenum type
, GLuint relativeoffset
);
220 void _mesa_glthread_DSAAttribFormat(struct gl_context
*ctx
, GLuint vaobj
,
221 GLuint attribindex
, GLint size
, GLenum type
,
222 GLuint relativeoffset
);
223 void _mesa_glthread_VertexBuffer(struct gl_context
*ctx
, GLuint bindingindex
,
224 GLuint buffer
, GLintptr offset
, GLsizei stride
);
225 void _mesa_glthread_DSAVertexBuffer(struct gl_context
*ctx
, GLuint vaobj
,
226 GLuint bindingindex
, GLuint buffer
,
227 GLintptr offset
, GLsizei stride
);
228 void _mesa_glthread_DSAVertexBuffers(struct gl_context
*ctx
, GLuint vaobj
,
229 GLuint first
, GLsizei count
,
230 const GLuint
*buffers
,
231 const GLintptr
*offsets
,
232 const GLsizei
*strides
);
233 void _mesa_glthread_BindingDivisor(struct gl_context
*ctx
, GLuint bindingindex
,
235 void _mesa_glthread_DSABindingDivisor(struct gl_context
*ctx
, GLuint vaobj
,
236 GLuint bindingindex
, GLuint divisor
);
237 void _mesa_glthread_AttribBinding(struct gl_context
*ctx
, GLuint attribindex
,
238 GLuint bindingindex
);
239 void _mesa_glthread_DSAAttribBinding(struct gl_context
*ctx
, GLuint vaobj
,
240 GLuint attribindex
, GLuint bindingindex
);
241 void _mesa_glthread_DSAElementBuffer(struct gl_context
*ctx
, GLuint vaobj
,
243 void _mesa_glthread_PushClientAttrib(struct gl_context
*ctx
, GLbitfield mask
,
245 void _mesa_glthread_PopClientAttrib(struct gl_context
*ctx
);
246 void _mesa_glthread_ClientAttribDefault(struct gl_context
*ctx
, GLbitfield mask
);
248 #endif /* _GLTHREAD_H*/