Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions src/asahi/vulkan/hk_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,18 +2222,20 @@ queue_submit_recordings(struct hk_device *dev, struct hk_queue *queue,
nr_cdm++;
}

/* Tile hazards against this queue's earlier submissions need the point
* the queue has completed; fetched only when a partial-tile render pass
* instance is submitted while such a footprint may still be running. On
* failure every earlier submission is treated as still running. */
uint64_t completed = 0;
/* Tile hazards against this queue's earlier submissions and retired exact
* prior pruning need the point the queue has completed. Start from the
* cached monotonic lower bound and refresh via drmSyncobjQuery() when live
* footprints or unretired exact priors exist. On failure, earlier
* submissions remain conservatively treated as running. */
uint64_t completed = p_atomic_read(&queue->drm.signalled_value);
if (hk_sync_submit_needs_completed(
queue, (struct hk_cmd_buffer *const *)submit->command_buffers,
submit->command_buffer_count)) {
submit->command_buffer_count) ||
hk_sync_submit_has_unretired_priors(queue)) {
uint64_t point = 0;
if (drmSyncobjQuery(dev->dev.fd, &queue->drm.syncobj, &point, 1) == 0) {
hk_queue_note_signalled(queue, point);
completed = point;
completed = MAX2(completed, point);
}
}

Expand Down Expand Up @@ -2581,18 +2583,36 @@ queue_submit_recordings(struct hk_device *dev, struct hk_queue *queue,
}
hk_query_stamps_note_cs(dev, queue, queue->drm.timeline_value, cs);

/* Prefer DRM_ASAHI_RENDER_FRAGMENT_BARRIERS over staged render
* prefixes whenever the vertex half needs no render prefix and the
* compute prefix is unchanged: both describe identical ordering,
* while FRAGMENT_BARRIERS keeps the smaller render payload and
* stays eligible for direct kernel publication. */
const bool m5_frag_barriers_only =
(dev->dev.params.features &
DRM_ASAHI_FEATURE_FRAGMENT_BARRIERS) &&
cs->sync.ta_split &&
cs->sync.barrier_ta[HK_SYNC_VDM] == DRM_ASAHI_BARRIER_NONE &&
cs->sync.prior_ta[HK_SYNC_VDM] == 0 &&
ta_command_prior[HK_SYNC_VDM] == 0 &&
cs->sync.barrier_ta[HK_SYNC_CDM] == cs->sync.barrier[HK_SYNC_CDM] &&
cs->sync.prior_ta[HK_SYNC_CDM] == cs->sync.prior[HK_SYNC_CDM] &&
ta_command_prior[HK_SYNC_CDM] == command_prior[HK_SYNC_CDM] &&
(cs->sync.barrier[HK_SYNC_VDM] != DRM_ASAHI_BARRIER_NONE ||
cs->sync.prior[HK_SYNC_VDM] != 0);

