Modify spirv_assembly tests adding dependency on 16bit_storage extension
[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 "vkShaderToSpirV.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::HlslSource& source, glu::ShaderProgramInfo* buildInfo)
95 {
96         return vk::buildProgram(source, buildInfo);
97 }
98
99 vk::ProgramBinary* compileProgram (const vk::SpirVAsmSource& source, vk::SpirVProgramInfo* buildInfo)
100 {
101         return vk::assembleProgram(source, buildInfo);
102 }
103
104 template <typename InfoType, typename IteratorType>
105 vk::ProgramBinary* buildProgram (const std::string&                                     casePath,
106                                                                  IteratorType                                           iter,
107                                                                  const vk::BinaryRegistryReader&        prebuiltBinRegistry,
108                                                                  tcu::TestLog&                                          log,
109                                                                  vk::BinaryCollection*                          progCollection)
110 {
111         const vk::ProgramIdentifier             progId          (casePath, iter.getName());
112         const tcu::ScopedLogSection             progSection     (log, iter.getName(), "Program: " + iter.getName());
113         de::MovePtr<vk::ProgramBinary>  binProg;
114         InfoType                                                buildInfo;
115
116         try
117         {
118                 binProg = de::MovePtr<vk::ProgramBinary>(compileProgram(iter.getProgram(), &buildInfo));
119                 log << buildInfo;
120         }
121         catch (const tcu::NotSupportedError& err)
122         {
123                 // Try to load from cache
124                 log << err << tcu::TestLog::Message << "Building from source not supported, loading stored binary instead" << tcu::TestLog::EndMessage;
125
126                 binProg = de::MovePtr<vk::ProgramBinary>(prebuiltBinRegistry.loadProgram(progId));
127
128                 log << iter.getProgram();
129         }
130         catch (const tcu::Exception&)
131         {
132                 // Build failed for other reason
133                 log << buildInfo;
134                 throw;
135         }
136
137         TCU_CHECK_INTERNAL(binProg);
138
139         {
140                 vk::ProgramBinary* const        returnBinary    = binProg.get();
141
142                 progCollection->add(progId.programName, binProg);
143
144                 return returnBinary;
145         }
146 }
147
148 } // anonymous(compilation)
149
150 namespace vkt
151 {
152
153 using std::vector;
154 using de::UniquePtr;
155 using de::MovePtr;
156 using tcu::TestLog;
157
158 namespace
159 {
160
161 MovePtr<vk::DebugReportRecorder> createDebugReportRecorder (const vk::PlatformInterface& vkp, const vk::InstanceInterface& vki, vk::VkInstance instance)
162 {
163         if (isDebugReportSupported(vkp))
164                 return MovePtr<vk::DebugReportRecorder>(new vk::DebugReportRecorder(vki, instance));
165         else
166                 TCU_THROW(NotSupportedError, "VK_EXT_debug_report is not supported");
167 }
168
169 } // anonymous
170
171 // TestCaseExecutor
172
173 class TestCaseExecutor : public tcu::TestCaseExecutor
174 {
175 public:
176                                                                                                 TestCaseExecutor        (tcu::TestContext& testCtx);
177                                                                                                 ~TestCaseExecutor       (void);
178
179         virtual void                                                            init                            (tcu::TestCase* testCase, const std::string& path);
180         virtual void                                                            deinit                          (tcu::TestCase* testCase);
181
182         virtual tcu::TestNode::IterateResult            iterate                         (tcu::TestCase* testCase);
183
184 private:
185         vk::BinaryCollection                                            m_progCollection;
186         vk::BinaryRegistryReader                                        m_prebuiltBinRegistry;
187
188         const UniquePtr<vk::Library>                            m_library;
189         Context                                                                         m_context;
190
191         const UniquePtr<vk::DebugReportRecorder>        m_debugReportRecorder;
192
193         TestInstance*                                                           m_instance;                     //!< Current test case instance
194 };
195
196 static MovePtr<vk::Library> createLibrary (tcu::TestContext& testCtx)
197 {
198         return MovePtr<vk::Library>(testCtx.getPlatform().getVulkanPlatform().createLibrary());
199 }
200
201 TestCaseExecutor::TestCaseExecutor (tcu::TestContext& testCtx)
202         : m_prebuiltBinRegistry (testCtx.getArchive(), "vulkan/prebuilt")
203         , m_library                             (createLibrary(testCtx))
204         , m_context                             (testCtx, m_library->getPlatformInterface(), m_progCollection)
205         , m_debugReportRecorder (testCtx.getCommandLine().isValidationEnabled()
206                                                          ? createDebugReportRecorder(m_library->getPlatformInterface(),
207                                                                                                                  m_context.getInstanceInterface(),
208                                                                                                                  m_context.getInstance())
209                                                          : MovePtr<vk::DebugReportRecorder>(DE_NULL))
210         , m_instance                    (DE_NULL)
211 {
212 }
213
214 TestCaseExecutor::~TestCaseExecutor (void)
215 {
216         delete m_instance;
217 }
218
219 void TestCaseExecutor::init (tcu::TestCase* testCase, const std::string& casePath)
220 {
221         const TestCase*                 vktCase         = dynamic_cast<TestCase*>(testCase);
222         tcu::TestLog&                   log                     = m_context.getTestContext().getLog();
223         vk::SourceCollections   sourceProgs;
224
225         DE_UNREF(casePath); // \todo [2015-03-13 pyry] Use this to identify ProgramCollection storage path
226
227         if (!vktCase)
228                 TCU_THROW(InternalError, "Test node not an instance of vkt::TestCase");
229
230         m_progCollection.clear();
231         vktCase->initPrograms(sourceProgs);
232
233         for (vk::GlslSourceCollection::Iterator progIter = sourceProgs.glslSources.begin(); progIter != sourceProgs.glslSources.end(); ++progIter)
234         {
235                 const vk::ProgramBinary* const binProg = buildProgram<glu::ShaderProgramInfo, vk::GlslSourceCollection::Iterator>(casePath, progIter, m_prebuiltBinRegistry, log, &m_progCollection);
236
237                 try
238                 {
239                         std::ostringstream disasm;
240
241                         vk::disassembleProgram(*binProg, &disasm);
242
243                         log << vk::SpirVAsmSource(disasm.str());
244                 }
245                 catch (const tcu::NotSupportedError& err)
246                 {
247                         log << err;
248                 }
249         }
250
251         for (vk::HlslSourceCollection::Iterator progIter = sourceProgs.hlslSources.begin(); progIter != sourceProgs.hlslSources.end(); ++progIter)
252         {
253                 const vk::ProgramBinary* const binProg = buildProgram<glu::ShaderProgramInfo, vk::HlslSourceCollection::Iterator>(casePath, progIter, m_prebuiltBinRegistry, log, &m_progCollection);
254
255                 try
256                 {
257                         std::ostringstream disasm;
258
259                         vk::disassembleProgram(*binProg, &disasm);
260
261                         log << vk::SpirVAsmSource(disasm.str());
262                 }
263                 catch (const tcu::NotSupportedError& err)
264                 {
265                         log << err;
266                 }
267         }
268
269         for (vk::SpirVAsmCollection::Iterator asmIterator = sourceProgs.spirvAsmSources.begin(); asmIterator != sourceProgs.spirvAsmSources.end(); ++asmIterator)
270         {
271                 buildProgram<vk::SpirVProgramInfo, vk::SpirVAsmCollection::Iterator>(casePath, asmIterator, m_prebuiltBinRegistry, log, &m_progCollection);
272         }
273
274         DE_ASSERT(!m_instance);
275         m_instance = vktCase->createInstance(m_context);
276 }
277
278 void TestCaseExecutor::deinit (tcu::TestCase*)
279 {
280         delete m_instance;
281         m_instance = DE_NULL;
282
283         // Collect and report any debug messages
284         if (m_debugReportRecorder)
285         {
286                 // \note We are not logging INFORMATION and DEBUG messages
287                 static const vk::VkDebugReportFlagsEXT                  errorFlags              = vk::VK_DEBUG_REPORT_ERROR_BIT_EXT;
288                 static const vk::VkDebugReportFlagsEXT                  logFlags                = errorFlags
289                                                                                                                                                 | vk::VK_DEBUG_REPORT_WARNING_BIT_EXT
290                                                                                                                                                 | vk::VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
291
292                 typedef vk::DebugReportRecorder::MessageList    DebugMessages;
293
294                 const DebugMessages&    messages        = m_debugReportRecorder->getMessages();
295                 tcu::TestLog&                   log                     = m_context.getTestContext().getLog();
296
297                 if (messages.begin() != messages.end())
298                 {
299                         const tcu::ScopedLogSection     section         (log, "DebugMessages", "Debug Messages");
300                         int                                                     numErrors       = 0;
301
302                         for (DebugMessages::const_iterator curMsg = messages.begin(); curMsg != messages.end(); ++curMsg)
303                         {
304                                 if ((curMsg->flags & logFlags) != 0)
305                                         log << tcu::TestLog::Message << *curMsg << tcu::TestLog::EndMessage;
306
307                                 if ((curMsg->flags & errorFlags) != 0)
308                                         numErrors += 1;
309                         }
310
311                         m_debugReportRecorder->clearMessages();
312
313                         if (numErrors > 0)
314                                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, (de::toString(numErrors) + " API usage errors found").c_str());
315                 }
316         }
317 }
318
319 tcu::TestNode::IterateResult TestCaseExecutor::iterate (tcu::TestCase*)
320 {
321         DE_ASSERT(m_instance);
322
323         const tcu::TestStatus   result  = m_instance->iterate();
324
325         if (result.isComplete())
326         {
327                 // Vulkan tests shouldn't set result directly
328                 DE_ASSERT(m_context.getTestContext().getTestResult() == QP_TEST_RESULT_LAST);
329                 m_context.getTestContext().setTestResult(result.getCode(), result.getDescription().c_str());
330                 return tcu::TestNode::STOP;
331         }
332         else
333                 return tcu::TestNode::CONTINUE;
334 }
335
336 // GLSL shader tests
337
338 void createGlslTests (tcu::TestCaseGroup* glslTests)
339 {
340         tcu::TestContext&       testCtx         = glslTests->getTestContext();
341
342         // ShaderLibrary-based tests
343         static const struct
344         {
345                 const char*             name;
346                 const char*             description;
347         } s_es310Tests[] =
348         {
349                 { "arrays",                                             "Arrays"                                        },
350                 { "conditionals",                               "Conditional statements"        },
351                 { "constant_expressions",               "Constant expressions"          },
352                 { "constants",                                  "Constants"                                     },
353                 { "conversions",                                "Type conversions"                      },
354                 { "functions",                                  "Functions"                                     },
355                 { "linkage",                                    "Linking"                                       },
356                 { "scoping",                                    "Scoping"                                       },
357                 { "swizzles",                                   "Swizzles"                                      },
358         };
359
360         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_es310Tests); ndx++)
361                 glslTests->addChild(createShaderLibraryGroup(testCtx,
362                                                                                                          s_es310Tests[ndx].name,
363                                                                                                          s_es310Tests[ndx].description,
364                                                                                                          std::string("vulkan/glsl/es310/") + s_es310Tests[ndx].name + ".test").release());
365
366         static const struct
367         {
368                 const char*             name;
369                 const char*             description;
370         } s_440Tests[] =
371         {
372                 { "linkage",                                    "Linking"                                       },
373         };
374
375         de::MovePtr<tcu::TestCaseGroup> glsl440Tests = de::MovePtr<tcu::TestCaseGroup>(new tcu::TestCaseGroup(testCtx, "440", ""));
376
377         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_440Tests); ndx++)
378                 glsl440Tests->addChild(createShaderLibraryGroup(testCtx,
379                                                                                                          s_440Tests[ndx].name,
380                                                                                                          s_440Tests[ndx].description,
381                                                                                                          std::string("vulkan/glsl/440/") + s_440Tests[ndx].name + ".test").release());
382
383         glslTests->addChild(glsl440Tests.release());
384
385         // ShaderRenderCase-based tests
386         glslTests->addChild(sr::createDerivateTests                     (testCtx));
387         glslTests->addChild(sr::createDiscardTests                      (testCtx));
388         glslTests->addChild(sr::createIndexingTests                     (testCtx));
389         glslTests->addChild(sr::createLoopTests                         (testCtx));
390         glslTests->addChild(sr::createMatrixTests                       (testCtx));
391         glslTests->addChild(sr::createOperatorTests                     (testCtx));
392         glslTests->addChild(sr::createReturnTests                       (testCtx));
393         glslTests->addChild(sr::createStructTests                       (testCtx));
394         glslTests->addChild(sr::createSwitchTests                       (testCtx));
395         glslTests->addChild(sr::createTextureFunctionTests      (testCtx));
396         glslTests->addChild(sr::createTextureGatherTests        (testCtx));
397         glslTests->addChild(sr::createBuiltinVarTests           (testCtx));
398
399         // ShaderExecutor-based tests
400         glslTests->addChild(shaderexecutor::createBuiltinTests                          (testCtx));
401         glslTests->addChild(shaderexecutor::createOpaqueTypeIndexingTests       (testCtx));
402         glslTests->addChild(shaderexecutor::createAtomicOperationTests          (testCtx));
403 }
404
405 // TestPackage
406
407 TestPackage::TestPackage (tcu::TestContext& testCtx)
408         : tcu::TestPackage(testCtx, "dEQP-VK", "dEQP Vulkan Tests")
409 {
410 }
411
412 TestPackage::~TestPackage (void)
413 {
414 }
415
416 tcu::TestCaseExecutor* TestPackage::createExecutor (void) const
417 {
418         return new TestCaseExecutor(m_testCtx);
419 }
420
421 void TestPackage::init (void)
422 {
423         addChild(createTestGroup                                (m_testCtx, "info", "Build and Device Info Tests", createInfoTests));
424         addChild(api::createTests                               (m_testCtx));
425         addChild(memory::createTests                    (m_testCtx));
426         addChild(pipeline::createTests                  (m_testCtx));
427         addChild(BindingModel::createTests              (m_testCtx));
428         addChild(SpirVAssembly::createTests             (m_testCtx));
429         addChild(createTestGroup                                (m_testCtx, "glsl", "GLSL shader execution tests", createGlslTests));
430         addChild(createRenderPassTests                  (m_testCtx));
431         addChild(ubo::createTests                               (m_testCtx));
432         addChild(DynamicState::createTests              (m_testCtx));
433         addChild(ssbo::createTests                              (m_testCtx));
434         addChild(QueryPool::createTests                 (m_testCtx));
435         addChild(Draw::createTests                              (m_testCtx));
436         addChild(compute::createTests                   (m_testCtx));
437         addChild(image::createTests                             (m_testCtx));
438         addChild(wsi::createTests                               (m_testCtx));
439         addChild(synchronization::createTests   (m_testCtx));
440         addChild(sparse::createTests                    (m_testCtx));
441         addChild(tessellation::createTests              (m_testCtx));
442         addChild(rasterization::createTests             (m_testCtx));
443         addChild(clipping::createTests                  (m_testCtx));
444         addChild(FragmentOperations::createTests(m_testCtx));
445         addChild(texture::createTests                   (m_testCtx));
446         addChild(geometry::createTests                  (m_testCtx));
447         addChild(robustness::createTests                (m_testCtx));
448         addChild(ycbcr::createTests                             (m_testCtx));
449 }
450
451 } // vkt