nvnSyncWait on a sync that was never fenced answers timeout, but the console answers failed #1515

Open
opened 2026-11-18 01:46:13 +00:00 by mooki · 1 comment
Member

Type: correctness · Area: NVN host layer, sync objects · Part of: #1493

TL;DR

nvnSyncWait on a sync object that was initialised but never fenced returns NVN_SYNC_WAIT_RESULT_TIMEOUT_EXPIRED in the port. The console's driver returns NVN_SYNC_WAIT_RESULT_FAILED for the same call, so the port's own comment "as on the console" is wrong. We propose one changed result code, plus a once-logged line so a run shows whether the game ever takes this path.

Breakdown

  • Who it affects: only code that waits on a sync before any fence call has been made on it. Whether the game does that has not been counted in a run. The existing sync log does not tell a never-fenced wait from any other.
  • What is wrong: the host answers "timed out", which tells a caller to try again. The console answers "failed", which tells it the wait cannot succeed.
  • What we propose: return FAILED for a never-fenced sync, fix the comment, and log the first few hits.
  • What does not change: every other nvnSyncWait result. The study confirmed that the port matches the console for already signalled (0), waited (1) and timed out (2), for the nanosecond timeout (a timeout of 0 is a poll), and for the all-ones infinite timeout.
  • Can it change pixels: not directly. It changes which way the caller's code goes. A caller that retries on timeout would spin; a caller that checks for failure would take its error path. Which one the game does is not known.
  • How we would prove it: a game-free test of the real function, then a normal run that shows how often the new log line fires.

Evidence

Port code is on forge/main at 310e7c9df. Nothing here was run in a game.

What the port does today

  • host/nvn_native.c:1127 has the comment "never fenced: times out, as on the console", and :1133 is if (!s->fenced) { RET(NVN_SYNC_WAIT_RESULT_TIMEOUT_EXPIRED); return; }.
  • nvnSyncInitialize sets fenced = 0 (:1063). nvnQueueFenceSync sets fenced = 1 (:1105). Window-acquire syncs and syncs made from a native handle are marked 3, "signalled" (:2571, :2681), so they are not touched by this change.
  • The result codes are in gpu/render/nvn_api.h:1045-1048: 0 already signalled, 1 condition satisfied, 2 timeout expired, 3 failed.
  • The sync log line at :1130-1132 prints the fence number and the timeout but does not say whether the sync was ever fenced.

What the console does (behaviour only)

  • A sync that has been initialised and never fenced answers NVN_SYNC_WAIT_RESULT_FAILED at once, whatever the timeout. A fenced sync answers 0, 1 or 2 as the port does.

