Lines Matching refs:cs
30 tu_cs_init(struct tu_cs *cs, in tu_cs_init() argument
37 memset(cs, 0, sizeof(*cs)); in tu_cs_init()
39 cs->device = device; in tu_cs_init()
40 cs->mode = mode; in tu_cs_init()
41 cs->next_bo_size = initial_size; in tu_cs_init()
48 tu_cs_init_external(struct tu_cs *cs, uint32_t *start, uint32_t *end) in tu_cs_init_external() argument
50 memset(cs, 0, sizeof(*cs)); in tu_cs_init_external()
52 cs->mode = TU_CS_MODE_EXTERNAL; in tu_cs_init_external()
53 cs->start = cs->reserved_end = cs->cur = start; in tu_cs_init_external()
54 cs->end = end; in tu_cs_init_external()
61 tu_cs_finish(struct tu_cs *cs) in tu_cs_finish() argument
63 for (uint32_t i = 0; i < cs->bo_count; ++i) { in tu_cs_finish()
64 tu_bo_finish(cs->device, cs->bos[i]); in tu_cs_finish()
65 free(cs->bos[i]); in tu_cs_finish()
68 free(cs->entries); in tu_cs_finish()
69 free(cs->bos); in tu_cs_finish()
77 tu_cs_get_offset(const struct tu_cs *cs) in tu_cs_get_offset() argument
79 assert(cs->bo_count); in tu_cs_get_offset()
80 return cs->start - (uint32_t *) cs->bos[cs->bo_count - 1]->map; in tu_cs_get_offset()
88 tu_cs_add_bo(struct tu_cs *cs, uint32_t size) in tu_cs_add_bo() argument
91 assert(cs->mode != TU_CS_MODE_EXTERNAL); in tu_cs_add_bo()
94 assert(tu_cs_is_empty(cs)); in tu_cs_add_bo()
97 if (cs->bo_count == cs->bo_capacity) { in tu_cs_add_bo()
98 uint32_t new_capacity = MAX2(4, 2 * cs->bo_capacity); in tu_cs_add_bo()
100 realloc(cs->bos, new_capacity * sizeof(struct tu_bo *)); in tu_cs_add_bo()
104 cs->bo_capacity = new_capacity; in tu_cs_add_bo()
105 cs->bos = new_bos; in tu_cs_add_bo()
113 tu_bo_init_new(cs->device, new_bo, size * sizeof(uint32_t), true); in tu_cs_add_bo()
119 result = tu_bo_map(cs->device, new_bo); in tu_cs_add_bo()
121 tu_bo_finish(cs->device, new_bo); in tu_cs_add_bo()
126 cs->bos[cs->bo_count++] = new_bo; in tu_cs_add_bo()
128 cs->start = cs->cur = cs->reserved_end = (uint32_t *) new_bo->map; in tu_cs_add_bo()
129 cs->end = cs->start + new_bo->size / sizeof(uint32_t); in tu_cs_add_bo()
138 tu_cs_reserve_entry(struct tu_cs *cs) in tu_cs_reserve_entry() argument
141 assert(cs->mode == TU_CS_MODE_GROW); in tu_cs_reserve_entry()
144 if (cs->entry_count == cs->entry_capacity) { in tu_cs_reserve_entry()
145 uint32_t new_capacity = MAX2(4, cs->entry_capacity * 2); in tu_cs_reserve_entry()
147 realloc(cs->entries, new_capacity * sizeof(struct tu_cs_entry)); in tu_cs_reserve_entry()
151 cs->entry_capacity = new_capacity; in tu_cs_reserve_entry()
152 cs->entries = new_entries; in tu_cs_reserve_entry()
163 tu_cs_add_entry(struct tu_cs *cs) in tu_cs_add_entry() argument
166 assert(cs->mode == TU_CS_MODE_GROW); in tu_cs_add_entry()
169 assert(!tu_cs_is_empty(cs)); in tu_cs_add_entry()
175 assert(cs->bo_count); in tu_cs_add_entry()
176 assert(cs->entry_count < cs->entry_capacity); in tu_cs_add_entry()
179 cs->entries[cs->entry_count++] = (struct tu_cs_entry) { in tu_cs_add_entry()
180 .bo = cs->bos[cs->bo_count - 1], in tu_cs_add_entry()
181 .size = tu_cs_get_size(cs) * sizeof(uint32_t), in tu_cs_add_entry()
182 .offset = tu_cs_get_offset(cs) * sizeof(uint32_t), in tu_cs_add_entry()
185 cs->start = cs->cur; in tu_cs_add_entry()
192 tu_cs_add_entries(struct tu_cs *cs, struct tu_cs *target) in tu_cs_add_entries() argument
196 assert(cs->mode == TU_CS_MODE_GROW); in tu_cs_add_entries()
199 if (!tu_cs_is_empty(cs)) in tu_cs_add_entries()
200 tu_cs_add_entry(cs); in tu_cs_add_entries()
203 result = tu_cs_reserve_entry(cs); in tu_cs_add_entries()
206 cs->entries[cs->entry_count++] = target->entries[i]; in tu_cs_add_entries()
217 tu_cs_begin(struct tu_cs *cs) in tu_cs_begin() argument
219 assert(cs->mode != TU_CS_MODE_SUB_STREAM); in tu_cs_begin()
220 assert(tu_cs_is_empty(cs)); in tu_cs_begin()
228 tu_cs_end(struct tu_cs *cs) in tu_cs_end() argument
230 assert(cs->mode != TU_CS_MODE_SUB_STREAM); in tu_cs_end()
232 if (cs->mode == TU_CS_MODE_GROW && !tu_cs_is_empty(cs)) in tu_cs_end()
233 tu_cs_add_entry(cs); in tu_cs_end()
245 tu_cs_begin_sub_stream(struct tu_cs *cs, uint32_t size, struct tu_cs *sub_cs) in tu_cs_begin_sub_stream() argument
247 assert(cs->mode == TU_CS_MODE_SUB_STREAM); in tu_cs_begin_sub_stream()
250 VkResult result = tu_cs_reserve_space(cs, size); in tu_cs_begin_sub_stream()
254 tu_cs_init_external(sub_cs, cs->cur, cs->reserved_end); in tu_cs_begin_sub_stream()
268 tu_cs_alloc(struct tu_cs *cs, in tu_cs_alloc() argument
273 assert(cs->mode == TU_CS_MODE_SUB_STREAM); in tu_cs_alloc()
281 VkResult result = tu_cs_reserve_space(cs, count * size + (size-1)); in tu_cs_alloc()
285 struct tu_bo *bo = cs->bos[cs->bo_count - 1]; in tu_cs_alloc()
286 size_t offset = align(tu_cs_get_offset(cs), size); in tu_cs_alloc()
291 cs->start = cs->cur = (uint32_t*) bo->map + offset + count * size; in tu_cs_alloc()
304 tu_cs_end_sub_stream(struct tu_cs *cs, struct tu_cs *sub_cs) in tu_cs_end_sub_stream() argument
306 assert(cs->mode == TU_CS_MODE_SUB_STREAM); in tu_cs_end_sub_stream()
307 assert(cs->bo_count); in tu_cs_end_sub_stream()
308 assert(sub_cs->start == cs->cur && sub_cs->end == cs->reserved_end); in tu_cs_end_sub_stream()
313 cs->cur = sub_cs->cur; in tu_cs_end_sub_stream()
316 .bo = cs->bos[cs->bo_count - 1], in tu_cs_end_sub_stream()
317 .size = tu_cs_get_size(cs) * sizeof(uint32_t), in tu_cs_end_sub_stream()
318 .offset = tu_cs_get_offset(cs) * sizeof(uint32_t), in tu_cs_end_sub_stream()
321 cs->start = cs->cur; in tu_cs_end_sub_stream()
331 tu_cs_reserve_space(struct tu_cs *cs, uint32_t reserved_size) in tu_cs_reserve_space() argument
333 if (tu_cs_get_space(cs) < reserved_size) { in tu_cs_reserve_space()
334 if (cs->mode == TU_CS_MODE_EXTERNAL) { in tu_cs_reserve_space()
340 if (!tu_cs_is_empty(cs)) { in tu_cs_reserve_space()
342 assert(cs->mode != TU_CS_MODE_SUB_STREAM); in tu_cs_reserve_space()
344 tu_cs_add_entry(cs); in tu_cs_reserve_space()
347 if (cs->cond_flags) { in tu_cs_reserve_space()
349 *cs->cond_dwords = cs->cur - cs->cond_dwords - 1; in tu_cs_reserve_space()
356 uint32_t new_size = MAX2(cs->next_bo_size, reserved_size); in tu_cs_reserve_space()
357 VkResult result = tu_cs_add_bo(cs, new_size); in tu_cs_reserve_space()
362 if (cs->cond_flags) { in tu_cs_reserve_space()
363 cs->reserved_end = cs->cur + reserved_size; in tu_cs_reserve_space()
365 tu_cs_emit_pkt7(cs, CP_COND_REG_EXEC, 2); in tu_cs_reserve_space()
366 tu_cs_emit(cs, cs->cond_flags); in tu_cs_reserve_space()
368 cs->cond_dwords = cs->cur; in tu_cs_reserve_space()
371 tu_cs_emit(cs, CP_COND_REG_EXEC_1_DWORDS(0)); in tu_cs_reserve_space()
376 if (cs->next_bo_size < new_size) in tu_cs_reserve_space()
377 cs->next_bo_size = new_size; in tu_cs_reserve_space()
380 assert(tu_cs_get_space(cs) >= reserved_size); in tu_cs_reserve_space()
381 cs->reserved_end = cs->cur + reserved_size; in tu_cs_reserve_space()
383 if (cs->mode == TU_CS_MODE_GROW) { in tu_cs_reserve_space()
385 return tu_cs_reserve_entry(cs); in tu_cs_reserve_space()
396 tu_cs_reset(struct tu_cs *cs) in tu_cs_reset() argument
398 if (cs->mode == TU_CS_MODE_EXTERNAL) { in tu_cs_reset()
399 assert(!cs->bo_count && !cs->entry_count); in tu_cs_reset()
400 cs->reserved_end = cs->cur = cs->start; in tu_cs_reset()
404 for (uint32_t i = 0; i + 1 < cs->bo_count; ++i) { in tu_cs_reset()
405 tu_bo_finish(cs->device, cs->bos[i]); in tu_cs_reset()
406 free(cs->bos[i]); in tu_cs_reset()
409 if (cs->bo_count) { in tu_cs_reset()
410 cs->bos[0] = cs->bos[cs->bo_count - 1]; in tu_cs_reset()
411 cs->bo_count = 1; in tu_cs_reset()
413 cs->start = cs->cur = cs->reserved_end = (uint32_t *) cs->bos[0]->map; in tu_cs_reset()
414 cs->end = cs->start + cs->bos[0]->size / sizeof(uint32_t); in tu_cs_reset()
417 cs->entry_count = 0; in tu_cs_reset()