Merge branch 'mesa_7_7_branch'
[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 * Describe a
61 *
62 * This holds the information to emit a SVGA3dCmdSurfaceDMA.
63 */
64 struct svga_buffer_upload
65 {
66 /**
67 * Guest memory region.
68 */
69 struct svga_winsys_buffer *buf;
70
71 struct svga_buffer_range ranges[SVGA_BUFFER_MAX_RANGES];
72 unsigned num_ranges;
73
74 SVGA3dSurfaceDMAFlags flags;
75
76 /**
77 * Pointer to the DMA copy box *inside* the command buffer.
78 */
79 SVGA3dCopyBox *boxes;
80
81 /**
82 * Context that has the pending DMA to this buffer.
83 */
84 struct svga_context *svga;
85 };
86
87
88 /**
89 * SVGA pipe buffer.
90 */
91 struct svga_buffer
92 {
93 struct pipe_buffer base;
94
95 /**
96 * Marker to detect bad casts in runtime.
97 */
98 uint32_t magic;
99
100 /**
101 * Regular (non DMA'able) memory.
102 *
103 * Used for user buffers or for buffers which we know before hand that can
104 * never be used by the virtual hardware directly, such as constant buffers.
105 */
106 void *swbuf;
107
108 /**
109 * Whether swbuf was created by the user or not.
110 */
111 boolean user;
112
113 /**
114 * DMA'ble memory.
115 *
116 * A piece of GMR memory. It is created when mapping the buffer, and will be
117 * used to upload/download vertex data from the host.
118 */
119 struct svga_buffer_upload hw;
120
121 /**
122 * Creation key for the host surface handle.
123 *
124 * This structure describes all the host surface characteristics so that it
125 * can be looked up in cache, since creating a host surface is often a slow
126 * operation.
127 */
128 struct svga_host_surface_cache_key key;
129
130 /**
131 * Host surface handle.
132 *
133 * This is a platform independent abstraction for host SID. We create when
134 * trying to bind
135 */
136 struct svga_winsys_surface *handle;
137
138 /**
139 * Whether the host has been ever written.
140 */
141 boolean host_written;
142
143 struct {
144 unsigned count;
145 boolean writing;
146 boolean flush_explicit;
147 } map;
148
149 boolean needs_flush;
150 struct list_head head;
151 };
152
153
154 static INLINE struct svga_buffer *
155 svga_buffer(struct pipe_buffer *buffer)
156 {
157 if (buffer) {
158 assert(((struct svga_buffer *)buffer)->magic == SVGA_BUFFER_MAGIC);
159 return (struct svga_buffer *)buffer;
160 }
161 return NULL;
162 }
163
164
165 /**
166 * Returns TRUE for user buffers. We may
167 * decide to use an alternate upload path for these buffers.
168 */
169 static INLINE boolean
170 svga_buffer_is_user_buffer( struct pipe_buffer *buffer )
171 {
172 return svga_buffer(buffer)->user;
173 }
174
175
176 void
177 svga_screen_init_buffer_functions(struct pipe_screen *screen);
178
179 struct svga_winsys_surface *
180 svga_buffer_handle(struct svga_context *svga,
181 struct pipe_buffer *buf);
182
183 void
184 svga_context_flush_buffers(struct svga_context *svga);
185
186 struct svga_winsys_buffer *
187 svga_winsys_buffer_create(struct svga_screen *ss,
188 unsigned alignment,
189 unsigned usage,
190 unsigned size);
191
192 #endif /* SVGA_BUFFER_H */