Transformation with double instead float precision

399 views
Skip to first unread message

扈马克

unread,
Jan 8, 2018, 8:53:04 AM1/8/18
to skia-d...@googlegroups.com
I'm writing a mapping application with different rendering backends. With skia, I have precision problems when zooming in. I think the reason is that SKMatrix / SkScala per default is float instead of double.
Is there a way to set up a transformation with double precision? I found only the following article regarding this topic:

https://groups.google.com/forum/#!topic/skia-discuss/Ie3d-i0PAsM

However it is quite old, so I don't know if it is still valid.

Thanks for any help,
Marco

Mike Klein

unread,
Jan 8, 2018, 9:16:57 AM1/8/18
to skia-d...@googlegroups.com
Back in the days of that post you linked, SkScalar could be either a float or a 16.16 fixed point.  We've since dropped the fixed point option, so it's always float now.

Logically SkScalar could be replaced with a double, but I bet there are many parts of the code base that will assume it's 4 byte, or even exactly a 1-8-23 layout float.  This would be a challenging project.

I believe we still support floats or doubles for SkMatrix44, but that is not the 3x3 matrix (SkMatrix) used by most of the drawing pipeline.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Mike Reed

unread,
Jan 8, 2018, 9:43:18 AM1/8/18
to skia-d...@googlegroups.com
Just off-hand, do you think it would be sufficient for your case if matrix was doubles, but geometries (i.e. paths, rects) were still floats?

On Mon, Jan 8, 2018 at 9:16 AM, 'Mike Klein' via skia-discuss <skia-d...@googlegroups.com> wrote:
Back in the days of that post you linked, SkScalar could be either a float or a 16.16 fixed point.  We've since dropped the fixed point option, so it's always float now.

Logically SkScalar could be replaced with a double, but I bet there are many parts of the code base that will assume it's 4 byte, or even exactly a 1-8-23 layout float.  This would be a challenging project.

I believe we still support floats or doubles for SkMatrix44, but that is not the 3x3 matrix (SkMatrix) used by most of the drawing pipeline.
On Mon, Jan 8, 2018 at 8:53 AM 扈马克 <geoh...@gmail.com> wrote:
I'm writing a mapping application with different rendering backends. With skia, I have precision problems when zooming in. I think the reason is that SKMatrix / SkScala per default is float instead of double.
Is there a way to set up a transformation with double precision? I found only the following article regarding this topic:

https://groups.google.com/forum/#!topic/skia-discuss/Ie3d-i0PAsM

However it is quite old, so I don't know if it is still valid.

Thanks for any help,
Marco

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

扈马克

unread,
Jan 8, 2018, 10:14:35 AM1/8/18
to skia-discuss

Just off-hand, do you think it would be sufficient for your case if matrix was doubles, but geometries (i.e. paths, rects) were still floats?


Yes, I think it would be sufficient if the matrix was doubles and the geometries float.

 

On Mon, Jan 8, 2018 at 9:16 AM, 'Mike Klein' via skia-discuss <skia-d...@googlegroups.com> wrote:
Back in the days of that post you linked, SkScalar could be either a float or a 16.16 fixed point.  We've since dropped the fixed point option, so it's always float now.

Logically SkScalar could be replaced with a double, but I bet there are many parts of the code base that will assume it's 4 byte, or even exactly a 1-8-23 layout float.  This would be a challenging project.

I believe we still support floats or doubles for SkMatrix44, but that is not the 3x3 matrix (SkMatrix) used by most of the drawing pipeline.
On Mon, Jan 8, 2018 at 8:53 AM 扈马克 <geoh...@gmail.com> wrote:
I'm writing a mapping application with different rendering backends. With skia, I have precision problems when zooming in. I think the reason is that SKMatrix / SkScala per default is float instead of double.
Is there a way to set up a transformation with double precision? I found only the following article regarding this topic:

https://groups.google.com/forum/#!topic/skia-discuss/Ie3d-i0PAsM

