pb_bufmgr.h revision 1672e8e05996d48e51a1998bd7e9b08b78e012f5
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 José 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_error.h"
55
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61
62struct pb_desc;
63struct pipe_buffer;
64struct pipe_winsys;
65
66
67/**
68 * Abstract base class for all buffer managers.
69 */
70struct pb_manager
71{
72   void
73   (*destroy)( struct pb_manager *mgr );
74
75   struct pb_buffer *
76   (*create_buffer)( struct pb_manager *mgr,
77	             size_t size,
78	             const struct pb_desc *desc);
79
80   /**
81    * Flush all temporary-held buffers.
82    *
83    * Used mostly to aid debugging memory issues or to clean up resources when
84    * the drivers are long lived.
85    */
86   void
87   (*flush)( struct pb_manager *mgr );
88};
89
90
91/**
92 * Malloc buffer provider.
93 *
94 * Simple wrapper around pb_malloc_buffer_create for convenience.
95 */
96struct pb_manager *
97pb_malloc_bufmgr_create(void);
98
99
100/**
101 * Static buffer pool sub-allocator.
102 *
103 * Manages the allocation of equally sized buffers. It does so by allocating
104 * a single big buffer and divide it equally sized buffers.
105 *
106 * It is meant to manage the allocation of batch buffer pools.
107 */
108struct pb_manager *
109pool_bufmgr_create(struct pb_manager *provider,
110                   size_t n, size_t size,
111                   const struct pb_desc *desc);
112
113
114/**
115 * Static sub-allocator based the old memory manager.
116 *
117 * It managers buffers of different sizes. It does so by allocating a buffer
118 * with the size of the heap, and then using the old mm memory manager to manage
119 * that heap.
120 */
121struct pb_manager *
122mm_bufmgr_create(struct pb_manager *provider,
123                 size_t size, size_t align2);
124
125/**
126 * Same as mm_bufmgr_create.
127 *
128 * Buffer will be release when the manager is destroyed.
129 */
130struct pb_manager *
131mm_bufmgr_create_from_buffer(struct pb_buffer *buffer,
132                             size_t size, size_t align2);
133
134
135/**
136 * Slab sub-allocator.
137 */
138struct pb_manager *
139pb_slab_manager_create(struct pb_manager *provider,
140                       size_t bufSize,
141                       size_t slabSize,
142                       const struct pb_desc *desc);
143
144/**
145 * Allow a range of buffer size, by aggregating multiple slabs sub-allocators
146 * with different bucket sizes.
147 */
148struct pb_manager *
149pb_slab_range_manager_create(struct pb_manager *provider,
150                             size_t minBufSize,
151                             size_t maxBufSize,
152                             size_t slabSize,
153                             const struct pb_desc *desc);
154
155
156/**
157 * Time-based buffer cache.
158 *
159 * This manager keeps a cache of destroyed buffers during a time interval.
160 */
161struct pb_manager *
162pb_cache_manager_create(struct pb_manager *provider,
163                     	unsigned usecs);
164
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 */
175struct pb_manager *
176fenced_bufmgr_create(struct pb_manager *provider,
177                     struct pipe_winsys *winsys);
178
179
180struct pb_manager *
181pb_alt_manager_create(struct pb_manager *provider1,
182                      struct pb_manager *provider2);
183
184
185/**
186 * Debug buffer manager to detect buffer under- and overflows.
187 *
188 * Band size should be a multiple of the largest alignment
189 */
190struct pb_manager *
191pb_debug_manager_create(struct pb_manager *provider, size_t band_size);
192
193
194#ifdef __cplusplus
195}
196#endif
197
198#endif /*PB_BUFMGR_H_*/
199