Merge branch 'nouveau-import'
[mesa.git] / src / mesa / drivers / dri / i965 / bufmgr.h
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef BUFMGR_H
29 #define BUFMGR_H
30
31 #include "intel_context.h"
32
33
34 /* The buffer manager context. Opaque.
35 */
36 struct bufmgr;
37 struct buffer;
38
39
40 struct bufmgr *bm_fake_intel_Attach( struct intel_context *intel );
41
42 /* Flags for validate and other calls. If both NO_UPLOAD and NO_EVICT
43 * are specified, ValidateBuffers is essentially a query.
44 */
45 #define BM_MEM_LOCAL 0x1
46 #define BM_MEM_AGP 0x2
47 #define BM_MEM_VRAM 0x4 /* not yet used */
48 #define BM_WRITE 0x8 /* not yet used */
49 #define BM_READ 0x10 /* not yet used */
50 #define BM_NO_UPLOAD 0x20
51 #define BM_NO_EVICT 0x40
52 #define BM_NO_MOVE 0x80 /* not yet used */
53 #define BM_NO_ALLOC 0x100 /* legacy "fixed" buffers only */
54 #define BM_CLIENT 0x200 /* for map - pointer will be accessed
55 * without dri lock */
56
57 #define BM_MEM_MASK (BM_MEM_LOCAL|BM_MEM_AGP|BM_MEM_VRAM)
58
59
60
61
62 /* Create a pool of a given memory type, from a certain offset and a
63 * certain size.
64 *
65 * Also passed in is a virtual pointer to the start of the pool. This
66 * is useful in the faked-out version in i915 so that MapBuffer can
67 * return a pointer to a buffer residing in AGP space.
68 *
69 * Flags passed into a pool are inherited by all buffers allocated in
70 * that pool. So pools representing the static front,back,depth
71 * buffer allocations should have MEM_AGP|NO_UPLOAD|NO_EVICT|NO_MOVE to match
72 * the behaviour of the legacy allocations.
73 *
74 * Returns -1 for failure, pool number for success.
75 */
76 int bmInitPool( struct intel_context *,
77 unsigned long low_offset,
78 void *low_virtual,
79 unsigned long size,
80 unsigned flags);
81
82
83 /* Stick closely to ARB_vbo semantics - they're well defined and
84 * understood, and drivers can just pass the calls through without too
85 * much thunking.
86 */
87 void bmGenBuffers(struct intel_context *, const char *, unsigned n, struct buffer **buffers,
88 int align );
89 void bmDeleteBuffers(struct intel_context *, unsigned n, struct buffer **buffers);
90
91
92 /* Hook to inform faked buffer manager about fixed-position
93 * front,depth,back buffers. These may move to a fully memory-managed
94 * scheme, or they may continue to be managed as is.
95 */
96 struct buffer *bmGenBufferStatic(struct intel_context *,
97 unsigned pool);
98
99 /* On evict, buffer manager will call invalidate_cb() to note that the
100 * buffer needs to be reloaded.
101 *
102 * Buffer is uploaded by calling bmMapBuffer() and copying data into
103 * the returned pointer.
104 *
105 * This is basically a big hack to get some more performance by
106 * turning off backing store for buffers where we either have it
107 * already (textures) or don't need it (batch buffers, temporary
108 * vbo's).
109 */
110 void bmBufferSetInvalidateCB(struct intel_context *,
111 struct buffer *buf,
112 void (*invalidate_cb)( struct intel_context *, void *ptr ),
113 void *ptr,
114 GLboolean dont_fence_subdata);
115
116
117 /* The driver has more intimate knowledge of the hardare than a GL
118 * client would, so flags here is more proscriptive than the usage
119 * values in the ARB_vbo interface:
120 */
121 int bmBufferData(struct intel_context *,
122 struct buffer *buf,
123 unsigned size,
124 const void *data,
125 unsigned flags );
126
127 int bmBufferSubData(struct intel_context *,
128 struct buffer *buf,
129 unsigned offset,
130 unsigned size,
131 const void *data );
132
133
134 int bmBufferDataAUB(struct intel_context *,
135 struct buffer *buf,
136 unsigned size,
137 const void *data,
138 unsigned flags,
139 unsigned aubtype,
140 unsigned aubsubtype );
141
142 int bmBufferSubDataAUB(struct intel_context *,
143 struct buffer *buf,
144 unsigned offset,
145 unsigned size,
146 const void *data,
147 unsigned aubtype,
148 unsigned aubsubtype );
149
150
151 /* In this version, taking the offset will provoke an upload on
152 * buffers not already resident in AGP:
153 */
154 unsigned bmBufferOffset(struct intel_context *,
155 struct buffer *buf);
156
157
158 /* Extract data from the buffer:
159 */
160 void bmBufferGetSubData(struct intel_context *,
161 struct buffer *buf,
162 unsigned offset,
163 unsigned size,
164 void *data );
165
166 void *bmMapBuffer( struct intel_context *,
167 struct buffer *buf,
168 unsigned access );
169
170 void bmUnmapBuffer( struct intel_context *,
171 struct buffer *buf );
172
173 void bmUnmapBufferAUB( struct intel_context *,
174 struct buffer *buf,
175 unsigned aubtype,
176 unsigned aubsubtype );
177
178
179 /* Pertains to all buffers who's offset has been taken since the last
180 * fence or release.
181 */
182 int bmValidateBuffers( struct intel_context * );
183 void bmReleaseBuffers( struct intel_context * );
184
185 GLuint bmCtxId( struct intel_context *intel );
186
187
188 GLboolean bmError( struct intel_context * );
189 void bmEvictAll( struct intel_context * );
190
191 void *bmFindVirtual( struct intel_context *intel,
192 unsigned int offset,
193 size_t sz );
194
195 /* This functionality is used by the buffer manager, not really sure
196 * if we need to be exposing it in this way, probably libdrm will
197 * offer equivalent calls.
198 *
199 * For now they can stay, but will likely change/move before final:
200 */
201 unsigned bmSetFence( struct intel_context * );
202 unsigned bmLockAndFence( struct intel_context *intel );
203 int bmTestFence( struct intel_context *, unsigned fence );
204 void bmFinishFence( struct intel_context *, unsigned fence );
205
206 void bm_fake_NotifyContendedLockTake( struct intel_context * );
207
208 extern int INTEL_DEBUG;
209 #define DEBUG_BUFMGR 0x10000000
210
211 #define DBG(...) do { if (INTEL_DEBUG & DEBUG_BUFMGR) _mesa_printf(__VA_ARGS__); } while(0)
212
213 #endif