1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Vulkan Test Package
22 *//*--------------------------------------------------------------------*/
24 #include "vktTestPackage.hpp"
26 #include "tcuPlatform.hpp"
27 #include "tcuTestCase.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuCommandLine.hpp"
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 #include "vkApiVersion.hpp"
39 #include "deUniquePtr.hpp"
41 #include "vktTestGroupUtil.hpp"
42 #include "vktApiTests.hpp"
43 #include "vktPipelineTests.hpp"
44 #include "vktBindingModelTests.hpp"
45 #include "vktSpvAsmTests.hpp"
46 #include "vktShaderLibrary.hpp"
47 #include "vktRenderPassTests.hpp"
48 #include "vktMemoryTests.hpp"
49 #include "vktShaderRenderBuiltinVarTests.hpp"
50 #include "vktShaderRenderDerivateTests.hpp"
51 #include "vktShaderRenderDiscardTests.hpp"
52 #include "vktShaderRenderIndexingTests.hpp"
53 #include "vktShaderRenderLoopTests.hpp"
54 #include "vktShaderRenderMatrixTests.hpp"
55 #include "vktShaderRenderOperatorTests.hpp"
56 #include "vktShaderRenderReturnTests.hpp"
57 #include "vktShaderRenderStructTests.hpp"
58 #include "vktShaderRenderSwitchTests.hpp"
59 #include "vktShaderRenderTextureFunctionTests.hpp"
60 #include "vktShaderRenderTextureGatherTests.hpp"
61 #include "vktShaderBuiltinTests.hpp"
62 #include "vktOpaqueTypeIndexingTests.hpp"
63 #include "vktAtomicOperationTests.hpp"
64 #include "vktUniformBlockTests.hpp"
65 #include "vktDynamicStateTests.hpp"
66 #include "vktSSBOLayoutTests.hpp"
67 #include "vktQueryPoolTests.hpp"
68 #include "vktDrawTests.hpp"
69 #include "vktComputeTests.hpp"
70 #include "vktImageTests.hpp"
71 #include "vktInfoTests.hpp"
72 #include "vktWsiTests.hpp"
73 #include "vktSynchronizationTests.hpp"
74 #include "vktSparseResourcesTests.hpp"
75 #include "vktTessellationTests.hpp"
76 #include "vktRasterizationTests.hpp"
77 #include "vktClippingTests.hpp"
78 #include "vktFragmentOperationsTests.hpp"
79 #include "vktTextureTests.hpp"
80 #include "vktGeometryTests.hpp"
81 #include "vktRobustnessTests.hpp"
82 #include "vktMultiViewTests.hpp"
83 #include "vktSubgroupsTests.hpp"
84 #include "vktYCbCrTests.hpp"
85 #include "vktProtectedMemTests.hpp"
86 #include "vktDeviceGroupTests.hpp"
91 namespace // compilation
94 vk::ProgramBinary* compileProgram (const vk::GlslSource& source, glu::ShaderProgramInfo* buildInfo, const tcu::CommandLine& commandLine)
96 return vk::buildProgram(source, buildInfo, commandLine);
99 vk::ProgramBinary* compileProgram (const vk::HlslSource& source, glu::ShaderProgramInfo* buildInfo, const tcu::CommandLine& commandLine)
101 return vk::buildProgram(source, buildInfo, commandLine);
104 vk::ProgramBinary* compileProgram (const vk::SpirVAsmSource& source, vk::SpirVProgramInfo* buildInfo, const tcu::CommandLine& commandLine)
106 return vk::assembleProgram(source, buildInfo, commandLine);
109 template <typename InfoType, typename IteratorType>
110 vk::ProgramBinary* buildProgram (const std::string& casePath,
112 const vk::BinaryRegistryReader& prebuiltBinRegistry,
114 vk::BinaryCollection* progCollection,
115 const tcu::CommandLine& commandLine)
117 const vk::ProgramIdentifier progId (casePath, iter.getName());
118 const tcu::ScopedLogSection progSection (log, iter.getName(), "Program: " + iter.getName());
119 de::MovePtr<vk::ProgramBinary> binProg;
124 binProg = de::MovePtr<vk::ProgramBinary>(compileProgram(iter.getProgram(), &buildInfo, commandLine));
127 catch (const tcu::NotSupportedError& err)
129 // Try to load from cache
130 log << err << tcu::TestLog::Message << "Building from source not supported, loading stored binary instead" << tcu::TestLog::EndMessage;
132 binProg = de::MovePtr<vk::ProgramBinary>(prebuiltBinRegistry.loadProgram(progId));
134 log << iter.getProgram();
136 catch (const tcu::Exception&)
138 // Build failed for other reason
143 TCU_CHECK_INTERNAL(binProg);
146 vk::ProgramBinary* const returnBinary = binProg.get();
148 progCollection->add(progId.programName, binProg);
154 } // anonymous(compilation)
167 MovePtr<vk::DebugReportRecorder> createDebugReportRecorder (const vk::PlatformInterface& vkp, const vk::InstanceInterface& vki, vk::VkInstance instance)
169 if (isDebugReportSupported(vkp))
170 return MovePtr<vk::DebugReportRecorder>(new vk::DebugReportRecorder(vki, instance));
172 TCU_THROW(NotSupportedError, "VK_EXT_debug_report is not supported");
179 class TestCaseExecutor : public tcu::TestCaseExecutor
182 TestCaseExecutor (tcu::TestContext& testCtx);
183 ~TestCaseExecutor (void);
185 virtual void init (tcu::TestCase* testCase, const std::string& path);
186 virtual void deinit (tcu::TestCase* testCase);
188 virtual tcu::TestNode::IterateResult iterate (tcu::TestCase* testCase);
191 vk::BinaryCollection m_progCollection;
192 vk::BinaryRegistryReader m_prebuiltBinRegistry;
194 const UniquePtr<vk::Library> m_library;
197 const UniquePtr<vk::DebugReportRecorder> m_debugReportRecorder;
199 TestInstance* m_instance; //!< Current test case instance
202 static MovePtr<vk::Library> createLibrary (tcu::TestContext& testCtx)
204 return MovePtr<vk::Library>(testCtx.getPlatform().getVulkanPlatform().createLibrary());
207 TestCaseExecutor::TestCaseExecutor (tcu::TestContext& testCtx)
208 : m_prebuiltBinRegistry (testCtx.getArchive(), "vulkan/prebuilt")
209 , m_library (createLibrary(testCtx))
210 , m_context (testCtx, m_library->getPlatformInterface(), m_progCollection)
211 , m_debugReportRecorder (testCtx.getCommandLine().isValidationEnabled()
212 ? createDebugReportRecorder(m_library->getPlatformInterface(),
213 m_context.getInstanceInterface(),
214 m_context.getInstance())
215 : MovePtr<vk::DebugReportRecorder>(DE_NULL))
216 , m_instance (DE_NULL)
220 TestCaseExecutor::~TestCaseExecutor (void)
225 void TestCaseExecutor::init (tcu::TestCase* testCase, const std::string& casePath)
227 const TestCase* vktCase = dynamic_cast<TestCase*>(testCase);
228 tcu::TestLog& log = m_context.getTestContext().getLog();
229 const deUint32 usedVulkanVersion = m_context.getUsedApiVersion();
230 const vk::SpirvVersion spirvVersionForGlsl = vk::getSpirvVersionForGlsl(usedVulkanVersion);
231 const vk::SpirvVersion spirvVersionForAsm = vk::getSpirvVersionForAsm(usedVulkanVersion);
232 vk::ShaderBuildOptions defaultGlslBuildOptions (spirvVersionForGlsl, 0u);
233 vk::ShaderBuildOptions defaultHlslBuildOptions (spirvVersionForGlsl, 0u);
234 vk::SpirVAsmBuildOptions defaultSpirvAsmBuildOptions (spirvVersionForAsm);
235 vk::SourceCollections sourceProgs (usedVulkanVersion, defaultGlslBuildOptions, defaultHlslBuildOptions, defaultSpirvAsmBuildOptions);
236 const bool doShaderLog = log.isShaderLoggingEnabled();
237 const tcu::CommandLine& commandLine = m_context.getTestContext().getCommandLine();
239 DE_UNREF(casePath); // \todo [2015-03-13 pyry] Use this to identify ProgramCollection storage path
242 TCU_THROW(InternalError, "Test node not an instance of vkt::TestCase");
244 vktCase->checkSupport(m_context);
246 m_progCollection.clear();
247 vktCase->initPrograms(sourceProgs);
249 for (vk::GlslSourceCollection::Iterator progIter = sourceProgs.glslSources.begin(); progIter != sourceProgs.glslSources.end(); ++progIter)
251 if (progIter.getProgram().buildOptions.targetVersion > vk::getSpirvVersionForGlsl(m_context.getUsedApiVersion()))
252 TCU_THROW(NotSupportedError, "Shader requires SPIR-V higher than available");
254 const vk::ProgramBinary* const binProg = buildProgram<glu::ShaderProgramInfo, vk::GlslSourceCollection::Iterator>(casePath, progIter, m_prebuiltBinRegistry, log, &m_progCollection, commandLine);
260 std::ostringstream disasm;
262 vk::disassembleProgram(*binProg, &disasm, spirvVersionForGlsl);
264 log << vk::SpirVAsmSource(disasm.str());
266 catch (const tcu::NotSupportedError& err)
273 for (vk::HlslSourceCollection::Iterator progIter = sourceProgs.hlslSources.begin(); progIter != sourceProgs.hlslSources.end(); ++progIter)
275 if (progIter.getProgram().buildOptions.targetVersion > vk::getSpirvVersionForGlsl(m_context.getUsedApiVersion()))
276 TCU_THROW(NotSupportedError, "Shader requires SPIR-V higher than available");
278 const vk::ProgramBinary* const binProg = buildProgram<glu::ShaderProgramInfo, vk::HlslSourceCollection::Iterator>(casePath, progIter, m_prebuiltBinRegistry, log, &m_progCollection, commandLine);
284 std::ostringstream disasm;
286 vk::disassembleProgram(*binProg, &disasm, spirvVersionForGlsl);
288 log << vk::SpirVAsmSource(disasm.str());
290 catch (const tcu::NotSupportedError& err)
297 for (vk::SpirVAsmCollection::Iterator asmIterator = sourceProgs.spirvAsmSources.begin(); asmIterator != sourceProgs.spirvAsmSources.end(); ++asmIterator)
299 if (asmIterator.getProgram().buildOptions.targetVersion > vk::getSpirvVersionForAsm(m_context.getUsedApiVersion()))
300 TCU_THROW(NotSupportedError, "Shader requires SPIR-V higher than available");
302 buildProgram<vk::SpirVProgramInfo, vk::SpirVAsmCollection::Iterator>(casePath, asmIterator, m_prebuiltBinRegistry, log, &m_progCollection, commandLine);
305 DE_ASSERT(!m_instance);
306 m_instance = vktCase->createInstance(m_context);
309 void TestCaseExecutor::deinit (tcu::TestCase*)
312 m_instance = DE_NULL;
314 // Collect and report any debug messages
315 if (m_debugReportRecorder)
317 // \note We are not logging INFORMATION and DEBUG messages
318 static const vk::VkDebugReportFlagsEXT errorFlags = vk::VK_DEBUG_REPORT_ERROR_BIT_EXT;
319 static const vk::VkDebugReportFlagsEXT logFlags = errorFlags
320 | vk::VK_DEBUG_REPORT_WARNING_BIT_EXT
321 | vk::VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
323 typedef vk::DebugReportRecorder::MessageList DebugMessages;
325 const DebugMessages& messages = m_debugReportRecorder->getMessages();
326 tcu::TestLog& log = m_context.getTestContext().getLog();
328 if (messages.begin() != messages.end())
330 const tcu::ScopedLogSection section (log, "DebugMessages", "Debug Messages");
333 for (DebugMessages::const_iterator curMsg = messages.begin(); curMsg != messages.end(); ++curMsg)
335 if ((curMsg->flags & logFlags) != 0)
336 log << tcu::TestLog::Message << *curMsg << tcu::TestLog::EndMessage;
338 if ((curMsg->flags & errorFlags) != 0)
342 m_debugReportRecorder->clearMessages();
345 m_context.getTestContext().setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, (de::toString(numErrors) + " API usage errors found").c_str());
350 tcu::TestNode::IterateResult TestCaseExecutor::iterate (tcu::TestCase*)
352 DE_ASSERT(m_instance);
354 const tcu::TestStatus result = m_instance->iterate();
356 if (result.isComplete())
358 // Vulkan tests shouldn't set result directly
359 DE_ASSERT(m_context.getTestContext().getTestResult() == QP_TEST_RESULT_LAST);
360 m_context.getTestContext().setTestResult(result.getCode(), result.getDescription().c_str());
361 return tcu::TestNode::STOP;
364 return tcu::TestNode::CONTINUE;
369 void createGlslTests (tcu::TestCaseGroup* glslTests)
371 tcu::TestContext& testCtx = glslTests->getTestContext();
373 // ShaderLibrary-based tests
377 const char* description;
380 { "arrays", "Arrays" },
381 { "conditionals", "Conditional statements" },
382 { "constant_expressions", "Constant expressions" },
383 { "constants", "Constants" },
384 { "conversions", "Type conversions" },
385 { "functions", "Functions" },
386 { "linkage", "Linking" },
387 { "scoping", "Scoping" },
388 { "swizzles", "Swizzles" },
391 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_es310Tests); ndx++)
392 glslTests->addChild(createShaderLibraryGroup(testCtx,
393 s_es310Tests[ndx].name,
394 s_es310Tests[ndx].description,
395 std::string("vulkan/glsl/es310/") + s_es310Tests[ndx].name + ".test").release());
400 const char* description;
403 { "linkage", "Linking" },
406 de::MovePtr<tcu::TestCaseGroup> glsl440Tests = de::MovePtr<tcu::TestCaseGroup>(new tcu::TestCaseGroup(testCtx, "440", ""));
408 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_440Tests); ndx++)
409 glsl440Tests->addChild(createShaderLibraryGroup(testCtx,
410 s_440Tests[ndx].name,
411 s_440Tests[ndx].description,
412 std::string("vulkan/glsl/440/") + s_440Tests[ndx].name + ".test").release());
414 glslTests->addChild(glsl440Tests.release());
416 // ShaderRenderCase-based tests
417 glslTests->addChild(sr::createDerivateTests (testCtx));
418 glslTests->addChild(sr::createDiscardTests (testCtx));
419 glslTests->addChild(sr::createIndexingTests (testCtx));
420 glslTests->addChild(sr::createLoopTests (testCtx));
421 glslTests->addChild(sr::createMatrixTests (testCtx));
422 glslTests->addChild(sr::createOperatorTests (testCtx));
423 glslTests->addChild(sr::createReturnTests (testCtx));
424 glslTests->addChild(sr::createStructTests (testCtx));
425 glslTests->addChild(sr::createSwitchTests (testCtx));
426 glslTests->addChild(sr::createTextureFunctionTests (testCtx));
427 glslTests->addChild(sr::createTextureGatherTests (testCtx));
428 glslTests->addChild(sr::createBuiltinVarTests (testCtx));
430 // ShaderExecutor-based tests
431 glslTests->addChild(shaderexecutor::createBuiltinTests (testCtx));
432 glslTests->addChild(shaderexecutor::createOpaqueTypeIndexingTests (testCtx));
433 glslTests->addChild(shaderexecutor::createAtomicOperationTests (testCtx));
438 TestPackage::TestPackage (tcu::TestContext& testCtx)
439 : tcu::TestPackage(testCtx, "dEQP-VK", "dEQP Vulkan Tests")
443 TestPackage::~TestPackage (void)
447 tcu::TestCaseExecutor* TestPackage::createExecutor (void) const
449 return new TestCaseExecutor(m_testCtx);
452 void TestPackage::init (void)
454 addChild(createTestGroup (m_testCtx, "info", "Build and Device Info Tests", createInfoTests));
455 addChild(api::createTests (m_testCtx));
456 addChild(memory::createTests (m_testCtx));
457 addChild(pipeline::createTests (m_testCtx));
458 addChild(BindingModel::createTests (m_testCtx));
459 addChild(SpirVAssembly::createTests (m_testCtx));
460 addChild(createTestGroup (m_testCtx, "glsl", "GLSL shader execution tests", createGlslTests));
461 addChild(createRenderPassTests (m_testCtx));
462 addChild(ubo::createTests (m_testCtx));
463 addChild(DynamicState::createTests (m_testCtx));
464 addChild(ssbo::createTests (m_testCtx));
465 addChild(QueryPool::createTests (m_testCtx));
466 addChild(Draw::createTests (m_testCtx));
467 addChild(compute::createTests (m_testCtx));
468 addChild(image::createTests (m_testCtx));
469 addChild(wsi::createTests (m_testCtx));
470 addChild(synchronization::createTests (m_testCtx));
471 addChild(sparse::createTests (m_testCtx));
472 addChild(tessellation::createTests (m_testCtx));
473 addChild(rasterization::createTests (m_testCtx));
474 addChild(clipping::createTests (m_testCtx));
475 addChild(FragmentOperations::createTests(m_testCtx));
476 addChild(texture::createTests (m_testCtx));
477 addChild(geometry::createTests (m_testCtx));
478 addChild(robustness::createTests (m_testCtx));
479 addChild(MultiView::createTests (m_testCtx));
480 addChild(subgroups::createTests (m_testCtx));
481 addChild(ycbcr::createTests (m_testCtx));
482 addChild(ProtectedMem::createTests (m_testCtx));
483 addChild(DeviceGroup::createTests (m_testCtx));