2 * Copyright 2009 VMware, Inc.
3 * Copyright 2019 Collabora Ltd.
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:
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
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.
25 /* virgl staging buffer manager, heavily inspired by u_upload_mgr. */
27 #ifndef VIRGL_STAGING_MGR_H
28 #define VIRGL_STAGING_MGR_H
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. */
48 * Init the staging manager.
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.
55 virgl_staging_init(struct virgl_staging_mgr
*staging
, struct pipe_context
*pipe
,
56 unsigned default_size
);
59 * Destroy the staging manager.
62 virgl_staging_destroy(struct virgl_staging_mgr
*staging
);
65 * Sub-allocate new memory from the staging buffer.
67 * The returned pointer to the buffer references the internal staging buffer.
69 * The returned pointer to staging buffer memory is guaranteed to be valid
70 * for as long as the returned buffer is still referenced.
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.
81 virgl_staging_alloc(struct virgl_staging_mgr
*staging
,
85 struct virgl_hw_res
**outbuf
,