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 30struct panvk_bo_pool { 31 struct util_dynarray free_bos; 32}; 33 34static inline void panvk_bo_pool_init(struct panvk_bo_pool *bo_pool) 35{ 36 util_dynarray_init(&bo_pool->free_bos, NULL); 37} 38 39static 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 49struct 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 struct util_dynarray big_bos; 61 62 /* Current transient BO */ 63 struct panfrost_bo *transient_bo; 64 65 /* Within the topmost transient BO, how much has been used? */ 66 unsigned transient_offset; 67}; 68 69static inline struct panvk_pool * 70to_panvk_pool(struct pan_pool *pool) 71{ 72 return container_of(pool, struct panvk_pool, base); 73} 74 75void 76panvk_pool_init(struct panvk_pool *pool, struct panfrost_device *dev, 77 struct panvk_bo_pool *bo_pool, unsigned create_flags, 78 size_t slab_size, const char *label, bool prealloc); 79 80void 81panvk_pool_reset(struct panvk_pool *pool); 82 83void 84panvk_pool_cleanup(struct panvk_pool *pool); 85 86static inline unsigned 87panvk_pool_num_bos(struct panvk_pool *pool) 88{ 89 return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *); 90} 91 92void 93panvk_pool_get_bo_handles(struct panvk_pool *pool, uint32_t *handles); 94 95#endif 96