Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/vulkan/panvk_mempool.h
4560 views
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_bo_pool {
31
struct util_dynarray free_bos;
32
};
33
34
static inline void panvk_bo_pool_init(struct panvk_bo_pool *bo_pool)
35
{
36
util_dynarray_init(&bo_pool->free_bos, NULL);
37
}
38
39
static inline void panvk_bo_pool_cleanup(struct panvk_bo_pool *bo_pool)
40
{
41
util_dynarray_foreach(&bo_pool->free_bos, struct panfrost_bo *, bo)
42
panfrost_bo_unreference(*bo);
43
util_dynarray_fini(&bo_pool->free_bos);
44
}
45
46
/* Represents grow-only memory. It may be owned by the batch (OpenGL), or may
47
be unowned for persistent uploads. */
48
49
struct panvk_pool {
50
/* Inherit from pan_pool */
51
struct pan_pool base;
52
53
/* Before allocating a new BO, check if the BO pool has free BOs.
54
* When returning BOs, if bo_pool != NULL, return them to this bo_pool.
55
*/
56
struct panvk_bo_pool *bo_pool;
57
58
/* BOs allocated by this pool */
59
struct util_dynarray bos;
60
61
/* Current transient BO */
62
struct panfrost_bo *transient_bo;
63
64
/* Within the topmost transient BO, how much has been used? */
65
unsigned transient_offset;
66
};
67
68
static inline struct panvk_pool *
69
to_panvk_pool(struct pan_pool *pool)
70
{
71
return container_of(pool, struct panvk_pool, base);
72
}
73
74
void
75
panvk_pool_init(struct panvk_pool *pool, struct panfrost_device *dev,
76
struct panvk_bo_pool *bo_pool, unsigned create_flags,
77
size_t slab_size, const char *label, bool prealloc);
78
79
void
80
panvk_pool_reset(struct panvk_pool *pool);
81
82
void
83
panvk_pool_cleanup(struct panvk_pool *pool);
84
85
static inline unsigned
86
panvk_pool_num_bos(struct panvk_pool *pool)
87
{
88
return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *);
89
}
90
91
void
92
panvk_pool_get_bo_handles(struct panvk_pool *pool, uint32_t *handles);
93
94
#endif
95
96