2ff9e070e3440d6689570ae153ddbddd9392007a
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / draw / vktDrawTestCaseUtil.hpp
1 #ifndef _VKTDRAWTESTCASEUTIL_HPP
2 #define _VKTDRAWTESTCASEUTIL_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 Draw Test Case Utils
25  *//*--------------------------------------------------------------------*/
26
27
28 #include "tcuDefs.hpp"
29 #include "tcuResource.hpp"
30
31 #include "vktTestCase.hpp"
32
33 #include "gluShaderUtil.hpp"
34 #include "vkPrograms.hpp"
35
36 #include "deUniquePtr.hpp"
37
38 #include <map>
39
40 namespace vkt
41 {
42 namespace Draw
43 {
44
45 class ShaderSourceProvider
46 {
47 public:
48         static std::string getSource (tcu::Archive& archive, const char* path)
49         {
50                 de::UniquePtr<tcu::Resource> resource(archive.getResource(path));
51
52                 std::vector<deUint8> readBuffer(resource->getSize() + 1);
53                 resource->read(&readBuffer[0], resource->getSize());
54                 readBuffer[readBuffer.size() - 1] = 0;
55
56                 return std::string(reinterpret_cast<const char*>(&readBuffer[0]));
57         }
58 };
59
60 typedef std::map<glu::ShaderType, const char*> ShaderMap;
61
62 template<typename Instance>
63 class InstanceFactory : public TestCase
64 {
65 public:
66         InstanceFactory (tcu::TestContext& testCtx, const std::string& name, const std::string& desc,
67                 const std::map<glu::ShaderType, const char*> shaderPaths, const vk::VkPrimitiveTopology topology)
68                 : TestCase              (testCtx, name, desc)
69                 , m_shaderPaths (shaderPaths)
70                 , m_topology    (topology)
71         {
72         }
73
74         TestInstance* createInstance (Context& context) const
75         {
76                 return new Instance(context, m_shaderPaths, m_topology);
77         }
78
79         virtual void initPrograms (vk::SourceCollections& programCollection) const
80         {
81                 for (ShaderMap::const_iterator i = m_shaderPaths.begin(); i != m_shaderPaths.end(); ++i)
82                 {
83                         programCollection.glslSources.add(i->second) <<
84                                 glu::ShaderSource(i->first, ShaderSourceProvider::getSource(m_testCtx.getArchive(), i->second));
85                 }
86         }
87
88 private:
89         const ShaderMap m_shaderPaths;
90         const vk::VkPrimitiveTopology m_topology;
91 };
92
93 } // Draw
94 } // vkt
95
96 #endif // _VKTDRAWTESTCASEUTIL_HPP