This comes from a private study of the console driver (read, then confirmed by running the driver's functions alone in an emulator); no code, addresses or game data from it are here.

Can it change anything seen? It changes control flow at the call site, so it can change timing (a spin removed) or take a path the port has never run (an error path). It does not change a picture by itself. We would see it as the new log line, and as a frame-pacing change only if the game was spinning on this call.

Proposed change

  1. host/nvn_native.c:1133: return NVN_SYNC_WAIT_RESULT_FAILED when the sync was never fenced. Fix the comment at :1127.
  2. Log the first few hits once each, with the caller's address, in the style of the QueueWaitSync line at :1837-1839 ("a sync not fenced yet"), so the log answers "does the game ever do this".
  3. Nothing else in nvnSyncWait changes.

How we would test it

  • Game-free, fails today (a new tests/test_nvn_sync_wait.py, built like tests/test_nvn_null_pool.py, which compiles the real function from host/nvn_native.c with stubs for the renderer's wait and the clock):
    1. a sync from nvnSyncInitialize, never fenced, timeout 0 and timeout infinite: expects 3 (today 2);
    2. a fenced sync whose fence is already done: expects 0;
    3. a fenced sync, not done, timeout 0: expects 2;
    4. a fenced sync that becomes done during the wait: expects 1;
    5. a window-acquire sync (marked 3): expects 0.
      Only case 1 fails on current main; the other four lock in what already matches.
  • Game run: one ordinary run from boot into play with the new log line on. Before and after, count the lines. If the count is 0 in every run we try, the change is harmless for the game and we say so. If it is not 0, we compare the same save and spot before and after, and describe what the caller did.
  • Pictures: an image hash of fixed spots before and after, only needed if the count is not 0.
  • Speed: no speed claim. If a removed spin ever shows up as a frame-time change, it needs paired timing after a null main-against-main pair.

#1493 (renderer rewrite; this is one of the places where the host answers differently from the console). No thread covers a wait on a never-fenced sync. Searched open and closed issues and pull requests for SyncWait, nvnSyncWait, sync wait, never fenced, fence sync and TIMEOUT_EXPIRED. Threads that touch the same function: #916 (closed, left as a record) changed nvnSyncWait for the frame limiter's call only, and its check built the real function with a fake GPU, which is the fixture this issue's test would use. #1268, #1190 and #1020 (open) are about the time the main thread spends in fenced nvnSyncWait waits, a different question that this change does not touch. #656 (open) is about another wait, the present poll.

New on this forge; not opened on GitHub.

**Type:** correctness · **Area:** NVN host layer, sync objects · **Part of:** #1493 ## TL;DR `nvnSyncWait` on a sync object that was initialised but never fenced returns `NVN_SYNC_WAIT_RESULT_TIMEOUT_EXPIRED` in the port. The console's driver returns `NVN_SYNC_WAIT_RESULT_FAILED` for the same call, so the port's own comment "as on the console" is wrong. We propose one changed result code, plus a once-logged line so a run shows whether the game ever takes this path. ## Breakdown - **Who it affects:** only code that waits on a sync before any fence call has been made on it. Whether the game does that has not been counted in a run. The existing sync log does not tell a never-fenced wait from any other. - **What is wrong:** the host answers "timed out", which tells a caller to try again. The console answers "failed", which tells it the wait cannot succeed. - **What we propose:** return `FAILED` for a never-fenced sync, fix the comment, and log the first few hits. - **What does not change:** every other `nvnSyncWait` result. The study confirmed that the port matches the console for already signalled (0), waited (1) and timed out (2), for the nanosecond timeout (a timeout of 0 is a poll), and for the all-ones infinite timeout. - **Can it change pixels:** not directly. It changes which way the caller's code goes. A caller that retries on timeout would spin; a caller that checks for failure would take its error path. Which one the game does is not known. - **How we would prove it:** a game-free test of the real function, then a normal run that shows how often the new log line fires. ## Evidence Port code is on forge/main at 310e7c9df. Nothing here was run in a game. **What the port does today** - `host/nvn_native.c:1127` has the comment "never fenced: times out, as on the console", and `:1133` is `if (!s->fenced) { RET(NVN_SYNC_WAIT_RESULT_TIMEOUT_EXPIRED); return; }`. - `nvnSyncInitialize` sets `fenced = 0` (`:1063`). `nvnQueueFenceSync` sets `fenced = 1` (`:1105`). Window-acquire syncs and syncs made from a native handle are marked 3, "signalled" (`:2571`, `:2681`), so they are not touched by this change. - The result codes are in `gpu/render/nvn_api.h:1045-1048`: 0 already signalled, 1 condition satisfied, 2 timeout expired, 3 failed. - The sync log line at `:1130-1132` prints the fence number and the timeout but does not say whether the sync was ever fenced. **What the console does** (behaviour only) - A sync that has been initialised and never fenced answers `NVN_SYNC_WAIT_RESULT_FAILED` at once, whatever the timeout. A fenced sync answers 0, 1 or 2 as the port does. This comes from a private study of the console driver (read, then confirmed by running the driver's functions alone in an emulator); no code, addresses or game data from it are here. **Can it change anything seen?** It changes control flow at the call site, so it can change timing (a spin removed) or take a path the port has never run (an error path). It does not change a picture by itself. We would see it as the new log line, and as a frame-pacing change only if the game was spinning on this call. ## Proposed change 1. `host/nvn_native.c:1133`: return `NVN_SYNC_WAIT_RESULT_FAILED` when the sync was never fenced. Fix the comment at `:1127`. 2. Log the first few hits once each, with the caller's address, in the style of the QueueWaitSync line at `:1837-1839` ("a sync not fenced yet"), so the log answers "does the game ever do this". 3. Nothing else in `nvnSyncWait` changes. ## How we would test it - **Game-free, fails today** (a new `tests/test_nvn_sync_wait.py`, built like `tests/test_nvn_null_pool.py`, which compiles the real function from `host/nvn_native.c` with stubs for the renderer's wait and the clock): 1. a sync from `nvnSyncInitialize`, never fenced, timeout 0 and timeout infinite: expects 3 (today 2); 2. a fenced sync whose fence is already done: expects 0; 3. a fenced sync, not done, timeout 0: expects 2; 4. a fenced sync that becomes done during the wait: expects 1; 5. a window-acquire sync (marked 3): expects 0. Only case 1 fails on current main; the other four lock in what already matches. - **Game run:** one ordinary run from boot into play with the new log line on. Before and after, count the lines. If the count is 0 in every run we try, the change is harmless for the game and we say so. If it is not 0, we compare the same save and spot before and after, and describe what the caller did. - **Pictures:** an image hash of fixed spots before and after, only needed if the count is not 0. - **Speed:** no speed claim. If a removed spin ever shows up as a frame-time change, it needs paired timing after a null main-against-main pair. ## Related #1493 (renderer rewrite; this is one of the places where the host answers differently from the console). No thread covers a wait on a never-fenced sync. Searched open and closed issues and pull requests for SyncWait, nvnSyncWait, sync wait, never fenced, fence sync and TIMEOUT_EXPIRED. Threads that touch the same function: #916 (closed, left as a record) changed `nvnSyncWait` for the frame limiter's call only, and its check built the real function with a fake GPU, which is the fixture this issue's test would use. #1268, #1190 and #1020 (open) are about the time the main thread spends in fenced `nvnSyncWait` waits, a different question that this change does not touch. #656 (open) is about another wait, the present poll. New on this forge; not opened on GitHub.
Collaborator

Possibly related, for context:

  • issue #1493 Renderer rewrite — Parent renderer-rewrite initiative; this host-layer correctness discrepancy is within its scope.
  • PR #916 WIP: perf(nvn): the game's frame limiter waits for the frame before last on the GPU, so heavy scenes run 11 to 15 % faster — Prior change and test coverage for the real nvnSyncWait function, but it targets a different call site and wait behavior.
Possibly related, for context: - issue #1493 Renderer rewrite — Parent renderer-rewrite initiative; this host-layer correctness discrepancy is within its scope. - PR #916 WIP: perf(nvn): the game's frame limiter waits for the frame before last on the GPU, so heavy scenes run 11 to 15 % faster — Prior change and test coverage for the real nvnSyncWait function, but it targets a different call site and wait behavior.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot#1515
No description provided.