Fix Vulkan null driver
[platform/upstream/VK-GL-CTS.git] / framework / platform / wayland / tcuWaylandVulkanPlatform.cpp
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 Wayland Vulkan Platform.
22  *//*--------------------------------------------------------------------*/
23
24 #include "tcuWaylandVulkanPlatform.hpp"
25 #include "tcuWaylandPlatform.hpp"
26 #include "vkWsiPlatform.hpp"
27 #include "gluPlatform.hpp"
28 #include "tcuWayland.hpp"
29 #include "tcuFunctionLibrary.hpp"
30 #include "deUniquePtr.hpp"
31 #include "deMemory.h"
32
33 #include <sys/utsname.h>
34
35 using de::MovePtr;
36 using de::UniquePtr;
37
38 namespace tcu
39 {
40 namespace wayland
41 {
42
43 class VulkanWindowWayland : public vk::wsi::WaylandWindowInterface
44 {
45 public:
46         VulkanWindowWayland (MovePtr<wayland::Window> window)
47                 : vk::wsi::WaylandWindowInterface       (vk::pt::WaylandSurfacePtr(window->getSurface()))
48                 , m_window                                                      (window)
49         {
50         }
51
52         void resize (const UVec2& newSize)
53         {
54                 m_window->setDimensions((int)newSize.x(), (int)newSize.y());
55         }
56
57 private:
58         UniquePtr<wayland::Window>      m_window;
59 };
60
61 class VulkanDisplayWayland : public vk::wsi::WaylandDisplayInterface
62 {
63 public:
64         VulkanDisplayWayland (MovePtr<wayland::Display> display)
65                 : vk::wsi::WaylandDisplayInterface      (vk::pt::WaylandDisplayPtr(display->getDisplay()))
66                 , m_display             (display)
67         {
68         }
69
70         vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
71         {
72                 const deUint32  height          = !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
73                 const deUint32  width           = !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
74                 return new VulkanWindowWayland(MovePtr<wayland::Window>(new wayland::Window(*m_display, (int)width, (int)height)));
75         }
76
77 private:
78         MovePtr<wayland::Display> m_display;
79 };
80
81 class VulkanLibrary : public vk::Library
82 {
83 public:
84         VulkanLibrary (void)
85                 : m_library     ("libvulkan.so.1")
86                 , m_driver      (m_library)
87         {
88         }
89
90         const vk::PlatformInterface& getPlatformInterface (void) const
91         {
92                 return m_driver;
93         }
94
95 private:
96         const DynamicFunctionLibrary    m_library;
97         const vk::PlatformDriver                m_driver;
98 };
99
100 WaylandVulkanPlatform::WaylandVulkanPlatform (EventState& eventState)
101         : m_eventState(eventState)
102 {
103 }
104
105 vk::wsi::Display* WaylandVulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
106 {
107         switch(wsiType)
108         {
109         case vk::wsi::TYPE_WAYLAND:
110                 return new VulkanDisplayWayland(MovePtr<Display>(new Display(m_eventState, DE_NULL)));
111                 break;
112         default:
113                 TCU_THROW(NotSupportedError, "WSI type not supported");
114
115         };
116 }
117
118 vk::Library* WaylandVulkanPlatform::createLibrary (void) const
119 {
120         return new VulkanLibrary();
121 }
122
123 void WaylandVulkanPlatform::describePlatform (std::ostream& dst) const
124 {
125         utsname         sysInfo;
126         deMemset(&sysInfo, 0, sizeof(sysInfo));
127
128         if (uname(&sysInfo) != 0)
129                 throw std::runtime_error("uname() failed");
130
131         dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
132         dst << "CPU: " << sysInfo.machine << "\n";
133 }
134
135 void WaylandVulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const
136 {
137         limits.totalSystemMemory                                        = 256*1024*1024;
138         limits.totalDeviceLocalMemory                           = 128*1024*1024;
139         limits.deviceMemoryAllocationGranularity        = 64*1024;
140         limits.devicePageSize                                           = 4096;
141         limits.devicePageTableEntrySize                         = 8;
142         limits.devicePageTableHierarchyLevels           = 3;
143 }
144
145 } // wayland
146 } // tcu
147