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_) : position(position_), color(color_)
50     {
51     }
52     tcu::Vec4 position;
53     tcu::Vec4 color;
54 };
55 
56 typedef std::map<glu::ShaderType, const char *> ShaderMap;
57 
58 template <typename Instance, typename Support = NoSupport0>
59 class InstanceFactory : public TestCase
60 {
61 public:
InstanceFactory(tcu::TestContext & testCtx,const std::string & name,const vk::PipelineConstructionType pipelineConstructionType,const ShaderMap & shaderPaths)62     InstanceFactory(tcu::TestContext &testCtx, const std::string &name,
63                     const vk::PipelineConstructionType pipelineConstructionType, const ShaderMap &shaderPaths)
64         : TestCase(testCtx, name)
65         , m_pipelineConstructionType(pipelineConstructionType)
66         , m_shaderPaths(shaderPaths)
67         , m_support()
68     {
69     }
70 
InstanceFactory(tcu::TestContext & testCtx,const std::string & name,const vk::PipelineConstructionType pipelineConstructionType,const ShaderMap & shaderPaths,const Support & support)71     InstanceFactory(tcu::TestContext &testCtx, const std::string &name,
72                     const vk::PipelineConstructionType pipelineConstructionType, const ShaderMap &shaderPaths,
73                     const Support &support)
74         : TestCase(testCtx, name)
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 :
98                                                                                                  defaultOptions);
99             }
100         }
101     }
102 
checkSupport(Context & context) const103     virtual void checkSupport(Context &context) const
104     {
105         checkPipelineConstructionRequirements(context.getInstanceInterface(), context.getPhysicalDevice(),
106                                               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 } // namespace DynamicState
118 } // namespace vkt
119 
120 #endif // _VKTDYNAMICSTATETESTCASEUTIL_HPP
121