1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2016 The Android Open Source Project
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 Win32 Vulkan platform
22 *//*--------------------------------------------------------------------*/
24 // \todo [2016-01-22 pyry] GetVersionEx() used by getOSInfo() is deprecated.
25 // Find a way to get version info without using deprecated APIs.
26 #pragma warning(disable : 4996)
28 #include "tcuWin32VulkanPlatform.hpp"
29 #include "tcuWin32Window.hpp"
31 #include "tcuFormatUtil.hpp"
32 #include "tcuFunctionLibrary.hpp"
33 #include "tcuVector.hpp"
35 #include "vkWsiPlatform.hpp"
37 #include "deUniquePtr.hpp"
48 DE_STATIC_ASSERT(sizeof(vk::pt::Win32InstanceHandle) == sizeof(HINSTANCE));
49 DE_STATIC_ASSERT(sizeof(vk::pt::Win32WindowHandle) == sizeof(HWND));
51 class VulkanWindow : public vk::wsi::Win32WindowInterface
54 VulkanWindow (MovePtr<win32::Window> window)
55 : vk::wsi::Win32WindowInterface (vk::pt::Win32WindowHandle(window->getHandle()))
60 void resize (const UVec2& newSize)
62 m_window->setSize((int)newSize.x(), (int)newSize.y());
66 UniquePtr<win32::Window> m_window;
69 class VulkanDisplay : public vk::wsi::Win32DisplayInterface
72 VulkanDisplay (HINSTANCE instance)
73 : vk::wsi::Win32DisplayInterface (vk::pt::Win32InstanceHandle(instance))
77 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
79 const HINSTANCE instance = (HINSTANCE)m_native.internal;
80 const deUint32 width = !initialSize ? 400 : initialSize->x();
81 const deUint32 height = !initialSize ? 300 : initialSize->y();
83 return new VulkanWindow(MovePtr<win32::Window>(new win32::Window(instance, (int)width, (int)height)));
87 class VulkanLibrary : public vk::Library
91 : m_library ("vulkan-1.dll")
92 , m_driver (m_library)
96 const vk::PlatformInterface& getPlatformInterface (void) const
102 const tcu::DynamicFunctionLibrary m_library;
103 const vk::PlatformDriver m_driver;
106 VulkanPlatform::VulkanPlatform (HINSTANCE instance)
107 : m_instance(instance)
111 VulkanPlatform::~VulkanPlatform (void)
115 vk::Library* VulkanPlatform::createLibrary (void) const
117 return new VulkanLibrary();
120 const char* getProductTypeName (WORD productType)
124 case VER_NT_DOMAIN_CONTROLLER: return "Windows Server (domain controller)";
125 case VER_NT_SERVER: return "Windows Server";
126 case VER_NT_WORKSTATION: return "Windows NT";
127 default: return DE_NULL;
131 static void getOSInfo (std::ostream& dst)
133 OSVERSIONINFOEX osInfo;
135 deMemset(&osInfo, 0, sizeof(osInfo));
136 osInfo.dwOSVersionInfoSize = (DWORD)sizeof(osInfo);
138 GetVersionEx((OSVERSIONINFO*)&osInfo);
141 const char* const productName = getProductTypeName(osInfo.wProductType);
146 dst << "unknown product " << tcu::toHex(osInfo.wProductType);
149 dst << " " << osInfo.dwMajorVersion << "." << osInfo.dwMinorVersion
150 << ", service pack " << osInfo.wServicePackMajor << "." << osInfo.wServicePackMinor
151 << ", build " << osInfo.dwBuildNumber;
154 const char* getProcessorArchitectureName (WORD arch)
158 case PROCESSOR_ARCHITECTURE_AMD64: return "AMD64";
159 case PROCESSOR_ARCHITECTURE_ARM: return "ARM";
160 case PROCESSOR_ARCHITECTURE_IA64: return "IA64";
161 case PROCESSOR_ARCHITECTURE_INTEL: return "INTEL";
162 case PROCESSOR_ARCHITECTURE_UNKNOWN: return "UNKNOWN";
163 default: return DE_NULL;
167 static void getProcessorInfo (std::ostream& dst)
171 deMemset(&sysInfo, 0, sizeof(sysInfo));
172 GetSystemInfo(&sysInfo);
176 const char* const archName = getProcessorArchitectureName(sysInfo.wProcessorArchitecture);
181 dst << tcu::toHex(sysInfo.wProcessorArchitecture);
184 dst << ", level " << tcu::toHex(sysInfo.wProcessorLevel) << ", revision " << tcu::toHex(sysInfo.wProcessorRevision);
187 void VulkanPlatform::describePlatform (std::ostream& dst) const
194 getProcessorInfo(dst);
198 void VulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const
200 limits.totalSystemMemory = 256*1024*1024;
201 limits.totalDeviceLocalMemory = 128*1024*1024;
202 limits.deviceMemoryAllocationGranularity = 64*1024;
203 limits.devicePageSize = 4096;
204 limits.devicePageTableEntrySize = 8;
205 limits.devicePageTableHierarchyLevels = 3;
208 vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
210 if (wsiType != vk::wsi::TYPE_WIN32)
211 TCU_THROW(NotSupportedError, "WSI type not supported");
213 return new VulkanDisplay(m_instance);