fix(agc): clamp an exported pixel depth to the viewport depth range #10348
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10348"
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 oneandonlydean on 2026-10-23T18:33:44Z.
What
A pixel shader that exports depth now has the exported value clamped to the viewport depth range before it reaches the depth attachment, as the DB does.
PA_SC_VPORT_ZMIN_0andZMAX_0when the shader exports depth (0 and 1 otherwise), and the recompiled shaderNClamps the exported value to them before it storesgl_FragDepth. Only viewport 0 bounds the clamp.DB_RENDER_OVERRIDE.DISABLE_VIEWPORT_CLAMPset, the value is stored as exported. Non-finite or inverted bounds are rejected.DB_RENDER_OVERRIDEjoins the draw key registers.The DB clamps an exported depth to
ZMIN/ZMAXunless the override disables it. Vulkan only clamps withdepthClamp, which also turns off clipping, so until now the exported value reached the depth attachment unclamped.This writes recompile request version 49 and reads the depth bounds from version 49 on. Main is at version 48 (the barycentric built-ins flag from #9193); this branch keeps main's version-48 fields and adds the bounds after them. Version 46, 47 and 48 requests still decode, with default depth bounds.
Tested
Head
d4a296d863(maind13b3d7c55merged in), compared with maind13b3d7c55, same machine, NVIDIA GeForce RTX 4090 (driver 610.57.04, Vulkan 1.4.341), Linux, Release build,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.363) andVK_LOADER_DEBUG=layer, so each log shows the loader inserting the layer. Tests selected:agc_driver_depth_export_clamp,agc_shader_memory,request_serializer,agc_driver_graphics,agc_masked_selectand every test withdepthin its name.d13b3d7c55d4a296d863Insert instance layer "VK_LAYER_KHRONOS_validation"(loader lines)was not found but was requestedVUID-linesThere are a couple more inserted-layer lines than tests because some tests create more than one Vulkan instance.
The extra passing test on the head is
agc_driver_depth_export_clamp, which does not exist on main. It runs on the device.agc_driver_depth_export_clampandagc_shader_memoryfail, so the tests cover the clamp.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 repositoryImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T19:25:16Z.
Review: CHANGES_REQUESTED
The reported RTX 4090 run covers the changed head, but this PR changes both the AGC driver and shader recompiler. CONTRIBUTING requires the same focused tests on
mainand this change, on the same machine and GPU, withVK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1, andANYPS5_REQUIRE_VULKAN=1, plus confirmation that the requested layer loaded and a comparison showing no newVUID-errors. Please add those baseline/change results (including the depth-export test and relevant serializer coverage) before merge. I could not dispatch the repository's manual build workflow from this account; GitHub returned HTTP 403 because workflow dispatch requires repository admin rights. My local configure also cannot reach the test build: this checkout has no SDL2 submodule sources and the host lacks XRandR development support, so I did not run the product tests.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T00:47:36Z.
Review: DISMISSED
The change reads right: the exported value is
NClamped toPA_SC_VPORT_ZMIN_0/ZMAX_0unlessDB_RENDER_OVERRIDEbit 16 is set, the bounds key the draw, the recompile cache (depth-exporting shaders only) and the serializer, and the new tests fail without the clamp. Two things block it:main, which now writes request version 46 (#8564:targetMergefields at the end ofreadPixelInfo/writePixelInfo). The bounds must be written and read after thetargetMergeblock, gated onversion >= 47, and the version fixtures inRequestSerializerTests.cppandShaderMemory.cpp(base64 prefixes, the byte-stripping legacy fixtures, "future version") need redoing on top of 46. Conflicts are inRequestSerializer.cpp,ShaderMemory.cppandRequestSerializerTests.cpp.agc_driver_depth_export_clamp,agc_shader_memory,request_serializer, the depth tests) onmainand on this branch, same machine and GPU, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, confirmation that the layer loaded, and a comparison showing no newVUID-errors. Please add those logs toTestedafter rebasing.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-26T16:20:40Z.
Review: DISMISSED
The rebase onto version 46 reads right: the bounds are written after the
targetMergeblock, read withversion >= 47, and the fixtures were redone. @wachi35676's control run (main's emitter with the rest of this PR) failsagc_driver_depth_export_clampandagc_shader_memoryon NVIDIA and AMD, so the tests cover the clamp. Two things are left:agc_driver_depth_export_clamp,agc_shader_memory,request_serializer, the depth tests) onmainand on this head, same machine and GPU, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, confirmation that the layer loaded (nowas not found but was requested by env var VK_INSTANCE_LAYERSin either log), and a comparison showing no newVUID-errors. The Windows runs above don't use the layer. Please add those logs toTested.Whatand updateTestedwith the run on the current head.Also, as wachi35676 noted, only
PA_SC_VPORT_ZMIN_0/ZMAX_0are read, so a draw that selects another viewport is clamped to viewport 0's range; please add a line for that indocs/dev/debt/for the AGC driver.