Keith Gardner | 19 Aug 20:35 2011

Question about QVector2D, QVector3D, QVector4D, etc...

I noticed that QVector2D, QVector3D, QVector4D, etc… use floats as the storage type and I recognize that it was a performance decision to do it this way.  I am just wondering why the getters and setters for the structures use qreal as the parameter type instead of floats.

 

I know that on a mobile system qreal is a float, but on desktop systems qreal is a double.  I would like to use these data structures but the conversion from double to float only to be accessed as a double again seems to be overly expensive.

 

In Qt5, would it be possible to have the function parameters take a floats instead of a qreals?

 

Thanks,

Keith

_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
gunnar.sletta | 19 Aug 20:46 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...


On Aug 19, 2011, at 8:35 PM, ext Keith Gardner wrote:

> I noticed that QVector2D, QVector3D, QVector4D, etc… use floats as the storage type and I recognize
that it was a performance decision to do it this way.  I am just wondering why the getters and setters for the
structures use qreal as the parameter type instead of floats.
>  
> I know that on a mobile system qreal is a float, but on desktop systems qreal is a double.  I would like to use
these data structures but the conversion from double to float only to be accessed as a double again seems to
be overly expensive.
>  
> In Qt5, would it be possible to have the function parameters take a floats instead of a qreals?

I think that is a very good idea. Could you make a suggestion about that on the Qt bugtracker?

In general, we have discussed dropping the concept of qreal and sticking to the native C++ types. It is a pain
to develop something on desktop and have the sizeof(qreal) change behind the scenes or to have an
algorithm you developed suddenly become numerically unstable when ported to device. We've been
thinking it is better to be explicit.

For most of graphics floats is the "right" choice as it maps directly to OpenGL, is storage-wise efficient
and quality-wise precise enough. Then for the cases where precision is very important, we should
explicitly use double. 

best regards,
Gunnar
Keith Gardner | 19 Aug 21:31 2011

Re: Question about QVector2D, QVector3D, QVector4D, etc...

Thanks for the quick response.  It is now QTBUG-21035.

Keith

-----Original Message-----
From: gunnar.sletta <at> nokia.com [mailto:gunnar.sletta <at> nokia.com] 
Sent: Friday, August 19, 2011 1:47 PM
To: Keith Gardner
Cc: qt5-feedback <at> qt.nokia.com
Subject: Re: [Qt5-feedback] Question about QVector2D, QVector3D, QVector4D, etc...

On Aug 19, 2011, at 8:35 PM, ext Keith Gardner wrote:

> I noticed that QVector2D, QVector3D, QVector4D, etc... use floats as the storage type and I recognize
that it was a performance decision to do it this way.  I am just wondering why the getters and setters for the
structures use qreal as the parameter type instead of floats.
>  
> I know that on a mobile system qreal is a float, but on desktop systems qreal is a double.  I would like to use
these data structures but the conversion from double to float only to be accessed as a double again seems to
be overly expensive.
>  
> In Qt5, would it be possible to have the function parameters take a floats instead of a qreals?

I think that is a very good idea. Could you make a suggestion about that on the Qt bugtracker?

In general, we have discussed dropping the concept of qreal and sticking to the native C++ types. It is a pain
to develop something on desktop and have the sizeof(qreal) change behind the scenes or to have an
algorithm you developed suddenly become numerically unstable when ported to device. We've been
thinking it is better to be explicit.

For most of graphics floats is the "right" choice as it maps directly to OpenGL, is storage-wise efficient
and quality-wise precise enough. Then for the cases where precision is very important, we should
explicitly use double. 

best regards,
Gunnar
Thiago Macieira | 20 Aug 00:49 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...

On Friday, 19 de August de 2011 20:46:32 gunnar.sletta <at> nokia.com wrote:
> In general, we have discussed dropping the concept of qreal and sticking to
> the native C++ types. It is a pain to develop something on desktop and have
> the sizeof(qreal) change behind the scenes or to have an algorithm you
> developed suddenly become numerically unstable when ported to device. We've
> been thinking it is better to be explicit.

Every time I meet someone from Canonical, they also ask me to drop the 
distinction.

The following code usually works fine on the desktop:

	qMax(1.0, someQRealFunction());

but on embedded platforms with qreal==float, it breaks. Sure, we can fix it for 
qMin, qMax, qBound, but there are plenty more template functions to be fixed.

Unfortunately, the argument to the contrary is that double-precision floating 
point on the ARM Cortex-A8 is still much worse than single-precision -- it's 
even worse than on ARM11. Only on the A9 is the performance acceptable.

--

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
gunnar.sletta | 20 Aug 08:16 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...


