Repository navigation
cvcGL eWave: the update pass's own sin and cos, so macOS's renderer agrees with the CPU - #1224
Merged
Merged
Conversation
…grees with the CPU cvcgl_ewave failed on every macOS package lane: on the Apple Software Renderer the GPU window left the CPU one by about 8e-4 of the field a step, 3e-2 after the test's 48 steps, against its 1e-3. The update pass took cos(om dt) and sin(om dt) from GLSL's built-ins, which GLSL bounds only to an absolute 2^-11 (4.9e-4) on [-pi, pi]; that renderer uses the slack, llvmpipe and real GPUs don't. The pass now computes them itself: x less the nearest multiple of pi / 2 (two-part pi / 2), the series to r^9 and r^10 on |r| <= pi / 4, then the quadrant. In float with one rounding per operation that is within 8.4e-8 of sin and cos on [0, 256] rad. The coefficients stay per texel from uniforms, so a new dt still costs nothing; sqrt, tanh and exp stay GLSL's (bounded in ulps).
transfix
enabled auto-merge (squash)
November 14, 2026 06:49
#1194's symmetric step (no-flux walls, the default) takes kappa~ = 4 sin^2(omega dt_s / 2) / (g dt_s^2) in its multiply pass, from GLSL's sin: at the default substep the argument is a tenth of a radian or less, where GLSL's absolute 2^-11 is a relative error of several percent. sinCos is now one string literal (CVC_EWAVE_SINCOS_GLSL) that the update and multiply passes both take in, and the multiply pass's sin is its .x. EWave.h keeps #1194's description, with where sin and cos come from.
transfix
added a commit
that referenced
this pull request
Nov 14, 2026
…ates #1194 gave EWave the CPU's symmetric step for no-flux walls (fill, multiply and gather passes) and #1224 gave the update and multiply passes their own sin and cos series. Both rewrote the code this branch changed, so EWave.cpp and EWave.h start from master's and take this branch's change on both paths: - The exact step reads each mode's coefficients (modeCoefficients, as ewave::prepare) and each cell's real-space factor (realFactors, as ewave::update_real) from textures worked out on the host in double. - The symmetric step's multiply pass reads kappa~ and damping_k2's 1 - F (symmetricMultipliers, as ewave::prepare_symmetric, -expm1 for 1 - F), and its gather pass reads the real-space factors for dt_s. - The last pass home only zeroes walls, as before. No pass takes a sin, cos, exp, sqrt or tanh of its own, so #1224's series goes. - Each table is worked out again only when the step, the depth (setDepth) or the mask changes; dt_s is fixed, so the symmetric step pays once. cvcgl_ewave and cvcgl_wake pass on Windows (Intel Arc). Against master's #1224 on the same machine: step 48 (no-flux walls) h 3.14e-6 -> 2.20e-6, phi 2.23e-6 -> 1.53e-6; the zero-wall run 1.04e-5 -> 9.62e-6, the no-flux wall run 5.05e-6 -> 3.63e-6. Step times within run-to-run noise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cvcgl_ewavefails on every macOS package lane, so master's push runs show the red too (#1201'spackage-macos / libcvc-release-grpc, job 132021840192, is one). On macOS CI's Apple Software Renderer the GPU eWave window drifts from the CPU one by about 8e-4 of the field per step, reaching 3.0e-2 after the test's 48 steps; the test allows 1e-3. The drop as added matches to 2e-8, so the float textures are fine; the error builds up in the step.Cause
The update pass took
cos(om dt)andsin(om dt)from GLSL's built-ins. GLSL bounds those only to an absolute 2^-11 (4.9e-4) on [-pi, pi], and that renderer appears to use the slack. llvmpipe and real GPUs are far tighter, so Linux and Windows pass. The FFT's twiddles come from a table computed on the CPU, which is whycvcgl_ocean_fftpasses on macOS.Fix
The pass computes sin and cos itself (
sinCosinEWave.cpp):In float32, with one rounding per operation and no FMA, that is within 8.4e-8 of sin and cos on [0, 256] rad (checked with numpy). The coefficients stay per texel from uniforms, so a new dt still costs nothing.
sqrt,tanhandexpkeep GLSL's built-ins, which GLSL bounds in ulps.Checked locally (Windows, Intel Iris Xe,
cvcgl_ewaveRelease)The middle column was a throwaway experiment, not part of this PR. It gave the old shader built-ins that are wrong by an amount GLSL allows, and it reproduced macOS's three failures, with the same steady growth and the same order of magnitude.
Not checked here: macOS itself. PRs no longer run the macOS package lanes (#1205), so master's push run after this merges is the first macOS check. llvmpipe is covered by this PR's Linux and Windows jobs.
After #1194 (the symmetric step with no-flux walls)
#1194's multiply pass computes kappa~ = 4 sin^2(omega dt_s / 2) / (g dt_s^2) with GLSL's
sin. At the default 1/60 s substep that argument is about 0.1 rad or less, so GLSL's absolute 2^-11 is a relative error of several percent: 4.9% at 0.01 rad.sinCosis now one string literal,CVC_EWAVE_SINCOS_GLSL, and both passes take it in. The multiply pass uses its.x, which is within 1 float ulp (relative) on [1e-6, 0.5] rad. No eWave shader calls the built-insinorcosnow.Checked locally on the merged tree (Intel Iris Xe), 3 runs:
cvcgl_ewavepasses. Drift after 48 steps is h 3.1e-6 and phi 2.2e-6, and the no-flux and zero walls match the CPU to 5.1e-6 and 1.0e-5. The energy check holds on both 10,000-step jittered runs.sinoff by up to 4.5e-4, within GLSL's bound. It fails 6 checks. Drift reaches 4.5e-2, the no-flux wall run is off from the CPU by 6.8e-2, and the walled solver's energy rises above its start.