Debian Codegraph @

tests/auto/render/alignedresourcesmanagers-sse/tst_alignedresourcesmanagers-sse.cpp

raw symbols SCIP
1 // Copyright (C) 2017 Paul Lemire <[email protected]>
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <Qt3DCore/qnodeid.h>
6 #include <Qt3DCore/private/matrix4x4_sse_p.h>
7 #include <Qt3DCore/private/qresourcemanager_p.h>
8 #include <Qt3DRender/private/cameralens_p.h>
9
10 using namespace Qt3DCore;
11
12 using HMatrix = Qt3DCore::QHandle<Matrix4x4_SSE>;
13 using HCameraLens = Qt3DCore::QHandle<Qt3DRender::Render::CameraLens>;
14
15 class MatrixManager : public Qt3DCore::QResourceManager<
16 Matrix4x4_SSE,
17 Qt3DCore::QNodeId,
18 Qt3DCore::NonLockingPolicy>
19 {
20 public:
21 MatrixManager() {}
22 };
23
24 class CameraLensManager : public Qt3DCore::QResourceManager<
25 Qt3DRender::Render::CameraLens,
26 Qt3DCore::QNodeId,
27 Qt3DCore::NonLockingPolicy>
28 {
29 public:
30 CameraLensManager() {}
31 };
32
33
34 class tst_AlignedResourcesManagersSSE: public QObject
35 {
36 Q_OBJECT
37
38 #ifdef __SSE2__
39 private Q_SLOTS:
40
41 void checkAllocationAndAlignmentMatrix4x4()
42 {
43 // GIVEN
44 MatrixManager manager;
45
46 // WHEN
47 for (uint i = 0; i < std::numeric_limits<ushort>::max(); ++i)
48 manager.getOrCreateResource(Qt3DCore::QNodeId::createId());
49
50 // THEN
51 // Shouldn't crash
52
53 const std::vector<HMatrix> &activeHandles = manager.activeHandles();
54 for (const HMatrix &handle : activeHandles) {
55 // WHEN
56 Matrix4x4_SSE *mat = manager.data(handle);
57 // THEN
58 QCOMPARE(int((uintptr_t)mat % 16), 0);
59 }
60
61 // WHEN
62 for (uint i = 2; i < std::numeric_limits<ushort>::max(); ++i) {
63 Matrix4x4_SSE *mat1 = manager.data(activeHandles.at(i - 2));
64 Matrix4x4_SSE *mat2 = manager.data(activeHandles.at(i - 1));
65 Matrix4x4_SSE *mat3 = manager.data(activeHandles.at(i));
66
67 // WHEN
68 *mat3 = (*mat2 * *mat1);
69
70 // THEN
71 // Shouldn't crash
72 }
73 }
74
75 void checkAllocationAndAlignmentCameraLens()
76 {
77 // GIVEN
78 CameraLensManager manager;
79
80 // WHEN
81 for (uint i = 0; i < std::numeric_limits<ushort>::max(); ++i)
82 manager.getOrCreateResource(Qt3DCore::QNodeId::createId());
83
84 // THEN
85 // Shouldn't crash
86
87 const std::vector<HCameraLens> &activeHandles = manager.activeHandles();
88 for (const HCameraLens &handle : activeHandles) {
89 // WHEN
90 Qt3DRender::Render::CameraLens *lens = manager.data(handle);
91 // THEN
92 # ifdef __AVX2__
93 QCOMPARE(int((uintptr_t)lens % 32), 0);
94 # else
95 QCOMPARE(int((uintptr_t)lens % 16), 0);
96 # endif
97 }
98 }
99 #endif // __SSE2__
100 };
101
102 QTEST_MAIN(tst_AlignedResourcesManagersSSE)
103
104 #include "tst_alignedresourcesmanagers-sse.moc"