xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r600/compute_memory_pool.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Authors:
3  *      Adam Rak <[email protected]>
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #ifndef COMPUTE_MEMORY_POOL
8 #define COMPUTE_MEMORY_POOL
9 
10 #include <stdlib.h>
11 
12 #define ITEM_MAPPED_FOR_READING (1<<0)
13 #define ITEM_MAPPED_FOR_WRITING (1<<1)
14 #define ITEM_FOR_PROMOTING      (1<<2)
15 #define ITEM_FOR_DEMOTING       (1<<3)
16 
17 #define POOL_FRAGMENTED (1<<0)
18 
19 struct compute_memory_pool;
20 
21 struct compute_memory_item
22 {
23 	int64_t id;		/**< ID of the memory chunk */
24 
25 	uint32_t status;	/**< Will track the status of the item */
26 
27 	/** Start pointer in dwords relative in the pool bo. If an item
28 	 * is unallocated, then this value must be -1 to indicate this. */
29 	int64_t start_in_dw;
30 	int64_t size_in_dw;	/**< Size of the chunk in dwords */
31 
32 	/** Intermediate buffer associated with an item. It is used mainly for mapping
33 	 * items against it. They are listed in the pool's unallocated list */
34 	struct r600_resource *real_buffer;
35 
36 	struct compute_memory_pool* pool;
37 
38 	struct list_head link;
39 };
40 
41 struct compute_memory_pool
42 {
43 	int64_t next_id;	/**< For generating unique IDs for memory chunks */
44 	int64_t size_in_dw;	/**< Size of the pool in dwords */
45 
46 	struct r600_resource *bo;	/**< The pool buffer object resource */
47 	struct r600_screen *screen;
48 
49 	uint32_t *shadow;	/**< host copy of the pool, used for growing the pool */
50 
51 	uint32_t status;	/**< Status of the pool */
52 
53 	/** Allocated memory items in the pool, they must be ordered by "start_in_dw" */
54 	struct list_head *item_list;
55 
56 	/** Unallocated memory items, this list contains all the items that aren't
57 	 * yet in the pool */
58 	struct list_head *unallocated_list;
59 };
60 
61 
is_item_in_pool(struct compute_memory_item * item)62 static inline int is_item_in_pool(struct compute_memory_item *item)
63 {
64 	return item->start_in_dw != -1;
65 }
66 
is_item_user_ptr(struct compute_memory_item * item)67 static inline int is_item_user_ptr(struct compute_memory_item *item)
68 {
69 	assert(item->real_buffer);
70 	return item->real_buffer->b.is_user_ptr;
71 }
72 
73 struct compute_memory_pool* compute_memory_pool_new(struct r600_screen *rscreen);
74 
75 void compute_memory_pool_delete(struct compute_memory_pool* pool);
76 
77 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
78 	struct pipe_context * pipe);
79 
80 void compute_memory_demote_item(struct compute_memory_pool *pool,
81 	struct compute_memory_item *item, struct pipe_context *pipe);
82 
83 void compute_memory_free(struct compute_memory_pool* pool, int64_t id);
84 
85 struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* pool,
86 	int64_t size_in_dw);
87 
88 #endif
89