Comments (5)
So it turns out in this case fill->radial.a = fill->radial.dr * fill->radial.dr - fill->radial.dx * fill->radial.dx - fill->radial.dy * fill->radial.dy;
at line 204 evaluates to 0 on Intel, but to 0.0107421838 on Apple Silicon !
The correct result is indeed 0 as a=dr²-dx²-dy² with dx=0, dr=dy=599.999939
It seems clang is doing some instruction reordering / FMA which is causing loss of precision.
This happens in both release/debug builds, with options such as GCC_FAST_MATH
set to off.
I found that storing intermediary results in temporary variables as shown below fixes the problem:
// Prevent loss of precision on Apple Silicon when dr=dy and dx=0
// https://github.com/thorvg/thorvg/issues/2014
const float dr2 = fill->radial.dr * fill->radial.dr;
const float dx2 = fill->radial.dx * fill->radial.dx;
const float dy2 = fill->radial.dy * fill->radial.dy;
fill->radial.a = dr2 - dx2 - dy2;
@mgrudzinska Do you want me to submit a PR ?
from thorvg.
@lmdsp ThorVG welcomes contributors! If you have solutions or improvements, please don't hesitate to submit patches. Thank you for your support!
from thorvg.
@lmdsp Your fix will be applied in 0.12.7. Thanks for your contribution
from thorvg.
@lmdsp could you please try after this slight change?
#2018
this is a random guess since for now I'm able to test on apple silicon.
Also could you please test what will happen if you change fy="-600" to fy="-597" ?
from thorvg.
@mgrudzinska Thanks for looking into this.
Changing from fy="-600" to fy="-597" doesn't change anything.
Changing line 207 from if (fill->radial.a > 0);
to if (fill->radial.a > RADIAL_A_THRESHOLD);
doesn't fix the problem either I'm afraid.
Perhaps a hint; those are the contents before and after executing the instructions at line 198
//This condition fulfills the SVG 1.1 std:
//the focal point, if outside the end circle, is moved to be on the end circle
//See: the SVG 2 std requirements: https://www.w3.org/TR/SVG2/pservers.html#RadialGradientNotes
if (fill->radial.a < 0) {
(lldb) p fill->radial
(SwFill::SwRadial) (a11 = 0, a12 = 0, a13 = 0, a21 = 0, a22 = 0, a23 = 0, fx = 429, fy = -600, fr = 0, dx = 0, dy = 603, dr = 599.999939, invA = 0, a = -3609.0625)
(lldb) p fill->radial
(SwFill::SwRadial) (a11 = 0, a12 = 0, a13 = 0, a21 = 0, a22 = 0, a23 = 0, fx = 429, fy = -596.999939, fr = 0, dx = 0, dy = 599.999939, dr = 599.999939, invA = 0, a = 0.0107421838)
from thorvg.
Related Issues (20)
- Update the thorvg viewer to support `.lottie` HOT 5
- First rows/column of pixels missing from embedded png in SVG HOT 5
- Rendering fails with SVG bitmap image outside canvas HOT 3
- SVG id attribute not validated. HOT 1
- [SVG] `fill="url(#a b)"` syntax is wrong so it should render as default, but renders the "a" ID instead HOT 4
- Question: Android JNI HOT 3
- Basic steps to compile for linux (wg_beta) HOT 3
- Divergence of starting points between SVG and Lottie standards HOT 1
- svg reference id spacer issue HOT 2
- static webp memory sanitizer detection
- What technique is used to triangulate shapes? HOT 2
- Memory problems that occur when the wasm class is destroyed HOT 2
- Incorrect outline for specific curve HOT 1
- Hash collisions in SVG loader HOT 4
- Lottie regression bug HOT 1
- Add c/c++ test suites for lottie slot
- Apply clang-format HOT 1
- Lottie loader is not updating the canvas HOT 8
- Metal backend support?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thorvg.