6aac54b7f42922e13df917781a2006e0f666e36c
1 /**************************************************************************
3 * Copyright © 2007 Intel Corporation
4 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
28 **************************************************************************/
30 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
31 * Keith Whitwell <keithw-at-tungstengraphics-dot-com>
32 * Eric Anholt <eric@anholt.net>
35 #ifndef _DRI_BUFMGR_H_
36 #define _DRI_BUFMGR_H_
39 typedef struct _dri_bufmgr dri_bufmgr
;
40 typedef struct _dri_bo dri_bo
;
41 typedef struct _dri_fence dri_fence
;
44 /** Size in bytes of the buffer object. */
47 * Card virtual address (offset from the beginning of the aperture) for the
48 * object. Only valid while validated.
52 * Virtual address for accessing the buffer data. Only valid while mapped.
55 /** Buffer manager context associated with this buffer object */
61 * This is an ORed mask of DRM_BO_FLAG_READ, DRM_BO_FLAG_WRITE, and
62 * DRM_FLAG_EXE indicating the operations associated with this fence.
64 * It is constant for the life of the fence object.
67 /** Buffer manager context associated with this fence */
72 * Context for a buffer manager instance.
74 * Contains public methods followed by private storage for the buffer manager.
78 * Allocate a buffer object.
80 * Buffer objects are not necessarily initially mapped into CPU virtual
81 * address space or graphics device aperture. They must be mapped using
82 * bo_map() to be used by the CPU, and validated for use using bo_validate()
83 * to be used from the graphics device.
85 dri_bo
*(*bo_alloc
)(dri_bufmgr
*bufmgr_ctx
, const char *name
,
86 unsigned long size
, unsigned int alignment
,
87 unsigned int location_mask
);
90 * Allocates a buffer object for a static allocation.
92 * Static allocations are ones such as the front buffer that are offered by
93 * the X Server, which are never evicted and never moved.
95 dri_bo
*(*bo_alloc_static
)(dri_bufmgr
*bufmgr_ctx
, const char *name
,
96 unsigned long offset
, unsigned long size
,
97 void *virtual, unsigned int location_mask
);
99 /** Takes a reference on a buffer object */
100 void (*bo_reference
)(dri_bo
*bo
);
103 * Releases a reference on a buffer object, freeing the data if
106 void (*bo_unreference
)(dri_bo
*bo
);
109 * Maps the buffer into userspace.
111 * This function will block waiting for any existing fence on the buffer to
112 * clear, first. The resulting mapping is available at buf->virtual.
114 int (*bo_map
)(dri_bo
*buf
, GLboolean write_enable
);
116 /** Reduces the refcount on the userspace mapping of the buffer object. */
117 int (*bo_unmap
)(dri_bo
*buf
);
120 * Makes the buffer accessible to the graphics chip.
122 * The resulting offset of the buffer within the graphics aperture is then
123 * available at buf->offset until the buffer is fenced.
125 * Flags should consist of the memory types that the buffer may be validated
126 * into and the read/write/exe flags appropriate to the use of the buffer.
128 int (*bo_validate
)(dri_bo
*buf
, unsigned int flags
);
131 * Associates the current set of validated buffers with a fence.
133 * Once fenced, the buffer manager will allow the validated buffers to be
134 * evicted when the graphics device's execution has passed the fence
137 * The fence object will have flags for the sum of the read/write/exe flags
138 * of the validated buffers associated with it.
140 dri_fence
* (*fence_validated
)(dri_bufmgr
*bufmgr
, const char *name
,
143 /** Takes a reference on a fence object */
144 void (*fence_reference
)(dri_fence
*fence
);
147 * Releases a reference on a fence object, freeing the data if
150 void (*fence_unreference
)(dri_fence
*fence
);
153 * Blocks until the given fence is signaled.
155 void (*fence_wait
)(dri_fence
*fence
);
158 * Checks and returns whether the given fence is signaled.
162 dri_bo
*dri_bo_alloc(dri_bufmgr
*bufmgr
, const char *name
, unsigned long size
,
163 unsigned int alignment
, unsigned int location_mask
);
164 dri_bo
*dri_bo_alloc_static(dri_bufmgr
*bufmgr
, const char *name
,
165 unsigned long offset
, unsigned long size
,
166 void *virtual, unsigned int location_mask
);
167 void dri_bo_reference(dri_bo
*bo
);
168 void dri_bo_unreference(dri_bo
*bo
);
169 int dri_bo_map(dri_bo
*buf
, GLboolean write_enable
);
170 int dri_bo_unmap(dri_bo
*buf
);
171 int dri_bo_validate(dri_bo
*buf
, unsigned int flags
);
172 dri_fence
*dri_fence_validated(dri_bufmgr
*bufmgr
, const char *name
,
174 void dri_fence_wait(dri_fence
*fence
);
175 void dri_fence_reference(dri_fence
*fence
);
176 void dri_fence_unreference(dri_fence
*fence
);
178 void dri_bo_subdata(dri_bo
*bo
, unsigned long offset
,
179 unsigned long size
, const void *data
);
180 void dri_bo_get_subdata(dri_bo
*bo
, unsigned long offset
,
181 unsigned long size
, void *data
);
183 dri_bufmgr
*dri_bufmgr_ttm_init(int fd
, unsigned int fence_type
,
184 unsigned int fence_type_flush
);
186 void dri_bufmgr_fake_contended_lock_take(dri_bufmgr
*bufmgr
);
187 dri_bufmgr
*dri_bufmgr_fake_init(unsigned long low_offset
, void *low_virtual
,
189 unsigned int (*fence_emit
)(void *private),
190 int (*fence_wait
)(void *private,
191 unsigned int cookie
),
193 void dri_bufmgr_fake_contended_lock_take(dri_bufmgr
*bufmgr
);