pb_buffer_fenced.h revision 7c12e1aa53ba457d29edf4c07d834c70d51f0bbd
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 fencing.
31 *
32 * "Fenced buffers" is actually a misnomer. They should be referred as
33 * "fenceable buffers", i.e, buffers that can be fenced, but I couldn't find
34 * the word "fenceable" in the dictionary.
35 *
36 * A "fenced buffer" is a decorator around a normal buffer, which adds two
37 * special properties:
38 * - the ability for the destruction to be delayed by a fence;
39 * - reference counting.
40 *
41 * Usually DMA buffers have a life-time that will extend the life-time of its
42 * handle. The end-of-life is dictated by the fence signalling.
43 *
44 * Between the handle's destruction, and the fence signalling, the buffer is
45 * stored in a fenced buffer list.
46 *
47 * \author José Fonseca <jrfonseca@tungstengraphics.com>
48 */
49
50#ifndef PB_BUFFER_FENCED_H_
51#define PB_BUFFER_FENCED_H_
52
53
54#include "pipe/p_debug.h"
55
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61
62struct pipe_winsys;
63struct pipe_buffer;
64struct pipe_fence_handle;
65
66
67/**
68 * List of buffers which are awaiting fence signalling.
69 */
70struct fenced_buffer_list;
71
72
73/**
74 * The fenced buffer's virtual function table.
75 *
76 * NOTE: Made public for debugging purposes.
77 */
78extern const struct pb_vtbl fenced_buffer_vtbl;
79
80
81/**
82 * Create a fenced buffer list.
83 *
84 * See also fenced_bufmgr_create for a more convenient way to use this.
85 */
86struct fenced_buffer_list *
87fenced_buffer_list_create(struct pipe_winsys *winsys);
88
89
90/**
91 * Walk the fenced buffer list to check and free signalled buffers.
92 */
93void
94fenced_buffer_list_check_free(struct fenced_buffer_list *fenced_list,
95                              int wait);
96
97
98#ifdef DEBUG
99void
100fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list);
101#endif
102
103
104void
105fenced_buffer_list_destroy(struct fenced_buffer_list *fenced_list);
106
107
108/**
109 * Wrap a buffer in a fenced buffer.
110 *
111 * NOTE: this will not increase the buffer reference count.
112 */
113struct pb_buffer *
114fenced_buffer_create(struct fenced_buffer_list *fenced,
115                     struct pb_buffer *buffer);
116
117
118/**
119 * Set a buffer's fence.
120 *
121 * NOTE: Although it takes a generic pb_buffer argument, it will fail
122 * on everything but buffers returned by fenced_buffer_create.
123 */
124void
125buffer_fence(struct pb_buffer *buf,
126             struct pipe_fence_handle *fence);
127
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /*PB_BUFFER_FENCED_H_*/
134