Skip to content

fix(agc): keep unit flags unchanged when growing them fails under libc++ - #20063

Open
XIIYAZ wants to merge 1 commit into
boykopovar:mainfrom
XIIYAZ:fix/agc-unit-flags-strong-assign
Open

XIIYAZ wants to merge 1 commit into
boykopovar:mainfrom
XIIYAZ:fix/agc-unit-flags-strong-assign

Conversation

@XIIYAZ

@XIIYAZ XIIYAZ commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

What

On macOS, agc_unit_flags_allocation_failure_populated fails:

failed growth changed the existing unit flags

UnitFlags::assign resizes its words with std::vector::assign(n, value). When n is larger than the capacity, libc++ frees the old buffer before it allocates the new one. So if that allocation throws, the vector is left empty. libstdc++ keeps the old contents, which is why only libc++ builds fail. A standalone check under the same toolchain shows it:

std::vector<unsigned long long> v(2, 7);
// the next allocation throws std::bad_alloc
v.assign(3, 1);   // size afterwards: 0, was 2

In UnitFlags that is worse than a lost value. count is updated only after the assign, so after a failed growth it still says 65 while words is empty. The next operator[], AnyIn or SetRange then indexes past the end of the vector.

When the new size needs more words than the capacity, assign now builds the new vector first and swaps it in. A failed allocation then leaves both words and count as they were. When the words fit in the current capacity, it still calls std::vector::assign. That does not allocate, so nothing changes on that path.

Tested

Setup:

  • Apple M4, macOS 26.7.3, Apple clang 21.0.0 (libc++)
  • full Release build with -DCMAKE_OSX_ARCHITECTURES=x86_64; tests run under Rosetta
  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 (MoltenVK 1.4.2, LunarG Vulkan SDK 1.4.363.1)
  • on main with the open macOS build fixes applied

Results:

  • agc_unit_flags_allocation_failure_populated fails before this change and passes after it. agc_unit_flags_allocation_failure_empty passes before and after.
  • ctest -R 'unit_flags|allocation_failure|texture_units|unit_' (13 tests) passes.
  • I ran ctest -R '^(agc|shader|job)' (1578 tests, -j 1) and compared it with the same run before this change: the test above is fixed and nothing new fails (16 failures before, 15 after).

On libstdc++ the observable behaviour is the same as before; on libc++ a failed growth no longer clears the flags.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M4 (MoltenVK 1.4.2, LunarG Vulkan SDK 1.4.363.1, macOS 26.7.3)
  • AI-assisted: yes

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 7085 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 8246 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 10743 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 12746 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 13251 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 15058 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 15136 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 18956 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 20041 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 20728 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 21669 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 22531 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 23234 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 23739 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28118 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28119 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28176 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28292 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28293 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28333 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28411 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28451 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28894 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28937 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28945 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28952 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28957 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28958 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 28984 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29074 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29076 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29082 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29083 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29085 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29095 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29101 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29118 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29121 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29123 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 29218 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp

@github-actions github-actions Bot added the agc libSceAgc* label Nov 14, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The reviewed change provides strong exception safety for UnitFlags growth by replacing the vector only after the new allocation succeeds; no blocking defect was found in the changed code.

What I ran

Reviewed head 2599195b793dd9864d8c54c69db63741f2cb4af6. Read the prepared description, commits, manifest, diff, and the complete changed file core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp. Used the pinned repository reader repo_read.py search for related uses. No build or tests were run.

Results

Check Result Note
Changed code review passed Exception-safe growth path
Tests not run Author reports test results

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports libc++ allocation-failure tests and a broader ctest run, but these were not run during this review. No other files were changed or excluded according to the manifest.

To get this to a good state

Nothing is required.

@JJenkx

JJenkx commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 2599195b79, merged onto main ee25ae607b. Setup: Windows 11 Enterprise 22621, AMD RX 6700 XT, AMD driver 26.10.1, MinGW-w64 GCC 15.2 UCRT, Release.

All 10 selected tests (agc_driver_depth_expand_out_of_place_inline, agc_driver_fill_completion_labels_chain, agc_driver_fill_completion_labels_cpu_disjoint, agc_driver_fill_completion_labels_cpu_overlap, ...):

  • GPU, through the shared Windows GPU FIFO with ANYPS5_REQUIRE_VULKAN=1 (merge 664746ad57): all 10 passed in 3 of 3 runs, 30 of 30 outcomes. The binaries matched the hashes recorded at preparation, and the receipt shows exit 0 and app_count=0.
  • CPU, Vulkan hidden (merge b7f158f8ba): 3 passed and 7 skipped (they need a device), 0 failed, in each of 3 runs.

AI-assisted: yes.

@kurexw kurexw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on macOS 27.2 / Apple M4 with MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1, validation layer 1.4.363), x86-64 build under Rosetta. This is the only GPU I tested.

Head 2599195b79 merged alone onto main 3b17977ba6, compared with 3b17977ba6 itself. I ran the 29 AGC tests that fail on main on this Mac, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer, through ctest --test-dir build -R <those 29> -V, three runs per side. Every Vulkan test logged Insert instance layer "VK_LAYER_KHRONOS_validation" and none logged was not found but was requested by env var VK_INSTANCE_LAYERS.

