Path: blob/21.2-virgl/src/panfrost/vulkan/panvk_mempool.h
4560 views
/*1* © Copyright 2017-2018 Alyssa Rosenzweig2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22*/2324#ifndef __PANVK_POOL_H__25#define __PANVK_POOL_H__2627#include "pan_pool.h"2829struct panvk_bo_pool {30struct util_dynarray free_bos;31};3233static inline void panvk_bo_pool_init(struct panvk_bo_pool *bo_pool)34{35util_dynarray_init(&bo_pool->free_bos, NULL);36}3738static inline void panvk_bo_pool_cleanup(struct panvk_bo_pool *bo_pool)39{40util_dynarray_foreach(&bo_pool->free_bos, struct panfrost_bo *, bo)41panfrost_bo_unreference(*bo);42util_dynarray_fini(&bo_pool->free_bos);43}4445/* Represents grow-only memory. It may be owned by the batch (OpenGL), or may46be unowned for persistent uploads. */4748struct panvk_pool {49/* Inherit from pan_pool */50struct pan_pool base;5152/* Before allocating a new BO, check if the BO pool has free BOs.53* When returning BOs, if bo_pool != NULL, return them to this bo_pool.54*/55struct panvk_bo_pool *bo_pool;5657/* BOs allocated by this pool */58struct util_dynarray bos;5960/* Current transient BO */61struct panfrost_bo *transient_bo;6263/* Within the topmost transient BO, how much has been used? */64unsigned transient_offset;65};6667static inline struct panvk_pool *68to_panvk_pool(struct pan_pool *pool)69{70return container_of(pool, struct panvk_pool, base);71}7273void74panvk_pool_init(struct panvk_pool *pool, struct panfrost_device *dev,75struct panvk_bo_pool *bo_pool, unsigned create_flags,76size_t slab_size, const char *label, bool prealloc);7778void79panvk_pool_reset(struct panvk_pool *pool);8081void82panvk_pool_cleanup(struct panvk_pool *pool);8384static inline unsigned85panvk_pool_num_bos(struct panvk_pool *pool)86{87return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *);88}8990void91panvk_pool_get_bo_handles(struct panvk_pool *pool, uint32_t *handles);9293#endif949596