1 #ifndef _VKTTESTCASE_HPP
2 #define _VKTTESTCASE_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2015 Google Inc.
8 * Copyright (c) 2023 LunarG, Inc.
9 * Copyright (c) 2023 Nintendo
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 *
23 *//*!
24 * \file
25 * \brief Vulkan test case base classes
26 *//*--------------------------------------------------------------------*/
27
28 #include "tcuDefs.hpp"
29 #include "tcuTestCase.hpp"
30 #include "vkDefs.hpp"
31 #include "deUniquePtr.hpp"
32 #include "vkPrograms.hpp"
33 #include "vkApiVersion.hpp"
34 #include "vkDebugReportUtil.hpp"
35 #include "vkPlatform.hpp"
36 #include "vkResourceInterface.hpp"
37 #include "vktTestCaseDefs.hpp"
38 #include "vkPipelineConstructionUtil.hpp"
39 #include <vector>
40 #include <string>
41 #ifdef CTS_USES_VULKANSC
42 #include <mutex>
43 #endif // CTS_USES_VULKANSC
44
45 namespace glu
46 {
47 struct ProgramSources;
48 }
49
50 namespace vk
51 {
52 class PlatformInterface;
53 class Allocator;
54 struct SourceCollections;
55 }
56
57 namespace vkt
58 {
59
60 struct ContextCommonData {
61 const vk::InstanceInterface& vki;
62 vk::VkDevice device;
63 const vk::DeviceInterface& vkd;
64 vk::VkPhysicalDevice physicalDevice;
65 vk::Allocator& allocator;
66 deUint32 qfIndex;
67 vk::VkQueue queue;
68 };
69
70 class DefaultDevice;
71
72 class Context
73 {
74 public:
75 Context (tcu::TestContext& testCtx,
76 const vk::PlatformInterface& platformInterface,
77 vk::BinaryCollection& progCollection,
78 de::SharedPtr<vk::ResourceInterface> resourceInterface);
79 ~Context (void);
80
getTestContext(void) const81 tcu::TestContext& getTestContext (void) const { return m_testCtx; }
getPlatformInterface(void) const82 const vk::PlatformInterface& getPlatformInterface (void) const { return m_platformInterface; }
getBinaryCollection(void) const83 vk::BinaryCollection& getBinaryCollection (void) const { return m_progCollection; }
84
85 // Default instance & device, selected with --deqp-vk-device-id=N
86 deUint32 getMaximumFrameworkVulkanVersion (void) const;
87 deUint32 getAvailableInstanceVersion (void) const;
88 const std::vector<std::string>& getInstanceExtensions (void) const;
89 vk::VkInstance getInstance (void) const;
90 const vk::InstanceInterface& getInstanceInterface (void) const;
91 vk::VkPhysicalDevice getPhysicalDevice (void) const;
92 deUint32 getDeviceVersion (void) const;
93 bool isDeviceFeatureInitialized (vk::VkStructureType sType) const;
94 const vk::VkPhysicalDeviceFeatures& getDeviceFeatures (void) const;
95 const vk::VkPhysicalDeviceFeatures2& getDeviceFeatures2 (void) const;
96 const vk::VkPhysicalDeviceVulkan11Features& getDeviceVulkan11Features (void) const;
97 const vk::VkPhysicalDeviceVulkan12Features& getDeviceVulkan12Features (void) const;
98 #ifndef CTS_USES_VULKANSC
99 const vk::VkPhysicalDeviceVulkan13Features& getDeviceVulkan13Features (void) const;
100 #endif
101 #ifdef CTS_USES_VULKANSC
102 const vk::VkPhysicalDeviceVulkanSC10Features& getDeviceVulkanSC10Features (void) const;
103 #endif // CTS_USES_VULKANSC
104
105 bool isInstanceFunctionalitySupported (const std::string& extension) const;
106 bool isDeviceFunctionalitySupported (const std::string& extension) const;
107
108 #include "vkDeviceFeaturesForContextDecl.inl"
109
110 bool isDevicePropertyInitialized (vk::VkStructureType sType) const;
111 const vk::VkPhysicalDeviceProperties& getDeviceProperties (void) const;
112 const vk::VkPhysicalDeviceProperties2& getDeviceProperties2 (void) const;
113 const vk::VkPhysicalDeviceVulkan11Properties& getDeviceVulkan11Properties (void) const;
114 const vk::VkPhysicalDeviceVulkan12Properties& getDeviceVulkan12Properties (void) const;
115 #ifndef CTS_USES_VULKANSC
116 const vk::VkPhysicalDeviceVulkan13Properties& getDeviceVulkan13Properties (void) const;
117 #endif
118 #ifdef CTS_USES_VULKANSC
119 const vk::VkPhysicalDeviceVulkanSC10Properties& getDeviceVulkanSC10Properties (void) const;
120 #endif // CTS_USES_VULKANSC
121
122 #include "vkDevicePropertiesForContextDecl.inl"
123
124 const std::vector<std::string>& getDeviceExtensions (void) const;
125 const std::vector<const char*>& getDeviceCreationExtensions (void) const;
126 vk::VkDevice getDevice (void) const;
127 const vk::DeviceInterface& getDeviceInterface (void) const;
128 deUint32 getUniversalQueueFamilyIndex (void) const;
129 vk::VkQueue getUniversalQueue (void) const;
130 deUint32 getUsedApiVersion (void) const;
131 deUint32 getSparseQueueFamilyIndex (void) const;
132 vk::VkQueue getSparseQueue (void) const;
133 de::SharedPtr<vk::ResourceInterface> getResourceInterface (void) const;
134 vk::Allocator& getDefaultAllocator (void) const;
135 bool contextSupports (const deUint32 variantNum, const deUint32 majorNum, const deUint32 minorNum, const deUint32 patchNum) const;
136 bool contextSupports (const vk::ApiVersion version) const;
137 bool contextSupports (const deUint32 requiredApiVersionBits) const;
138 bool requireDeviceFunctionality (const std::string& required) const;
139 bool requireInstanceFunctionality (const std::string& required) const;
140 bool requireDeviceCoreFeature (const DeviceCoreFeature requiredDeviceCoreFeature);
141
142 #ifndef CTS_USES_VULKANSC
143 vk::VkFormatProperties3 getFormatProperties (const vk::VkFormat& format) const;
144 vk::VkFormatProperties3 getRequiredFormatProperties (const vk::VkFormat& format) const;
145 #endif // CTS_USES_VULKANSC
146
147
148 void* getInstanceProcAddr ();
149
150 bool isBufferDeviceAddressSupported (void) const;
151
resultSetOnValidation() const152 bool resultSetOnValidation () const { return m_resultSetOnValidation; }
resultSetOnValidation(bool value)153 void resultSetOnValidation (bool value) { m_resultSetOnValidation = value; }
154
155 #ifndef CTS_USES_VULKANSC
156 bool hasDebugReportRecorder () const;
157 vk::DebugReportRecorder& getDebugReportRecorder () const;
158 #endif // CTS_USES_VULKANSC
159
160 void checkPipelineConstructionRequirements (const vk::PipelineConstructionType pipelineConstructionType);
161 void resetCommandPoolForVKSC (const vk::VkDevice device,
162 const vk::VkCommandPool commandPool);
163 ContextCommonData getContextCommonData ();
164
165 #ifdef CTS_USES_VULKANSC
166 static std::vector<VkFaultData> m_faultData;
167 static std::mutex m_faultDataMutex;
168 static VKAPI_ATTR void VKAPI_CALL faultCallbackFunction(VkBool32 unrecordedFaults,
169 deUint32 faultCount,
170 const VkFaultData* pFaults);
171 #endif // CTS_USES_VULKANSC
172
173 protected:
174 tcu::TestContext& m_testCtx;
175 const vk::PlatformInterface& m_platformInterface;
176 vk::BinaryCollection& m_progCollection;
177
178 de::SharedPtr<vk::ResourceInterface> m_resourceInterface;
179 const de::UniquePtr<DefaultDevice> m_device;
180 const de::UniquePtr<vk::Allocator> m_allocator;
181
182 bool m_resultSetOnValidation;
183
184 private:
185 Context (const Context&); // Not allowed
186 Context& operator= (const Context&); // Not allowed
187 };
188
189 class TestInstance;
190
191 class TestCase : public tcu::TestCase
192 {
193 public:
194 TestCase (tcu::TestContext& testCtx, const std::string& name);
195 TestCase (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name);
~TestCase(void)196 virtual ~TestCase (void) {}
197
198 virtual void delayedInit (void); // non-const init called after checkSupport but before initPrograms
199 virtual void initPrograms (vk::SourceCollections& programCollection) const;
200 virtual TestInstance* createInstance (Context& context) const = 0;
201 virtual void checkSupport (Context& context) const;
202
iterate(void)203 IterateResult iterate (void) { DE_ASSERT(false); return STOP; } // Deprecated in this module
204 };
205
206 class TestInstance
207 {
208 public:
TestInstance(Context & context)209 TestInstance (Context& context) : m_context(context) {}
~TestInstance(void)210 virtual ~TestInstance (void) {}
211
212 virtual tcu::TestStatus iterate (void) = 0;
213
214 protected:
215 Context& m_context;
216
217 private:
218 TestInstance (const TestInstance&);
219 TestInstance& operator= (const TestInstance&);
220 };
221
TestCase(tcu::TestContext & testCtx,const std::string & name)222 inline TestCase::TestCase (tcu::TestContext& testCtx, const std::string& name)
223 : tcu::TestCase(testCtx, name.c_str(), "")
224 {
225 }
226
TestCase(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name)227 inline TestCase::TestCase (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name)
228 : tcu::TestCase(testCtx, type, name.c_str(), "")
229 {
230 }
231
232 #ifndef CTS_USES_VULKANSC
233
234 void collectAndReportDebugMessages(vk::DebugReportRecorder &debugReportRecorder, Context& context);
235
236 #endif // CTS_USES_VULKANSC
237
238 deUint32 findQueueFamilyIndexWithCaps(const vk::InstanceInterface& vkInstance, vk::VkPhysicalDevice physicalDevice, vk::VkQueueFlags requiredCaps, vk::VkQueueFlags excludedCaps = 0u);
239
240 } // vkt
241
242 #endif // _VKTTESTCASE_HPP
243