fix: avoid empty emplace() in GCC 14 libstdc++ #1325

Closed
github-bot wants to merge 6 commits from gh-pr/1325/head into gh-pr/1325/base
Owner

@⁠gavvahar on GitHub · 2026-10-09 19:37 UTC · original
gavvahar:fix/indirect-descriptor-default-ctor → main · +66 −6 · 5 files · 6 commits · closed without merging

Fixes a pre-existing compile failure in tests/ResourceMaterializationTests.cpp seen in recent CI runs on main (e.g. run 37964051144) and other branches, on GCC 14.

Root cause

DescriptorSource::IndirectDescriptor is default-constructible (Value has Value() = default;, and every other member is a scalar with an initializer, std::optional, or std::vector). But std::optional<T>::emplace() with no args is SFINAE-constrained on is_constructible_v<T>, and GCC 14's libstdc++ computes that trait incorrectly as false for this type — a known libstdc++ bug fixed in v15. CI builds with Clang against GCC 14's libstdc++ headers, which is why this doesn't reproduce with a newer libstdc++.

Not caught locally because resource_materialization_tests is EXCLUDE_FROM_ALL, so it's skipped by the default build target.

Fix

Construct the IndirectDescriptor directly (goes through the language's type system, not the buggy trait), then pass it to the one-arg emplace(Args...), which only needs move-constructibility.

DescriptorSource::IndirectDescriptor desc;
desc.sources = {0, 1};
indirect.indirect_descriptor.emplace(std::move(desc));

Verified: builds clean and resource_materialization_tests passes locally (Clang + libstdc++ 15.3). Test-only change, no production code touched.

**@⁠gavvahar** on GitHub · 2026-10-09 19:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1325) `gavvahar:fix/indirect-descriptor-default-ctor` → `main` · +66 −6 · 5 files · 6 commits · closed without merging Fixes a pre-existing compile failure in `tests/ResourceMaterializationTests.cpp` seen in recent CI runs on `main` (e.g. run 37964051144) and other branches, on GCC 14. ## Root cause `DescriptorSource::IndirectDescriptor` **is** default-constructible (`Value` has `Value() = default;`, and every other member is a scalar with an initializer, `std::optional`, or `std::vector`). But `std::optional<T>::emplace()` with no args is SFINAE-constrained on `is_constructible_v<T>`, and GCC 14's libstdc++ computes that trait incorrectly as `false` for this type — a known libstdc++ bug fixed in v15. CI builds with Clang against GCC 14's libstdc++ headers, which is why this doesn't reproduce with a newer libstdc++. Not caught locally because `resource_materialization_tests` is `EXCLUDE_FROM_ALL`, so it's skipped by the default build target. ## Fix Construct the `IndirectDescriptor` directly (goes through the language's type system, not the buggy trait), then pass it to the one-arg `emplace(Args...)`, which only needs move-constructibility. ```cpp DescriptorSource::IndirectDescriptor desc; desc.sources = {0, 1}; indirect.indirect_descriptor.emplace(std::move(desc)); ``` Verified: builds clean and `resource_materialization_tests` passes locally (Clang + libstdc++ 15.3). Test-only change, no production code touched.
The pipeline cache (VkPipelineCache serialized to _PipelineCache/{title_id}.bin)
survives crashes only if the graphics subsystem has an emergency_shutdown
callback to flush it to disk before process exit. Currently, the graphics
lifecycle registers only a shutdown callback (runs on clean exit) but no
emergency_shutdown (runs on assertion/EXIT() crashes).

