Path: blob/21.2-virgl/src/gallium/winsys/virgl/common/virgl_resource_cache.h
4573 views
/*1* Copyright 2019 Collabora Ltd.2*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* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the 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 NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#ifndef VIRGL_RESOURCE_CACHE_H24#define VIRGL_RESOURCE_CACHE_H2526#include <stdint.h>2728#include "util/list.h"2930struct virgl_resource_cache_entry {31struct list_head head;32int64_t timeout_start;33int64_t timeout_end;34uint32_t size;35uint32_t bind;36uint32_t format;37uint32_t flags;38};3940/* Pointer to a function that returns whether the resource represented by41* the specified cache entry is busy.42*/43typedef bool (*virgl_resource_cache_entry_is_busy_func) (44struct virgl_resource_cache_entry *entry, void *user_data);4546/* Pointer to a function that destroys the resource represented by47* the specified cache entry.48*/49typedef void (*virgl_resource_cache_entry_release_func) (50struct virgl_resource_cache_entry *entry, void *user_data);5152struct virgl_resource_cache {53struct list_head resources;54unsigned timeout_usecs;55virgl_resource_cache_entry_is_busy_func entry_is_busy_func;56virgl_resource_cache_entry_release_func entry_release_func;57void *user_data;58};5960void61virgl_resource_cache_init(struct virgl_resource_cache *cache,62unsigned timeout_usecs,63virgl_resource_cache_entry_is_busy_func is_busy_func,64virgl_resource_cache_entry_release_func destroy_func,65void *user_data);6667/** Adds a resource to the cache.68*69* Adding a resource that's already present in the cache leads to undefined70* behavior.71*/72void73virgl_resource_cache_add(struct virgl_resource_cache *cache,74struct virgl_resource_cache_entry *entry);7576/** Finds and removes a cached resource compatible with size, bind and format.77*78* Returns a pointer to the cache entry of the compatible resource, or NULL if79* no such resource was found.80*/81struct virgl_resource_cache_entry *82virgl_resource_cache_remove_compatible(struct virgl_resource_cache *cache,83uint32_t size, uint32_t bind,84uint32_t format, uint32_t flags);8586/** Empties the resource cache. */87void88virgl_resource_cache_flush(struct virgl_resource_cache *cache);8990static inline void91virgl_resource_cache_entry_init(struct virgl_resource_cache_entry *entry,92uint32_t size, uint32_t bind,93uint32_t format, uint32_t flags)94{95entry->size = size;96entry->bind = bind;97entry->format = format;98entry->flags = flags;99}100101#endif102103104