mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-23 05:25:56 +00:00
TOTK_SYNC_AHEAD=1 works without shadow storage: the frame wait is answered one frame late with the GPU reading the game's memory in place, as Savage Wind does
With shadow off the back end turns on guards, each with its own switch: the mirror syncs copy the synced pages into staging on the CPU at submit and wait for an earlier write-back into the same range first (TOTK_SYNC_AHEAD_MSYNC), a texture the CPU rewrote takes the CPU deswizzle (TOTK_SYNC_AHEAD_DESWZ), an invalidate of a range not read lately waits for the pending GPU write into it, from a bounded list pruned at completion (TOTK_SYNC_AHEAD_READS), and the frame wait waits up to the value of a one-off small target (Savage Wind's 16-frame, 64-entry rule, TOTK_SYNC_AHEAD_ONESHOT) or, off by default, of a samples-passed report (TOTK_SYNC_AHEAD_QUERIES). TOTK_SYNC_AHEAD_CHECK=1 runs the check-mode detector with the late wait itself. The shadow form and the default are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
df10f20fe4
commit
b558317a7a
10 files changed
+418
-52
No files matched your search
+37
-14
@@ -1,4 +1,5 @@
|
||||
"""Exercise the production sync-ahead wait selection with a deterministic back end (TOTK_SYNC_AHEAD 0, 1, check).
|
||||
"""Exercise the production sync-ahead wait selection with a deterministic back end (TOTK_SYNC_AHEAD 0, 1, check; shadow
|
||||
storage on and off, the in-place form's wait up to a one-off value).
|
||||
|
||||
python tests/sync_ahead_check.py [--cc path/to/clang]
|
||||
"""
|
||||
@@ -40,7 +41,13 @@ static const char *cfg_value(const char *name) {
|
||||
assert(!strcmp(name, "TOTK_SYNC_AHEAD"));
|
||||
return enabled == 2 ? "check" : enabled ? "1" : "0";
|
||||
}
|
||||
static int entry_calls, lag_calls, done_calls, done_ok;
|
||||
static int entry_calls, lag_calls, done_calls, done_ok, oneshot_calls;
|
||||
static int vk_ahead_on; // the detector: check mode, or the switch on with TOTK_SYNC_AHEAD_CHECK=1 (det)
|
||||
static uint64_t oneshot, oneshot_lo, oneshot_hi; // the back end's one-off value (vk_ahead_oneshot: in (lo, hi] or 0)
|
||||
static uint64_t vk_ahead_oneshot(uint64_t lo, uint64_t hi) {
|
||||
oneshot_calls++, oneshot_lo = lo, oneshot_hi = hi;
|
||||
return oneshot > lo && oneshot <= hi ? oneshot : 0;
|
||||
}
|
||||
static uint64_t lag_asked, lag_value;
|
||||
static int lag_behind;
|
||||
static void vk_ahead_frame_entry(void) { assert(!lag_calls && !done_calls); entry_calls++; }
|
||||
@@ -70,8 +77,9 @@ PRODUCTION
|
||||
static uint32_t seed = 0x19ed634b;
|
||||
static uint32_t random_word(void) { seed ^= seed << 13; seed ^= seed >> 17; return seed ^= seed << 5; }
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 4);
|
||||
assert(argc == 5);
|
||||
rt_game_version = atoi(argv[1]); enabled = atoi(argv[2]); shadow = atoi(argv[3]);
|
||||
int det = atoi(argv[4]);
|
||||
int supported = rt_game_version == 110 || rt_game_version == 121 || rt_game_version == 143;
|
||||
uint64_t site = rt_game_version == 110 ? 0x7000b39aa4ull : rt_game_version == 121 ? 0x7000b23dfcull :
|
||||
rt_game_version == 143 ? 0x70002db99cull : 0;
|
||||
@@ -79,11 +87,12 @@ int main(int argc, char **argv) {
|
||||
qstamp_on = rt_game_version == 143 && enabled;
|
||||
last = 20; nvn_sync_ahead_present();
|
||||
last = 40; nvn_sync_ahead_present();
|
||||
int on = enabled == 1 && shadow && supported, check = enabled == 2 && supported;
|
||||
int on = enabled == 1 && supported, check = enabled == 2 && supported; // shadow off: the in-place form
|
||||
vk_ahead_on = check || (on && det);
|
||||
assert(pa_fence[0] == (on || check ? 40 : 0));
|
||||
assert(pa_fence[1] == (on || check ? 20 : 0));
|
||||
assert(qstamp_on == (rt_game_version == 143 && on)); // a refused switch and check leave the game's check
|
||||
int relaxed_cases = 0, polls = 0, other_waits = 0;
|
||||
int relaxed_cases = 0, polls = 0, other_waits = 0, oneshot_cases = 0;
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
sync_t sync = {.fenced = random_word() % 2, .fence = random_word() % 65};
|
||||
uint64_t timeout = i % 3 == 0 ? 0 : i % 3 == 1 ? 1 : UINT64_MAX;
|
||||
@@ -91,25 +100,36 @@ int main(int argc, char **argv) {
|
||||
completed = random_word() % 65;
|
||||
uint64_t initial_done = completed, target = sync.fence;
|
||||
succeed = random_word() % 2;
|
||||
oneshot = random_word() % 4 ? 0 : random_word() % 65;
|
||||
int lagcase = sync.fenced && timeout && lr == site && completed < target && target > 20 && target <= 40;
|
||||
relaxed = on && lagcase;
|
||||
int checked = check && sync.fenced && timeout && lr == site;
|
||||
// the late wait waits for 20, or for a one-off value in (20, target] the back end names
|
||||
uint64_t late = lagcase && oneshot > 20 && oneshot <= target ? oneshot : 20;
|
||||
relaxed = on && lagcase && late < target;
|
||||
int oneshot_asked = on && lagcase;
|
||||
oneshot_cases += oneshot_asked && late > 20;
|
||||
int checked = vk_ahead_on && sync.fenced && timeout && lr == site;
|
||||
int checkcase = checked && target > 20 && target <= 40; // check: as if the GPU were behind
|
||||
relaxed_cases += relaxed; polls += timeout == 0; other_waits += lr != site;
|
||||
if (relaxed) target = 20;
|
||||
replay_calls = shadow_calls = sync_calls = wait_calls = 0;
|
||||
if (relaxed) target = late;
|
||||
replay_calls = shadow_calls = sync_calls = wait_calls = oneshot_calls = 0;
|
||||
entry_calls = lag_calls = done_calls = 0;
|
||||
synced = waited = waited_timeout = replay_value = UINT64_MAX;
|
||||
pa_guard = 0;
|
||||
Cpu cpu = {0}; cpu.x[0] = (uintptr_t)&sync; cpu.x[1] = timeout; cpu.x[30] = lr;
|
||||
nvnSyncWait(&cpu);
|
||||
assert(replay_calls == relaxed && shadow_calls == relaxed);
|
||||
assert(oneshot_calls == oneshot_asked);
|
||||
if (oneshot_asked) assert(oneshot_lo == 20 && oneshot_hi == sync.fence);
|
||||
assert(entry_calls == checked && lag_calls == checked && done_calls == checked);
|
||||
if (checked) { // exact wait, the late one's value told to the check
|
||||
if (checked && check) { // exact wait, the late one's value told to the check
|
||||
assert(lag_asked == sync.fence && lag_value == (checkcase ? 20 : sync.fence));
|
||||
assert(lag_behind == (initial_done < sync.fence));
|
||||
assert(done_ok == (initial_done >= target || succeed));
|
||||
}
|
||||
if (checked && on) { // the late wait itself: the value it waited for told to the detector
|
||||
assert(lag_asked == sync.fence && lag_value == (relaxed ? late : sync.fence));
|
||||
assert(done_ok == (initial_done >= target || succeed));
|
||||
}
|
||||
assert(pa_guard == (relaxed ? sync.fence : 0));
|
||||
if (relaxed) assert(replay_value == sync.fence);
|
||||
if (!sync.fenced) {
|
||||
@@ -125,16 +145,18 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
assert(polls > 0 && other_waits > 0);
|
||||
assert((relaxed_cases > 0) == on);
|
||||
assert((relaxed_cases > 0) == on && (oneshot_cases > 0) == on);
|
||||
// Raising the guard for an older request must not lower a guard already published by another waiter.
|
||||
if (on) {
|
||||
sync_t sync = {.fenced = 1, .fence = 35};
|
||||
completed = 25; pa_guard = 39; relaxed = 1;
|
||||
completed = 25; pa_guard = 39; relaxed = 1; oneshot = 0;
|
||||
replay_calls = shadow_calls = sync_calls = wait_calls = entry_calls = lag_calls = done_calls = 0;
|
||||
Cpu cpu = {0}; cpu.x[0] = (uintptr_t)&sync; cpu.x[1] = UINT64_MAX; cpu.x[30] = site;
|
||||
nvnSyncWait(&cpu);
|
||||
assert(pa_guard == 39);
|
||||
}
|
||||
printf("sync-ahead version %d enabled %d shadow %d: 100000 wait selections passed (%d relaxed)\n", rt_game_version, enabled, shadow, relaxed_cases);
|
||||
printf("sync-ahead version %d enabled %d shadow %d detector %d: 100000 wait selections passed (%d relaxed, %d up "
|
||||
"to a one-off value)\n", rt_game_version, enabled, shadow, det, relaxed_cases, oneshot_cases);
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -155,7 +177,8 @@ def main():
|
||||
for version in (110, 121, 143, 999):
|
||||
for enabled in (0, 1, 2):
|
||||
for shadow in (0, 1):
|
||||
subprocess.run([str(exe), str(version), str(enabled), str(shadow)], check=True)
|
||||
for det in (0, 1):
|
||||
subprocess.run([str(exe), str(version), str(enabled), str(shadow), str(det)], check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user