upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/main.cpp
diff options
context:
space:
mode:
authorthiefyzheng <thiefyzheng@users.noreply.github.com>2026-11-25 13:16:38 +0000
committerthiefyzheng <thiefyzheng@users.noreply.github.com>2026-11-25 13:16:42 +0000
commit06c3b4a6ac65d044faa7c99a10f46094cbfa9fc5 (patch)
treef9c5647c38ad1ec0dcb862b7569d73244578adaf /runtime/src/main.cpp
parent98c2f7777276f83eb90b491a51721ef90a43ea73 (diff)
RT-D24-CPU-ROUNDEVEN: Depth24 CPU conversions independent of the thread's rounding mode
depth24_quantize multiplied in float and rounded with std::nearbyint, and depth24_to_float divided in double and narrowed to float; all three follow the calling thread's rounding mode, while depth24_convert.comp is roundEven of a correctly rounded product and integer arithmetic. Under FE_DOWNWARD or FE_TOWARDZERO 0x1p-23f quantised to 1, not 2, so CPU clears (vulkan_replay.h depth24_clear_value) could disagree with GPU uploads and copies. No fesetround (a library must not change the caller's environment, and fenv access can be compiled out). No existing helper fits (vulkan_replay.h's round_half_even is in a header that includes this one's users and rounds only once), so depth24_detail::round_even is floor/fmod based like it: exact in every mode. The float product is formed exactly in a double (24 x 24 bits), rounded to 24 significant bits by scaling with ldexp and round_even, then rounded to the integer, which is the shader's two roundings. depth24_to_float uses the shader's integer formula, float(m + 1) * 2^(e-47), every step exact. depth24_cpu_test (no GPU, no Vulkan loader; same pattern as clear_color_test) runs the conversions under FE_TONEAREST, FE_DOWNWARD, FE_UPWARD and FE_TOWARDZERO and compares with a float multiply + nearbyint reference run under the default mode, with fixed cases (0x1p-23f -> 2, 0.5f -> 8388608 tie to even). AI-assisted. Checked with g++ -std=c++20 -O2 (also -frounding-math, -ffast-math); not built with MSVC.
Diffstat (limited to 'runtime/src/main.cpp')
0 files changed, 0 insertions, 0 deletions