mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 12:59:58 -04:00
Leave lazily armed memory out of the camera-speed search, so a sensitivity change no longer fetches GPU buffers.
camera_speed.c rewrite reads the guest's heap and alias regions in 16 MiB pieces under mem_read_hold and skipped only untouched lazy-heap runs. A piece holding pages the lazy write-back had armed (GPU-written buffers the CPU has not read since) faulted into memory.c lazy_fault on each armed range, which fetches it from the GPU under frz_lock while the game runs, disarms those buffers, and keeps the game's mapping calls waiting on the read hold meanwhile. This happened at every change of the stick sensitivity with the lazy write-back on (the Windows default except on AMD's driver). A piece that mem_lazy_touches reports armed is now gone through in 64 KiB steps, and the armed steps are not read; the camera table never lies in a GPU-written buffer. The step after a piece still starts a little before its end, so a copy across two steps or two pieces is found as before. The first search that leaves memory out logs how much, since with NX2NAVI_WB_PROBE every range counts as armed and the search then reports the table "not in memory". A range armed between the check and the read still costs one fetch, as before. Not reproduced before the change (no log of a sensitivity change under trace). tests/camera_search_check.py cuts factor and rewrite from camera_speed.c over a 40 MiB stand-in heap with one armed 64 KiB step: the copies in plain memory, across two pieces and across two steps are rewritten, the copy in armed memory is left alone and no read touches it, the left-out memory is logged once, and with every range armed nothing is read. Against the previous camera_speed.c it fails six of its checks. mouse_stick_check passes, and the compile check adds no warnings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -161,8 +161,15 @@ static void factor(float out[8], float k) { // the array at factor k, as cam_p
|
||||
// read and write; each copy found becomes the array at factor to and is remembered (copies, when fresh is set).
|
||||
// Returns how many were rewritten. Runs on its own thread: the regions are read 16 MiB at a time under mem_read_hold,
|
||||
// so the game's own mapping calls wait for one piece at most.
|
||||
// Pages the lazy write-back has armed (GPU-written buffers the CPU has not read since, never the camera table) are
|
||||
// left alone: a read would fetch each armed range from the GPU inside the fault handler (memory.c lazy_fault) while
|
||||
// the game runs, and hold the game's mapping calls meanwhile. A piece that holds some is gone through in STEP pieces,
|
||||
// without the armed ones; the first search that leaves some out says so, since with NX2NAVI_WB_PROBE every piece
|
||||
// counts as armed and the search then finds nothing.
|
||||
static int rewrite(float k, float to, int fresh) {
|
||||
enum { PIECE = 16 << 20 };
|
||||
enum { PIECE = 16 << 20, STEP = 64 << 10 };
|
||||
static int told;
|
||||
uint64_t left_out = 0;
|
||||
float from[8], into[8];
|
||||
factor(from, k);
|
||||
factor(into, to);
|
||||
@@ -189,6 +196,14 @@ static int rewrite(float k, float to, int fresh) {
|
||||
continue;
|
||||
}
|
||||
uint64_t n = stop - a < PIECE ? stop - a : PIECE;
|
||||
if (mem_lazy_touches(a, n)) {
|
||||
if (n > STEP) n = STEP;
|
||||
if (mem_lazy_touches(a, n)) {
|
||||
a += n;
|
||||
left_out += n;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (n >= len && mem_read_hold(a, n)) {
|
||||
const uint8_t *p = (const uint8_t *)(uintptr_t)a, *e = p + n;
|
||||
for (const uint8_t *q = p; q + len <= e && (q = memchr(q, first, (size_t)(e - q) - len + 1)); q++) {
|
||||
@@ -201,10 +216,15 @@ static int rewrite(float k, float to, int fresh) {
|
||||
mem_read_release();
|
||||
}
|
||||
// a copy across two pieces: the next piece starts a little before this one's end
|
||||
a += n < PIECE ? n : n - (len - 1);
|
||||
a += a + n >= stop ? n : n - (len - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (left_out && !told) {
|
||||
told = 1;
|
||||
rt_log("camera speed: the search left out %.1f MiB the GPU wrote and the CPU has not read since (lazy "
|
||||
"write-back; with NX2NAVI_WB_PROBE all of it)", left_out / 1048576.0);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user