| 1 | /**************************************************************************** | 
|---|---|
| 2 | ** | 
| 3 | ** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com> | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 | |
| 29 | #include <QtTest/QtTest> | 
| 30 | #include <Qt3DCore/qnodeid.h> | 
| 31 | #include <Qt3DCore/private/matrix4x4_sse_p.h> | 
| 32 | #include <Qt3DCore/private/qresourcemanager_p.h> | 
| 33 | #include <Qt3DRender/private/cameralens_p.h> | 
| 34 | |
| 35 | using namespace Qt3DCore; | 
| 36 | |
| 37 | using HMatrix = Qt3DCore::QHandle<Matrix4x4_SSE>; | 
| 38 | using HCameraLens = Qt3DCore::QHandle<Qt3DRender::Render::CameraLens>; | 
| 39 | |
| 40 | class MatrixManager : public Qt3DCore::QResourceManager< | 
| 41 | Matrix4x4_SSE, | 
| 42 | Qt3DCore::QNodeId, | 
| 43 | Qt3DCore::NonLockingPolicy> | 
| 44 | { | 
| 45 | public: | 
| 46 | MatrixManager() {} | 
| 47 | }; | 
| 48 | |
| 49 | class CameraLensManager : public Qt3DCore::QResourceManager< | 
| 50 | Qt3DRender::Render::CameraLens, | 
| 51 | Qt3DCore::QNodeId, | 
| 52 | Qt3DCore::NonLockingPolicy> | 
| 53 | { | 
| 54 | public: | 
| 55 | CameraLensManager() {} | 
| 56 | }; | 
| 57 | |
| 58 | |
| 59 | class tst_AlignedResourcesManagersSSE: public QObject | 
| 60 | { | 
| 61 | Q_OBJECT | 
| 62 | |
| 63 | private Q_SLOTS: | 
| 64 | |
| 65 | void checkAllocationAndAlignmentMatrix4x4() | 
| 66 | { | 
| 67 | // GIVEN | 
| 68 | MatrixManager manager; | 
| 69 | |
| 70 | // WHEN | 
| 71 | for (uint i = 0; i < std::numeric_limits<ushort>::max(); ++i) | 
| 72 | manager.getOrCreateResource(id: Qt3DCore::QNodeId::createId()); | 
| 73 | |
| 74 | // THEN | 
| 75 | // Shouldn't crash | 
| 76 | |
| 77 | const std::vector<HMatrix> &activeHandles = manager.activeHandles(); | 
| 78 | for (const HMatrix handle : activeHandles) { | 
| 79 | // WHEN | 
| 80 | Matrix4x4_SSE *mat = manager.data(handle); | 
| 81 | // THEN | 
| 82 | QCOMPARE(int((uintptr_t)mat % 16), 0); | 
| 83 | } | 
| 84 | |
| 85 | // WHEN | 
| 86 | for (uint i = 2; i < std::numeric_limits<ushort>::max(); ++i) { | 
| 87 | Matrix4x4_SSE *mat1 = manager.data(handle: activeHandles.at(n: i - 2)); | 
| 88 | Matrix4x4_SSE *mat2 = manager.data(handle: activeHandles.at(n: i - 1)); | 
| 89 | Matrix4x4_SSE *mat3 = manager.data(handle: activeHandles.at(n: i)); | 
| 90 | |
| 91 | // WHEN | 
| 92 | *mat3 = (*mat2 * *mat1); | 
| 93 | |
| 94 | // THEN | 
| 95 | // Shouldn't crash | 
| 96 | } | 
| 97 | } | 
| 98 | |
| 99 | void checkAllocationAndAlignmentCameraLens() | 
| 100 | { | 
| 101 | // GIVEN | 
| 102 | CameraLensManager manager; | 
| 103 | |
| 104 | // WHEN | 
| 105 | for (uint i = 0; i < std::numeric_limits<ushort>::max(); ++i) | 
| 106 | manager.getOrCreateResource(id: Qt3DCore::QNodeId::createId()); | 
| 107 | |
| 108 | // THEN | 
| 109 | // Shouldn't crash | 
| 110 | |
| 111 | const std::vector<HCameraLens> &activeHandles = manager.activeHandles(); | 
| 112 | for (const HCameraLens handle : activeHandles) { | 
| 113 | // WHEN | 
| 114 | Qt3DRender::Render::CameraLens *lens = manager.data(handle); | 
| 115 | // THEN | 
| 116 | QCOMPARE(int((uintptr_t)lens % 16), 0); | 
| 117 | } | 
| 118 | } | 
| 119 | }; | 
| 120 | |
| 121 | QTEST_MAIN(tst_AlignedResourcesManagersSSE) | 
| 122 | |
| 123 | #include "tst_alignedresourcesmanagers-sse.moc" | 
| 124 | 
