• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTCUSTOMINSTANCESDEVICES_HPP
2 #define _VKTCUSTOMINSTANCESDEVICES_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2019 The Khronos Group Inc.
8  * Copyright (c) 2019 Valve 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 Auxiliar functions to help create custom devices and instances.
25  *//*--------------------------------------------------------------------*/
26 
27 #include "vkDefs.hpp"
28 #include "vktTestCase.hpp"
29 
30 #include <vector>
31 #include <memory>
32 
33 namespace vk
34 {
35 	class PlatformInterface;
36 	class InstanceInterface;
37 }
38 
39 namespace tcu
40 {
41 	class CommandLine;
42 }
43 
44 namespace vkt
45 {
46 
47 std::vector<const char*> getValidationLayers (const vk::PlatformInterface& vkp);
48 
49 std::vector<const char*> getValidationLayers (const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice);
50 
51 class CustomInstance
52 {
53 public:
54 								CustomInstance			();
55 #ifndef CTS_USES_VULKANSC
56 								CustomInstance			(Context& context, vk::Move<vk::VkInstance> instance, std::unique_ptr<vk::DebugReportRecorder>& recorder);
57 #else
58 								CustomInstance			(Context& context, vk::Move<vk::VkInstance> instance);
59 #endif // CTS_USES_VULKANSC
60 								CustomInstance			(CustomInstance&& other);
61 								~CustomInstance			();
62 	CustomInstance&				operator=				(CustomInstance&& other);
63 								operator vk::VkInstance	() const;
64 	void						swap					(CustomInstance& other);
65 	const vk::InstanceDriver&	getDriver				() const;
66 	void						collectMessages			();
67 
68 								CustomInstance			(const CustomInstance& other) = delete;
69 	CustomInstance&				operator=				(const CustomInstance& other) = delete;
70 private:
71 	Context*									m_context;
72 #ifndef CTS_USES_VULKANSC
73 	std::unique_ptr<vk::DebugReportRecorder>	m_recorder;
74 #endif // CTS_USES_VULKANSC
75 	vk::Move<vk::VkInstance>					m_instance;
76 #ifndef CTS_USES_VULKANSC
77 	std::unique_ptr<vk::InstanceDriver>			m_driver;
78 	vk::Move<vk::VkDebugReportCallbackEXT>		m_callback;
79 #else
80 	std::unique_ptr<vk::InstanceDriverSC>		m_driver;
81 #endif // CTS_USES_VULKANSC
82 };
83 
84 class UncheckedInstance
85 {
86 public:
87 						UncheckedInstance		();
88 #ifndef CTS_USES_VULKANSC
89 						UncheckedInstance		(Context& context, vk::VkInstance instance, const vk::VkAllocationCallbacks* pAllocator, std::unique_ptr<vk::DebugReportRecorder>& recorder);
90 #else
91 						UncheckedInstance		(Context& context, vk::VkInstance instance, const vk::VkAllocationCallbacks* pAllocator);
92 #endif // CTS_USES_VULKANSC
93 						UncheckedInstance		(UncheckedInstance&& other);
94 						~UncheckedInstance		();
95 	UncheckedInstance&	operator=				(UncheckedInstance&& other);
96 						operator vk::VkInstance	() const;
97 						operator bool			() const;
98 	void				swap					(UncheckedInstance& other);
99 
100 						UncheckedInstance		(const UncheckedInstance& other) = delete;
101 	UncheckedInstance&	operator=				(const UncheckedInstance& other) = delete;
102 private:
103 	Context*									m_context;
104 #ifndef CTS_USES_VULKANSC
105 	std::unique_ptr<vk::DebugReportRecorder>	m_recorder;
106 #endif // CTS_USES_VULKANSC
107 	const vk::VkAllocationCallbacks*			m_allocator;
108 	vk::VkInstance								m_instance;
109 #ifndef CTS_USES_VULKANSC
110 	std::unique_ptr<vk::InstanceDriver>			m_driver;
111 	vk::Move<vk::VkDebugReportCallbackEXT>		m_callback;
112 #else
113 	std::unique_ptr<vk::InstanceDriverSC>		m_driver;
114 #endif // CTS_USES_VULKANSC
115 };
116 
117 // Custom instances.
118 
119 CustomInstance createCustomInstanceWithExtensions (Context& context, const std::vector<std::string>& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
120 
121 CustomInstance createCustomInstanceWithExtension (Context& context, const std::string& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
122 
123 CustomInstance createCustomInstanceFromContext (Context& context, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
124 
125 CustomInstance createCustomInstanceFromInfo (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
126 
127 // Unchecked instance: creation allowed to fail.
128 
129 vk::VkResult createUncheckedInstance (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator, UncheckedInstance* instance, bool allowLayers = true);
130 
131 // Custom devices.
132 
133 vk::Move<vk::VkDevice> createCustomDevice (bool validationEnabled, const vk::PlatformInterface& vkp, vk::VkInstance instance, const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice, const vk::VkDeviceCreateInfo* pCreateInfo, const vk::VkAllocationCallbacks* pAllocator = DE_NULL);
134 
135 // Unchecked device: creation allowed to fail.
136 
137 vk::VkResult createUncheckedDevice (bool validationEnabled, const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice, const vk::VkDeviceCreateInfo* pCreateInfo, const vk::VkAllocationCallbacks* pAllocator, vk::VkDevice* pDevice);
138 
139 class CustomInstanceWrapper
140 {
141 public:
142 	CustomInstanceWrapper(Context& context);
143 	CustomInstanceWrapper(Context& context, const std::vector<std::string> extensions);
144 	vkt::CustomInstance instance;
145 };
146 
147 class VideoDevice
148 {
149 public:
150 #ifndef CTS_USES_VULKANSC
151 	typedef vk::VkVideoCodecOperationFlagsKHR VideoCodecOperationFlags;
152 #else
153 	typedef uint32_t VideoCodecOperationFlags;
154 #endif // CTS_USES_VULKANSC
155 
156 	enum VideoDeviceFlagBits
157 	{
158 		VIDEO_DEVICE_FLAG_NONE									= 0,
159 		VIDEO_DEVICE_FLAG_QUERY_WITH_STATUS_FOR_DECODE_SUPPORT	= 0x00000001,
160 		VIDEO_DEVICE_FLAG_REQUIRE_YCBCR_OR_NOT_SUPPORTED		= 0x00000002,
161 		VIDEO_DEVICE_FLAG_REQUIRE_SYNC2_OR_NOT_SUPPORTED		= 0x00000004
162 	};
163 	typedef uint32_t VideoDeviceFlags;
164 
165 	static void						checkSupport				(Context&						context,
166 																 const VideoCodecOperationFlags	videoCodecOperation);
167 	static vk::VkQueueFlags			getQueueFlags				(const VideoCodecOperationFlags	videoCodecOperationFlags);
168 
169 	static void						addVideoDeviceExtensions	(std::vector<const char*>&		deviceExtensions,
170 																 const uint32_t					apiVersion,
171 																 const vk::VkQueueFlags			queueFlagsRequired,
172 																 const VideoCodecOperationFlags	videoCodecOperationFlags);
173 	static bool						isVideoEncodeOperation		(const VideoCodecOperationFlags	videoCodecOperationFlags);
174 	static bool						isVideoDecodeOperation		(const VideoCodecOperationFlags	videoCodecOperationFlags);
175 	static bool						isVideoOperation			(const VideoCodecOperationFlags	videoCodecOperationFlags);
176 
177 									VideoDevice					(Context&						context);
178 									VideoDevice					(Context&						context,
179 																 const VideoCodecOperationFlags	videoCodecOperation,
180 																 const VideoDeviceFlags			videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE);
181 	virtual							~VideoDevice				(void);
182 
183 	vk::VkDevice					getDeviceSupportingQueue	(const vk::VkQueueFlags			queueFlagsRequired = 0,
184 																 const VideoCodecOperationFlags	videoCodecOperationFlags = 0,
185 																 const VideoDeviceFlags			videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE);
186 	bool							createDeviceSupportingQueue	(const vk::VkQueueFlags			queueFlagsRequired,
187 																 const VideoCodecOperationFlags	videoCodecOperationFlags,
188 																 const VideoDeviceFlags			videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE);
189 	const vk::DeviceDriver&			getDeviceDriver				(void);
190 	const deUint32&					getQueueFamilyIndexTransfer	(void);
191 	const deUint32&					getQueueFamilyIndexDecode	(void);
192 	const deUint32&					getQueueFamilyIndexEncode	(void);
193 	const deUint32&					getQueueFamilyVideo			(void);
194 	vk::Allocator&					getAllocator				(void);
195 
196 protected:
197 	Context&						m_context;
198 
199 	vk::Move<vk::VkDevice>			m_logicalDevice;
200 	de::MovePtr<vk::DeviceDriver>	m_deviceDriver;
201 	de::MovePtr<vk::Allocator>		m_allocator;
202 	deUint32						m_queueFamilyTransfer;
203 	deUint32						m_queueFamilyDecode;
204 	deUint32						m_queueFamilyEncode;
205 	VideoCodecOperationFlags		m_videoCodecOperation;
206 };
207 
208 }
209 
210 #endif // _VKTCUSTOMINSTANCESDEVICES_HPP
211