/* M5: the vertex half's own render and compute prefixes, when
* they are narrower than the whole render's, so its tiling can
* overlap the fragment work of the renders only its fragment
* half depends on. Supersedes the single-subqueue forms below. */
const bool m5_staged_v2 =
agx_chip_g17_m5(dev->dev.chip) && !queue->sync.serialize &&
queue->sync.exact_prior &&
queue->sync.exact_prior && !m5_frag_barriers_only &&
(dev->dev.params.features &
DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2) &&
cs->sync.ta_split;
const bool stage_prefixes =
!m5_staged_v2 &&
!m5_staged_v2 && !m5_frag_barriers_only &&
agx_chip_g17_m5(dev->dev.chip) && !queue->sync.serialize &&
queue->sync.exact_prior &&
(dev->dev.params.features &
Expand Down
64 changes: 64 additions & 0 deletions src/asahi/vulkan/hk_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,51 @@ hk_sync_submit_needs_completed(const struct hk_queue *queue,
return false;
}

bool
hk_sync_submit_has_unretired_priors(const struct hk_queue *queue)
{
const struct hk_sync_queue *q = &queue->sync;
return q->exact_prior && q->retired_count > 0 &&
(q->submitted[HK_SYNC_VDM] > q->retired_ord[HK_SYNC_VDM] ||
q->submitted[HK_SYNC_CDM] > q->retired_ord[HK_SYNC_CDM]);
}

static void
sync_advance_retired(struct hk_sync_queue *q, uint64_t completed)
{
const uint32_t n = MIN2(q->retired_count, HK_SYNC_RETIRED_RING);
for (uint32_t i = 0; i < n; ++i) {
if (q->retired[i].point && q->retired[i].point <= completed) {
for (unsigned sq = 0; sq < HK_SYNC_NUM_SQ; ++sq)
q->retired_ord[sq] = MAX2(q->retired_ord[sq], q->retired[i].ord[sq]);
}
}

for (unsigned sq = 0; sq < HK_SYNC_NUM_SQ; ++sq) {
const uint64_t ret = q->retired_ord[sq];
if (!ret)
continue;
for (unsigned k = 0; k < HK_SYNC_NUM_KINDS; ++k) {
if (q->last_absolute[k][sq] <= ret)
q->last_absolute[k][sq] = 0;
if (q->tail[k][sq] <= ret)
q->tail[k][sq] = 0;
}
}
}

static void
sync_record_retired(struct hk_sync_queue *q, uint64_t point)
{
if (!point)
return;
q->retired[q->retired_next].point = point;
for (unsigned sq = 0; sq < HK_SYNC_NUM_SQ; ++sq)
q->retired[q->retired_next].ord[sq] = q->submitted[sq];
q->retired_next = (q->retired_next + 1) % HK_SYNC_RETIRED_RING;
q->retired_count = MIN2(q->retired_count + 1, HK_SYNC_RETIRED_RING);
}

/* Whether a footprint of an earlier render on the render subqueue that
* shares a tile with fp needs only fp's fragment half ordered after it
* (hk_sync_queue::load_hazard_frag). */
Expand Down Expand Up @@ -2958,6 +3003,8 @@ hk_sync_resolve_submit_ex(struct hk_queue *queue,
if (queue->sync.submitted[sq] > UINT64_MAX - added[sq])
return false;
}
if (completed)
sync_advance_retired(&queue->sync, completed);
}

bool indexed = !queue->sync.precise_tile_evictions ||
Expand Down Expand Up @@ -3285,6 +3332,21 @@ hk_sync_resolve_submit_ex(struct hk_queue *queue,
covered[sq] = cs->sync.index;
}

/* Prune exact historical priors already retired on the queue timeline
* before computing ta_split so stale ordinals (e.g. an old GFX_MEM
* render) do not block fragment-only barriers or direct submission. */
if (queue->sync.exact_prior) {
for (unsigned sq = 0; sq < HK_SYNC_NUM_SQ; ++sq) {
const uint64_t ret = queue->sync.retired_ord[sq];
if (ret) {
if (cs->sync.prior[sq] <= ret)
cs->sync.prior[sq] = 0;
if (cs->sync.prior_ta[sq] <= ret)
cs->sync.prior_ta[sq] = 0;
}
}
}

/* A render's vertex half may wait for less than its fragment half
* only when the kernel orders the halves separately and nothing
* above raised the whole render's fields afterwards (the
Expand Down Expand Up @@ -3361,6 +3423,8 @@ hk_sync_resolve_submit_ex(struct hk_queue *queue,
*tail_raised_out = tail_raised;
for (unsigned sq = 0; sq < HK_SYNC_NUM_SQ; ++sq)
queue->sync.submitted[sq] += ss.count[sq];
if (ss.count[HK_SYNC_VDM] || ss.count[HK_SYNC_CDM])
sync_record_retired(&queue->sync, queue->drm.timeline_value);
}

/* This queue has now run these kinds. */
Expand Down
14 changes: 13 additions & 1 deletion src/asahi/vulkan/hk_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,23 @@ struct hk_sync_queue {
* (hk_sync.h, tile hazards). */
bool load_hazard_frag;
uint64_t last_preserve, evicted_preserve;

/* Recent VDM renders' attachment blooms for exact-image HK_SYNC_GFX_IMG
* narrowing across submissions. */
struct hk_sync_vdm_att recent_vdm_att[HK_SYNC_RECENT_VDM_ATT];
uint32_t recent_vdm_att_next, recent_vdm_att_count;
uint64_t recent_vdm_att_evicted;

/* Retired-ordinal map for exact priors: each entry pairs a queue timeline
* point with the submitted VDM/CDM ordinals through that submission. Once
* `completed >= point`, every ordinal up to `ord[sq]` has retired and can
* be pruned to 0. */
#define HK_SYNC_RETIRED_RING 64
struct {
uint64_t point;
uint64_t ord[HK_SYNC_NUM_SQ];
} retired[HK_SYNC_RETIRED_RING];
uint32_t retired_next, retired_count;
uint64_t retired_ord[HK_SYNC_NUM_SQ];
};

