1 #ifndef _VKTTESTCASE_HPP
2 #define _VKTTESTCASE_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2015 Google Inc.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Vulkan test case base classes
24 *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 #include "vkDefs.hpp"
29 #include "deUniquePtr.hpp"
30 #include "vkPrograms.hpp"
31 #include "vkApiVersion.hpp"
32 #include "vkDebugReportUtil.hpp"
33 #include "vkPlatform.hpp"
34 #include "vktTestCaseDefs.hpp"
35 #include <vector>
36 #include <string>
37
38 namespace glu
39 {
40 struct ProgramSources;
41 }
42
43 namespace vk
44 {
45 class PlatformInterface;
46 class Allocator;
47 struct SourceCollections;
48 }
49
50 namespace vkt
51 {
52
53 class DefaultDevice;
54
55 class Context
56 {
57 public:
58 Context (tcu::TestContext& testCtx,
59 const vk::PlatformInterface& platformInterface,
60 vk::BinaryCollection& progCollection);
61 ~Context (void);
62
getTestContext(void) const63 tcu::TestContext& getTestContext (void) const { return m_testCtx; }
getPlatformInterface(void) const64 const vk::PlatformInterface& getPlatformInterface (void) const { return m_platformInterface; }
getBinaryCollection(void) const65 vk::BinaryCollection& getBinaryCollection (void) const { return m_progCollection; }
66
67 // Default instance & device, selected with --deqp-vk-device-id=N
68 deUint32 getMaximumFrameworkVulkanVersion (void) const;
69 deUint32 getAvailableInstanceVersion (void) const;
70 const std::vector<std::string>& getInstanceExtensions (void) const;
71 vk::VkInstance getInstance (void) const;
72 const vk::InstanceInterface& getInstanceInterface (void) const;
73 vk::VkPhysicalDevice getPhysicalDevice (void) const;
74 deUint32 getDeviceVersion (void) const;
75 bool isDeviceFeatureInitialized (vk::VkStructureType sType) const;
76 const vk::VkPhysicalDeviceFeatures& getDeviceFeatures (void) const;
77 const vk::VkPhysicalDeviceFeatures2& getDeviceFeatures2 (void) const;
78
79 bool isInstanceFunctionalitySupported (const std::string& extension) const;
80 bool isDeviceFunctionalitySupported (const std::string& extension) const;
81
82 #include "vkDeviceFeaturesForContextDecl.inl"
83
84 bool isDevicePropertyInitialized (vk::VkStructureType sType) const;
85 const vk::VkPhysicalDeviceProperties& getDeviceProperties (void) const;
86 const vk::VkPhysicalDeviceProperties2& getDeviceProperties2 (void) const;
87
88 #include "vkDevicePropertiesForContextDecl.inl"
89
90 const std::vector<std::string>& getDeviceExtensions (void) const;
91 vk::VkDevice getDevice (void) const;
92 const vk::DeviceInterface& getDeviceInterface (void) const;
93 deUint32 getUniversalQueueFamilyIndex (void) const;
94 vk::VkQueue getUniversalQueue (void) const;
95 deUint32 getUsedApiVersion (void) const;
96 deUint32 getSparseQueueFamilyIndex (void) const;
97 vk::VkQueue getSparseQueue (void) const;
98 vk::Allocator& getDefaultAllocator (void) const;
99 bool contextSupports (const deUint32 majorNum, const deUint32 minorNum, const deUint32 patchNum) const;
100 bool contextSupports (const vk::ApiVersion version) const;
101 bool contextSupports (const deUint32 requiredApiVersionBits) const;
102 bool requireDeviceFunctionality (const std::string& required) const;
103 bool requireInstanceFunctionality (const std::string& required) const;
104 bool requireDeviceCoreFeature (const DeviceCoreFeature requiredDeviceCoreFeature);
105
106 void* getInstanceProcAddr ();
107
108 bool isBufferDeviceAddressSupported (void) const;
109
resultSetOnValidation() const110 bool resultSetOnValidation () const { return m_resultSetOnValidation; }
resultSetOnValidation(bool value)111 void resultSetOnValidation (bool value) { m_resultSetOnValidation = value; }
112
113 protected:
114 tcu::TestContext& m_testCtx;
115 const vk::PlatformInterface& m_platformInterface;
116 vk::BinaryCollection& m_progCollection;
117
118 const de::UniquePtr<DefaultDevice> m_device;
119 const de::UniquePtr<vk::Allocator> m_allocator;
120
121 bool m_resultSetOnValidation;
122
123 private:
124 Context (const Context&); // Not allowed
125 Context& operator= (const Context&); // Not allowed
126 };
127
128 class TestInstance;
129
130 class TestCase : public tcu::TestCase
131 {
132 public:
133 TestCase (tcu::TestContext& testCtx, const std::string& name, const std::string& description);
134 TestCase (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& description);
~TestCase(void)135 virtual ~TestCase (void) {}
136
137 virtual void delayedInit (void); // non-const init called after checkSupport but before initPrograms
138 virtual void initPrograms (vk::SourceCollections& programCollection) const;
139 virtual TestInstance* createInstance (Context& context) const = 0;
140 virtual void checkSupport (Context& context) const;
141
iterate(void)142 IterateResult iterate (void) { DE_ASSERT(false); return STOP; } // Deprecated in this module
143 };
144
145 class TestInstance
146 {
147 public:
TestInstance(Context & context)148 TestInstance (Context& context) : m_context(context) {}
~TestInstance(void)149 virtual ~TestInstance (void) {}
150
151 virtual tcu::TestStatus iterate (void) = 0;
152
153 protected:
154 Context& m_context;
155
156 private:
157 TestInstance (const TestInstance&);
158 TestInstance& operator= (const TestInstance&);
159 };
160
TestCase(tcu::TestContext & testCtx,const std::string & name,const std::string & description)161 inline TestCase::TestCase (tcu::TestContext& testCtx, const std::string& name, const std::string& description)
162 : tcu::TestCase(testCtx, name.c_str(), description.c_str())
163 {
164 }
165
TestCase(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & description)166 inline TestCase::TestCase (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& description)
167 : tcu::TestCase(testCtx, type, name.c_str(), description.c_str())
168 {
169 }
170
171 void collectAndReportDebugMessages(vk::DebugReportRecorder &debugReportRecorder, Context& context);
172
173 } // vkt
174
175 #endif // _VKTTESTCASE_HPP
176