feat(shader): support Null destination in scalar loads #15488
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15488"
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 Kikoarl on 2026-11-03T14:57:32Z.
What
Null(125) as destination inscalarDestinationOperandfor SMEM scalar loads (s_load_dword*ands_buffer_load_dword*), discarding loaded components for cache prefetches without mutating registers.null: "Write: data is discarded"), and §13.4 "SMEM" / Table 76 ("SMEM Instruction Fields", fieldSDATA: "[6:0] specifies SGPR or NULL (125)").SIRegisterInfo.td#L234(defm SGPR_NULL_gfxpre11 : SIRegLoHi16 <"null", 125>;),SIRegisterInfo.td#L776(def SReg_32_XM0_XEXEC : SIRegisterClass<... (add ..., SGPR_NULL, ...)>), andSMInstructions.td#L326(defm S_LOAD_DWORD : SM_Pseudo_Loads <SReg_64, SReg_32_XM0_XEXEC>;).M0,ExecLo, andExecHias scalar load destinations inscalarDestinationOperand.sbase > 104(SMEM base register range overflow).TranslationContext.hpp.ShaderSpecialRegistersTests.cpptesting real decoded SMEM instruction words viaDecodeRdnaSmemandTranslateInstruction.docs/dev/debt/shader.md.Tested
/tmp/anyps5_build.ctest --test-dir /tmp/anyps5_build -R "^shader_special_registers$": Passed 100% (0.00 s)./tmp/anyps5_build/tests/shader_special_registers_tests: Passed cleanly.ctest --test-dir /tmp/anyps5_build -R "^shader_"): 14/14 passed (100%).OperandAccess.cpptomainfails withterminate called after throwing an instance of std::runtime_error what(): TranslationContext::scalarDestinationOperand invalid scalar-memory destination(exit code 134).M0,ExecLo, andExecHidestinations, and decoder refusal onsbase > 104.python3 tools/check_conventions.py --base origin/maincleanly with 0 errors and 0 warnings.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 XairRrR on 2026-11-03T15:36:09Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The PR merges and builds cleanly, and its new test passes and fails as expected against
main. However, it changes SMEM register semantics without naming a source, replaces a correct throw inreadOperand(F64)with a value of the wrong type, loosens IR type validation for a type no opcode produces, and adds a debt entry that records no gap.What I ran
Head
8138127ae8b313d49d1c33996246c15860f5e6fd,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree22fce29cb6db4e6b1c86330560dc4e6838574c2b. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6).Results
git diff --checkcheck_conventions.pymain.agc_driver_alpha_to_coverage_sample_mask_exportpassed when rerun.shader_special_registersVUID-linesgit status --porcelainemptyNegative control
I reverted the five production
.cppfiles tomainand kept the newTranslationContext.hppaccessors so the test still compiles. The test then aborts at its firstM0destination check:output
With the merged files restored and the target rebuilt, the test passes again.
Findings
Blocking
SMEM semantics with no source. These are the changes:
ScalarBufferInstructions.cpp:14and:33-38now acceptEXECas the 64-bit SBASE of a raw scalar load.OperandAccess.cpp:103-164now acceptsM0,NULL,EXEC_LOandEXEC_HIas SMEM SDATA destinations. ANULLdestination now discards every component instead of throwing.CONTRIBUTING requires a PR that adds or changes shader instruction semantics to name an ISA section, an LLVM/ACO/Mesa file or a hardware measurement, and to keep throwing for cases the source doesn't settle. The description names none and says
GPUs tested: none. Compilers may never pickM0orEXECas an SMEM destination. From memory, LLVM's SMEMsdstregister classes exclude M0 and EXEC (I could not check that here). If so, hardware behaviour for these encodings isn't settled by a compiler source.Fix: cite the RDNA2 ISA section, or an LLVM/ACO/Mesa file, that defines SDATA = M0/NULL/EXEC and SBASE = EXEC for SMEM, or a hardware-oracle measurement. Keep throwing for any case it doesn't cover, and record the unverified parts in the debt entry.
readOperand(IrType::F64)returns aU64value instead of throwing. The IR has no F64-typed values: every 64-bit float opcode usesU64(for exampleIrOpcode.cpp:295,makeMeta("FPAdd64", U64, U64, U64)). Onmain,readOperand(op, F64)reached the "unsupported operand type" throw, which was correct for a type the IR never uses.OperandAccess.cpp:266-269returns aCompositeConstructU64of typeU64. It is the only branch whose result type differs from the requested type. The test asserts this mismatch atShaderSpecialRegistersTests.cpp:343("readOperand F64 returns U64 pair construct").writeOperandatOperandAccess.cpp:338accepts F64.CompositeExtractU64now takes an F64 argument against its declaredU64signature, special-cased inIrBuilderCore.cpp:27,IrBuilderCore.cpp:51,IrProgram.cpp:708andIrBuilderConversions.cpp:32.No production path in the tree produces an F64-typed value. The only one is the test's hand-made
CreateValue(IrOpcode::FPAdd64, IrType::F64)atShaderSpecialRegistersTests.cpp:258, which breaks that opcode's own signature. So these changes widen the IR type checks for code that cannot run, and nothing checks that the SPIR-V emitter would handle an F64 operand toCompositeExtractU64.Fix: drop the F64 changes (
readOperand,writeOperand, the builder, validator andCompositeExtractexceptions) and the matching tests. If a real producer of F64 values appears later, add the type with its own opcode signatures, or a bitcast toU64, in that PR.The debt entry records no gap.
docs/dev/debt/shader.md:38describes implemented behaviour: what is mapped, what advances and what throws. CONTRIBUTING says an entry states the gap first (what differs from the console, what is unverified, what throws) and describes behaviour only as far as the gap needs it. The PR also adds no code comment, so no debt entry is required for the conventions check.Fix: replace it with the actual gap, for example "SMEM SDATA M0/NULL/EXEC and SBASE EXEC are not measured on a PS5", with a closing condition. Remove it if a cited source settles everything.
Non-blocking
U16andF16reads from scalar and special registers inreadOperand. Both branches (OperandAccess.cpp:242-248) are unchanged frommain. The new tests for them pass without this PR's changes to those lines.TranslationContext.hpp:35-38adds publicReadOperand/WriteOperand/ScalarDestinationOperand/SLoadwrappers whose only purpose is the test. Consider testing throughTranslationContext's existing public translation entry points with decoded SMEM instructions. That would also cover the decoder's mapping of codes 124-127, which the hand-builtRdnaOperands skip.ShaderSpecialRegistersTests.cppincludesRdnaDecoder/RdnaInstructionDecoder.hppbut never decodes anything.Not verified
shader_special_registersmyself. The wider selected suite and the Khronos validation layer comparison are the script's results, on lavapipe only.CompositeExtractU64, because no production code produces one.To get this to a good state
readOperand/writeOperandand theCompositeExtractU64F64 exceptions in the builder and validator, together with their tests.docs/dev/debt/shader.mdentry so it states only what is unverified, with a closing condition, or drop it.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T20:42:32Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
The new push removes the F64 operand handling, drops the unused include, rewrites the debt entry as a gap and names an RDNA2 ISA and LLVM source. Two problems remain. The LLVM citation does not seem to support SDATA = M0/EXEC. The new raw SBASE = EXEC path can't be reached from decoded shaders.
What changed since my last review
8138127ae8b3to3d7836f85bdc.IrBuilder,IrProgramandCompositeExtractexceptions. The PR now touches 6 files instead of 9.RdnaDecoder/RdnaInstructionDecoder.hppis no longer included by the test.docs/dev/debt/shader.md:38now opens with what is unmeasured, cites "RDNA2 ISA §§9.2, 12.4, 13.3.7 Table 88 and LLVM SMInstructions.td (allowing SReg_32 for SDATA and SReg_64 for SBASE)", and ends with "Closes when: measured on a PS5".What I ran
Head
3d7836f85bdc0bd1495f64603ad22f0c7c45c8b0,main086c0686c8adff3ee648fdbe34e0b0b647e1d511, merged tree6df5f43869cbde9b7d5db9fb756ce4ffe7ae70fc. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6).git diff --checkcheck_conventions.pymain.shader_special_registersscalarDestinationOperand invalid scalar-memory destinationagc_driver_image_gather_volumelistsVUID-VkSamplerCreateInfo-addressMode*lines marked "test not run on main". I got the same 4 VUIDs with this PR's production files reverted tomain, so they come frommain, not from this PR.git status --porcelainis emptyPrevious findings
readOperand(F64)returnsU64/ F64 IR exceptions. Resolved. The diff againstmainhas no F64 changes left.TranslationContext.hpp:35-38. Still open. Because the tests bypass the decoder, they hide new blocking finding 2.New findings
Blocking
docs/dev/debt/shader.md:38) says LLVMSMInstructions.tdallowsSReg_32for SDATA.S_LOAD_DWORDwith theSReg_32_XM0_XEXECdestination class and the wider loads withSReg_*_XEXEC. Those classes exclude M0 and EXEC on purpose. If so, LLVM never emits these encodings, and the source doesn't settle what hardware does with them.llvm-mcand no network._XM0_XEXEC, keep throwing for M0, EXEC_LO and EXEC_HI as SMEM destinations. NULL can stay if the ISA text covers it.ScalarBufferInstructions.cpp:14and:33-38acceptExecLoas a raw base.SMEM base register range overflowfor anysbase * 2 > 104other than 106, sosbase126 never gets past it: RdnaMemoryOpDecoder.cpp#L790-L797.ExecLooperand by hand and calls the newSLoadaccessor.ExecLobase support is not true for real shaders, and the debt entry records a gap for code that never runs.ExecLobase changes and that part of the debt entry, or mapsbase126 toExecLoin the decoder and test it with a decodeds_load_dwordx*word. Doing the latter needs the source from finding 1.Non-blocking
Not verified
f655009and8138127, not this one.GPUs tested: none.shader_special_registersandagc_driver_image_gather_volumemyself. The rest are the script's results, on lavapipe only.To get this to a good state
ExecLoSBASE handling, or wire it through the decoder and test it with a decoded instruction.TranslationContextaccessors.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T23:23:13Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
The commit was rewritten as
77d3ddaf66d6. It now only lets SMEM scalar loads takeNull(125) as the destination, and it drops the M0/EXEC destination, the EXEC base and the test-only accessors. The tests now decode real SMEM words. One rule is still not met: the new instruction semantics name no source.What changed since my last review
3d7836f85bdcwas replaced by77d3ddaf66d6. The PR now touches 4 files (+170 −0).OperandAccess.cppnow has only an early return forRdnaOperandKind::NullinscalarDestinationOperand(core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp:104-106). M0, EXEC_LO and EXEC_HI still reach theinvalid scalar-memory destinationthrow.ScalarBufferInstructions.cppandTranslationContext.hppare no longer changed. On the merged tree they are the same as onmain.ShaderSpecialRegistersTests.cppbuilds SMEM words and runs them throughDecodeRdnaSmemandTranslateInstruction. It checks:s_load_dword*ands_buffer_load_dword*emits no register writes.sbase63 is refused by the decoder.s4andvcc_lodestinations still lower to writes.docs/dev/debt/shader.md:38) is shorter. It no longer cites the RDNA2 ISA sections or LLVMSMInstructions.td.f655009and8138127.What I ran
Head
77d3ddaf66d684be0d9e116723ce6523243aab16,main1c8c0efc8c41314402e6966da5bef6ea3d639d10, merged tree67eba10a5600b90700dfa4df794ec4425b4f5b83. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6).git diff --checkcheck_conventions.pymaintoo.shader_special_registersagc_driver_image_gather_volumereportsVUID-VkSamplerCreateInfo-addressMode*marked "test not run on main". WithOperandAccess.cppreverted tomainI got the same 4 VUIDs, so they come frommain, not from this PR.git status --porcelainis emptyNegative control output
Previous findings
OperandAccess.cpp:112), and the test checks this with decoded words 124, 126 and 127.ScalarBufferInstructions.cppis unchanged frommain, and the PR no longer claims an EXEC base.Null. The ISA/LLVM citation was removed together with the M0/EXEC part, and nothing replaced it. See new blocking finding 1.TranslationContext.hpp(non-blocking). Resolved. The header is unchanged and the tests go throughDecodeRdnaSmemandTranslateInstruction.New findings
Blocking
docs/dev/debt/shader.md:38names a source. The behaviour is very likely right, since NULL ignores writes everywhere else in the recompiler (writeRawU32,OperandAccess.cpp:514-516). But the rule asks for a source, and the reviewer has to be able to check it.s_load_dword null, ...on gfx10. A permanent link is enough. No code change is needed.Non-blocking
sLoadstill callsaddMemoryInfoand emitsLoadAddressU32/ReadConstBufferfor each component before the writes are dropped (ScalarBufferInstructions.cpp:37-50). So a NULL-destination raw load still registers a scalar-address resource and still issues a host read unless later passes remove it. If the guest address is invalid, this differs from a prefetch. The debt entry already records the faulting question, so this is a note, not a request.Not verified
f655009and8138127, and the checklist saysGPUs tested: none. Lavapipe only.shader_special_registersandagc_driver_image_gather_volumemyself. The other results come from the script.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:21:51Z.
Review: APPROVED
Reviewed — looks good
The change preserves
Nullfor scalar memory load destinations and adds focused decoder and translation coverage; no blocking defect was found in the reviewed code.What I ran
Reviewed head
eb6aec786d87356494b827b9e37111eb50d830cdusing the pinnedrepo_read.pyreader. No build or test commands were run; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No commands were run. The reported Linux build, test suite, differential test, and conventions check were not independently verified. Console cache effects and invalid-address faulting were not measured.
files.jsonwas unavailable through the reader; the manifest lists four changed files, all included and read. No changed files were excluded according to the supplied manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T10:36:01Z.
Review: APPROVED
I read the diff at
c524383b52. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged intomainatb97867d3ce6together with other open PRs (so not an isolated build).shader_special_registers: pass on both.main's): fails on both with "TranslationContext::scalarDestinationOperand invalid scalar-memory destination".Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:41:06Z.
Review: COMMENTED
The trial merge onto
c1601e56d5was clean. The translator fixture checks that the Null destination does not write SGPR, VCC, EXEC, or M0 state and retains a real-SGPR control. Please keep the cache and invalid-address semantics recorded as unmeasured, since the IR register-state test cannot settle what the console’s memory path does. Move the direct shader debt edit into a fragment. Paired controls are pending.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.