Skip to content

fix(shader): decode the scalar aperture sources 235-238 instead of failing the shader - #1940

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Dextroid17:feat/aperture-sources
Oct 10, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Dextroid17:feat/aperture-sources

Conversation

@Dextroid17

Copy link
Copy Markdown
Contributor

What

DecodeRdnaScalarSource throws unsupported scalar source operand code for scalar source codes 235 to 238, which fails the whole shader. Those codes have names — src_shared_base, src_shared_limit, src_private_base, src_private_limit, per LLVM's SIRegisterInfo.td (lines 266-269) — so this decodes them to their own operand kinds and names, and makes a read of one refuse with a message that names the source instead of falling into the generic invalid-operand path.

readScalarCode also gained explicit refusal cases: its default answered 0, which for an aperture base would be a silently wrong address rather than a refusal.

What is deliberately not modelled: the value. The wave's shared and private aperture bases and limits are unknown here, so a shader that reads one refuses (and, with #1836's deferral, is left unprepared) instead of being handed a plausible address. A shader that only carries the value into an address — the shape that motivated this — prepares normally.

Tested

Not verified: the value the console gives these operands (that is what "not modelled" means), and any title whose shaders read rather than carry them.

Checklist

@popcoder565

Copy link
Copy Markdown
Contributor

Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head b0c4d944, merged onto main d70b899 in one build with 33 other AGC/shader PRs that had no Windows run.

No title was run.

🤖 Addressed by Claude Code

@Dextroid17

Copy link
Copy Markdown
Contributor Author

Thank you for this — a native Windows run is exactly the evidence this PR could not produce for itself, and folding 33 AGC/shader PRs into one build is more useful than running yours alone.

On the one failure you attribute here: I do not think it is #2257's registration. Its two new modes are added to the same foreach(preparedMode ...) list as the existing ones, and the Windows PATH line sits inside that loop:

