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