mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 11:29:58 -04:00
Under the perf trace, name the guest threads that submit and present on each queue, and log a submit or present that starts while another runs.
The synchronous replay's front end takes no lock of its own and relies on one such call at a time; a run now shows whether that holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,10 @@ _Static_assert(sizeof(nvn_mapping_t) == 0x28, "NVNmappingRequest stride");
|
||||
const pool_t *nvn_pool_find(uint64_t addr, uint64_t len); // GPU-visible pool holding [addr, addr+len], NULL if none
|
||||
uint64_t nvn_prog_made_ns(uint64_t serial); // NX2NAVI_PROG_LEAD: when the program was made, 0 unknown
|
||||
uint64_t nvn_new_serial(void); // next tex_t / prog_t serial, from 1
|
||||
// NX2NAVI_TRACE=perf: a guest thread enters (enter 1) or leaves (0) QueueSubmitCommands (present 0) or
|
||||
// QueuePresentTexture (1) on queue q: the first call of each thread, kind and queue gets a line, and so does a call
|
||||
// that enters while another of these calls runs (nvn_api_core.c nvn_call_note).
|
||||
void nvn_call_note(int present, uintptr_t q, int enter);
|
||||
uint64_t nvn_fence_last(void); // fence value of the newest submit (0 before the first)
|
||||
int nvn_depth_minus_w(void); // 1 after DeviceSetDepthMode(NEAR_IS_MINUS_W), else 0
|
||||
extern int nvn_submits_in_frame; // nvnQueueSubmitCommands calls since the last present (NX2NAVI_SUBMIT_FINISH)
|
||||
|
||||
@@ -624,12 +624,47 @@ static uint64_t lod_entered, lod_issued, lod_fence[LOD_RING];
|
||||
// core given up (section 2.2), or queued for the replay thread (NX2NAVI_REPLAY_ASYNC, vk_backend.c); the newest fence
|
||||
// value is what QueueFenceSync records. With the queue the fence covers replay and GPU, so the LOD guard below waits
|
||||
// for both.
|
||||
// NX2NAVI_TRACE=perf (nvn_api.h): which threads submit and present, and whether two of these calls run at once. The
|
||||
// synchronous replay's front end (vk_backend.c submit_sync, vk_be_present's held present, nvn_submits_in_frame) takes
|
||||
// no lock of its own, so it relies on one thread at a time; this tells a run whether that holds.
|
||||
void nvn_call_note(int present, uintptr_t q, int enter) {
|
||||
if (!(rt_trace & RT_TRACE_PERF)) return;
|
||||
static volatile int32_t inside;
|
||||
static volatile int32_t overlaps;
|
||||
static PlatMutex seen_lock = PLAT_MUTEX_INIT;
|
||||
static struct { uint32_t tid; uintptr_t q; int present; } seen[32];
|
||||
static int nseen;
|
||||
if (!enter) {
|
||||
plat_dec32(&inside);
|
||||
return;
|
||||
}
|
||||
int32_t n = plat_inc32(&inside);
|
||||
uint32_t tid = plat_thread_id();
|
||||
if (n > 1) {
|
||||
int32_t k = plat_inc32(&overlaps);
|
||||
if (k <= 16 || !(k & (k - 1)))
|
||||
rt_log("nvn: thread %u enters %s on queue %#llx while %d other submit or present call%s run (overlap %d, "
|
||||
"frame %llu)", tid, present ? "a present" : "a submit", (unsigned long long)q, n - 1, n > 2 ? "s" : "",
|
||||
k, (unsigned long long)__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED));
|
||||
}
|
||||
plat_mutex_lock(&seen_lock);
|
||||
int i = 0;
|
||||
while (i < nseen && !(seen[i].tid == tid && seen[i].q == q && seen[i].present == present)) i++;
|
||||
int fresh = i == nseen && nseen < 32;
|
||||
if (fresh) seen[nseen++] = (typeof(seen[0])){tid, q, present};
|
||||
plat_mutex_unlock(&seen_lock);
|
||||
if (fresh)
|
||||
rt_log("nvn: thread %u %s on queue %#llx (first at frame %llu)", tid, present ? "presents" : "submits",
|
||||
(unsigned long long)q, (unsigned long long)__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED));
|
||||
}
|
||||
|
||||
NVN_API(nvnQueueSubmitCommands) {
|
||||
queue_t *q = arg_p(c, 0);
|
||||
int n = (int)arg_x(c, 1);
|
||||
const uint64_t *h = arg_p(c, 2);
|
||||
if (n < 0 || (n && !h)) rt_fatal("nvn: QueueSubmitCommands with %d handles at %p", n, (const void *)h);
|
||||
NVN_BLOCKING();
|
||||
nvn_call_note(0, (uintptr_t)q, 1);
|
||||
uint64_t no = __atomic_add_fetch(&lod_entered, 1, __ATOMIC_SEQ_CST);
|
||||
q->submits++;
|
||||
uint64_t f;
|
||||
@@ -675,6 +710,7 @@ NVN_API(nvnQueueSubmitCommands) {
|
||||
}
|
||||
int idx = nvn_submits_in_frame++;
|
||||
if (finish_mask && f && (finish_mask == -1 || (idx < 63 && (finish_mask >> idx & 1)))) gfx_backend()->exec_wait(f, UINT64_MAX);
|
||||
nvn_call_note(0, (uintptr_t)q, 0);
|
||||
}
|
||||
|
||||
// The producer (1.2.1 main f_70008c6460) releases the read lock on obj+0x538 at lr 0x70008c70c8; when
|
||||
|
||||
@@ -864,6 +864,7 @@ NVN_API(nvnQueuePresentTexture) {
|
||||
NVN_BLOCKING();
|
||||
if (o->magic != NVN_WIN_MAGIC || idx < 0 || idx >= o->ntex || idx >= 4 || !o->tex[idx])
|
||||
rt_fatal("nvn: QueuePresentTexture of image %d on window %p", idx, (void *)o);
|
||||
nvn_call_note(1, (uintptr_t)arg_p(c, 0), 1);
|
||||
o->presents++;
|
||||
nvn_submits_in_frame = 0;
|
||||
const tex_t *t = (const tex_t *)o->tex[idx];
|
||||
@@ -877,4 +878,5 @@ NVN_API(nvnQueuePresentTexture) {
|
||||
last_present_fence = nvn_fence_last();
|
||||
frame_step_present(slot, o->interval); // frame_rate.c: the real-time step follows the display times
|
||||
rt_frame_presented(t, o->presents);
|
||||
nvn_call_note(1, (uintptr_t)arg_p(c, 0), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user