1e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
2e5c31af7Sopenharmony_ci * drawElements Quality Program Tester Core
3e5c31af7Sopenharmony_ci * ----------------------------------------
4e5c31af7Sopenharmony_ci *
5e5c31af7Sopenharmony_ci * Copyright (c) 2016 The Khronos Group Inc.
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
10e5c31af7Sopenharmony_ci *
11e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
17e5c31af7Sopenharmony_ci * limitations under the License.
18e5c31af7Sopenharmony_ci *
19e5c31af7Sopenharmony_ci *//*!
20e5c31af7Sopenharmony_ci * \file
21e5c31af7Sopenharmony_ci * \brief Linux Vulkan Platform.
22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
23e5c31af7Sopenharmony_ci
24e5c31af7Sopenharmony_ci#include "tcuLnxVulkanPlatform.hpp"
25e5c31af7Sopenharmony_ci#include "tcuLnxPlatform.hpp"
26e5c31af7Sopenharmony_ci#include "vkDefs.hpp"
27e5c31af7Sopenharmony_ci#include "vkDeviceUtil.hpp"
28e5c31af7Sopenharmony_ci#include "vkQueryUtil.hpp"
29e5c31af7Sopenharmony_ci#include "vkWsiPlatform.hpp"
30e5c31af7Sopenharmony_ci#include "gluPlatform.hpp"
31e5c31af7Sopenharmony_ci#include "tcuLibDrm.hpp"
32e5c31af7Sopenharmony_ci#include "tcuLnx.hpp"
33e5c31af7Sopenharmony_ci#include "tcuFunctionLibrary.hpp"
34e5c31af7Sopenharmony_ci#include "deUniquePtr.hpp"
35e5c31af7Sopenharmony_ci#include "deMemory.h"
36e5c31af7Sopenharmony_ci
37e5c31af7Sopenharmony_ci#include <sys/utsname.h>
38e5c31af7Sopenharmony_ci
39e5c31af7Sopenharmony_ciusing de::MovePtr;
40e5c31af7Sopenharmony_ciusing de::UniquePtr;
41e5c31af7Sopenharmony_ci#if DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
42e5c31af7Sopenharmony_ciusing tcu::LibDrm;
43e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
44e5c31af7Sopenharmony_ci
45e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_X11)
46e5c31af7Sopenharmony_ci#	include "tcuLnxX11.hpp"
47e5c31af7Sopenharmony_ci#	if defined (DEQP_SUPPORT_XCB)
48e5c31af7Sopenharmony_ci#		include "tcuLnxX11Xcb.hpp"
49e5c31af7Sopenharmony_ci#	endif // DEQP_SUPPORT_XCB
50e5c31af7Sopenharmony_ci#	define X11_DISPLAY ""
51e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_X11
52e5c31af7Sopenharmony_ci
53e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_WAYLAND)
54e5c31af7Sopenharmony_ci#	include "tcuLnxWayland.hpp"
55e5c31af7Sopenharmony_ci#	define WAYLAND_DISPLAY DE_NULL
56e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_WAYLAND
57e5c31af7Sopenharmony_ci
58e5c31af7Sopenharmony_ci#if !defined(DEQP_VULKAN_LIBRARY_PATH)
59e5c31af7Sopenharmony_ci#   define DEQP_VULKAN_LIBRARY_PATH "libvulkan.so.1"
60e5c31af7Sopenharmony_ci#endif
61e5c31af7Sopenharmony_ci
62e5c31af7Sopenharmony_cinamespace tcu
63e5c31af7Sopenharmony_ci{
64e5c31af7Sopenharmony_cinamespace lnx
65e5c31af7Sopenharmony_ci{
66e5c31af7Sopenharmony_ci
67e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_X11)
68e5c31af7Sopenharmony_ci
69e5c31af7Sopenharmony_ciclass VulkanWindowXlib : public vk::wsi::XlibWindowInterface
70e5c31af7Sopenharmony_ci{
71e5c31af7Sopenharmony_cipublic:
72e5c31af7Sopenharmony_ci	VulkanWindowXlib (MovePtr<x11::XlibWindow> window)
73e5c31af7Sopenharmony_ci		: vk::wsi::XlibWindowInterface	(vk::pt::XlibWindow(window->getXID()))
74e5c31af7Sopenharmony_ci		, m_window						(window)
75e5c31af7Sopenharmony_ci	{
76e5c31af7Sopenharmony_ci	}
77e5c31af7Sopenharmony_ci
78e5c31af7Sopenharmony_ci	void setVisible(bool visible)
79e5c31af7Sopenharmony_ci	{
80e5c31af7Sopenharmony_ci		m_window->setVisibility(visible);
81e5c31af7Sopenharmony_ci	}
82e5c31af7Sopenharmony_ci
83e5c31af7Sopenharmony_ci	void resize (const UVec2& newSize)
84e5c31af7Sopenharmony_ci	{
85e5c31af7Sopenharmony_ci		m_window->setDimensions((int)newSize.x(), (int)newSize.y());
86e5c31af7Sopenharmony_ci	}
87e5c31af7Sopenharmony_ci
88e5c31af7Sopenharmony_ci	void setMinimized(bool minimized)
89e5c31af7Sopenharmony_ci	{
90e5c31af7Sopenharmony_ci		DE_UNREF(minimized);
91e5c31af7Sopenharmony_ci		TCU_THROW(NotSupportedError, "Minimized on X11 is not implemented");
92e5c31af7Sopenharmony_ci	}
93e5c31af7Sopenharmony_ci
94e5c31af7Sopenharmony_ciprivate:
95e5c31af7Sopenharmony_ci	UniquePtr<x11::XlibWindow>	m_window;
96e5c31af7Sopenharmony_ci};
97e5c31af7Sopenharmony_ci
98e5c31af7Sopenharmony_ciclass VulkanDisplayXlib : public vk::wsi::XlibDisplayInterface
99e5c31af7Sopenharmony_ci{
100e5c31af7Sopenharmony_cipublic:
101e5c31af7Sopenharmony_ci	VulkanDisplayXlib (MovePtr<x11::DisplayBase> display)
102e5c31af7Sopenharmony_ci		: vk::wsi::XlibDisplayInterface	(vk::pt::XlibDisplayPtr(((x11::XlibDisplay*)display.get())->getXDisplay()))
103e5c31af7Sopenharmony_ci		, m_display	(display)
104e5c31af7Sopenharmony_ci	{
105e5c31af7Sopenharmony_ci	}
106e5c31af7Sopenharmony_ci
107e5c31af7Sopenharmony_ci	vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
108e5c31af7Sopenharmony_ci	{
109e5c31af7Sopenharmony_ci		x11::XlibDisplay*	instance	= (x11::XlibDisplay*)(m_display.get());
110e5c31af7Sopenharmony_ci		const deUint32		height		= !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
111e5c31af7Sopenharmony_ci		const deUint32		width		= !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
112e5c31af7Sopenharmony_ci		return new VulkanWindowXlib(MovePtr<x11::XlibWindow>(new x11::XlibWindow(*instance, (int)width, (int)height, instance->getVisual(0))));
113e5c31af7Sopenharmony_ci	}
114e5c31af7Sopenharmony_ci
115e5c31af7Sopenharmony_ciprivate:
116e5c31af7Sopenharmony_ci	MovePtr<x11::DisplayBase> m_display;
117e5c31af7Sopenharmony_ci};
118e5c31af7Sopenharmony_ci
119e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_X11
120e5c31af7Sopenharmony_ci
121e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_XCB)
122e5c31af7Sopenharmony_ci
123e5c31af7Sopenharmony_ciclass VulkanWindowXcb : public vk::wsi::XcbWindowInterface
124e5c31af7Sopenharmony_ci{
125e5c31af7Sopenharmony_cipublic:
126e5c31af7Sopenharmony_ci	VulkanWindowXcb (MovePtr<x11::XcbWindow> window)
127e5c31af7Sopenharmony_ci		: vk::wsi::XcbWindowInterface	(vk::pt::XcbWindow(window->getXID()))
128e5c31af7Sopenharmony_ci		, m_window						(window)
129e5c31af7Sopenharmony_ci	{
130e5c31af7Sopenharmony_ci	}
131e5c31af7Sopenharmony_ci
132e5c31af7Sopenharmony_ci	void setVisible(bool visible)
133e5c31af7Sopenharmony_ci	{
134e5c31af7Sopenharmony_ci		m_window->setVisibility(visible);
135e5c31af7Sopenharmony_ci	}
136e5c31af7Sopenharmony_ci
137e5c31af7Sopenharmony_ci	void resize (const UVec2& newSize)
138e5c31af7Sopenharmony_ci	{
139e5c31af7Sopenharmony_ci		m_window->setDimensions((int)newSize.x(), (int)newSize.y());
140e5c31af7Sopenharmony_ci	}
141e5c31af7Sopenharmony_ci
142e5c31af7Sopenharmony_ci	void setMinimized(bool minimized)
143e5c31af7Sopenharmony_ci	{
144e5c31af7Sopenharmony_ci		DE_UNREF(minimized);
145e5c31af7Sopenharmony_ci		TCU_THROW(NotSupportedError, "Minimized on xcb is not implemented");
146e5c31af7Sopenharmony_ci	}
147e5c31af7Sopenharmony_ci
148e5c31af7Sopenharmony_ciprivate:
149e5c31af7Sopenharmony_ci	UniquePtr<x11::XcbWindow>	m_window;
150e5c31af7Sopenharmony_ci};
151e5c31af7Sopenharmony_ci
152e5c31af7Sopenharmony_ciclass VulkanDisplayXcb : public vk::wsi::XcbDisplayInterface
153e5c31af7Sopenharmony_ci{
154e5c31af7Sopenharmony_cipublic:
155e5c31af7Sopenharmony_ci	VulkanDisplayXcb (MovePtr<x11::DisplayBase> display)
156e5c31af7Sopenharmony_ci		: vk::wsi::XcbDisplayInterface	(vk::pt::XcbConnectionPtr(((x11::XcbDisplay*)display.get())->getConnection()))
157e5c31af7Sopenharmony_ci		, m_display		(display)
158e5c31af7Sopenharmony_ci	{
159e5c31af7Sopenharmony_ci	}
160e5c31af7Sopenharmony_ci
161e5c31af7Sopenharmony_ci	vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
162e5c31af7Sopenharmony_ci	{
163e5c31af7Sopenharmony_ci		x11::XcbDisplay*	instance	= (x11::XcbDisplay*)(m_display.get());
164e5c31af7Sopenharmony_ci		const deUint32		height		= !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
165e5c31af7Sopenharmony_ci		const deUint32		width		= !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
166e5c31af7Sopenharmony_ci		return new VulkanWindowXcb(MovePtr<x11::XcbWindow>(new x11::XcbWindow(*instance, (int)width, (int)height, DE_NULL)));
167e5c31af7Sopenharmony_ci	}
168e5c31af7Sopenharmony_ci
169e5c31af7Sopenharmony_ciprivate:
170e5c31af7Sopenharmony_ci	MovePtr<x11::DisplayBase> m_display;
171e5c31af7Sopenharmony_ci};
172e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_XCB
173e5c31af7Sopenharmony_ci
174e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_WAYLAND)
175e5c31af7Sopenharmony_ciclass VulkanWindowWayland : public vk::wsi::WaylandWindowInterface
176e5c31af7Sopenharmony_ci{
177e5c31af7Sopenharmony_cipublic:
178e5c31af7Sopenharmony_ci	VulkanWindowWayland (MovePtr<wayland::Window> window)
179e5c31af7Sopenharmony_ci		: vk::wsi::WaylandWindowInterface	(vk::pt::WaylandSurfacePtr(window->getSurface()))
180e5c31af7Sopenharmony_ci		, m_window							(window)
181e5c31af7Sopenharmony_ci	{
182e5c31af7Sopenharmony_ci	}
183e5c31af7Sopenharmony_ci
184e5c31af7Sopenharmony_ci	void setVisible(bool visible)
185e5c31af7Sopenharmony_ci	{
186e5c31af7Sopenharmony_ci		m_window->setVisibility(visible);
187e5c31af7Sopenharmony_ci	}
188e5c31af7Sopenharmony_ci
189e5c31af7Sopenharmony_ci	void resize (const UVec2& newSize)
190e5c31af7Sopenharmony_ci	{
191e5c31af7Sopenharmony_ci		m_window->setDimensions((int)newSize.x(), (int)newSize.y());
192e5c31af7Sopenharmony_ci	}
193e5c31af7Sopenharmony_ci
194e5c31af7Sopenharmony_ci	void setMinimized(bool minimized)
195e5c31af7Sopenharmony_ci	{
196e5c31af7Sopenharmony_ci		DE_UNREF(minimized);
197e5c31af7Sopenharmony_ci		TCU_THROW(NotSupportedError, "Minimized on wayland is not implemented");
198e5c31af7Sopenharmony_ci	}
199e5c31af7Sopenharmony_ci
200e5c31af7Sopenharmony_ciprivate:
201e5c31af7Sopenharmony_ci	UniquePtr<wayland::Window>	m_window;
202e5c31af7Sopenharmony_ci};
203e5c31af7Sopenharmony_ci
204e5c31af7Sopenharmony_ciclass VulkanDisplayWayland : public vk::wsi::WaylandDisplayInterface
205e5c31af7Sopenharmony_ci{
206e5c31af7Sopenharmony_cipublic:
207e5c31af7Sopenharmony_ci	VulkanDisplayWayland (MovePtr<wayland::Display> display)
208e5c31af7Sopenharmony_ci		: vk::wsi::WaylandDisplayInterface	(vk::pt::WaylandDisplayPtr(display->getDisplay()))
209e5c31af7Sopenharmony_ci		, m_display		(display)
210e5c31af7Sopenharmony_ci	{
211e5c31af7Sopenharmony_ci	}
212e5c31af7Sopenharmony_ci
213e5c31af7Sopenharmony_ci	vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
214e5c31af7Sopenharmony_ci	{
215e5c31af7Sopenharmony_ci		const deUint32	height		= !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
216e5c31af7Sopenharmony_ci		const deUint32	width		= !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
217e5c31af7Sopenharmony_ci		return new VulkanWindowWayland(MovePtr<wayland::Window>(new wayland::Window(*m_display, (int)width, (int)height)));
218e5c31af7Sopenharmony_ci	}
219e5c31af7Sopenharmony_ci
220e5c31af7Sopenharmony_ciprivate:
221e5c31af7Sopenharmony_ci	MovePtr<wayland::Display> m_display;
222e5c31af7Sopenharmony_ci};
223e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_WAYLAND
224e5c31af7Sopenharmony_ci
225e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_HEADLESS)
226e5c31af7Sopenharmony_ci
227e5c31af7Sopenharmony_cistruct VulkanWindowHeadless : public vk::wsi::Window
228e5c31af7Sopenharmony_ci{
229e5c31af7Sopenharmony_cipublic:
230e5c31af7Sopenharmony_ci	void resize (const UVec2&)
231e5c31af7Sopenharmony_ci	{
232e5c31af7Sopenharmony_ci	}
233e5c31af7Sopenharmony_ci};
234e5c31af7Sopenharmony_ci
235e5c31af7Sopenharmony_ciclass VulkanDisplayHeadless : public vk::wsi::Display
236e5c31af7Sopenharmony_ci{
237e5c31af7Sopenharmony_cipublic:
238e5c31af7Sopenharmony_ci	VulkanDisplayHeadless ()
239e5c31af7Sopenharmony_ci	{
240e5c31af7Sopenharmony_ci	}
241e5c31af7Sopenharmony_ci
242e5c31af7Sopenharmony_ci	vk::wsi::Window* createWindow (const Maybe<UVec2>&) const
243e5c31af7Sopenharmony_ci	{
244e5c31af7Sopenharmony_ci		return new VulkanWindowHeadless();
245e5c31af7Sopenharmony_ci	}
246e5c31af7Sopenharmony_ci};
247e5c31af7Sopenharmony_ci
248e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_HEADLESS
249e5c31af7Sopenharmony_ci
250e5c31af7Sopenharmony_ci#if DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
251e5c31af7Sopenharmony_ci
252e5c31af7Sopenharmony_cistruct VulkanWindowDirectDrm : public vk::wsi::Window
253e5c31af7Sopenharmony_ci{
254e5c31af7Sopenharmony_cipublic:
255e5c31af7Sopenharmony_ci	void resize (const UVec2&)
256e5c31af7Sopenharmony_ci	{
257e5c31af7Sopenharmony_ci	}
258e5c31af7Sopenharmony_ci};
259e5c31af7Sopenharmony_ci
260e5c31af7Sopenharmony_ciclass VulkanDisplayDirectDrm : public vk::wsi::DirectDrmDisplayInterface
261e5c31af7Sopenharmony_ci{
262e5c31af7Sopenharmony_cipublic:
263e5c31af7Sopenharmony_ci	VulkanDisplayDirectDrm (void)
264e5c31af7Sopenharmony_ci	{
265e5c31af7Sopenharmony_ci	}
266e5c31af7Sopenharmony_ci
267e5c31af7Sopenharmony_ci	vk::wsi::Window* createWindow (const Maybe<UVec2>&) const override
268e5c31af7Sopenharmony_ci	{
269e5c31af7Sopenharmony_ci		return new VulkanWindowDirectDrm();
270e5c31af7Sopenharmony_ci	}
271e5c31af7Sopenharmony_ci
272e5c31af7Sopenharmony_ci	void initializeDisplay (const vk::InstanceInterface& vki, vk::VkInstance instance, const tcu::CommandLine& cmdLine) override
273e5c31af7Sopenharmony_ci	{
274e5c31af7Sopenharmony_ci		if (m_initialized)
275e5c31af7Sopenharmony_ci			return;
276e5c31af7Sopenharmony_ci
277e5c31af7Sopenharmony_ci		vk::VkPhysicalDevice physDevice = vk::chooseDevice(vki, instance, cmdLine);
278e5c31af7Sopenharmony_ci
279e5c31af7Sopenharmony_ci		/* Get a Drm fd that matches the device. */
280e5c31af7Sopenharmony_ci
281e5c31af7Sopenharmony_ci		vk::VkPhysicalDeviceProperties2			deviceProperties2;
282e5c31af7Sopenharmony_ci		vk::VkPhysicalDeviceDrmPropertiesEXT	deviceDrmProperties;
283e5c31af7Sopenharmony_ci
284e5c31af7Sopenharmony_ci		deMemset(&deviceDrmProperties, 0, sizeof(deviceDrmProperties));
285e5c31af7Sopenharmony_ci		deviceDrmProperties.sType = vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT;
286e5c31af7Sopenharmony_ci		deviceDrmProperties.pNext = DE_NULL;
287e5c31af7Sopenharmony_ci
288e5c31af7Sopenharmony_ci		deMemset(&deviceProperties2, 0, sizeof(deviceProperties2));
289e5c31af7Sopenharmony_ci		deviceProperties2.sType = vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
290e5c31af7Sopenharmony_ci		deviceProperties2.pNext = &deviceDrmProperties;
291e5c31af7Sopenharmony_ci
292e5c31af7Sopenharmony_ci		vki.getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
293e5c31af7Sopenharmony_ci
294e5c31af7Sopenharmony_ci		if (!deviceDrmProperties.hasPrimary)
295e5c31af7Sopenharmony_ci			TCU_THROW(NotSupportedError, "No DRM primary device.");
296e5c31af7Sopenharmony_ci
297e5c31af7Sopenharmony_ci		LibDrm libDrm;
298e5c31af7Sopenharmony_ci		int numDrmDevices;
299e5c31af7Sopenharmony_ci		drmDevicePtr* drmDevices = libDrm.getDevices(&numDrmDevices);
300e5c31af7Sopenharmony_ci		const char* drmNode = libDrm.findDeviceNode(drmDevices, numDrmDevices, deviceDrmProperties.primaryMajor, deviceDrmProperties.primaryMinor);
301e5c31af7Sopenharmony_ci
302e5c31af7Sopenharmony_ci		if (!drmNode)
303e5c31af7Sopenharmony_ci			TCU_THROW(NotSupportedError, "No DRM node.");
304e5c31af7Sopenharmony_ci
305e5c31af7Sopenharmony_ci		m_fdPtr = libDrm.openFd(drmNode).move();
306e5c31af7Sopenharmony_ci		if (!m_fdPtr)
307e5c31af7Sopenharmony_ci			TCU_THROW(NotSupportedError, "Could not open DRM.");
308e5c31af7Sopenharmony_ci		int fd = *m_fdPtr;
309e5c31af7Sopenharmony_ci
310e5c31af7Sopenharmony_ci		/* Get a connector to the display. */
311e5c31af7Sopenharmony_ci
312e5c31af7Sopenharmony_ci		LibDrm::ResPtr res = libDrm.getResources(fd);
313e5c31af7Sopenharmony_ci		if (!res)
314e5c31af7Sopenharmony_ci			TCU_THROW(NotSupportedError, "Could not get DRM resources.");
315e5c31af7Sopenharmony_ci
316e5c31af7Sopenharmony_ci		deUint32 connectorId = 0;
317e5c31af7Sopenharmony_ci		for (int i = 0; i < res->count_connectors; ++i) {
318e5c31af7Sopenharmony_ci			LibDrm::ConnectorPtr conn = libDrm.getConnector(fd, res->connectors[i]);
319e5c31af7Sopenharmony_ci
320e5c31af7Sopenharmony_ci			if (conn && conn->connection == DRM_MODE_CONNECTED) {
321e5c31af7Sopenharmony_ci				connectorId = res->connectors[i];
322e5c31af7Sopenharmony_ci				break;
323e5c31af7Sopenharmony_ci			}
324e5c31af7Sopenharmony_ci		}
325e5c31af7Sopenharmony_ci		if (!connectorId)
326e5c31af7Sopenharmony_ci			TCU_THROW(NotSupportedError, "Could not find a DRM connector.");
327e5c31af7Sopenharmony_ci
328e5c31af7Sopenharmony_ci		/* Get and acquire the display for the connector. */
329e5c31af7Sopenharmony_ci
330e5c31af7Sopenharmony_ci		vk::VkDisplayKHR* display = const_cast<vk::VkDisplayKHR*>(&m_native);
331e5c31af7Sopenharmony_ci		VK_CHECK_SUPPORTED(vki.getDrmDisplayEXT(physDevice, fd, connectorId, display));
332e5c31af7Sopenharmony_ci
333e5c31af7Sopenharmony_ci		if (m_native == DE_NULL)
334e5c31af7Sopenharmony_ci			TCU_THROW(NotSupportedError, "vkGetDrmDisplayEXT did not set display.");
335e5c31af7Sopenharmony_ci
336e5c31af7Sopenharmony_ci		VK_CHECK_SUPPORTED(vki.acquireDrmDisplayEXT(physDevice, fd, m_native));
337e5c31af7Sopenharmony_ci		m_initialized = true;
338e5c31af7Sopenharmony_ci	}
339e5c31af7Sopenharmony_ci
340e5c31af7Sopenharmony_ci	MovePtr<LibDrm::FdPtr::element_type, LibDrm::FdPtr::deleter_type> m_fdPtr;
341e5c31af7Sopenharmony_ci	bool m_initialized = false;
342e5c31af7Sopenharmony_ci};
343e5c31af7Sopenharmony_ci
344e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
345e5c31af7Sopenharmony_ci
346e5c31af7Sopenharmony_ciclass VulkanLibrary : public vk::Library
347e5c31af7Sopenharmony_ci{
348e5c31af7Sopenharmony_cipublic:
349e5c31af7Sopenharmony_ci	VulkanLibrary (const char* libraryPath)
350e5c31af7Sopenharmony_ci		: m_library	(libraryPath != DE_NULL ? libraryPath : DEQP_VULKAN_LIBRARY_PATH)
351e5c31af7Sopenharmony_ci		, m_driver	(m_library)
352e5c31af7Sopenharmony_ci	{
353e5c31af7Sopenharmony_ci	}
354e5c31af7Sopenharmony_ci
355e5c31af7Sopenharmony_ci	const vk::PlatformInterface&	getPlatformInterface	(void) const
356e5c31af7Sopenharmony_ci	{
357e5c31af7Sopenharmony_ci		return m_driver;
358e5c31af7Sopenharmony_ci	}
359e5c31af7Sopenharmony_ci
360e5c31af7Sopenharmony_ci	const tcu::FunctionLibrary&		getFunctionLibrary		(void) const
361e5c31af7Sopenharmony_ci	{
362e5c31af7Sopenharmony_ci		return m_library;
363e5c31af7Sopenharmony_ci	}
364e5c31af7Sopenharmony_ci
365e5c31af7Sopenharmony_ciprivate:
366e5c31af7Sopenharmony_ci	const DynamicFunctionLibrary	m_library;
367e5c31af7Sopenharmony_ci	const vk::PlatformDriver		m_driver;
368e5c31af7Sopenharmony_ci};
369e5c31af7Sopenharmony_ci
370e5c31af7Sopenharmony_ciVulkanPlatform::VulkanPlatform (EventState& eventState)
371e5c31af7Sopenharmony_ci	: m_eventState(eventState)
372e5c31af7Sopenharmony_ci{
373e5c31af7Sopenharmony_ci}
374e5c31af7Sopenharmony_ci
375e5c31af7Sopenharmony_civk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
376e5c31af7Sopenharmony_ci{
377e5c31af7Sopenharmony_ci	if (!hasDisplay(wsiType))
378e5c31af7Sopenharmony_ci	{
379e5c31af7Sopenharmony_ci	    throw NotSupportedError("This display type is not available: ", NULL, __FILE__, __LINE__);
380e5c31af7Sopenharmony_ci	}
381e5c31af7Sopenharmony_ci
382e5c31af7Sopenharmony_ci	switch(wsiType)
383e5c31af7Sopenharmony_ci	{
384e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_X11)
385e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_XLIB:
386e5c31af7Sopenharmony_ci		return new VulkanDisplayXlib(MovePtr<x11::DisplayBase>(new x11::XlibDisplay(m_eventState,X11_DISPLAY)));
387e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_X11
388e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_XCB)
389e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_XCB:
390e5c31af7Sopenharmony_ci		return new VulkanDisplayXcb(MovePtr<x11::DisplayBase>(new x11::XcbDisplay(m_eventState,X11_DISPLAY)));
391e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_XCB
392e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_WAYLAND)
393e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_WAYLAND:
394e5c31af7Sopenharmony_ci		return new VulkanDisplayWayland(MovePtr<wayland::Display>(new wayland::Display(m_eventState, WAYLAND_DISPLAY)));
395e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_WAYLAND
396e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_HEADLESS)
397e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_HEADLESS:
398e5c31af7Sopenharmony_ci		return new VulkanDisplayHeadless();
399e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_HEADLESS
400e5c31af7Sopenharmony_ci#if DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
401e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_DIRECT_DRM:
402e5c31af7Sopenharmony_ci		return new VulkanDisplayDirectDrm();
403e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
404e5c31af7Sopenharmony_ci
405e5c31af7Sopenharmony_ci	default:
406e5c31af7Sopenharmony_ci		TCU_THROW(NotSupportedError, "WSI type not supported");
407e5c31af7Sopenharmony_ci
408e5c31af7Sopenharmony_ci	}
409e5c31af7Sopenharmony_ci}
410e5c31af7Sopenharmony_cibool VulkanPlatform::hasDisplay (vk::wsi::Type wsiType) const
411e5c31af7Sopenharmony_ci{
412e5c31af7Sopenharmony_ci	switch(wsiType)
413e5c31af7Sopenharmony_ci	{
414e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_X11)
415e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_XLIB:
416e5c31af7Sopenharmony_ci		return x11::XlibDisplay::hasDisplay(X11_DISPLAY);
417e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_X11
418e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_XCB)
419e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_XCB:
420e5c31af7Sopenharmony_ci		return x11::XcbDisplay::hasDisplay(X11_DISPLAY);
421e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_XCB
422e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_WAYLAND)
423e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_WAYLAND:
424e5c31af7Sopenharmony_ci		return wayland::Display::hasDisplay(WAYLAND_DISPLAY);
425e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_WAYLAND
426e5c31af7Sopenharmony_ci#if defined (DEQP_SUPPORT_HEADLESS)
427e5c31af7Sopenharmony_ci       case vk::wsi::TYPE_HEADLESS:
428e5c31af7Sopenharmony_ci               return true;
429e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_HEADLESS
430e5c31af7Sopenharmony_ci#if DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
431e5c31af7Sopenharmony_ci	case vk::wsi::TYPE_DIRECT_DRM:
432e5c31af7Sopenharmony_ci		return true;
433e5c31af7Sopenharmony_ci#endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
434e5c31af7Sopenharmony_ci	default:
435e5c31af7Sopenharmony_ci		return false;
436e5c31af7Sopenharmony_ci
437e5c31af7Sopenharmony_ci	}
438e5c31af7Sopenharmony_ci}
439e5c31af7Sopenharmony_ci
440e5c31af7Sopenharmony_civk::Library* VulkanPlatform::createLibrary (LibraryType libraryType, const char* libraryPath) const
441e5c31af7Sopenharmony_ci{
442e5c31af7Sopenharmony_ci	switch(libraryType)
443e5c31af7Sopenharmony_ci	{
444e5c31af7Sopenharmony_ci		case LIBRARY_TYPE_VULKAN:						return new VulkanLibrary(libraryPath);
445e5c31af7Sopenharmony_ci
446e5c31af7Sopenharmony_ci		default: TCU_THROW(InternalError, "Unknown library type requested");
447e5c31af7Sopenharmony_ci	}
448e5c31af7Sopenharmony_ci}
449e5c31af7Sopenharmony_ci
450e5c31af7Sopenharmony_civoid VulkanPlatform::describePlatform (std::ostream& dst) const
451e5c31af7Sopenharmony_ci{
452e5c31af7Sopenharmony_ci	utsname		sysInfo;
453e5c31af7Sopenharmony_ci	deMemset(&sysInfo, 0, sizeof(sysInfo));
454e5c31af7Sopenharmony_ci
455e5c31af7Sopenharmony_ci	if (uname(&sysInfo) != 0)
456e5c31af7Sopenharmony_ci		throw std::runtime_error("uname() failed");
457e5c31af7Sopenharmony_ci
458e5c31af7Sopenharmony_ci	dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
459e5c31af7Sopenharmony_ci	dst << "CPU: " << sysInfo.machine << "\n";
460e5c31af7Sopenharmony_ci}
461e5c31af7Sopenharmony_ci
462e5c31af7Sopenharmony_ci} // linux
463e5c31af7Sopenharmony_ci} // tcu
464e5c31af7Sopenharmony_ci
465