Add Vulkan WSI support to the Wayland platform
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 9 Nov 2016 17:38:22 +0000 (09:38 -0800)
committerPyry Haulos <phaulos@google.com>
Fri, 11 Nov 2016 22:45:19 +0000 (17:45 -0500)
Change-Id: I572e30710202cd53d503036310c379f2fd5468a7

framework/platform/wayland/tcuWayland.cpp
framework/platform/wayland/tcuWayland.hpp
framework/platform/wayland/tcuWaylandPlatform.cpp
framework/platform/wayland/tcuWaylandVulkanPlatform.cpp [new file with mode: 0644]
framework/platform/wayland/tcuWaylandVulkanPlatform.hpp [new file with mode: 0644]
targets/wayland/wayland.cmake

index 70640bb..071cbb4 100644 (file)
@@ -34,12 +34,6 @@ namespace tcu
 namespace wayland
 {
 
-enum
-{
-       DEFAULT_WINDOW_WIDTH    = 400,
-       DEFAULT_WINDOW_HEIGHT   = 300
-};
-
 EventState::EventState (void)
        : m_quit(false)
 {
@@ -95,6 +89,9 @@ void Display::handleGlobalRemove (void* data, struct wl_registry* registry, uint
 Display::Display (EventState& eventState, const char* name)
        : m_eventState  (eventState)
        , m_display             (DE_NULL)
+       , m_registry    (DE_NULL)
+       , m_compositor  (DE_NULL)
+       , m_shell               (DE_NULL)
 {
        try
        {
index d4cc94c..2a2468c 100644 (file)
@@ -38,6 +38,12 @@ namespace tcu
 namespace wayland
 {
 
+enum
+{
+       DEFAULT_WINDOW_WIDTH    = 400,
+       DEFAULT_WINDOW_HEIGHT   = 300
+};
+
 class EventState
 {
 public:
@@ -95,6 +101,7 @@ public:
 
        void                                    processEvents                   (void);
        Display&                                getDisplay                              (void) { return m_display; }
+       void*                                   getSurface                              (void) { return m_surface; }
        void*                                   getWindow                               (void) { return m_window; }
 
        void                                    getDimensions                   (int* width, int* height) const;
index 55391b4..bf3f001 100644 (file)
@@ -30,6 +30,7 @@
 #include "gluPlatform.hpp"
 #include "vkPlatform.hpp"
 #include "tcuWayland.hpp"
+#include "tcuWaylandVulkanPlatform.hpp"
 #include "tcuFunctionLibrary.hpp"
 #include "deMemory.h"
 
@@ -49,57 +50,6 @@ public:
        }
 };
 
-class VulkanLibrary : public vk::Library
-{
-public:
-       VulkanLibrary (void)
-               : m_library     ("libvulkan.so.1")
-               , m_driver      (m_library)
-       {
-       }
-
-       const vk::PlatformInterface& getPlatformInterface (void) const
-       {
-               return m_driver;
-       }
-
-private:
-       const tcu::DynamicFunctionLibrary       m_library;
-       const vk::PlatformDriver                        m_driver;
-};
-
-class WaylandVulkanPlatform : public vk::Platform
-{
-public:
-       vk::Library* createLibrary (void) const
-       {
-               return new VulkanLibrary();
-       }
-
-       void describePlatform (std::ostream& dst) const
-       {
-               utsname         sysInfo;
-
-               deMemset(&sysInfo, 0, sizeof(sysInfo));
-
-               if (uname(&sysInfo) != 0)
-                       throw std::runtime_error("uname() failed");
-
-               dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
-               dst << "CPU: " << sysInfo.machine << "\n";
-       }
-
-       void getMemoryLimits (vk::PlatformMemoryLimits& limits) const
-       {
-               limits.totalSystemMemory                                        = 256*1024*1024;
-               limits.totalDeviceLocalMemory                           = 128*1024*1024;
-               limits.deviceMemoryAllocationGranularity        = 64*1024;
-               limits.devicePageSize                                           = 4096;
-               limits.devicePageTableEntrySize                         = 8;
-               limits.devicePageTableHierarchyLevels           = 3;
-       }
-};
-
 class WaylandPlatform : public tcu::Platform
 {
 public:
@@ -119,6 +69,7 @@ private:
 
 WaylandPlatform::WaylandPlatform (void)
        : m_eglPlatform (m_eventState)
+       , m_vkPlatform  (m_eventState)
 {
        m_glPlatform.registerFactory(m_eglPlatform.createContextFactory());
 }
diff --git a/framework/platform/wayland/tcuWaylandVulkanPlatform.cpp b/framework/platform/wayland/tcuWaylandVulkanPlatform.cpp
new file mode 100644 (file)
index 0000000..77b686e
--- /dev/null
@@ -0,0 +1,147 @@
+/*-------------------------------------------------------------------------
+ * drawElements Quality Program Tester Core
+ * ----------------------------------------
+ *
+ * Copyright (c) 2016 The Khronos Group Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *//*!
+ * \file
+ * \brief Wayland Vulkan Platform.
+ *//*--------------------------------------------------------------------*/
+
+#include "tcuWaylandVulkanPlatform.hpp"
+#include "tcuWaylandPlatform.hpp"
+#include "vkWsiPlatform.hpp"
+#include "gluPlatform.hpp"
+#include "tcuWayland.hpp"
+#include "tcuFunctionLibrary.hpp"
+#include "deUniquePtr.hpp"
+#include "deMemory.h"
+
+#include <sys/utsname.h>
+
+using de::MovePtr;
+using de::UniquePtr;
+
+namespace tcu
+{
+namespace wayland
+{
+
+class VulkanWindowWayland : public vk::wsi::WaylandWindowInterface
+{
+public:
+       VulkanWindowWayland (MovePtr<wayland::Window> window)
+               : vk::wsi::WaylandWindowInterface       (vk::pt::WaylandSurfacePtr(window->getSurface()))
+               , m_window                                                      (window)
+       {
+       }
+
+       void resize (const UVec2& newSize)
+       {
+               m_window->setDimensions((int)newSize.x(), (int)newSize.y());
+       }
+
+private:
+       UniquePtr<wayland::Window>      m_window;
+};
+
+class VulkanDisplayWayland : public vk::wsi::WaylandDisplayInterface
+{
+public:
+       VulkanDisplayWayland (MovePtr<wayland::Display> display)
+               : vk::wsi::WaylandDisplayInterface      (vk::pt::WaylandDisplayPtr(display->getDisplay()))
+               , m_display             (display)
+       {
+       }
+
+       vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
+       {
+               const deUint32  height          = !initialSize ? (deUint32)DEFAULT_WINDOW_HEIGHT : initialSize->y();
+               const deUint32  width           = !initialSize ? (deUint32)DEFAULT_WINDOW_WIDTH : initialSize->x();
+               return new VulkanWindowWayland(MovePtr<wayland::Window>(new wayland::Window(*m_display, (int)width, (int)height)));
+       }
+
+private:
+       MovePtr<wayland::Display> m_display;
+};
+
+class VulkanLibrary : public vk::Library
+{
+public:
+       VulkanLibrary (void)
+               : m_library     ("libvulkan.so.1")
+               , m_driver      (m_library)
+       {
+       }
+
+       const vk::PlatformInterface& getPlatformInterface (void) const
+       {
+               return m_driver;
+       }
+
+private:
+       const DynamicFunctionLibrary    m_library;
+       const vk::PlatformDriver                m_driver;
+};
+
+WaylandVulkanPlatform::WaylandVulkanPlatform (EventState& eventState)
+       : m_eventState(eventState)
+{
+}
+
+vk::wsi::Display* WaylandVulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
+{
+       switch(wsiType)
+       {
+       case vk::wsi::TYPE_WAYLAND:
+               return new VulkanDisplayWayland(MovePtr<Display>(new Display(m_eventState, DE_NULL)));
+               break;
+       default:
+               TCU_THROW(NotSupportedError, "WSI type not supported");
+
+       };
+}
+
+vk::Library* WaylandVulkanPlatform::createLibrary (void) const
+{
+       return new VulkanLibrary();
+}
+
+void WaylandVulkanPlatform::describePlatform (std::ostream& dst) const
+{
+       utsname         sysInfo;
+       deMemset(&sysInfo, 0, sizeof(sysInfo));
+
+       if (uname(&sysInfo) != 0)
+               throw std::runtime_error("uname() failed");
+
+       dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
+       dst << "CPU: " << sysInfo.machine << "\n";
+}
+
+void WaylandVulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const
+{
+       limits.totalSystemMemory                                        = 256*1024*1024;
+       limits.totalDeviceLocalMemory                           = 128*1024*1024;
+       limits.deviceMemoryAllocationGranularity        = 64*1024;
+       limits.devicePageSize                                           = 4096;
+       limits.devicePageTableEntrySize                         = 8;
+       limits.devicePageTableHierarchyLevels           = 3;
+}
+
+} // wayland
+} // tcu
+
diff --git a/framework/platform/wayland/tcuWaylandVulkanPlatform.hpp b/framework/platform/wayland/tcuWaylandVulkanPlatform.hpp
new file mode 100644 (file)
index 0000000..dfa5828
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef _TCUWAYLANDVULKANPLATFORM_HPP
+#define _TCUWAYLANDVULKANPLATFORM_HPP
+/*-------------------------------------------------------------------------
+ * drawElements Quality Program Tester Core
+ * ----------------------------------------
+ *
+ * Copyright (c) 2016 The Khronos Group Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *//*!
+ * \file
+ * \brief Wayland Vulkan Platform.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkWsiPlatform.hpp"
+#include "vkPlatform.hpp"
+#include "tcuWayland.hpp"
+
+namespace tcu
+{
+namespace wayland
+{
+
+class WaylandVulkanPlatform : public vk::Platform
+{
+public:
+                                               WaylandVulkanPlatform   (EventState& eventState);
+       vk::wsi::Display*       createWsiDisplay                (vk::wsi::Type wsiType) const;
+       vk::Library*            createLibrary                   (void) const;
+       void                            describePlatform                (std::ostream& dst) const;
+       void                            getMemoryLimits                 (vk::PlatformMemoryLimits& limits) const;
+
+private :
+        EventState&            m_eventState;
+};
+
+
+} // wayland
+} // tcu
+
+#endif // _TCUWAYLANDVULKANPLATFORM_HPP
index 4d1ca3d..3de6e7c 100644 (file)
@@ -43,4 +43,6 @@ set(TCUTIL_PLATFORM_SRCS
        wayland/tcuWaylandPlatform.hpp
        wayland/tcuWaylandEglPlatform.cpp
        wayland/tcuWaylandEglPlatform.hpp
+       wayland/tcuWaylandVulkanPlatform.cpp
+       wayland/tcuWaylandVulkanPlatform.hpp
        )