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"
38 #include "deUniquePtr.hpp"
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"
86 namespace // compilation
89 vk::ProgramBinary* compileProgram (const vk::GlslSource& source, glu::ShaderProgramInfo* buildInfo)
91 return vk::buildProgram(source, buildInfo);
94 vk::ProgramBinary* compileProgram (const vk::HlslSource& source, glu::ShaderProgramInfo* buildInfo)
96 return vk::buildProgram(source, buildInfo);
99 vk::ProgramBinary* compileProgram (const vk::SpirVAsmSource& source, vk::SpirVProgramInfo* buildInfo)
101 return vk::assembleProgram(source, buildInfo);
104 template <typename InfoType, typename IteratorType>
105 vk::ProgramBinary* buildProgram (const std::string& casePath,
107 const vk::BinaryRegistryReader& prebuiltBinRegistry,
109 vk::BinaryCollection* progCollection)
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;
118 binProg = de::MovePtr<vk::ProgramBinary>(compileProgram(iter.getProgram(), &buildInfo));
121 catch (const tcu::NotSupportedError& err)
123 // Try to load from cache
124 log << err << tcu::TestLog::Message << "Building from source not supported, loading stored binary instead" << tcu::TestLog::EndMessage;
126 binProg = de::MovePtr<vk::ProgramBinary>(prebuiltBinRegistry.loadProgram(progId));
128 log << iter.getProgram();
130 catch (const tcu::Exception&)
132 // Build failed for other reason
137 TCU_CHECK_INTERNAL(binProg);
140 vk::ProgramBinary* const returnBinary = binProg.get();
142 progCollection->add(progId.programName, binProg);
148 } // anonymous(compilation)
161 MovePtr<vk::DebugReportRecorder> createDebugReportRecorder (const vk::PlatformInterface& vkp, const vk::InstanceInterface& vki, vk::VkInstance instance)
163 if (isDebugReportSupported(vkp))
164 return MovePtr<vk::DebugReportRecorder>(new vk::DebugReportRecorder(vki, instance));
166 TCU_THROW(NotSupportedError, "VK_EXT_debug_report is not supported");
173 class TestCaseExecutor : public tcu::TestCaseExecutor
176 TestCaseExecutor (tcu::TestContext& testCtx);
177 ~TestCaseExecutor (void);
179 virtual void init (tcu::TestCase* testCase, const std::string& path);
180 virtual void deinit (tcu::TestCase* testCase);
182 virtual tcu::TestNode::IterateResult iterate (tcu::TestCase* testCase);
185 vk::BinaryCollection m_progCollection;
186 vk::BinaryRegistryReader m_prebuiltBinRegistry;
188 const UniquePtr<vk::Library> m_library;
191 const UniquePtr<vk::DebugReportRecorder> m_debugReportRecorder;
193 TestInstance* m_instance; //!< Current test case instance
196 static MovePtr<vk::Library> createLibrary (tcu::TestContext& testCtx)
198 return MovePtr<vk::Library>(testCtx.getPlatform().getVulkanPlatform().createLibrary());
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)
214 TestCaseExecutor::~TestCaseExecutor (void)
219 void TestCaseExecutor::init (tcu::TestCase* testCase, const std::string& casePath)
221 const TestCase* vktCase = dynamic_cast<TestCase*>(testCase);
222 tcu::TestLog& log = m_context.getTestContext().getLog();
223 vk::SourceCollections sourceProgs;
225 DE_UNREF(casePath); // \todo [2015-03-13 pyry] Use this to identify ProgramCollection storage path
228 TCU_THROW(InternalError, "Test node not an instance of vkt::TestCase");
230 m_progCollection.clear();
231 vktCase->initPrograms(sourceProgs);
233 for (vk::GlslSourceCollection::Iterator progIter = sourceProgs.glslSources.begin(); progIter != sourceProgs.glslSources.end(); ++progIter)
235 const vk::ProgramBinary* const binProg = buildProgram<glu::ShaderProgramInfo, vk::GlslSourceCollection::Iterator>(casePath, progIter, m_prebuiltBinRegistry, log, &m_progCollection);
239 std::ostringstream disasm;
241 vk::disassembleProgram(*binProg, &disasm);
243 log << vk::SpirVAsmSource(disasm.str());
245 catch (const tcu::NotSupportedError& err)
251 for (vk::HlslSourceCollection::Iterator progIter = sourceProgs.hlslSources.begin(); progIter != sourceProgs.hlslSources.end(); ++progIter)
253 const vk::ProgramBinary* const binProg = buildProgram<glu::ShaderProgramInfo, vk::HlslSourceCollection::Iterator>(casePath, progIter, m_prebuiltBinRegistry, log, &m_progCollection);
257 std::ostringstream disasm;
259 vk::disassembleProgram(*binProg, &disasm);
261 log << vk::SpirVAsmSource(disasm.str());
263 catch (const tcu::NotSupportedError& err)
269 for (vk::SpirVAsmCollection::Iterator asmIterator = sourceProgs.spirvAsmSources.begin(); asmIterator != sourceProgs.spirvAsmSources.end(); ++asmIterator)
271 buildProgram<vk::SpirVProgramInfo, vk::SpirVAsmCollection::Iterator>(casePath, asmIterator, m_prebuiltBinRegistry, log, &m_progCollection);
274 DE_ASSERT(!m_instance);
275 m_instance = vktCase->createInstance(m_context);
278 void TestCaseExecutor::deinit (tcu::TestCase*)
281 m_instance = DE_NULL;
283 // Collect and report any debug messages
284 if (m_debugReportRecorder)
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;
292 typedef vk::DebugReportRecorder::MessageList DebugMessages;
294 const DebugMessages& messages = m_debugReportRecorder->getMessages();
295 tcu::TestLog& log = m_context.getTestContext().getLog();
297 if (messages.begin() != messages.end())
299 const tcu::ScopedLogSection section (log, "DebugMessages", "Debug Messages");
302 for (DebugMessages::const_iterator curMsg = messages.begin(); curMsg != messages.end(); ++curMsg)
304 if ((curMsg->flags & logFlags) != 0)
305 log << tcu::TestLog::Message << *curMsg << tcu::TestLog::EndMessage;
307 if ((curMsg->flags & errorFlags) != 0)
311 m_debugReportRecorder->clearMessages();
314 m_context.getTestContext().setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, (de::toString(numErrors) + " API usage errors found").c_str());
319 tcu::TestNode::IterateResult TestCaseExecutor::iterate (tcu::TestCase*)
321 DE_ASSERT(m_instance);
323 const tcu::TestStatus result = m_instance->iterate();
325 if (result.isComplete())
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;
333 return tcu::TestNode::CONTINUE;
338 void createGlslTests (tcu::TestCaseGroup* glslTests)
340 tcu::TestContext& testCtx = glslTests->getTestContext();
342 // ShaderLibrary-based tests
346 const char* description;
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" },
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());
366 // ShaderRenderCase-based tests
367 glslTests->addChild(sr::createDerivateTests (testCtx));
368 glslTests->addChild(sr::createDiscardTests (testCtx));
369 glslTests->addChild(sr::createIndexingTests (testCtx));
370 glslTests->addChild(sr::createLoopTests (testCtx));
371 glslTests->addChild(sr::createMatrixTests (testCtx));
372 glslTests->addChild(sr::createOperatorTests (testCtx));
373 glslTests->addChild(sr::createReturnTests (testCtx));
374 glslTests->addChild(sr::createStructTests (testCtx));
375 glslTests->addChild(sr::createSwitchTests (testCtx));
376 glslTests->addChild(sr::createTextureFunctionTests (testCtx));
377 glslTests->addChild(sr::createTextureGatherTests (testCtx));
378 glslTests->addChild(sr::createBuiltinVarTests (testCtx));
380 // ShaderExecutor-based tests
381 glslTests->addChild(shaderexecutor::createBuiltinTests (testCtx));
382 glslTests->addChild(shaderexecutor::createOpaqueTypeIndexingTests (testCtx));
383 glslTests->addChild(shaderexecutor::createAtomicOperationTests (testCtx));
388 TestPackage::TestPackage (tcu::TestContext& testCtx)
389 : tcu::TestPackage(testCtx, "dEQP-VK", "dEQP Vulkan Tests")
393 TestPackage::~TestPackage (void)
397 tcu::TestCaseExecutor* TestPackage::createExecutor (void) const
399 return new TestCaseExecutor(m_testCtx);
402 void TestPackage::init (void)
404 addChild(createTestGroup (m_testCtx, "info", "Build and Device Info Tests", createInfoTests));
405 addChild(api::createTests (m_testCtx));
406 addChild(memory::createTests (m_testCtx));
407 addChild(pipeline::createTests (m_testCtx));
408 addChild(BindingModel::createTests (m_testCtx));
409 addChild(SpirVAssembly::createTests (m_testCtx));
410 addChild(createTestGroup (m_testCtx, "glsl", "GLSL shader execution tests", createGlslTests));
411 addChild(createRenderPassTests (m_testCtx));
412 addChild(ubo::createTests (m_testCtx));
413 addChild(DynamicState::createTests (m_testCtx));
414 addChild(ssbo::createTests (m_testCtx));
415 addChild(QueryPool::createTests (m_testCtx));
416 addChild(Draw::createTests (m_testCtx));
417 addChild(compute::createTests (m_testCtx));
418 addChild(image::createTests (m_testCtx));
419 addChild(wsi::createTests (m_testCtx));
420 addChild(synchronization::createTests (m_testCtx));
421 addChild(sparse::createTests (m_testCtx));
422 addChild(tessellation::createTests (m_testCtx));
423 addChild(rasterization::createTests (m_testCtx));
424 addChild(clipping::createTests (m_testCtx));
425 addChild(FragmentOperations::createTests(m_testCtx));
426 addChild(texture::createTests (m_testCtx));
427 addChild(geometry::createTests (m_testCtx));
428 addChild(robustness::createTests (m_testCtx));
429 addChild(ycbcr::createTests (m_testCtx));