test main (3 runs) this PR (3 runs)
agc_unit_flags_allocation_failure_populated Failed, Failed, Failed Passed, Passed, Passed

The other 27 tests gave the same result on both sides.

agc_driver_label_after_import_copy is flaky on main as well: main Failed, Passed, Passed, this PR Failed, Failed, Failed. Every failure on either side is the same timing check ("round N: a CPU read after the label that followed the copy found K of 262144 destination bytes not yet copied"), and it varied the same way across the other PRs I tested in the same session, so I don't attribute it to this change.

VUID- lines: identical per test on both sides (30 on main, 30 with this PR, over the three runs). The VUID- lines on both sides are main's existing VUID-VkDeviceCreateInfo-sType-unique (a duplicated VkPhysicalDevicePortabilitySubsetFeaturesKHR in the device pNext chain) and VUID-VkSamplerCreateInfo-samplerMipLodBias-04467; this PR adds none. (agc_unit_flags_allocation_failure_populated doesn't create a Vulkan device, so it logs no layer insertion on either side.)

@Romannachwievor

Copy link
Copy Markdown
Contributor

Tested on an Apple M1 (macOS 26.5, Apple clang 21.0.0), x86_64 Release under Rosetta 2. The tree was main 245210b07e with #17425 and #11049, which the macOS build needs. I applied this PR's diff (head 2599195b79) on top.

agc_unit_flags_allocation_failure_populated: fails 3 of 3 runs without this PR (failed growth changed the existing unit flags) and passes 3 of 3 with it.

AI-assisted: yes (Claude Code)

@magnub

magnub commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Tested on an Apple M1 Pro, macOS 27.0.1 (26A434), Apple clang 21.0.0 (clang-2100.3.34.2), x86_64 Release under Rosetta 2. Base: main ae54dc8 + #17425 + #11049, with this PR’s head 2599195 merged on top.

Without this PR, agc_unit_flags_allocation_failure_populated fails on every run with failed growth changed the existing unit flags, also at a4d1053.
With this PR, agc_unit_flags_allocation_failure_empty and agc_unit_flags_allocation_failure_populated pass 5 of 5 runs each.

AI-assisted: yes

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 2599195b79, applied with git apply on main fd4aeed483 together with the other 28 PRs of one batch (#22683, #23796, #23923, #24367, #24370, #24409, #24486, #24587, #10623, #18903, #18941, #19461, #21018, #21303, #21451, #21965, #23477, #23478, #23726, #24463, #12827, #14127, #14991, #24103, #24331, #24508, #24565, #15838). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
none: no test of its own in this PR - -

Whole batch: the full ctest -j 12 (6523 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #24409 (guest_usbd); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_net_dns_info, test_script_registration. The 2126 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@Gonic0

Gonic0 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Tested on macOS: Apple M5 Pro, macOS 27.3, Apple clang, x86_64 Release under Rosetta 2, BUILD_TESTING=ON.

Tree: main a3b6b62649 plus #17425, #11049 and #25116, which main still needs to build on macOS (#24117). This pull request's head 2599195b79 applied on top without conflicts.

  • Without this pull request, agc_unit_flags_allocation_failure_populated fails on macOS: failed growth changed the existing unit flags.
  • With it, agc_unit_flags_allocation_failure_populated passes.
  • Only that test executable was rebuilt and run for this check; the rest of the suite was not rerun with this pull request.

AI-assisted: yes (Claude Code)

@ycbuzi

ycbuzi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Tested 2599195b79 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 2 tests failed out of 6922; 99% tests passed, 2 tests failed out of 6922. 2 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 6922; 100% tests passed, 0 tests failed out of 6922. run

Not covered: GPU. This pull request changes GPU code, and the GitHub-hosted runners above have no GPU, so the Vulkan and GPU tests fail there on main and on this pull request alike. This result says nothing about the changed GPU paths; they still need a run on a real GPU.

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trial merge onto a1b75b0947 was clean. I checked that UnitFlags::assign constructs the replacement words before changing live storage or count when capacity must grow. The populated allocation-failure case is the most diagnostic one, because both members need to retain their prior values. Keep the paired libc++ results distinct from the Linux/libstdc++ control, where main can already preserve the old allocation.

AI-assisted: yes.

@NobleBrains

Copy link
Copy Markdown
Contributor

Host: macOS 15.7.9, Apple M4, x86_64 Release build under Rosetta 2, BUILD_TESTING=ON. The tree was main e8f09d2877 plus the open macOS build fixes #27201, #27767, #27739 and #27843, so it is not a build of this branch alone. This PR's diff (gh pr diff, head 2599195b79) was applied on top. The other two PRs I was testing in the same tree touch different files.

agc_unit_flags_allocation_failure_populated: fails without this PR (failed growth changed the existing unit flags), passes with it. I removed only this diff from the tree again to check, and the test failed again.

The full ctest -j2 run of that tree (7152 tests) had no new failure from this change. guest_main_stack_move failed in it too, but it is flaky on this host with and without the PRs (5 of 30 runs fail without the #28075 change).

I did not test natively on arm64 or on Intel hardware, and no title was run.

AI-assisted: yes (Claude Code)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.