Merge commit 'origin/gallium-0.1' into gallium-0.1
[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 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 struct pb_desc;
57 struct pipe_buffer;
58 struct pipe_winsys;
59
60
61 /**
62 * Abstract base class for all buffer managers.
63 */
64 struct pb_manager
65 {
66 /* XXX: we will likely need more allocation flags */
67 struct pb_buffer *
68 (*create_buffer)( struct pb_manager *mgr,
69 size_t size,
70 const struct pb_desc *desc);
71
72 void
73 (*destroy)( struct pb_manager *mgr );
74 };
75
76
77 /**
78 * Static buffer pool manager.
79 *
80 * Manages the allocation of equally sized buffers. It does so by allocating
81 * a single big buffer and divide it equally sized buffers.
82 *
83 * It is meant to manage the allocation of batch buffer pools.
84 */
85 struct pb_manager *
86 pool_bufmgr_create(struct pb_manager *provider,
87 size_t n, size_t size,
88 const struct pb_desc *desc);
89
90
91 /**
92 * Wraper around the old memory manager.
93 *
94 * It managers buffers of different sizes. It does so by allocating a buffer
95 * with the size of the heap, and then using the old mm memory manager to manage
96 * that heap.
97 */
98 struct pb_manager *
99 mm_bufmgr_create(struct pb_manager *provider,
100 size_t size, size_t align2);
101
102 /**
103 * Same as mm_bufmgr_create.
104 *
105 * Buffer will be release when the manager is destroyed.
106 */
107 struct pb_manager *
108 mm_bufmgr_create_from_buffer(struct pb_buffer *buffer,
109 size_t size, size_t align2);
110
111
112 /**
113 * Fenced buffer manager.
114 *
115 * This manager is just meant for convenience. It wraps the buffers returned
116 * by another manager in fenced buffers, so that
117 *
118 * NOTE: the buffer manager that provides the buffers will be destroyed
119 * at the same time.
120 */
121 struct pb_manager *
122 fenced_bufmgr_create(struct pb_manager *provider,
123 struct pipe_winsys *winsys);
124
125
126 #endif /*PB_BUFMGR_H_*/