However it is quite old, so I don't know if it is still valid.

Thanks for any help,
Marco

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.

扈马克

unread,
Jan 14, 2018, 9:52:26 AM1/14/18
to skia-discuss
Sorry, after doing a few experiments, I have to correct myself. Matrix _and_ geometries would need to be in double.

Mike Reed

unread,
Jan 16, 2018, 9:13:03 AM1/16/18
to skia-d...@googlegroups.com
That was my guess too, that to be valuable everything related to geometry would need to be double.


To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

Dirk Weltz

unread,
Apr 6, 2018, 3:11:28 PM4/6/18
to skia-discuss
I'm facing the same problem.

I work with "huge" values in a map library. They normally between -20 000 000 and +20 000 000. When creating a path and than transform this path, the resulting path "jumps" at high zoom levels. It seems, that I at the precision limit of matrix operations. You could find an example here or here.When I do the same by "hand" with double precision, than there isn't any such effect.

Is there any workaround?

Mike Reed

unread,
Apr 6, 2018, 3:38:08 PM4/6/18
to skia-d...@googlegroups.com
I don't see a way for Skia to honestly support doubles everywhere, given the (perceived) hard-limit on 3D driver apis (e.g. DX, GL, VK) of only using floats for transformations and rasterization.

To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

Shawn Riordan

unread,
Apr 7, 2018, 12:23:38 AM4/7/18
to skia-discuss
Dirk, you might be able to get the SkMatrix version of your engine to work, without re-creating your path everytime.
Try this experiment:

When creating your paths, divide all your coordinate values by 1 million first.  
Which would mean that your maps would range from -20.0 to 20.0.  Instead of from -20000000.0 to 20000000.0.

Then zoom in on the same areas and do your test to look for the swimming you saw before.

Shawn Riordan

unread,
Apr 7, 2018, 12:27:39 AM4/7/18
to skia-discuss
Mike, why can't you do the math using doubles in the matrix and just promote the point float values to doubles -- for the math -- then demote them back back down to float when forming the point result? 

Dirk Weltz

unread,
Apr 7, 2018, 4:41:04 AM4/7/18
to skia-discuss
Thank you, Shawn, for your help, but no, that makes the things only slightly better, but they don't vanish. I tried to bring values in order of screen size.

So it seems, that I have to think about this problem again.

Sebastian Keller

unread,
May 3, 2018, 4:01:52 PM5/3/18
to skia-discuss
Hi Dirk,

did you found a solution for this problem? I'm facing the same issue and currently I'm converting all coordinates 'by hand', but i have to update each path object if the viewport changes.

Sadly it seems like one is not able to edit SKPoints behind an SKPath without copying a new array. An in place edit would be lovely.

Dirk Weltz

unread,
May 3, 2018, 5:19:12 PM5/3/18
to skia-discuss
Hi Sebastian,

no, sorry, I didn‘t find a solution for this problem. Up to now, I create the SKPath new each time before drawing it. It‘s time consuming, but works without artifacts. If you find a better solution, I would be happy, if you could publish it.

Cheers,
Dirk

Sebastian Keller

unread,
May 3, 2018, 5:29:21 PM5/3/18
to skia-d...@googlegroups.com
Hi Dirk,

thanks for the response! Yeah, we pretty much have the same workings...
One trick I've found is to save the SKPath object (allocating this one is fairly expensive) and calling rewind() on it before updating the points.

Rewind will clear all points, but keep the allocated SKPoints buffer. I guess you'll add the same number of points every time, so this safes at least one (big?) allocation when updating the points.


Have a good one,
Sebastian



________________________________________________________

Sebastian Keller

MENTZ GmbH, Grillparzerstr. 18, 81675 München
T:+49 (0)89 4 18 68-179, F:+49 (0)89 4 18 68-160

Sitz der Gesellschaft: Grillparzerstraße 18, 81675 München
Geschäftsführer Christoph Mentz, Amtsgericht München, HRB 91898
________________________________________________________

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages