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 X11Vulkan Platform.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuX11VulkanPlatform.hpp"
25 #include "tcuX11Platform.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_XCB)
39 #include "tcuX11Xcb.hpp"
40 #endif // DEQP_SUPPORT_XCB
47 class VulkanWindowXlib : public vk::wsi::XlibWindowInterface
50 VulkanWindowXlib (MovePtr<XlibWindow> window)
51 : vk::wsi::XlibWindowInterface (vk::pt::XlibWindow(window->getXID()))
56 void resize (const UVec2& newSize)
58 m_window->setDimensions((int)newSize.x(), (int)newSize.y());
62 UniquePtr<XlibWindow> m_window;
65 class VulkanDisplayXlib : public vk::wsi::XlibDisplayInterface
68 VulkanDisplayXlib (MovePtr<DisplayBase> display)
69 : vk::wsi::XlibDisplayInterface (vk::pt::XlibDisplayPtr(((XlibDisplay*)display.get())->getXDisplay()))
74 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
76 XlibDisplay* instance = (XlibDisplay*)(m_display.get());
77 const deUint32 height = !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
78 const deUint32 width = !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
79 return new VulkanWindowXlib(MovePtr<XlibWindow>(new XlibWindow(*instance, (int)width, (int)height, instance->getVisual(0))));
83 MovePtr<DisplayBase> m_display;
86 #if defined (DEQP_SUPPORT_XCB)
88 class VulkanWindowXcb : public vk::wsi::XcbWindowInterface
91 VulkanWindowXcb (MovePtr<XcbWindow> window)
92 : vk::wsi::XcbWindowInterface (vk::pt::XcbWindow(window->getXID()))
97 void resize (const UVec2& newSize)
99 m_window->setDimensions((int)newSize.x(), (int)newSize.y());
103 UniquePtr<XcbWindow> m_window;
106 class VulkanDisplayXcb : public vk::wsi::XcbDisplayInterface
109 VulkanDisplayXcb (MovePtr<DisplayBase> display)
110 : vk::wsi::XcbDisplayInterface (vk::pt::XcbConnectionPtr(((XcbDisplay*)display.get())->getConnection()))
111 , m_display (display)
115 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
117 XcbDisplay* instance = (XcbDisplay*)(m_display.get());
118 const deUint32 height = !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
119 const deUint32 width = !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
120 return new VulkanWindowXcb(MovePtr<XcbWindow>(new XcbWindow(*instance, (int)width, (int)height, DE_NULL)));
124 MovePtr<DisplayBase> m_display;
126 #endif // DEQP_SUPPORT_XCB
128 class VulkanLibrary : public vk::Library
132 : m_library ("libvulkan.so.1")
133 , m_driver (m_library)
137 const vk::PlatformInterface& getPlatformInterface (void) const
143 const DynamicFunctionLibrary m_library;
144 const vk::PlatformDriver m_driver;
147 VulkanPlatform::VulkanPlatform (EventState& eventState)
148 : m_eventState(eventState)
152 vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
156 case vk::wsi::TYPE_XLIB:
157 return new VulkanDisplayXlib(MovePtr<DisplayBase>(new XlibDisplay(m_eventState,"")));
159 #if defined (DEQP_SUPPORT_XCB)
160 case vk::wsi::TYPE_XCB:
161 return new VulkanDisplayXcb(MovePtr<DisplayBase>(new XcbDisplay(m_eventState,"")));
163 #endif // DEQP_SUPPORT_XCB
165 TCU_THROW(NotSupportedError, "WSI type not supported");
170 vk::Library* VulkanPlatform::createLibrary (void) const
172 return new VulkanLibrary();
175 void VulkanPlatform::describePlatform (std::ostream& dst) const
178 deMemset(&sysInfo, 0, sizeof(sysInfo));
180 if (uname(&sysInfo) != 0)
181 throw std::runtime_error("uname() failed");
183 dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
184 dst << "CPU: " << sysInfo.machine << "\n";
187 void VulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const
189 limits.totalSystemMemory = 256*1024*1024;
190 limits.totalDeviceLocalMemory = 128*1024*1024;
191 limits.deviceMemoryAllocationGranularity = 64*1024;
192 limits.devicePageSize = 4096;
193 limits.devicePageTableEntrySize = 8;
194 limits.devicePageTableHierarchyLevels = 3;