if(WIN32)
    set_tests_properties(${preparedTest} PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()

so agc_driver_prepared_shaders_deferred_undecodable gets the same modification as ..._indirect and the rest. Your later run at 5b8316ff on #2257 went the other way — all seven agc_driver_prepared_shaders* pass — and you note a local fix for #2193's Windows build in that same run. That reads like a missing DLL from #2193 rather than a registration gap in #2257.

If you can still see the 15:23 failure, could you say which binary it reported as missing, or re-run on #2257's current head from a clean shell? If it does turn out to be the registration I will fix it here, but I would rather correct the cause than the attribution.

aperture_sources reporting no skipped cases is the part I wanted most, so thank you also for saying explicitly that no title was run.

Written with AI assistance.

@tv7

tv7 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Tested on Windows with a second title that hits the same failure as #1920.

Setup: Windows 11 Pro (10.0.26200), RTX 3070, GCC 15.2.0 UCRT (WinLibs), Release. This PR (b0c4d94) merged onto main 54f28f2, together with other open PRs this title needs to get this far (#1836, #1893, #1709, #1837, and #1339 before it merged). Title: Marvel's Wolverine (PPSA03671).

Without this PR: the title aborts while preparing shaders with unsupported scalar source operand code 235 at program counter 816 (src_shared_base), after about 800 shaders.

With this PR: that abort is gone. The title runs for the whole 300 s test window without crashing, with the window and swapchain up and about 1,400 shaders compiled. aperture_sources and the rest of ctest (521/521) pass on this host with the same merge.

Limits: one title, one run. I have not checked whether the shaders that read the aperture registers render correctly, or whether frames are presented after the swapchain is created. The remaining log lines are shaders deferred at registration for other known reasons (data-dependent s_swappc_b64, registered type 8).

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checked the decode, the translation refusals and the build: aperture_sources passes here and needs the change to compile. Thanks also to @popcoder565 and @tv7 for the Windows runs. Two things to fix:

  • core/libs/tests/ApertureSources.cpp:28-33: CheckRefusesTranslation only checks the decoded kind. The refusal of a read is what the PR promises and replaces the old silent 0 default, but nothing pins it. Translate an instruction that reads source 235..238 (see core/libs/tests/ScalarSwappc.cpp for how to build and translate one) and assert that it throws with the source named, for both the readScalarCode and the readRawU32 paths.
  • core/libs/prx/libSceAgcDriver/CMakeLists.txt:1024-1030: the new test block is not indented like the surrounding ones.

Once these are in, this is ready from my side.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@Dextroid17
Dextroid17 force-pushed the feat/aperture-sources branch from b0c4d94 to 6532dc7 Compare October 10, 2026 10:51
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@Dextroid17
Dextroid17 force-pushed the feat/aperture-sources branch from 6532dc7 to b7e32b3 Compare October 10, 2026 10:57
@Dextroid17

Copy link
Copy Markdown
Contributor Author

Both points are addressed, and the branch is rebased onto a29ef592 — the PR went from CONFLICTING to MERGEABLE. The only conflict was the TechnicalDebt.md entry, resolved by keeping both lines (the new VertexBufferReadSize entry and this one).

1. The refusal is now pinned by a test that translates, not just a decode check. core/libs/tests/ApertureSources.cpp builds s_mov_b32 s0, <source> for each of 235 to 238, translates it through TranslationContext, and asserts the refusal names the source it refused. Both refusals now name it — readRawU32 through RdnaOperandToString(operand), readScalarCode through the same mapping — so a bare "not modelled" can no longer be told apart from a decode gap.

Two negative controls, each against a rebuilt binary, then restored:

restore the old silent 0 default      what(): reading src_shared_base was accepted
                                      exit 134
keep the refusal, drop the name       what(): the refusal does not name src_shared_base: …
                                      exit 134
restored                              aperture sources tests passed, exit 0

ctest -R "aperture|scalar_swappc|shader_memory|scalar_call" → 6/6 pass. tools/check_conventions.py passes; tools/check_test_registration.py reports "none new".

2. The CMake block is indented like its neighbours (4 spaces at statement level, 8 inside if(WIN32), 12 for the continued PATH line). While fixing that I also found my earlier revision had de-indented the following pre-existing add_test_executable(scalar_call_tests …) line to column 0; that is restored, so the diff is now a pure insertion rather than an insertion plus a moved line.

One thing I could not test, and would rather flag than paper over: the readScalarCode half of the refusal is defensive — no decoded instruction reaches it. Every caller traces to a register number: getResourceDword(index, dword) is called with memory.resource/memory.sampler, each derived from inst.sourceX.reg / 4u on a decoded SGPR (≤ 105), so the buffer and sampler paths top out at 26 * 4 + 3 = 107 and the image path (8 dwords) at 26 * 4 + 7 = 111; getScalarAddressResource(base) takes base ≤ 106 and reads base and base + 1, topping out at 107; and the last caller reads a terminator's indirectSelectorCode, which is never assigned anywhere in the tree — it is default-initialised to InvalidControlFlowId and guarded by != InvalidControlFlowId, so that branch is dead. The only other writers of resource/sampler are the memory patches in ResourceTracker.cpp, which carry collection ids, and a literal 1u in InstructionTranslator.cpp; neither can reach 235. Since the method is private, a translation test cannot construct a code of 235 to 238 for it.

I have left the guard in place, because it refuses instead of silently returning 0 — the behaviour this PR is about. If you would rather not carry an unreachable branch, say so and I will drop it; if you want it pinned, I can add the seam.

@Dextroid17

Copy link
Copy Markdown
Contributor Author

Measurement on a real title, in case it helps this land.

PPSA26344 (Ghost of Yōtei, 01.008) gets further with this change than without it.

Without it — current main, Linux x86-64, lavapipe, running the title's own directory (yotei-header.log):

[libc] unhandled exception 'St16invalid_argument'
terminate called after throwing an instance of 'std::invalid_argument'
  what():  unsupported scalar source operand code 235 at program counter 856

With it — this branch rebased on a29ef592, same device, same run directory (yotei-main.log):

  • the shader that carries code 235 decodes instead of ending the run,
  • the title continues through about 1,300 shader compilations on a cold cache (final totals 1294 misses / 1289 writes) to a presentation window and a swapchain (2393x1346, 3 images),
  • and stops later, at a different wall:
what():  AGC driver: graphics ABI refers to a replaced shader header

So this change moves the title past the wall #1920 names, which is why unsupported scalar source operand code 235 no longer appears.

One detail worth having, because it is easy to assume the opposite: the new aperture refusal does still fire in these runs — each log records the scalar aperture source src_shared_base is not modelled — but it is not fatal. Registration skips that shader and the run carries on to the header refusal below, instead of ending here.

A follow-up build that also names the fields of that refusal (yotei-both.log) shows what the title replaces:

(changed: cx_registers, sh_registers, specials, input_semantics, output_semantics)

Three qualifications, so the numbers are not read for more than they are: the runs are not a controlled A/B on a single tree — the later one reused a warm shader cache (1264 hits, no misses) while the first was fully cold; reaching a swapchain is not a correct frame; and the wall the title stops at next is another open question rather than a pass.

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked after the rebase: aperture_sources now translates s_mov_b32 from sources 235..238 and pins that the refusal names the source; with the OperandAccess.cpp refusals reverted the test fails, and without the change it does not compile. agc_driver_flat_apertures and the scoped ctest are green, CI is green, and the Windows runs by @popcoder565 and @tv7 cover the platform. Merging.

@adriadam10
adriadam10 merged commit 13851b5 into boykopovar:main Oct 10, 2026
12 checks passed
fdfawef324 added a commit to fdfawef324/AnyPS5 that referenced this pull request Oct 13, 2026
Reading src_shared_base, src_shared_limit, src_private_base or
src_private_limit (scalar source codes 235-238) refused the shader since
boykopovar#1940, because their values were unknown. They now read as the 64-bit
apertures that the flat routing from boykopovar#1190 classifies: a base is the
aperture's high dword over a low dword of 0, a limit is the same high
dword over 0xffffffff (shared 0x80000000, private 0x70000000).

A 64-bit read (s_mov_b64, a 64-bit VALU source, a wave64 lane mask)
gets the whole value and a 32-bit read gets the low dword. A flat
pointer built from the high dword therefore reaches LDS or scratch, and
64-bit compares against the limits order as on the hardware. The flat
routing and the reads share one definition of the two high dwords.

Sources: LLVM SIRegisterInfo.td (aperture registers are 64-bit, their
low 32 bits are always 0 for a base and -1 for a limit) and
getSegmentAperture in AMDGPULegalizerInfo.cpp and SIISelLowering.cpp
(a 64-bit read whose high half is the aperture); the RDNA 2 ISA guide,
sections 5.2, 5.8 (SH_MEM_BASES holds 16-bit bases) and 9.3; the KFD's
MAKE_LDS_APP_LIMIT (limit = base | 0xffffffff); the gfx1030 and gfx1035
readouts on boykopovar#1190 and boykopovar#3803. The PS5's two high dwords stay inferred,
as the shader technical debt records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fdfawef324 added a commit to fdfawef324/AnyPS5 that referenced this pull request Oct 13, 2026
Reading src_shared_base, src_shared_limit, src_private_base or
src_private_limit (scalar source codes 235-238) refused the shader since
boykopovar#1940, because their values were unknown. They now read as the 64-bit
apertures that the flat routing from boykopovar#1190 classifies: a base is the
aperture's high dword over a low dword of 0, a limit is the same high
dword over 0xffffffff (shared 0x80000000, private 0x70000000).

A 64-bit read (s_mov_b64, a 64-bit VALU source, a wave64 lane mask)
gets the whole value and a 32-bit read gets the low dword. A flat
pointer built from the high dword therefore reaches LDS or scratch, and
64-bit compares against the limits order as on the hardware. The flat
routing and the reads share one definition of the two high dwords.

Sources: LLVM SIRegisterInfo.td (aperture registers are 64-bit, their
low 32 bits are always 0 for a base and -1 for a limit) and
getSegmentAperture in AMDGPULegalizerInfo.cpp and SIISelLowering.cpp
(a 64-bit read whose high half is the aperture); the RDNA 2 ISA guide,
sections 5.2, 5.8 (SH_MEM_BASES holds 16-bit bases) and 9.3; the KFD's
MAKE_LDS_APP_LIMIT (limit = base | 0xffffffff); the gfx1030 and gfx1035
readouts on boykopovar#1190 and boykopovar#3803. The PS5's two high dwords stay inferred,
as the shader technical debt records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fdfawef324 added a commit to fdfawef324/AnyPS5 that referenced this pull request Oct 13, 2026
Reading src_shared_base, src_shared_limit, src_private_base or
src_private_limit (scalar source codes 235-238) refused the shader since
boykopovar#1940, because their values were unknown. They now read as the 64-bit
apertures that the flat routing from boykopovar#1190 classifies: a base is the
aperture's high dword over a low dword of 0, a limit is the same high
dword over 0xffffffff (shared 0x80000000, private 0x70000000).

A 64-bit read (s_mov_b64, a 64-bit VALU source, a wave64 lane mask)
gets the whole value and a 32-bit read gets the low dword. A flat
pointer built from the high dword therefore reaches LDS or scratch, and
64-bit compares against the limits order as on the hardware. The flat
routing and the reads share one definition of the two high dwords.

Sources: LLVM SIRegisterInfo.td (aperture registers are 64-bit, their
low 32 bits are always 0 for a base and -1 for a limit) and
getSegmentAperture in AMDGPULegalizerInfo.cpp and SIISelLowering.cpp
(a 64-bit read whose high half is the aperture); the RDNA 2 ISA guide,
sections 5.2, 5.8 (SH_MEM_BASES holds 16-bit bases) and 9.3; the KFD's
MAKE_LDS_APP_LIMIT (limit = base | 0xffffffff); the gfx1030 and gfx1035
readouts on boykopovar#1190 and boykopovar#3803. The PS5's two high dwords stay inferred,
as the shader technical debt records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fdfawef324 added a commit to fdfawef324/AnyPS5 that referenced this pull request Oct 13, 2026
Reading src_shared_base, src_shared_limit, src_private_base or
src_private_limit (scalar source codes 235-238) refused the shader since
boykopovar#1940, because their values were unknown. They now read as the 64-bit
apertures that the flat routing from boykopovar#1190 classifies: a base is the
aperture's high dword over a low dword of 0, a limit is the same high
dword over 0xffffffff (shared 0x80000000, private 0x70000000).

A 64-bit read (s_mov_b64, a 64-bit VALU source, a wave64 lane mask)
gets the whole value and a 32-bit read gets the low dword. A flat
pointer built from the high dword therefore reaches LDS or scratch, and
64-bit compares against the limits order as on the hardware. The flat
routing and the reads share one definition of the two high dwords.

Sources: LLVM SIRegisterInfo.td (aperture registers are 64-bit, their
low 32 bits are always 0 for a base and -1 for a limit) and
getSegmentAperture in AMDGPULegalizerInfo.cpp and SIISelLowering.cpp
(a 64-bit read whose high half is the aperture); the RDNA 2 ISA guide,
sections 5.2, 5.8 (SH_MEM_BASES holds 16-bit bases) and 9.3; the KFD's
MAKE_LDS_APP_LIMIT (limit = base | 0xffffffff); the gfx1030 and gfx1035
readouts on boykopovar#1190 and boykopovar#3803. The PS5's two high dwords stay inferred,
as the shader technical debt records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fdfawef324 added a commit to fdfawef324/AnyPS5 that referenced this pull request Oct 14, 2026
Reading src_shared_base, src_shared_limit, src_private_base or
src_private_limit (scalar source codes 235-238) refused the shader since
boykopovar#1940, because their values were unknown. They now read as the 64-bit
apertures that the flat routing from boykopovar#1190 classifies: a base is the
aperture's high dword over a low dword of 0, a limit is the same high
dword over 0xffffffff (shared 0x80000000, private 0x70000000).

A 64-bit read (s_mov_b64, a 64-bit VALU source, a wave64 lane mask)
gets the whole value and a 32-bit read gets the low dword. A flat
pointer built from the high dword therefore reaches LDS or scratch, and
64-bit compares against the limits order as on the hardware. The flat
routing and the reads share one definition of the two high dwords.

Sources: LLVM SIRegisterInfo.td (aperture registers are 64-bit, their
low 32 bits are always 0 for a base and -1 for a limit) and
getSegmentAperture in AMDGPULegalizerInfo.cpp and SIISelLowering.cpp
(a 64-bit read whose high half is the aperture); the RDNA 2 ISA guide,
sections 5.2, 5.8 (SH_MEM_BASES holds 16-bit bases) and 9.3; the KFD's
MAKE_LDS_APP_LIMIT (limit = base | 0xffffffff); the gfx1030 and gfx1035
readouts on boykopovar#1190 and boykopovar#3803. The PS5's two high dwords stay inferred,
as the shader technical debt records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fdfawef324 added a commit to fdfawef324/AnyPS5 that referenced this pull request Oct 14, 2026
Reading src_shared_base, src_shared_limit, src_private_base or
src_private_limit (scalar source codes 235-238) refused the shader since
boykopovar#1940, because their values were unknown. They now read as the 64-bit
apertures that the flat routing from boykopovar#1190 classifies: a base is the
aperture's high dword over a low dword of 0, a limit is the same high
dword over 0xffffffff (shared 0x80000000, private 0x70000000).

A 64-bit read (s_mov_b64, a 64-bit VALU source, a wave64 lane mask)
gets the whole value and a 32-bit read gets the low dword. A flat
pointer built from the high dword therefore reaches LDS or scratch, and
64-bit compares against the limits order as on the hardware. The flat
routing and the reads share one definition of the two high dwords.

Sources: LLVM SIRegisterInfo.td (aperture registers are 64-bit, their
low 32 bits are always 0 for a base and -1 for a limit) and
getSegmentAperture in AMDGPULegalizerInfo.cpp and SIISelLowering.cpp
(a 64-bit read whose high half is the aperture); the RDNA 2 ISA guide,
sections 5.2, 5.8 (SH_MEM_BASES holds 16-bit bases) and 9.3; the KFD's
MAKE_LDS_APP_LIMIT (limit = base | 0xffffffff); the gfx1030 and gfx1035
readouts on boykopovar#1190 and boykopovar#3803. The PS5's two high dwords stay inferred,
as the shader technical debt records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants