svga: Further cleanup/comment svga buffer code.
[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 * DMA'ble memory.
139 *
140 * A piece of GMR memory, with the same size of the buffer. It is created
141 * when mapping the buffer, and will be used to upload vertex data to the
142 * host.
143 */
144 struct svga_winsys_buffer *hwbuf;
145
146 /**
147 * Information about pending DMA uploads.
148 *
149 */
150 struct {
151 /**
152 * Whether this buffer has an unfinished DMA upload command.
153 *
154 * If not set then the rest of the information is null.
155 */
156 boolean pending;
157
158 SVGA3dSurfaceDMAFlags flags;
159
160 /**
161 * Pointer to the DMA copy box *inside* the command buffer.
162 */
163 SVGA3dCopyBox *boxes;
164
165 /**
166 * Context that has the pending DMA to this buffer.
167 */
168 struct svga_context *svga;
169 } dma;
170
171 /**
172 * Linked list head, used to gather all buffers with pending dma uploads on
173 * a context. It is only valid if the dma.pending is set above.
174 */
175 struct list_head head;
176 };
177
178
179 static INLINE struct svga_buffer *
180 svga_buffer(struct pipe_buffer *buffer)
181 {
182 if (buffer) {
183 assert(((struct svga_buffer *)buffer)->magic == SVGA_BUFFER_MAGIC);
184 return (struct svga_buffer *)buffer;
185 }
186 return NULL;
187 }
188
189
190 /**
191 * Returns TRUE for user buffers. We may
192 * decide to use an alternate upload path for these buffers.
193 */
194 static INLINE boolean
195 svga_buffer_is_user_buffer( struct pipe_buffer *buffer )
196 {
197 return svga_buffer(buffer)->user;
198 }
199
200
201 void
202 svga_screen_init_buffer_functions(struct pipe_screen *screen);
203
204 struct svga_winsys_surface *
205 svga_buffer_handle(struct svga_context *svga,
206 struct pipe_buffer *buf);
207
208 void
209 svga_context_flush_buffers(struct svga_context *svga);
210
211 struct svga_winsys_buffer *
212 svga_winsys_buffer_create(struct svga_screen *ss,
213 unsigned alignment,
214 unsigned usage,
215 unsigned size);
216
217 #endif /* SVGA_BUFFER_H */