void hk_sync_reset(struct hk_cmd_buffer *cmd);
Expand Down Expand Up @@ -819,6 +830,7 @@ void hk_sync_apply_dep(struct hk_cmd_buffer *cmd, struct hk_cs *into,
bool hk_sync_submit_needs_completed(const struct hk_queue *queue,
struct hk_cmd_buffer *const *cmdbufs,
unsigned count);
bool hk_sync_submit_has_unretired_priors(const struct hk_queue *queue);

/* The driver's own resolve pass after a render: waits on the render. */
void hk_sync_resolve_begin(struct hk_cmd_buffer *cmd);
Expand Down
49 changes: 49 additions & 0 deletions src/asahi/vulkan/tests/test-hk-sync-prior.c
Original file line number Diff line number Diff line change
Expand Up @@ -3232,6 +3232,55 @@ main(void)
p_atomic_read(&mq->drm.signalled_value) == 12);
}
test_vertex_image_bloom();
/* Retired exact prior pruning drops completed VDM/CDM ordinals while
* preserving unretired dependencies and FRAGMENT_BARRIERS ta_split. */
{
struct hk_queue *rq = new_queue(true);
/* Submit 1 (point 10): HK_SYNC_GFX_MEM render (ord 1) + barrier. */
rq->drm.timeline_value = 10;
struct hk_cmd_buffer *s1 = new_cmd();
struct hk_cs *r_mem = add(s1, false);
hk_sync_note_memory_write(s1, r_mem);
hk_sync_barrier(s1, HK_SYNC_ALL, HK_SYNC_ALL);
T("retired-prior setup s1",
hk_sync_resolve_submit(rq, &s1, 1, false, false, 0, NULL));
T("retired-prior reports unretired priors after s1",
hk_sync_submit_has_unretired_priors(rq));

/* Submit 2 (point 11): plain render (ord 2) + fragment-only barrier,
* while point 10 is still in flight (completed = 0). */
rq->drm.timeline_value = 11;
struct hk_cmd_buffer *s2 = new_cmd();
struct hk_cs *r2 = add(s2, false);
hk_sync_barrier(s2, HK_SYNC_GFX, HK_SYNC_GFX_FRAG);
T("retired-prior s2 unretired",
hk_sync_resolve_submit(rq, &s2, 1, false, false, 0, NULL));
T("retired-prior keeps unretired GFX_MEM prior_ta",
r2->sync.prior[HK_SYNC_VDM] == 1 && r2->sync.prior_ta[HK_SYNC_VDM] == 1);

/* Submit 3 (point 12): point 10 has retired (completed = 10), point 11
* is still live -> prior_ta[VDM] (1) prunes to 0 while prior[VDM] (2)
* stays live with ta_split=true! */
rq->drm.timeline_value = 12;
struct hk_cmd_buffer *s3 = new_cmd();
struct hk_cs *r3 = add(s3, false);
T("retired-prior s3 partial retirement",
hk_sync_resolve_submit(rq, &s3, 1, false, false, 10, NULL));
T("retired-prior prunes retired prior_ta while keeping live fragment prior",
r3->sync.prior[HK_SYNC_VDM] == 2 && r3->sync.prior_ta[HK_SYNC_VDM] == 0 &&
r3->sync.ta_split);

/* Submit 4 (point 13): everything through point 12 has retired -> both
* prior and prior_ta prune to 0 and ta_split clears. */
rq->drm.timeline_value = 13;
struct hk_cmd_buffer *s4 = new_cmd();
struct hk_cs *r4 = add(s4, false);
T("retired-prior s4 full retirement",
hk_sync_resolve_submit(rq, &s4, 1, false, false, 12, NULL));
T("retired-prior clears both priors and ta_split when all retired",
r4->sync.prior[HK_SYNC_VDM] == 0 && r4->sync.prior_ta[HK_SYNC_VDM] == 0 &&
!r4->sync.ta_split);
}
printf("RESULT checks=%u failures=%u\n", tests, failures);
ralloc_free(test_context);
return failures ? EXIT_FAILURE : EXIT_SUCCESS;
Expand Down