Path: blob/21.2-virgl/src/gallium/drivers/panfrost/pan_mempool.h
4570 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 __PAN_MEMPOOL_H__25#define __PAN_MEMPOOL_H__2627#include "pan_pool.h"2829/* Represents grow-only memory. It may be owned by the batch (OpenGL), or may30be unowned for persistent uploads. */3132struct panfrost_pool {33/* Inherit from pan_pool */34struct pan_pool base;3536/* BOs allocated by this pool */37struct util_dynarray bos;3839/* Current transient BO */40struct panfrost_bo *transient_bo;4142/* Within the topmost transient BO, how much has been used? */43unsigned transient_offset;4445/* Mode of the pool. BO management is in the pool for owned mode, but46* the consumed for unowned mode. */47bool owned;48};4950static inline struct panfrost_pool *51to_panfrost_pool(struct pan_pool *pool)52{53return container_of(pool, struct panfrost_pool, base);54}5556/* Reference to pool allocated memory for an unowned pool */5758struct panfrost_pool_ref {59/* Owning BO */60struct panfrost_bo *bo;6162/* Mapped GPU VA */63mali_ptr gpu;64};6566/* Take a reference to an allocation pool. Call directly after allocating from67* an unowned pool for correct operation. */6869static inline struct panfrost_pool_ref70panfrost_pool_take_ref(struct panfrost_pool *pool, mali_ptr ptr)71{72if (!pool->owned)73panfrost_bo_reference(pool->transient_bo);7475return (struct panfrost_pool_ref) {76.bo = pool->transient_bo,77.gpu = ptr78};79}8081void82panfrost_pool_init(struct panfrost_pool *pool, void *memctx,83struct panfrost_device *dev, unsigned create_flags,84size_t slab_size, const char *label, bool prealloc, bool85owned);8687void88panfrost_pool_cleanup(struct panfrost_pool *pool);8990static inline unsigned91panfrost_pool_num_bos(struct panfrost_pool *pool)92{93assert(pool->owned && "pool does not track BOs in unowned mode");94return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *);95}9697void98panfrost_pool_get_bo_handles(struct panfrost_pool *pool, uint32_t *handles);99100#endif101102103