• 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 #ifndef _GLTHREAD_H
25 #define _GLTHREAD_H
26 
27 #include "main/mtypes.h"
28 
29 /* The size of one batch and the maximum size of one call.
30  *
31  * This should be as low as possible, so that:
32  * - multiple synchronizations within a frame don't slow us down much
33  * - a smaller number of calls per frame can still get decent parallelism
34  * - the memory footprint of the queue is low, and with that comes a lower
35  *   chance of experiencing CPU cache thrashing
36  * but it should be high enough so that u_queue overhead remains negligible.
37  */
38 #define MARSHAL_MAX_CMD_SIZE (8 * 1024)
39 
40 /* The number of batch slots in memory.
41  *
42  * One batch is being executed, one batch is being filled, the rest are
43  * waiting batches. There must be at least 1 slot for a waiting batch,
44  * so the minimum number of batches is 3.
45  */
46 #define MARSHAL_MAX_BATCHES 8
47 
48 #include <inttypes.h>
49 #include <stdbool.h>
50 #include "util/u_queue.h"
51 
52 enum marshal_dispatch_cmd_id;
53 
54 /** A single batch of commands queued up for execution. */
55 struct glthread_batch
56 {
57    /** Batch fence for waiting for the execution to finish. */
58    struct util_queue_fence fence;
59 
60    /** The worker thread will access the context with this. */
61    struct gl_context *ctx;
62 
63    /** Amount of data used by batch commands, in bytes. */
64    size_t used;
65 
66    /** Data contained in the command buffer. */
67    uint8_t buffer[MARSHAL_MAX_CMD_SIZE];
68 };
69 
70 struct glthread_state
71 {
72    /** Multithreaded queue. */
73    struct util_queue queue;
74 
75    /** This is sent to the driver for framebuffer overlay / HUD. */
76    struct util_queue_monitoring stats;
77 
78    /** The ring of batches in memory. */
79    struct glthread_batch batches[MARSHAL_MAX_BATCHES];
80 
81    /** Index of the last submitted batch. */
82    unsigned last;
83 
84    /** Index of the batch being filled and about to be submitted. */
85    unsigned next;
86 
87    /**
88     * Tracks on the main thread side whether the current vertex array binding
89     * is in a VBO.
90     */
91    bool vertex_array_is_vbo;
92 
93    /**
94     * Tracks on the main thread side whether the current element array (index
95     * buffer) binding is in a VBO.
96     */
97    bool element_array_is_vbo;
98 };
99 
100 void _mesa_glthread_init(struct gl_context *ctx);
101 void _mesa_glthread_destroy(struct gl_context *ctx);
102 
103 void _mesa_glthread_restore_dispatch(struct gl_context *ctx);
104 void _mesa_glthread_flush_batch(struct gl_context *ctx);
105 void _mesa_glthread_finish(struct gl_context *ctx);
106 
107 #endif /* _GLTHREAD_H*/
108