Path: blob/21.2-virgl/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h
4565 views
/**************************************************************************1*2* Copyright 2007 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* \file29* Buffer management.30*31* A buffer manager does only one basic thing: it creates buffers. Actually,32* "buffer factory" would probably a more accurate description.33*34* You can chain buffer managers so that you can have a finer grained memory35* management.36*37* For example, for a simple batch buffer manager you would chain:38* - the native buffer manager, which provides DMA memory from the graphics39* memory space;40* - the fenced buffer manager, which will delay buffer destruction until the41* the moment the card finishing processing it.42*43* \author Jose Fonseca <[email protected]>44*/4546#ifndef PB_BUFMGR_H_47#define PB_BUFMGR_H_484950#include "pb_buffer.h"515253#ifdef __cplusplus54extern "C" {55#endif565758struct pb_desc;596061/**62* Abstract base class for all buffer managers.63*/64struct pb_manager65{66void67(*destroy)( struct pb_manager *mgr );6869struct pb_buffer *70(*create_buffer)( struct pb_manager *mgr,71pb_size size,72const struct pb_desc *desc);7374/**75* Flush all temporary-held buffers.76*77* Used mostly to aid debugging memory issues or to clean up resources when78* the drivers are long lived.79*/80void81(*flush)( struct pb_manager *mgr );8283boolean84(*is_buffer_busy)( struct pb_manager *mgr,85struct pb_buffer *buf );86};8788/**89* Static sub-allocator based the old memory manager.90*91* It managers buffers of different sizes. It does so by allocating a buffer92* with the size of the heap, and then using the old mm memory manager to manage93* that heap.94*/95struct pb_manager *96mm_bufmgr_create(struct pb_manager *provider,97pb_size size, pb_size align2);9899/**100* Same as mm_bufmgr_create.101*102* Buffer will be release when the manager is destroyed.103*/104struct pb_manager *105mm_bufmgr_create_from_buffer(struct pb_buffer *buffer,106pb_size size, pb_size align2);107108109/**110* Slab sub-allocator.111*/112struct pb_manager *113pb_slab_manager_create(struct pb_manager *provider,114pb_size bufSize,115pb_size slabSize,116const struct pb_desc *desc);117118/**119* Allow a range of buffer size, by aggregating multiple slabs sub-allocators120* with different bucket sizes.121*/122struct pb_manager *123pb_slab_range_manager_create(struct pb_manager *provider,124pb_size minBufSize,125pb_size maxBufSize,126pb_size slabSize,127const struct pb_desc *desc);128129130/**131* Time-based buffer cache.132*133* This manager keeps a cache of destroyed buffers during a time interval.134*/135struct pb_manager *136pb_cache_manager_create(struct pb_manager *provider,137unsigned usecs,138float size_factor,139unsigned bypass_usage,140uint64_t maximum_cache_size);141142/**143* Remove a buffer from the cache, but keep it alive.144*/145void146pb_cache_manager_remove_buffer(struct pb_buffer *buf);147148struct pb_fence_ops;149150/**151* Fenced buffer manager.152*153* This manager is just meant for convenience. It wraps the buffers returned154* by another manager in fenced buffers, so that155*156* NOTE: the buffer manager that provides the buffers will be destroyed157* at the same time.158*/159struct pb_manager *160fenced_bufmgr_create(struct pb_manager *provider,161struct pb_fence_ops *ops,162pb_size max_buffer_size,163pb_size max_cpu_total_size);164165/**166* Debug buffer manager to detect buffer under- and overflows.167*168* Under/overflow sizes should be a multiple of the largest alignment169*/170struct pb_manager *171pb_debug_manager_create(struct pb_manager *provider,172pb_size underflow_size, pb_size overflow_size);173174175#ifdef __cplusplus176}177#endif178179#endif /*PB_BUFMGR_H_*/180181182