Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

GPU: note why Posterize's division correction is an fma (#405 follow-up)

Brandon Thomasea785355cd98
diff --git a/crates/gpu/src/shaders/fx_stylize.wgsl b/crates/gpu/src/shaders/fx_stylize.wgsl
index b98c74742..3db442750 100644
--- a/crates/gpu/src/shaders/fx_stylize.wgsl
+++ b/crates/gpu/src/shaders/fx_stylize.wgsl
@@ -40,6 +40,8 @@ fn fxs_smoothstep(e0: f32, e1: f32, x: f32) -> f32 {
fn fxs_qdiv(x: vec3<f32>, a: f32) -> vec3<f32> {
let q = x / a;
let r = fma(-q, vec3<f32>(a), x);
+ // `q + r / a`, written as an fma so drivers (NVIDIA Vulkan) can't contract it another way
+ // and round differently from the CPU.
return fma(r / a, vec3<f32>(1.0), q);
}