1/*------------------------------------------------------------------------- 2 * drawElements Quality Program Tester Core 3 * ---------------------------------------- 4 * 5 * Copyright (c) 2016 The Khronos Group Inc. 6 * 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 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 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. 18 * 19 *//*! 20 * \file 21 * \brief X11Vulkan Platform. 22 *//*--------------------------------------------------------------------*/ 23 24#include "tcuX11VulkanPlatform.hpp" 25#include "tcuX11Platform.hpp" 26#include "vkWsiPlatform.hpp" 27#include "gluPlatform.hpp" 28#include "tcuX11.hpp" 29#include "tcuFunctionLibrary.hpp" 30#include "deUniquePtr.hpp" 31#include "deMemory.h" 32 33#include <sys/utsname.h> 34 35using de::MovePtr; 36using de::UniquePtr; 37 38#if defined (DEQP_SUPPORT_XCB) 39#include "tcuX11Xcb.hpp" 40#endif // DEQP_SUPPORT_XCB 41 42namespace tcu 43{ 44namespace x11 45{ 46 47class VulkanWindowXlib : public vk::wsi::XlibWindowInterface 48{ 49public: 50 VulkanWindowXlib (MovePtr<XlibWindow> window) 51 : vk::wsi::XlibWindowInterface (vk::pt::XlibWindow(window->getXID())) 52 , m_window (window) 53 { 54 } 55 56 void resize (const UVec2& newSize) 57 { 58 m_window->setDimensions((int)newSize.x(), (int)newSize.y()); 59 } 60 61private: 62 UniquePtr<XlibWindow> m_window; 63}; 64 65class VulkanDisplayXlib : public vk::wsi::XlibDisplayInterface 66{ 67public: 68 VulkanDisplayXlib (MovePtr<DisplayBase> display) 69 : vk::wsi::XlibDisplayInterface (vk::pt::XlibDisplayPtr(((XlibDisplay*)display.get())->getXDisplay())) 70 , m_display (display) 71 { 72 } 73 74 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const 75 { 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)))); 80 } 81 82private: 83 MovePtr<DisplayBase> m_display; 84}; 85 86#if defined (DEQP_SUPPORT_XCB) 87 88class VulkanWindowXcb : public vk::wsi::XcbWindowInterface 89{ 90public: 91 VulkanWindowXcb (MovePtr<XcbWindow> window) 92 : vk::wsi::XcbWindowInterface (vk::pt::XcbWindow(window->getXID())) 93 , m_window (window) 94 { 95 } 96 97 void resize (const UVec2& newSize) 98 { 99 m_window->setDimensions((int)newSize.x(), (int)newSize.y()); 100 } 101 102private: 103 UniquePtr<XcbWindow> m_window; 104}; 105 106class VulkanDisplayXcb : public vk::wsi::XcbDisplayInterface 107{ 108public: 109 VulkanDisplayXcb (MovePtr<DisplayBase> display) 110 : vk::wsi::XcbDisplayInterface (vk::pt::XcbConnectionPtr(((XcbDisplay*)display.get())->getConnection())) 111 , m_display (display) 112 { 113 } 114 115 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const 116 { 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))); 121 } 122 123private: 124 MovePtr<DisplayBase> m_display; 125}; 126#endif // DEQP_SUPPORT_XCB 127 128class VulkanLibrary : public vk::Library 129{ 130public: 131 VulkanLibrary (void) 132 : m_library ("libvulkan.so.1") 133 , m_driver (m_library) 134 { 135 } 136 137 const vk::PlatformInterface& getPlatformInterface (void) const 138 { 139 return m_driver; 140 } 141 142private: 143 const DynamicFunctionLibrary m_library; 144 const vk::PlatformDriver m_driver; 145}; 146 147VulkanPlatform::VulkanPlatform (EventState& eventState) 148 : m_eventState(eventState) 149{ 150} 151 152vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const 153{ 154 switch(wsiType) 155 { 156 case vk::wsi::TYPE_XLIB: 157 return new VulkanDisplayXlib(MovePtr<DisplayBase>(new XlibDisplay(m_eventState,""))); 158 break; 159#if defined (DEQP_SUPPORT_XCB) 160 case vk::wsi::TYPE_XCB: 161 return new VulkanDisplayXcb(MovePtr<DisplayBase>(new XcbDisplay(m_eventState,""))); 162 break; 163#endif // DEQP_SUPPORT_XCB 164 default: 165 TCU_THROW(NotSupportedError, "WSI type not supported"); 166 167 }; 168} 169 170vk::Library* VulkanPlatform::createLibrary (void) const 171{ 172 return new VulkanLibrary(); 173} 174 175void VulkanPlatform::describePlatform (std::ostream& dst) const 176{ 177 utsname sysInfo; 178 deMemset(&sysInfo, 0, sizeof(sysInfo)); 179 180 if (uname(&sysInfo) != 0) 181 throw std::runtime_error("uname() failed"); 182 183 dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n"; 184 dst << "CPU: " << sysInfo.machine << "\n"; 185} 186 187void VulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const 188{ 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; 195} 196 197} // x11 198} // tcu 199 200