Path: blob/21.2-virgl/src/gallium/frontends/nine/nine_memory_helper.h
4561 views
/*1* Copyright 2020 Axel Davy <[email protected]>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. */2122#ifndef _NINE_MEMORY_HELPER_H_23#define _NINE_MEMORY_HELPER_H_242526struct NineDevice9;2728struct nine_allocator;29struct nine_allocation;3031/* Note: None of these functions are thread safe, thus the worker thread is disallowed32* to call any of them. Only exception is nine_free_worker reserved for it. */3334struct nine_allocation *35nine_allocate(struct nine_allocator *allocator, unsigned size);3637/* Note: Suballocations MUST be freed before their parent */38void nine_free(struct nine_allocator *allocator, struct nine_allocation *allocation);39void nine_free_worker(struct nine_allocator *allocator, struct nine_allocation *allocation);4041void *nine_get_pointer(struct nine_allocator *allocator, struct nine_allocation *allocation);4243/* We don't need the pointer anymore, but we are likely to need it again soon */44void nine_pointer_weakrelease(struct nine_allocator *allocator, struct nine_allocation *allocation);4546/* We don't need the pointer anymore, probably for a long time */47void nine_pointer_strongrelease(struct nine_allocator *allocator, struct nine_allocation *allocation);4849/* You can strong release when counter becomes 0.50* Once a counter is used for a given allocation, the same must keep being used */51void nine_pointer_delayedstrongrelease(struct nine_allocator *allocator,52struct nine_allocation *allocation,53unsigned *counter);5455/* Note: It is disallowed to release a suballocation before its parent.56* It is disallowed to suballocate on a suballocation. */57struct nine_allocation *58nine_suballocate(struct nine_allocator* allocator, struct nine_allocation *allocation, int offset);5960/* Won't be freed - but at least we can use the same interface */61struct nine_allocation *62nine_wrap_external_pointer(struct nine_allocator* allocator, void* data);636465/* memfd_virtualsizelimit: Limit for the virtual memory usage (in MB)66* above which memfd files are unmapped (to reduce virtual memory usage).67* If negative, disables memfd usage. */68struct nine_allocator *69nine_allocator_create(struct NineDevice9 *device, int memfd_virtualsizelimit);7071void72nine_allocator_destroy(struct nine_allocator *allocator);7374#endif /* _NINE_MEMORY_HELPER_H_ */757677