runtime: fix D16S8 fragment depth quantisation and pc_format fallback gating #1764
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1764
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1764"
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?
@IlyassRS3 on GitHub · 2026-11-25 11:39 UTC · original
IlyassRS3:fix/depth16-quantise-fallback→main· +673 −16 · 5 files · 2 commits · merged 2026-11-26 18:23 UTCItem ID:
RT-DEPTH16-QUANTISE-AND-FALLBACKClaim: #1608
Summary
Fixes three bugs in the Xbox
D16_UNORM_S8_UINT(DXGI 118) depth-draw path introduced indb19bbd3:256x depth shrinkage in
depth24_fragment.h(levels == 65535.0f):Patch::quantise()scaled and clamped fragment depth bylevels_(65535.0f), but still hardcoded the 24-bit UNORM reconstruction constants (0xffffffu,23 - e,e + 80). As a result, every fragment depth in(0, 1)on a D16S8 fallback pass was divided by16,777,215instead of65,535(e.g.0.5 -> 0.001953,0.9999 -> 0.003906, while1.0 -> 1.0).levels_ == 65535.0f(n = d << (15 - e),m = (n << 8) + ((n + 128) >> 8),scale = 2^(e - 39)via biased exponente + 88), matchingstatic_cast<float>(double(d) / 65535.0)bit-for-bit across all 65,536 codes without relying on SPIR-VOpFDiv's 2.5 ULP bound.Patch::prime_quantise()beforeapply()soshader_writes_depth(at_return) never emits undeclared global constants.levelsvalues (anything other than16777215.0for65535.0f) instead of silently feeding them into the 24-bit formula, and fixed-WreorderonPatch::levels_.packed16_fallbackbypassedpc_format()ind3d12_vulkan_device.cpp:7298:PipelineState::create_graphics()checked rawdesc.DSVFormat == xbox_d16s8instead ofvulkan_format(desc.DSVFormat, true).format == VK_FORMAT_D16_UNORM_S8_UINT. On NVIDIA GPUs (defaultLEONIDA_CONSOLE_D16S8=d24, wherepc_format(118)backs format 118 with nativeVK_FORMAT_D24_UNORM_S8_UINT),packed16_fallbackstill evaluated true — returningE_NOTIMPLon MSAA format-118 PSOs, disabling hardware depth bias, and patching single-sampled fragment shaders with 16-bit quantisation against a D24S8 target.D16S8 clear/fragment tie & NaN parity in
vulkan_replay.h:4344: replacedstd::round(std::clamp(depth, 0.0f, 1.0f) * 65535.0f) / 65535.0fwithdetail::quantize_depth16()(float multiply +round_half_even+NaN -> 0.0f+ double divide) soClearDepthStencilViewmatchesPatch::quantise(levels = 65535.0f)bit-for-bit forEQUALdepth tests.Testing
runtime/shims/d3d12_vulkan_device.cppandruntime/src/vulkan_replay.hcould not be compiled or GPU-tested locally and rely on CI / Windows GPU verification.clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined runtime/test/depth24_fragment_test.cpp -o <tmp> && <tmp>— PASS (all 65536 D16 codes, ties, specials, bias/clamp, D24 parity, including structural SPIR-V validation and execution of depth-only, plain PS, and multi-returnSV_DepthPS)clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/depth24_fragment_test.cpp -o <tmp> && <tmp>— PASSmain:runtime/src/depth24_fragment.h— reproduced exact failure (D16 mismatch at d=1: got 33800001 (5.96046519e-08), want 37800080 (1.52590219e-05), exit 1)python3 -I scripts/check_no_game_data.py runtime/src/depth24_fragment.h runtime/shims/d3d12_vulkan_device.cpp runtime/src/vulkan_replay.h runtime/test/depth24_fragment_test.cpp runtime/CMakeLists.txt— PASSpython3 -I tests/test_text_write_line_endings.py— PASS (3/3)@copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 11:39 UTC · original · reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
@ecox982745 on GitHub · 2026-11-25 11:48 UTC · original
Native Windows 11 / RTX 4090 (NVIDIA 616.64), built with MSVC. The D16 shader change fixes a measurable output error on this card.
bcaa13dad4645a3f62I used a 256×256 full-screen draw with one D16 code per pixel. The input shader wrote
float(code) / 65535.0togl_FragDepth. For each revision I ran its productiondepth24_patch_fragmentwith 65,535 levels and zero bias, then copied the final shader depth to an RGBA32F color attachment immediately before return. Both the original patched modules and the instrumented modules passed Vulkan 1.0 SPIR-V validation. This measures the GPU shader output before depth attachment storage.All seven targeted CTests passed on the PR, including the fragment code sweep, D16S8 storage/surface tests and D24 draw regression. The D24 draw test skipped its six native-D24 bias-clamp cases on this setup. The GPU ramp uses a single sample; format-118 multisample pipeline creation is outside its coverage.
AI-assisted verification with OpenAI Codex. All inputs were synthetic.
@ecox982745 on GitHub · 2026-11-25 12:18 UTC · original
Verified the other two changes on native Windows 11, RTX 4090 (616.64). I built the parent
bcaa13dadand PR4645a3f62with MSVC and ran identical synthetic fixtures against both.4× MSAA with Xbox depth format 118. With default settings, the parent returned
E_NOTIMPL(0x80004001) from the firstCreateGraphicsPipelineState. The PR returnedS_OK, drew and resolved, and matched all 4,096 expected color pixels. Of 189 edge pixels, 64 had partial sample coverage, and the one-sample write mask behaved as expected. To reproduce, use format 118 in the three D32 sites inruntime/test/d3d12_msaa_draw_test.cpp(pipeline, resource, and view). The original D32 fixture passed on both builds. WithLEONIDA_CONSOLE_D16S8=nativeboth builds still returnedE_NOTIMPLfor the format-118 multisample pipeline, as intended on this card.Depth clear rounding. I used the six-layer
xbox_depth_storage_testwithLEONIDA_CONSOLE_D16S8=nativeandLEONIDA_TEST_D16S8_UAV=1. These are actual D16 depth words read back through the fixture’s UAV round trip.NaN read back as 0 on both builds. On the PR all 6,144 depth words and 6,144 stencil bytes matched, including the rectangle overwritten by the fixture. Both the default MSAA draw and the opt-in depth-clear test passed again in fresh processes.
AI-assisted verification with OpenAI Codex.
@Timon360SB on GitHub · 2026-11-25 14:40 UTC · original
Independent verification — Turing and Blackwell
bcaa13dad35f560748bd9b6293cd46504fe288c64645a3f62a7655ce69b930da70bdc1a858d1d0a1Environment
NVIDIA 621.14, Vulkan SDK 1.4.363.0, MSVC 19.44, Ninja RelWithDebInfo.
Three initial repetitions per configuration, followed by two additional sets of validated runs. Duplicate checkpoint results were excluded.
Results
depth24_convertd3d12_depth24_drawd3d12_d24_supportxbox_d16s8_storagexbox_d16s8_surfaced3d12_msaa_drawd3d12_depth_stencil_uavxbox_d16s8_refused_uav384 unique test executions: 276 passed, 108 failed, 0 CTest skips.
Findings
VUID-vkCmdCopyBufferToImage-pRegions-07931under validation on both revisions and GPUs.depth24_convertadditionally reportsVUID-vkDestroyDevice-device-05137.Conclusion
No new regressions observed in the selected tests on either architecture.
The new
depth24_fragmenttest, dedicated D16 quantisation sweep and format-118 MSAA experiment were not included. The standard MSAA fixture uses D32_FLOAT.Synthetic tests only. No game files used.
AI-assisted: yes.
@aslan2142 on GitHub · 2026-11-26 18:23 UTC · original
Merging.
bbf861fbb: a merge ofmainbdbc7e923into the branch. It resolves one conflict inruntime/CMakeLists.txt, wheremainadded three test entries at the place this branch addsdepth24_fragment. Both sides are kept; nothing else was changed.main, anddepth24_fragmentpasses.check_no_game_data.pyis clean on the five changed files.Thanks @IlyassRS3, and @ecox982745 and @Timon360SB for the tests.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)