mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #1764] [MERGED] runtime: fix D16S8 fragment depth quantisation and pc_format fallback gating #1776
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1776
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1764
Author: @IlyassRS3
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142
Base:
main← Head:fix/depth16-quantise-fallback📝 Commits (2)
4645a3fruntime: fix D16S8 fragment depth quantisation and pc_format fallback gatingbbf861fMerge main into fix/depth16-quantise-fallback📊 Changes
5 files changed (+673 additions, -16 deletions)
View changed files
📝
runtime/CMakeLists.txt(+4 -0)📝
runtime/shims/d3d12_vulkan_device.cpp(+6 -3)📝
runtime/src/depth24_fragment.h(+44 -12)📝
runtime/src/vulkan_replay.h(+11 -1)➕
runtime/test/depth24_fragment_test.cpp(+608 -0)📄 Description
Item ID:
RT-DEPTH16-QUANTISE-AND-FALLBACKClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161138331
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)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.