On Aug 20, 2011, at 12:49 AM, ext Thiago Macieira wrote:

> On Friday, 19 de August de 2011 20:46:32 gunnar.sletta <at> nokia.com wrote:
>> In general, we have discussed dropping the concept of qreal and sticking to
>> the native C++ types. It is a pain to develop something on desktop and have
>> the sizeof(qreal) change behind the scenes or to have an algorithm you
>> developed suddenly become numerically unstable when ported to device. We've
>> been thinking it is better to be explicit.
> 
> Every time I meet someone from Canonical, they also ask me to drop the 
> distinction.
> 
> The following code usually works fine on the desktop:
> 
> 	qMax(1.0, someQRealFunction());
> 
> but on embedded platforms with qreal==float, it breaks.

I have lost count on how many times I've had to fix this :)

> Sure, we can fix it for 
> qMin, qMax, qBound, but there are plenty more template functions to be fixed.
> 
> Unfortunately, the argument to the contrary is that double-precision floating 
> point on the ARM Cortex-A8 is still much worse than single-precision -- it's 
> even worse than on ARM11. Only on the A9 is the performance acceptable.
> 

I would think this is fine though, double will be used so seldom that in practice it won't impact performance much.

Both QML Scene Graph and Qt3D use primarily floats for the vertex data and other parameters, for instance.

-
Gunnar
Thiago Macieira | 20 Aug 12:04 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...

On Saturday, 20 de August de 2011 08:16:45 gunnar.sletta <at> nokia.com wrote:
> > Unfortunately, the argument to the contrary is that double-precision
> > floating point on the ARM Cortex-A8 is still much worse than
> > single-precision -- it's even worse than on ARM11. Only on the A9 is the
> > performance acceptable.
> I would think this is fine though, double will be used so seldom that in
> practice it won't impact performance much.
> 
> Both QML Scene Graph and Qt3D use primarily floats for the vertex data and
> other parameters, for instance.

Which is good, that's where the math is concentrated. Using doubles for 
parameter passing isn't a big deal, however, provided a "hard float" approach 
is used (passing parameters in registers). Loading and storing, converting to 
single precision, etc., shouldn't take too much time, not much worse than float 
itself.

The difficulty lies in writing single-precision code, as C and C++ have an 
automatic promotion to double. More difficult than that is to write code that 
operates on shorts, since promotion to int happens even more easily.

--

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Giuseppe D'Angelo | 20 Aug 14:09 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...

On Fri, Aug 19, 2011 at 8:35 PM, Keith Gardner
<kgardner <at> zebraimaging.com> wrote:
> I noticed that QVector2D, QVector3D, QVector4D, etc… use floats as the
> storage type and I recognize that it was a performance decision to do it
> this way.  I am just wondering why the getters and setters for the
> structures use qreal as the parameter type instead of floats.

And OTOH QMatrix4x4 uses qreal internally, leading to conversions
to/from OpenGL's GLfloat when qreal == double.
Cf. http://qt.gitorious.org/qt/qt/blobs/master/src/opengl/qglshaderprogram.cpp#line2188
Do you think it's worth to port it to float as well?
--

-- 
Giuseppe D'Angelo
_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Sean Harmer | 20 Aug 15:15 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...

On 20/08/2011 13:09, Giuseppe D'Angelo wrote:
> On Fri, Aug 19, 2011 at 8:35 PM, Keith Gardner
> <kgardner <at> zebraimaging.com>  wrote:
>> I noticed that QVector2D, QVector3D, QVector4D, etc… use floats as the
>> storage type and I recognize that it was a performance decision to do it
>> this way.  I am just wondering why the getters and setters for the
>> structures use qreal as the parameter type instead of floats.
> And OTOH QMatrix4x4 uses qreal internally, leading to conversions
> to/from OpenGL's GLfloat when qreal == double.
> Cf. http://qt.gitorious.org/qt/qt/blobs/master/src/opengl/qglshaderprogram.cpp#line2188
> Do you think it's worth to port it to float as well?

Or perhaps templatise it? Or use Eigen instead to save some work?

Cheers,

Sean

--

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Tom Cooksey | 5 Sep 19:41 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...


While on the subject, it would be great if QVector* and QMatrix* internal formats could be made to map to NEON intrinsic built-ins too so operations could be implemented with vectorized instructions. I guess that would also apply to SIMD on other processor architectures too...


