Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /* |
2 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
3 | * copy of this software and associated documentation files (the "Software"), |
||
4 | * to deal in the Software without restriction, including without limitation |
||
5 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
||
6 | * license, and/or sell copies of the Software, and to permit persons to whom |
||
7 | * the Software is furnished to do so, subject to the following conditions: |
||
8 | * |
||
9 | * The above copyright notice and this permission notice (including the next |
||
10 | * paragraph) shall be included in all copies or substantial portions of the |
||
11 | * Software. |
||
12 | * |
||
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
15 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
16 | * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
||
17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
||
18 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
||
19 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
20 | * |
||
21 | * Authors: |
||
22 | * Adam Rak |
||
23 | */ |
||
24 | |||
25 | #ifndef COMPUTE_MEMORY_POOL |
||
26 | #define COMPUTE_MEMORY_POOL |
||
27 | |||
28 | #include |
||
29 | |||
30 | #define ITEM_MAPPED_FOR_READING (1<<0) |
||
31 | #define ITEM_MAPPED_FOR_WRITING (1<<1) |
||
32 | #define ITEM_FOR_PROMOTING (1<<2) |
||
33 | #define ITEM_FOR_DEMOTING (1<<3) |
||
34 | |||
35 | #define POOL_FRAGMENTED (1<<0) |
||
36 | |||
37 | struct compute_memory_pool; |
||
38 | |||
39 | struct compute_memory_item |
||
40 | { |
||
41 | int64_t id; /**< ID of the memory chunk */ |
||
42 | |||
43 | uint32_t status; /**< Will track the status of the item */ |
||
44 | |||
45 | /** Start pointer in dwords relative in the pool bo. If an item |
||
46 | * is unallocated, then this value must be -1 to indicate this. */ |
||
47 | int64_t start_in_dw; |
||
48 | int64_t size_in_dw; /**< Size of the chunk in dwords */ |
||
49 | |||
50 | /** Intermediate buffer asociated with an item. It is used mainly for mapping |
||
51 | * items against it. They are listed in the pool's unallocated list */ |
||
52 | struct r600_resource *real_buffer; |
||
53 | |||
54 | struct compute_memory_pool* pool; |
||
55 | |||
56 | struct list_head link; |
||
57 | }; |
||
58 | |||
59 | struct compute_memory_pool |
||
60 | { |
||
61 | int64_t next_id; /**< For generating unique IDs for memory chunks */ |
||
62 | int64_t size_in_dw; /**< Size of the pool in dwords */ |
||
63 | |||
64 | struct r600_resource *bo; /**< The pool buffer object resource */ |
||
65 | struct r600_screen *screen; |
||
66 | |||
67 | uint32_t *shadow; /**< host copy of the pool, used for growing the pool */ |
||
68 | |||
69 | uint32_t status; /**< Status of the pool */ |
||
70 | |||
71 | /** Allocated memory items in the pool, they must be ordered by "start_in_dw" */ |
||
72 | struct list_head *item_list; |
||
73 | |||
74 | /** Unallocated memory items, this list contains all the items that aren't |
||
75 | * yet in the pool */ |
||
76 | struct list_head *unallocated_list; |
||
77 | }; |
||
78 | |||
79 | |||
80 | static inline int is_item_in_pool(struct compute_memory_item *item) |
||
81 | { |
||
82 | return item->start_in_dw != -1; |
||
83 | } |
||
84 | |||
85 | struct compute_memory_pool* compute_memory_pool_new(struct r600_screen *rscreen); |
||
86 | |||
87 | void compute_memory_pool_delete(struct compute_memory_pool* pool); |
||
88 | |||
89 | int64_t compute_memory_prealloc_chunk(struct compute_memory_pool* pool, |
||
90 | int64_t size_in_dw); |
||
91 | |||
92 | struct list_head *compute_memory_postalloc_chunk(struct compute_memory_pool* pool, |
||
93 | int64_t start_in_dw); |
||
94 | |||
95 | int compute_memory_grow_defrag_pool(struct compute_memory_pool* pool, |
||
96 | struct pipe_context *pipe, int new_size_in_dw); |
||
97 | |||
98 | void compute_memory_shadow(struct compute_memory_pool* pool, |
||
99 | struct pipe_context *pipe, int device_to_host); |
||
100 | |||
101 | int compute_memory_finalize_pending(struct compute_memory_pool* pool, |
||
102 | struct pipe_context * pipe); |
||
103 | |||
104 | void compute_memory_defrag(struct compute_memory_pool *pool, |
||
105 | struct pipe_resource *src, struct pipe_resource *dst, |
||
106 | struct pipe_context *pipe); |
||
107 | |||
108 | int compute_memory_promote_item(struct compute_memory_pool *pool, |
||
109 | struct compute_memory_item *item, struct pipe_context *pipe, |
||
110 | int64_t allocated); |
||
111 | |||
112 | void compute_memory_demote_item(struct compute_memory_pool *pool, |
||
113 | struct compute_memory_item *item, struct pipe_context *pipe); |
||
114 | |||
115 | void compute_memory_move_item(struct compute_memory_pool *pool, |
||
116 | struct pipe_resource *src, struct pipe_resource *dst, |
||
117 | struct compute_memory_item *item, uint64_t new_start_in_dw, |
||
118 | struct pipe_context *pipe); |
||
119 | |||
120 | void compute_memory_free(struct compute_memory_pool* pool, int64_t id); |
||
121 | |||
122 | struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* pool, |
||
123 | int64_t size_in_dw); |
||
124 | |||
125 | void compute_memory_transfer(struct compute_memory_pool* pool, |
||
126 | struct pipe_context * pipe, int device_to_host, |
||
127 | struct compute_memory_item* chunk, void* data, |
||
128 | int offset_in_chunk, int size); |
||
129 | |||
130 | void compute_memory_transfer_direct(struct compute_memory_pool* pool, |
||
131 | int chunk_to_data, struct compute_memory_item* chunk, |
||
132 | struct r600_resource* data, int offset_in_chunk, |
||
133 | int offset_in_data, int size); |
||
134 | |||
135 | #endif>>>>>>>>0) |