1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Linux Vulkan Platform.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuLnxVulkanPlatform.hpp"
25 #include "tcuLnxPlatform.hpp"
26 #include "vkWsiPlatform.hpp"
27 #include "gluPlatform.hpp"
29 #include "tcuFunctionLibrary.hpp"
30 #include "deUniquePtr.hpp"
33 #include <sys/utsname.h>
38 #if defined (DEQP_SUPPORT_X11)
39 # include "tcuLnxX11.hpp"
40 # if defined (DEQP_SUPPORT_XCB)
41 # include "tcuLnxX11Xcb.hpp"
42 # endif // DEQP_SUPPORT_XCB
43 #endif // DEQP_SUPPORT_X11
45 #if defined (DEQP_SUPPORT_WAYLAND)
46 # include "tcuLnxWayland.hpp"
47 #endif // DEQP_SUPPORT_WAYLAND
54 #if defined (DEQP_SUPPORT_X11)
56 class VulkanWindowXlib : public vk::wsi::XlibWindowInterface
59 VulkanWindowXlib (MovePtr<x11::XlibWindow> window)
60 : vk::wsi::XlibWindowInterface (vk::pt::XlibWindow(window->getXID()))
65 void resize (const UVec2& newSize)
67 m_window->setDimensions((int)newSize.x(), (int)newSize.y());
71 UniquePtr<x11::XlibWindow> m_window;
74 class VulkanDisplayXlib : public vk::wsi::XlibDisplayInterface
77 VulkanDisplayXlib (MovePtr<x11::DisplayBase> display)
78 : vk::wsi::XlibDisplayInterface (vk::pt::XlibDisplayPtr(((x11::XlibDisplay*)display.get())->getXDisplay()))
83 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
85 x11::XlibDisplay* instance = (x11::XlibDisplay*)(m_display.get());
86 const deUint32 height = !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
87 const deUint32 width = !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
88 return new VulkanWindowXlib(MovePtr<x11::XlibWindow>(new x11::XlibWindow(*instance, (int)width, (int)height, instance->getVisual(0))));
92 MovePtr<x11::DisplayBase> m_display;
95 #endif // DEQP_SUPPORT_X11
97 #if defined (DEQP_SUPPORT_XCB)
99 class VulkanWindowXcb : public vk::wsi::XcbWindowInterface
102 VulkanWindowXcb (MovePtr<x11::XcbWindow> window)
103 : vk::wsi::XcbWindowInterface (vk::pt::XcbWindow(window->getXID()))
108 void resize (const UVec2& newSize)
110 m_window->setDimensions((int)newSize.x(), (int)newSize.y());
114 UniquePtr<x11::XcbWindow> m_window;
117 class VulkanDisplayXcb : public vk::wsi::XcbDisplayInterface
120 VulkanDisplayXcb (MovePtr<x11::DisplayBase> display)
121 : vk::wsi::XcbDisplayInterface (vk::pt::XcbConnectionPtr(((x11::XcbDisplay*)display.get())->getConnection()))
122 , m_display (display)
126 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
128 x11::XcbDisplay* instance = (x11::XcbDisplay*)(m_display.get());
129 const deUint32 height = !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
130 const deUint32 width = !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
131 return new VulkanWindowXcb(MovePtr<x11::XcbWindow>(new x11::XcbWindow(*instance, (int)width, (int)height, DE_NULL)));
135 MovePtr<x11::DisplayBase> m_display;
137 #endif // DEQP_SUPPORT_XCB
139 #if defined (DEQP_SUPPORT_WAYLAND)
140 class VulkanWindowWayland : public vk::wsi::WaylandWindowInterface
143 VulkanWindowWayland (MovePtr<wayland::Window> window)
144 : vk::wsi::WaylandWindowInterface (vk::pt::WaylandSurfacePtr(window->getSurface()))
149 void resize (const UVec2& newSize)
151 m_window->setDimensions((int)newSize.x(), (int)newSize.y());
155 UniquePtr<wayland::Window> m_window;
158 class VulkanDisplayWayland : public vk::wsi::WaylandDisplayInterface
161 VulkanDisplayWayland (MovePtr<wayland::Display> display)
162 : vk::wsi::WaylandDisplayInterface (vk::pt::WaylandDisplayPtr(display->getDisplay()))
163 , m_display (display)
167 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
169 const deUint32 height = !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
170 const deUint32 width = !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
171 return new VulkanWindowWayland(MovePtr<wayland::Window>(new wayland::Window(*m_display, (int)width, (int)height)));
175 MovePtr<wayland::Display> m_display;
177 #endif // DEQP_SUPPORT_WAYLAND
179 class VulkanLibrary : public vk::Library
183 : m_library ("libvulkan.so.1")
184 , m_driver (m_library)
188 const vk::PlatformInterface& getPlatformInterface (void) const
194 const DynamicFunctionLibrary m_library;
195 const vk::PlatformDriver m_driver;
198 VulkanPlatform::VulkanPlatform (EventState& eventState)
199 : m_eventState(eventState)
203 vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
207 #if defined (DEQP_SUPPORT_X11)
208 case vk::wsi::TYPE_XLIB:
209 return new VulkanDisplayXlib(MovePtr<x11::DisplayBase>(new x11::XlibDisplay(m_eventState,"")));
211 #endif // DEQP_SUPPORT_X11
212 #if defined (DEQP_SUPPORT_XCB)
213 case vk::wsi::TYPE_XCB:
214 return new VulkanDisplayXcb(MovePtr<x11::DisplayBase>(new x11::XcbDisplay(m_eventState,"")));
216 #endif // DEQP_SUPPORT_XCB
217 #if defined (DEQP_SUPPORT_WAYLAND)
218 case vk::wsi::TYPE_WAYLAND:
219 return new VulkanDisplayWayland(MovePtr<wayland::Display>(new wayland::Display(m_eventState, DE_NULL)));
221 #endif // DEQP_SUPPORT_WAYLAND
224 TCU_THROW(NotSupportedError, "WSI type not supported");
229 vk::Library* VulkanPlatform::createLibrary (void) const
231 return new VulkanLibrary();
234 void VulkanPlatform::describePlatform (std::ostream& dst) const
237 deMemset(&sysInfo, 0, sizeof(sysInfo));
239 if (uname(&sysInfo) != 0)
240 throw std::runtime_error("uname() failed");
242 dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
243 dst << "CPU: " << sysInfo.machine << "\n";
246 void VulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const
248 limits.totalSystemMemory = 256*1024*1024;
249 limits.totalDeviceLocalMemory = 128*1024*1024;
250 limits.deviceMemoryAllocationGranularity = 64*1024;
251 limits.devicePageSize = 4096;
252 limits.devicePageTableEntrySize = 8;
253 limits.devicePageTableHierarchyLevels = 3;