DRI2: report swap events correctly in direct rendered case
[mesa.git] / src / gallium / drivers / svga / svga_screen_buffer.h
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #ifndef SVGA_BUFFER_H
27 #define SVGA_BUFFER_H
28
29
30 #include "pipe/p_compiler.h"
31 #include "pipe/p_state.h"
32
33 #include "util/u_double_list.h"
34
35 #include "svga_screen_cache.h"
36
37
38 #define SVGA_BUFFER_MAGIC 0x344f9005
39
40 /**
41 * Maximum number of discontiguous ranges
42 */
43 #define SVGA_BUFFER_MAX_RANGES 32
44
45
46 struct svga_screen;
47 struct svga_context;
48 struct svga_winsys_buffer;
49 struct svga_winsys_surface;
50
51
52 struct svga_buffer_range
53 {
54 unsigned start;
55 unsigned end;
56 };
57
58
59 /**
60 * SVGA pipe buffer.
61 */
62 struct svga_buffer
63 {
64 struct pipe_buffer base;
65
66 /**
67 * Marker to detect bad casts in runtime.
68 */
69 uint32_t magic;
70
71 /**
72 * Regular (non DMA'able) memory.
73 *
74 * Used for user buffers or for buffers which we know before hand that can
75 * never be used by the virtual hardware directly, such as constant buffers.
76 */
77 void *swbuf;
78
79 /**
80 * Whether swbuf was created by the user or not.
81 */
82 boolean user;
83
84 /**
85 * Creation key for the host surface handle.
86 *
87 * This structure describes all the host surface characteristics so that it
88 * can be looked up in cache, since creating a host surface is often a slow
89 * operation.
90 */
91 struct svga_host_surface_cache_key key;
92
93 /**
94 * Host surface handle.
95 *
96 * This is a platform independent abstraction for host SID. We create when
97 * trying to bind
98 */
99 struct svga_winsys_surface *handle;
100
101 /**
102 * Information about ongoing and past map operations.
103 */
104 struct {
105 /**
106 * Number of concurrent mappings.
107 *
108 * XXX: It is impossible to guarantee concurrent maps work in all
109 * circumstances -- pipe_buffers really need transfer objects too.
110 */
111 unsigned count;
112
113 /**
114 * Whether this buffer is currently mapped for writing.
115 */
116 boolean writing;
117
118 /**
119 * Whether the application will tell us explicity which ranges it touched
120 * or not.
121 */
122 boolean flush_explicit;
123
124 /**
125 * Dirty ranges.
126 *
127 * Ranges that were touched by the application and need to be uploaded to
128 * the host.
129 *
130 * This information will be copied into dma.boxes, when emiting the
131 * SVGA3dCmdSurfaceDMA command.
132 */
133 struct svga_buffer_range ranges[SVGA_BUFFER_MAX_RANGES];
134 unsigned num_ranges;
135 } map;
136
137 /**
138 * Information about uploaded version of user buffers.
139 */
140 struct {
141 struct pipe_buffer *buffer;
142
143 /**
144 * We combine multiple user buffers into the same hardware buffer. This
145 * is the relative offset within that buffer.
146 */
147 unsigned offset;
148 } uploaded;
149
150 /**
151 * DMA'ble memory.
152 *
153 * A piece of GMR memory, with the same size of the buffer. It is created
154 * when mapping the buffer, and will be used to upload vertex data to the
155 * host.
156 */
157 struct svga_winsys_buffer *hwbuf;
158
159 /**
160 * Information about pending DMA uploads.
161 *
162 */
163 struct {
164 /**
165 * Whether this buffer has an unfinished DMA upload command.
166 *
167 * If not set then the rest of the information is null.
168 */
169 boolean pending;
170
171 SVGA3dSurfaceDMAFlags flags;
172
173 /**
174 * Pointer to the DMA copy box *inside* the command buffer.
175 */
176 SVGA3dCopyBox *boxes;
177
178 /**
179 * Context that has the pending DMA to this buffer.
180 */
181 struct svga_context *svga;
182 } dma;
183
184 /**
185 * Linked list head, used to gather all buffers with pending dma uploads on
186 * a context. It is only valid if the dma.pending is set above.
187 */
188 struct list_head head;
189 };
190
191
192 static INLINE struct svga_buffer *
193 svga_buffer(struct pipe_buffer *buffer)
194 {
195 if (buffer) {
196 assert(((struct svga_buffer *)buffer)->magic == SVGA_BUFFER_MAGIC);
197 return (struct svga_buffer *)buffer;
198 }
199 return NULL;
200 }
201
202
203 /**
204 * Returns TRUE for user buffers. We may
205 * decide to use an alternate upload path for these buffers.
206 */
207 static INLINE boolean
208 svga_buffer_is_user_buffer( struct pipe_buffer *buffer )
209 {
210 return svga_buffer(buffer)->user;
211 }
212
213
214 void
215 svga_screen_init_buffer_functions(struct pipe_screen *screen);
216
217
218 /**
219 * Get the host surface handle for this buffer.
220 *
221 * This will ensure the host surface is updated, issuing DMAs as needed.
222 *
223 * NOTE: This may insert new commands in the context, so it *must* be called
224 * before reserving command buffer space. And, in order to insert commands
225 * it may need to call svga_context_flush().
226 */
227 struct svga_winsys_surface *
228 svga_buffer_handle(struct svga_context *svga,
229 struct pipe_buffer *buf);
230
231 void
232 svga_context_flush_buffers(struct svga_context *svga);
233
234 struct svga_winsys_buffer *
235 svga_winsys_buffer_create(struct svga_screen *ss,
236 unsigned alignment,
237 unsigned usage,
238 unsigned size);
239
240 #endif /* SVGA_BUFFER_H */