feat(shader): flatten oversized 1D image arrays to 2D #14871
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14871"
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-01T21:55:05Z.
What
A 1D image array with more slices than
maxImageArrayLayerscould not be bound:ArrayLayerWindoweither threw or exposed only a window of it. God of War Ragnarök's present compute shader uses a256x1, 5120-layer, linear R8 1D array withimage_load_mip; on this devicemaxImageArrayLayersis 2048.This treats a 1D array that is only loaded or stored (not sampled) as the equivalent 2D image of
height = layers:PrepareImageModes, a non-sampled 1D array has its base dimension changed toDim2Dandflattened1DArrayset before SPIR-V emission. The plan, the specialized module and the binding all use the 2D binding (the binding number isbase + dimension, which is why a runtime mode that changed only the mode index produced mismatched bindings).DescriptorBindingcarries a per-elementimageFlattened1DArrayflag; the driver flattens only those elements, not every Image2D-over-1D-array window (the existing window path still serves sampled arrays and 2D-instruction/1D-T# views).height = last - base + 1, base address advanced by the viewed slices,depth = 0,baseArray = 0); anything else still throws.Limitations, also in the debt entry: sampled 1D arrays are not flattened (sampling would filter across layers); a loaded 1D array with mipmaps, tiled storage or DCC now throws instead of using the window path; 2D arrays past the limit remain unsupported. No console measurement exists for sampling a flattened array.
Tested
Linux x86-64 (CachyOS), GCC 16.2.1, Release, NVIDIA GeForce RTX 4080 SUPER (driver 615.78.8.0):
agc_driver_graphics(includes the new flatten unit test: base and windowed flatten),agc_driver_image_array_window_past_layer_limit,agc_driver_image_array_sample_on_volumeandagc_driver_image_packed_horizontal_gatherpass withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation; 0VUID-lines.image view of more array slices than maxImageArrayLayersandspecialized module bindings disagree with the prepared planfailures are gone. Together with #14870 (compute builtins) the run advances to a different, unrelated blocker,vertex shader does not export position.tools/check_conventions.py --base origin/mainandgit diff --checkare clean;tools/pr_overlap.py --branch feat/shader-flatten-large-1d-arraysreports no overlap with open pull requests.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 XairRrR on 2026-11-03T09:57:35Z.
Review: APPROVED
Reviewed — approved
The PR merges cleanly, builds, and passes its focused tests on lavapipe, including under the validation layer. The new execution test fails against
main's production code. I found nothing blocking; three small non-blocking notes are below.What I ran
Head
588e87b50a6f7c9b4e819a7ccc813d8d7f400e0a,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged with--no-ff(tree0499e6f05931d3a0ab147ea27c02162cd188bfa8). Machine: Debian 13 VM, 32 vCPU (2× Xeon Gold 6136), GCC 14.2.0, Release, Vulkan through lavapipe (Mesa 26.1.6, LLVM 19), no GPU.Results
git diff --checkcheck_conventions.pylibs(script)mainagc_driver_image_flatten_large_one_dimensional_arraywith the validation layerVUID-linesVUID-lines are inagc_driver_native_depth_uniform_planes(see below)agc_driver_native_depth_uniform_planesVUID-vkCmdDispatch-groupCountX-00386main's production files, so they come frommain, not from this PRThe baseline did not run
agc_driver_native_depth_uniform_planes((test not run on main)). I rebuilt its executable with every production file of this PR restored frommainand got the same 8VUID-vkCmdDispatch-groupCountX-00386lines, so I don't count it as a finding.agc_driver_graphicstook 34.1 s here, running in parallel with 5 other tests. This PR only adds a few lines of CPU-only checks to it. The NVIDIA CI comment had already flagged it at 32.5 s on an earlier head.Negative control
I restored all 17 production files of the diff from
mainand kept the tests. I then rebuiltagc_driver_image_flatten_large_one_dimensional_array_tests. The test fails as expected:output
With the merged files restored and the build tree rebuilt, the test passes again and
git status --porcelainis empty.The new
TextureTiling.cppblock callsFlattenLargeOneDimensionalArray, which does not exist onmain, so that part ofagc_driver_graphicscan't build againstmain's production code. Its negative control is a build failure, which I did not run separately.Earlier review points
oneandonlydean's three points are resolved at this head:
FormatVersionis now 69.flattenRequiredholds: the viewed layer count is greater thanmaxImageArrayLayersand the image is not sampled. The flattened mode is chosen only when the image is also linear, single-mip and DCC-free (ResourceMaterializer.cpp:2343-2346). The fittingkZ64KBXcase is covered by the new execution test, with and without the cache.rejectchecks are gone fromTextureTiling.cpp.Findings
Blocking
None.
Non-blocking
PrepareImageModessetsflattenAllowedon table images too (core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp:2466).ResolveImageTables→decodeTableEntrycan choose theDim2Dflattened mode for an oversized linear 1D-array table entry. It stores the entry withmode.dimensionand the original words (ResourceMaterializer.cpp:1947).imageFlattened1DArrayflag. The driver therefore rejects the entry with "guest texture dimension disagrees with the table entry's image shape" (core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp:5485).mainas well, so this is not a regression. But the error is misleading, and the shader gains a table mode it can never use.flattenAllowedonly forimage.table == NoTable, or flatten the descriptor in the table path. Either way, mention table entries in the new debt entry.maxImageArrayLayersassignments inVulkanDevice.cppare redundant.buildTarget()already setstarget.maxImageArrayLayersonmain(core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:4308).Target()starts fromshaderProfile->Target(), which is built frombuildTarget()(VulkanDevice.cpp:2308).VulkanDevice.cpp:4275and:4288change nothing; they can be dropped.ShaderResources.cpp:3811drops theconstfromresourcewithout changing it afterwards.IrResourcePlan::maxImageArrayLayersand inImageResource::maxArrayLayers(Resources.hpp:107, the layer-row work).ShaderInfo::maxImageArrayLayersand copies it throughApplyResourcePlanInfo.Not verified
maxImageArrayLayersis 2048, so the test uses 2049 layers.DescribeSurface/GuestLayerOffsetmodel, so it checks that the driver is consistent with itself, not with the console layout.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T21:37:16Z.
Review: COMMENTED
Reviewed — comments
The prepared diff supports the stated flattening design, but I did not run the reported checks or read every included file, so a formal decision is not justified.
What I ran
Reviewed head
e1560ded0325a0f1452981108e06fb0f77ce180eusing the prepared diff andrepo_read.py. No commands or tests were run; the reported test results are author supplied.Results
Negative control
Not run; this review environment provided no shell or test runner.
Findings
Blocking
None identified in the code inspected.
Non-blocking
Sources
e1560ded0325a0f1452981108e06fb0f77ce180e.Not verified
The full text of
VulkanDevice.cppandShaderResources.cppwas excluded as too large for the review folder; targeted relevant ranges were read throughrepo_read.py. I reviewed the diff hunks for all changed files but did not read every included file in full. Tests, conventions, diff checks, game behavior, and console behavior were not independently verified. The reported author checks and their environment are recorded indescription.md.To get this to a good state
Nothing is required. Optional: add targeted coverage for the documented unsupported oversized-resource cases.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T10:32:34Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
89cec1b94d28fae84c4ae40ad00482470be09630. No commands or tests were run; the review reader provided access to the prepared diff and pinned repository files.Results
Findings
Blocking
None.
Non-blocking
maxImageArrayLayers + 1, so it skips on devices reporting 8192 or more layers and otherwise tests just beyond the limit. Consider adding coverage for a much larger layer count (or a boundary test) to exercise address and allocation arithmetic across the advertised use case. Changed lines:core/libs/prx/libSceAgcDriver/tests/execution/ImageFlattenLargeOneDimensionalArray.cpp:292-299.Not verified
VulkanDevice.cppandShaderResources.cppwere too large to include in the prepared full-text files; targeted lines were read through the reader. Other uninspected changed file contents and excluded files were not verified.files.jsonwas not available through the reader, so the excluded-by-rule inventory could not be checked. The manifest lists 16 changed files; targeted review covered the diff plus selected repository ranges, not every listed file in full.To get this to a good state
Nothing is required. Optional: add broader layer-count coverage to the execution test.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T06:42:07Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected implementation blocks merging; the reviewed paths support the stated flattening behavior, with the limitations recorded below.
What I ran
Reviewed head
4855f7adb886398edd9b1ed43ffc5e442ba2dc5e. No build or tests were run; the reported GPU tests and title run are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No commands, build, or tests were run. The PR reports successful NVIDIA Linux tests and a God of War Ragnarök run; those results were not independently confirmed. No console measurement is reported for sampling flattened arrays, and sampled arrays are outside this implementation's flatten path. Full text for
VulkanDevice.cppandShaderResources.cppwas excluded from the review bundle; relevant ranges were read throughrepo_read.py. Other changed files not listed here were not read in full. Bundle files read:description.md,commits.md,manifest.json,diff.patch;files.jsonwas not available through the reader. Targeted repository files read:VulkanDevice.cpp,GuestTextureResource.hpp,GuestTextureResource.cpp,ShaderResources.cpp,Texture.cpp,TextureTiling.cpp,ResourceMaterializer.hpp,ResourceMaterializer.cpp,BindingAllocator.cpp,DescriptorBindingBuilder.cpp,ShaderInfoCollector.cpp,Recompiler.cpp,Recompiler.hpp,ShaderDiskCache.cpp,ShaderDiskCache.hpp,SpirvImageEmitter.cpp, andSpirvEmitterHelpers.cpp.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:50:59Z.
Review: CHANGES_REQUESTED
Reviewed — comments
Changes are required before merge: the runtime mode selection does not reject oversized 1D arrays when flattening is unsupported, allowing them to select the ordinary 1D-array mode and reach Vulkan past its layer limit.
What I ran
204e32f5d1f4f2a00a613c1ad72c9875f7e609d0.Results
Findings
Blocking
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp:2594— When an oversized 1D array has mipmaps, tiled storage, or DCC,flattenSupportedis false. The ordinary mode is still eligible becausemodeEligiblereturns!flattenRequiredfor non-flattened modes, and the regular 1D-array mode matches the decoded dimension. The driver then attempts to bind the over-limit array without flattening, contrary to the stated unsupported-path behavior and risking a Vulkan validation failure or unusable image view. RejectflattenRequired && !flattenSupportedbefore selecting a mode.Non-blocking
None.
Not verified
VulkanDevice.cppandShaderResources.cppwas excluded from the review folder; only the relevant source ranges were read through the reader.files.jsonwas not available as a review document; the changed-file inclusion list was obtained from the review directory listing.To get this to a good state
Reject oversized arrays when their resource properties do not support flattening, then rerun the relevant tests and review the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T09:08:22Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the optional point below is to add storage-write coverage for flattened arrays.
What I ran
Reviewed head
78c4a27d83f4a88031ab0f3823d181660613238busing the prepared diff and pinned repository readerrepo_read.py. I ran no build or test commands; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
image_loadfrom the flattened image, while the change also enables storage writes. Consider adding animage_storecase to cover writes through the same flattened binding. Relevant changed lines:core/libs/prx/libSceAgcDriver/tests/execution/ImageFlattenLargeOneDimensionalArray.cpp:37andcore/shader/recompiler/Optimization/src/ResourceMaterializer.cpp:2381.Not verified
Build and test commands were not run. The PR description reports NVIDIA RTX 4080 SUPER runs on CachyOS with GCC 16.2.1, and a God of War Ragnarök run; these were not independently verified. The two files excluded from the review folder were read through the pinned repository reader:
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp. No other changed files were excluded; all files marked reviewed in the manifest were read.To get this to a good state
Nothing is required. The optional storage-write coverage point is listed above.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T07:55:24Z.
Review: COMMENTED
Actionable comments posted: 3
b5cbbb69-9cdb-4c2f-a0eb-365b9e144016Reviewing files that changed from the base of the PR and between
6ce3a027b1andb9ddb1e1c0.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/TextureTiling.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageFlattenLargeOneDimensionalArray.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ShaderInfo.hppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/BindingAllocator.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ShaderInfoCollector.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppdocs/dev/debt/shader.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-27T08:19:57Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review supports merging, with console behavior and the author-reported runs not independently verified.
What I ran
Reviewed head
b9ddb1e1c0de6b2e80c332f1a6a58d6d1391891fusing the prepared diff andrepo_read.pyfor targeted source context. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The device test results and God of War Ragnarök behavior in the description were not independently reproduced. Full text was read for 18 of 20 changed files;
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppwere excluded from the review bundle and only targeted ranges were read throughrepo_read.py. The remaining changed files were read in full from the bundle.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T22:20:33Z.
Review: COMMENTED
Actionable comments
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp, lines1540–1542· 🎯 Functional Correctness · ⚡ Quick winDim2Dmode withflattened1DArray=true. This guard still treats that mode as a non-array view and requires the original layer coordinate to equal zero. Reads from layer 1 return zero. The equivalent guards at Line 1730 and Line 1833 also suppress stores and atomics.flattened1DArrayfrom all three zero-layer guards. Keep the guards for ordinary non-array views.CoordU32already carries the original layer coordinate into the flattened image's row coordinate.5657aa4e-ec6a-42b5-b6cb-57258de3ab0cReviewing files that changed from the base of the PR and between
b9ddb1e1c0and7689758539.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppdocs/dev/debt/shader.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:45:25Z.
Review: COMMENTED
Please check the height limit on the flattened resource. The new selection is based on
maxImageArrayLayers, thenFlattenLargeOneDimensionalArraysets the 2D image height to the number of viewed slices. It needs a distinctmaxImageDimension2Dcheck before creating that 2D image, since a view can exceed both limits. The existing limit inTexture.cppguards thelayerRowspath for 1D arrays; this helper changes the descriptor tok2D. Include a clean refusal or supported fallback for a view taller than the device’s 2D limit. The trial merge ontoc1601e56d5was clean and paired execution is pending.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T01:05:40Z.
Review: COMMENTED
Reviewed — no blocking findings
I found no blocking defect in the 18 changed files whose full text I could inspect; two changed files remain unverified because the pinned reader could not complete those reads.
What I ran
Reviewed head
7689758539a93713b372cabcdfa8ea2924a93d0dusing the prepared diff and included file texts, plus one successful pinned-reader read. No build or tests were run. The review host toolchain was not recorded.The reader failed on later reads because it could not write its read log in the read-only workspace. Full text was available for 18 of the 20 files listed under
reviewedinfiles.json.Results
Negative control
Not run; no tests were run in this review.
Findings
Blocking
None in the files whose full text I inspected.
Non-blocking
None.
Sources
The inspected implementation adds flattening eligibility and runtime image modes in ResourceMaterializer.cpp and applies the converted texture resource in GuestTextureResource.cpp.
Not verified
Full source text for
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppwas excluded from the review folder. The pinned reader could not complete reads for those files. Their changed hunks were visible in the prepared diff, but surrounding source behavior was not verified. Tests, build, and the author-reported GPU behavior were not independently verified.To get this to a good state
Nothing is required. Optional: make the pinned reader available for the two excluded files so their surrounding code can be reviewed before a formal approval.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T16:20:59Z.
Review: COMMENTED
Actionable comments
c3426c78-281c-4408-9cfb-979f79a5c6d2Reviewing files that changed from the base of the PR and between
7689758539and1db19819ec.core/libs/prx/libSceAgcDriver/Graphics/include/GuestTextureResource.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/TextureTiling.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageFlattenLargeOneDimensionalArray.cppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/ShaderInfoCollector.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppdocs/dev/debt/shader.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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.