Path: blob/21.2-virgl/src/gallium/drivers/r600/compute_memory_pool.h
4570 views
/*1* Permission is hereby granted, free of charge, to any person obtaining a2* copy of this software and associated documentation files (the "Software"),3* to deal in the Software without restriction, including without limitation4* on the rights to use, copy, modify, merge, publish, distribute, sub5* license, and/or sell copies of the Software, and to permit persons to whom6* the Software is furnished to do so, subject to the following conditions:7*8* The above copyright notice and this permission notice (including the next9* paragraph) shall be included in all copies or substantial portions of the10* Software.11*12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL15* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,16* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR17* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE18* USE OR OTHER DEALINGS IN THE SOFTWARE.19*20* Authors:21* Adam Rak <[email protected]>22*/2324#ifndef COMPUTE_MEMORY_POOL25#define COMPUTE_MEMORY_POOL2627#include <stdlib.h>2829#define ITEM_MAPPED_FOR_READING (1<<0)30#define ITEM_MAPPED_FOR_WRITING (1<<1)31#define ITEM_FOR_PROMOTING (1<<2)32#define ITEM_FOR_DEMOTING (1<<3)3334#define POOL_FRAGMENTED (1<<0)3536struct compute_memory_pool;3738struct compute_memory_item39{40int64_t id; /**< ID of the memory chunk */4142uint32_t status; /**< Will track the status of the item */4344/** Start pointer in dwords relative in the pool bo. If an item45* is unallocated, then this value must be -1 to indicate this. */46int64_t start_in_dw;47int64_t size_in_dw; /**< Size of the chunk in dwords */4849/** Intermediate buffer associated with an item. It is used mainly for mapping50* items against it. They are listed in the pool's unallocated list */51struct r600_resource *real_buffer;5253struct compute_memory_pool* pool;5455struct list_head link;56};5758struct compute_memory_pool59{60int64_t next_id; /**< For generating unique IDs for memory chunks */61int64_t size_in_dw; /**< Size of the pool in dwords */6263struct r600_resource *bo; /**< The pool buffer object resource */64struct r600_screen *screen;6566uint32_t *shadow; /**< host copy of the pool, used for growing the pool */6768uint32_t status; /**< Status of the pool */6970/** Allocated memory items in the pool, they must be ordered by "start_in_dw" */71struct list_head *item_list;7273/** Unallocated memory items, this list contains all the items that aren't74* yet in the pool */75struct list_head *unallocated_list;76};777879static inline int is_item_in_pool(struct compute_memory_item *item)80{81return item->start_in_dw != -1;82}8384struct compute_memory_pool* compute_memory_pool_new(struct r600_screen *rscreen);8586void compute_memory_pool_delete(struct compute_memory_pool* pool);8788int compute_memory_finalize_pending(struct compute_memory_pool* pool,89struct pipe_context * pipe);9091void compute_memory_demote_item(struct compute_memory_pool *pool,92struct compute_memory_item *item, struct pipe_context *pipe);9394void compute_memory_free(struct compute_memory_pool* pool, int64_t id);9596struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* pool,97int64_t size_in_dw);9899#endif100101102