Path: blob/21.2-virgl/src/gallium/auxiliary/pipebuffer/pb_cache.h
4565 views
/**************************************************************************1*2* Copyright 2007-2008 VMware, Inc.3* Copyright 2015 Advanced Micro Devices, Inc.4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the8* "Software"), to deal in the Software without restriction, including9* without limitation the rights to use, copy, modify, merge, publish,10* distribute, sub license, and/or sell copies of the Software, and to11* permit persons to whom the Software is furnished to do so, subject to12* the following conditions:13*14* The above copyright notice and this permission notice (including the15* next paragraph) shall be included in all copies or substantial portions16* of the Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS19* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF20* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.21* IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR22* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,23* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE24* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.25*26**************************************************************************/2728#ifndef PB_CACHE_H29#define PB_CACHE_H3031#include "pb_buffer.h"32#include "util/list.h"33#include "os/os_thread.h"3435/**36* Statically inserted into the driver-specific buffer structure.37*/38struct pb_cache_entry39{40struct list_head head;41struct pb_buffer *buffer; /**< Pointer to the structure this is part of. */42struct pb_cache *mgr;43int64_t start, end; /**< Caching time interval */44unsigned bucket_index;45};4647struct pb_cache48{49/* The cache is divided into buckets for minimizing cache misses.50* The driver controls which buffer goes into which bucket.51*/52struct list_head *buckets;5354mtx_t mutex;55void *winsys;56uint64_t cache_size;57uint64_t max_cache_size;58unsigned num_heaps;59unsigned usecs;60unsigned num_buffers;61unsigned bypass_usage;62float size_factor;6364void (*destroy_buffer)(void *winsys, struct pb_buffer *buf);65bool (*can_reclaim)(void *winsys, struct pb_buffer *buf);66};6768void pb_cache_add_buffer(struct pb_cache_entry *entry);69struct pb_buffer *pb_cache_reclaim_buffer(struct pb_cache *mgr, pb_size size,70unsigned alignment, unsigned usage,71unsigned bucket_index);72void pb_cache_release_all_buffers(struct pb_cache *mgr);73void pb_cache_init_entry(struct pb_cache *mgr, struct pb_cache_entry *entry,74struct pb_buffer *buf, unsigned bucket_index);75void pb_cache_init(struct pb_cache *mgr, uint num_heaps,76uint usecs, float size_factor,77unsigned bypass_usage, uint64_t maximum_cache_size,78void *winsys,79void (*destroy_buffer)(void *winsys, struct pb_buffer *buf),80bool (*can_reclaim)(void *winsys, struct pb_buffer *buf));81void pb_cache_deinit(struct pb_cache *mgr);8283#endif848586