hn.today

When the fractional part of a float fixes your shader

crocidb.com3 points0 comments
Screenshot of When the fractional part of a float fixes your shader

A Voronoi-diagram shader intended as a moving background produced a visible stutter on one Windows machine while running fine elsewhere. The visual artifact came from the noise that places Voronoi centers: replacing GLSL fract(x) with the mathematically equivalent x - floor(x) immediately removed the snapping. An LLM suggested a specific NVIDIA driver miscompile (driver 595.79 on an RTX 4070) that made fract temporally discontinuous for large operands, but that explanation proved incomplete after further testing.

Hands-on experiments revealed a different, subtler cause: changing a single float literal (e.g., 398.0 → 398.1) or inserting any fractional multiplication in the noise input also eliminated the stutter, even with fract still present. Capturing browser frames with RenderDoc and inspecting pixel-shader disassembly showed dramatically different compiled code paths depending on that literal, and that the browser was using DirectX 11 shader binaries. The outcome points to a GPU compiler/optimization quirk in the WebGL/driver toolchain that alters instruction emission and floating-point behavior; pragmatic fixes are to avoid fract() in critical noise kernels or force different expression forms/literals so the compiler emits safe code.

Read on crocidb.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Bend

Bend

Bend is a high-speed programming language that emphasizes correctness through proofs and laws, ensuring AI-generated code is error-free. It compiles to native code, runs parallel across multiple cores or GPUs, and verifies AI adherence to rules with rapid type checking and proof systems. (bend-lang.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.