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