1 #ifndef _VKTDYNAMICSTATETESTCASEUTIL_HPP 2 #define _VKTDYNAMICSTATETESTCASEUTIL_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2015 The Khronos Group Inc. 8 * Copyright (c) 2015 Intel Corporation 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Dynamic State Tests Test Case Utilities 25 *//*--------------------------------------------------------------------*/ 26 27 #include "tcuDefs.hpp" 28 29 #include "vktTestCase.hpp" 30 #include "vktTestCaseUtil.hpp" 31 32 #include "gluShaderUtil.hpp" 33 #include "vkPrograms.hpp" 34 #include "vkPipelineConstructionUtil.hpp" 35 36 #include "deUniquePtr.hpp" 37 38 #include <map> 39 40 namespace vkt 41 { 42 namespace DynamicState 43 { 44 45 struct PositionColorVertex 46 { PositionColorVertexvkt::DynamicState::PositionColorVertex47 PositionColorVertex(const tcu::Vec4& position_, const tcu::Vec4& color_) 48 : position(position_) 49 , color(color_) 50 {} 51 tcu::Vec4 position; 52 tcu::Vec4 color; 53 }; 54 55 typedef std::map<glu::ShaderType, const char*> ShaderMap; 56 57 template<typename Instance, typename Support = NoSupport0> 58 class InstanceFactory : public TestCase 59 { 60 public: InstanceFactory(tcu::TestContext & testCtx,const std::string & name,const std::string & desc,const vk::PipelineConstructionType pipelineConstructionType,const ShaderMap & shaderPaths)61 InstanceFactory (tcu::TestContext& testCtx, const std::string& name, const std::string& desc, 62 const vk::PipelineConstructionType pipelineConstructionType, 63 const ShaderMap& shaderPaths) 64 : TestCase (testCtx, name, desc) 65 , m_pipelineConstructionType (pipelineConstructionType) 66 , m_shaderPaths (shaderPaths) 67 , m_support () 68 { 69 } 70 InstanceFactory(tcu::TestContext & testCtx,const std::string & name,const std::string & desc,const vk::PipelineConstructionType pipelineConstructionType,const ShaderMap & shaderPaths,const Support & support)71 InstanceFactory (tcu::TestContext& testCtx, const std::string& name, const std::string& desc, 72 const vk::PipelineConstructionType pipelineConstructionType, 73 const ShaderMap& shaderPaths, const Support& support) 74 : TestCase (testCtx, name, desc) 75 , m_pipelineConstructionType (pipelineConstructionType) 76 , m_shaderPaths (shaderPaths) 77 , m_support (support) 78 { 79 } 80 createInstance(Context & context) const81 TestInstance* createInstance (Context& context) const 82 { 83 return new Instance(context, m_pipelineConstructionType, m_shaderPaths); 84 } 85 initPrograms(vk::SourceCollections & programCollection) const86 virtual void initPrograms (vk::SourceCollections& programCollection) const 87 { 88 const vk::ShaderBuildOptions defaultOptions (programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_0, 0u); 89 const vk::ShaderBuildOptions spv14Options (programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, 0u, true); 90 91 for (ShaderMap::const_iterator i = m_shaderPaths.begin(); i != m_shaderPaths.end(); ++i) 92 { 93 if (i->second) 94 { 95 programCollection.glslSources.add(i->second) 96 << glu::ShaderSource(i->first, ShaderSourceProvider::getSource(m_testCtx.getArchive(), i->second)) 97 << ((i->first == glu::SHADERTYPE_TASK || i->first == glu::SHADERTYPE_MESH) ? spv14Options : defaultOptions); 98 } 99 } 100 } 101 checkSupport(Context & context) const102 virtual void checkSupport (Context& context) const 103 { 104 checkPipelineLibraryRequirements(context.getInstanceInterface(), context.getPhysicalDevice(), m_pipelineConstructionType); 105 106 m_support.checkSupport(context); 107 } 108 109 private: 110 const vk::PipelineConstructionType m_pipelineConstructionType; 111 const ShaderMap m_shaderPaths; 112 const Support m_support; 113 }; 114 115 } // DynamicState 116 } // vkt 117 118 #endif // _VKTDYNAMICSTATETESTCASEUTIL_HPP 119