Giter Club home page Giter Club logo

Comments (5)

lmdsp avatar lmdsp commented on June 3, 2024 1

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.

hermet avatar hermet commented on June 3, 2024 1

@lmdsp ThorVG welcomes contributors! If you have solutions or improvements, please don't hesitate to submit patches. Thank you for your support!

from thorvg.

hermet avatar hermet commented on June 3, 2024 1

@lmdsp Your fix will be applied in 0.12.7. Thanks for your contribution

from thorvg.

mgrudzinska avatar mgrudzinska commented on June 3, 2024

@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.

lmdsp avatar lmdsp commented on June 3, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.