Fix shift-negative-value warning am: cb38ffc012 am: f1c9c43d6f am: e650480a02
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / dynamic_state / vktDynamicStateTestCaseUtil.hpp
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  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and/or associated documentation files (the
12  * "Materials"), to deal in the Materials without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Materials, and to
15  * permit persons to whom the Materials are furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice(s) and this permission notice shall be included
19  * in all copies or substantial portions of the Materials.
20  *
21  * The Materials are Confidential Information as defined by the
22  * Khronos Membership Agreement until designated non-confidential by Khronos,
23  * at which point this condition clause shall be removed.
24  *
25  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
29  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
30  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32  *
33  *//*!
34  * \file
35  * \brief Dynamic State Tests Test Case Utilities
36  *//*--------------------------------------------------------------------*/
37
38 #include "tcuDefs.hpp"
39 #include "tcuResource.hpp"
40
41 #include "vktTestCase.hpp"
42
43 #include "gluShaderUtil.hpp"
44 #include "vkPrograms.hpp"
45
46 #include <map>
47
48 namespace vkt
49 {
50 namespace DynamicState
51 {
52
53 struct PositionColorVertex
54 {
55         PositionColorVertex(const tcu::Vec4& position_, const tcu::Vec4& color_)
56                 : position(position_)
57                 , color(color_)
58         {}
59         tcu::Vec4 position;
60         tcu::Vec4 color;
61 };
62
63 class ShaderSourceProvider
64 {
65 public:
66         static std::string getSource(tcu::Archive& archive, const char* path)
67         {
68                 tcu::Resource *resource = archive.getResource(path);
69
70                 std::vector<deUint8> readBuffer(resource->getSize() + 1);
71                 resource->read(&readBuffer[0], resource->getSize());
72                 readBuffer[readBuffer.size() - 1] = 0;
73
74                 return reinterpret_cast<const char*>(&readBuffer[0]);
75         }
76 };
77
78 typedef std::map<glu::ShaderType, const char*> ShaderMap;
79
80 template<typename Instance>
81 class InstanceFactory : public TestCase
82 {
83 public:
84         InstanceFactory (tcu::TestContext& testCtx, const std::string& name, const std::string& desc,
85                 const std::map<glu::ShaderType, const char*> shaderPaths)
86                 : TestCase              (testCtx, name, desc)
87                 , m_shaderPaths (shaderPaths)
88         {
89         }
90
91         TestInstance* createInstance (Context& context) const
92         {
93                 return new Instance(context, m_shaderPaths);
94         }
95
96         virtual void initPrograms (vk::SourceCollections& programCollection) const
97         {
98                 for (ShaderMap::const_iterator i = m_shaderPaths.begin(); i != m_shaderPaths.end(); ++i)
99                 {
100                         programCollection.glslSources.add(i->second) <<
101                                 glu::ShaderSource(i->first, ShaderSourceProvider::getSource(m_testCtx.getArchive(), i->second));
102                 }
103         }
104
105 private:
106         const ShaderMap m_shaderPaths;
107 };
108
109 } // DynamicState
110 } // vkt
111
112 #endif // _VKTDYNAMICSTATETESTCASEUTIL_HPP