diff --git a/src/imagination/common/pvr_debug.c b/src/imagination/common/pvr_debug.c index 5e97f7cda14..d9eecfe4742 100644 --- a/src/imagination/common/pvr_debug.c +++ b/src/imagination/common/pvr_debug.c @@ -44,6 +44,8 @@ static const struct debug_named_value debug_control[] = { { "compute_log", PVR_DEBUG_COMPUTE_LOG, "Log compute pipelines and dispatches." }, { "bo_log", PVR_DEBUG_BO_LOG, "Log device-memory and driver BO allocations with size, heap and purpose; live-set summary on any failed allocation and at device destroy." }, + { "pass_log", PVR_DEBUG_PASS_LOG, + "Log every render (targets, load/store, draws, programs), job submit and graphics pipeline to $PVR_PASS_LOG. (else stderr)." }, DEBUG_NAMED_VALUE_END }; /* clang-format on */ diff --git a/src/imagination/common/pvr_debug.h b/src/imagination/common/pvr_debug.h index 86198a951f5..2c64ad1361f 100644 --- a/src/imagination/common/pvr_debug.h +++ b/src/imagination/common/pvr_debug.h @@ -47,6 +47,8 @@ extern uint32_t PVR_DEBUG; #define PVR_DEBUG_ERRORS BITFIELD_BIT(8) #define PVR_DEBUG_COMPUTE_LOG BITFIELD_BIT(9) +/* per-render, per-submit and per-pipeline records (pvr_pass_log.h) */ +#define PVR_DEBUG_PASS_LOG BITFIELD_BIT(10) void pvr_process_debug_variable(void); diff --git a/src/imagination/vulkan/meson.build b/src/imagination/vulkan/meson.build index 41a5a507b4b..abcad8248ae 100644 --- a/src/imagination/vulkan/meson.build +++ b/src/imagination/vulkan/meson.build @@ -48,6 +48,7 @@ pvr_files = files( 'winsys/pvr_winsys_helper.c', 'pvr_bo.c', 'pvr_bo_log.c', + 'pvr_pass_log.c', 'pvr_csb.c', 'pvr_descriptor_set.c', 'pvr_device.c', @@ -173,6 +174,7 @@ common_per_arch_files += files( pvr_files += files( 'pvr_g5p_formats.c', 'pvr_g5p_image.c', + 'pvr_g5p_reuse.c', 'pvr_g5p_nir.c', 'pvr_g5p_shader_dump.c', 'pvr_errlog.c', diff --git a/src/imagination/vulkan/pvr_arch_cmd_buffer.c b/src/imagination/vulkan/pvr_arch_cmd_buffer.c index bc6efa3cdff..b4b6f963043 100644 --- a/src/imagination/vulkan/pvr_arch_cmd_buffer.c +++ b/src/imagination/vulkan/pvr_arch_cmd_buffer.c @@ -21,6 +21,7 @@ * SOFTWARE. */ +#include "pvr_g5p_reuse.h" #include "pvr_cmd_buffer.h" #include @@ -192,6 +193,17 @@ struct pvr_renderpass_hwsetup_render *pvr_arch_pass_info_get_hw_render( return &render_pass_info->pass->hw_setup->renders[idx]; } +/* G5P: a primary command buffer's control stream blocks go back to the + * device's cache once its submissions have completed (pvr_g5p_reuse.h). A + * secondary's are linked from primaries this buffer does not know of: freed. */ +static void pvr_cmd_buffer_retire_csb(struct pvr_cmd_buffer *cmd_buffer, struct pvr_csb *csb) +{ + if (cmd_buffer->device->g5p_reuse && cmd_buffer->vk.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) + pvr_g5p_csb_retire(cmd_buffer->device, csb, cmd_buffer->g5p_retire); + else + pvr_csb_finish(csb); +} + static void pvr_cmd_buffer_free_sub_cmd(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd *sub_cmd) { @@ -213,7 +225,7 @@ static void pvr_cmd_buffer_free_sub_cmd(struct pvr_cmd_buffer *cmd_buffer, pvr_bo_free(cmd_buffer->device, *bo); util_dynarray_fini(&sub_cmd->gfx.g9p_view_bos); util_dynarray_fini(&sub_cmd->gfx.unbound_deferred_clears); - pvr_csb_finish(&sub_cmd->gfx.control_stream); + pvr_cmd_buffer_retire_csb(cmd_buffer, &sub_cmd->gfx.control_stream); pvr_bo_free(cmd_buffer->device, sub_cmd->gfx.terminate_ctrl_stream); pvr_bo_free(cmd_buffer->device, sub_cmd->gfx.multiview_ctrl_stream); pvr_bo_suballoc_free(sub_cmd->gfx.depth_bias_bo); @@ -234,7 +246,7 @@ static void pvr_cmd_buffer_free_sub_cmd(struct pvr_cmd_buffer *cmd_buffer, free(l->line); free(l); } - pvr_csb_finish(&sub_cmd->compute.control_stream); + pvr_cmd_buffer_retire_csb(cmd_buffer, &sub_cmd->compute.control_stream); break; case PVR_SUB_CMD_TYPE_TRANSFER: @@ -285,6 +297,8 @@ static void pvr_cmd_buffer_free_resources(struct pvr_cmd_buffer *cmd_buffer) util_dynarray_fini(&cmd_buffer->state.query_indices); pvr_cmd_buffer_free_sub_cmds(cmd_buffer); + /* the blocks recorded from now on belong to no submission yet */ + memset(cmd_buffer->g5p_retire, 0, sizeof(cmd_buffer->g5p_retire)); memset(cmd_buffer->g5p_upload, 0, sizeof(cmd_buffer->g5p_upload)); if (cmd_buffer->g5p_views) { @@ -1756,6 +1770,148 @@ static VkResult pvr_render_targets_dataset_init( struct pvr_render_state *rstate, const struct pvr_renderpass_hwsetup_render *hw_render); +/* Barrier precision (pvr_geom_hazard.h): what this render's fragment job writes. Every view of the pass counts + * (colour, depth/stencil, resolve; one the render only reads is merely conservative). A fragment program with stores + * or atomics, or an attachment a buffer may alias, writes memory the driver cannot name: opaque. + */ +static void +pvr_geom_hazard_note_attachments(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd_gfx *sub) +{ + const struct pvr_render_pass_info *info = &cmd_buffer->state.render_pass_info; + struct pvr_geom_hazard *hz = &sub->geom_hz; + + if (pvr_geom_precise_level(&cmd_buffer->device->pdevice->dev_info) < 2) + return; + if (sub->frag_has_side_effects || sub->frag_uses_atomic_ops) + hz->writes_opaque = true; + for (uint32_t i = 0; i < info->attachment_count && !hz->writes_opaque; i++) { + const struct pvr_image_view *iview = info->attachments ? info->attachments[i] : NULL; + const struct pvr_image *image; + + if (!iview) + continue; + image = pvr_image_view_get_image(iview); + if (pvr_geom_image_buffer_visible(image)) { + hz->writes_opaque = true; + break; + } + pvr_geom_hazard_add_write(hz, pvr_geom_image_range(image)); + } +} + +/* PVR_DEBUG=pass_log: the P line of a render, as recorded (pvr_pass_log.h). Chip-agnostic: the + * render's API shape and draws for every chip, then what the chip's job init chose. */ +static char +pvr_pass_log_op(VkAttachmentLoadOp op) +{ + return op == VK_ATTACHMENT_LOAD_OP_LOAD ? 'L' : op == VK_ATTACHMENT_LOAD_OP_CLEAR ? 'C' + : op == VK_ATTACHMENT_LOAD_OP_DONT_CARE ? 'D' : 'N'; +} + +static void +pvr_pass_log_record(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd_gfx *sub, VkResult result) +{ + const struct pvr_device_info *dev_info = &cmd_buffer->device->pdevice->dev_info; + struct pvr_cmd_buffer_state *state = &cmd_buffer->state; + const struct pvr_render_pass_info *info = &state->render_pass_info; + const struct pvr_renderpass_hwsetup_render *hw = pvr_arch_pass_info_get_hw_render(info, sub->hw_render_idx); + const struct pvr_render_pass_attachment *pass_att = sub->dr_info ? sub->dr_info->attachments + : info->pass ? info->pass->attachments : NULL; + const uint32_t pass_att_count = sub->dr_info ? sub->dr_info->attachment_count + : info->pass ? info->pass->attachment_count : 0; + const struct pvr_pass_log_stats *st = &sub->pass_log; + const struct pvr_render_job *job = &sub->job; + char buf[1024]; + int n = 0; +#define PL_ADD(...) \ + do { if (n < (int)sizeof(buf)) n += snprintf(buf + n, sizeof(buf) - n, __VA_ARGS__); } while (0) + + sub->pass_log_serial = pvr_pass_log_next_serial(); + PL_ADD("P pass=%u cb=%p res=%d chip=%s dyn=%u area=%d,%d,%ux%u samples=%u draws=%u idx=%u ind=%u clears=%u " + "verts=%" PRIu64 " sets=%u%s tex=%u lin=%u lin_pot=%u lin_big=%u " + "ycbcr=%u ext=%u nopipe=%u pipes=", + sub->pass_log_serial, (void *)cmd_buffer, result, + PVR_HAS_FEATURE(dev_info, apple_g5p) ? (PVR_HAS_FEATURE(dev_info, apple_g4p) ? "g4p" : "g5p") + : PVR_HAS_FEATURE(dev_info, apple_g9p) ? "g9p" : "rogue", + sub->dr_info != NULL, info->render_area.offset.x, info->render_area.offset.y, + info->render_area.extent.width, info->render_area.extent.height, hw ? hw->sample_count : 0, + st->draws, st->indexed, st->indirect, st->clears, + st->verts, st->nsets, st->sets_overflow ? "+" : "", + st->tex, st->tex_lin, st->tex_lin_pot, st->tex_lin_big, + st->ycbcr, st->ext, st->no_pipe); + for (uint32_t i = 0; i < st->npipes; i++) + PL_ADD("%s%08x", i ? "," : "", st->pipes[i]); + PL_ADD("%s", st->pipes_overflow ? ",+" : st->npipes ? "" : "-"); + /* the drawn area (scissors and clear rectangles) clipped to the render area: what empty-tile skipping keeps */ + if (st->bbox_valid) { + const VkRect2D *a = &info->render_area; + const int32_t x0 = MAX2(st->bx0, a->offset.x), y0 = MAX2(st->by0, a->offset.y); + const int32_t x1 = MIN2(st->bx1, a->offset.x + (int32_t)a->extent.width); + const int32_t y1 = MIN2(st->by1, a->offset.y + (int32_t)a->extent.height); + PL_ADD(" bbox=%d,%d,%dx%d", x0, y0, MAX2(x1 - x0, 0), MAX2(y1 - y0, 0)); + } else { + PL_ADD(" bbox=-"); + } + + uint64_t first_target = 0; + char first_load = '-'; + for (uint32_t t = 0; hw && t < hw->eot_surface_count; t++) { + const struct pvr_renderpass_hwsetup_eot_surface *eot = &hw->eot_surfaces[t]; + if (eot->attachment_idx >= info->attachment_count || !info->attachments[eot->attachment_idx]) + continue; + const struct pvr_image_view *iview = info->attachments[eot->attachment_idx]; + const struct pvr_image *image = pvr_image_view_get_image(iview); + char load = '-', store = '?'; + for (uint32_t i = 0; i < hw->color_init_count; i++) + if (hw->color_init[i].index == eot->attachment_idx) + load = pvr_pass_log_op(hw->color_init[i].op); + if (pass_att && eot->attachment_idx < pass_att_count) + store = pass_att[eot->attachment_idx].store_op == VK_ATTACHMENT_STORE_OP_STORE ? 'S' : 'D'; + /* the surface: the image, its level and layer (a split pass continues the same one) */ + if (!t) { + first_target = image->dev_addr.addr ^ (uint64_t)iview->vk.base_mip_level << 56 ^ + (uint64_t)iview->vk.base_array_layer << 40; + first_load = load; + } + PL_ADD(" c%u=%s:%ux%u:s%u:%s%s:load=%c:store=%c:resolve=%u:@%" PRIx64 "/l%u/a%u", t, + pvr_pass_log_format(iview->vk.format), iview->vk.extent.width, iview->vk.extent.height, + image->vk.samples, image->memlayout == PVR_MEMLAYOUT_LINEAR ? "lin" : "twd", + image->vk.external_handle_types ? ":ext" : "", load, store, eot->need_resolve, + image->dev_addr.addr, iview->vk.base_mip_level, iview->vk.base_array_layer); + } + /* colour inits of attachments that are not stored */ + for (uint32_t i = 0; hw && i < hw->color_init_count; i++) { + bool stored = false; + for (uint32_t t = 0; t < hw->eot_surface_count; t++) + stored |= hw->eot_surfaces[t].attachment_idx == hw->color_init[i].index; + if (!stored) + PL_ADD(" cinit%u=%c", hw->color_init[i].index, pvr_pass_log_op(hw->color_init[i].op)); + } + if (hw && hw->ds_attach_idx != VK_ATTACHMENT_UNUSED && hw->ds_attach_idx < info->attachment_count && + info->attachments[hw->ds_attach_idx]) { + const struct pvr_image_view *iview = info->attachments[hw->ds_attach_idx]; + PL_ADD(" ds=%s:%ux%u:dload=%c:sload=%c:dstore=%u:sstore=%u", pvr_pass_log_format(iview->vk.format), + iview->vk.extent.width, iview->vk.extent.height, pvr_pass_log_op(hw->depth_init), + pvr_pass_log_op(hw->stencil_init), hw->depth_store, hw->stencil_store); + } + if (job->has_depth_attachment || job->has_stencil_attachment) + PL_ADD(" zls=load:%u%u,store:%u%u", job->ds.load.d, job->ds.load.s, job->ds.store.d, job->ds.store.s); + /* the same first colour target as this command buffer's previous render, loaded: a split pass */ + PL_ADD(" cont=%u", first_target && first_target == state->pass_log_prev_target && first_load == 'L'); + state->pass_log_prev_target = first_target; + PL_ADD(" bstore=%u bload=%u transfer=%u", sub->barrier_store, sub->barrier_load, sub->g5p_transfer); + if (job->g5p.enabled) + PL_ADD(" g5p=%ux%u:t%u:bg=%s:partial=%u:skip_empty=%u:msaa_resolve=%u:raw=%u", job->g5p.width, + job->g5p.height, job->g5p.targets, job->g5p.load_background ? "load" : "clear", + job->g5p.partial_area, job->g5p.skip_empty_tiles, job->g5p.msaa_resolve, job->g5p.raw_words); + if (job->g9p.enabled) + PL_ADD(" g9p=%ux%u", job->g9p.width, job->g9p.height); + if (!job->g5p.enabled && !job->g9p.enabled) + PL_ADD(" empty_tiles=%u bg_tag=%u", job->process_empty_tiles, job->enable_bg_tag); +#undef PL_ADD + pvr_pass_log_printf("%s", buf); +} + static VkResult pvr_sub_cmd_gfx_job_init(const struct pvr_device_info *dev_info, struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd_gfx *sub_cmd) @@ -2750,10 +2906,18 @@ VkResult pvr_arch_cmd_buffer_end_sub_cmd(struct pvr_cmd_buffer *cmd_buffer) if (gfx_sub_cmd->geom_only) { pvr_sub_cmd_gfx_geom_only_job_init(cmd_buffer, gfx_sub_cmd); + if (pvr_pass_log_enabled()) { + gfx_sub_cmd->pass_log_serial = pvr_pass_log_next_serial(); + pvr_pass_log_printf("P pass=%u cb=%p geom_only=1 draws=%u", gfx_sub_cmd->pass_log_serial, + (void *)cmd_buffer, gfx_sub_cmd->pass_log.draws); + } } else { + pvr_geom_hazard_note_attachments(cmd_buffer, gfx_sub_cmd); result = pvr_sub_cmd_gfx_job_init(&device->pdevice->dev_info, cmd_buffer, gfx_sub_cmd); + if (pvr_pass_log_enabled()) + pvr_pass_log_record(cmd_buffer, gfx_sub_cmd, result); if (result == VK_ERROR_FEATURE_NOT_PRESENT && device->pdevice->skip_refused_work) { gfx_sub_cmd->g5p_refused = true; @@ -9789,6 +9953,54 @@ g5p_draw_result(struct pvr_cmd_buffer *cmd_buffer, VkResult result) vk_command_buffer_set_error(&cmd_buffer->vk, pvr_refusal_to_api(result)); } +/* PVR_DEBUG=pass_log: count a draw into the render it is recorded in (pvr_pass_log.h) */ +static inline void +pvr_pass_log_count_draw(struct pvr_cmd_buffer *cmd_buffer, bool indexed, bool indirect, uint64_t verts) +{ + struct pvr_sub_cmd *sub = cmd_buffer->state.current_sub_cmd; + if (!sub || sub->type != PVR_SUB_CMD_TYPE_GRAPHICS) + return; + const struct pvr_graphics_pipeline *p = cmd_buffer->state.gfx_pipeline; + struct pvr_pass_log_stats *s = &sub->gfx.pass_log; + pvr_pass_log_draw(s, p ? &p->pass_log : NULL, indexed, indirect, verts); + + /* the drawn area: the first scissor (the render area without one) */ + const struct vk_dynamic_graphics_state *dyn = &cmd_buffer->vk.dynamic_graphics_state; + const VkRect2D *r = dyn->vp.scissor_count ? &dyn->vp.scissors[0] : &cmd_buffer->state.render_pass_info.render_area; + pvr_pass_log_rect(s, r->offset.x, r->offset.y, r->extent.width, r->extent.height); + + /* a bound set holding an imported or multi-planar image, plus sampled-image census */ + const uint32_t sets = p && p->base.layout ? MIN2(p->base.layout->set_count, PVR_MAX_DESCRIPTOR_SETS) : 0; + bool ext_seen = false; + for (uint32_t i = 0; i < sets; i++) { + const struct pvr_descriptor_set *set = cmd_buffer->state.gfx_desc_state.sets[i]; + if (!set) + continue; + if (set->pass_log_ext) + ext_seen = true; + bool seen = false; + for (uint32_t j = 0; j < s->nsets; j++) { + if (s->sets[j] == set) { + seen = true; + break; + } + } + if (seen) + continue; + if (s->nsets < ARRAY_SIZE(s->sets)) { + s->sets[s->nsets++] = set; + s->tex += util_bitcount64(set->pass_log_tex); + s->tex_lin += util_bitcount64(set->pass_log_lin); + s->tex_lin_pot += util_bitcount64(set->pass_log_lin_pot); + s->tex_lin_big += util_bitcount64(set->pass_log_lin_big); + } else { + s->sets_overflow = true; + } + } + if (ext_seen) + s->ext++; +} + void PVR_PER_ARCH(CmdDraw)(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, @@ -9808,6 +10020,9 @@ void PVR_PER_ARCH(CmdDraw)(VkCommandBuffer commandBuffer, PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); + if (pvr_pass_log_enabled()) + pvr_pass_log_count_draw(cmd_buffer, false, false, (uint64_t)vertexCount * instanceCount); + PVR_TRACE_BEGIN_DRAW(cmd_buffer, PVR_DRAW); if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g5p) && @@ -9898,6 +10113,9 @@ void PVR_PER_ARCH(CmdDrawIndexed)(VkCommandBuffer commandBuffer, PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); + if (pvr_pass_log_enabled()) + pvr_pass_log_count_draw(cmd_buffer, true, false, (uint64_t)indexCount * instanceCount); + PVR_TRACE_BEGIN_DRAW(cmd_buffer, PVR_DRAW_INDEXED); if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g5p) && @@ -9984,6 +10202,9 @@ void PVR_PER_ARCH(CmdDrawIndexedIndirect)(VkCommandBuffer commandBuffer, PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); + if (pvr_pass_log_enabled()) + pvr_pass_log_count_draw(cmd_buffer, true, true, 0); + PVR_TRACE_BEGIN_DRAW(cmd_buffer, PVR_DRAW_INDEXED_INDIRECT); PVR_G5P_HOOK(g5p_indexed_indirect) pvr_update_draw_state(state, &draw_state); @@ -10028,6 +10249,9 @@ void PVR_PER_ARCH(CmdDrawIndirect)(VkCommandBuffer commandBuffer, PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); + if (pvr_pass_log_enabled()) + pvr_pass_log_count_draw(cmd_buffer, false, true, 0); + PVR_TRACE_BEGIN_DRAW(cmd_buffer, PVR_DRAW_INDIRECT); PVR_G5P_HOOK(g5p_indirect) pvr_update_draw_state(state, &draw_state); @@ -10056,7 +10280,9 @@ void PVR_PER_ARCH(CmdDrawIndirect)(VkCommandBuffer commandBuffer, static VkResult pvr_cmd_buffer_insert_barrier_event(struct pvr_cmd_buffer *cmd_buffer, uint32_t src_stage_mask, - uint32_t dst_stage_mask) + uint32_t dst_stage_mask, + bool geom_precise, + uint32_t geom_src_stage_mask) { VkResult result; @@ -10070,6 +10296,8 @@ pvr_cmd_buffer_insert_barrier_event(struct pvr_cmd_buffer *cmd_buffer, .barrier = { .wait_for_stage_mask = src_stage_mask, .wait_at_stage_mask = dst_stage_mask, + .geom_precise = geom_precise, + .geom_wait_for_stage_mask = geom_src_stage_mask, }, }; @@ -10227,6 +10455,9 @@ void PVR_PER_ARCH(CmdDrawIndirectByteCountEXT)(VkCommandBuffer commandBuffer, PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); + if (pvr_pass_log_enabled()) + pvr_pass_log_count_draw(cmd_buffer, false, true, 0); + result = pvr_update_indirect_draw_byte_count_ext(cmd_buffer, drawCount, firstInstance, @@ -10241,7 +10472,9 @@ void PVR_PER_ARCH(CmdDrawIndirectByteCountEXT)(VkCommandBuffer commandBuffer, result = pvr_cmd_buffer_insert_barrier_event(cmd_buffer, PVR_PIPELINE_STAGE_GEOM_BIT, - PVR_PIPELINE_STAGE_GEOM_BIT); + PVR_PIPELINE_STAGE_GEOM_BIT, + false, + 0); if (result != VK_SUCCESS) return; @@ -10502,6 +10735,9 @@ pvr_execute_graphics_cmd_buffer(struct pvr_cmd_buffer *cmd_buffer, if (!sec_sub_cmd->gfx.empty_cmd) primary_sub_cmd->gfx.empty_cmd = false; + /* barrier precision: the secondary's draws are the primary render's (pvr_geom_hazard.h) */ + pvr_geom_hazard_merge(&primary_sub_cmd->gfx.geom_hz, &sec_sub_cmd->gfx.geom_hz); + if (sec_sub_cmd->gfx.query_pool) { primary_sub_cmd->gfx.query_pool = sec_sub_cmd->gfx.query_pool; @@ -11104,6 +11340,33 @@ void PVR_PER_ARCH(CmdPipelineBarrier2)(VkCommandBuffer commandBuffer, src_stage_mask = pvr_stage_mask_src(&cmd_buffer->device->pdevice->dev_info, vk_src_stage_mask); dst_stage_mask = pvr_stage_mask_dst(&cmd_buffer->device->pdevice->dev_info, vk_dst_stage_mask); + /* Barrier precision (pvr_geom_hazard.h, PVR_GEOM_PRECISE >= 1): the union + * above pairs every source with every destination. The geometry stage + * waits only for the sources of the barriers whose destination includes + * it (a FRAG -> FRAG image barrier next to a TRANSFER -> VERTEX_INPUT + * buffer barrier no longer makes geometry wait for fragments). + */ + const bool geom_precise = + pvr_geom_precise_level(&cmd_buffer->device->pdevice->dev_info) >= 1; + uint32_t geom_src_stage_mask = 0U; + + if (geom_precise) { + const struct pvr_device_info *dev_info = &cmd_buffer->device->pdevice->dev_info; + +#define PVR_GEOM_PAIR(b) \ + do { \ + if (pvr_stage_mask_dst(dev_info, (b)->dstStageMask) & PVR_PIPELINE_STAGE_GEOM_BIT) \ + geom_src_stage_mask |= pvr_stage_mask_src(dev_info, (b)->srcStageMask); \ + } while (0) + for (uint32_t i = 0; i < pDependencyInfo->memoryBarrierCount; i++) + PVR_GEOM_PAIR(&pDependencyInfo->pMemoryBarriers[i]); + for (uint32_t i = 0; i < pDependencyInfo->bufferMemoryBarrierCount; i++) + PVR_GEOM_PAIR(&pDependencyInfo->pBufferMemoryBarriers[i]); + for (uint32_t i = 0; i < pDependencyInfo->imageMemoryBarrierCount; i++) + PVR_GEOM_PAIR(&pDependencyInfo->pImageMemoryBarriers[i]); +#undef PVR_GEOM_PAIR + } + for (uint32_t stage = 0U; stage != PVR_NUM_SYNC_PIPELINE_STAGES; stage++) { if (!(dst_stage_mask & BITFIELD_BIT(stage))) continue; @@ -11112,11 +11375,16 @@ void PVR_PER_ARCH(CmdPipelineBarrier2)(VkCommandBuffer commandBuffer, } src_stage_mask &= required_stage_mask; + geom_src_stage_mask &= src_stage_mask; for (uint32_t stage = 0U; stage != PVR_NUM_SYNC_PIPELINE_STAGES; stage++) { if (!(dst_stage_mask & BITFIELD_BIT(stage))) continue; - state->barriers_needed[stage] &= ~src_stage_mask; + /* the geometry stage is ordered only after the sources it waits for */ + if (geom_precise && stage == PVR_JOB_TYPE_GEOM) + state->barriers_needed[stage] &= ~geom_src_stage_mask; + else + state->barriers_needed[stage] &= ~src_stage_mask; } if (src_stage_mask == 0 || dst_stage_mask == 0) { @@ -11197,7 +11465,9 @@ void PVR_PER_ARCH(CmdPipelineBarrier2)(VkCommandBuffer commandBuffer, } else if (is_barrier_needed) { result = pvr_cmd_buffer_insert_barrier_event(cmd_buffer, src_stage_mask, - dst_stage_mask); + dst_stage_mask, + geom_precise, + geom_src_stage_mask); if (result != VK_SUCCESS) mesa_loge("Failed to insert pipeline barrier event."); } diff --git a/src/imagination/vulkan/pvr_arch_csb.c b/src/imagination/vulkan/pvr_arch_csb.c index 66edec7622b..8cd00d9ec48 100644 --- a/src/imagination/vulkan/pvr_arch_csb.c +++ b/src/imagination/vulkan/pvr_arch_csb.c @@ -29,6 +29,7 @@ #include "util/list.h" #include "util/u_dynarray.h" #include "vk_log.h" +#include "pvr_g5p_reuse.h" /** * \brief Adds VDMCTRL_STREAM_LINK/CDMCTRL_STREAM_LINK dwords into the control @@ -121,12 +122,16 @@ static bool pvr_csb_buffer_extend(struct pvr_csb *csb) STATIC_ASSERT(ROGUE_VDMCTRL_GUARD_SIZE_DEFAULT == ROGUE_CDMCTRL_GUARD_SIZE_DEFAULT); - result = pvr_bo_alloc(csb->device, - csb->device->heaps.general_heap, - PVR_CMD_BUFFER_CSB_BO_SIZE, - cache_line_size, - PVR_BO_ALLOC_FLAG_CPU_MAPPED, - &pvr_bo); + /* G5P: a block retired by an earlier command buffer whose jobs have + * completed, zeroed (pvr_g5p_reuse.h); else a new one */ + pvr_g5p_csb_block_alloc(csb->device, &pvr_bo); + result = pvr_bo ? VK_SUCCESS + : pvr_bo_alloc(csb->device, + csb->device->heaps.general_heap, + PVR_CMD_BUFFER_CSB_BO_SIZE, + cache_line_size, + PVR_BO_ALLOC_FLAG_CPU_MAPPED, + &pvr_bo); if (result != VK_SUCCESS) { vk_error(csb->device, result); csb->status = result; diff --git a/src/imagination/vulkan/pvr_arch_descriptor_set.c b/src/imagination/vulkan/pvr_arch_descriptor_set.c index 4a49af05b4a..c49abb22da9 100644 --- a/src/imagination/vulkan/pvr_arch_descriptor_set.c +++ b/src/imagination/vulkan/pvr_arch_descriptor_set.c @@ -5,9 +5,12 @@ */ #include +#include #include "pvr_descriptor_set.h" +#include "util/u_math.h" #include "vk_descriptor_update_template.h" +#include "vk_format.h" #include "vk_log.h" #include "vk_util.h" @@ -16,6 +19,7 @@ #include "pvr_device.h" #include "pvr_entrypoints.h" #include "pvr_image.h" +#include "pvr_pass_log.h" #include "pvr_physical_device.h" #include "pvr_sampler.h" #include "pvr_g5p_compute_state.h" @@ -107,6 +111,86 @@ write_sampler(const struct pvr_descriptor_set *set, memcpy(desc_mapping, &sampler_desc, sizeof(sampler_desc)); } +/* PVR_DEBUG=pass_log: which bindings hold sampled images and their layout/ext census (pvr_pass_log.h) */ +static void +pvr_pass_log_note_image(const struct pvr_descriptor_set *cset, + const struct pvr_descriptor_set_layout_binding *binding, + const VkDescriptorImageInfo *image_info) +{ + struct pvr_descriptor_set *set = (struct pvr_descriptor_set *)cset; + const ptrdiff_t b = binding - set->layout->bindings; + bool ext = false, tex = false, lin = false, lin_pot = false, lin_big = false; + + if (b < 0 || b >= 64) + return; + if (image_info && image_info->imageView != VK_NULL_HANDLE) { + VK_FROM_HANDLE(pvr_image_view, iv, image_info->imageView); + const struct pvr_image *img = pvr_image_view_get_image(iv); + const uint32_t w = img->vk.extent.width; + const uint32_t h = img->vk.extent.height; + ext = img->vk.external_handle_types || vk_format_get_plane_count(img->vk.format) > 1; + tex = true; + lin = img->memlayout == PVR_MEMLAYOUT_LINEAR; + const bool pot = util_is_power_of_two_nonzero(w) && util_is_power_of_two_nonzero(h); + lin_pot = lin && pot && img->vk.mip_levels == 1 && !img->vk.external_handle_types; + lin_big = lin && (uint64_t)w * h >= 256 * 256; + if (pvr_pass_log_enabled() && pvr_pass_log_image_first(img)) { + pvr_pass_log_printf("T img=@%" PRIx64 " fmt=%s %ux%u levels=%u layers=%u layout=%s usage=%" PRIx64 " ext=%u", + img->dev_addr.addr, pvr_pass_log_format(img->vk.format), w, h, + img->vk.mip_levels, img->vk.array_layers, lin ? "lin" : "twd", + (uint64_t)img->vk.usage, (unsigned)ext); + } + } + const uint64_t bit = BITFIELD64_BIT(b); + if (ext) + set->pass_log_ext |= bit; + else + set->pass_log_ext &= ~bit; + if (tex) + set->pass_log_tex |= bit; + else + set->pass_log_tex &= ~bit; + if (lin) + set->pass_log_lin |= bit; + else + set->pass_log_lin &= ~bit; + if (lin_pot) + set->pass_log_lin_pot |= bit; + else + set->pass_log_lin_pot &= ~bit; + if (lin_big) + set->pass_log_lin_big |= bit; + else + set->pass_log_lin_big &= ~bit; +} + +/* Barrier precision (pvr_geom_hazard.h): the image of a descriptor a + * pre-raster stage may read, by (binding, element). Push descriptor sets are + * written into a stack copy and stay untracked; the draw-side capture treats + * them as unknown. + */ +#define PVR_GEOM_PRE_RASTER_STAGES \ + (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | \ + VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT) + +static void +pvr_geom_note_image(const struct pvr_descriptor_set *cset, + const struct pvr_descriptor_set_layout_binding *binding, + uint32_t elem, + const VkDescriptorImageInfo *image_info) +{ + struct pvr_descriptor_set *set = (struct pvr_descriptor_set *)cset; + struct pvr_geom_range range = { 0, 0 }; + + if (!(binding->stage_flags & PVR_GEOM_PRE_RASTER_STAGES)) + return; + if (image_info && image_info->imageView != VK_NULL_HANDLE) { + VK_FROM_HANDLE(pvr_image_view, iv, image_info->imageView); + range = pvr_geom_image_range(pvr_image_view_get_image(iv)); + } + pvr_geom_set_store(&set->geom_images, (uint32_t)(binding - set->layout->bindings), elem, range); +} + static void write_image_sampler(const struct pvr_descriptor_set *set, const VkDescriptorImageInfo *image_info, @@ -151,6 +235,9 @@ write_image_sampler(const struct pvr_descriptor_set *set, } PVR_G5P_HOOK(image_sampler, set, image_info, &image_sampler_desc) memcpy(desc_mapping, &image_sampler_desc, sizeof(image_sampler_desc)); + pvr_geom_note_image(set, binding, elem, image_info); + if (pvr_pass_log_enabled()) + pvr_pass_log_note_image(set, binding, image_info); } static void @@ -189,6 +276,9 @@ write_sampled_image(const struct pvr_descriptor_set *set, assert(!image_view->sampler_words[0] && !image_view->sampler_words[1]); memcpy(desc_mapping, &sampled_image_desc, sizeof(sampled_image_desc)); + pvr_geom_note_image(set, binding, elem, image_info); + if (pvr_pass_log_enabled()) + pvr_pass_log_note_image(set, binding, image_info); } static void @@ -201,6 +291,8 @@ write_storage_image(const struct pvr_descriptor_set *set, const unsigned desc_offset = binding->offset + (elem * binding->stride); void *desc_mapping = (uint8_t *)set->mapping + desc_offset; + pvr_geom_note_image(set, binding, elem, image_info); + if (image_info->imageView == VK_NULL_HANDLE) { memset(desc_mapping, 0, sizeof(struct pvr_image_descriptor)); return; @@ -479,6 +571,31 @@ void PVR_PER_ARCH(UpdateDescriptorSets)( memcpy(dst_desc_mapping, src_desc_mapping, src_binding->stride); } } + /* barrier precision: the copied elements' images (pvr_geom_note_image()) */ + if (dst_binding->stage_flags & PVR_GEOM_PRE_RASTER_STAGES) { + if (src_set->geom_images.overflow) + dst_set->geom_images.overflow = true; + for (uint32_t j = 0; j < copy->descriptorCount; j++) { + const struct pvr_geom_set_image *e = + pvr_geom_set_find(&src_set->geom_images, copy->srcBinding, copy->srcArrayElement + j); + const struct pvr_geom_range none = { 0, 0 }; + + pvr_geom_set_store(&dst_set->geom_images, copy->dstBinding, copy->dstArrayElement + j, + e ? e->range : none); + } + } + if (pvr_pass_log_enabled() && copy->descriptorCount > 0 && + copy->srcBinding < 64 && copy->dstBinding < 64) { + const uint64_t sbit = BITFIELD64_BIT(copy->srcBinding); + const uint64_t dbit = BITFIELD64_BIT(copy->dstBinding); + dst_set->pass_log_ext = (dst_set->pass_log_ext & ~dbit) | ((src_set->pass_log_ext & sbit) ? dbit : 0); + dst_set->pass_log_tex = (dst_set->pass_log_tex & ~dbit) | ((src_set->pass_log_tex & sbit) ? dbit : 0); + dst_set->pass_log_lin = (dst_set->pass_log_lin & ~dbit) | ((src_set->pass_log_lin & sbit) ? dbit : 0); + dst_set->pass_log_lin_pot = + (dst_set->pass_log_lin_pot & ~dbit) | ((src_set->pass_log_lin_pot & sbit) ? dbit : 0); + dst_set->pass_log_lin_big = + (dst_set->pass_log_lin_big & ~dbit) | ((src_set->pass_log_lin_big & sbit) ? dbit : 0); + } } } diff --git a/src/imagination/vulkan/pvr_arch_device.c b/src/imagination/vulkan/pvr_arch_device.c index a6597ba27cb..5c80ef5f957 100644 --- a/src/imagination/vulkan/pvr_arch_device.c +++ b/src/imagination/vulkan/pvr_arch_device.c @@ -10,6 +10,7 @@ * SPDX-License-Identifier: MIT */ +#include "pvr_g5p_reuse.h" #include "pvr_bo_log.h" #include "pvr_device.h" @@ -901,6 +902,8 @@ VkResult PVR_PER_ARCH(create_device)(struct pvr_physical_device *pdevice, device, device->suballoc_usc.default_size); + pvr_g5p_reuse_init(device); + if (p_atomic_inc_return(&instance->active_device_count) > PVR_SECONDARY_DEVICE_THRESHOLD) { initial_free_list_size = PVR_SECONDARY_DEVICE_FREE_LIST_INITAL_SIZE; @@ -1079,6 +1082,7 @@ VkResult PVR_PER_ARCH(create_device)(struct pvr_physical_device *pdevice, pvr_bo_log_summary(device, "destroy"); pvr_bo_log_device_finish(device); } + pvr_g5p_reuse_finish(device); pvr_bo_suballocator_fini(&device->suballoc_cmd_usc); pvr_bo_suballocator_fini(&device->suballoc_cmd_pds); pvr_bo_suballocator_fini(&device->suballoc_cmd_general); @@ -1158,6 +1162,7 @@ void PVR_PER_ARCH(destroy_device)(struct pvr_device *device, pvr_bo_log_summary(device, "destroy"); pvr_bo_log_device_finish(device); } + pvr_g5p_reuse_finish(device); pvr_bo_suballocator_fini(&device->suballoc_cmd_usc); pvr_bo_suballocator_fini(&device->suballoc_cmd_pds); pvr_bo_suballocator_fini(&device->suballoc_cmd_general); diff --git a/src/imagination/vulkan/pvr_arch_g5p.c b/src/imagination/vulkan/pvr_arch_g5p.c index d1e87eb764d..09f3c186475 100644 --- a/src/imagination/vulkan/pvr_arch_g5p.c +++ b/src/imagination/vulkan/pvr_arch_g5p.c @@ -1606,6 +1606,8 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd hw_render->stencil_resolve_mode != VK_RESOLVE_MODE_NONE; } g->skip_empty_tiles = !keep; + g->load_background = load; + g->partial_area = partial; memcpy(g->background, bgnd, sizeof(g->background)); g->eot[0] = eot_data.data_offset; diff --git a/src/imagination/vulkan/pvr_arch_g5p_compute.c b/src/imagination/vulkan/pvr_arch_g5p_compute.c index 3da2046451b..c07843e4ef4 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_compute.c +++ b/src/imagination/vulkan/pvr_arch_g5p_compute.c @@ -1099,7 +1099,7 @@ PVR_PER_ARCH(g5p_compute_job_submit)(struct pvr_compute_ctx *ctx, * run on the device. */ if (cs->pvr_bo != list_first_entry(&cs->pvr_bo_list, struct pvr_bo, link)) return vk_errorf(d, VK_ERROR_OUT_OF_HOST_MEMORY, "G5P: chained CDM stream not implemented yet"); - struct pvr_winsys_compute_submit_info info = { .wait = wait, + struct pvr_winsys_compute_submit_info info = { .stamp = sub->g5p_stamp, .wait = wait, .g5p_log = sub->g5p_log_first, .g5p_log_count = sub->g5p_log_count, .frame_num = d->global_queue_present_count, .job_num = d->global_cmd_buffer_submit_count }; info.fw_stream_len = diff --git a/src/imagination/vulkan/pvr_arch_g5p_gfx.c b/src/imagination/vulkan/pvr_arch_g5p_gfx.c index 6fe858b5cc7..f96b64ac7d8 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_gfx.c +++ b/src/imagination/vulkan/pvr_arch_g5p_gfx.c @@ -37,6 +37,7 @@ #include "util/u_math.h" #include "pco_g5p_general.h" +#include "pvr_g5p_vtex_plan.h" #include "pdsc.h" #include "pdsc_internal.h" #include "pdsc_isa_pack.h" @@ -2396,6 +2397,94 @@ g5p_realign_binding(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_vertex_b return VK_SUCCESS; } +/* Barrier precision (pvr_geom_hazard.h): the image a vertex upload reads, into the render's read set; an image + * the driver cannot name makes the geometry stage opaque */ +static enum pvr_geom_opaque +g5p_geom_read_image(struct pvr_geom_hazard *hz, const struct pvr_descriptor_state *desc, unsigned set_idx, + unsigned binding, unsigned element) +{ + const struct pvr_descriptor_set *set = set_idx < PVR_MAX_DESCRIPTOR_SETS ? desc->sets[set_idx] : NULL; + const struct pvr_geom_set_image *e; + + /* push descriptors are written to a stack copy (untracked); an unbound or overflowing set is unknown */ + if (!set || !set->layout || (desc->push_set && set == &desc->push_set->instantiate_set) || + set->geom_images.overflow || binding >= set->layout->binding_count) + return PVR_GEOM_OPAQUE_DESC; + /* its contents may change after this draw is recorded */ + if (set->layout->bindings[binding].flags & VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT) + return PVR_GEOM_OPAQUE_DESC; + e = pvr_geom_set_find((struct pvr_geom_set_images *)&set->geom_images, binding, element); + if (e) + pvr_geom_hazard_add_read(hz, e->range); + return PVR_GEOM_OPAQUE_NONE; +} + +/* Barrier precision: what this draw's geometry stage reads that a fragment job can write (the images its vertex + * program uploads: a G5P vertex program reads no other image), whether it writes memory (vertex stores, transform + * feedback), and whether its fragment program writes memory. Called once the draw's render is final (after the VDM + * split), so the record lands on the render the draw is in. Buffers are not listed: a fragment job writes one only + * through stores (opaque) or a linear attachment (opaque, pvr_geom_image_buffer_visible()). */ +static void +g5p_geom_hazard_note_draw(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g5p_pipeline *g, bool xfb) +{ + struct pvr_sub_cmd *sub = cmd_buffer->state.current_sub_cmd; + const struct pvr_descriptor_state *desc = &cmd_buffer->state.gfx_desc_state; + struct pvr_geom_hazard *hz; + const struct pvr_g5p_stage_uploads *up; + bool same; + + STATIC_ASSERT(PVR_MAX_DESCRIPTOR_SETS <= PVR_GEOM_HAZARD_MAX_SETS); + if (!sub || sub->type != PVR_SUB_CMD_TYPE_GRAPHICS || + pvr_geom_precise_level(&cmd_buffer->device->pdevice->dev_info) < 2) + return; + hz = &sub->gfx.geom_hz; + hz->draws++; + if (g->fs_side_effects) + hz->writes_opaque = true; + if (xfb || g->vs_side_effects) { + hz->reads_opaque = PVR_GEOM_OPAQUE_VS_WRITES; + return; + } + up = g->vs_uploads; + if (hz->reads_opaque || !up) + return; + + /* the same program and sets as the previous draw of this render: nothing new (a bound set's contents are fixed + * while the command buffer is recorded; update-after-bind bindings are opaque) */ + same = hz->last_pipeline == (const void *)g; + for (unsigned s = 0; s < PVR_MAX_DESCRIPTOR_SETS; s++) { + if (hz->sets[s] != (const void *)desc->sets[s]) { + same = false; + hz->sets[s] = desc->sets[s]; + } + } + hz->set_count = PVR_MAX_DESCRIPTOR_SETS; + hz->last_pipeline = g; + if (same) + return; + + const unsigned n = up->vtex ? up->vtex->count : up->count; + for (unsigned i = 0; i < n && !hz->reads_opaque; i++) { + enum pvr_geom_opaque why; + + if (up->vtex) { + const struct pco_g5p_upload *u = &up->vtex->u[i]; + + if (u->kind != PCO_G5P_UPLOAD_IMAGE) + continue; + why = g5p_geom_read_image(hz, desc, u->set, u->binding, u->element); + } else { + const struct pvr_g5p_stage_upload *u = &up->u[i]; + + if (u->kind != PCO_G5P_UPLOAD_IMAGE) + continue; + why = g5p_geom_read_image(hz, desc, u->set, u->binding, u->element); + } + if (why) + hz->reads_opaque = why; + } +} + VkResult PVR_PER_ARCH(g5p_cmd_draw)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g5p_draw *draw) { @@ -2513,6 +2602,8 @@ PVR_PER_ARCH(g5p_cmd_draw)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g return result; if (g->fs_depth_feedback) cs->current_sub_cmd->gfx.has_depth_feedback = true; + /* barrier precision: after the last change of program variant (xfb, one-layer, LOD-bias, punch) */ + g5p_geom_hazard_note_draw(cmd_buffer, g, xfb); /* the clip: the render area within the attachment, cut to the scissor * and to the viewport. A clip smaller than the attachment is the A9 ICD's diff --git a/src/imagination/vulkan/pvr_arch_image.c b/src/imagination/vulkan/pvr_arch_image.c index c9e6167a919..786d52291b5 100644 --- a/src/imagination/vulkan/pvr_arch_image.c +++ b/src/imagination/vulkan/pvr_arch_image.c @@ -20,6 +20,9 @@ #include "pvr_macros.h" #include "pvr_physical_device.h" #include "pvr_tex_state.h" +#include "pvr_pass_log.h" +#include +#include "vk_format.h" #include "pvr_ycbcr.h" #include "g5p_texel_defs.h" #include "util/log.h" @@ -283,6 +286,15 @@ VkResult PVR_PER_ARCH(CreateImageView)(VkDevice _device, *pView = pvr_image_view_to_handle(iview); + /* PVR_DEBUG=pass_log: a view of an imported or multi-planar image (the video planes) */ + if (pvr_pass_log_enabled() && + (image->vk.external_handle_types || vk_format_get_plane_count(image->vk.format) > 1)) + pvr_pass_log_printf("V img=@%" PRIx64 " fmt=%s view=%s %ux%u planes=%u ext=%u aspect=%x tiling=%s", + image->dev_addr.addr, pvr_pass_log_format(image->vk.format), + pvr_pass_log_format(iview->vk.format), iview->vk.extent.width, iview->vk.extent.height, + vk_format_get_plane_count(image->vk.format), image->vk.external_handle_types != 0, + iview->vk.aspects, image->memlayout == PVR_MEMLAYOUT_LINEAR ? "lin" : "twd"); + return VK_SUCCESS; err_vk_image_view_destroy: diff --git a/src/imagination/vulkan/pvr_arch_job_compute.c b/src/imagination/vulkan/pvr_arch_job_compute.c index 92b2fa2ac79..43d09444f80 100644 --- a/src/imagination/vulkan/pvr_arch_job_compute.c +++ b/src/imagination/vulkan/pvr_arch_job_compute.c @@ -206,6 +206,7 @@ static void pvr_compute_job_ws_submit_info_init( submit_info->job_num = device->global_cmd_buffer_submit_count; submit_info->wait = wait; + submit_info->stamp = sub_cmd->g5p_stamp; pvr_submit_info_stream_init(ctx, sub_cmd, submit_info); pvr_submit_info_ext_stream_init(ctx, submit_info); diff --git a/src/imagination/vulkan/pvr_arch_job_render.c b/src/imagination/vulkan/pvr_arch_job_render.c index f03122f9774..872c303a8a6 100644 --- a/src/imagination/vulkan/pvr_arch_job_render.c +++ b/src/imagination/vulkan/pvr_arch_job_render.c @@ -1565,6 +1565,7 @@ static void pvr_render_job_ws_submit_info_init( submit_info->frame_num = ctx->device->global_queue_present_count; submit_info->job_num = ctx->device->global_cmd_buffer_submit_count; + submit_info->stamp = job->g5p_stamp; pvr_render_job_ws_geometry_state_init(ctx, job, diff --git a/src/imagination/vulkan/pvr_arch_pipeline.c b/src/imagination/vulkan/pvr_arch_pipeline.c index 69992ff1301..9511bbebdf2 100644 --- a/src/imagination/vulkan/pvr_arch_pipeline.c +++ b/src/imagination/vulkan/pvr_arch_pipeline.c @@ -3661,6 +3661,52 @@ pvr_create_renderpass_state(const VkGraphicsPipelineCreateInfo *const info, }; } +/* PVR_DEBUG=pass_log: the pipeline's program ids and sampler census, and its F line (pvr_pass_log.h) */ +static void +pvr_pass_log_pipeline(const VkGraphicsPipelineCreateInfo *pCreateInfo, + struct pvr_graphics_pipeline *gfx_pipeline, + const struct vk_graphics_pipeline_state *state) +{ + struct pvr_pass_log_pipe *pl = &gfx_pipeline->pass_log; + const struct vk_pipeline_layout *layout = gfx_pipeline->base.layout; + + memset(pl, 0, sizeof(*pl)); + for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { + const VkPipelineShaderStageCreateInfo *stage = &pCreateInfo->pStages[i]; + if (stage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) + pl->fs_id = pvr_pass_log_stage_id(stage); + else if (stage->stage == VK_SHADER_STAGE_VERTEX_BIT) + pl->vs_id = pvr_pass_log_stage_id(stage); + } + for (uint32_t s = 0; layout && s < layout->set_count; s++) { + if (!layout->set_layouts[s]) + continue; + const struct pvr_descriptor_set_layout *sl = vk_to_pvr_descriptor_set_layout(layout->set_layouts[s]); + for (uint32_t b = 0; b < sl->binding_count; b++) { + const struct pvr_descriptor_set_layout_binding *lb = &sl->bindings[b]; + if (lb->type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER && + lb->type != VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) + continue; + pl->samplers += lb->descriptor_count; + for (uint32_t i = 0; lb->immutable_samplers && i < lb->immutable_sampler_count; i++) + if (lb->immutable_samplers[i] && lb->immutable_samplers[i]->vk.ycbcr_conversion) + pl->ycbcr++; + } + } + + bool blend = false; + uint32_t cwm = 0; + if (state->cb) { + for (uint32_t i = 0; i < state->cb->attachment_count && i < 8; i++) { + blend |= state->cb->attachments[i].blend_enable; + cwm |= (uint32_t)(state->cb->attachments[i].write_mask & 0xf) << (4 * i); + } + } + pvr_pass_log_printf("F pipe=%08x vs=%08x samplers=%u ycbcr=%u blend=%u ztest=%u zwrite=%u cwm=%x", pl->fs_id, + pl->vs_id, pl->samplers, pl->ycbcr, blend, state->ds ? state->ds->depth.test_enable : 0, + state->ds ? state->ds->depth.write_enable : 0, cwm); +} + static VkResult pvr_graphics_pipeline_init(struct pvr_device *device, struct vk_pipeline_cache *cache, @@ -3748,6 +3794,9 @@ pvr_graphics_pipeline_init(struct pvr_device *device, if (result != VK_SUCCESS) goto err_pipeline_finish; + if (pvr_pass_log_enabled()) + pvr_pass_log_pipeline(pCreateInfo, gfx_pipeline, &state); + return VK_SUCCESS; err_pipeline_finish: diff --git a/src/imagination/vulkan/pvr_arch_queue.c b/src/imagination/vulkan/pvr_arch_queue.c index fc264dcd2d1..d614c5589a1 100644 --- a/src/imagination/vulkan/pvr_arch_queue.c +++ b/src/imagination/vulkan/pvr_arch_queue.c @@ -32,6 +32,7 @@ #include "util/os_time.h" #include "pvr_bo_log.h" #include "pvr_g9p.h" +#include "pvr_g5p_reuse.h" #include "pvr_queue.h" #include "pvr_g5p_layout.h" #include "pvr_rt_dataset.h" @@ -55,6 +56,7 @@ #include "pvr_job_transfer.h" #include "pvr_limits.h" #include "pvr_macros.h" +#include "pvr_pass_log.h" #include "pvr_physical_device.h" #include "pvr_query.h" #include "pvr_buffer.h" @@ -160,6 +162,10 @@ static VkResult pvr_queue_init(struct pvr_device *device, if (result != VK_SUCCESS) goto err_query_ctx_destroy; + result = pvr_g5p_queue_stamp_init(device, queue, index_in_family); + if (result != VK_SUCCESS) + goto err_gfx_ctx_destroy; + queue->device = device; queue->gfx_ctx = gfx_ctx; queue->compute_ctx = compute_ctx; @@ -170,6 +176,9 @@ static VkResult pvr_queue_init(struct pvr_device *device, return VK_SUCCESS; +err_gfx_ctx_destroy: + pvr_arch_render_ctx_destroy(gfx_ctx); + err_query_ctx_destroy: pvr_arch_compute_ctx_destroy(query_ctx); @@ -225,6 +234,9 @@ VkResult pvr_arch_queues_create(struct pvr_device *device, static void pvr_queue_finish(struct pvr_queue *queue) { + if (queue->geom_defer.sync) + vk_sync_destroy(&queue->device->vk, queue->geom_defer.sync); + for (uint32_t i = 0; i < ARRAY_SIZE(queue->next_job_wait_sync); i++) { if (queue->next_job_wait_sync[i]) vk_sync_destroy(&queue->device->vk, queue->next_job_wait_sync[i]); @@ -240,6 +252,7 @@ static void pvr_queue_finish(struct pvr_queue *queue) pvr_arch_compute_ctx_destroy(queue->compute_ctx); if (queue->transfer_ctx) pvr_arch_transfer_ctx_destroy(queue->transfer_ctx); + pvr_g5p_queue_stamp_finish(queue->device, queue); vk_queue_finish(&queue->vk); } @@ -258,15 +271,12 @@ static void pvr_update_job_syncs(struct pvr_device *device, enum pvr_job_type submitted_job_type) { if (queue->next_job_wait_sync[submitted_job_type]) { - vk_sync_destroy(&device->vk, - queue->next_job_wait_sync[submitted_job_type]); + pvr_g5p_sync_put(device, queue->next_job_wait_sync[submitted_job_type]); queue->next_job_wait_sync[submitted_job_type] = NULL; } - if (queue->last_job_signal_sync[submitted_job_type]) { - vk_sync_destroy(&device->vk, - queue->last_job_signal_sync[submitted_job_type]); - } + if (queue->last_job_signal_sync[submitted_job_type]) + pvr_g5p_sync_put(device, queue->last_job_signal_sync[submitted_job_type]); queue->g5p_src_done[submitted_job_type] = false; queue->last_job_signal_sync[submitted_job_type] = new_signal_sync; @@ -285,13 +295,13 @@ g5p_merge_syncs(struct pvr_device *device, struct vk_sync *a, struct vk_sync *b, waits[n++] = (struct vk_sync_wait){ .sync = a, .stage_mask = ~(VkPipelineStageFlags2)0 }; if (b) waits[n++] = (struct vk_sync_wait){ .sync = b, .stage_mask = ~(VkPipelineStageFlags2)0 }; - result = vk_sync_create(&device->vk, &device->pdevice->sync_type, 0U, 0UL, out); + result = pvr_g5p_sync_get(device, out); if (result != VK_SUCCESS) return result; const struct vk_sync_signal signal = { .sync = *out, .stage_mask = ~(VkPipelineStageFlags2)0 }; result = device->ws->ops->null_job_submit(device->ws, waits, n, (struct vk_sync_signal *)&signal); if (result != VK_SUCCESS) { - vk_sync_destroy(&device->vk, *out); + pvr_g5p_sync_put(device, *out); *out = NULL; } return result; @@ -314,20 +324,12 @@ pvr_process_graphics_cmd_for_view(struct pvr_device *device, (view_index + job->ds.base_array_layer)); job->view_state.view_index = view_index; - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &geom_signal_sync); + result = pvr_g5p_sync_get(device, &geom_signal_sync); if (result != VK_SUCCESS) return result; if (job->run_frag) { - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &frag_signal_sync); + result = pvr_g5p_sync_get(device, &frag_signal_sync); if (result != VK_SUCCESS) goto err_destroy_geom_sync; } @@ -351,8 +353,10 @@ pvr_process_graphics_cmd_for_view(struct pvr_device *device, if (result != VK_SUCCESS) goto err_destroy_frag_sync; pvr_update_job_syncs(device, queue, geom_signal_sync, PVR_JOB_TYPE_GEOM); - if (job->run_frag) + if (job->run_frag) { pvr_update_job_syncs(device, queue, frag_signal_sync, PVR_JOB_TYPE_FRAG); + queue->geom_defer.frag_last_noop = true; + } return VK_SUCCESS; } @@ -372,6 +376,8 @@ pvr_process_graphics_cmd_for_view(struct pvr_device *device, /* First submit must not touch fragment work. */ job->geometry_terminate = false; job->run_frag = false; + /* the second submit's stamp covers this one (same geometry queue) */ + job->g5p_stamp = (struct pvr_winsys_stamp){ 0 }; result = pvr_arch_render_job_submit( queue->gfx_ctx, @@ -435,6 +441,7 @@ pvr_process_graphics_cmd_for_view(struct pvr_device *device, goto err_destroy_frag_sync; frag_wait = g5p_frag_wait; } + job->g5p_stamp = pvr_g5p_queue_stamp_next(queue); result = pvr_arch_render_job_submit(queue->gfx_ctx, &sub_cmd->job, @@ -442,8 +449,10 @@ pvr_process_graphics_cmd_for_view(struct pvr_device *device, frag_wait, geom_signal_sync, frag_signal_sync); + if (result == VK_SUCCESS) + pvr_g5p_queue_stamp_issued(queue, job->g5p_stamp); if (g5p_frag_wait) - vk_sync_destroy(&device->vk, g5p_frag_wait); + pvr_g5p_sync_put(device, g5p_frag_wait); if (original_ctrl_stream_addr.addr > 0) job->ctrl_stream_addr = original_ctrl_stream_addr; @@ -614,8 +623,11 @@ pvr_process_graphics_cmd_for_view(struct pvr_device *device, pvr_update_job_syncs(device, queue, geom_signal_sync, PVR_JOB_TYPE_GEOM); - if (job->run_frag) + if (job->run_frag) { pvr_update_job_syncs(device, queue, frag_signal_sync, PVR_JOB_TYPE_FRAG); + /* barrier precision: what this fragment job writes (pvr_geom_hazard.h) */ + pvr_geom_defer_note_frag(&queue->geom_defer, &sub_cmd->geom_hz); + } /* ... and later transfer-stage barriers wait for its fragments */ if (sub_cmd->g5p_transfer && job->run_frag) { @@ -633,19 +645,90 @@ pvr_process_graphics_cmd_for_view(struct pvr_device *device, err_destroy_frag_sync: if (frag_signal_sync) - vk_sync_destroy(&device->vk, frag_signal_sync); + pvr_g5p_sync_put(device, frag_signal_sync); err_destroy_geom_sync: - vk_sync_destroy(&device->vk, geom_signal_sync); + pvr_g5p_sync_put(device, geom_signal_sync); return result; } +/* Barrier precision (pvr_geom_hazard.h): before a render's geometry job, take + * the deferred FRAG -> GEOM wait when its geometry stage can observe a covered + * fragment job's writes; otherwise leave it for the next render. Runs before + * anything that reads next_job_wait_sync[GEOM] (the split first kick, the noop + * render's CPU wait, the vertex realign copy). + */ +static VkResult +pvr_geom_defer_resolve(struct pvr_device *device, + struct pvr_queue *queue, + const struct pvr_sub_cmd_gfx *sub_cmd) +{ + struct pvr_geom_defer *d = &queue->geom_defer; + const struct pvr_geom_hazard *hz = &sub_cmd->geom_hz; + static const char *const why_str[] = { "-", "hit", "vs", "fs" }; + const char *act; + enum pvr_geom_need need; + VkResult result; + + if (!d->sync) + return VK_SUCCESS; + + if (d->armed_seq <= d->synced_seq || + vk_sync_wait(&device->vk, d->sync, 0, VK_SYNC_WAIT_COMPLETE, 0) == VK_SUCCESS) { + /* the covered fragment jobs are done (or seen done at a barrier) */ + pvr_g5p_sync_put(device, d->sync); + d->sync = NULL; + pvr_geom_defer_advance(d, d->armed_seq); + d->n_done++; + need = PVR_GEOM_NEED_NONE; + act = "done"; + } else { + need = pvr_geom_defer_need(d, hz); + if (need == PVR_GEOM_NEED_NONE) { + d->n_drop++; + act = "drop"; + } else { + struct vk_sync *merged; + + result = g5p_merge_syncs(device, queue->next_job_wait_sync[PVR_JOB_TYPE_GEOM], d->sync, &merged); + if (result != VK_SUCCESS) + return result; + if (queue->next_job_wait_sync[PVR_JOB_TYPE_GEOM]) + pvr_g5p_sync_put(device, queue->next_job_wait_sync[PVR_JOB_TYPE_GEOM]); + queue->next_job_wait_sync[PVR_JOB_TYPE_GEOM] = merged; + pvr_g5p_sync_put(device, d->sync); + d->sync = NULL; + /* this geometry job, and every later one (geometry jobs run in order), follows the covered jobs */ + pvr_geom_defer_advance(d, d->armed_seq); + d->n_keep++; + d->keep_hit += need == PVR_GEOM_NEED_HIT; + d->keep_vs += need == PVR_GEOM_NEED_VS; + d->keep_fs += need == PVR_GEOM_NEED_FS; + act = "keep"; + } + } + + if (pvr_pass_log_enabled()) + pvr_pass_log_printf("G t=%" PRIu64 " pass=%u act=%s why=%s draws=%u reads=%u vsop=%u writes=%u fsop=%u " + "armed=%" PRIu64 " synced=%" PRIu64 " fragw=%u", + pvr_pass_log_now_ns(), sub_cmd->pass_log_serial, act, why_str[need], hz->draws, + hz->read_count, hz->reads_opaque, hz->write_count, hz->writes_opaque, + d->armed_seq, d->synced_seq, d->write_count); + return VK_SUCCESS; +} + static VkResult pvr_process_graphics_cmd(struct pvr_device *device, struct pvr_queue *queue, struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd_gfx *sub_cmd) { const pvr_dev_addr_t ds_addr = sub_cmd->job.ds.addr; + { + VkResult result = pvr_geom_defer_resolve(device, queue, sub_cmd); + + if (result != VK_SUCCESS) + return result; + } PVR_G5P_HOOK(xfb_before_job, device, cmd_buffer, sub_cmd) if (util_dynarray_num_elements(&sub_cmd->g9p_realigns, char)) { @@ -693,11 +776,16 @@ static VkResult pvr_process_graphics_cmd(struct pvr_device *device, u_foreach_bit (view_idx, sub_cmd->view_mask) { VkResult result; + /* PVR_DEBUG=pass_log: the winsys' submit lines name this render (pvr_pass_log.h) */ + if (pvr_pass_log_enabled()) + pvr_pass_log_set_current(sub_cmd->pass_log_serial); result = pvr_process_graphics_cmd_for_view(device, queue, cmd_buffer, sub_cmd, view_idx); + if (pvr_pass_log_enabled()) + pvr_pass_log_set_current(0); sub_cmd->job.ds.addr = ds_addr; if (result != VK_SUCCESS) @@ -715,23 +803,21 @@ static VkResult pvr_process_compute_cmd(struct pvr_device *device, struct vk_sync *sync; VkResult result; - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &sync); + result = pvr_g5p_sync_get(device, &sync); if (result != VK_SUCCESS) return result; + sub_cmd->g5p_stamp = pvr_g5p_queue_stamp_next(queue); result = pvr_arch_compute_job_submit( queue->compute_ctx, sub_cmd, queue->next_job_wait_sync[PVR_JOB_TYPE_COMPUTE], sync); if (result != VK_SUCCESS) { - vk_sync_destroy(&device->vk, sync); + pvr_g5p_sync_put(device, sync); return result; } + pvr_g5p_queue_stamp_issued(queue, sub_cmd->g5p_stamp); /* G9P_SYNC: wait for each compute job too */ if (PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g9p) && getenv("G9P_SYNC") && @@ -753,11 +839,7 @@ static VkResult pvr_process_transfer_cmds(struct pvr_device *device, struct vk_sync *sync; VkResult result; - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &sync); + result = pvr_g5p_sync_get(device, &sync); if (result != VK_SUCCESS) return result; @@ -801,7 +883,7 @@ static VkResult pvr_process_transfer_cmds(struct pvr_device *device, queue->next_job_wait_sync[PVR_JOB_TYPE_TRANSFER], sync); if (result != VK_SUCCESS) { - vk_sync_destroy(&device->vk, sync); + pvr_g5p_sync_put(device, sync); return result; } @@ -900,23 +982,21 @@ static VkResult pvr_process_query_cmd(struct pvr_device *device, * commands? */ - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &sync); + result = pvr_g5p_sync_get(device, &sync); if (result != VK_SUCCESS) return result; + sub_cmd->g5p_stamp = pvr_g5p_queue_stamp_next(queue); result = pvr_arch_compute_job_submit(queue->query_ctx, sub_cmd, queue->next_job_wait_sync[PVR_JOB_TYPE_QUERY], sync); if (result != VK_SUCCESS) { - vk_sync_destroy(&device->vk, sync); + pvr_g5p_sync_put(device, sync); return result; } + pvr_g5p_queue_stamp_issued(queue, sub_cmd->g5p_stamp); pvr_update_job_syncs(device, queue, sync, PVR_JOB_TYPE_QUERY); @@ -930,8 +1010,16 @@ pvr_process_event_cmd_barrier(struct pvr_device *device, { const uint32_t src_mask = sub_cmd->wait_for_stage_mask; const uint32_t dst_mask = sub_cmd->wait_at_stage_mask; - struct vk_sync_wait wait_syncs[PVR_JOB_TYPE_MAX + 1]; + const unsigned precise = + sub_cmd->geom_precise ? pvr_geom_precise_level(&device->pdevice->dev_info) : 0; + /* the sources the geometry stage waits for (pvr_geom_hazard.h, level >= 1: per-barrier pairing) */ + const uint32_t geom_src_mask = precise ? (sub_cmd->geom_wait_for_stage_mask & src_mask) : src_mask; + /* the sources, then per destination stage its waits (at most the sources and next_job_wait_sync) */ + struct vk_sync_wait wait_syncs[2 * PVR_JOB_TYPE_MAX + 1]; + uint32_t wait_stage[PVR_JOB_TYPE_MAX]; + struct pvr_geom_defer *defer = &queue->geom_defer; uint32_t src_wait_count = 0; + bool geom_deferred = false; VkResult result; assert(!(src_mask & @@ -951,9 +1039,14 @@ pvr_process_event_cmd_barrier(struct pvr_device *device, continue; if (vk_sync_wait(&device->vk, s, 0, VK_SYNC_WAIT_COMPLETE, 0) == VK_SUCCESS) { queue->g5p_src_done[stage] = true; + /* a submitted fragment job is done, so every earlier one is (ring order): none can race a later + * geometry job. Not after a noop render, whose sync was signalled without waiting. */ + if (stage == PVR_JOB_TYPE_FRAG && !defer->frag_last_noop) + pvr_geom_defer_advance(defer, defer->frag_seq); continue; } } + wait_stage[src_wait_count] = stage; wait_syncs[src_wait_count++] = (struct vk_sync_wait){ .sync = s, .stage_mask = ~(VkPipelineStageFlags2)0, @@ -961,21 +1054,59 @@ pvr_process_event_cmd_barrier(struct pvr_device *device, }; } + /* PVR_GEOM_PRECISE=2: this barrier's FRAG -> GEOM wait goes to the queue's + * deferred wait; the next render whose geometry stage can observe a covered + * fragment job's writes takes it (pvr_geom_defer_resolve()) */ + if (precise >= 2 && (dst_mask & PVR_PIPELINE_STAGE_GEOM_BIT) && + (geom_src_mask & PVR_PIPELINE_STAGE_FRAG_BIT)) { + for (uint32_t i = 0; i < src_wait_count; i++) { + struct vk_sync *merged; + + if (wait_stage[i] != PVR_JOB_TYPE_FRAG) + continue; + result = g5p_merge_syncs(device, defer->sync, wait_syncs[i].sync, &merged); + if (result != VK_SUCCESS) + return result; + if (defer->sync) + pvr_g5p_sync_put(device, defer->sync); + defer->sync = merged; + defer->armed_seq = defer->frag_seq; + defer->n_defer++; + geom_deferred = true; + } + } + + if (pvr_pass_log_enabled()) + pvr_pass_log_printf("B t=%" PRIu64 " src=%x dst=%x waits=%u gsrc=%x gdefer=%u gpending=%u " + "gdefers=%u gdrops=%u gkeeps=%u gdone=%u gkeep_hit=%u gkeep_vs=%u gkeep_fs=%u", + pvr_pass_log_now_ns(), src_mask, dst_mask, src_wait_count, geom_src_mask, + geom_deferred, defer->sync != NULL, defer->n_defer, defer->n_drop, defer->n_keep, + defer->n_done, defer->keep_hit, defer->keep_vs, defer->keep_fs); + /* No previous src jobs that need finishing so no need for a barrier. */ if (src_wait_count == 0) return VK_SUCCESS; u_foreach_bit (stage, dst_mask) { - uint32_t wait_count = src_wait_count; + uint32_t wait_count = 0; struct vk_sync_signal signal; struct vk_sync *signal_sync; - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &signal_sync); + for (uint32_t i = 0; i < src_wait_count; i++) { + if (stage == PVR_JOB_TYPE_GEOM) { + if (!(geom_src_mask & BITFIELD_BIT(wait_stage[i]))) + continue; + if (geom_deferred && wait_stage[i] == PVR_JOB_TYPE_FRAG) + continue; + } + wait_syncs[src_wait_count + wait_count++] = wait_syncs[i]; + } + /* the geometry stage has nothing left to wait for here */ + if (!wait_count) + continue; + + result = pvr_g5p_sync_get(device, &signal_sync); if (result != VK_SUCCESS) return result; @@ -986,7 +1117,7 @@ pvr_process_event_cmd_barrier(struct pvr_device *device, }; if (queue->next_job_wait_sync[stage]) { - wait_syncs[wait_count++] = (struct vk_sync_wait){ + wait_syncs[src_wait_count + wait_count++] = (struct vk_sync_wait){ .sync = queue->next_job_wait_sync[stage], .stage_mask = ~(VkPipelineStageFlags2)0, .wait_value = 0, @@ -994,16 +1125,16 @@ pvr_process_event_cmd_barrier(struct pvr_device *device, } result = device->ws->ops->null_job_submit(device->ws, - wait_syncs, + &wait_syncs[src_wait_count], wait_count, &signal); if (result != VK_SUCCESS) { - vk_sync_destroy(&device->vk, signal_sync); + pvr_g5p_sync_put(device, signal_sync); return result; } if (queue->next_job_wait_sync[stage]) - vk_sync_destroy(&device->vk, queue->next_job_wait_sync[stage]); + pvr_g5p_sync_put(device, queue->next_job_wait_sync[stage]); queue->next_job_wait_sync[stage] = signal_sync; } @@ -1151,11 +1282,7 @@ pvr_process_event_cmd_wait(struct pvr_device *device, assert(wait_count <= (sub_cmd->count + 1)); - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &signal_sync); + result = pvr_g5p_sync_get(device, &signal_sync); if (result != VK_SUCCESS) goto err_free_waits; @@ -1170,12 +1297,12 @@ pvr_process_event_cmd_wait(struct pvr_device *device, wait_count, &signal); if (result != VK_SUCCESS) { - vk_sync_destroy(&device->vk, signal.sync); + pvr_g5p_sync_put(device, signal.sync); goto err_free_waits; } if (queue->next_job_wait_sync[stage]) - vk_sync_destroy(&device->vk, queue->next_job_wait_sync[stage]); + pvr_g5p_sync_put(device, queue->next_job_wait_sync[stage]); queue->next_job_wait_sync[stage] = signal.sync; } @@ -1233,6 +1360,8 @@ static VkResult pvr_process_cmd_buffer(struct pvr_device *device, /* a refused render pass (pvr_arch_cmd_buffer.c): nothing to submit */ if (PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g5p) && sub_cmd->gfx.g5p_refused) { + if (pvr_pass_log_enabled()) + pvr_pass_log_printf("R pass=%u refused", sub_cmd->gfx.pass_log_serial); if (!sub_cmd->is_resume) { suspended_data->rts = NULL; suspended_data->query_pool = NULL; @@ -1633,11 +1762,7 @@ static VkResult pvr_process_queue_waits(struct pvr_queue *queue, }; } - result = vk_sync_create(&device->vk, - &device->pdevice->sync_type, - 0U, - 0UL, - &queue->next_job_wait_sync[i]); + result = pvr_g5p_sync_get(device, &queue->next_job_wait_sync[i]); if (result != VK_SUCCESS) { queue->next_job_wait_sync[i] = prev_wait; goto err_free_waits; @@ -1656,7 +1781,7 @@ static VkResult pvr_process_queue_waits(struct pvr_queue *queue, if (result != VK_SUCCESS) goto err_free_waits; if (prev_wait) - vk_sync_destroy(&device->vk, prev_wait); + pvr_g5p_sync_put(device, prev_wait); } STACK_ARRAY_FINISH(stage_waits); @@ -1677,6 +1802,9 @@ static VkResult pvr_driver_queue_submit_jobs(struct vk_queue *queue, VkResult result; const int64_t g9p_tc = os_time_get_nano(); + if (pvr_pass_log_enabled()) + pvr_pass_log_printf("Q t=%" PRIu64 " cmdbufs=%u waits=%u signals=%u", pvr_pass_log_now_ns(), + submit->command_buffer_count, submit->wait_count, submit->signal_count); /* a semaphore wait's second synchronization scope is its own batch; a batch * without command buffers orders only its signals */ const bool waitonly_local = PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g5p) && !submit->command_buffer_count && submit->wait_count; @@ -1702,11 +1830,14 @@ static VkResult pvr_driver_queue_submit_jobs(struct vk_queue *queue, struct pvr_suspended_data suspended_data = {0}; for (uint32_t i = 0U; i < submit->command_buffer_count; i++) { - result = pvr_process_cmd_buffer( - device, - driver_queue, - container_of(submit->command_buffers[i], struct pvr_cmd_buffer, vk), - &suspended_data); + struct pvr_cmd_buffer *cmd_buffer = + container_of(submit->command_buffers[i], struct pvr_cmd_buffer, vk); + + result = pvr_process_cmd_buffer(device, driver_queue, cmd_buffer, &suspended_data); + /* G5P reuse: its blocks are free again once this queue's stamp passes + * the last point issued so far (jobs submitted before a failure too) */ + if (driver_queue->g5p_stamp_syncobj) + cmd_buffer->g5p_retire[driver_queue->g5p_index] = driver_queue->g5p_stamp_issued; if (result != VK_SUCCESS) return result; } diff --git a/src/imagination/vulkan/pvr_cmd_buffer.h b/src/imagination/vulkan/pvr_cmd_buffer.h index 622d85ea9b9..6b4a13d010d 100644 --- a/src/imagination/vulkan/pvr_cmd_buffer.h +++ b/src/imagination/vulkan/pvr_cmd_buffer.h @@ -19,8 +19,10 @@ #include "pvr_common.h" #include "util/ralloc.h" #include "pvr_framebuffer.h" +#include "pvr_geom_hazard.h" #include "pvr_job_render.h" #include "pvr_hw_pass.h" +#include "pvr_pass_log.h" #include "pvr_types.h" #include "util/perf/u_trace.h" @@ -151,6 +153,11 @@ struct pvr_dynamic_render_info { }; struct pvr_sub_cmd_gfx { + /* PVR_DEBUG=pass_log (pvr_pass_log.h): its draws, and its serial once recorded (0: none) */ + struct pvr_pass_log_stats pass_log; + uint32_t pass_log_serial; + /* barrier precision (pvr_geom_hazard.h): what its geometry stage reads and its fragment job writes */ + struct pvr_geom_hazard geom_hz; /* a vk_meta blit's render pass: transfer work for barriers (pvr_arch_g5p_meta.c) */ bool g5p_transfer; /* a render pass G5P refuses (pvr_arch_g5p_job_init(): a shape it cannot run yet, named on stderr): @@ -255,6 +262,9 @@ struct pvr_sub_cmd_gfx { }; struct pvr_sub_cmd_compute { + /* G5P submit reuse: what its job signals (pvr_g5p_reuse.h) */ + struct pvr_winsys_stamp g5p_stamp; + /* Control stream builder object. */ struct pvr_csb control_stream; @@ -317,6 +327,14 @@ struct pvr_sub_cmd_event { uint32_t wait_for_stage_mask; /* Stages to wait at. */ uint32_t wait_at_stage_mask; + /* An application barrier (vkCmdPipelineBarrier2) whose geometry + * wait may be narrowed (pvr_geom_hazard.h): the stages the + * barriers with a geometry destination wait for. Internal barriers + * (split renders, stencil store/load, queries) leave it false and + * keep their full wait. + */ + bool geom_precise; + uint32_t geom_wait_for_stage_mask; } barrier; }; }; @@ -505,6 +523,8 @@ struct pvr_cmd_buffer_xfb_state { }; struct pvr_cmd_buffer_state { + /* PVR_DEBUG=pass_log: the previous render's first colour target (address) in this command buffer */ + uint64_t pass_log_prev_target; /* Pipeline binding. */ const struct pvr_graphics_pipeline *gfx_pipeline; @@ -686,6 +706,10 @@ struct pvr_cmd_buffer { struct pvr_suballoc_bo *block; uint32_t used; } g5p_upload[2]; + /* G5P submit reuse: per queue, the stamp point after which this buffer's + * last submission there has completed; 0: not submitted there since its + * last reset (pvr_g5p_reuse.h) */ + uint64_t g5p_retire[PVR_MAX_QUEUES]; struct linear_ctx *g5p_views; struct list_head sub_cmds; diff --git a/src/imagination/vulkan/pvr_descriptor_set.h b/src/imagination/vulkan/pvr_descriptor_set.h index 4bb2cf56ef7..eed563da3e3 100644 --- a/src/imagination/vulkan/pvr_descriptor_set.h +++ b/src/imagination/vulkan/pvr_descriptor_set.h @@ -21,6 +21,7 @@ #include "vk_util.h" #include "pvr_common.h" +#include "pvr_geom_hazard.h" #include "pvr_macros.h" #include "pvr_types.h" @@ -83,6 +84,13 @@ struct pvr_descriptor_set { pvr_dev_addr_t dev_addr; /** Descriptor set device address. */ void *mapping; /** Descriptor set CPU mapping. */ + /** PVR_DEBUG=pass_log: bindings (< 64) last written with an imported or multi-planar image */ + uint64_t pass_log_ext; + uint64_t pass_log_tex, pass_log_lin, pass_log_lin_pot, pass_log_lin_big; + + /** barrier precision (pvr_geom_hazard.h): images of its pre-raster image descriptors */ + struct pvr_geom_set_images geom_images; + struct pvr_buffer_descriptor dynamic_buffers[]; }; diff --git a/src/imagination/vulkan/pvr_device.c b/src/imagination/vulkan/pvr_device.c index a92172609c2..48cdc1a94ed 100644 --- a/src/imagination/vulkan/pvr_device.c +++ b/src/imagination/vulkan/pvr_device.c @@ -634,20 +634,35 @@ VkResult pvr_bind_memory(struct pvr_device *device, assert(offset % alignment == 0); assert(offset < mem->bo->size); - result = device->ws->ops->heap_alloc(device->heaps.general_heap, - virt_size, - alignment, - &vma); - if (result != VK_SUCCESS) { - mesa_loge("pvr: no GPU address space for %" PRIu64 " bytes (alignment %" PRIu64 ")", - (uint64_t)virt_size, (uint64_t)alignment); - goto err_out; - } + if (mem->vk.import_handle_type && device->ws->ops->vma_map_imported) { + result = device->ws->ops->vma_map_imported(device->heaps.general_heap, + mem->bo, + offset, + size, + alignment, + &vma, + &dev_addr); + if (result != VK_SUCCESS) { + mesa_loge("pvr: mapping imported %" PRIu64 " bytes into the GPU failed (%d)", + (uint64_t)size, result); + goto err_out; + } + } else { + result = device->ws->ops->heap_alloc(device->heaps.general_heap, + virt_size, + alignment, + &vma); + if (result != VK_SUCCESS) { + mesa_loge("pvr: no GPU address space for %" PRIu64 " bytes (alignment %" PRIu64 ")", + (uint64_t)virt_size, (uint64_t)alignment); + goto err_out; + } - result = device->ws->ops->vma_map(vma, mem->bo, offset, size, &dev_addr); - if (result != VK_SUCCESS) { - mesa_loge("pvr: mapping %" PRIu64 " bytes into the GPU failed (%d)", (uint64_t)size, result); - goto err_free_vma; + result = device->ws->ops->vma_map(vma, mem->bo, offset, size, &dev_addr); + if (result != VK_SUCCESS) { + mesa_loge("pvr: mapping %" PRIu64 " bytes into the GPU failed (%d)", (uint64_t)size, result); + goto err_free_vma; + } } *dev_addr_out = dev_addr; diff --git a/src/imagination/vulkan/pvr_device.h b/src/imagination/vulkan/pvr_device.h index d28e7d32198..5742750a6e8 100644 --- a/src/imagination/vulkan/pvr_device.h +++ b/src/imagination/vulkan/pvr_device.h @@ -179,6 +179,9 @@ struct pvr_device { struct pvr_suballocator suballoc_cmd_pds; struct pvr_suballocator suballoc_cmd_usc; + /* G5P submit reuse (pvr_g5p_reuse.h); NULL when off */ + struct pvr_g5p_reuse *g5p_reuse; + struct { struct pvr_pds_upload pds; struct pvr_suballoc_bo *usc; diff --git a/src/imagination/vulkan/pvr_g5p.h b/src/imagination/vulkan/pvr_g5p.h index 3c0c2f5c457..72a6ed0af8e 100644 --- a/src/imagination/vulkan/pvr_g5p.h +++ b/src/imagination/vulkan/pvr_g5p.h @@ -284,6 +284,9 @@ struct pvr_g5p_job { bool a7_pbe_a8; /* the A7, PVR_G3_A7_PBE=a8: the A8's PBE register words (diagnostics) */ bool a7_load; /* the A7: a LOADed target, upstream's load-op background */ uint64_t a7_bgnd1; /* the A7's load op: PDS_BGRND1_BASE, its texture state's data */ + /* what the background does, for PVR_DEBUG=pass_log: loads the targets (else clears them), and why */ + bool load_background; + bool partial_area; }; /* diff --git a/src/imagination/vulkan/pvr_g5p_nir.c b/src/imagination/vulkan/pvr_g5p_nir.c index a7a350a9287..5e56879e67a 100644 --- a/src/imagination/vulkan/pvr_g5p_nir.c +++ b/src/imagination/vulkan/pvr_g5p_nir.c @@ -679,6 +679,7 @@ g5p_nir(const uint32_t *spv, size_t words, mesa_shader_stage stage, const char * util_call_once(&once, g5p_init_options); struct spirv_capabilities caps = { .Shader = true, .Float16 = true, .Int16 = true, .Int8 = true, .Int64 = true, .Float64 = true, .TransformFeedback = true, + .FloatControls2 = true, /* user clip distances: the TA user planes (pvr_g5p_clip_distance_probe()) */ .ClipDistance = true }; struct spirv_to_nir_options opts = { diff --git a/src/imagination/vulkan/pvr_g5p_reuse.c b/src/imagination/vulkan/pvr_g5p_reuse.c new file mode 100644 index 00000000000..b91fc6dc17b --- /dev/null +++ b/src/imagination/vulkan/pvr_g5p_reuse.c @@ -0,0 +1,345 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Apple's A9 GPU (G5P): submit-time reuse (pvr_g5p_reuse.h). + */ + +#include "pvr_g5p_reuse.h" + +#include +#include +#include + +#include "pvr_bo.h" +#include "pvr_csb.h" +#include "pvr_device.h" +#include "pvr_physical_device.h" +#include "pvr_queue.h" +#include "util/u_debug.h" +#include "vk_alloc.h" +#include "vk_drm_syncobj.h" +#include "vk_sync.h" + +/* The command stream blocks retired by one command buffer, pending until + * every queue's stamp timeline has reached its point. */ +struct pvr_g5p_retired { + struct list_head link; + struct list_head bos; + uint32_t count; + uint64_t points[PVR_MAX_QUEUES]; +}; + +void pvr_g5p_reuse_init(struct pvr_device *device) +{ + const struct pvr_winsys_ops *ops = device->ws->ops; + struct pvr_g5p_reuse *r; + + device->g5p_reuse = NULL; + if (!PVR_HAS_FEATURE(&device->pdevice->dev_info, apple_g5p) || !pvr_g5p_reuse_option()) + return; + if (!ops->stamp_create || !ops->stamp_destroy || !ops->stamp_query || !ops->syncs_reset || + !vk_sync_type_is_drm_syncobj(&device->pdevice->sync_type)) + return; + + r = vk_zalloc(&device->vk.alloc, sizeof(*r), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + if (!r) + return; /* reuse is an optimisation: without it, the plain paths */ + + simple_mtx_init(&r->mtx, mtx_plain); + simple_mtx_init(&r->sync_mtx, mtx_plain); + list_inithead(&r->free_blocks); + list_inithead(&r->pending); + r->stats = debug_get_bool_option("PVR_G5P_REUSE_STATS", false); + device->g5p_reuse = r; +} + +void pvr_g5p_reuse_finish(struct pvr_device *device) +{ + struct pvr_g5p_reuse *r = device->g5p_reuse; + + if (!r) + return; + + /* The queues are gone (pvr_arch_queues_destroy()): nothing runs any more. */ + if (r->stats) + fprintf(stderr, + "pvr: g5p reuse: blocks reused %" PRIu64 " fresh %" PRIu64 " queries %" PRIu64 + " freed %" PRIu64 " (free %u pending %u); syncs reused %" PRIu64 " fresh %" PRIu64 + " resets %" PRIu64 "\n", + r->block_reused, r->block_fresh, r->block_queries, r->block_freed, r->free_count, + r->pending_count, r->sync_reused, r->sync_fresh, r->sync_resets); + + list_for_each_entry_safe (struct pvr_g5p_retired, ret, &r->pending, link) { + list_for_each_entry_safe (struct pvr_bo, bo, &ret->bos, link) { + list_del(&bo->link); + pvr_bo_free(device, bo); + } + list_del(&ret->link); + vk_free(&device->vk.alloc, ret); + } + list_for_each_entry_safe (struct pvr_bo, bo, &r->free_blocks, link) { + list_del(&bo->link); + pvr_bo_free(device, bo); + } + for (uint32_t i = 0; i < r->nclean; i++) + vk_sync_destroy(&device->vk, r->clean_syncs[i]); + for (uint32_t i = 0; i < r->ndirty; i++) + vk_sync_destroy(&device->vk, r->dirty_syncs[i]); + + simple_mtx_destroy(&r->sync_mtx); + simple_mtx_destroy(&r->mtx); + vk_free(&device->vk.alloc, r); + device->g5p_reuse = NULL; +} + +VkResult pvr_g5p_queue_stamp_init(struct pvr_device *device, struct pvr_queue *queue, uint32_t index) +{ + struct pvr_g5p_reuse *r = device->g5p_reuse; + VkResult result; + + queue->g5p_index = index; + queue->g5p_stamp_syncobj = 0; + queue->g5p_stamp_issued = 0; + if (!r) + return VK_SUCCESS; + + assert(index < PVR_MAX_QUEUES); + /* A queue without a stamp would leave its command buffers' blocks looking + * unsubmitted: no queue runs without one while reuse is on. */ + result = device->ws->ops->stamp_create(device->ws, &queue->g5p_stamp_syncobj); + if (result != VK_SUCCESS) + return result; + + simple_mtx_lock(&r->mtx); + r->stamp_syncobj[index] = queue->g5p_stamp_syncobj; + r->completed[index] = 0; + simple_mtx_unlock(&r->mtx); + return VK_SUCCESS; +} + +void pvr_g5p_queue_stamp_finish(struct pvr_device *device, struct pvr_queue *queue) +{ + struct pvr_g5p_reuse *r = device->g5p_reuse; + + if (!r || !queue->g5p_stamp_syncobj) + return; + simple_mtx_lock(&r->mtx); + r->stamp_syncobj[queue->g5p_index] = 0; + simple_mtx_unlock(&r->mtx); + device->ws->ops->stamp_destroy(device->ws, queue->g5p_stamp_syncobj); + queue->g5p_stamp_syncobj = 0; +} + +struct pvr_winsys_stamp pvr_g5p_queue_stamp_next(const struct pvr_queue *queue) +{ + if (!queue->g5p_stamp_syncobj) + return (struct pvr_winsys_stamp){ 0 }; + return (struct pvr_winsys_stamp){ + .syncobj = queue->g5p_stamp_syncobj, + .point = queue->g5p_stamp_issued + 1, + }; +} + +void pvr_g5p_queue_stamp_issued(struct pvr_queue *queue, struct pvr_winsys_stamp stamp) +{ + if (stamp.syncobj) { + assert(stamp.point == queue->g5p_stamp_issued + 1); + queue->g5p_stamp_issued = stamp.point; + } +} + +static bool g5p_points_reached(const struct pvr_g5p_reuse *r, const uint64_t points[PVR_MAX_QUEUES]) +{ + for (uint32_t q = 0; q < PVR_MAX_QUEUES; q++) { + if (points[q] > r->completed[q]) + return false; + } + return true; +} + +/* Free blocks past the cap (the oldest first) onto `out`, to be freed after + * the lock: pending blocks stay whatever their count. */ +static void g5p_trim_locked(struct pvr_g5p_reuse *r, struct list_head *out) +{ + while (r->free_count && r->free_count + r->pending_count > PVR_G5P_REUSE_BLOCK_CAP) { + struct pvr_bo *bo = list_first_entry(&r->free_blocks, struct pvr_bo, link); + + list_del(&bo->link); + list_addtail(&bo->link, out); + r->free_count--; + r->block_freed++; + } +} + +/* Read every queue's stamp timeline (one ioctl) and free the pending blocks + * whose points were all reached. */ +static void g5p_collect_locked(struct pvr_device *device, struct pvr_g5p_reuse *r) +{ + uint32_t syncobjs[PVR_MAX_QUEUES], index[PVR_MAX_QUEUES]; + uint64_t points[PVR_MAX_QUEUES]; + uint32_t n = 0; + + for (uint32_t q = 0; q < PVR_MAX_QUEUES; q++) { + if (r->stamp_syncobj[q]) { + syncobjs[n] = r->stamp_syncobj[q]; + index[n++] = q; + } + } + if (!n || device->ws->ops->stamp_query(device->ws, syncobjs, points, n) != VK_SUCCESS) + return; + r->block_queries++; + for (uint32_t i = 0; i < n; i++) + r->completed[index[i]] = MAX2(r->completed[index[i]], points[i]); + + list_for_each_entry_safe (struct pvr_g5p_retired, ret, &r->pending, link) { + if (!g5p_points_reached(r, ret->points)) + continue; + list_splicetail(&ret->bos, &r->free_blocks); + r->free_count += ret->count; + r->pending_count -= ret->count; + list_del(&ret->link); + vk_free(&device->vk.alloc, ret); + } +} + +static void g5p_free_blocks(struct pvr_device *device, struct list_head *bos) +{ + list_for_each_entry_safe (struct pvr_bo, bo, bos, link) { + list_del(&bo->link); + pvr_bo_free(device, bo); + } +} + +VkResult pvr_g5p_csb_block_alloc(struct pvr_device *device, struct pvr_bo **bo_out) +{ + struct pvr_g5p_reuse *r = device->g5p_reuse; + struct pvr_bo *bo = NULL; + struct list_head extra; + + *bo_out = NULL; + if (!r) + return VK_SUCCESS; + + list_inithead(&extra); + simple_mtx_lock(&r->mtx); + /* Ask the kernel (one ioctl) only when there is something to learn: no + * free block, some pending. A fresh block joins the cache when it is + * retired, so the cache grows to what the GPU holds in flight. */ + if (list_is_empty(&r->free_blocks) && r->pending_count) { + g5p_collect_locked(device, r); + g5p_trim_locked(r, &extra); + } + if (!list_is_empty(&r->free_blocks)) { + bo = list_first_entry(&r->free_blocks, struct pvr_bo, link); + list_del(&bo->link); + r->free_count--; + r->block_reused++; + } else { + r->block_fresh++; + } + simple_mtx_unlock(&r->mtx); + g5p_free_blocks(device, &extra); + + if (bo) { + /* what a new BO holds: the VDM reads ahead of the stream's end */ + memset(bo->bo->map, 0, bo->bo->size); + *bo_out = bo; + } + return VK_SUCCESS; +} + +void pvr_g5p_csb_retire(struct pvr_device *device, struct pvr_csb *csb, + const uint64_t retire[PVR_MAX_QUEUES]) +{ + struct pvr_g5p_reuse *r = device->g5p_reuse; + struct pvr_g5p_retired *ret = NULL; + struct list_head extra; + bool moved = false; + uint32_t count; + + if (!r || csb->stream_type == PVR_CMD_STREAM_TYPE_GRAPHICS_DEFERRED || + csb->stream_type == PVR_CMD_STREAM_TYPE_INVALID || list_is_empty(&csb->pvr_bo_list)) { + pvr_csb_finish(csb); + return; + } + + count = list_length(&csb->pvr_bo_list); + list_inithead(&extra); + simple_mtx_lock(&r->mtx); + if (g5p_points_reached(r, retire)) { + /* never submitted, or already known complete */ + list_splicetail(&csb->pvr_bo_list, &r->free_blocks); + r->free_count += count; + moved = true; + } else { + ret = vk_alloc(&device->vk.alloc, sizeof(*ret), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + if (ret) { + list_inithead(&ret->bos); + list_splicetail(&csb->pvr_bo_list, &ret->bos); + ret->count = count; + memcpy(ret->points, retire, sizeof(ret->points)); + list_addtail(&ret->link, &r->pending); + r->pending_count += count; + moved = true; + } + } + g5p_trim_locked(r, &extra); + simple_mtx_unlock(&r->mtx); + g5p_free_blocks(device, &extra); + + /* the blocks moved (or, without memory for the record, are freed as + * before): finish an empty stream */ + if (moved) + list_inithead(&csb->pvr_bo_list); + pvr_csb_finish(csb); +} + +VkResult pvr_g5p_sync_get(struct pvr_device *device, struct vk_sync **sync_out) +{ + struct pvr_g5p_reuse *r = device->g5p_reuse; + + if (r) { + struct vk_sync *sync = NULL; + + simple_mtx_lock(&r->sync_mtx); + /* reset in batches: below one, a new sync joins the pool instead */ + if (!r->nclean && r->ndirty >= PVR_G5P_REUSE_SYNC_BATCH && + device->ws->ops->syncs_reset(device->ws, r->dirty_syncs, r->ndirty) == VK_SUCCESS) { + memcpy(r->clean_syncs, r->dirty_syncs, r->ndirty * sizeof(r->dirty_syncs[0])); + r->nclean = r->ndirty; + r->ndirty = 0; + r->sync_resets++; + } + if (r->nclean) { + sync = r->clean_syncs[--r->nclean]; + r->sync_reused++; + } else { + r->sync_fresh++; + } + simple_mtx_unlock(&r->sync_mtx); + if (sync) { + *sync_out = sync; + return VK_SUCCESS; + } + } + return vk_sync_create(&device->vk, &device->pdevice->sync_type, 0U, 0UL, sync_out); +} + +void pvr_g5p_sync_put(struct pvr_device *device, struct vk_sync *sync) +{ + struct pvr_g5p_reuse *r = device->g5p_reuse; + + if (!sync) + return; + if (r) { + assert(sync->type == &device->pdevice->sync_type && !(sync->flags & VK_SYNC_IS_TIMELINE)); + simple_mtx_lock(&r->sync_mtx); + if (r->ndirty < PVR_G5P_REUSE_SYNC_CAP) { + r->dirty_syncs[r->ndirty++] = sync; + sync = NULL; + } + simple_mtx_unlock(&r->sync_mtx); + if (!sync) + return; + } + vk_sync_destroy(&device->vk, sync); +} diff --git a/src/imagination/vulkan/pvr_g5p_reuse.h b/src/imagination/vulkan/pvr_g5p_reuse.h new file mode 100644 index 00000000000..ad24ca65b8a --- /dev/null +++ b/src/imagination/vulkan/pvr_g5p_reuse.h @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Apple's A9 GPU (G5P): submit-time reuse instead of per-submit kernel work. + * + * What a vkQueueSubmit used to create and destroy every time: + * - its command stream blocks: one 4 KiB BO each (pvr_csb_buffer_extend()), + * created, CPU-mapped and GPU-mapped while recording, unmapped and closed + * at the command buffer's reset (7 kernel calls per block). On the A9 every + * GPU unmap also moves the MMU tag of every loaded VM slot, so the next job + * of every client starts with its TLB dropped; + * - its job syncobjs (create + destroy per job and per merged wait), and the + * null job's merge syncobj. + * + * Apple (iOS 16 IOGPU.framework): command buffer storage comes from a + * device-wide pool (IOGPUMetalCommandBufferStoragePoolCreateStorage) and goes + * back to it from the completion handler, + * -[IOGPUMetalCommandBuffer didCompleteWithStartTime:endTime:error:] -> + * IOGPUMetalCommandBufferStorageDealloc -> ...StorageReset + + * ...StoragePoolReturnStorage: the memory is reused only once the GPU is done + * with it, never at the app's say. + * + * Here: + * - Stamps. Each queue owns one timeline syncobj. Every GPU job it submits + * (render, compute, query) also signals the next point of it, as one more + * sync op of the same SUBMIT_JOBS ioctl. A queue's points only grow, so the + * timeline's value is the point up to which all its jobs have completed. + * A command buffer records, per queue, the last point its jobs signal. + * - Command stream blocks. A primary command buffer's blocks, when it is reset + * or freed, go to the device's pending list with those points. They become + * free for reuse only after a query (one ioctl for all queues) shows every + * point reached; a never-submitted buffer's blocks are free at once. With no + * free block, a fresh one is allocated: reuse never waits. A reused block + * is zeroed, so the GPU sees exactly what a new BO holds. Secondary command + * buffers (linked from primaries) keep the plain free. + * - Syncs. The queue's job syncs are returned to a pool and reset together + * (one ioctl) before reuse, back to the state vk_sync_create() gives. + * + * PVR_G5P_REUSE=0 turns all of it off (pvr_g5p_reuse_option()). + */ + +#ifndef PVR_G5P_REUSE_H +#define PVR_G5P_REUSE_H + +#include +#include +#include + +#include "pvr_limits.h" +#include "util/list.h" +#include "util/simple_mtx.h" +#include "winsys/pvr_winsys.h" + +struct pvr_bo; +struct pvr_csb; +struct pvr_device; +struct pvr_queue; +struct vk_sync; + +/* free + pending command stream blocks kept at most (pending ones are kept + * whatever the count: the GPU may still read them) */ +#define PVR_G5P_REUSE_BLOCK_CAP 512 +#define PVR_G5P_REUSE_SYNC_CAP 64 +/* syncs reset together, at least */ +#define PVR_G5P_REUSE_SYNC_BATCH 32 + +struct pvr_g5p_reuse { + simple_mtx_t mtx; /* blocks and stamps */ + struct list_head free_blocks; /* struct pvr_bo, by link */ + struct list_head pending; /* struct pvr_g5p_retired */ + uint32_t free_count, pending_count; + /* each queue's stamp timeline (0: none) and its last queried value */ + uint32_t stamp_syncobj[PVR_MAX_QUEUES]; + uint64_t completed[PVR_MAX_QUEUES]; + + simple_mtx_t sync_mtx; + struct vk_sync *clean_syncs[PVR_G5P_REUSE_SYNC_CAP]; + struct vk_sync *dirty_syncs[PVR_G5P_REUSE_SYNC_CAP]; + uint32_t nclean, ndirty; + + /* PVR_G5P_REUSE_STATS=1: printed at device destruction */ + bool stats; + uint64_t block_reused, block_fresh, block_queries, block_freed; + uint64_t sync_reused, sync_fresh, sync_resets; +}; + +void pvr_g5p_reuse_init(struct pvr_device *device); +void pvr_g5p_reuse_finish(struct pvr_device *device); + +/* stamps */ +VkResult pvr_g5p_queue_stamp_init(struct pvr_device *device, struct pvr_queue *queue, uint32_t index); +void pvr_g5p_queue_stamp_finish(struct pvr_device *device, struct pvr_queue *queue); +/* the stamp the queue's next GPU job signals ({0} without reuse); after the + * job was submitted, pvr_g5p_queue_stamp_issued() makes it the queue's last */ +struct pvr_winsys_stamp pvr_g5p_queue_stamp_next(const struct pvr_queue *queue); +void pvr_g5p_queue_stamp_issued(struct pvr_queue *queue, struct pvr_winsys_stamp stamp); + +/* command stream blocks */ +VkResult pvr_g5p_csb_block_alloc(struct pvr_device *device, struct pvr_bo **bo_out); +/* Gives up a command buffer's control stream: its blocks go pending until + * every point of retire[] (per queue, 0: not submitted there) is reached. + * Leaves the csb finished, as pvr_csb_finish() does. */ +void pvr_g5p_csb_retire(struct pvr_device *device, struct pvr_csb *csb, + const uint64_t retire[PVR_MAX_QUEUES]); + +/* syncs: as vk_sync_create(device's sync type, binary, 0) / vk_sync_destroy() + * for syncs no one else holds */ +VkResult pvr_g5p_sync_get(struct pvr_device *device, struct vk_sync **sync_out); +void pvr_g5p_sync_put(struct pvr_device *device, struct vk_sync *sync); + +#endif /* PVR_G5P_REUSE_H */ diff --git a/src/imagination/vulkan/pvr_geom_hazard.h b/src/imagination/vulkan/pvr_geom_hazard.h new file mode 100644 index 00000000000..cb59f317425 --- /dev/null +++ b/src/imagination/vulkan/pvr_geom_hazard.h @@ -0,0 +1,320 @@ +/* + * Copyright © 2026 OrchardLinux contributors + * + * SPDX-License-Identifier: MIT + */ + +/* + * Barrier precision on G5P (A7/A8/A9): a render's geometry job waits for an + * earlier fragment job only when its geometry stage can observe that job's + * writes. The Vulkan stage mapping (pvr_stage_mask()) is faithful; what is wide + * is the clients' masks: a fragment-written image that the next render samples + * in its fragment shader comes with VERTEX_SHADER (and COMPUTE_SHADER) in the + * barrier's destination too, so every render's geometry job waited for the + * previous render's fragment job (TA -> 3D -> TA, one handoff each way). + * + * The rule (per resource, as Metal tracks hazards): + * - a fragment job writes its render's attachments (device-address ranges), + * or memory it cannot name (a fragment program with stores or atomics, a + * non-optimal attachment that a buffer may alias, too many attachments): + * then it is "opaque"; + * - a render's geometry stage reads the images its vertex program uploads + * (G5P vertex uploads name each (set, binding, element)), vertex, index and + * indirect buffers, and buffers through descriptors. A fragment job can + * write buffers only when it is opaque, so only image ranges are kept; + * - a geometry stage that writes memory (vertex stores, transform feedback) + * or reads a descriptor whose image cannot be named is opaque too; + * - an application barrier's FRAG -> GEOM wait is deferred to the queue + * (pvr_queue::geom_defer). The next render's geometry job takes it when it + * reads a range a covered fragment job wrote, or either side is opaque; + * otherwise it is carried to the render after. It is dropped only once + * taken or seen signalled. + * + * PVR_GEOM_PRECISE: 0 = the old behaviour, 1 = per-barrier src/dst pairing + * only, 2 (default) = pairing and the deferred FRAG -> GEOM wait. + * See docs/gpu/barrier-precision-20261203.md in the linux-a9 workspace. + */ + +#ifndef PVR_GEOM_HAZARD_H +#define PVR_GEOM_HAZARD_H + +#include +#include +#include + +#include "pvr_device_info.h" +#include "util/macros.h" +#include "util/u_math.h" + +struct vk_sync; + +#define PVR_GEOM_HAZARD_MAX_READS 16 +#define PVR_GEOM_HAZARD_MAX_WRITES 12 +#define PVR_GEOM_HAZARD_MAX_SETS 8 +#define PVR_GEOM_DEFER_MAX_WRITES 32 +/* pre-raster image descriptors tracked per descriptor set */ +#define PVR_GEOM_SET_MAX_IMAGES 16 + +/* why a render's geometry stage is opaque (pass log 'G' lines) */ +enum pvr_geom_opaque { + PVR_GEOM_OPAQUE_NONE = 0, + PVR_GEOM_OPAQUE_VS_WRITES, /* vertex stores or transform feedback */ + PVR_GEOM_OPAQUE_DESC, /* a vertex image the driver cannot name (push, update-after-bind, overflow) */ + PVR_GEOM_OPAQUE_READS, /* more image ranges than PVR_GEOM_HAZARD_MAX_READS */ +}; + +struct pvr_geom_range { + uint64_t start, end; /* [start, end) device addresses */ +}; + +/* Recorded per graphics sub-command (pvr_sub_cmd_gfx::geom_hz) */ +struct pvr_geom_hazard { + /* consumer side: the geometry stage */ + uint32_t draws; + uint8_t reads_opaque; /* enum pvr_geom_opaque */ + uint8_t read_count; + struct pvr_geom_range reads[PVR_GEOM_HAZARD_MAX_READS]; + /* descriptor sets already folded in (their contents are fixed while the command buffer is recorded) */ + uint8_t set_count; + const void *sets[PVR_GEOM_HAZARD_MAX_SETS]; + const void *last_pipeline; + + /* source side: the fragment job */ + bool writes_opaque; + uint8_t write_count; + struct pvr_geom_range writes[PVR_GEOM_HAZARD_MAX_WRITES]; +}; + +/* Per descriptor set: the images of its pre-raster-visible image descriptors */ +struct pvr_geom_set_image { + uint16_t binding, element; + struct pvr_geom_range range; /* start == end: no image */ +}; + +struct pvr_geom_set_images { + bool overflow; + uint8_t count; + struct pvr_geom_set_image img[PVR_GEOM_SET_MAX_IMAGES]; +}; + +/* Per queue: the deferred FRAG -> GEOM wait and the fragment writes it covers */ +struct pvr_geom_defer_write { + struct pvr_geom_range range; + uint64_t lo, hi; /* the first and last FRAG job (sequence) that wrote it since synced */ +}; + +struct pvr_geom_defer { + struct vk_sync *sync; /* NULL: nothing deferred */ + uint64_t frag_seq; /* FRAG jobs submitted */ + uint64_t armed_seq; /* FRAG jobs <= this are covered by sync */ + uint64_t synced_seq; /* FRAG jobs <= this are ordered before every later geometry job */ + uint64_t opaque_min; /* 0, or the first FRAG job > synced_seq whose writes are opaque */ + uint64_t opaque_max; /* the last FRAG job whose writes are opaque */ + /* last_job_signal_sync[FRAG] is a noop render's (already signalled) sync, not a submitted job's: its being + * signalled says nothing about earlier fragment jobs */ + bool frag_last_noop; + uint32_t write_count; + struct pvr_geom_defer_write w[PVR_GEOM_DEFER_MAX_WRITES]; + /* PVR_DEBUG=pass_log counters (B and G lines) */ + uint32_t n_defer, n_drop, n_keep, n_done; + uint32_t keep_hit, keep_vs, keep_fs; +}; + +static inline unsigned +pvr_geom_precise_level(const struct pvr_device_info *dev_info) +{ + static int level = -1; + + /* G5P draws only (pvr_arch_g5p_gfx.c records each draw's reads); the A7's + * renders take another draw path (pvr_g3_tri()), the A10 (G9P) and Rogue + * keep the old waits */ + if (!PVR_HAS_FEATURE(dev_info, apple_g5p) || PVR_HAS_FEATURE(dev_info, apple_g3)) + return 0; + if (level < 0) { + const char *e = getenv("PVR_GEOM_PRECISE"); + level = e ? CLAMP(atoi(e), 0, 2) : 2; + } + return level; +} + +static inline bool +pvr_geom_ranges_overlap(const struct pvr_geom_range *a, const struct pvr_geom_range *b) +{ + return a->start < b->end && b->start < a->end; +} + +static inline void +pvr_geom_hazard_add_read(struct pvr_geom_hazard *hz, struct pvr_geom_range r) +{ + if (r.start >= r.end || hz->reads_opaque) + return; + for (unsigned i = 0; i < hz->read_count; i++) { + if (hz->reads[i].start == r.start && hz->reads[i].end == r.end) + return; + } + if (hz->read_count >= PVR_GEOM_HAZARD_MAX_READS) { + hz->reads_opaque = PVR_GEOM_OPAQUE_READS; + return; + } + hz->reads[hz->read_count++] = r; +} + +static inline void +pvr_geom_hazard_add_write(struct pvr_geom_hazard *hz, struct pvr_geom_range r) +{ + if (r.start >= r.end || hz->writes_opaque) + return; + for (unsigned i = 0; i < hz->write_count; i++) { + if (hz->writes[i].start == r.start && hz->writes[i].end == r.end) + return; + } + if (hz->write_count >= PVR_GEOM_HAZARD_MAX_WRITES) { + hz->writes_opaque = true; + return; + } + hz->writes[hz->write_count++] = r; +} + +/* A secondary command buffer's render merged into the primary's */ +static inline void +pvr_geom_hazard_merge(struct pvr_geom_hazard *dst, const struct pvr_geom_hazard *src) +{ + dst->draws += src->draws; + if (src->reads_opaque && !dst->reads_opaque) + dst->reads_opaque = src->reads_opaque; + for (unsigned i = 0; i < src->read_count; i++) + pvr_geom_hazard_add_read(dst, src->reads[i]); + dst->writes_opaque |= src->writes_opaque; + for (unsigned i = 0; i < src->write_count; i++) + pvr_geom_hazard_add_write(dst, src->writes[i]); +} + +/* Descriptor-set side (pvr_arch_descriptor_set.c) */ +static inline struct pvr_geom_set_image * +pvr_geom_set_find(struct pvr_geom_set_images *s, uint32_t binding, uint32_t element) +{ + for (unsigned i = 0; i < s->count; i++) { + if (s->img[i].binding == binding && s->img[i].element == element) + return &s->img[i]; + } + return NULL; +} + +static inline void +pvr_geom_set_store(struct pvr_geom_set_images *s, uint32_t binding, uint32_t element, + struct pvr_geom_range range) +{ + struct pvr_geom_set_image *e; + + if (binding > UINT16_MAX || element > UINT16_MAX) { + s->overflow = true; + return; + } + e = pvr_geom_set_find(s, binding, element); + if (!e) { + if (range.start >= range.end) + return; /* no image, nothing recorded */ + if (s->count >= PVR_GEOM_SET_MAX_IMAGES) { + s->overflow = true; + return; + } + e = &s->img[s->count++]; + e->binding = binding; + e->element = element; + } + e->range = range; +} + +/* Queue side (pvr_arch_queue.c) */ + +/* FRAG jobs <= seq are now ordered before every later geometry job */ +static inline void +pvr_geom_defer_advance(struct pvr_geom_defer *d, uint64_t seq) +{ + uint32_t n = 0; + + if (seq <= d->synced_seq) + return; + d->synced_seq = seq; + for (uint32_t i = 0; i < d->write_count; i++) { + struct pvr_geom_defer_write w = d->w[i]; + + if (w.hi <= seq) + continue; + w.lo = MAX2(w.lo, seq + 1); + d->w[n++] = w; + } + d->write_count = n; + /* opaque jobs between the two are not enumerated: assume the first is the next one */ + if (d->opaque_min && d->opaque_min <= seq) + d->opaque_min = d->opaque_max > seq ? seq + 1 : 0; +} + +/* A FRAG job was submitted with these writes */ +static inline void +pvr_geom_defer_note_frag(struct pvr_geom_defer *d, const struct pvr_geom_hazard *hz) +{ + const uint64_t seq = ++d->frag_seq; + + d->frag_last_noop = false; + + if (hz->writes_opaque) { + if (!d->opaque_min) + d->opaque_min = seq; + d->opaque_max = seq; + return; + } + for (unsigned i = 0; i < hz->write_count; i++) { + const struct pvr_geom_range r = hz->writes[i]; + bool found = false; + + for (uint32_t j = 0; j < d->write_count; j++) { + if (d->w[j].range.start == r.start && d->w[j].range.end == r.end) { + d->w[j].hi = seq; + found = true; + break; + } + } + if (found) + continue; + if (d->write_count >= PVR_GEOM_DEFER_MAX_WRITES) { + if (!d->opaque_min) + d->opaque_min = seq; + d->opaque_max = seq; + continue; + } + d->w[d->write_count++] = (struct pvr_geom_defer_write){ .range = r, .lo = seq, .hi = seq }; + } +} + +enum pvr_geom_need { + PVR_GEOM_NEED_NONE = 0, + PVR_GEOM_NEED_HIT, /* reads a range a covered FRAG job wrote */ + PVR_GEOM_NEED_VS, /* the geometry stage is opaque */ + PVR_GEOM_NEED_FS, /* a covered FRAG job's writes are opaque */ +}; + +/* Does a render with this record need the deferred wait (FRAG jobs in (synced, armed])? */ +static inline enum pvr_geom_need +pvr_geom_defer_need(const struct pvr_geom_defer *d, const struct pvr_geom_hazard *hz) +{ + if (!hz->draws) + return PVR_GEOM_NEED_NONE; /* a geometry job without draws reads nothing */ + if (hz->reads_opaque) + return PVR_GEOM_NEED_VS; + if (d->opaque_min && d->opaque_min > d->synced_seq && d->opaque_min <= d->armed_seq) + return PVR_GEOM_NEED_FS; + for (uint32_t i = 0; i < d->write_count; i++) { + const struct pvr_geom_defer_write *w = &d->w[i]; + + if (w->lo > d->armed_seq || w->hi <= d->synced_seq) + continue; + for (unsigned j = 0; j < hz->read_count; j++) { + if (pvr_geom_ranges_overlap(&w->range, &hz->reads[j])) + return PVR_GEOM_NEED_HIT; + } + } + return PVR_GEOM_NEED_NONE; +} + +#endif /* PVR_GEOM_HAZARD_H */ diff --git a/src/imagination/vulkan/pvr_image.h b/src/imagination/vulkan/pvr_image.h index 0f84a3bb179..4a498ff1537 100644 --- a/src/imagination/vulkan/pvr_image.h +++ b/src/imagination/vulkan/pvr_image.h @@ -19,6 +19,7 @@ #include "vk_image.h" #include "pvr_common.h" +#include "pvr_geom_hazard.h" #include "pvr_types.h" #define PVR_MAX_PLANE_COUNT 3 @@ -170,6 +171,31 @@ pvr_image_view_get_image(const struct pvr_image_view *const iview) return vk_to_pvr_image(iview->vk.image); } +/* Barrier precision (pvr_geom_hazard.h): the device addresses an image may + * occupy, from its bound address over its import offset and size (wider than + * the image is harmless: it only keeps a wait). Empty when unbound. + */ +static inline struct pvr_geom_range +pvr_geom_image_range(const struct pvr_image *image) +{ + const uint64_t start = image->dev_addr.addr; + const uint64_t size = image->import_offset + MAX2(image->total_size, 1); + + if (!start) + return (struct pvr_geom_range){ 0, 0 }; + return (struct pvr_geom_range){ start, start + size }; +} + +/* An attachment a buffer may alias with a defined layout (Vulkan "Memory + * Aliasing": linear subresources are host-accessible), so its fragment writes + * may reach a vertex, index or uniform buffer: opaque for barrier precision. + */ +static inline bool +pvr_geom_image_buffer_visible(const struct pvr_image *image) +{ + return image->vk.tiling != VK_IMAGE_TILING_OPTIMAL; +} + void pvr_get_image_subresource_layout(const struct pvr_image *image, const VkImageSubresource *subresource, VkSubresourceLayout *layout); diff --git a/src/imagination/vulkan/pvr_job_render.h b/src/imagination/vulkan/pvr_job_render.h index 85636aad7b8..7ea26811b1c 100644 --- a/src/imagination/vulkan/pvr_job_render.h +++ b/src/imagination/vulkan/pvr_job_render.h @@ -71,6 +71,9 @@ struct pvr_rt_mtile_info { * (although it doesn't subclass). */ struct pvr_render_job { + /* G5P submit reuse: what this submission's last job signals (pvr_g5p_reuse.h) */ + struct pvr_winsys_stamp g5p_stamp; + struct { bool run_frag : 1; bool geometry_terminate : 1; diff --git a/src/imagination/vulkan/pvr_pass_log.c b/src/imagination/vulkan/pvr_pass_log.c new file mode 100644 index 00000000000..528f7101049 --- /dev/null +++ b/src/imagination/vulkan/pvr_pass_log.c @@ -0,0 +1,197 @@ +/* + * Copyright © 2026 Orchard contributors + * SPDX-License-Identifier: MIT + */ + +#include "pvr_pass_log.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util/mesa-blake3.h" +#include "util/set.h" +#include "util/simple_mtx.h" +#include "util/u_atomic.h" +#include "util/u_call_once.h" +#include "vk_shader_module.h" +#include "vk_enum_to_str.h" +#include "vk_util.h" + +static int log_fd = -2; /* -2: not opened yet, -1: stderr */ +static util_once_flag log_once = UTIL_ONCE_FLAG_INIT; +static uint32_t log_serial; +static __thread uint32_t current_serial; +static struct set *seen_images; +static util_once_flag seen_images_once = UTIL_ONCE_FLAG_INIT; +static simple_mtx_t seen_images_mtx = SIMPLE_MTX_INITIALIZER; + +static void +seen_images_init(void) +{ + seen_images = _mesa_pointer_set_create(NULL); +} + +bool +pvr_pass_log_image_first(const void *img) +{ + if (!img) + return false; + util_call_once(&seen_images_once, seen_images_init); + if (!seen_images) + return false; + simple_mtx_lock(&seen_images_mtx); + bool found = false; + _mesa_set_search_or_add(seen_images, img, &found); + simple_mtx_unlock(&seen_images_mtx); + return !found; +} + +static void +log_open(void) +{ + const char *path = getenv("PVR_PASS_LOG"); + log_fd = -1; + if (!path || !*path) + return; + char name[4096]; + snprintf(name, sizeof(name), "%s.%ld", path, (long)getpid()); + const int fd = open(name, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644); + if (fd < 0) { + fprintf(stderr, "pvr pass_log: cannot open %s (errno %d), logging to stderr\n", name, errno); + return; + } + log_fd = fd; +} + +void +pvr_pass_log_printf(const char *fmt, ...) +{ + char line[1024]; + va_list ap; + + util_call_once(&log_once, log_open); + va_start(ap, fmt); + int n = vsnprintf(line, sizeof(line) - 1, fmt, ap); + va_end(ap); + if (n < 0) + return; + if (n > (int)sizeof(line) - 2) + n = sizeof(line) - 2; /* truncated: still one line */ + line[n++] = '\n'; + + const int fd = log_fd >= 0 ? log_fd : STDERR_FILENO; + const char *p = line; + while (n > 0) { + const ssize_t w = write(fd, p, n); + if (w < 0 && errno == EINTR) + continue; + if (w <= 0) + return; + p += w; + n -= w; + } +} + +uint64_t +pvr_pass_log_now_ns(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000ull + ts.tv_nsec; +} + +uint32_t +pvr_pass_log_next_serial(void) +{ + return p_atomic_inc_return(&log_serial); +} + +uint32_t +pvr_pass_log_stage_id(const VkPipelineShaderStageCreateInfo *info) +{ + const VkShaderModuleCreateInfo *inline_ci = + vk_find_struct_const(info->pNext, SHADER_MODULE_CREATE_INFO); + const uint32_t *words = NULL; + size_t bytes = 0; + + if (info->module != VK_NULL_HANDLE) { + VK_FROM_HANDLE(vk_shader_module, module, info->module); + words = (const uint32_t *)module->data; + bytes = module->size; + } else if (inline_ci) { + words = inline_ci->pCode; + bytes = inline_ci->codeSize; + } + if (!words || !bytes) + return 0; + + blake3_hash hash; + _mesa_blake3_compute(words, bytes, hash); + const uint32_t id = (uint32_t)hash[0] << 24 | (uint32_t)hash[1] << 16 | (uint32_t)hash[2] << 8 | hash[3]; + return id ? id : 1; +} + +void +pvr_pass_log_draw(struct pvr_pass_log_stats *s, const struct pvr_pass_log_pipe *pipe, bool indexed, bool indirect, + uint64_t verts) +{ + s->draws++; + s->verts += verts; + s->indexed += indexed; + s->indirect += indirect; + if (!pipe) { + s->no_pipe++; + return; + } + s->ycbcr += pipe->ycbcr != 0; + for (uint32_t i = 0; i < s->npipes; i++) + if (s->pipes[i] == pipe->fs_id) + return; + if (s->npipes < PVR_PASS_LOG_MAX_PIPES) + s->pipes[s->npipes++] = pipe->fs_id; + else + s->pipes_overflow = true; +} + +void +pvr_pass_log_rect(struct pvr_pass_log_stats *s, int32_t x, int32_t y, uint32_t w, uint32_t h) +{ + const int32_t x1 = x + (int32_t)MIN2(w, (uint32_t)INT32_MAX / 2), y1 = y + (int32_t)MIN2(h, (uint32_t)INT32_MAX / 2); + if (!s->bbox_valid) { + s->bx0 = x, s->by0 = y, s->bx1 = x1, s->by1 = y1; + s->bbox_valid = true; + return; + } + s->bx0 = MIN2(s->bx0, x); + s->by0 = MIN2(s->by0, y); + s->bx1 = MAX2(s->bx1, x1); + s->by1 = MAX2(s->by1, y1); +} + +void +pvr_pass_log_set_current(uint32_t serial) +{ + current_serial = serial; +} + +void +pvr_pass_log_submit(const char *type, const char *jobs, uint64_t t0, uint64_t t1, int result) +{ + pvr_pass_log_printf("S t0=%" PRIu64 " t1=%" PRIu64 " tid=%d type=%s jobs=%s pass=%u res=%d", t0, t1, + (int)syscall(SYS_gettid), type, jobs, current_serial, result); +} + +const char * +pvr_pass_log_format(VkFormat format) +{ + const char *name = vk_Format_to_str(format); + return strncmp(name, "VK_FORMAT_", 10) ? name : name + 10; +} diff --git a/src/imagination/vulkan/pvr_pass_log.h b/src/imagination/vulkan/pvr_pass_log.h new file mode 100644 index 00000000000..32d54d34fae --- /dev/null +++ b/src/imagination/vulkan/pvr_pass_log.h @@ -0,0 +1,107 @@ +/* + * Copyright © 2026 Orchard contributors + * SPDX-License-Identifier: MIT + */ + +/* + * PVR_DEBUG=pass_log: one line per hardware render (graphics sub-command) + * when it is recorded, one line per job-submit ioctl, one line per new + * graphics pipeline. Chip-agnostic: the same records on every PowerVR chip; + * the chip's own effective choices (background, empty tiles, ...) are added + * where that chip's job init made them. + * + * Output: the file PVR_PASS_LOG names, suffixed "." (one file per + * process), else stderr. Every line is written with one write() so lines + * never interleave, and none are dropped or sampled: a later join with the + * kernel's ftrace (trace_clock mono) matches submit lines by CLOCK_MONOTONIC + * time and thread id. + * + * Line formats (fields are key=value, space separated): + * F pipe= vs= samplers= ycbcr= blend=<0/1> ztest=<0/1> + * zwrite=<0/1> cwm= a new graphics pipeline + * P pass= ... a recorded render + * S t0= t1= tid= type= jobs= + * pass= res= a job-submit ioctl + * Q t= cmdbufs= waits= signals= a vkQueueSubmit batch + * R pass= refused a render the chip refused (not submitted) + * V img=@ fmt= x planes= ext=<0/1> aspect= + * a view of an imported or multi-planar image + * T img=@ fmt= x levels= layers= layout= usage= ext=<0/1> + * first sampled-image descriptor naming an image + * B t= src= dst= waits= a pipeline barrier event + */ + +#ifndef PVR_PASS_LOG_H +#define PVR_PASS_LOG_H + +#include +#include +#include + +#include "pvr_debug.h" +#include "util/macros.h" + +#define PVR_PASS_LOG_MAX_PIPES 8 + +/* what a render's draws did, counted while it is recorded */ +struct pvr_pass_log_stats { + uint32_t draws; /* every draw call */ + uint32_t indexed; /* of them indexed */ + uint32_t indirect; /* of them indirect */ + uint32_t clears; /* vkCmdClearAttachments calls */ + uint32_t ycbcr; /* draws whose pipeline samples through a YCbCr conversion */ + uint32_t no_pipe; /* draws with no graphics pipeline bound */ + uint32_t ext; /* draws with a bound set that holds an imported (dma-buf) or multi-planar image */ + /* the union of the draws' scissors and the clears' rectangles (bbox_valid: any) */ + bool bbox_valid; + int32_t bx0, by0, bx1, by1; + uint32_t npipes; /* distinct fragment programs */ + bool pipes_overflow; + uint32_t pipes[PVR_PASS_LOG_MAX_PIPES]; + uint64_t verts; /* Σ vertexCount|indexCount × instanceCount of direct draws */ + uint32_t nsets; /* distinct descriptor sets bound at draws (≤ 16) */ + bool sets_overflow; + const void *sets[16]; + uint32_t tex, tex_lin, tex_lin_pot, tex_lin_big; /* sampled-image bindings in those sets */ +}; + +/* what the pipeline log needs of a graphics pipeline (struct pvr_graphics_pipeline) */ +struct pvr_pass_log_pipe { + uint32_t fs_id; /* first 32 bits of the fragment SPIR-V's BLAKE3; 0 = driver-internal */ + uint32_t vs_id; + uint16_t samplers; /* sampled-image bindings in the layout */ + uint16_t ycbcr; /* of them with an immutable YCbCr-conversion sampler */ +}; + +static inline bool +pvr_pass_log_enabled(void) +{ + return PVR_IS_DEBUG_SET(PASS_LOG); +} + +void pvr_pass_log_printf(const char *fmt, ...) PRINTFLIKE(1, 2); + +uint64_t pvr_pass_log_now_ns(void); +uint32_t pvr_pass_log_next_serial(void); + +uint32_t pvr_pass_log_stage_id(const VkPipelineShaderStageCreateInfo *info); + +void pvr_pass_log_draw(struct pvr_pass_log_stats *s, const struct pvr_pass_log_pipe *pipe, bool indexed, + bool indirect, uint64_t verts); + +/* returns true once per distinct image pointer in the process (for T lines) */ +bool pvr_pass_log_image_first(const void *img); + +/* add a rectangle to the render's drawn area */ +void pvr_pass_log_rect(struct pvr_pass_log_stats *s, int32_t x, int32_t y, uint32_t w, uint32_t h); + +/* the render whose job the calling thread submits next (0: none); read by the winsys' submit line */ +void pvr_pass_log_set_current(uint32_t serial); + +/* the winsys' job-submit ioctl: @jobs is a string of job-type letters (g f c t) */ +void pvr_pass_log_submit(const char *type, const char *jobs, uint64_t t0, uint64_t t1, int result); + +/* "B8G8R8A8_UNORM" for VK_FORMAT_B8G8R8A8_UNORM */ +const char *pvr_pass_log_format(VkFormat format); + +#endif /* PVR_PASS_LOG_H */ diff --git a/src/imagination/vulkan/pvr_pipeline.h b/src/imagination/vulkan/pvr_pipeline.h index 8118ddf8f3c..4dbd2a5b14f 100644 --- a/src/imagination/vulkan/pvr_pipeline.h +++ b/src/imagination/vulkan/pvr_pipeline.h @@ -22,6 +22,7 @@ #include "pvr_device_info.h" #include "pvr_g9p_xfb_core.h" #include "pvr_pds.h" +#include "pvr_pass_log.h" #include "util/shader_stats.h" #include "pvr_g5p_compute_state.h" struct pvr_suballoc_bo; @@ -270,6 +271,9 @@ struct pvr_graphics_pipeline { /* G5P (pvr_arch_g5p_gfx.c, pvr_g5p.h): the programs of its draws */ struct pvr_g5p_pipeline *g5p; + + /* PVR_DEBUG=pass_log (pvr_pass_log.h): its program ids and sampler census */ + struct pvr_pass_log_pipe pass_log; }; struct pvr_private_compute_pipeline { diff --git a/src/imagination/vulkan/pvr_queue.h b/src/imagination/vulkan/pvr_queue.h index 0064a4a221f..86ca59e2db8 100644 --- a/src/imagination/vulkan/pvr_queue.h +++ b/src/imagination/vulkan/pvr_queue.h @@ -18,6 +18,7 @@ #include "vk_queue.h" #include "pvr_common.h" +#include "pvr_geom_hazard.h" struct vk_sync; @@ -40,6 +41,14 @@ struct pvr_queue { struct vk_sync *next_job_wait_sync[PVR_JOB_TYPE_MAX]; /* G5P: last_job_signal_sync[i] is known complete (zero-timeout wait succeeded); cleared whenever it is replaced */ bool g5p_src_done[PVR_JOB_TYPE_MAX]; + /* G5P barrier precision (pvr_geom_hazard.h): the deferred FRAG -> GEOM wait */ + struct pvr_geom_defer geom_defer; + + /* G5P submit reuse (pvr_g5p_reuse.h): this queue's index, its stamp + * timeline (0: none) and the last point its jobs signal */ + uint32_t g5p_index; + uint32_t g5p_stamp_syncobj; + uint64_t g5p_stamp_issued; }; VK_DEFINE_HANDLE_CASTS(pvr_queue, vk.base, VkQueue, VK_OBJECT_TYPE_QUEUE) diff --git a/src/imagination/vulkan/rogue/pvr_blit.c b/src/imagination/vulkan/rogue/pvr_blit.c index 23564c50ff2..592fe71c142 100644 --- a/src/imagination/vulkan/rogue/pvr_blit.c +++ b/src/imagination/vulkan/rogue/pvr_blit.c @@ -2702,6 +2702,14 @@ void pvr_rogue_CmdClearAttachments(VkCommandBuffer commandBuffer, PVR_CHECK_COMMAND_BUFFER_BUILDING_STATE(cmd_buffer); assert(state->current_sub_cmd->type == PVR_SUB_CMD_TYPE_GRAPHICS); + /* PVR_DEBUG=pass_log: the render's clears (pvr_pass_log.h) */ + if (pvr_pass_log_enabled()) { + sub_cmd->pass_log.clears++; + for (uint32_t i = 0; i < rectCount; i++) + pvr_pass_log_rect(&sub_cmd->pass_log, pRects[i].rect.offset.x, pRects[i].rect.offset.y, + pRects[i].rect.extent.width, pRects[i].rect.extent.height); + } + /* G9P: Rogue's clear programs do not run there (they hung the geometry job) */ if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g9p)) { VkResult result = PVR_PER_ARCH(g9p_clear_attachments)(cmd_buffer, attachmentCount, diff --git a/src/imagination/vulkan/winsys/powervr/pvr_drm.c b/src/imagination/vulkan/winsys/powervr/pvr_drm.c index e6f809d98b0..813fd29a858 100644 --- a/src/imagination/vulkan/winsys/powervr/pvr_drm.c +++ b/src/imagination/vulkan/winsys/powervr/pvr_drm.c @@ -22,9 +22,10 @@ */ #include +#include +#include #include #include -#include #include #include @@ -37,6 +38,7 @@ #include "pvr_drm_job_render.h" #include "pvr_drm_job_transfer.h" #include "pvr_drm_public.h" +#include "pvr_pass_log.h" #include "pvr_macros.h" #include "pvr_winsys.h" #include "pvr_winsys_helper.h" @@ -108,7 +110,25 @@ VkResult pvr_drm_submit_jobs(struct pvr_drm_winsys *ws, struct drm_pvr_ioctl_submit_jobs_args *args, const char *job_type) { - if (pvr_drm_ioctl_retry(ws, DRM_IOCTL_PVR_SUBMIT_JOBS, args) == 0) + /* PVR_DEBUG=pass_log: one line per submit ioctl, CLOCK_MONOTONIC before and after (pvr_pass_log.h) */ + if (pvr_pass_log_enabled()) { + char jobs[17]; + const struct drm_pvr_job *job = (const struct drm_pvr_job *)(uintptr_t)args->jobs.array; + uint32_t j = 0; + for (; j < args->jobs.count && j < sizeof(jobs) - 1; j++) { + const uint32_t type = ((const struct drm_pvr_job *)((const uint8_t *)job + j * args->jobs.stride))->type; + jobs[j] = type == DRM_PVR_JOB_TYPE_GEOMETRY ? 'g' : type == DRM_PVR_JOB_TYPE_FRAGMENT ? 'f' + : type == DRM_PVR_JOB_TYPE_COMPUTE ? 'c' : type == DRM_PVR_JOB_TYPE_TRANSFER_FRAG ? 't' : '?'; + } + jobs[j] = 0; + const uint64_t t0 = pvr_pass_log_now_ns(); + const int ret = pvr_drm_ioctl_retry(ws, DRM_IOCTL_PVR_SUBMIT_JOBS, args); + const int saved = errno; + pvr_pass_log_submit(job_type, jobs, t0, pvr_pass_log_now_ns(), ret ? -saved : 0); + errno = saved; + if (ret == 0) + return VK_SUCCESS; + } else if (pvr_drm_ioctl_retry(ws, DRM_IOCTL_PVR_SUBMIT_JOBS, args) == 0) return VK_SUCCESS; const int err = errno; if (err == EIO) @@ -124,6 +144,98 @@ static bool pvr_drm_winsys_is_lost(struct pvr_winsys *ws) return p_atomic_read(&drm_ws->lost); } +/* G5P submit reuse: a queue's stamp timeline (pvr_g5p_reuse.h) */ +static VkResult pvr_drm_stamp_create(struct pvr_winsys *base, uint32_t *syncobj_out) +{ + if (drmSyncobjCreate(base->render_fd, 0, syncobj_out)) + return vk_errorf(NULL, VK_ERROR_OUT_OF_HOST_MEMORY, "stamp syncobj: %s", strerror(errno)); + return VK_SUCCESS; +} + +static void pvr_drm_stamp_destroy(struct pvr_winsys *base, uint32_t syncobj) +{ + drmSyncobjDestroy(base->render_fd, syncobj); +} + +static VkResult pvr_drm_stamp_query(struct pvr_winsys *base, const uint32_t *syncobjs, + uint64_t *points, uint32_t count) +{ + /* flags 0: the last point up to which the timeline has signalled */ + if (drmSyncobjQuery(base->render_fd, (uint32_t *)syncobjs, points, count)) + return vk_errorf(NULL, VK_ERROR_DEVICE_LOST, "stamp query: %s", strerror(errno)); + return VK_SUCCESS; +} + +static VkResult pvr_drm_syncs_reset(struct pvr_winsys *base, struct vk_sync *const *syncs, + uint32_t count) +{ + struct pvr_drm_winsys *ws = to_pvr_drm_winsys(base); + uint32_t handles[64]; + uint32_t n = 0; + + for (uint32_t i = 0; i < count; i++) { + struct vk_drm_syncobj *sync = vk_sync_as_drm_syncobj(syncs[i]); + assert(sync && !(syncs[i]->flags & VK_SYNC_IS_TIMELINE)); + /* the tag names the job a fence error belongs to: a fresh sync has none */ + if (ws->base.job_sync_size && syncs[i]->type->size == ws->base.job_sync_size) + ((struct pvr_drm_job_sync *)syncs[i])->job_type = NULL; + handles[n++] = sync->syncobj; + if (n == ARRAY_SIZE(handles) || i + 1 == count) { + if (drmSyncobjReset(base->render_fd, handles, n)) + return vk_errorf(NULL, VK_ERROR_OUT_OF_HOST_MEMORY, "syncobj reset: %s", strerror(errno)); + n = 0; + } + } + return VK_SUCCESS; +} + +/* A null job's merge syncobj: a reset one kept from an earlier null job if + * there is one (4 or more dirty ones are reset together first), else a new + * one. + * Without G5P reuse: always a new one, as before. */ +uint32_t pvr_drm_tmp_syncobj_get(struct pvr_drm_winsys *ws, int *err_out) +{ + uint32_t syncobj = 0; + + *err_out = 0; + if (ws->g5p_reuse) { + simple_mtx_lock(&ws->tmp_syncobjs.lock); + /* reset in batches of 4 or more: below that, a new one joins */ + if (!ws->tmp_syncobjs.nclean && ws->tmp_syncobjs.ndirty >= 4 && + !drmSyncobjReset(ws->base.render_fd, ws->tmp_syncobjs.dirty, ws->tmp_syncobjs.ndirty)) { + memcpy(ws->tmp_syncobjs.clean, ws->tmp_syncobjs.dirty, + ws->tmp_syncobjs.ndirty * sizeof(uint32_t)); + ws->tmp_syncobjs.nclean = ws->tmp_syncobjs.ndirty; + ws->tmp_syncobjs.ndirty = 0; + } + if (ws->tmp_syncobjs.nclean) + syncobj = ws->tmp_syncobjs.clean[--ws->tmp_syncobjs.nclean]; + simple_mtx_unlock(&ws->tmp_syncobjs.lock); + if (syncobj) + return syncobj; + } + if (drmSyncobjCreate(ws->base.render_fd, 0, &syncobj)) { + *err_out = errno; + return 0; + } + return syncobj; +} + +void pvr_drm_tmp_syncobj_put(struct pvr_drm_winsys *ws, uint32_t syncobj) +{ + if (ws->g5p_reuse) { + simple_mtx_lock(&ws->tmp_syncobjs.lock); + if (ws->tmp_syncobjs.ndirty < ARRAY_SIZE(ws->tmp_syncobjs.dirty)) { + ws->tmp_syncobjs.dirty[ws->tmp_syncobjs.ndirty++] = syncobj; + syncobj = 0; + } + simple_mtx_unlock(&ws->tmp_syncobjs.lock); + if (!syncobj) + return; + } + drmSyncobjDestroy(ws->base.render_fd, syncobj); +} + static VkResult pvr_drm_check_job_fences(struct pvr_winsys *base, uint32_t count, const struct vk_sync_wait *waits) @@ -198,6 +310,8 @@ static void pvr_drm_winsys_destroy(struct pvr_winsys *ws) if (drm_ws->query_only) goto out; + pvr_drm_import_cache_finish(drm_ws); + pvr_winsys_helper_free_static_memory(drm_ws->general_vma, drm_ws->pds_vma, drm_ws->usc_vma); @@ -213,6 +327,12 @@ static void pvr_drm_winsys_destroy(struct pvr_winsys *ws) util_sparse_array_finish(&drm_ws->bo_map); u_rwlock_destroy(&drm_ws->dmabuf_bo_lock); + for (uint32_t i = 0; i < drm_ws->tmp_syncobjs.nclean; i++) + drmSyncobjDestroy(ws->render_fd, drm_ws->tmp_syncobjs.clean[i]); + for (uint32_t i = 0; i < drm_ws->tmp_syncobjs.ndirty; i++) + drmSyncobjDestroy(ws->render_fd, drm_ws->tmp_syncobjs.dirty[i]); + simple_mtx_destroy(&drm_ws->tmp_syncobjs.lock); + simple_mtx_destroy(&drm_ws->import_cache.lock); vk_free(ws->alloc, drm_ws); } @@ -532,6 +652,7 @@ static const struct pvr_winsys_ops drm_winsys_ops = { .heap_free = pvr_drm_winsys_heap_free, .vma_map = pvr_drm_winsys_vma_map, .vma_unmap = pvr_drm_winsys_vma_unmap, + .vma_map_imported = pvr_drm_winsys_vma_map_imported, .vma_map_mirror = pvr_drm_winsys_vma_map_mirror, .free_list_create = pvr_drm_winsys_free_list_create, .free_list_destroy = pvr_drm_winsys_free_list_destroy, @@ -547,6 +668,10 @@ static const struct pvr_winsys_ops drm_winsys_ops = { .transfer_ctx_destroy = pvr_drm_winsys_transfer_ctx_destroy, .transfer_submit = pvr_drm_winsys_transfer_submit, .null_job_submit = pvr_drm_winsys_null_job_submit, + .stamp_create = pvr_drm_stamp_create, + .stamp_destroy = pvr_drm_stamp_destroy, + .stamp_query = pvr_drm_stamp_query, + .syncs_reset = pvr_drm_syncs_reset, }; struct pvr_static_data_area_description { @@ -857,6 +982,10 @@ VkResult pvr_drm_winsys_create(const int render_fd, util_sparse_array_init(&drm_ws->bo_map, sizeof(struct pvr_drm_winsys_bo), 512); + simple_mtx_init(&drm_ws->tmp_syncobjs.lock, mtx_plain); + drm_ws->import_cache.enabled = debug_get_bool_option("PVR_IMPORT_CACHE", true); + simple_mtx_init(&drm_ws->import_cache.lock, mtx_plain); + list_inithead(&drm_ws->import_cache.lru); result = pvr_drm_get_gpu_info(drm_ws, &gpu_info); if (result != VK_SUCCESS) @@ -871,10 +1000,12 @@ VkResult pvr_drm_winsys_create(const int render_fd, PVR_HAS_FEATURE(&info, apple_g9p); drm_ws->base.job_sync_size = drm_ws->job_fence_errors ? sizeof(struct pvr_drm_job_sync) : 0; - /* The A8's physical-device winsys answers device queries only: no VM context, heaps or static memory, so - * a process holds one VM (its VkDevice's) instead of two. powervr's A8 variant gives every VM the hardware - * object window, the zero and data pages and a user slot, and a client that never submits needs none. */ - drm_ws->query_only = query_only && PVR_HAS_FEATURE(&info, apple_g4p); + drm_ws->g5p_reuse = drm_ws->is_g5p && pvr_g5p_reuse_option(); + /* The physical-device winsys on A8 through A10 only answers device + * queries. The VkDevice's winsys owns the VM, heaps and static memory. + */ + drm_ws->query_only = query_only && (drm_ws->is_g5p || + PVR_HAS_FEATURE(&info, apple_g9p)); } if (drm_ws->query_only) { *ws_out = &drm_ws->base; @@ -933,6 +1064,8 @@ VkResult pvr_drm_winsys_create(const int render_fd, VK_ERROR_UNKNOWN); err_util_sparse_array_finish_bo_map: + simple_mtx_destroy(&drm_ws->import_cache.lock); + simple_mtx_destroy(&drm_ws->tmp_syncobjs.lock); util_sparse_array_finish(&drm_ws->bo_map); u_rwlock_destroy(&drm_ws->dmabuf_bo_lock); diff --git a/src/imagination/vulkan/winsys/powervr/pvr_drm.h b/src/imagination/vulkan/winsys/powervr/pvr_drm.h index 956c4232fcd..0e1c58aab49 100644 --- a/src/imagination/vulkan/winsys/powervr/pvr_drm.h +++ b/src/imagination/vulkan/winsys/powervr/pvr_drm.h @@ -30,8 +30,10 @@ #include "pvr_winsys.h" #include "vk_drm_syncobj.h" +#include "util/list.h" #include "util/macros.h" #include "util/rwlock.h" +#include "util/simple_mtx.h" #include "util/sparse_array.h" /* Identify job out-fences without inspecting ordinary poll waits. */ @@ -51,7 +53,7 @@ struct pvr_drm_winsys { uint64_t bvnc; bool is_g5p; - /* pvr_drm_winsys_create(query_only) on the A8: device queries only, no VM context */ + /* The physical-device winsys only answers device queries. */ bool query_only; uint64_t caps; int madvise_warning; @@ -104,8 +106,35 @@ struct pvr_drm_winsys { struct pvr_winsys_vma *general_vma; uint32_t vm_context; + + /* G5P submit reuse (PVR_G5P_REUSE, default on): a null job's merge + * syncobj is reset and kept instead of created and destroyed per job + * (pvr_drm_job_null.c). The dirty ones are reset together. + */ + bool g5p_reuse; + struct { + simple_mtx_t lock; + uint32_t clean[16], dirty[16]; + uint32_t nclean, ndirty; + } tmp_syncobjs; + + /* Cached whole-BO GPU VM mappings for imported buffers (PVR_IMPORT_CACHE, + * default on). Keyed by GEM handle via drm_bo->import_vma; active imports + * keep the mapping alive and recently released imports stay in the LRU so + * rotating surface pools avoid per-frame VM_MAP/VM_UNMAP TLB invalidations. + */ + struct { + bool enabled; + simple_mtx_t lock; + struct list_head lru; + uint32_t lru_count; + uint64_t lru_bytes; + } import_cache; }; +uint32_t pvr_drm_tmp_syncobj_get(struct pvr_drm_winsys *ws, int *err_out); +void pvr_drm_tmp_syncobj_put(struct pvr_drm_winsys *ws, uint32_t syncobj); + #define PVR_DRM_CAP_RETRY_ENOMEM DRM_PVR_CAP_RETRY_ENOMEM #define PVR_DRM_CAP_BO_MADVISE DRM_PVR_CAP_BO_MADVISE int pvr_drm_ioctl_retry(struct pvr_drm_winsys *ws, unsigned long request, void *args); diff --git a/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.c b/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.c index f63c5e7a138..6fed42d2684 100644 --- a/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.c +++ b/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.c @@ -182,6 +182,7 @@ static void pvr_drm_buffer_release(struct pvr_drm_winsys_bo *drm_bo) * since otherwise there is a chance the application creates another BO in * a different thread and gets the same array entry, causing a race. */ + assert(!drm_bo->import_vma); memset(drm_bo, 0, sizeof(*drm_bo)); g9p_bolog('-', handle, 0); @@ -495,25 +496,31 @@ VkResult pvr_drm_heap_alloc_carveout(struct pvr_winsys_heap *const heap, return result; } +static bool pvr_drm_import_cache_flush_lru(struct pvr_drm_winsys *drm_ws); + VkResult pvr_drm_winsys_heap_alloc(struct pvr_winsys_heap *heap, uint64_t size, uint64_t alignment, struct pvr_winsys_vma **const vma_out) { - const struct pvr_drm_winsys *const drm_ws = to_pvr_drm_winsys(heap->ws); + struct pvr_drm_winsys *const drm_ws = to_pvr_drm_winsys(heap->ws); struct pvr_drm_winsys_vma *drm_vma; VkResult result; - drm_vma = vk_alloc(drm_ws->base.alloc, - sizeof(*drm_vma), - 8, - VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + drm_vma = vk_zalloc(drm_ws->base.alloc, + sizeof(*drm_vma), + 8, + VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); if (!drm_vma) { result = vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY); goto err_out; } result = pvr_winsys_helper_heap_alloc(heap, size, alignment, &drm_vma->base); + if (result != VK_SUCCESS && heap == &drm_ws->general_heap.base && + pvr_drm_import_cache_flush_lru(drm_ws)) { + result = pvr_winsys_helper_heap_alloc(heap, size, alignment, &drm_vma->base); + } if (result != VK_SUCCESS) goto err_free_vma; @@ -537,6 +544,12 @@ void pvr_drm_winsys_heap_free(struct pvr_winsys_vma *vma) /* A vma with an existing device mapping should not be freed. */ assert(!drm_vma->base.bo); + if (drm_vma->is_import_view) { + assert(!drm_vma->import_vma); + vk_free(drm_ws->base.alloc, drm_vma); + return; + } + /* Check if we are dealing with carveout address range. */ if (vma->dev_addr.addr >= carveout_addr && vma->dev_addr.addr < @@ -642,8 +655,26 @@ VkResult pvr_drm_winsys_vma_map_mirror(struct pvr_winsys_vma *vma, struct pvr_wi return VK_SUCCESS; } +static void pvr_drm_import_vma_put(struct pvr_drm_winsys *drm_ws, + struct pvr_drm_import_vma *entry); + void pvr_drm_winsys_vma_unmap(struct pvr_winsys_vma *vma) { + struct pvr_drm_winsys_vma *const drm_vma = to_pvr_drm_winsys_vma(vma); + + /* Address should be mapped. */ + assert(vma->bo); + + if (drm_vma->import_vma) { + struct pvr_drm_winsys *const drm_ws = to_pvr_drm_winsys(vma->bo->ws); + + assert(!vma->mirrored); + pvr_drm_import_vma_put(drm_ws, drm_vma->import_vma); + drm_vma->import_vma = NULL; + vma->bo = NULL; + return; + } + if (vma->mirrored) { /* two mappings of the buffer (pvr_drm_winsys_vma_map_mirror()): the second one first, then the first * through the ordinary path */ @@ -667,9 +698,6 @@ void pvr_drm_winsys_vma_unmap(struct pvr_winsys_vma *vma) .size = vma->mapped_size, }; - /* Address should be mapped. */ - assert(vma->bo); - if (p_atomic_read(&drm_ws->lost)) { if (drmIoctl(drm_ws->base.render_fd, DRM_IOCTL_PVR_VM_UNMAP, &args) && p_atomic_cmpxchg(&drm_ws->unmap_loss_reported, 0, 1) == 0) { @@ -690,3 +718,332 @@ void pvr_drm_winsys_vma_unmap(struct pvr_winsys_vma *vma) vma->bo = NULL; } + +#define PVR_DRM_IMPORT_CACHE_MAX_LRU_ENTRIES 32U +#define PVR_DRM_IMPORT_CACHE_MAX_LRU_BYTES (64ULL * 1024 * 1024) + +struct pvr_drm_import_vma { + struct list_head lru_link; + struct pvr_drm_winsys_bo *drm_bo; + struct pvr_winsys_vma *backing_vma; + uint32_t use_count; + bool in_lru; +}; + +static void +pvr_drm_import_vma_destroy(struct pvr_drm_winsys *drm_ws, + struct pvr_drm_import_vma *entry) +{ + assert(entry->use_count == 0); + assert(!entry->in_lru); + + pvr_drm_winsys_vma_unmap(entry->backing_vma); + pvr_drm_winsys_heap_free(entry->backing_vma); + vk_free(drm_ws->base.alloc, entry); +} + +static void +pvr_drm_import_vma_put(struct pvr_drm_winsys *drm_ws, + struct pvr_drm_import_vma *entry) +{ + struct list_head to_evict; + list_inithead(&to_evict); + + simple_mtx_lock(&drm_ws->import_cache.lock); + + assert(entry->use_count > 0); + entry->use_count--; + + if (entry->use_count == 0) { + assert(!entry->in_lru); + if (entry->backing_vma->mapped_size > PVR_DRM_IMPORT_CACHE_MAX_LRU_BYTES) { + assert(entry->drm_bo->import_vma == entry); + entry->drm_bo->import_vma = NULL; + list_addtail(&entry->lru_link, &to_evict); + } else { + list_add(&entry->lru_link, &drm_ws->import_cache.lru); + entry->in_lru = true; + drm_ws->import_cache.lru_count++; + drm_ws->import_cache.lru_bytes += entry->backing_vma->mapped_size; + + while (drm_ws->import_cache.lru_count > + PVR_DRM_IMPORT_CACHE_MAX_LRU_ENTRIES || + drm_ws->import_cache.lru_bytes > + PVR_DRM_IMPORT_CACHE_MAX_LRU_BYTES) { + assert(!list_is_empty(&drm_ws->import_cache.lru)); + struct pvr_drm_import_vma *victim = + list_last_entry(&drm_ws->import_cache.lru, + struct pvr_drm_import_vma, + lru_link); + assert(victim->use_count == 0); + assert(victim->in_lru); + assert(victim->drm_bo->import_vma == victim); + + list_del(&victim->lru_link); + victim->in_lru = false; + drm_ws->import_cache.lru_count--; + drm_ws->import_cache.lru_bytes -= victim->backing_vma->mapped_size; + victim->drm_bo->import_vma = NULL; + list_addtail(&victim->lru_link, &to_evict); + } + } + } + + simple_mtx_unlock(&drm_ws->import_cache.lock); + + list_for_each_entry_safe (struct pvr_drm_import_vma, victim, &to_evict, lru_link) { + list_del(&victim->lru_link); + pvr_drm_import_vma_destroy(drm_ws, victim); + } +} + +static bool +pvr_drm_import_cache_flush_lru(struct pvr_drm_winsys *drm_ws) +{ + struct list_head to_evict; + list_inithead(&to_evict); + + simple_mtx_lock(&drm_ws->import_cache.lock); + list_for_each_entry_safe (struct pvr_drm_import_vma, entry, + &drm_ws->import_cache.lru, lru_link) { + assert(entry->use_count == 0); + assert(entry->in_lru); + assert(entry->drm_bo->import_vma == entry); + + list_del(&entry->lru_link); + entry->in_lru = false; + drm_ws->import_cache.lru_count--; + drm_ws->import_cache.lru_bytes -= entry->backing_vma->mapped_size; + entry->drm_bo->import_vma = NULL; + list_addtail(&entry->lru_link, &to_evict); + } + assert(drm_ws->import_cache.lru_count == 0); + assert(drm_ws->import_cache.lru_bytes == 0); + simple_mtx_unlock(&drm_ws->import_cache.lock); + + bool evicted = !list_is_empty(&to_evict); + list_for_each_entry_safe (struct pvr_drm_import_vma, victim, &to_evict, lru_link) { + list_del(&victim->lru_link); + pvr_drm_import_vma_destroy(drm_ws, victim); + } + + return evicted; +} + +void pvr_drm_import_cache_finish(struct pvr_drm_winsys *drm_ws) +{ + pvr_drm_import_cache_flush_lru(drm_ws); +} + +static VkResult +pvr_drm_vma_alloc_and_map(struct pvr_winsys_heap *heap, + struct pvr_winsys_bo *bo, + uint64_t offset, + uint64_t size, + uint64_t alignment, + struct pvr_winsys_vma **const vma_out, + pvr_dev_addr_t *const dev_addr_out) +{ + const uint64_t virt_size = size + (offset & (heap->page_size - 1)); + struct pvr_winsys_vma *vma; + VkResult result; + + result = pvr_drm_winsys_heap_alloc(heap, virt_size, alignment, &vma); + if (result != VK_SUCCESS) + return result; + + result = pvr_drm_winsys_vma_map(vma, bo, offset, size, dev_addr_out); + if (result != VK_SUCCESS) { + pvr_drm_winsys_heap_free(vma); + return result; + } + + *vma_out = vma; + return VK_SUCCESS; +} + +static bool +pvr_drm_import_vma_matches(const struct pvr_drm_import_vma *entry, + const struct pvr_winsys_heap *heap, + uint64_t offset, + uint64_t phys_page_offset, + uint64_t aligned_virt_size, + uint64_t alignment) +{ + const struct pvr_winsys_vma *backing = entry->backing_vma; + + if (backing->heap != heap) + return false; + if (phys_page_offset > backing->mapped_size || + aligned_virt_size > backing->mapped_size - phys_page_offset) + return false; + if (alignment > heap->page_size && + ((backing->dev_addr.addr + offset) & (alignment - 1)) != 0) + return false; + + return true; +} + +VkResult pvr_drm_winsys_vma_map_imported(struct pvr_winsys_heap *heap, + struct pvr_winsys_bo *bo, + uint64_t offset, + uint64_t size, + uint64_t alignment, + struct pvr_winsys_vma **const vma_out, + pvr_dev_addr_t *const dev_addr_out) +{ + struct pvr_drm_winsys_bo *const drm_bo = to_pvr_drm_winsys_bo(bo); + struct pvr_drm_winsys *const drm_ws = to_pvr_drm_winsys(bo->ws); + const uint64_t page_size = heap->page_size; + + if (!drm_ws->import_cache.enabled || heap != &drm_ws->general_heap.base || + size == 0) { + return pvr_drm_vma_alloc_and_map(heap, bo, offset, size, alignment, + vma_out, dev_addr_out); + } + + if (offset > bo->size || size > bo->size - offset) + return vk_error(NULL, VK_ERROR_MEMORY_MAP_FAILED); + + const uint64_t virt_offset = offset & (page_size - 1); + const uint64_t phys_page_offset = offset - virt_offset; + const uint64_t aligned_virt_size = ALIGN_POT(virt_offset + size, page_size); + const uint64_t map_size = bo->size & ~(page_size - 1); + + if (ALIGN_POT(offset + size, page_size) > bo->size || map_size == 0) + return vk_error(NULL, VK_ERROR_MEMORY_MAP_FAILED); + + struct pvr_drm_winsys_vma *drm_vma = + vk_zalloc(drm_ws->base.alloc, + sizeof(*drm_vma), + 8, + VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + if (!drm_vma) + return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY); + + struct pvr_drm_import_vma *entry = NULL; + bool fallback = false; + + simple_mtx_lock(&drm_ws->import_cache.lock); + if (drm_bo->import_vma) { + if (pvr_drm_import_vma_matches(drm_bo->import_vma, heap, offset, + phys_page_offset, aligned_virt_size, + alignment)) { + entry = drm_bo->import_vma; + if (entry->use_count == 0) { + assert(entry->in_lru); + list_del(&entry->lru_link); + entry->in_lru = false; + drm_ws->import_cache.lru_count--; + drm_ws->import_cache.lru_bytes -= entry->backing_vma->mapped_size; + } + entry->use_count++; + } else { + fallback = true; + } + } + simple_mtx_unlock(&drm_ws->import_cache.lock); + + if (fallback) { + vk_free(drm_ws->base.alloc, drm_vma); + return pvr_drm_vma_alloc_and_map(heap, bo, offset, size, alignment, + vma_out, dev_addr_out); + } + + if (!entry) { + struct pvr_drm_import_vma *new_entry = + vk_zalloc(drm_ws->base.alloc, + sizeof(*new_entry), + 8, + VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + if (!new_entry) { + vk_free(drm_ws->base.alloc, drm_vma); + return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY); + } + + VkResult result = pvr_drm_winsys_heap_alloc(heap, map_size, page_size, + &new_entry->backing_vma); + if (result != VK_SUCCESS) { + vk_free(drm_ws->base.alloc, new_entry); + vk_free(drm_ws->base.alloc, drm_vma); + return result; + } + + result = pvr_drm_winsys_vma_map(new_entry->backing_vma, bo, 0, map_size, + NULL); + if (result != VK_SUCCESS && pvr_drm_import_cache_flush_lru(drm_ws)) { + result = pvr_drm_winsys_vma_map(new_entry->backing_vma, bo, 0, + map_size, NULL); + } + if (result != VK_SUCCESS) { + pvr_drm_winsys_heap_free(new_entry->backing_vma); + vk_free(drm_ws->base.alloc, new_entry); + vk_free(drm_ws->base.alloc, drm_vma); + return result; + } + + new_entry->drm_bo = drm_bo; + + if (!pvr_drm_import_vma_matches(new_entry, heap, offset, phys_page_offset, + aligned_virt_size, alignment)) { + pvr_drm_import_vma_destroy(drm_ws, new_entry); + vk_free(drm_ws->base.alloc, drm_vma); + return pvr_drm_vma_alloc_and_map(heap, bo, offset, size, alignment, + vma_out, dev_addr_out); + } + + struct pvr_drm_import_vma *discard = NULL; + + simple_mtx_lock(&drm_ws->import_cache.lock); + if (!drm_bo->import_vma) { + new_entry->use_count = 1; + drm_bo->import_vma = new_entry; + entry = new_entry; + } else if (pvr_drm_import_vma_matches(drm_bo->import_vma, heap, offset, + phys_page_offset, aligned_virt_size, + alignment)) { + entry = drm_bo->import_vma; + if (entry->use_count == 0) { + assert(entry->in_lru); + list_del(&entry->lru_link); + entry->in_lru = false; + drm_ws->import_cache.lru_count--; + drm_ws->import_cache.lru_bytes -= entry->backing_vma->mapped_size; + } + entry->use_count++; + discard = new_entry; + } else { + discard = new_entry; + fallback = true; + } + simple_mtx_unlock(&drm_ws->import_cache.lock); + + if (discard) + pvr_drm_import_vma_destroy(drm_ws, discard); + + if (fallback) { + vk_free(drm_ws->base.alloc, drm_vma); + return pvr_drm_vma_alloc_and_map(heap, bo, offset, size, alignment, + vma_out, dev_addr_out); + } + } + + const uint64_t view_mapped_size = + entry->backing_vma->mapped_size - phys_page_offset; + + drm_vma->base.heap = heap; + drm_vma->base.bo = bo; + drm_vma->base.bo_offset = offset; + drm_vma->base.dev_addr = + PVR_DEV_ADDR_OFFSET(entry->backing_vma->dev_addr, phys_page_offset); + drm_vma->base.size = view_mapped_size; + drm_vma->base.mapped_size = view_mapped_size; + drm_vma->import_vma = entry; + drm_vma->is_import_view = true; + + if (dev_addr_out) + *dev_addr_out = PVR_DEV_ADDR_OFFSET(drm_vma->base.dev_addr, virt_offset); + + *vma_out = &drm_vma->base; + return VK_SUCCESS; +} diff --git a/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.h b/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.h index 323ce6e4d04..a3ab85a7441 100644 --- a/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.h +++ b/src/imagination/vulkan/winsys/powervr/pvr_drm_bo.h @@ -36,6 +36,8 @@ struct definitions *******************************************/ +struct pvr_drm_import_vma; + struct pvr_drm_winsys_bo { struct pvr_winsys_bo base; uint32_t ref_count; @@ -44,10 +46,20 @@ struct pvr_drm_winsys_bo { uint8_t count_kind; uint32_t handle; uint64_t flags; + + /* Cached whole-BO GPU VM mapping for imported buffers (protected by + * drm_ws->import_cache.lock). While non-NULL, the entry holds a ref on this + * BO so the kernel keeps the GEM handle stably bound to the same dma-buf. + */ + struct pvr_drm_import_vma *import_vma; }; struct pvr_drm_winsys_vma { struct pvr_winsys_vma base; + /* Non-NULL while bound to a cached imported-BO mapping. */ + struct pvr_drm_import_vma *import_vma; + /* True for view VMAs returned by vma_map_imported() (do not heap_free). */ + bool is_import_view; }; /******************************************* @@ -91,6 +103,14 @@ VkResult pvr_drm_winsys_vma_map(struct pvr_winsys_vma *vma, uint64_t size, pvr_dev_addr_t *dev_addr_out); void pvr_drm_winsys_vma_unmap(struct pvr_winsys_vma *vma); +VkResult pvr_drm_winsys_vma_map_imported(struct pvr_winsys_heap *heap, + struct pvr_winsys_bo *bo, + uint64_t offset, + uint64_t size, + uint64_t alignment, + struct pvr_winsys_vma **vma_out, + pvr_dev_addr_t *dev_addr_out); +void pvr_drm_import_cache_finish(struct pvr_drm_winsys *drm_ws); VkResult pvr_drm_winsys_vma_map_mirror(struct pvr_winsys_vma *vma, struct pvr_winsys_bo *bo); /******************************************* diff --git a/src/imagination/vulkan/winsys/powervr/pvr_drm_job_compute.c b/src/imagination/vulkan/winsys/powervr/pvr_drm_job_compute.c index 98990b7cf18..ba03ebc7725 100644 --- a/src/imagination/vulkan/winsys/powervr/pvr_drm_job_compute.c +++ b/src/imagination/vulkan/winsys/powervr/pvr_drm_job_compute.c @@ -181,7 +181,7 @@ VkResult pvr_drm_winsys_compute_submit( struct pvr_drm_winsys_compute_ctx *drm_ctx = to_pvr_drm_winsys_compute_ctx((struct pvr_winsys_compute_ctx *)ctx); - struct drm_pvr_sync_op sync_ops[2]; + struct drm_pvr_sync_op sync_ops[3]; /* wait, signal, stamp */ struct drm_pvr_job job_args = { .type = DRM_PVR_JOB_TYPE_COMPUTE, .context_handle = drm_ctx->handle, @@ -219,6 +219,15 @@ VkResult pvr_drm_winsys_compute_submit( }; } + if (submit_info->stamp.syncobj) { + assert(submit_info->stamp.point); + sync_ops[job_args.sync_ops.count++] = (struct drm_pvr_sync_op){ + .handle = submit_info->stamp.syncobj, + .flags = DRM_PVR_SYNC_OP_FLAG_SIGNAL | DRM_PVR_SYNC_OP_FLAG_HANDLE_TYPE_TIMELINE_SYNCOBJ, + .value = submit_info->stamp.point, + }; + } + /* Returns VK_ERROR_OUT_OF_DEVICE_MEMORY to match pvrsrv. */ const VkResult result = pvr_drm_submit_jobs(drm_ws, &args, "compute"); if (result == VK_SUCCESS) diff --git a/src/imagination/vulkan/winsys/powervr/pvr_drm_job_null.c b/src/imagination/vulkan/winsys/powervr/pvr_drm_job_null.c index d4b70229850..3791968a7c9 100644 --- a/src/imagination/vulkan/winsys/powervr/pvr_drm_job_null.c +++ b/src/imagination/vulkan/winsys/powervr/pvr_drm_job_null.c @@ -71,9 +71,16 @@ VkResult pvr_drm_winsys_null_job_submit(struct pvr_winsys *ws, return VK_SUCCESS; } - ret = drmSyncobjCreate(drm_ws->base.render_fd, - wait_count == 0 ? DRM_SYNCOBJ_CREATE_SIGNALED : 0, - &tmp_syncobj); + if (wait_count == 0) { + ret = drmSyncobjCreate(drm_ws->base.render_fd, DRM_SYNCOBJ_CREATE_SIGNALED, &tmp_syncobj); + } else { + /* G5P reuse: a kept merge syncobj, reset (no fence, point 0) */ + int err; + + tmp_syncobj = pvr_drm_tmp_syncobj_get((struct pvr_drm_winsys *)drm_ws, &err); + ret = tmp_syncobj ? 0 : -1; + errno = err; + } if (ret) { return vk_errorf(NULL, VK_ERROR_OUT_OF_DEVICE_MEMORY, @@ -122,6 +129,9 @@ VkResult pvr_drm_winsys_null_job_submit(struct pvr_winsys *ws, } out_destroy_tmp_syncobj: - drmSyncobjDestroy(drm_ws->base.render_fd, tmp_syncobj); + if (wait_count == 0) + drmSyncobjDestroy(drm_ws->base.render_fd, tmp_syncobj); + else + pvr_drm_tmp_syncobj_put((struct pvr_drm_winsys *)drm_ws, tmp_syncobj); return result; } diff --git a/src/imagination/vulkan/winsys/powervr/pvr_drm_job_render.c b/src/imagination/vulkan/winsys/powervr/pvr_drm_job_render.c index ddf43186e42..dd360bc10f0 100644 --- a/src/imagination/vulkan/winsys/powervr/pvr_drm_job_render.c +++ b/src/imagination/vulkan/winsys/powervr/pvr_drm_job_render.c @@ -486,7 +486,8 @@ VkResult pvr_drm_winsys_render_submit( const struct pvr_drm_winsys_rt_dataset *drm_rt_dataset = to_pvr_drm_winsys_rt_dataset(submit_info->rt_dataset); - struct drm_pvr_sync_op geom_sync_ops[2], pr_sync_ops[1], frag_sync_ops[3]; + /* one more each for a stamp (pvr_winsys_stamp) */ + struct drm_pvr_sync_op geom_sync_ops[3], pr_sync_ops[2], frag_sync_ops[4]; unsigned num_geom_syncs = 0, num_pr_syncs = 0, num_frag_syncs = 0; uint32_t geom_to_pr_syncobj; @@ -619,6 +620,25 @@ VkResult pvr_drm_winsys_render_submit( } } + /* The stamp: signalled by the submission's last job, so its point is + * reached only when every job of this submission (and, as the timeline's + * points only grow, of every earlier stamped one) has completed. */ + if (submit_info->stamp.syncobj) { + const struct drm_pvr_sync_op stamp = { + .handle = submit_info->stamp.syncobj, + .flags = DRM_PVR_SYNC_OP_FLAG_SIGNAL | DRM_PVR_SYNC_OP_FLAG_HANDLE_TYPE_TIMELINE_SYNCOBJ, + .value = submit_info->stamp.point, + }; + + assert(submit_info->stamp.point); + if (submit_info->has_fragment_job) + frag_sync_ops[num_frag_syncs++] = stamp; + else if (pr_state->fw_stream_len) + pr_sync_ops[num_pr_syncs++] = stamp; + else + geom_sync_ops[num_geom_syncs++] = stamp; + } + jobs_args[0].sync_ops.count = num_geom_syncs; /* the fragment job follows the partial-render job, or the geometry job without one */ if (pr_state->fw_stream_len) diff --git a/src/imagination/vulkan/winsys/pvr_winsys.h b/src/imagination/vulkan/winsys/pvr_winsys.h index 79dac01e211..9804626fedc 100644 --- a/src/imagination/vulkan/winsys/pvr_winsys.h +++ b/src/imagination/vulkan/winsys/pvr_winsys.h @@ -39,6 +39,7 @@ #include "pvr_rogue_fw.h" #include "pvr_types.h" #include "util/macros.h" +#include "util/u_debug.h" #include "util/vma.h" #include "vk_sync.h" #include "vk_sync_timeline.h" @@ -300,7 +301,26 @@ struct pvr_winsys_transfer_submit_info { struct pvr_g5p_dispatch_log; +/* G5P: a queue's completion stamp. A job that carries one also signals point + * `point` of the timeline syncobj `syncobj` when it completes, in the same + * submission (no extra ioctl). The points of a queue only grow, so the + * timeline's value is the last point up to which every stamped job of that + * queue has completed (pvr_g5p_reuse.h). syncobj 0: no stamp. */ +struct pvr_winsys_stamp { + uint32_t syncobj; + uint64_t point; +}; + +/* PVR_G5P_REUSE=0 turns G5P submit reuse off (the stamps, the command stream + * block cache, the sync pool and the null job's kept merge syncobj), for a + * same-boot A/B. Read at winsys and device creation only. */ +static inline bool pvr_g5p_reuse_option(void) +{ + return debug_get_bool_option("PVR_G5P_REUSE", true); +} + struct pvr_winsys_compute_submit_info { + struct pvr_winsys_stamp stamp; const struct pvr_g5p_dispatch_log *g5p_log; unsigned g5p_log_count; uint32_t frame_num; @@ -322,6 +342,8 @@ struct pvr_winsys_compute_submit_info { }; struct pvr_winsys_render_submit_info { + /* signalled by the submission's last job (fragment if any, else geometry) */ + struct pvr_winsys_stamp stamp; struct pvr_winsys_rt_dataset *rt_dataset; uint8_t rt_data_idx; @@ -414,6 +436,16 @@ struct pvr_winsys_ops { uint64_t size, pvr_dev_addr_t *dev_addr_out); void (*vma_unmap)(struct pvr_winsys_vma *vma); + /* Optional: allocate/reuse a cached GPU VM mapping for an imported BO + * (keyed by GEM handle, reference-counted with a small LRU). Released via + * vma_unmap() + heap_free() like an ordinary VMA. NULL where unsupported. */ + VkResult (*vma_map_imported)(struct pvr_winsys_heap *heap, + struct pvr_winsys_bo *bo, + uint64_t offset, + uint64_t size, + uint64_t alignment, + struct pvr_winsys_vma **vma_out, + pvr_dev_addr_t *dev_addr_out); /* The whole of bo mapped twice back to back, at vma->dev_addr and vma->dev_addr + bo->size (the vma holds * at least 2 * bo->size): the A8's region-header ring, which AGXG4P maps that way (kext 0x847d738, resources * created with flag 0x200000) so a frame's slice can run past the ring's end. Two VM_MAPs of one buffer; @@ -479,6 +511,18 @@ struct pvr_winsys_ops { struct vk_sync_wait *waits, uint32_t wait_count, struct vk_sync_signal *signal_sync); + + /* Optional (G5P submit reuse, pvr_g5p_reuse.h); NULL where unsupported. */ + /* a timeline syncobj for a queue's stamps, at point 0 */ + VkResult (*stamp_create)(struct pvr_winsys *ws, uint32_t *syncobj_out); + void (*stamp_destroy)(struct pvr_winsys *ws, uint32_t syncobj); + /* the completed point of each of count stamp timelines, one ioctl */ + VkResult (*stamp_query)(struct pvr_winsys *ws, const uint32_t *syncobjs, uint64_t *points, + uint32_t count); + /* Return count binary job syncs (of the device's sync type, from this + * winsys) to their initial state, as vk_sync_create(..., 0) leaves them: no + * fence, no job tag. One ioctl for all of them. */ + VkResult (*syncs_reset)(struct pvr_winsys *ws, struct vk_sync *const *syncs, uint32_t count); }; struct pvr_winsys {