Repository navigation
Preserve D3D9 state lifetimes and add staged performance diagnostics - #1
Conversation
…stics Publish the current candidate with native behavior regressions, source mapping reuse, bounded patch-rejection retries and paired measurement evidence. Keep end-to-end performance caveats and current local compiler failures explicit.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 491f8aa493
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| std::lock_guard<std::recursive_mutex> lock(m_bridgeObserverMutex); | ||
| const auto observer = m_bridgeObserver; | ||
| if (event == D3D9BridgeEvent::FinalRelease) | ||
| m_bridgeObserver = {}; | ||
| if (observer.Notify) | ||
| observer.Notify(observer.Context, this, event, result, params, present); |
There was a problem hiding this comment.
Keep lifecycle callbacks in a consistent device-lock order
For a multithreaded device, an overlapping Reset and Present can deadlock during measurement. Reset acquires LockDevice() before calling NotifyBridge, whereas PresentEx calls NotifyBridge(PresentAfter) without that lock. The Present callback holds m_bridgeObserverMutex while OnUnwrappedDeviceEvent calls RuntimePresent, whose attribution/HUD path calls GetAudit() and acquires the device lock. If Reset acquires the device lock first, it waits for the observer mutex while Present waits for the device lock, permanently blocking both threads. Serialize these lifecycle notifications with a consistent lock order rather than invoking device-lock-taking callbacks under the observer mutex in the opposite order.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Implemented in follow-up PR #2, commit f6876b2f. Both SetObserver and NotifyBridge now acquire the recursive device lock before the observer lock. Notification stays synchronous, including unregister and final release.
The native regression runs Reset on the device-creation thread while a second thread Presents, then reenters the real GetAudit from the callback. The pre-fix DLL deadlocks and exits through the watchdog with code 86; the fixed DLL passes 33 checks, including concurrent unregister and absence of later callbacks. Existing final-release audit coverage and the 82-check native runtime suite also pass.
The complete local pipeline passed 85/85 required/executed checks, with zero failures and only the two missing-external-input audit skips. Detailed regression evidence. The follow-up PR is open and not merged.
| if (!g_owner) g_owner = GetCurrentThreadId(); | ||
| g_controller.SetAvailable(g_config.cpu, g_config.journal || g_diagnostics != nullptr); | ||
| if (g_device != device || g_owner != GetCurrentThreadId()) return; |
There was a problem hiding this comment.
Validate the capture device before assigning its owner thread
If a secondary device presents on another thread before the selected device's first Present, this assigns the secondary thread to g_owner before rejecting its device. RuntimePrepareDevice retains the first registered device, and OnUnwrappedDeviceEvent forwards Presents from every registered device, so this ordering is reachable with multiple devices. All subsequent Presents from the selected device's actual render thread then fail the owner check, leaving its measurement HUD and F7/F8 capture permanently inactive until that device is released. Reject non-selected devices before initializing g_owner.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Implemented in follow-up PR #2, commit f6876b2f. The g_device != device guard now runs before owner assignment, capture-state advancement and key consumption.
The regression prepares a real selected HAL device, then Presents a second real device from another thread first with F8 held. The old runtime fails to start the selected device's capture. The fix passes all 8 focused checks: the secondary device does not consume F8 or start workers, and the selected render thread completes the capture with actual CPU samples. The complete native runtime suite passes 82 checks; full local validation is 85 passed / 0 failed / 2 missing-external-input skips.
Regression and validation report. The follow-up PR is open and not merged.
| RuntimeCpuModule module; | ||
| module.base = reinterpret_cast<std::uintptr_t>(entry.modBaseAddr); | ||
| module.size = entry.modBaseSize; | ||
| module.path = entry.szExePath; |
There was a problem hiding this comment.
Convert enumerated module paths to UTF-8 before resolving symbols
When the game is installed under a non-ASCII path on a Windows system using a non-UTF-8 ANSI code page, this stores ANSI bytes in module.path: the Bridge project uses CharacterSet=MultiByte, so MODULEENTRY32 and Module32First select the ANSI API. ResolveCpu subsequently passes that string to MeasurementSymbolResolver::LoadModule, which interprets it with std::filesystem::u8path. For example, a CP1252 path containing é cannot be decoded as UTF-8, so loading the Bridge/backend DLL and its valid .rsym fails and the capture loses its function-level attribution. Enumerate with the wide APIs and explicitly encode the resulting path as UTF-8.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Implemented in follow-up PR #2, commit f6876b2f. Module collection now uses MODULEENTRY32W, Module32FirstW and Module32NextW, followed by explicit UTF-16 → UTF-8 conversion.
The native regression runs under Windows ACP 936 and loads an actual backend DLL plus its matching RSYM from a path containing Chinese characters, é and Ω. It checks the captured report path, validates the sidecar against that DLL and resolves the real Direct3DCreate9 address. The old enumerator fails the lossless-path assertion; the fixed runtime passes all 9 focused checks. Full local validation is 85 passed / 0 failed / 2 missing-external-input skips.
Regression and validation report. The follow-up PR is open and not merged.
Repeated D3D9 state restoration and texture-source mapping reclamation add CPU work and require precise resource lifetimes. This candidate preserves those lifetimes, reduces redundant state/submission work, and provides staged F7/F8 diagnostics with HUD, main-thread/CS attribution and exact-binary symbol sidecars.
Included:
Validation:
6dd8c85a044d1236d7cebeccc586fb879b6f926b; its Git tree was verified identical to head491f8aa4934914a94746901115aa557ce5ccd354.Performance limits: pressured mip-chain uploads reduced CPU cycles about 7%, and failed-patch polling reduced CPU work in the recorded experiments. Single-mip and empty-Present wall-time regressions are included. Whole-Present throughput and a controlled fixed-route GTA FPS/first-exit improvement remain unproven; these limits are retained after manual functional acceptance.
See candidate status, measurement report and paired evidence.
Vulkan staging/copy behavior and public interfaces are retained. No new batching/multicore implementation is included.
Game acceptance (2026-11-09):
Post-merge verification:
659f9ed60084f16dba98bb4cd396edeca2ab17cc; main and the game-tested candidate have identical Git tree9a3da2adf8dbc70f72462271967646cd647f97f0.