1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Synchronization tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktSynchronizationTests.hpp"
25 #include "vktTestGroupUtil.hpp"
26 #include "vktSynchronizationSmokeTests.hpp"
27 #include "vktSynchronizationBasicFenceTests.hpp"
28 #include "vktSynchronizationBasicSemaphoreTests.hpp"
29 #include "vktSynchronizationBasicEventTests.hpp"
30 #include "vktSynchronizationOperationSingleQueueTests.hpp"
31 #include "vktSynchronizationOperationMultiQueueTests.hpp"
32 #include "vktSynchronizationInternallySynchronizedObjectsTests.hpp"
33 #include "vktSynchronizationCrossInstanceSharingTests.hpp"
34 #include "vktSynchronizationSignalOrderTests.hpp"
35 #include "vktSynchronizationTimelineSemaphoreTests.hpp"
36 #include "vktSynchronizationWin32KeyedMutexTests.hpp"
37 #include "vktSynchronizationNoneStageTests.hpp"
38 #include "vktSynchronizationUtil.hpp"
39 #include "vktSynchronizationImageLayoutTransitionTests.hpp"
40 #include "vktGlobalPriorityQueueTests.hpp"
41 
42 #include "deUniquePtr.hpp"
43 
44 namespace vkt
45 {
46 namespace synchronization
47 {
48 
49 namespace
50 {
51 
createBasicTests(tcu::TestContext & testCtx,SynchronizationType type,VideoCodecOperationFlags videoCodecOperation)52 tcu::TestCaseGroup *createBasicTests(tcu::TestContext &testCtx, SynchronizationType type,
53                                      VideoCodecOperationFlags videoCodecOperation)
54 {
55     de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "basic"));
56 
57     if (type == SynchronizationType::LEGACY)
58     {
59         group->addChild(createBasicEventTests(testCtx, videoCodecOperation));
60         group->addChild(createBasicFenceTests(testCtx, videoCodecOperation));
61     }
62     else
63     {
64         group->addChild(createSynchronization2BasicEventTests(testCtx, videoCodecOperation));
65     }
66 
67     group->addChild(createBasicBinarySemaphoreTests(testCtx, type, videoCodecOperation));
68     group->addChild(createBasicTimelineSemaphoreTests(testCtx, type, videoCodecOperation));
69 
70     return group.release();
71 }
72 
73 class OperationTests : public tcu::TestCaseGroup
74 {
75 public:
OperationTests(tcu::TestContext & testCtx,SynchronizationType type)76     OperationTests(tcu::TestContext &testCtx, SynchronizationType type)
77         : tcu::TestCaseGroup(testCtx, "op")
78         , m_type(type)
79     {
80     }
81 
init(void)82     void init(void)
83     {
84         addChild(createSynchronizedOperationSingleQueueTests(m_testCtx, m_type, m_pipelineCacheData));
85         addChild(createSynchronizedOperationMultiQueueTests(m_testCtx, m_type, m_pipelineCacheData));
86     }
87 
88 private:
89     SynchronizationType m_type;
90 
91     // synchronization.op tests share pipeline cache data to speed up test execution.
92     PipelineCacheData m_pipelineCacheData;
93 };
94 
getGroupName(SynchronizationType type,const std::string & name,VideoCodecOperationFlags videoCodecOperation)95 const std::pair<std::string, std::string> getGroupName(SynchronizationType type, const std::string &name,
96                                                        VideoCodecOperationFlags videoCodecOperation)
97 {
98     if (videoCodecOperation == 0)
99     {
100         const bool isSynchronization2(type == SynchronizationType::SYNCHRONIZATION2);
101         const char *groupDescription[]{"Synchronization tests", "VK_KHR_synchronization2 tests"};
102 
103         return std::pair<std::string, std::string>(name, groupDescription[isSynchronization2]);
104     }
105 
106 #ifndef CTS_USES_VULKANSC
107     return std::pair<std::string, std::string>(name, "");
108 #else
109     TCU_THROW(InternalError, "Video support is not implemented in Vulkan SC");
110 #endif
111 }
112 
createTestsInternal(tcu::TestContext & testCtx,SynchronizationType type,const std::string & name,VideoCodecOperationFlags videoCodecOperation)113 tcu::TestCaseGroup *createTestsInternal(tcu::TestContext &testCtx, SynchronizationType type, const std::string &name,
114                                         VideoCodecOperationFlags videoCodecOperation)
115 {
116     const bool isSynchronization2(type == SynchronizationType::SYNCHRONIZATION2);
117     const std::pair<std::string, std::string> groupName = getGroupName(type, name, videoCodecOperation);
118 
119     de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, groupName.first.c_str()));
120 
121     if (videoCodecOperation == 0)
122     {
123         if (isSynchronization2)
124         {
125             testGroup->addChild(createSynchronization2SmokeTests(testCtx));
126             testGroup->addChild(createSynchronization2TimelineSemaphoreTests(testCtx));
127 #ifndef CTS_USES_VULKANSC
128             testGroup->addChild(createNoneStageTests(testCtx));
129 #endif // CTS_USES_VULKANSC
130             testGroup->addChild(createImageLayoutTransitionTests(testCtx));
131         }
132         else // legacy synchronization
133         {
134             testGroup->addChild(createSmokeTests(testCtx));
135             testGroup->addChild(createTimelineSemaphoreTests(testCtx));
136 
137             testGroup->addChild(createInternallySynchronizedObjects(testCtx));
138 #ifndef CTS_USES_VULKANSC
139             testGroup->addChild(createWin32KeyedMutexTest(testCtx));
140             testGroup->addChild(createGlobalPriorityQueueTests(testCtx));
141 #endif // CTS_USES_VULKANSC
142         }
143     }
144 
145     testGroup->addChild(createBasicTests(testCtx, type, videoCodecOperation));
146 
147     if (videoCodecOperation == 0)
148     {
149         testGroup->addChild(new OperationTests(testCtx, type));
150 #ifndef CTS_USES_VULKANSC
151         testGroup->addChild(createCrossInstanceSharingTest(testCtx, type));
152         testGroup->addChild(createSignalOrderTests(testCtx, type));
153 #endif // CTS_USES_VULKANSC
154     }
155 
156     return testGroup.release();
157 }
158 } // namespace
159 
160 } // namespace synchronization
161 
createSynchronizationTests(tcu::TestContext & testCtx,const std::string & name)162 tcu::TestCaseGroup *createSynchronizationTests(tcu::TestContext &testCtx, const std::string &name)
163 {
164     return createSynchronizationTests(testCtx, name, 0u);
165 }
166 
createSynchronization2Tests(tcu::TestContext & testCtx,const std::string & name)167 tcu::TestCaseGroup *createSynchronization2Tests(tcu::TestContext &testCtx, const std::string &name)
168 {
169     return createSynchronization2Tests(testCtx, name, 0u);
170 }
171 
createSynchronizationTests(tcu::TestContext & testCtx,const std::string & name,synchronization::VideoCodecOperationFlags videoCodecOperation)172 tcu::TestCaseGroup *createSynchronizationTests(tcu::TestContext &testCtx, const std::string &name,
173                                                synchronization::VideoCodecOperationFlags videoCodecOperation)
174 {
175     using namespace synchronization;
176 
177     de::MovePtr<tcu::TestCaseGroup> testGroup(
178         createTestsInternal(testCtx, SynchronizationType::LEGACY, name, videoCodecOperation));
179 
180     return testGroup.release();
181 }
182 
createSynchronization2Tests(tcu::TestContext & testCtx,const std::string & name,synchronization::VideoCodecOperationFlags videoCodecOperation)183 tcu::TestCaseGroup *createSynchronization2Tests(tcu::TestContext &testCtx, const std::string &name,
184                                                 synchronization::VideoCodecOperationFlags videoCodecOperation)
185 {
186     using namespace synchronization;
187 
188     de::MovePtr<tcu::TestCaseGroup> testGroup(
189         createTestsInternal(testCtx, SynchronizationType::SYNCHRONIZATION2, name, videoCodecOperation));
190 
191     return testGroup.release();
192 }
193 
194 } // namespace vkt
195