turnip: add tu_device pointer to tu_cs
authorJonathan Marek <jonathan@marek.ca>
Mon, 24 Feb 2020 13:57:00 +0000 (08:57 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 24 Feb 2020 21:52:45 +0000 (21:52 +0000)
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3925>

src/freedreno/vulkan/tu_blit.c
src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_cs.c
src/freedreno/vulkan/tu_cs.h
src/freedreno/vulkan/tu_meta_buffer.c
src/freedreno/vulkan/tu_pipeline.c
src/freedreno/vulkan/tu_private.h
src/freedreno/vulkan/tu_query.c

index b71effb62ed11dcb7397adbf33cf4bcbb03186c0..73b04b4b0a03233dd8fc148f96cfcabf192d708d 100644 (file)
@@ -84,7 +84,7 @@ emit_blit_step(struct tu_cmd_buffer *cmdbuf, struct tu_cs *cs,
 {
    struct tu_physical_device *phys_dev = cmdbuf->device->physical_device;
 
-   tu_cs_reserve_space(cmdbuf->device, cs, 66);
+   tu_cs_reserve_space(cs, 66);
 
    enum a6xx_format fmt = tu6_get_native_format(blt->dst.fmt)->rb;
    if (fmt == FMT6_Z24_UNORM_S8_UINT)
@@ -280,7 +280,7 @@ void tu_blit(struct tu_cmd_buffer *cmdbuf, struct tu_cs *cs,
       assert(blt->dst.samples == 1);
    }
 
-   tu_cs_reserve_space(cmdbuf->device, cs, 18);
+   tu_cs_reserve_space(cs, 18);
 
    tu6_emit_event_write(cmdbuf, cs, LRZ_FLUSH, false);
    tu6_emit_event_write(cmdbuf, cs, PC_CCU_FLUSH_COLOR_TS, true);
@@ -365,7 +365,7 @@ void tu_blit(struct tu_cmd_buffer *cmdbuf, struct tu_cs *cs,
       blt->src.ubwc_va += blt->src.ubwc_size;
    }
 
-   tu_cs_reserve_space(cmdbuf->device, cs, 17);
+   tu_cs_reserve_space(cs, 17);
 
    tu6_emit_event_write(cmdbuf, cs, PC_CCU_FLUSH_COLOR_TS, true);
    tu6_emit_event_write(cmdbuf, cs, PC_CCU_FLUSH_DEPTH_TS, true);
index 1528bab0035ee10ec50455d0a9b5d05aea418f0f..9403f37b12d901c2a5f2f4781dd922de0fd80cac 100644 (file)
@@ -1061,7 +1061,7 @@ tu6_emit_restart_index(struct tu_cs *cs, uint32_t restart_index)
 static void
 tu6_init_hw(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 {
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, 256);
+   VkResult result = tu_cs_reserve_space(cs, 256);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1486,12 +1486,12 @@ tu_cmd_prepare_sysmem_clear_ib(struct tu_cmd_buffer *cmd,
    const struct tu_framebuffer *fb = cmd->state.framebuffer;
    const uint32_t blit_cmd_space = 25 + 66 * fb->layers + 17;
    const uint32_t clear_space =
-       blit_cmd_space * cmd->state.pass->attachment_count + 5;
+      blit_cmd_space * cmd->state.pass->attachment_count + 5;
 
    struct tu_cs sub_cs;
 
-   VkResult result = tu_cs_begin_sub_stream(cmd->device, &cmd->sub_cs,
-                                            clear_space, &sub_cs);
+   VkResult result =
+      tu_cs_begin_sub_stream(&cmd->sub_cs, clear_space, &sub_cs);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1503,7 +1503,7 @@ tu_cmd_prepare_sysmem_clear_ib(struct tu_cmd_buffer *cmd,
    /* TODO: We shouldn't need this flush, but without it we'd have an empty IB
     * when nothing clears which we currently can't handle.
     */
-   tu_cs_reserve_space(cmd->device, &sub_cs, 5);
+   tu_cs_reserve_space(&sub_cs, 5);
    tu6_emit_event_write(cmd, &sub_cs, PC_CCU_FLUSH_COLOR_TS, true);
 
    cmd->state.sysmem_clear_ib = tu_cs_end_sub_stream(&cmd->sub_cs, &sub_cs);
@@ -1513,7 +1513,7 @@ static void
 tu6_sysmem_render_begin(struct tu_cmd_buffer *cmd, struct tu_cs *cs,
                         const struct VkRect2D *renderArea)
 {
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, 1024);
+   VkResult result = tu_cs_reserve_space(cs, 1024);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1582,7 +1582,7 @@ tu6_sysmem_render_end(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
    }
 
    const uint32_t space = 14 + tu_cs_get_call_size(&cmd->draw_epilogue_cs);
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, space);
+   VkResult result = tu_cs_reserve_space(cs, space);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1607,7 +1607,7 @@ tu6_tile_render_begin(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 {
    struct tu_physical_device *phys_dev = cmd->device->physical_device;
 
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, 1024);
+   VkResult result = tu_cs_reserve_space(cs, 1024);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1668,7 +1668,7 @@ tu6_render_tile(struct tu_cmd_buffer *cmd,
                 const struct tu_tile *tile)
 {
    const uint32_t render_tile_space = 256 + tu_cs_get_call_size(&cmd->draw_cs);
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, render_tile_space);
+   VkResult result = tu_cs_reserve_space(cs, render_tile_space);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1705,7 +1705,7 @@ static void
 tu6_tile_render_end(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 {
    const uint32_t space = 16 + tu_cs_get_call_size(&cmd->draw_epilogue_cs);
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, space);
+   VkResult result = tu_cs_reserve_space(cs, space);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1749,7 +1749,7 @@ tu_cmd_render_sysmem(struct tu_cmd_buffer *cmd)
    tu6_sysmem_render_begin(cmd, &cmd->cs, &tiling->render_area);
 
    const uint32_t space = tu_cs_get_call_size(&cmd->draw_cs);
-   VkResult result = tu_cs_reserve_space(cmd->device, &cmd->cs, space);
+   VkResult result = tu_cs_reserve_space(&cmd->cs, space);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1772,8 +1772,8 @@ tu_cmd_prepare_tile_load_ib(struct tu_cmd_buffer *cmd,
 
    struct tu_cs sub_cs;
 
-   VkResult result = tu_cs_begin_sub_stream(cmd->device, &cmd->sub_cs,
-                                            tile_load_space, &sub_cs);
+   VkResult result =
+      tu_cs_begin_sub_stream(&cmd->sub_cs, tile_load_space, &sub_cs);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -1805,8 +1805,8 @@ tu_cmd_prepare_tile_store_ib(struct tu_cmd_buffer *cmd)
    const uint32_t tile_store_space = 32 + 23 * cmd->state.pass->attachment_count;
    struct tu_cs sub_cs;
 
-   VkResult result = tu_cs_begin_sub_stream(cmd->device, &cmd->sub_cs,
-                                            tile_store_space, &sub_cs);
+   VkResult result =
+      tu_cs_begin_sub_stream(&cmd->sub_cs, tile_store_space, &sub_cs);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -2004,10 +2004,10 @@ tu_create_cmd_buffer(struct tu_device *device,
    }
 
    tu_bo_list_init(&cmd_buffer->bo_list);
-   tu_cs_init(&cmd_buffer->cs, TU_CS_MODE_GROW, 4096);
-   tu_cs_init(&cmd_buffer->draw_cs, TU_CS_MODE_GROW, 4096);
-   tu_cs_init(&cmd_buffer->draw_epilogue_cs, TU_CS_MODE_GROW, 4096);
-   tu_cs_init(&cmd_buffer->sub_cs, TU_CS_MODE_SUB_STREAM, 2048);
+   tu_cs_init(&cmd_buffer->cs, device, TU_CS_MODE_GROW, 4096);
+   tu_cs_init(&cmd_buffer->draw_cs, device, TU_CS_MODE_GROW, 4096);
+   tu_cs_init(&cmd_buffer->draw_epilogue_cs, device, TU_CS_MODE_GROW, 4096);
+   tu_cs_init(&cmd_buffer->sub_cs, device, TU_CS_MODE_SUB_STREAM, 2048);
 
    *pCommandBuffer = tu_cmd_buffer_to_handle(cmd_buffer);
 
@@ -2043,10 +2043,10 @@ tu_cmd_buffer_destroy(struct tu_cmd_buffer *cmd_buffer)
    for (unsigned i = 0; i < VK_PIPELINE_BIND_POINT_RANGE_SIZE; i++)
       free(cmd_buffer->descriptors[i].push_set.set.mapped_ptr);
 
-   tu_cs_finish(cmd_buffer->device, &cmd_buffer->cs);
-   tu_cs_finish(cmd_buffer->device, &cmd_buffer->draw_cs);
-   tu_cs_finish(cmd_buffer->device, &cmd_buffer->draw_epilogue_cs);
-   tu_cs_finish(cmd_buffer->device, &cmd_buffer->sub_cs);
+   tu_cs_finish(&cmd_buffer->cs);
+   tu_cs_finish(&cmd_buffer->draw_cs);
+   tu_cs_finish(&cmd_buffer->draw_epilogue_cs);
+   tu_cs_finish(&cmd_buffer->sub_cs);
 
    tu_bo_list_destroy(&cmd_buffer->bo_list);
    vk_free(&cmd_buffer->pool->alloc, cmd_buffer);
@@ -2060,10 +2060,10 @@ tu_reset_cmd_buffer(struct tu_cmd_buffer *cmd_buffer)
    cmd_buffer->record_result = VK_SUCCESS;
 
    tu_bo_list_reset(&cmd_buffer->bo_list);
-   tu_cs_reset(cmd_buffer->device, &cmd_buffer->cs);
-   tu_cs_reset(cmd_buffer->device, &cmd_buffer->draw_cs);
-   tu_cs_reset(cmd_buffer->device, &cmd_buffer->draw_epilogue_cs);
-   tu_cs_reset(cmd_buffer->device, &cmd_buffer->sub_cs);
+   tu_cs_reset(&cmd_buffer->cs);
+   tu_cs_reset(&cmd_buffer->draw_cs);
+   tu_cs_reset(&cmd_buffer->draw_epilogue_cs);
+   tu_cs_reset(&cmd_buffer->sub_cs);
 
    for (unsigned i = 0; i < VK_PIPELINE_BIND_POINT_RANGE_SIZE; i++) {
       cmd_buffer->descriptors[i].valid = 0;
@@ -2236,7 +2236,7 @@ tu_CmdBindIndexBuffer(VkCommandBuffer commandBuffer,
    /* initialize/update the restart index */
    if (!cmd->state.index_buffer || cmd->state.index_type != indexType) {
       struct tu_cs *draw_cs = &cmd->draw_cs;
-      VkResult result = tu_cs_reserve_space(cmd->device, draw_cs, 2);
+      VkResult result = tu_cs_reserve_space(draw_cs, 2);
       if (result != VK_SUCCESS) {
          cmd->record_result = result;
          return;
@@ -2386,7 +2386,7 @@ tu_CmdSetViewport(VkCommandBuffer commandBuffer,
    TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
    struct tu_cs *draw_cs = &cmd->draw_cs;
 
-   VkResult result = tu_cs_reserve_space(cmd->device, draw_cs, 12);
+   VkResult result = tu_cs_reserve_space(draw_cs, 12);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -2407,7 +2407,7 @@ tu_CmdSetScissor(VkCommandBuffer commandBuffer,
    TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
    struct tu_cs *draw_cs = &cmd->draw_cs;
 
-   VkResult result = tu_cs_reserve_space(cmd->device, draw_cs, 3);
+   VkResult result = tu_cs_reserve_space(draw_cs, 3);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -2439,7 +2439,7 @@ tu_CmdSetDepthBias(VkCommandBuffer commandBuffer,
    TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
    struct tu_cs *draw_cs = &cmd->draw_cs;
 
-   VkResult result = tu_cs_reserve_space(cmd->device, draw_cs, 4);
+   VkResult result = tu_cs_reserve_space(draw_cs, 4);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -2458,7 +2458,7 @@ tu_CmdSetBlendConstants(VkCommandBuffer commandBuffer,
    TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
    struct tu_cs *draw_cs = &cmd->draw_cs;
 
-   VkResult result = tu_cs_reserve_space(cmd->device, draw_cs, 5);
+   VkResult result = tu_cs_reserve_space(draw_cs, 5);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -2668,7 +2668,7 @@ tu_CmdBeginRenderPass(VkCommandBuffer commandBuffer,
    tu_cmd_prepare_tile_load_ib(cmd, pRenderPassBegin);
    tu_cmd_prepare_tile_store_ib(cmd);
 
-   VkResult result = tu_cs_reserve_space(cmd->device, &cmd->draw_cs, 1024);
+   VkResult result = tu_cs_reserve_space(&cmd->draw_cs, 1024);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -2722,7 +2722,7 @@ tu_CmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
       }
    }
 
-   VkResult result = tu_cs_reserve_space(cmd->device, &cmd->draw_cs, 1024);
+   VkResult result = tu_cs_reserve_space(&cmd->draw_cs, 1024);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -3142,7 +3142,7 @@ tu6_emit_consts(struct tu_cmd_buffer *cmd,
                 gl_shader_stage type)
 {
    struct tu_cs cs;
-   tu_cs_begin_sub_stream(cmd->device, &cmd->sub_cs, 512, &cs); /* TODO: maximum size? */
+   tu_cs_begin_sub_stream(&cmd->sub_cs, 512, &cs); /* TODO: maximum size? */
 
    tu6_emit_user_consts(&cs, pipeline, descriptors_state, type, cmd->push_constants);
    tu6_emit_ubos(&cs, pipeline, descriptors_state, type);
@@ -3166,7 +3166,7 @@ tu6_emit_vs_params(struct tu_cmd_buffer *cmd,
       return VK_SUCCESS;
    }
 
-   VkResult result = tu_cs_begin_sub_stream(cmd->device, &cmd->sub_cs, 8, &cs);
+   VkResult result = tu_cs_begin_sub_stream(&cmd->sub_cs, 8, &cs);
    if (result != VK_SUCCESS)
       return result;
 
@@ -3199,7 +3199,6 @@ tu6_emit_textures(struct tu_cmd_buffer *cmd,
                   bool *needs_border,
                   bool is_sysmem)
 {
-   struct tu_device *device = cmd->device;
    struct tu_cs *draw_state = &cmd->sub_cs;
    const struct tu_program_descriptor_linkage *link =
       &pipeline->program.link[type];
@@ -3212,7 +3211,7 @@ tu6_emit_textures(struct tu_cmd_buffer *cmd,
 
    /* allocate and fill texture state */
    struct ts_cs_memory tex_const;
-   result = tu_cs_alloc(device, draw_state, link->texture_map.num_desc,
+   result = tu_cs_alloc(draw_state, link->texture_map.num_desc,
                         A6XX_TEX_CONST_DWORDS, &tex_const);
    if (result != VK_SUCCESS)
       return result;
@@ -3230,7 +3229,7 @@ tu6_emit_textures(struct tu_cmd_buffer *cmd,
    /* allocate and fill sampler state */
    struct ts_cs_memory tex_samp = { 0 };
    if (link->sampler_map.num_desc) {
-      result = tu_cs_alloc(device, draw_state, link->sampler_map.num_desc,
+      result = tu_cs_alloc(draw_state, link->sampler_map.num_desc,
                            A6XX_TEX_SAMP_DWORDS, &tex_samp);
       if (result != VK_SUCCESS)
          return result;
@@ -3275,7 +3274,7 @@ tu6_emit_textures(struct tu_cmd_buffer *cmd,
    }
 
    struct tu_cs cs;
-   result = tu_cs_begin_sub_stream(device, draw_state, 16, &cs);
+   result = tu_cs_begin_sub_stream(draw_state, 16, &cs);
    if (result != VK_SUCCESS)
       return result;
 
@@ -3319,7 +3318,6 @@ tu6_emit_ibo(struct tu_cmd_buffer *cmd,
              gl_shader_stage type,
              struct tu_cs_entry *entry)
 {
-   struct tu_device *device = cmd->device;
    struct tu_cs *draw_state = &cmd->sub_cs;
    const struct tu_program_descriptor_linkage *link =
       &pipeline->program.link[type];
@@ -3333,7 +3331,7 @@ tu6_emit_ibo(struct tu_cmd_buffer *cmd,
    }
 
    struct ts_cs_memory ibo_const;
-   result = tu_cs_alloc(device, draw_state, num_desc,
+   result = tu_cs_alloc(draw_state, num_desc,
                         A6XX_TEX_CONST_DWORDS, &ibo_const);
    if (result != VK_SUCCESS)
       return result;
@@ -3377,7 +3375,7 @@ tu6_emit_ibo(struct tu_cmd_buffer *cmd,
    assert(ssbo_index == num_desc);
 
    struct tu_cs cs;
-   result = tu_cs_begin_sub_stream(device, draw_state, 7, &cs);
+   result = tu_cs_begin_sub_stream(draw_state, 7, &cs);
    if (result != VK_SUCCESS)
       return result;
 
@@ -3487,7 +3485,7 @@ tu6_emit_border_color(struct tu_cmd_buffer *cmd,
       &pipeline->program.link[MESA_SHADER_FRAGMENT].sampler_map;
    struct ts_cs_memory ptr;
 
-   VkResult result = tu_cs_alloc(cmd->device, &cmd->sub_cs,
+   VkResult result = tu_cs_alloc(&cmd->sub_cs,
                                  vs_sampler->num_desc + fs_sampler->num_desc,
                                  128 / 4,
                                  &ptr);
@@ -3530,7 +3528,7 @@ tu6_bind_draw_states(struct tu_cmd_buffer *cmd,
    struct tu_descriptor_state *descriptors_state =
       &cmd->descriptors[VK_PIPELINE_BIND_POINT_GRAPHICS];
 
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, 256);
+   VkResult result = tu_cs_reserve_space(cs, 256);
    if (result != VK_SUCCESS)
       return result;
 
@@ -3842,7 +3840,7 @@ tu_draw(struct tu_cmd_buffer *cmd, const struct tu_draw_info *draw)
       return;
    }
 
-   result = tu_cs_reserve_space(cmd->device, cs, 32);
+   result = tu_cs_reserve_space(cs, 32);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -4017,7 +4015,7 @@ tu_dispatch(struct tu_cmd_buffer *cmd,
    struct tu_descriptor_state *descriptors_state =
       &cmd->descriptors[VK_PIPELINE_BIND_POINT_COMPUTE];
 
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, 256);
+   VkResult result = tu_cs_reserve_space(cs, 256);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -4249,7 +4247,7 @@ write_event(struct tu_cmd_buffer *cmd, struct tu_event *event, unsigned value)
 {
    struct tu_cs *cs = &cmd->cs;
 
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, 4);
+   VkResult result = tu_cs_reserve_space(cs, 4);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
@@ -4302,7 +4300,7 @@ tu_CmdWaitEvents(VkCommandBuffer commandBuffer,
    TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
    struct tu_cs *cs = &cmd->cs;
 
-   VkResult result = tu_cs_reserve_space(cmd->device, cs, eventCount * 7);
+   VkResult result = tu_cs_reserve_space(cs, eventCount * 7);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
index 4e7ea2b5022c2d80574c9e5cace2342f284ec989..6cb96b0926d284618403aa28fc2733422cf2ef77 100644 (file)
  * 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;
 }
@@ -54,10 +58,10 @@ tu_cs_init_external(struct tu_cs *cs, uint32_t *start, uint32_t *end)
  * 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]);
    }
 
@@ -110,7 +114,7 @@ tu_cs_is_empty(const struct tu_cs *cs)
  * 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);
@@ -134,15 +138,16 @@ tu_cs_add_bo(struct tu_device *dev, struct tu_cs *cs, uint32_t size)
    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;
    }
@@ -266,21 +271,18 @@ tu_cs_end(struct tu_cs *cs)
  * 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;
@@ -292,8 +294,7 @@ tu_cs_begin_sub_stream(struct tu_device *dev,
  *
  */
 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)
@@ -306,7 +307,7 @@ tu_cs_alloc(struct tu_device *dev,
 
    /* 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;
 
@@ -356,9 +357,7 @@ tu_cs_end_sub_stream(struct tu_cs *cs, struct tu_cs *sub_cs)
  * 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) {
@@ -376,7 +375,7 @@ tu_cs_reserve_space(struct tu_device *dev,
 
       /* 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;
 
@@ -402,7 +401,7 @@ tu_cs_reserve_space(struct tu_device *dev,
  * 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);
@@ -411,7 +410,7 @@ tu_cs_reset(struct tu_device *dev, struct tu_cs *cs)
    }
 
    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]);
    }
 
index e7fd0c42eb86b4a907382e5786b7180964a15f30..45e774c581a7a0dff533473ceefcd80a1032e0c4 100644 (file)
 #include "registers/adreno_pm4.xml.h"
 
 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);
 
 void
 tu_cs_init_external(struct tu_cs *cs, uint32_t *start, uint32_t *end);
 
 void
-tu_cs_finish(struct tu_device *dev, struct tu_cs *cs);
+tu_cs_finish(struct tu_cs *cs);
 
 void
 tu_cs_begin(struct tu_cs *cs);
@@ -43,14 +46,10 @@ void
 tu_cs_end(struct tu_cs *cs);
 
 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);
 
 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);
@@ -59,12 +58,10 @@ struct tu_cs_entry
 tu_cs_end_sub_stream(struct tu_cs *cs, struct tu_cs *sub_cs);
 
 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);
 
 void
-tu_cs_reset(struct tu_device *dev, struct tu_cs *cs);
+tu_cs_reset(struct tu_cs *cs);
 
 VkResult
 tu_cs_add_entries(struct tu_cs *cs, struct tu_cs *target);
@@ -224,7 +221,7 @@ tu_cond_exec_start(struct tu_device *dev, struct tu_cs *cs,
    /* Reserve enough space so that both the condition packet and the actual
     * condition will fit in the same IB.
     */
-   VkResult result = tu_cs_reserve_space(dev, cs, max_dwords + 3);
+   VkResult result = tu_cs_reserve_space(cs, max_dwords + 3);
    if (result != VK_SUCCESS)
       return result;
 
index c7fcbd5e6723050786715db49e4a57d6f81c4278..fd82b9cdf8d753a8428f7cb274d7bb3f85b96576 100644 (file)
@@ -45,7 +45,7 @@ tu_CmdUpdateBuffer(VkCommandBuffer commandBuffer,
    tu_bo_list_add(&cmd->bo_list, buffer->bo, MSM_SUBMIT_BO_WRITE);
 
    struct ts_cs_memory tmp;
-   VkResult result = tu_cs_alloc(cmd->device, &cmd->sub_cs, DIV_ROUND_UP(dataSize, 64), 64, &tmp);
+   VkResult result = tu_cs_alloc(&cmd->sub_cs, DIV_ROUND_UP(dataSize, 64), 64, &tmp);
    if (result != VK_SUCCESS) {
       cmd->record_result = result;
       return;
index 3d7278a4c897820ee2fe5467764f55aa4a39673d..75ce56dc6733f22937421b4d6d874e93a5625a14 100644 (file)
@@ -1524,10 +1524,10 @@ tu_pipeline_create(struct tu_device *dev,
    if (!pipeline)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
-   tu_cs_init(&pipeline->cs, TU_CS_MODE_SUB_STREAM, 2048);
+   tu_cs_init(&pipeline->cs, dev, TU_CS_MODE_SUB_STREAM, 2048);
 
    /* reserve the space now such that tu_cs_begin_sub_stream never fails */
-   VkResult result = tu_cs_reserve_space(dev, &pipeline->cs, 2048);
+   VkResult result = tu_cs_reserve_space(&pipeline->cs, 2048);
    if (result != VK_SUCCESS) {
       vk_free2(&dev->alloc, pAllocator, pipeline);
       return result;
@@ -1660,11 +1660,11 @@ tu_pipeline_builder_parse_shader_stages(struct tu_pipeline_builder *builder,
                                         struct tu_pipeline *pipeline)
 {
    struct tu_cs prog_cs;
-   tu_cs_begin_sub_stream(builder->device, &pipeline->cs, 512, &prog_cs);
+   tu_cs_begin_sub_stream(&pipeline->cs, 512, &prog_cs);
    tu6_emit_program(&prog_cs, builder, &pipeline->program.binary_bo, false);
    pipeline->program.state_ib = tu_cs_end_sub_stream(&pipeline->cs, &prog_cs);
 
-   tu_cs_begin_sub_stream(builder->device, &pipeline->cs, 512, &prog_cs);
+   tu_cs_begin_sub_stream(&pipeline->cs, 512, &prog_cs);
    tu6_emit_program(&prog_cs, builder, &pipeline->program.binary_bo, true);
    pipeline->program.binning_state_ib =
       tu_cs_end_sub_stream(&pipeline->cs, &prog_cs);
@@ -1688,7 +1688,7 @@ tu_pipeline_builder_parse_vertex_input(struct tu_pipeline_builder *builder,
    const struct tu_shader *vs = builder->shaders[MESA_SHADER_VERTEX];
 
    struct tu_cs vi_cs;
-   tu_cs_begin_sub_stream(builder->device, &pipeline->cs,
+   tu_cs_begin_sub_stream(&pipeline->cs,
                           MAX_VERTEX_ATTRIBS * 5 + 2, &vi_cs);
    tu6_emit_vertex_input(&vi_cs, &vs->variants[0], vi_info,
                          pipeline->vi.bindings, pipeline->vi.strides,
@@ -1696,7 +1696,7 @@ tu_pipeline_builder_parse_vertex_input(struct tu_pipeline_builder *builder,
    pipeline->vi.state_ib = tu_cs_end_sub_stream(&pipeline->cs, &vi_cs);
 
    if (vs->has_binning_pass) {
-      tu_cs_begin_sub_stream(builder->device, &pipeline->cs,
+      tu_cs_begin_sub_stream(&pipeline->cs,
                              MAX_VERTEX_ATTRIBS * 5 + 2, &vi_cs);
       tu6_emit_vertex_input(
          &vi_cs, &vs->variants[1], vi_info, pipeline->vi.binning_bindings,
@@ -1737,7 +1737,7 @@ tu_pipeline_builder_parse_viewport(struct tu_pipeline_builder *builder,
       builder->create_info->pViewportState;
 
    struct tu_cs vp_cs;
-   tu_cs_begin_sub_stream(builder->device, &pipeline->cs, 15, &vp_cs);
+   tu_cs_begin_sub_stream(&pipeline->cs, 15, &vp_cs);
 
    if (!(pipeline->dynamic_state.mask & TU_DYNAMIC_VIEWPORT)) {
       assert(vp_info->viewportCount == 1);
@@ -1763,7 +1763,7 @@ tu_pipeline_builder_parse_rasterization(struct tu_pipeline_builder *builder,
    assert(rast_info->polygonMode == VK_POLYGON_MODE_FILL);
 
    struct tu_cs rast_cs;
-   tu_cs_begin_sub_stream(builder->device, &pipeline->cs, 20, &rast_cs);
+   tu_cs_begin_sub_stream(&pipeline->cs, 20, &rast_cs);
 
    /* move to hw ctx init? */
    tu6_emit_gras_unknowns(&rast_cs);
@@ -1807,7 +1807,7 @@ tu_pipeline_builder_parse_depth_stencil(struct tu_pipeline_builder *builder,
          : &dummy_ds_info;
 
    struct tu_cs ds_cs;
-   tu_cs_begin_sub_stream(builder->device, &pipeline->cs, 12, &ds_cs);
+   tu_cs_begin_sub_stream(&pipeline->cs, 12, &ds_cs);
 
    /* move to hw ctx init? */
    tu6_emit_alpha_control_disable(&ds_cs);
@@ -1862,8 +1862,7 @@ tu_pipeline_builder_parse_multisample_and_color_blend(
                                      : &dummy_blend_info;
 
    struct tu_cs blend_cs;
-   tu_cs_begin_sub_stream(builder->device, &pipeline->cs, MAX_RTS * 3 + 9,
-                          &blend_cs);
+   tu_cs_begin_sub_stream(&pipeline->cs, MAX_RTS * 3 + 9, &blend_cs);
 
    uint32_t blend_enable_mask;
    tu6_emit_rb_mrt_controls(&blend_cs, blend_info,
@@ -1883,7 +1882,7 @@ tu_pipeline_finish(struct tu_pipeline *pipeline,
                    struct tu_device *dev,
                    const VkAllocationCallbacks *alloc)
 {
-   tu_cs_finish(dev, &pipeline->cs);
+   tu_cs_finish(&pipeline->cs);
 
    if (pipeline->program.binary_bo.gem_handle)
       tu_bo_finish(dev, &pipeline->program.binary_bo);
@@ -2123,7 +2122,7 @@ tu_compute_pipeline_create(VkDevice device,
       pipeline->compute.local_size[i] = v->shader->nir->info.cs.local_size[i];
 
    struct tu_cs prog_cs;
-   tu_cs_begin_sub_stream(dev, &pipeline->cs, 512, &prog_cs);
+   tu_cs_begin_sub_stream(&pipeline->cs, 512, &prog_cs);
    tu6_emit_compute_program(&prog_cs, shader, &pipeline->program.binary_bo);
    pipeline->program.state_ib = tu_cs_end_sub_stream(&pipeline->cs, &prog_cs);
 
index eb3cc5dd684f1ce8116604ebf11a9cf52d665ba5..08d8734a4763ce1af6ff4d598ebc1100bf9ddf31 100644 (file)
@@ -569,6 +569,7 @@ struct tu_cs
    uint32_t *reserved_end;
    uint32_t *end;
 
+   struct tu_device *device;
    enum tu_cs_mode mode;
    uint32_t next_bo_size;
 
index 5e3e2c1893a071948dd2cd86682c5cb6085c68d9..1dad575965d804f93c02bd58ca7b6caa1dcceadb 100644 (file)
@@ -290,7 +290,7 @@ copy_query_value_gpu(struct tu_cmd_buffer *cmdbuf,
          sizeof(uint64_t) : sizeof(uint32_t);
    uint64_t write_iova = base_write_iova + (offset * element_size);
 
-   tu_cs_reserve_space(cmdbuf->device, cs, 6);
+   tu_cs_reserve_space(cs, 6);
    tu_cs_emit_pkt7(cs, CP_MEM_TO_MEM, 5);
    uint32_t mem_to_mem_flags = flags & VK_QUERY_RESULT_64_BIT ?
          CP_MEM_TO_MEM_0_DOUBLE : 0;
@@ -319,7 +319,7 @@ emit_copy_occlusion_query_pool_results(struct tu_cmd_buffer *cmdbuf,
     * To ensure that previous writes to the available bit are coherent, first
     * wait for all writes to complete.
     */
-   tu_cs_reserve_space(cmdbuf->device, cs, 1);
+   tu_cs_reserve_space(cs, 1);
    tu_cs_emit_pkt7(cs, CP_WAIT_MEM_WRITES, 0);
 
    for (uint32_t i = 0; i < queryCount; i++) {
@@ -330,7 +330,7 @@ emit_copy_occlusion_query_pool_results(struct tu_cmd_buffer *cmdbuf,
       /* Wait for the available bit to be set if executed with the
        * VK_QUERY_RESULT_WAIT_BIT flag. */
       if (flags & VK_QUERY_RESULT_WAIT_BIT) {
-         tu_cs_reserve_space(cmdbuf->device, cs, 7);
+         tu_cs_reserve_space(cs, 7);
          tu_cs_emit_pkt7(cs, CP_WAIT_REG_MEM, 6);
          tu_cs_emit(cs, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ) |
                         CP_WAIT_REG_MEM_0_POLL_MEMORY);
@@ -356,7 +356,7 @@ emit_copy_occlusion_query_pool_results(struct tu_cmd_buffer *cmdbuf,
           * tests that ADDR0 != 0 and ADDR1 < REF. The packet here simply tests
           * that 0 < available < 2, aka available == 1.
           */
-         tu_cs_reserve_space(cmdbuf->device, cs, 7 + 6);
+         tu_cs_reserve_space(cs, 7 + 6);
          tu_cs_emit_pkt7(cs, CP_COND_EXEC, 6);
          tu_cs_emit_qw(cs, available_iova);
          tu_cs_emit_qw(cs, available_iova);
@@ -419,7 +419,7 @@ emit_reset_occlusion_query_pool(struct tu_cmd_buffer *cmdbuf,
       uint32_t query = firstQuery + i;
       uint64_t available_iova = occlusion_query_iova(pool, query, available);
       uint64_t result_iova = occlusion_query_iova(pool, query, result);
-      tu_cs_reserve_space(cmdbuf->device, cs, 11);
+      tu_cs_reserve_space(cs, 11);
       tu_cs_emit_pkt7(cs, CP_MEM_WRITE, 4);
       tu_cs_emit_qw(cs, available_iova);
       tu_cs_emit_qw(cs, 0x0);
@@ -475,7 +475,7 @@ emit_begin_occlusion_query(struct tu_cmd_buffer *cmdbuf,
 
    uint64_t begin_iova = occlusion_query_iova(pool, query, begin);
 
-   tu_cs_reserve_space(cmdbuf->device, cs, 7);
+   tu_cs_reserve_space(cs, 7);
    tu_cs_emit_regs(cs,
                    A6XX_RB_SAMPLE_COUNT_CONTROL(.copy = true));
 
@@ -540,7 +540,7 @@ emit_end_occlusion_query(struct tu_cmd_buffer *cmdbuf,
    uint64_t begin_iova = occlusion_query_iova(pool, query, begin);
    uint64_t end_iova = occlusion_query_iova(pool, query, end);
    uint64_t result_iova = occlusion_query_iova(pool, query, result);
-   tu_cs_reserve_space(cmdbuf->device, cs, 31);
+   tu_cs_reserve_space(cs, 31);
    tu_cs_emit_pkt7(cs, CP_MEM_WRITE, 4);
    tu_cs_emit_qw(cs, end_iova);
    tu_cs_emit_qw(cs, 0xffffffffffffffffull);
@@ -583,7 +583,7 @@ emit_end_occlusion_query(struct tu_cmd_buffer *cmdbuf,
        */
       cs = &cmdbuf->draw_epilogue_cs;
 
-   tu_cs_reserve_space(cmdbuf->device, cs, 5);
+   tu_cs_reserve_space(cs, 5);
    tu_cs_emit_pkt7(cs, CP_MEM_WRITE, 4);
    tu_cs_emit_qw(cs, available_iova);
    tu_cs_emit_qw(cs, 0x1);