Merge vk-gl-cts/aosp-deqp-dev into vk-gl-cts/master
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / vktTestPackage.cpp
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 Google 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 Vulkan Test Package
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktTestPackage.hpp"
25
26 #include "tcuPlatform.hpp"
27 #include "tcuTestCase.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuCommandLine.hpp"
30
31 #include "vkPlatform.hpp"
32 #include "vkPrograms.hpp"
33 #include "vkBinaryRegistry.hpp"
34 #include "vkGlslToSpirV.hpp"
35 #include "vkDebugReportUtil.hpp"
36 #include "vkQueryUtil.hpp"
37
38 #include "deUniquePtr.hpp"
39
40 #include "vktTestGroupUtil.hpp"
41 #include "vktApiTests.hpp"
42 #include "vktPipelineTests.hpp"
43 #include "vktBindingModelTests.hpp"
44 #include "vktSpvAsmTests.hpp"
45 #include "vktShaderLibrary.hpp"
46 #include "vktRenderPassTests.hpp"
47 #include "vktMemoryTests.hpp"
48 #include "vktShaderRenderBuiltinVarTests.hpp"
49 #include "vktShaderRenderDerivateTests.hpp"
50 #include "vktShaderRenderDiscardTests.hpp"
51 #include "vktShaderRenderIndexingTests.hpp"
52 #include "vktShaderRenderLoopTests.hpp"
53 #include "vktShaderRenderMatrixTests.hpp"
54 #include "vktShaderRenderOperatorTests.hpp"
55 #include "vktShaderRenderReturnTests.hpp"
56 #include "vktShaderRenderStructTests.hpp"
57 #include "vktShaderRenderSwitchTests.hpp"
58 #include "vktShaderRenderTextureFunctionTests.hpp"
59 #include "vktShaderRenderTextureGatherTests.hpp"
60 #include "vktShaderBuiltinTests.hpp"
61 #include "vktOpaqueTypeIndexingTests.hpp"
62 #include "vktAtomicOperationTests.hpp"
63 #include "vktUniformBlockTests.hpp"
64 #include "vktDynamicStateTests.hpp"
65 #include "vktSSBOLayoutTests.hpp"
66 #include "vktQueryPoolTests.hpp"
67 #include "vktDrawTests.hpp"
68 #include "vktComputeTests.hpp"
69 #include "vktImageTests.hpp"
70 #include "vktInfoTests.hpp"
71 #include "vktWsiTests.hpp"
72 #include "vktSynchronizationTests.hpp"
73 #include "vktSparseResourcesTests.hpp"
74 #include "vktTessellationTests.hpp"
75 #include "vktRasterizationTests.hpp"
76 #include "vktClippingTests.hpp"
77 #include "vktFragmentOperationsTests.hpp"
78 #include "vktTextureTests.hpp"
79 #include "vktGeometryTests.hpp"
80 #include "vktRobustnessTests.hpp"
81 #include "vktYCbCrTests.hpp"
82
83 #include <vector>
84 #include <sstream>
85
86 namespace // compilation
87 {
88
89 vk::ProgramBinary* compileProgram (const vk::GlslSource& source, glu::ShaderProgramInfo* buildInfo)
90 {
91         return vk::buildProgram(source, buildInfo);
92 }
93
94 vk::ProgramBinary* compileProgram (const vk::SpirVAsmSource& source, vk::SpirVProgramInfo* buildInfo)
95 {
96         return vk::assembleProgram(source, buildInfo);
97 }
98
99 template <typename InfoType, typename IteratorType>
100 vk::ProgramBinary* buildProgram (const std::string&                                     casePath,
101                                                                  IteratorType                                           iter,
102                                                                  const vk::BinaryRegistryReader&        prebuiltBinRegistry,
103                                                                  tcu::TestLog&                                          log,
104                                                                  vk::BinaryCollection*                          progCollection)
105 {
106         const vk::ProgramIdentifier             progId          (casePath, iter.getName());
107         const tcu::ScopedLogSection             progSection     (log, iter.getName(), "Program: " + iter.getName());
108         de::MovePtr<vk::ProgramBinary>  binProg;
109         InfoType                                                buildInfo;
110
111         try
112         {
113                 binProg = de::MovePtr<vk::ProgramBinary>(compileProgram(iter.getProgram(), &buildInfo));
114                 log << buildInfo;
115         }
116         catch (const tcu::NotSupportedError& err)
117         {
118                 // Try to load from cache
119                 log << err << tcu::TestLog::Message << "Building from source not supported, loading stored binary instead" << tcu::TestLog::EndMessage;
120
121                 binProg = de::MovePtr<vk::ProgramBinary>(prebuiltBinRegistry.loadProgram(progId));
122
123                 log << iter.getProgram();
124         }
125         catch (const tcu::Exception&)
126         {
127                 // Build failed for other reason
128                 log << buildInfo;
129                 throw;
130         }
131
132         TCU_CHECK_INTERNAL(binProg);
133
134         {
135                 vk::ProgramBinary* const        returnBinary    = binProg.get();
136
137                 progCollection->add(progId.programName, binProg);
138
139                 return returnBinary;
140         }
141 }
142
143 } // anonymous(compilation)
144
145 namespace vkt
146 {
147
148 using std::vector;
149 using de::UniquePtr;
150 using de::MovePtr;
151 using tcu::TestLog;
152
153 namespace
154 {
155
156 MovePtr<vk::DebugReportRecorder> createDebugReportRecorder (const vk::PlatformInterface& vkp, const vk::InstanceInterface& vki, vk::VkInstance instance)
157 {
158         if (isDebugReportSupported(vkp))
159                 return MovePtr<vk::DebugReportRecorder>(new vk::DebugReportRecorder(vki, instance));
160         else
161                 TCU_THROW(NotSupportedError, "VK_EXT_debug_report is not supported");
162 }
163
164 } // anonymous
165
166 // TestCaseExecutor
167
168 class TestCaseExecutor : public tcu::TestCaseExecutor
169 {
170 public:
171                                                                                                 TestCaseExecutor        (tcu::TestContext& testCtx);
172                                                                                                 ~TestCaseExecutor       (void);
173
174         virtual void                                                            init                            (tcu::TestCase* testCase, const std::string& path);
175         virtual void                                                            deinit                          (tcu::TestCase* testCase);
176
177         virtual tcu::TestNode::IterateResult            iterate                         (tcu::TestCase* testCase);
178
179 private:
180         vk::BinaryCollection                                            m_progCollection;
181         vk::BinaryRegistryReader                                        m_prebuiltBinRegistry;
182
183         const UniquePtr<vk::Library>                            m_library;
184         Context                                                                         m_context;
185
186         const UniquePtr<vk::DebugReportRecorder>        m_debugReportRecorder;
187
188         TestInstance*                                                           m_instance;                     //!< Current test case instance
189 };
190
191 static MovePtr<vk::Library> createLibrary (tcu::TestContext& testCtx)
192 {
193         return MovePtr<vk::Library>(testCtx.getPlatform().getVulkanPlatform().createLibrary());
194 }
195
196 TestCaseExecutor::TestCaseExecutor (tcu::TestContext& testCtx)
197         : m_prebuiltBinRegistry (testCtx.getArchive(), "vulkan/prebuilt")
198         , m_library                             (createLibrary(testCtx))
199         , m_context                             (testCtx, m_library->getPlatformInterface(), m_progCollection)
200         , m_debugReportRecorder (testCtx.getCommandLine().isValidationEnabled()
201                                                          ? createDebugReportRecorder(m_library->getPlatformInterface(),
202                                                                                                                  m_context.getInstanceInterface(),
203                                                                                                                  m_context.getInstance())
204                                                          : MovePtr<vk::DebugReportRecorder>(DE_NULL))
205         , m_instance                    (DE_NULL)
206 {
207 }
208
209 TestCaseExecutor::~TestCaseExecutor (void)
210 {
211         delete m_instance;
212 }
213
214 void TestCaseExecutor::init (tcu::TestCase* testCase, const std::string& casePath)
215 {
216         const TestCase*                 vktCase         = dynamic_cast<TestCase*>(testCase);
217         tcu::TestLog&                   log                     = m_context.getTestContext().getLog();
218         vk::SourceCollections   sourceProgs;
219
220         DE_UNREF(casePath); // \todo [2015-03-13 pyry] Use this to identify ProgramCollection storage path
221
222         if (!vktCase)
223                 TCU_THROW(InternalError, "Test node not an instance of vkt::TestCase");
224
225         m_progCollection.clear();
226         vktCase->initPrograms(sourceProgs);
227
228         for (vk::GlslSourceCollection::Iterator progIter = sourceProgs.glslSources.begin(); progIter != sourceProgs.glslSources.end(); ++progIter)
229         {
230                 vk::ProgramBinary* binProg = buildProgram<glu::ShaderProgramInfo, vk::GlslSourceCollection::Iterator>(casePath, progIter, m_prebuiltBinRegistry, log, &m_progCollection);
231
232                 try
233                 {
234                         std::ostringstream disasm;
235
236                         vk::disassembleProgram(*binProg, &disasm);
237
238                         log << vk::SpirVAsmSource(disasm.str());
239                 }
240                 catch (const tcu::NotSupportedError& err)
241                 {
242                         log << err;
243                 }
244         }
245
246         for (vk::SpirVAsmCollection::Iterator asmIterator = sourceProgs.spirvAsmSources.begin(); asmIterator != sourceProgs.spirvAsmSources.end(); ++asmIterator)
247         {
248                 buildProgram<vk::SpirVProgramInfo, vk::SpirVAsmCollection::Iterator>(casePath, asmIterator, m_prebuiltBinRegistry, log, &m_progCollection);
249         }
250
251         DE_ASSERT(!m_instance);
252         m_instance = vktCase->createInstance(m_context);
253 }
254
255 void TestCaseExecutor::deinit (tcu::TestCase*)
256 {
257         delete m_instance;
258         m_instance = DE_NULL;
259
260         // Collect and report any debug messages
261         if (m_debugReportRecorder)
262         {
263                 // \note We are not logging INFORMATION and DEBUG messages
264                 static const vk::VkDebugReportFlagsEXT                  errorFlags              = vk::VK_DEBUG_REPORT_ERROR_BIT_EXT;
265                 static const vk::VkDebugReportFlagsEXT                  logFlags                = errorFlags
266                                                                                                                                                 | vk::VK_DEBUG_REPORT_WARNING_BIT_EXT
267                                                                                                                                                 | vk::VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
268
269                 typedef vk::DebugReportRecorder::MessageList    DebugMessages;
270
271                 const DebugMessages&    messages        = m_debugReportRecorder->getMessages();
272                 tcu::TestLog&                   log                     = m_context.getTestContext().getLog();
273
274                 if (messages.begin() != messages.end())
275                 {
276                         const tcu::ScopedLogSection     section         (log, "DebugMessages", "Debug Messages");
277                         int                                                     numErrors       = 0;
278
279                         for (DebugMessages::const_iterator curMsg = messages.begin(); curMsg != messages.end(); ++curMsg)
280                         {
281                                 if ((curMsg->flags & logFlags) != 0)
282                                         log << tcu::TestLog::Message << *curMsg << tcu::TestLog::EndMessage;
283
284                                 if ((curMsg->flags & errorFlags) != 0)
285                                         numErrors += 1;
286                         }
287
288                         m_debugReportRecorder->clearMessages();
289
290                         if (numErrors > 0)
291                                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, (de::toString(numErrors) + " API usage errors found").c_str());
292                 }
293         }
294 }
295
296 tcu::TestNode::IterateResult TestCaseExecutor::iterate (tcu::TestCase*)
297 {
298         DE_ASSERT(m_instance);
299
300         const tcu::TestStatus   result  = m_instance->iterate();
301
302         if (result.isComplete())
303         {
304                 // Vulkan tests shouldn't set result directly
305                 DE_ASSERT(m_context.getTestContext().getTestResult() == QP_TEST_RESULT_LAST);
306                 m_context.getTestContext().setTestResult(result.getCode(), result.getDescription().c_str());
307                 return tcu::TestNode::STOP;
308         }
309         else
310                 return tcu::TestNode::CONTINUE;
311 }
312
313 // GLSL shader tests
314
315 void createGlslTests (tcu::TestCaseGroup* glslTests)
316 {
317         tcu::TestContext&       testCtx         = glslTests->getTestContext();
318
319         // ShaderLibrary-based tests
320         static const struct
321         {
322                 const char*             name;
323                 const char*             description;
324         } s_es310Tests[] =
325         {
326                 { "arrays",                                             "Arrays"                                        },
327                 { "conditionals",                               "Conditional statements"        },
328                 { "constant_expressions",               "Constant expressions"          },
329                 { "constants",                                  "Constants"                                     },
330                 { "conversions",                                "Type conversions"                      },
331                 { "functions",                                  "Functions"                                     },
332                 { "linkage",                                    "Linking"                                       },
333                 { "scoping",                                    "Scoping"                                       },
334                 { "swizzles",                                   "Swizzles"                                      },
335         };
336
337         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_es310Tests); ndx++)
338                 glslTests->addChild(createShaderLibraryGroup(testCtx,
339                                                                                                          s_es310Tests[ndx].name,
340                                                                                                          s_es310Tests[ndx].description,
341                                                                                                          std::string("vulkan/glsl/es310/") + s_es310Tests[ndx].name + ".test").release());
342
343         // ShaderRenderCase-based tests
344         glslTests->addChild(sr::createDerivateTests                     (testCtx));
345         glslTests->addChild(sr::createDiscardTests                      (testCtx));
346         glslTests->addChild(sr::createIndexingTests                     (testCtx));
347         glslTests->addChild(sr::createLoopTests                         (testCtx));
348         glslTests->addChild(sr::createMatrixTests                       (testCtx));
349         glslTests->addChild(sr::createOperatorTests                     (testCtx));
350         glslTests->addChild(sr::createReturnTests                       (testCtx));
351         glslTests->addChild(sr::createStructTests                       (testCtx));
352         glslTests->addChild(sr::createSwitchTests                       (testCtx));
353         glslTests->addChild(sr::createTextureFunctionTests      (testCtx));
354         glslTests->addChild(sr::createTextureGatherTests        (testCtx));
355         glslTests->addChild(sr::createBuiltinVarTests           (testCtx));
356
357         // ShaderExecutor-based tests
358         glslTests->addChild(shaderexecutor::createBuiltinTests                          (testCtx));
359         glslTests->addChild(shaderexecutor::createOpaqueTypeIndexingTests       (testCtx));
360         glslTests->addChild(shaderexecutor::createAtomicOperationTests          (testCtx));
361 }
362
363 // TestPackage
364
365 TestPackage::TestPackage (tcu::TestContext& testCtx)
366         : tcu::TestPackage(testCtx, "dEQP-VK", "dEQP Vulkan Tests")
367 {
368 }
369
370 TestPackage::~TestPackage (void)
371 {
372 }
373
374 tcu::TestCaseExecutor* TestPackage::createExecutor (void) const
375 {
376         return new TestCaseExecutor(m_testCtx);
377 }
378
379 void TestPackage::init (void)
380 {
381         addChild(createTestGroup                                (m_testCtx, "info", "Build and Device Info Tests", createInfoTests));
382         addChild(api::createTests                               (m_testCtx));
383         addChild(memory::createTests                    (m_testCtx));
384         addChild(pipeline::createTests                  (m_testCtx));
385         addChild(BindingModel::createTests              (m_testCtx));
386         addChild(SpirVAssembly::createTests             (m_testCtx));
387         addChild(createTestGroup                                (m_testCtx, "glsl", "GLSL shader execution tests", createGlslTests));
388         addChild(createRenderPassTests                  (m_testCtx));
389         addChild(ubo::createTests                               (m_testCtx));
390         addChild(DynamicState::createTests              (m_testCtx));
391         addChild(ssbo::createTests                              (m_testCtx));
392         addChild(QueryPool::createTests                 (m_testCtx));
393         addChild(Draw::createTests                              (m_testCtx));
394         addChild(compute::createTests                   (m_testCtx));
395         addChild(image::createTests                             (m_testCtx));
396         addChild(wsi::createTests                               (m_testCtx));
397         addChild(synchronization::createTests   (m_testCtx));
398         addChild(sparse::createTests                    (m_testCtx));
399         addChild(tessellation::createTests              (m_testCtx));
400         addChild(rasterization::createTests             (m_testCtx));
401         addChild(clipping::createTests                  (m_testCtx));
402         addChild(FragmentOperations::createTests(m_testCtx));
403         addChild(texture::createTests                   (m_testCtx));
404         addChild(geometry::createTests                  (m_testCtx));
405         addChild(robustness::createTests                (m_testCtx));
406         addChild(ycbcr::createTests                             (m_testCtx));
407 }
408
409 } // vkt