summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/gui
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2012-08-20 20:55:40 +0100
committerQt by Nokia <qt-info@nokia.com>2012-09-07 13:27:38 +0200
commit51d40d7e9bdfc63c5109aef5b732aa2ba10f985a (patch)
treeffa750956ab2e96e0cd8f02bafa820042aa9f78a /tests/benchmarks/gui
parent56414e2498ae19d305b391678afe3a67a9069832 (diff)
Make gui/math3d classes use float rather than qreal
This corrects the mismatch between using floats for internal storage and qreal in the API of QVector*D which leads to lots of implicit casts between double and float. This change also stops users from being surprised by the loss of precision when using these classes on desktop platforms and removes the need for the private constructors taking a dummy int as the final argument. The QMatrix4x4 and QQuaternion classes have been changed to use float for their internal storage since these are meant to be used in conjunction with the QVector*D classes. This is to prevent unexpected loss of precision and to improve performance. The on-disk format has also been changed from double to float thereby reducing the storage required when streaming vectors and matrices. This is potentially a large saving when working with complex 3D meshes etc. This also has a significant performance improvement when passing matrices to QOpenGLShaderProgram (and QGLShaderProgram) as we no longer have to iterate and convert the data to floats. This is an operation that could easily be needed many times per frame. This change also opens the door for further optimisations of these classes to be implemented by using SIMD intrinsics. This needs to be applied in conjunction with https://codereview.qt-project.org/#change,33548 Task-number: QTBUG-21035 Task-number: QTBUG-20661 Change-Id: I9321b06040ffb93ae1cbd72fd2013267ac901b2e Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/benchmarks/gui')
-rw-r--r--tests/benchmarks/gui/math3d/qmatrix4x4/tst_qmatrix4x4.cpp112
-rw-r--r--tests/benchmarks/gui/math3d/qquaternion/tst_qquaternion.cpp44
2 files changed, 78 insertions, 78 deletions
diff --git a/tests/benchmarks/gui/math3d/qmatrix4x4/tst_qmatrix4x4.cpp b/tests/benchmarks/gui/math3d/qmatrix4x4/tst_qmatrix4x4.cpp
index 9d12d1b055..0e97b989c5 100644
--- a/tests/benchmarks/gui/math3d/qmatrix4x4/tst_qmatrix4x4.cpp
+++ b/tests/benchmarks/gui/math3d/qmatrix4x4/tst_qmatrix4x4.cpp
@@ -96,7 +96,7 @@ private slots:
void compareRotateAfterScale();
};
-static qreal const generalValues[16] =
+static float const generalValues[16] =
{1.0f, 2.0f, 3.0f, 4.0f,
5.0f, 6.0f, 7.0f, 8.0f,
9.0f, 10.0f, 11.0f, 12.0f,
@@ -171,9 +171,9 @@ void tst_QMatrix4x4::multiplyDirect()
QMatrix4x4 m3;
- const qreal *m1data = m1.constData();
- const qreal *m2data = m2.constData();
- qreal *m3data = m3.data();
+ const float *m1data = m1.constData();
+ const float *m2data = m2.constData();
+ float *m3data = m3.data();
QBENCHMARK {
for (int row = 0; row < 4; ++row) {
@@ -266,9 +266,9 @@ void tst_QMatrix4x4::mapVectorDirect()
{
QFETCH(QMatrix4x4, m1);
- const qreal *m1data = m1.constData();
- qreal v[4] = {10.5f, -2.0f, 3.0f, 1.0f};
- qreal result[4];
+ const float *m1data = m1.constData();
+ float v[4] = {10.5f, -2.0f, 3.0f, 1.0f};
+ float result[4];
QBENCHMARK {
for (int row = 0; row < 4; ++row) {
@@ -310,9 +310,9 @@ void tst_QMatrix4x4::compareTranslate()
QFETCH(bool, useQTransform);
QFETCH(QVector3D, translation);
- qreal x = translation.x();
- qreal y = translation.y();
- qreal z = translation.z();
+ float x = translation.x();
+ float y = translation.y();
+ float z = translation.z();
if (useQTransform) {
QTransform t;
@@ -343,9 +343,9 @@ void tst_QMatrix4x4::compareTranslateAfterScale()
QFETCH(bool, useQTransform);
QFETCH(QVector3D, translation);
- qreal x = translation.x();
- qreal y = translation.y();
- qreal z = translation.z();
+ float x = translation.x();
+ float y = translation.y();
+ float z = translation.z();
if (useQTransform) {
QTransform t;
@@ -379,9 +379,9 @@ void tst_QMatrix4x4::compareTranslateAfterRotate()
QFETCH(bool, useQTransform);
QFETCH(QVector3D, translation);
- qreal x = translation.x();
- qreal y = translation.y();
- qreal z = translation.z();
+ float x = translation.x();
+ float y = translation.y();
+ float z = translation.z();
if (useQTransform) {
QTransform t;
@@ -431,9 +431,9 @@ void tst_QMatrix4x4::compareScale()
QFETCH(bool, useQTransform);
QFETCH(QVector3D, scale);
- qreal x = scale.x();
- qreal y = scale.y();
- qreal z = scale.z();
+ float x = scale.x();
+ float y = scale.y();
+ float z = scale.z();
if (useQTransform) {
QTransform t;
@@ -464,9 +464,9 @@ void tst_QMatrix4x4::compareScaleAfterTranslate()
QFETCH(bool, useQTransform);
QFETCH(QVector3D, scale);
- qreal x = scale.x();
- qreal y = scale.y();
- qreal z = scale.z();
+ float x = scale.x();
+ float y = scale.y();
+ float z = scale.z();
if (useQTransform) {
QTransform t;
@@ -500,9 +500,9 @@ void tst_QMatrix4x4::compareScaleAfterRotate()
QFETCH(bool, useQTransform);
QFETCH(QVector3D, scale);
- qreal x = scale.x();
- qreal y = scale.y();
- qreal z = scale.z();
+ float x = scale.x();
+ float y = scale.y();
+ float z = scale.z();
if (useQTransform) {
QTransform t;
@@ -530,65 +530,65 @@ void tst_QMatrix4x4::compareScaleAfterRotate()
void tst_QMatrix4x4::compareRotate_data()
{
QTest::addColumn<bool>("useQTransform");
- QTest::addColumn<qreal>("angle");
+ QTest::addColumn<float>("angle");
QTest::addColumn<QVector3D>("rotation");
QTest::addColumn<int>("axis");
QTest::newRow("QTransform::rotate(0, ZAxis)")
- << true << qreal(0.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis);
+ << true << 0.0f << QVector3D(0, 0, 1) << int(Qt::ZAxis);
QTest::newRow("QMatrix4x4::rotate(0, ZAxis)")
- << false << qreal(0.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis);
+ << false << 0.0f << QVector3D(0, 0, 1) << int(Qt::ZAxis);
QTest::newRow("QTransform::rotate(45, ZAxis)")
- << true << qreal(45.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis);
+ << true << 45.0f << QVector3D(0, 0, 1) << int(Qt::ZAxis);
QTest::newRow("QMatrix4x4::rotate(45, ZAxis)")
- << false << qreal(45.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis);
+ << false << 45.0f << QVector3D(0, 0, 1) << int(Qt::ZAxis);
QTest::newRow("QTransform::rotate(90, ZAxis)")
- << true << qreal(90.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis);
+ << true << 90.0f << QVector3D(0, 0, 1) << int(Qt::ZAxis);
QTest::newRow("QMatrix4x4::rotate(90, ZAxis)")
- << false << qreal(90.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis);
+ << false << 90.0f << QVector3D(0, 0, 1) << int(Qt::ZAxis);
QTest::newRow("QTransform::rotate(0, YAxis)")
- << true << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis);
+ << true << 0.0f << QVector3D(0, 1, 0) << int(Qt::YAxis);
QTest::newRow("QMatrix4x4::rotate(0, YAxis)")
- << false << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis);
+ << false << 0.0f << QVector3D(0, 1, 0) << int(Qt::YAxis);
QTest::newRow("QTransform::rotate(45, YAxis)")
- << true << qreal(45.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis);
+ << true << 45.0f << QVector3D(0, 1, 0) << int(Qt::YAxis);
QTest::newRow("QMatrix4x4::rotate(45, YAxis)")
- << false << qreal(45.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis);
+ << false << 45.0f << QVector3D(0, 1, 0) << int(Qt::YAxis);
QTest::newRow("QTransform::rotate(90, YAxis)")
- << true << qreal(90.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis);
+ << true << 90.0f << QVector3D(0, 1, 0) << int(Qt::YAxis);
QTest::newRow("QMatrix4x4::rotate(90, YAxis)")
- << false << qreal(90.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis);
+ << false << 90.0f << QVector3D(0, 1, 0) << int(Qt::YAxis);
QTest::newRow("QTransform::rotate(0, XAxis)")
- << true << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::XAxis);
+ << true << 0.0f << QVector3D(0, 1, 0) << int(Qt::XAxis);
QTest::newRow("QMatrix4x4::rotate(0, XAxis)")
- << false << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::XAxis);
+ << false << 0.0f << QVector3D(0, 1, 0) << int(Qt::XAxis);
QTest::newRow("QTransform::rotate(45, XAxis)")
- << true << qreal(45.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis);
+ << true << 45.0f << QVector3D(1, 0, 0) << int(Qt::XAxis);
QTest::newRow("QMatrix4x4::rotate(45, XAxis)")
- << false << qreal(45.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis);
+ << false << 45.0f << QVector3D(1, 0, 0) << int(Qt::XAxis);
QTest::newRow("QTransform::rotate(90, XAxis)")
- << true << qreal(90.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis);
+ << true << 90.0f << QVector3D(1, 0, 0) << int(Qt::XAxis);
QTest::newRow("QMatrix4x4::rotate(90, XAxis)")
- << false << qreal(90.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis);
+ << false << 90.0f << QVector3D(1, 0, 0) << int(Qt::XAxis);
}
void tst_QMatrix4x4::compareRotate()
{
QFETCH(bool, useQTransform);
- QFETCH(qreal, angle);
+ QFETCH(float, angle);
QFETCH(QVector3D, rotation);
QFETCH(int, axis);
- qreal x = rotation.x();
- qreal y = rotation.y();
- qreal z = rotation.z();
+ float x = rotation.x();
+ float y = rotation.y();
+ float z = rotation.z();
if (useQTransform) {
QTransform t;
@@ -612,13 +612,13 @@ void tst_QMatrix4x4::compareRotateAfterTranslate_data()
void tst_QMatrix4x4::compareRotateAfterTranslate()
{
QFETCH(bool, useQTransform);
- QFETCH(qreal, angle);
+ QFETCH(float, angle);
QFETCH(QVector3D, rotation);
QFETCH(int, axis);
- qreal x = rotation.x();
- qreal y = rotation.y();
- qreal z = rotation.z();
+ float x = rotation.x();
+ float y = rotation.y();
+ float z = rotation.z();
if (useQTransform) {
QTransform t;
@@ -644,13 +644,13 @@ void tst_QMatrix4x4::compareRotateAfterScale_data()
void tst_QMatrix4x4::compareRotateAfterScale()
{
QFETCH(bool, useQTransform);
- QFETCH(qreal, angle);
+ QFETCH(float, angle);
QFETCH(QVector3D, rotation);
QFETCH(int, axis);
- qreal x = rotation.x();
- qreal y = rotation.y();
- qreal z = rotation.z();
+ float x = rotation.x();
+ float y = rotation.y();
+ float z = rotation.z();
if (useQTransform) {
QTransform t;
diff --git a/tests/benchmarks/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/benchmarks/gui/math3d/qquaternion/tst_qquaternion.cpp
index 6ab473e1b4..e47fdccaae 100644
--- a/tests/benchmarks/gui/math3d/qquaternion/tst_qquaternion.cpp
+++ b/tests/benchmarks/gui/math3d/qquaternion/tst_qquaternion.cpp
@@ -77,38 +77,38 @@ void tst_QQuaternion::cleanup()
void tst_QQuaternion::multiply_data()
{
- QTest::addColumn<qreal>("x1");
- QTest::addColumn<qreal>("y1");
- QTest::addColumn<qreal>("z1");
- QTest::addColumn<qreal>("w1");
- QTest::addColumn<qreal>("x2");
- QTest::addColumn<qreal>("y2");
- QTest::addColumn<qreal>("z2");
- QTest::addColumn<qreal>("w2");
+ QTest::addColumn<float>("x1");
+ QTest::addColumn<float>("y1");
+ QTest::addColumn<float>("z1");
+ QTest::addColumn<float>("w1");
+ QTest::addColumn<float>("x2");
+ QTest::addColumn<float>("y2");
+ QTest::addColumn<float>("z2");
+ QTest::addColumn<float>("w2");
QTest::newRow("null")
- << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f
- << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f;
+ << 0.0f << 0.0f << 0.0f << 0.0f
+ << 0.0f << 0.0f << 0.0f << 0.0f;
QTest::newRow("unitvec")
- << (qreal)1.0f << (qreal)0.0f << (qreal)0.0f << (qreal)1.0f
- << (qreal)0.0f << (qreal)1.0f << (qreal)0.0f << (qreal)1.0f;
+ << 1.0f << 0.0f << 0.0f << 1.0f
+ << 0.0f << 1.0f << 0.0f << 1.0f;
QTest::newRow("complex")
- << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)7.0f
- << (qreal)4.0f << (qreal)5.0f << (qreal)6.0f << (qreal)8.0f;
+ << 1.0f << 2.0f << 3.0f << 7.0f
+ << 4.0f << 5.0f << 6.0f << 8.0f;
}
void tst_QQuaternion::multiply()
{
- QFETCH(qreal, x1);
- QFETCH(qreal, y1);
- QFETCH(qreal, z1);
- QFETCH(qreal, w1);
- QFETCH(qreal, x2);
- QFETCH(qreal, y2);
- QFETCH(qreal, z2);
- QFETCH(qreal, w2);
+ QFETCH(float, x1);
+ QFETCH(float, y1);
+ QFETCH(float, z1);
+ QFETCH(float, w1);
+ QFETCH(float, x2);
+ QFETCH(float, y2);
+ QFETCH(float, z2);
+ QFETCH(float, w2);
QQuaternion q1(w1, x1, y1, z1);
QQuaternion q2(w2, x2, y2, z2);