fix(libSceAgcDriver): quantize fallback D16_UNORM_S8_UINT depth clears, writes and bounds #17899
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17899"
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 hamb3r on 2026-11-09T21:18:55Z.
What
On devices without
VK_FORMAT_D16_UNORM_S8_UINTattachment support (such as NVIDIA GPUs),libSceAgcDriverbacks 16-bit depth-stencil surfaces withVK_FORMAT_D24_UNORM_S8_UINTorVK_FORMAT_D32_SFLOAT_S8_UINT. Previously, clears, fragment depth values and dynamic depth bounds kept the wider host format's sub-16-bit precision, causingEQUAL/LESS/GREATERdepth tests, stencil pass/depth-fail operations anddepthBoundsTestto diverge from native 16-bit RDNA2 depth buffers whenever two values fell into the same1 / 65535step.This PR matches native 16-bit unorm depth precision across all three paths on fallback surfaces:
DepthSurface): RoundvkCmdClearDepthStencilImageclear values to the nearest 16-bit unorm step (rint(clamp(z, 0, 1) * 65535) * (1 / 65535)), and add a trivially-destructiblethread_localfast-path cache toHostDepthFormatahead of the cache mutex.Pipeline): When a draw tests or writes depth on a fallbackD16_UNORM_S8_UINTtarget, rewrite the fragment shader's SPIR-V to quantizeFragDepthstores (or injectFragDepthquantized fromFragCoord.z) viaRoundEvenin[0, 1], stripEarlyFragmentTests/DepthLess/DepthGreaterand addDepthReplacing; shaders withEarlyFragmentTeststhat also write memory throw rather than moving early tests past side effects. Stencil-only and depth-bounds-only draws (!depthTest && !depthWrite) leave the shader untouched. Pipeline andVK_EXT_graphics_pipeline_librarykeys includeHostDepthFormatandQuantizesDepth16.Pipeline): Clamp and roundminDepthBounds/maxDepthBoundsto 16-bit unorm steps inBind,setLibraryStateandContinueBackFaces(HostDepthBounds), matching theDB_DEPTH_BOUNDS_MIN/DB_DEPTH_BOUNDS_MAXrounding and[0, 1]clamping measured on RDNA2D16_UNORM_S8_UINThardware even withVK_EXT_depth_range_unrestrictedenabled.16-bit depth with stencilentry indocs/dev/debt/libSceAgcDriver.mdand addagc_driver_d16_stencil_precisioncovering bucket boundaries,0.5-tie rounding, clears, interpolated depth,OpKill, explicitFragDepth,negativeOneToOne, sub-quantum and unrestricted depth bounds, sub-quantum and multi-step slope/constant depth bias, guest format controls andEarlyFragmentTestsmemory-write refusal.Tested
Windows 10 x64 with
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(verified active; 0 missing-layer warnings and 0VUID-validation errors across all runs):agc_driver_d16_stencil_precision:89/89on nativeVK_FORMAT_D16_UNORM_S8_UINTand85/85on forcedVK_FORMAT_D32_SFLOAT_S8_UINTfallback (1-to-1 match against native RDNA2 16-bit depth hardware).91/91on defaultVK_FORMAT_D24_UNORM_S8_UINTfallback and87/87on forcedVK_FORMAT_D32_SFLOAT_S8_UINTfallback.mainvs branch, both GPUs):agc_driver_depth_bias_per_faceandagc_driver_depth_range_remap_draw: passed on bothmainand this branch with0VUID-validation errors.tools/check_conventions.py --base origin/main: passed.tools/pr_overlap.py --branch fix/agc-d16s8-depth-quantization: no open PR implementsD16_UNORM_S8_UINTquantization.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-20T15:22:04Z.
Review: COMMENTED
Reviewed — comments
Material implementation defects are not verified from the inspected code; the new execution test’s build integration was not confirmed.
What I ran
Reviewed head
dbdf82b05ce034aa55dbfd4d5d07e16e63e54681using the prepared diff and the pinnedrepo_read.pyreader. No build or test commands were run. The GPU results in the PR description are author-reported.Results
Findings
Blocking
None verified.
Non-blocking
Not verified
Read:
description.md,commits.md,manifest.json,diff.patch,README.md, targeted ranges inPipeline.cppandDepthSurface.cpp, and the relevant range inD16StencilPrecision.cppas shown in the diff. All four changed files are included in the review bundle; full repository file texts were not read. Build registration, full test source, compilation, runtime behavior, validation output, and reported GPU results were not verified. Excluded files: none listed in the manifest.To get this to a good state
Nothing is required. Optional: confirm the new execution test is registered and run it in CI.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:45:44Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
5da49746a172d70d3e6aeb007ef40e2df1e1c638using the supplied review artifacts and the pinned repository reader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
Not verified
The runtime tests and validation runs described in the PR body were not run by this review. The listed changed files were all included and read:
DepthSurface.cpp,Pipeline.cpp,D16StencilPrecision.cpp, andfix-agc-d16s8-depth-quantization.md. No excluded changed files were listed. The build and test registration were inspected inCMakeLists.txtbut not executed.To get this to a good state
Nothing is required. The SPIR-V validation test is optional.