1 /*
2 * © Copyright 2017-2018 Alyssa Rosenzweig
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 */
24
25 #ifndef __PANVK_POOL_H__
26 #define __PANVK_POOL_H__
27
28 #include "pan_pool.h"
29
30 struct panvk_priv_bo;
31
32 struct panvk_bo_pool {
33 struct util_dynarray free_bos;
34 };
35
36 static inline void
panvk_bo_pool_init(struct panvk_bo_pool * bo_pool)37 panvk_bo_pool_init(struct panvk_bo_pool *bo_pool)
38 {
39 util_dynarray_init(&bo_pool->free_bos, NULL);
40 }
41
42 void panvk_bo_pool_cleanup(struct panvk_bo_pool *bo_pool);
43
44 /* Represents grow-only memory. It may be owned by the batch (OpenGL), or may
45 be unowned for persistent uploads. */
46
47 struct panvk_pool {
48 /* Inherit from pan_pool */
49 struct pan_pool base;
50
51 /* Parent device for allocation */
52 struct panvk_device *dev;
53
54 /* Label for created BOs */
55 const char *label;
56
57 /* BO flags to use in the pool */
58 unsigned create_flags;
59
60 /* Before allocating a new BO, check if the BO pool has free BOs.
61 * When returning BOs, if bo_pool != NULL, return them to this bo_pool.
62 */
63 struct panvk_bo_pool *bo_pool;
64
65 /* BOs allocated by this pool */
66 struct util_dynarray bos;
67 struct util_dynarray big_bos;
68
69 /* Current transient BO */
70 struct panvk_priv_bo *transient_bo;
71
72 /* Within the topmost transient BO, how much has been used? */
73 unsigned transient_offset;
74 };
75
76 static inline struct panvk_pool *
to_panvk_pool(struct pan_pool * pool)77 to_panvk_pool(struct pan_pool *pool)
78 {
79 return container_of(pool, struct panvk_pool, base);
80 }
81
82 void panvk_pool_init(struct panvk_pool *pool, struct panvk_device *dev,
83 struct panvk_bo_pool *bo_pool, unsigned create_flags,
84 size_t slab_size, const char *label, bool prealloc);
85
86 void panvk_pool_reset(struct panvk_pool *pool);
87
88 void panvk_pool_cleanup(struct panvk_pool *pool);
89
90 static inline unsigned
panvk_pool_num_bos(struct panvk_pool * pool)91 panvk_pool_num_bos(struct panvk_pool *pool)
92 {
93 return util_dynarray_num_elements(&pool->bos, struct panvk_priv_bo *);
94 }
95
96 void panvk_pool_get_bo_handles(struct panvk_pool *pool, uint32_t *handles);
97
98 #endif
99