pb_bufmgr.h revision a75a3df851339c782e045e01c2b21ffadb1e09f5
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 <stddef.h>
54
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60
61struct pb_desc;
62struct pipe_buffer;
63struct pipe_winsys;
64
65
66/**
67 * Abstract base class for all buffer managers.
68 */
69struct pb_manager
70{
71   /* XXX: we will likely need more allocation flags */
72   struct pb_buffer *
73   (*create_buffer)( struct pb_manager *mgr,
74	             size_t size,
75	             const struct pb_desc *desc);
76
77   void
78   (*destroy)( struct pb_manager *mgr );
79};
80
81
82/**
83 * Static buffer pool sub-allocator.
84 *
85 * Manages the allocation of equally sized buffers. It does so by allocating
86 * a single big buffer and divide it equally sized buffers.
87 *
88 * It is meant to manage the allocation of batch buffer pools.
89 */
90struct pb_manager *
91pool_bufmgr_create(struct pb_manager *provider,
92                   size_t n, size_t size,
93                   const struct pb_desc *desc);
94
95
96/**
97 * Static sub-allocator based the old memory manager.
98 *
99 * It managers buffers of different sizes. It does so by allocating a buffer
100 * with the size of the heap, and then using the old mm memory manager to manage
101 * that heap.
102 */
103struct pb_manager *
104mm_bufmgr_create(struct pb_manager *provider,
105                 size_t size, size_t align2);
106
107/**
108 * Same as mm_bufmgr_create.
109 *
110 * Buffer will be release when the manager is destroyed.
111 */
112struct pb_manager *
113mm_bufmgr_create_from_buffer(struct pb_buffer *buffer,
114                             size_t size, size_t align2);
115
116
117/**
118 * Slab sub-allocator.
119 */
120struct pb_manager *
121pb_slab_manager_create(struct pb_manager *provider,
122                       size_t bufSize,
123                       size_t slabSize,
124                       const struct pb_desc *desc);
125
126/**
127 * Allow a range of buffer size, by aggregating multiple slabs sub-allocators
128 * with different bucket sizes.
129 */
130struct pb_manager *
131pb_slab_range_manager_create(struct pb_manager *provider,
132                             size_t minBufSize,
133                             size_t maxBufSize,
134                             size_t slabSize,
135                             const struct pb_desc *desc);
136
137
138/**
139 * Time-based buffer cache.
140 *
141 * This manager keeps a cache of destroyed buffers during a time interval.
142 */
143struct pb_manager *
144pb_cache_manager_create(struct pb_manager *provider,
145                     	unsigned usecs);
146
147void
148pb_cache_flush(struct pb_manager *mgr);
149
150
151/**
152 * Fenced buffer manager.
153 *
154 * This manager is just meant for convenience. It wraps the buffers returned
155 * by another manager in fenced buffers, so that
156 *
157 * NOTE: the buffer manager that provides the buffers will be destroyed
158 * at the same time.
159 */
160struct pb_manager *
161fenced_bufmgr_create(struct pb_manager *provider,
162                     struct pipe_winsys *winsys);
163
164
165#ifdef __cplusplus
166}
167#endif
168
169#endif /*PB_BUFMGR_H_*/
170