fix(shader): avoid NVIDIA signed folding on unsigned int-to-float conversions #21159
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21159"
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 gurtgg on 2026-11-15T21:44:45Z.
What
Avoid emitting
OpConvertUToFfor sign-extended 32-bit integers in the SPIR-V ALU emitter, where NVIDIA's compiler can fold the conversion with the preceding sign extension as signed int-to-float and produce negative results that clamp to zero on unsigned sub-dword SDWA writes.SignExtendedU32(const IrValue& root)incore/shader/recompiler/SpirvBackend(SpirvEmitterHelpers.hpp/SpirvAluEmitterMath.cpp) to detect values originating fromBitFieldSExtractorShiftRightArithmetic32across phis, selects, lane/DPP/permute operations, bitcasts, and narrowing conversions.EmitConvertF32U32to convert sign-extended inputs via non-negative 31-bit sticky-halfOpConvertSToFfollowed byExactMul(..., 2.0f).EmitConvertF64U32to convert sign-extended inputs viaOpConvertSToFfollowed by a conditional exact2^32adjustment.core/libs/prx/libSceAgcDriver/tests/execution/SdwaDestination.cppto testWORD_0/WORD_1withSEXTpreserving bit 15 inRunConversionsand addedRunSignExtendedUnsignedConversionscovering all six sub-dword SDWA selectors (BYTE_0..BYTE_3,WORD_0,WORD_1) acrossZEXT/SEXTas well asv_readfirstlane_b32+s_sext_i32_i8/s_sext_i32_i16feedingv_cvt_f32_u32_e32.[Unsigned conversion of sign-extended SDWA sources on NVIDIA]fromdocs/dev/debt/shader.mdviadocs/dev/debt/changes/fix-shader-nvidia-sext-utof.md.Tested
ANYPS5_GPU="NVIDIA GeForce GTX 1660 SUPER" ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R "^(agc_driver_sdwa_destination.*|agc_driver_sdwa_cvt_f32_ubyte.*|agc_redundant_value_elimination|agc_denormal_flush_elimination|agc_shader_memory)$" -V):main(e9cfe038c1): 9/9 passed (4.39 sec), 6Insert instance layer "VK_LAYER_KHRONOS_validation"insertions, 0was not foundwarnings, 0VUID-errors.agc_driver_sdwa_destinationandagc_driver_sdwa_destination_wave64failed onlane 2 u32 wave32/wave64 source 4 sext 1 destination 0 unused 0 is 0x00000000, expected 0x000000ff.fix-shader-nvidia-sext-utof): 9/9 passed (4.05 sec), 6Insert instance layer "VK_LAYER_KHRONOS_validation"insertions, 0was not foundwarnings, 0VUID-errors (sdwa integer-to-f32 u32 wave32/64: 252 combinations passed,sdwa sign-extended u32-to-f32 wave32/64: 896 results passed).ctest --test-dir build -R "^(agc_driver_sdwa.*|agc_driver_f16_to_f32.*|shader.*)$" -j 4): 42/42 passed (10.01 sec).python3 tools/debt_fold.py --checkpassed.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T06:02:33Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the checks reported by the author are encouraging, but I did not run them, so approval is not justified.
What I ran
Reviewed head
199111fe7bb3a407bb06f368576bc3a8efbc56eeusingrepo_read.pyto inspect the prepared diff and pinned repository files. No commands or tests were run by me; test results below are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not execute the reported tests or independently validate the NVIDIA compiler behavior. Author-reported hardware, driver, Vulkan, and OS details are in the PR description. The prepared bundle lists all six changed files as included; I read every added line in those files. No excluded changed files were listed in the review folder.
To get this to a good state
Nothing is required. The reported test results are not independently verified, so this review does not approve the change.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T12:55:16Z.
Review: COMMENTED
Reviewed — no blocking findings
The shader conversion changes and focused test additions were reviewed at head
ca2b6ba24247c31ecf0b8db9ad7e57a023099430; no tests were run during this review, so a formal approval is not justified.What I ran
No commands or tests were run. I inspected the prepared diff and targeted source ranges using
repo_read.py.Results
Findings
Blocking
None identified in the inspected ranges.
Non-blocking
None.
Not verified
I read
description.md,commits.md,manifest.json, anddiff.patch. Of the six changed files listed in the manifest, I inspected targeted ranges inSdwaDestination.cpp,SpirvEmitterInstructions.hpp,SpirvAluEmitterMath.cpp, andSpirvAluEmitterFloat64.cpp; the full text of those files was not read. I did not readSpirvEmitterHelpers.hpporfix-shader-nvidia-sext-utof.md. Test results in the PR description were not independently verified. No files were excluded by the prepared review manifest.To get this to a good state
Nothing is required.