runtime: Depth24 CPU conversions independent of the thread's rounding mode (RT-D24-CPU-ROUNDEVEN) #1858
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1858
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/d24-cpu-roundeven"
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 successfully merged and closed
RT-D24-CPU-ROUNDEVEN
Claimed on #1608 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163485212). Fixes @cheltyi's finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163281819):
runtime/src/depth24.h's CPU-side Depth24 conversion followed the calling thread's rounding mode (float multiply +std::nearbyint), whiledepth24_convert.compisroundEvenof a correctly rounded product — so a thread with directed rounding (FE_DOWNWARD/FE_TOWARDZERO) quantized0x1p-23fto 1 instead of 2 (~1 integer ULP off, beyond the documented 0.6 ULP tolerance), letting CPU clears (vulkan_replay.hdepth24_clear_value) disagree with GPU uploads/copies.depth24_to_floathad the same environment dependence.What
depth24_detail::round_even: floor/fmod-based ties-to-even, exact in every rounding mode — nofesetround, no fenv dependence, holds under-ffast-math.depth24_quantize: exactdouble(value) * 16777215.0(24×24 bits fit a double), round to 24 significant bits vialdexp+round_even, then round to integer — the shader's two roundings.depth24_to_float: the shader's integer formulaldexp(float(m+1), e-47), every step exact.vulkan_replay.h'sround_half_evenrounds once and lives in a header that includes this one's users).runtime/test/depth24_cpu_test.cpp(ctestdepth24_cpu, no GPU, no Vulkan loader; theclear_color_testpattern): runs both directions under FE_TONEAREST / FE_DOWNWARD / FE_UPWARD / FE_TOWARDZERO against a nearest-mode reference, with fixed cases (0x1p-23f -> 2,0.5f -> 8388608tie-to-even).What was run
-std=c++20 -O2(also-frounding-math): 1,858,324 checks passed across all four rounding modes (all 2^24 codes round-trip in nearest and downward; every third float pattern in [0,1] quantized nearest-vs-towardzero); plus-ffast-math: 0 mismatches. Before the fix the old header fails immediately under FE_DOWNWARD (depth24_quantize(0x1p-23) = 1, expected 2).depth24_cpu_testbuilt andctest -R depth24_cpuPassed (0.67 s).depth24_convert_test,d3d12_depth24_draw) — no Vulkan device here; the CPU/GPU cross-check on hardware would be the remaining confirmation, though both sides now implement the same documented formula.Attribution
AI-assisted (Claude Sonnet 5.5 worker implementation, contributor verification incl. the winvm MSVC build, orchestration).
Tested on Windows 11 (26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, merged onto
main384abe5b:depth24_cpupasses, and so do the device-sidedepth24_convert,d3d12_depth24_draw,d3d12_d24_supportandclear_color. That covers the CPU/GPU cross-check you couldn't run, on NVIDIA at least.I also ran an exhaustive check with MSVC
/fp:strict. Every float in (0, 1) went throughdepth24_quantizeunder all four rounding modes and was compared with main's float multiply +nearbyintin round-to-nearest: 4,261,412,860 checks, 0 mismatches (main's header mismatches under the directed modes). All 2^24 codes throughdepth24_to_floatgive the nearest float to d / 16777215 and round-trip in every mode; main gets 16,777,214 of those wrong under the directed modes.Reading the change:
x + 0.5inround_evenis exact at both call sites (at most 24 integer and 24 fraction bits), andfloat(m + 1)is at most 2^24, so neither path depends on the rounding mode. Looks correct to me.AI-assisted (Claude).
@potatoe0100 — thank you; this closes every verification gap the PR body listed. Recording for whoever merges: on Windows/RTX 4060 (NVIDIA 621.14), the CPU test plus all device-side Depth24 tests pass (
depth24_convert,d3d12_depth24_draw,d3d12_d24_support,clear_color), an exhaustive MSVC /fp:strict sweep over every float in (0,1) x all four rounding modes — 4,261,412,860 checks, 0 mismatches against the round-to-nearest reference (main's header mismatches under directed modes), all 2^24depth24_to_floatcodes round-trip in every mode (main wrong on 16,777,214 of them), and a reading confirmation that neither path depends on the rounding environment (x + 0.5exact at both call sites,float(m+1)at most 2^24).The PR is now CPU-verified (g++ and MSVC), GPU-cross-checked on NVIDIA, and exhaustively swept — nothing left except merge. AI-assisted (orchestrator).
Independent verification — Turing and Blackwell
Tested the exact merge base and PR head on two NVIDIA architectures under native Windows.
98c2f7777276f83eb90b491a51721ef90a43ea7306c3b4a6ac65d044faa7c99a10f46094cbfa9fc5Environment
MSVC 19.44.35230, Ninja Multi-Config, RelWithDebInfo.
Validated runs requested core validation, GPU-assisted validation and synchronization validation.
Results
Three initial repetitions per configuration, followed by two additional sets of validated runs.
Duplicate checkpoint results were excluded using execution timestamps and SHA-256 hashes of the original CTest logs.
depth24_convert, validation offdepth24_convert, validation ond3d12_depth24_drawd3d12_d24_supportAcross 144 unique CTest executions: 108 passed, 36 failed.
Results were identical on both GPU architectures.
Depth24 conversion results
Every execution of
depth24_convert, including those that subsequently failed under validation, reported:d / 16777215.Existing validation failure
depth24_convertfailed under validation on both revisions and both GPUs.The following diagnostics reproduced in every validated execution:
VUID-vkCmdCopyBufferToImage-pRegions-07931line 559: value == 0VUID-vkDestroyDevice-device-05137— an undestroyedVkQueryPool.The symptoms match those discussed in #1475. No isolated validation-layer configuration experiment was performed to establish the cause independently.
Depth24 rendering
d3d12_depth24_drawpassed in every execution, including LESS/EQUAL comparisons, stored-depth checks and fragment-depth output.Six internal depth-bias clamp cases per execution were skipped because
depthBiasClampwas unavailable for native D24.d3d12_d24_supportalso passed in every execution.Conclusion
No new regressions were observed in the three selected CTest scenarios on either Turing or Blackwell.
The existing validation-only failure remains unchanged.
The new
depth24_cputest and explicit changes to the CPU floating-point rounding mode were not exercised in this run. Therefore, these results provide hardware regression coverage, not independent verification of rounding-mode invariance.Synthetic tests only. No game files used.
AI-assisted: yes, test automation and result analysis.
@Timon360SB — thank you for the two-architecture sweep. Recording for the merge decision: base and head are behaviorally identical on RTX 5070 (Blackwell) and RTX 2060 SUPER (Turing) across 144 deduplicated validated ctest runs —
d3d12_depth24_drawandd3d12_d24_supportgreen in every execution, and everydepth24_convertrun (validation off) converting all 16,777,216 words to the nearest float with full round-trip survival, identical on both archs. No new regressions; thedepth24_convertfailures under GPU-assisted validation are the known, already-documented class from #1475 (VUID-07931/05137), unchanged between base and head.As you note, this is hardware regression coverage; the rounding-mode invariance itself stands on the CPU receipts (g++ ASan/UBSan corpus + MSVC build & ctest + your earlier /fp:strict sweep is potatoe0100's — the exhaustive cross-arch picture is now: CPU invariance proven, device parity and non-regression proven on NVIDIA across three architectures). Together with @potatoe0100's run, only merge remains. AI-assisted (orchestrator).
Verified by OreoFR
a8465211f+ PR head06c3b4a6a(merged with --no-ff, no conflict; tested in a package with other PRs that share no file with it)ctest -R ^depth24_cpu$(red: this test with src/depth24.h from main)depth24_quantize(0x1p-23)gives 1 instead of 2xbox_presentplus one flaky test that passed 3/3 on rerunruntime/CMakeLists.txtwith the open #2566; a rebase may be needed if #2566 lands first.AI-assisted (Claude Code, Claude Opus 5.5).
Verified by OreoFR: link check
59e65849b+ this PR (head06c3b4a6a, the head verified earlier) merged with --no-ff, built without the XMA decoder (LEONIDA_CARGO=OFF, noLEONIDA_XMA2_DECODER_LIB: configure reports the XMA2 and Opus decoders not built), RelWithDebInfo, Ninja, MSVC 19.44.35230 (VS 2022 BuildTools),LEONIDA_REQUIRE_VULKAN=ONgta6rt.exelinks; imports unchanged vs main built the same way (dumpbin /imports: 25 DLLs, 655 functions, no WS2_32)AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
Independently verified head
06c3b4a6ac65d044faa7c99a10f46094cbfa9fc5merged cleanly ontoorigin/main(59e65849b0927ee8c435baf1c74aecd08104fd60) on Windows 11 (10.0.26200), MSVC19.44.35207(RelWithDebInfo), NVIDIA GeForce RTX 3090 (driver595.79), withVK_LAYER_KHRONOS_validation1.4.363.1(LEONIDA_VK_VALIDATION=1). No game files used.Red -> Green Verification
main'sruntime/src/depth24.hwith PR'sdepth24_cpu_test.cpp):ctest -C RelWithDebInfo -R "^depth24_cpu$": FAILED (rc=8) under directed rounding (FE_DOWNWARD/FE_TOWARDZERO:depth24_quantize(0x1p-23) = 1, expected 2).#1858merged withorigin/main59e65849b0on RTX 3090):LEONIDA_VK_VALIDATION=1,0Khronos validation errors):depth24_cpu: Passed (FE_TONEAREST,FE_DOWNWARD,FE_UPWARD,FE_TOWARDZEROall match round-to-nearest-even reference and round-trip cleanly).clear_color: Passed.d3d12_depth24_draw: Passed (0Khronos validation errors).d3d12_d24_support: Passed (0Khronos validation errors).depth24_convert,LEONIDA_VK_VALIDATION=0due to pre-existing#1475test copy-region VUID):depth24_convert: Passed (8.56 son RTX 3090, all16,777,21624-bit depth words converted and round-tripped).scripts/check_no_game_data.py&tests/test_ctest_registration.py: Passed.Code Audit Notes
exact = double(value) * 16777215.0in IEEE-754 binary64 (24 + 24 = 48 <= 53significand bits) has zero intermediate rounding in any FP rounding mode, anddepth24_detail::round_evenuses onlystd::floorandstd::fmodon inputs wherex + 0.5has at most 24 integer and 24 fraction bits (48 <= 53), making both the 24-bit significand rounding and integer rounding exact and independent offenv.depth24_to_float(d)(std::ldexp(static_cast<float>(m + 1u), e - 47)) uses at most2^24inm + 1u, which is exact infloatregardless of the calling thread's rounding mode and matchesdepth24_convert.comp.AI-assisted: yes
Merged after OreoFR's red/green check (check: green with this PR merged onto
main, red without it;gta6rt.exestill links with unchanged imports when the PR touches the runtime) and a re-check here: no conflict withmain01d7f7f70, same head as checked, not frozen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan).AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.