mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:45:54 +01:00
[PR #1858] runtime: Depth24 CPU conversions independent of the thread's rounding mode (RT-D24-CPU-ROUNDEVEN) #1870
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#1870
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/1858
Author: @thiefyzheng
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/d24-cpu-roundeven📝 Commits (1)
06c3b4aRT-D24-CPU-ROUNDEVEN: Depth24 CPU conversions independent of the thread's rounding mode📊 Changes
3 files changed (+167 additions, -5 deletions)
View changed files
📝
runtime/CMakeLists.txt(+7 -0)📝
runtime/src/depth24.h(+31 -5)➕
runtime/test/depth24_cpu_test.cpp(+129 -0)📄 Description
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).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.