fix(shader): evaluate float-to-signed conversions in runtime SRT values #21240
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21240"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-16T01:18:25Z.
What
An SRT descriptor expression that narrows a floating-point value to a signed integer was rejected at compile time:
ConvertS32F32was missing fromIsRuntimeUniformOp, from the SRT evaluator and from its tape, soSrtWalker::ValidateRuntimeValuerefused the whole chain before either could compute it. Every other operation such a chain is built from (the NaN test, both ordered range comparisons,SelectF32,SelectU32, the mask, the shift and the or) was already accepted.This adds the missing operation in all four places: round toward zero, which is what the backend emits for it (
OpConvertFToS), and refuse a NaN, an infinity or a value outside the signed 32-bit range instead of converting it, asConvertU32F32already refuses its own range.The shader disk cache
FormatVersionstays at main's 99: the cache is also keyed on the compiler source version, so a descriptor this change makes evaluable stops being planned as a table column (its sampler becomes direct) and the module it now emits already misses the old entries, while the serialized layout does not change.New case in
ShaderMemory:convertF32ToI32Saturated's shape (NaN and low clamp, high clamp, narrowing, mask/shift/or) is validated and evaluated through both the evaluator and its tape, and a raw conversion is evaluated directly for truncation toward zero and refused for a NaN and for 2^31.Tested
Linux x86-64 (CachyOS), GCC 16.2.1, Release, NVIDIA GeForce RTX 4080 SUPER, driver 615.78.8.0.
agc_shader_memorypasses with the change and fails without it in the new case's first assertion:SRT float-to-signed conversion: the runtime validator rejects a descriptor dword the evaluator computes.shaderctest selection: 119/119 on the rebased head (and 118/118 onmainbefore the rebase), same machine and GPU, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.363) andVK_LOADER_DEBUG=layer. Both logs show 77Insert instance layer "VK_LAYER_KHRONOS_validation"lines, neither containswas not found but was requested by env var, and neither contains aVUID-line.Title evidence: The Last of Us Part II Remastered (
PPSA15508, 02.001.010) registers compute shader0x129fe74400, whose S# dword 1 is assembled from SRT words throughconvertF32ToI32Saturated, and could not prepare it:GetSamplerResource dword 1 is not a valid runtime value; chain: ReadFirstLane(BitwiseOr32(BitwiseAnd32(ReadConst(GetSrtResource, Immediate), Immediate), ShiftLeftLogical32(SelectU32(FPOrdGreaterThanEqual32(BitCastF32U32(ReadConst(GetSrtResource, Immediate)), Immediate), Immediate, ConvertS32F32(SelectF32(...))), Immediate)), Immediate). Three pixel stage-5 shaders of the same title (0x129fe6ea00,0x129fe6fc00,0x129fe70f00) fail with the same chain.agc_shader_replay --prepareon the captured request emits 164801 SPIR-V words with this change and stops at that error onmain. The title itself has not been re-run with this change, so nothing is claimed about what it draws.python3 tools/check_conventions.py --base origin/main: 0 errors.python3 tools/pr_overlap.py --branch fix/shader-srt-convert-s32-f32 --jobs 32: no overlap with the 1637 open pull requests, in files or in exports.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T02:31:14Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the implementation and its evaluator/tape coverage look sound based on the code read.
What I ran
Reviewed head
fd5d713cfb2afeb4935bb711e17480307f7db9eeusing the prepared diff and pinned readerrepo_read.py. No commands or tests were run by me.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas read around the changed test function, but the file was excluded from the review folder because it was too large. Its full text and the added call at line 13133 were not reviewed.description.md,commits.md,manifest.json,diff.patch;SrtTape.hpp,SrtEvaluator.cpp,SrtInstructionPredicates.cpp,SrtTape.cpp,ShaderDiskCache.hpp, the relevantShaderMemory.cpprange, and the added debt note.files.jsonwas not available through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T06:51:00Z.
Review: APPROVED
Reviewed — looks good
Nothing in the reviewed code blocks merging; the SRT evaluator and tape now handle signed float conversion consistently for finite in-range inputs and reject invalid inputs.
What I ran
Inspected head
30415bbbc8b0eab3fbaf3e7d01fb510803155f08through the pinnedrepo_read.pyreader. No commands or tests were run in this review; runtime results below are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read the change description, commit summary, diff, and full text for all changed files except
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp, whose full text was excluded for size. I read the added test function from the pinned source. The reported test runs, native RDNA2/PS5 execution, and title behavior were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T17:10:11Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the new runtime path accepts and evaluates
ConvertS32F32, with both evaluator implementations applying finite/range checks before truncating toward zero.What I ran
Reviewed head
3e389ca0caceda2dbc484d5b9dda02f9d8c857a3using the prepared diff and pinned reader. No tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The complete text of
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded because it was too large for the review folder; its changed hunk was read fromdiff.patch. The changed evaluator, tape, predicate, tape header, disk cache header, and debt note were read. The full shader test run, title behavior, and native RDNA2/PS5 execution were not independently verified. No files were listed as excluded by rule; one file was omitted for size.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T22:21:54Z.
Review: COMMENTED
Actionable comments posted: 1
060cc0c0-9307-409b-abda-f974c96264efReviewing files that changed from the base of the PR and between
00b15fcbb0and8900a301ef.core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtTape.hppcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtInstructionPredicates.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtTape.cppcore/shader/recompiler/ShaderDiskCache.hppdocs/dev/debt/changes/fix-shader-srt-convert-s32-f32.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T22:43:53Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the conversion guards and evaluation paths are consistent, and the remaining comments are optional.
What I ran
8900a301efb238aaa69c83b9cf255c19f91ff7b7.Results
Findings
Blocking
None.
Non-blocking
ShaderMemory.cpptests negative and fractional inputs, but does not directly cover signed lower-bound conversion or just-outside-bound values. Consider adding cases around both signed limits to protect the guard behavior (core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp:1669).Not verified
ShaderMemory.cppfile was excluded from the bundle and was read through the pinned reader for lines 1560–1680.files.jsonwas available through the reader; exclusions were determined frommanifest.json.To get this to a good state
Nothing is required. The boundary test coverage suggestion above is optional.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T00:07:12Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional. The reviewed implementation at
ac7a4506844639133e382321d575fa339b0060e8consistently adds signed float-to-integer conversion to the SRT validator, evaluator, and tape.What I ran
Reviewed the prepared diff and all 7 files listed under
reviewed, usingrepo_read.pyat the pinned head for changed test lines and relevant translation/backend context. No tests or builds were run. The PR description’s reported checks were not independently verified.Results
Negative control
Not run; no source changes or tests were made during this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Native RDNA2/PS5 execution, title behavior, and the PR description’s reported test and convention-check results were not verified. No files were excluded by the prepared review manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:43:55Z.
Review: COMMENTED
I tested
ac7a450684againstmainat9d362fb088on Linux.agc_shader_memoryand the GCN scalar-buffer control passed on both revisions. Both runs required Vulkan and disabled the shader cache. The scalar execution log showed Khronos validation 1.4.369 inserted in both runs, with no missing-layer warnings orVUID-messages. The Vulkan control used Mesa lavapipe.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.