This causes crash scenarios to lose all compiled pipelines: if a game crashes
during initial load (reported in issue #1300), the cache is never persisted,
and the next launch has no warm cache, forcing full recompilation and
perpetuating the stutter the user experienced before the crash.

Add EmergencyShutdown() to Libs::Graphics following the exact pattern of
Libs::Controller and Libs::LibKernel::FileSystem. The function:
- Checks g_renderer != nullptr
- Uses TryLock to avoid deadlock if called from a thread already holding
  the render context mutex (safe no-op if lock fails)
- Calls Save() to persist the pipeline cache to disk

Fixes #1300
fix: save pipeline cache on emulator crash
The graphics mutex is recursive on all platforms (CRITICAL_SECTION on Windows,
std::recursive_mutex on Unix), so TryLock() always succeeds even if the current
thread already holds the lock. The previous code mistakenly relied on TryLock()
failing to detect ownership.

Add explicit owner tracking to MutexPrivate:
- m_owner: atomic thread ID (read by any thread, written only by owner)
- m_depth: recursion depth (read/written only by owner under the lock)

Update Lock/Unlock/TryLock to maintain ownership invariants.

Expose Mutex::IsHeldByCurrentThread() for crash-handler use.

Rewrite Graphics::EmergencyShutdown() to check ownership explicitly and bail out
if the crashing thread already holds the render lock (avoiding recursive Save()
and blocking I/O from within crash handling).

Fixes CodeRabbit finding: Do not use TryLock() as the emergency ownership check.
The zero-argument emplace() on std::optional requires the contained type to
be default-constructible via the is_constructible_v<T> trait. With GCC 14's
libstdc++, this trait incorrectly evaluates to false for
DescriptorSource::IndirectDescriptor, even though the type is in fact
default-constructible (aggregate with all default-constructible members).

This is a known libstdc++ v14 issue fixed in v15.

Workaround: construct the IndirectDescriptor directly (which uses the
language-level type system, not the trait), then pass it to emplace(Args...),
which only requires move-constructibility—a trait that works correctly across
all compiler/stdlib versions.

Fixes upstream CI failure with GCC 14.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:53:10 +00:00
github-bot closed this pull request 2026-11-26 09:53:10 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 19:42 UTC · original · edited 2026-10-09 20:24 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 08a0052c-969d-41b1-8d18-a90f56247aaf

📥 Commits

Reviewing files that changed from the base of the PR and between 7c428ec706 and 8164fe13ec.


📒 Files selected for processing (2)
  • src/libs/agc.cpp
  • tests/ResourceMaterializationTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.



📝 Walkthrough

Walkthrough

The change adds mutex ownership tracking and a public ownership query. Graphics adds an emergency-shutdown function and registers it in the lifecycle. The function saves the pipeline cache only when the renderer exists, the current thread does not already own its mutex, and TryLock() succeeds. The indirect descriptor test now builds and moves a local descriptor with source indices {0, 1}.

Suggested reviewers: nmzik


Priority: ⬇️ Low

Change: Feature

Merge Risk: 🟡 Moderate · up to 8164f

Mutex ownership can be reported incorrectly during condition-variable waits, and the tracking fields can be accessed concurrently. Correct the wait bookkeeping before merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: avoiding zero-argument emplace() to fix a GCC 14 libstdc++ compile failure.
Description check Passed The description directly explains the GCC 14 compile failure, its libstdc++ root cause, the test-only fix, and verification results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 19:42 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1325#issuecomment-6088012391) · edited 2026-10-09 20:24 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1325?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `08a0052c-969d-41b1-8d18-a90f56247aaf` <hr> </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7c428ec706c33248b8064fdf35cc4ff8578c20e6 and 8164fe13ecc805e365b6e96fba5b111506799c3d. <hr> </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/libs/agc.cpp` * `tests/ResourceMaterializationTests.cpp` <hr> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. <hr> </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The change adds mutex ownership tracking and a public ownership query. Graphics adds an emergency-shutdown function and registers it in the lifecycle. The function saves the pipeline cache only when the renderer exists, the current thread does not already own its mutex, and `TryLock()` succeeds. The indirect descriptor test now builds and moves a local descriptor with source indices `{0, 1}`. **Suggested reviewers:** `nmzik` <hr> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"8164fe13ecc805e365b6e96fba5b111506799c3d" --> **Change:** Feature <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **🟡 Moderate** · up to `8164f` <!-- final_review_risk_coverage:{"sourceCommitId":"8164fe13ecc805e365b6e96fba5b111506799c3d","coveredCommitId":"8164fe13ecc805e365b6e96fba5b111506799c3d","kind":"reviewed"} --> Mutex ownership can be reported incorrectly during condition-variable waits, and the tracking fields can be accessed concurrently. Correct the wait bookkeeping before merging. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>Pre-merge checks | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v1.svg" width="14" height="17" align="middle" alt="Passed" title="Passed"></picture></sup> 4 | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v1.svg" width="14" height="17" align="middle" alt="Failed" title="Failed"></picture></sup> 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 5 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly identifies the primary change: avoiding zero-argument emplace() to fix a GCC 14 libstdc++ compile failure. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the GCC 14 compile failure, its libstdc++ root cause, the test-only fix, and verification results. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <hr> </details> <hr> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1325)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) <hr> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -144,0 +149,4 @@
// it needs no synchronization; m_owner is atomic because other threads read it.
void Acquired() {
m_depth++;
m_owner.store(Thread::GetThreadIdUnique(), std::memory_order_relaxed);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 19:42 UTC · original

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Update ownership tracking when a condition-variable wait releases the mutex.

CondVar::Wait() and CondVar::WaitFor() release the underlying mutex without updating m_depth or m_owner. While a thread waits, IsHeldByCurrentThread() can report that it still owns the mutex. Another thread can then acquire the mutex and access m_depth concurrently. Update the tracking state on both sides of every underlying release and reacquisition, including the polling callback path.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 19:42 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1325#discussion_r4233925533) **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** **Update ownership tracking when a condition-variable wait releases the mutex.** `CondVar::Wait()` and `CondVar::WaitFor()` release the underlying mutex without updating `m_depth` or `m_owner`. While a thread waits, `IsHeldByCurrentThread()` can report that it still owns the mutex. Another thread can then acquire the mutex and access `m_depth` concurrently. Update the tracking state on both sides of every underlying release and reacquisition, including the polling callback path. <!-- coderabbit-global-learning v1 gid=fedd4396c48520a9 scope=practice --> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:83158edab56f878e5f9fe966 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 19:42 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 509535a5-e73d-4211-ac9b-85db6d68d268
📥 Commits

Reviewing files that changed from the base of the PR and between 59183dbfa8 and 7c428ec706.

📒 Files selected for processing (5)
  • src/common/threads.cpp
  • src/common/threads.h
  • src/libs/agc.cpp
  • src/libs/agc.h
  • tests/ResourceMaterializationTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 19:42 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1325#pullrequestreview-5474621118) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `509535a5-e73d-4211-ac9b-85db6d68d268` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 59183dbfa81ed7efdff6069177fed50de0552725 and 7c428ec706c33248b8064fdf35cc4ff8578c20e6. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `src/common/threads.cpp` * `src/common/threads.h` * `src/libs/agc.cpp` * `src/libs/agc.h` * `tests/ResourceMaterializationTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=a4884471-8071-4d2c-9e00-12d406003752 attempt=be97ac2b-0f8e-496f-88ba-efdac87457bf batch=1/1 -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.