meson: inline `inc_common`
[mesa.git] / src / gallium / drivers / virgl / virgl_staging_mgr.h
1 /*
2 * Copyright 2009 VMware, Inc.
3 * Copyright 2019 Collabora Ltd.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /* virgl staging buffer manager, heavily inspired by u_upload_mgr. */
26
27 #ifndef VIRGL_STAGING_MGR_H
28 #define VIRGL_STAGING_MGR_H
29
30 struct pipe_context;
31 struct virgl_hw_res;
32 struct virgl_winsys;
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 struct virgl_staging_mgr {
39 struct virgl_winsys *vws;
40 unsigned default_size; /* Minimum size of the staging buffer, in bytes. */
41 struct virgl_hw_res *hw_res; /* Staging buffer hw_res. */
42 unsigned size; /* Current staging buffer size. */
43 uint8_t *map; /* Pointer to the mapped staging buffer. */
44 unsigned offset; /* Offset pointing at the first unused buffer byte. */
45 };
46
47 /**
48 * Init the staging manager.
49 *
50 * \param staging Pointer to the staging manager to initialize.
51 * \param pipe Pipe driver.
52 * \param default_size Minimum size of the staging buffer, in bytes.
53 */
54 void
55 virgl_staging_init(struct virgl_staging_mgr *staging, struct pipe_context *pipe,
56 unsigned default_size);
57
58 /**
59 * Destroy the staging manager.
60 */
61 void
62 virgl_staging_destroy(struct virgl_staging_mgr *staging);
63
64 /**
65 * Sub-allocate new memory from the staging buffer.
66 *
67 * The returned pointer to the buffer references the internal staging buffer.
68 *
69 * The returned pointer to staging buffer memory is guaranteed to be valid
70 * for as long as the returned buffer is still referenced.
71 *
72 * \param staging Staging manager
73 * \param size Size of the allocation.
74 * \param alignment Alignment of the suballocation within the buffer.
75 * \param out_offset Pointer to where the new buffer offset will be returned.
76 * \param outbuf Pointer to where the staging buffer will be returned.
77 * \param ptr Pointer to the allocated memory that is returned.
78 * \return Whether the allocation is successful.
79 */
80 bool
81 virgl_staging_alloc(struct virgl_staging_mgr *staging,
82 unsigned size,
83 unsigned alignment,
84 unsigned *out_offset,
85 struct virgl_hw_res **outbuf,
86 void **ptr);
87
88 #ifdef __cplusplus
89 } // extern "C" {
90 #endif
91
92 #endif