Add shared pose motion vectors for Link and attached equipment

This commit is contained in:
automata.
2026-11-12 10:35:57 -05:00
committed by chrg6
parent 38afed16d5
commit b29cbbe6a6
11 changed files with 900 additions and 59 deletions

View File

@@ -24,6 +24,7 @@
#include "host.h"
#include "nvn_api.h"
#include "vk.h"
#include "motion_owner.h"
#include "vk_dlaa.h"
#include "platform/platform.h"
@@ -53,6 +54,7 @@ static struct {
int on; // this submission has a snapshot
uint64_t fence, gen;
Arena *arena;
MotionOwnerSnapshot *owners;
Rng *col; // collected ranges
int ncol, ccol;
Reg *reg; // merged, sorted by lo, disjoint
@@ -72,6 +74,7 @@ static PlatMutex gather_lock = PLAT_MUTEX_INIT;
// A copy taken at the submit call for the replay thread (vk_usnap_take), in submission order.
typedef struct Taken {
struct Taken *next;
MotionOwnerSnapshot *owners;
Arena *arena;
Reg *reg;
int nreg, n;
@@ -310,6 +313,10 @@ void vk_usnap_take(const uint64_t *handles, int n) {
Taken *t = calloc(1, sizeof *t);
if (!t) rt_fatal("vk_usnap: out of memory");
t->n = n, t->first = handles[0];
if (motion_owner_enabled()) {
t->owners = malloc(sizeof *t->owners);
if (t->owners) motion_owner_capture(t->owners);
}
int creg = 0;
plat_mutex_lock(&gather_lock);
U.ncol = 0;
@@ -342,6 +349,7 @@ void vk_usnap_take(const uint64_t *handles, int n) {
static void taken_free(Taken *t) {
if (t->arena) arena_done(t->arena);
free(t->owners);
free(t->reg);
free(t);
}
@@ -370,6 +378,7 @@ static int adopt(const uint64_t *handles, int n) {
if (wr_hits(U.reg[i].lo, U.reg[i].hi)) U.reg[i].dropped = 1, U.inflight++;
U.arena = t->arena, t->arena = NULL;
U.on = 1;
U.owners = t->owners, t->owners = NULL;
U.subs++, U.regions += (uint64_t)U.nreg, U.bytes += t->total, U.copy_ns += t->ns;
}
taken_free(t);
@@ -378,6 +387,7 @@ static int adopt(const uint64_t *handles, int n) {
void vk_usnap_begin(const uint64_t *handles, int n, uint64_t fence) {
if (!U.mode) U.mode = rt_knob("UBO_SNAPSHOT", "1") + 1; // stored +1: 0 is "not read yet"
free(U.owners), U.owners = NULL;
U.on = 0, U.fence = fence, U.gen++;
summary();
if (!RT_KNOB_ON(U.mode - 1)) {
@@ -386,6 +396,11 @@ void vk_usnap_begin(const uint64_t *handles, int n, uint64_t fence) {
return;
}
if (adopt(handles, n)) return;
// Without a producer snapshot, asynchronous replay must not read present-day actor ownership.
if (!gfx_replay_async() && motion_owner_enabled()) {
U.owners = malloc(sizeof *U.owners);
if (U.owners) motion_owner_capture(U.owners);
}
uint64_t t0 = kern_now_ns();
plat_mutex_lock(&gather_lock);
U.ncol = 0;
@@ -424,6 +439,7 @@ void vk_usnap_begin(const uint64_t *handles, int n, uint64_t fence) {
void vk_usnap_end(uint64_t fence) {
if (U.arena) vk_completion_add(fence, arena_done, U.arena), U.arena = NULL;
free(U.owners), U.owners = NULL;
U.on = 0, U.gen++;
}
@@ -529,6 +545,7 @@ const uint8_t *vk_usnap_bytes(uint64_t addr, uint64_t n) {
// The arenas back on the free list (vk_exec_draw_shutdown: the device is idle, every completion ran).
void vk_usnap_shutdown(void) {
free(U.owners), U.owners = NULL;
plat_mutex_lock(&free_lock);
for (Arena *a = free_arenas, *next; a; a = next) next = a->next, vmaDestroyBuffer(vk_ctx()->vma, a->buf, a->alloc), free(a->cpu), free(a);
free_arenas = NULL;
@@ -545,3 +562,22 @@ void vk_usnap_sizes(PerfSizes *s) {
perf_size(s, "free uniform snapshot arenas", n, 0, b);
perf_size(s, "uniform snapshot GPU writes", (uint64_t)__atomic_load_n(&U.nwr, __ATOMIC_RELAXED), 0, PERF_SIZE_NONE);
}
// Ownership travels with the uniform snapshot. A missing, GPU-written, or overlapping range is not a match.
int vk_usnap_motion_owner(uint64_t address, uint64_t size, MotionOwner *out) {
if (!U.on || !U.owners || !size || address > UINT64_MAX - size ||
vk_usnap_why(address, size) != VK_USNAP_FOUND) return 0;
// The producer excludes overlapping identities and sorts the remaining disjoint ranges once.
// Most scene draws are unowned, so do not scan every player binding for each one.
unsigned lo = 0, hi = U.owners->count;
while (lo < hi) {
unsigned mid = lo + (hi - lo) / 2;
if (U.owners->bindings[mid].address <= address) lo = mid + 1;
else hi = mid;
}
if (!lo) return 0;
const MotionOwnerBinding *b = &U.owners->bindings[lo - 1];
if (size > b->size || address - b->address > b->size - size) return 0;
*out = b->owner;
return 1;
}