On Sat, Aug 20, 2011 at 2:15 PM, Sean Harmer <sh <at> theharmers.co.uk> wrote:
On 20/08/2011 13:09, Giuseppe D'Angelo wrote:
> On Fri, Aug 19, 2011 at 8:35 PM, Keith Gardner
> <kgardner <at> zebraimaging.com>  wrote:
>> I noticed that QVector2D, QVector3D, QVector4D, etc… use floats as the
>> storage type and I recognize that it was a performance decision to do it
>> this way.  I am just wondering why the getters and setters for the
>> structures use qreal as the parameter type instead of floats.
> And OTOH QMatrix4x4 uses qreal internally, leading to conversions
> to/from OpenGL's GLfloat when qreal == double.
> Cf. http://qt.gitorious.org/qt/qt/blobs/master/src/opengl/qglshaderprogram.cpp#line2188
> Do you think it's worth to port it to float as well?

Or perhaps templatise it? Or use Eigen instead to save some work?

Cheers,

Sean

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback

_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
lars.knoll | 5 Sep 22:31 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...

Hi Tom,

On 9/5/11 7:41 PM, "ext Tom Cooksey" <tomcooksey <at> gmail.com> wrote:
>While on the subject, it would be great if QVector* and QMatrix* internal
>formats could be made to map to NEON intrinsic built-ins too so
>operations could be implemented with vectorized instructions. I guess
>that would also apply to SIMD on other processor architectures too...

I'm looking forward to a patch here :)

Cheers,
Lars

>
>
>
>On Sat, Aug 20, 2011 at 2:15 PM, Sean Harmer <sh <at> theharmers.co.uk> wrote:
>
>On 20/08/2011 13:09, Giuseppe D'Angelo wrote:
>> On Fri, Aug 19, 2011 at 8:35 PM, Keith Gardner
>> <kgardner <at> zebraimaging.com>  wrote:
>>> I noticed that QVector2D, QVector3D, QVector4D, etcŠ use floats as the
>>> storage type and I recognize that it was a performance decision to do
>>>it
>>> this way.  I am just wondering why the getters and setters for the
>>> structures use qreal as the parameter type instead of floats.
>> And OTOH QMatrix4x4 uses qreal internally, leading to conversions
>> to/from OpenGL's GLfloat when qreal == double.
>> Cf. 
>>http://qt.gitorious.org/qt/qt/blobs/master/src/opengl/qglshaderprogram.cp
>>p#line2188
>> Do you think it's worth to port it to float as well?
>
>
>Or perhaps templatise it? Or use Eigen instead to save some work?
>
>Cheers,
>
>Sean
>
>--
>This message has been scanned for viruses and
>dangerous content by MailScanner, and is
>believed to be clean.
>
>_______________________________________________
>Qt5-feedback mailing list
>Qt5-feedback <at> qt.nokia.com
>http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
>
>
>
>
>
>
>
Konstantin Tokarev | 5 Sep 22:35 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...

05.09.2011, 21:41, "Tom Cooksey" <tomcooksey <at> gmail.com>:
> While on the subject, it would be great if QVector* and QMatrix* internal formats could be made to map to
NEON intrinsic built-ins too so operations could be implemented with vectorized instructions. I guess
that would also apply to SIMD on other processor architectures too...

You can use Eigen. It supports NEON, SSE[2-4], and Altivec vectorization

--

-- 
Regards,
Konstantin
Keith Gardner | 6 Sep 01:27 2011

Re: Question about QVector2D, QVector3D, QVector4D, etc...

A library that we use is GLM (OpenGL Mathematics http://glm.g-truc.net/).  We have found this library to be very efficient and it is only header files.

Keith Gardner
Software Engineer
Zebra Imaging
9801 Metric Blvd., Suite 200
Austin, TX 78758
Office: 512-583-0677

On Sep 5, 2011, at 3:35 PM, Konstantin Tokarev wrote:

05.09.2011, 21:41, "Tom Cooksey" <tomcooksey <at> gmail.com>:
While on the subject, it would be great if QVector* and QMatrix* internal formats could be made to map to NEON intrinsic built-ins too so operations could be implemented with vectorized instructions. I guess that would also apply to SIMD on other processor architectures too...

You can use Eigen. It supports NEON, SSE[2-4], and Altivec vectorization

--
Regards,
Konstantin
_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback

_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Thiago Macieira | 5 Sep 23:39 2011
Picon

Re: Question about QVector2D, QVector3D, QVector4D, etc...

On Monday, 5 de September de 2011 18:41:08 Tom Cooksey wrote:
> While on the subject, it would be great if QVector* and QMatrix* internal
> formats could be made to map to NEON intrinsic built-ins too so operations
> could be implemented with vectorized instructions. I guess that would also
> apply to SIMD on other processor architectures too...

Can you be more specific? What's wrong with the internal format as it is?

Aside from not adding Q_DECL_ALIGNED(16).

--

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
_______________________________________________
Qt5-feedback mailing list
Qt5-feedback <at> qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback

Gmane