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
48 #include "util/u_queue.h"
51 enum marshal_dispatch_cmd_id
;
53 struct _mesa_HashTable
;
58 bool IndexBufferIsUserPointer
;
61 /** A single batch of commands queued up for execution. */
64 /** Batch fence for waiting for the execution to finish. */
65 struct util_queue_fence fence
;
67 /** The worker thread will access the context with this. */
68 struct gl_context
*ctx
;
70 /** Amount of data used by batch commands, in bytes. */
73 /** Data contained in the command buffer. */
74 uint8_t buffer
[MARSHAL_MAX_CMD_SIZE
];
79 /** Multithreaded queue. */
80 struct util_queue queue
;
82 /** This is sent to the driver for framebuffer overlay / HUD. */
83 struct util_queue_monitoring stats
;
85 /** The ring of batches in memory. */
86 struct glthread_batch batches
[MARSHAL_MAX_BATCHES
];
88 /** Index of the last submitted batch. */
91 /** Index of the batch being filled and about to be submitted. */
94 /** Vertex Array objects tracked by glthread independently of Mesa. */
95 struct _mesa_HashTable
*VAOs
;
96 struct glthread_vao
*CurrentVAO
;
97 struct glthread_vao
*LastLookedUpVAO
;
98 struct glthread_vao DefaultVAO
;
101 * Tracks on the main thread side whether the current vertex array binding
104 bool vertex_array_is_vbo
;
107 * Tracks on the main thread side whether the current element array (index
108 * buffer) binding is in a VBO.
110 bool draw_indirect_buffer_is_vbo
;
113 void _mesa_glthread_init(struct gl_context
*ctx
);
114 void _mesa_glthread_destroy(struct gl_context
*ctx
);
116 void _mesa_glthread_restore_dispatch(struct gl_context
*ctx
, const char *func
);
117 void _mesa_glthread_disable(struct gl_context
*ctx
, const char *func
);
118 void _mesa_glthread_flush_batch(struct gl_context
*ctx
);
119 void _mesa_glthread_finish(struct gl_context
*ctx
);
120 void _mesa_glthread_finish_before(struct gl_context
*ctx
, const char *func
);
122 void _mesa_glthread_BindVertexArray(struct gl_context
*ctx
, GLuint id
);
123 void _mesa_glthread_DeleteVertexArrays(struct gl_context
*ctx
,
124 GLsizei n
, const GLuint
*ids
);
125 void _mesa_glthread_GenVertexArrays(struct gl_context
*ctx
,
126 GLsizei n
, GLuint
*arrays
);
127 void _mesa_glthread_AttribPointer(struct gl_context
*ctx
);
129 #endif /* _GLTHREAD_H*/