36692fe57043209a19f1c123b481aa10ff658270
[mesa.git] / src / mesa / main / glthread.h
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 #ifndef _GLTHREAD_H
25 #define _GLTHREAD_H
26
27 #include "main/mtypes.h"
28
29 /* Command size is a number of bytes stored in a short. */
30 #define MARSHAL_MAX_CMD_SIZE 65535
31
32 /* The number of batch slots in memory.
33 *
34 * One batch is being executed, one batch is being filled, the rest are
35 * waiting batches. There must be at least 1 slot for a waiting batch,
36 * so the minimum number of batches is 3.
37 */
38 #define MARSHAL_MAX_BATCHES 4
39
40 #include <inttypes.h>
41 #include <stdbool.h>
42 #include <pthread.h>
43 #include "util/u_queue.h"
44
45 enum marshal_dispatch_cmd_id;
46
47 /** A single batch of commands queued up for execution. */
48 struct glthread_batch
49 {
50 /** Batch fence for waiting for the execution to finish. */
51 struct util_queue_fence fence;
52
53 /** The worker thread will access the context with this. */
54 struct gl_context *ctx;
55
56 /** Amount of data used by batch commands, in bytes. */
57 size_t used;
58
59 /** Data contained in the command buffer. */
60 uint8_t buffer[MARSHAL_MAX_CMD_SIZE];
61 };
62
63 struct glthread_state
64 {
65 /** Multithreaded queue. */
66 struct util_queue queue;
67
68 /** This is sent to the driver for framebuffer overlay / HUD. */
69 struct util_queue_monitoring stats;
70
71 /** The ring of batches in memory. */
72 struct glthread_batch batches[MARSHAL_MAX_BATCHES];
73
74 /** Index of the last submitted batch. */
75 unsigned last;
76
77 /** Index of the batch being filled and about to be submitted. */
78 unsigned next;
79
80 /**
81 * Tracks on the main thread side whether the current vertex array binding
82 * is in a VBO.
83 */
84 bool vertex_array_is_vbo;
85
86 /**
87 * Tracks on the main thread side whether the current element array (index
88 * buffer) binding is in a VBO.
89 */
90 bool element_array_is_vbo;
91 };
92
93 void _mesa_glthread_init(struct gl_context *ctx);
94 void _mesa_glthread_destroy(struct gl_context *ctx);
95
96 void _mesa_glthread_restore_dispatch(struct gl_context *ctx);
97 void _mesa_glthread_flush_batch(struct gl_context *ctx);
98 void _mesa_glthread_finish(struct gl_context *ctx);
99
100 #endif /* _GLTHREAD_H*/