Merge commit 'origin/7.8'
[mesa.git] / src / gallium / auxiliary / pipebuffer / pb_bufmgr.h
1 /**************************************************************************
2 *
3 * Copyright 2007 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 /**
29 * \file
30 * Buffer management.
31 *
32 * A buffer manager does only one basic thing: it creates buffers. Actually,
33 * "buffer factory" would probably a more accurate description.
34 *
35 * You can chain buffer managers so that you can have a finer grained memory
36 * management and pooling.
37 *
38 * For example, for a simple batch buffer manager you would chain:
39 * - the native buffer manager, which provides DMA memory from the graphics
40 * memory space;
41 * - the pool buffer manager, which keep around a pool of equally sized buffers
42 * to avoid latency associated with the native buffer manager;
43 * - the fenced buffer manager, which will delay buffer destruction until the
44 * the moment the card finishing processing it.
45 *
46 * \author Jose Fonseca <jrfonseca@tungstengraphics.com>
47 */
48
49 #ifndef PB_BUFMGR_H_
50 #define PB_BUFMGR_H_
51
52
53 #include "pipe/p_compiler.h"
54 #include "pipe/p_defines.h"
55
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61
62 struct pb_desc;
63
64
65 /**
66 * Abstract base class for all buffer managers.
67 */
68 struct pb_manager
69 {
70 void
71 (*destroy)( struct pb_manager *mgr );
72
73 struct pb_buffer *
74 (*create_buffer)( struct pb_manager *mgr,
75 pb_size size,
76 const struct pb_desc *desc);
77
78 /**
79 * Flush all temporary-held buffers.
80 *
81 * Used mostly to aid debugging memory issues or to clean up resources when
82 * the drivers are long lived.
83 */
84 void
85 (*flush)( struct pb_manager *mgr );
86 };
87
88
89 /**
90 * Malloc buffer provider.
91 *
92 * Simple wrapper around pb_malloc_buffer_create for convenience.
93 */
94 struct pb_manager *
95 pb_malloc_bufmgr_create(void);
96
97
98 /**
99 * Static buffer pool sub-allocator.
100 *
101 * Manages the allocation of equally sized buffers. It does so by allocating
102 * a single big buffer and divide it equally sized buffers.
103 *
104 * It is meant to manage the allocation of batch buffer pools.
105 */
106 struct pb_manager *
107 pool_bufmgr_create(struct pb_manager *provider,
108 pb_size n, pb_size size,
109 const struct pb_desc *desc);
110
111
112 /**
113 * Static sub-allocator based the old memory manager.
114 *
115 * It managers buffers of different sizes. It does so by allocating a buffer
116 * with the size of the heap, and then using the old mm memory manager to manage
117 * that heap.
118 */
119 struct pb_manager *
120 mm_bufmgr_create(struct pb_manager *provider,
121 pb_size size, pb_size align2);
122
123 /**
124 * Same as mm_bufmgr_create.
125 *
126 * Buffer will be release when the manager is destroyed.
127 */
128 struct pb_manager *
129 mm_bufmgr_create_from_buffer(struct pb_buffer *buffer,
130 pb_size size, pb_size align2);
131
132
133 /**
134 * Slab sub-allocator.
135 */
136 struct pb_manager *
137 pb_slab_manager_create(struct pb_manager *provider,
138 pb_size bufSize,
139 pb_size slabSize,
140 const struct pb_desc *desc);
141
142 /**
143 * Allow a range of buffer size, by aggregating multiple slabs sub-allocators
144 * with different bucket sizes.
145 */
146 struct pb_manager *
147 pb_slab_range_manager_create(struct pb_manager *provider,
148 pb_size minBufSize,
149 pb_size maxBufSize,
150 pb_size slabSize,
151 const struct pb_desc *desc);
152
153
154 /**
155 * Time-based buffer cache.
156 *
157 * This manager keeps a cache of destroyed buffers during a time interval.
158 */
159 struct pb_manager *
160 pb_cache_manager_create(struct pb_manager *provider,
161 unsigned usecs);
162
163
164 struct pb_fence_ops;
165
166 /**
167 * Fenced buffer manager.
168 *
169 * This manager is just meant for convenience. It wraps the buffers returned
170 * by another manager in fenced buffers, so that
171 *
172 * NOTE: the buffer manager that provides the buffers will be destroyed
173 * at the same time.
174 */
175 struct pb_manager *
176 fenced_bufmgr_create(struct pb_manager *provider,
177 struct pb_fence_ops *ops,
178 pb_size max_buffer_size,
179 pb_size max_cpu_total_size);
180
181
182 struct pb_manager *
183 pb_alt_manager_create(struct pb_manager *provider1,
184 struct pb_manager *provider2);
185
186
187 /**
188 * Ondemand buffer manager.
189 *
190 * Buffers are created in malloc'ed memory (fast and cached), and the constents
191 * is transfered to a buffer from the provider (typically in slow uncached
192 * memory) when there is an attempt to validate the buffer.
193 *
194 * Ideal for situations where one does not know before hand whether a given
195 * buffer will effectively be used by the hardware or not.
196 */
197 struct pb_manager *
198 pb_ondemand_manager_create(struct pb_manager *provider);
199
200
201 /**
202 * Debug buffer manager to detect buffer under- and overflows.
203 *
204 * Under/overflow sizes should be a multiple of the largest alignment
205 */
206 struct pb_manager *
207 pb_debug_manager_create(struct pb_manager *provider,
208 pb_size underflow_size, pb_size overflow_size);
209
210
211 #ifdef __cplusplus
212 }
213 #endif
214
215 #endif /*PB_BUFMGR_H_*/