* Initialize a command stream.
*/
void
-tu_cs_init(struct tu_cs *cs, enum tu_cs_mode mode, uint32_t initial_size)
+tu_cs_init(struct tu_cs *cs,
+ struct tu_device *device,
+ enum tu_cs_mode mode,
+ uint32_t initial_size)
{
assert(mode != TU_CS_MODE_EXTERNAL);
memset(cs, 0, sizeof(*cs));
+ cs->device = device;
cs->mode = mode;
cs->next_bo_size = initial_size;
}
* Finish and release all resources owned by a command stream.
*/
void
-tu_cs_finish(struct tu_device *dev, struct tu_cs *cs)
+tu_cs_finish(struct tu_cs *cs)
{
for (uint32_t i = 0; i < cs->bo_count; ++i) {
- tu_bo_finish(dev, cs->bos[i]);
+ tu_bo_finish(cs->device, cs->bos[i]);
free(cs->bos[i]);
}
return cs->start - (uint32_t *) cs->bos[cs->bo_count - 1]->map;
}
-/**
- * Get the size of the command packets emitted since the last call to
- * tu_cs_add_entry.
- */
-static uint32_t
-tu_cs_get_size(const struct tu_cs *cs)
-{
- return cs->cur - cs->start;
-}
-
-/**
- * Get the size of the remaining space in the current BO.
- */
-static uint32_t
-tu_cs_get_space(const struct tu_cs *cs)
-{
- return cs->end - cs->cur;
-}
-
-/**
- * Return true if there is no command packet emitted since the last call to
- * tu_cs_add_entry.
- */
-static uint32_t
-tu_cs_is_empty(const struct tu_cs *cs)
-{
- return tu_cs_get_size(cs) == 0;
-}
-
/*
* Allocate and add a BO to a command stream. Following command packets will
* be emitted to the new BO.
*/
static VkResult
-tu_cs_add_bo(struct tu_device *dev, struct tu_cs *cs, uint32_t size)
+tu_cs_add_bo(struct tu_cs *cs, uint32_t size)
{
/* no BO for TU_CS_MODE_EXTERNAL */
assert(cs->mode != TU_CS_MODE_EXTERNAL);
if (!new_bo)
return VK_ERROR_OUT_OF_HOST_MEMORY;
- VkResult result = tu_bo_init_new(dev, new_bo, size * sizeof(uint32_t));
+ VkResult result =
+ tu_bo_init_new(cs->device, new_bo, size * sizeof(uint32_t));
if (result != VK_SUCCESS) {
free(new_bo);
return result;
}
- result = tu_bo_map(dev, new_bo);
+ result = tu_bo_map(cs->device, new_bo);
if (result != VK_SUCCESS) {
- tu_bo_finish(dev, new_bo);
+ tu_bo_finish(cs->device, new_bo);
free(new_bo);
return result;
}
assert(cs->mode == TU_CS_MODE_GROW);
assert(target->mode == TU_CS_MODE_GROW);
- if (!tu_cs_is_empty(cs)) {
+ if (!tu_cs_is_empty(cs))
tu_cs_add_entry(cs);
- result = tu_cs_reserve_entry(cs);
- if (result != VK_SUCCESS)
- return result;
- }
for (unsigned i = 0; i < target->entry_count; i++) {
- cs->entries[cs->entry_count++] = target->entries[i];
result = tu_cs_reserve_entry(cs);
if (result != VK_SUCCESS)
return result;
+ cs->entries[cs->entry_count++] = target->entries[i];
}
return VK_SUCCESS;
* emission.
*/
VkResult
-tu_cs_begin_sub_stream(struct tu_device *dev,
- struct tu_cs *cs,
- uint32_t size,
- struct tu_cs *sub_cs)
+tu_cs_begin_sub_stream(struct tu_cs *cs, uint32_t size, struct tu_cs *sub_cs)
{
assert(cs->mode == TU_CS_MODE_SUB_STREAM);
assert(size);
- VkResult result = tu_cs_reserve_space(dev, cs, size);
+ VkResult result = tu_cs_reserve_space(cs, size);
if (result != VK_SUCCESS)
return result;
tu_cs_init_external(sub_cs, cs->cur, cs->reserved_end);
tu_cs_begin(sub_cs);
- result = tu_cs_reserve_space(dev, sub_cs, size);
+ result = tu_cs_reserve_space(sub_cs, size);
assert(result == VK_SUCCESS);
return VK_SUCCESS;
*
*/
VkResult
-tu_cs_alloc(struct tu_device *dev,
- struct tu_cs *cs,
+tu_cs_alloc(struct tu_cs *cs,
uint32_t count,
uint32_t size,
- struct ts_cs_memory *memory)
+ struct tu_cs_memory *memory)
{
assert(cs->mode == TU_CS_MODE_SUB_STREAM);
assert(size && size <= 1024);
/* TODO: smarter way to deal with alignment? */
- VkResult result = tu_cs_reserve_space(dev, cs, count * size + (size-1));
+ VkResult result = tu_cs_reserve_space(cs, count * size + (size-1));
if (result != VK_SUCCESS)
return result;
* This never fails when \a cs has mode TU_CS_MODE_EXTERNAL.
*/
VkResult
-tu_cs_reserve_space(struct tu_device *dev,
- struct tu_cs *cs,
- uint32_t reserved_size)
+tu_cs_reserve_space(struct tu_cs *cs, uint32_t reserved_size)
{
if (tu_cs_get_space(cs) < reserved_size) {
if (cs->mode == TU_CS_MODE_EXTERNAL) {
tu_cs_add_entry(cs);
}
+ if (cs->cond_flags) {
+ /* Subtract one here to account for the DWORD field itself. */
+ *cs->cond_dwords = cs->cur - cs->cond_dwords - 1;
+
+ /* space for CP_COND_REG_EXEC in next bo */
+ reserved_size += 3;
+ }
+
/* switch to a new BO */
uint32_t new_size = MAX2(cs->next_bo_size, reserved_size);
- VkResult result = tu_cs_add_bo(dev, cs, new_size);
+ VkResult result = tu_cs_add_bo(cs, new_size);
if (result != VK_SUCCESS)
return result;
+ /* if inside a condition, emit a new CP_COND_REG_EXEC */
+ if (cs->cond_flags) {
+ cs->reserved_end = cs->cur + reserved_size;
+
+ tu_cs_emit_pkt7(cs, CP_COND_REG_EXEC, 2);
+ tu_cs_emit(cs, cs->cond_flags);
+
+ cs->cond_dwords = cs->cur;
+
+ /* Emit dummy DWORD field here */
+ tu_cs_emit(cs, CP_COND_REG_EXEC_1_DWORDS(0));
+ }
+
/* double the size for the next bo */
new_size <<= 1;
if (cs->next_bo_size < new_size)
* packets in \a cs, but does not necessarily release all resources.
*/
void
-tu_cs_reset(struct tu_device *dev, struct tu_cs *cs)
+tu_cs_reset(struct tu_cs *cs)
{
if (cs->mode == TU_CS_MODE_EXTERNAL) {
assert(!cs->bo_count && !cs->entry_count);
}
for (uint32_t i = 0; i + 1 < cs->bo_count; ++i) {
- tu_bo_finish(dev, cs->bos[i]);
+ tu_bo_finish(cs->device, cs->bos[i]);
free(cs->bos[i]);
}