VulkanPlatform for OSX
authorDzmitry Malyshau <dmalyshau@mozilla.com>
Fri, 2 Mar 2018 19:12:15 +0000 (14:12 -0500)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Sun, 22 Apr 2018 18:48:01 +0000 (14:48 -0400)
The change modularizes the OSX platform framework by splitting the GL
platform implementation out (into tcu::OSXGLPlatform) and adding a
basic Vulkan platform implementation (in tcu::osx::VulkanPlatform).
It is currently missing the WSI integration, and the memory limits may
need to be revised in follow-ups. This change allows the CTS to be run
against a Vulkan portability library on MacOS.

Components: Framework

Change-Id: I67eb9af5b97de701b4188aedcaca7485276d9001

framework/platform/CMakeLists.txt
framework/platform/osx/tcuOSXPlatform.cpp
framework/platform/osx/tcuOSXPlatform.hpp
framework/platform/osx/tcuOSXVulkanPlatform.cpp [new file with mode: 0644]
framework/platform/osx/tcuOSXVulkanPlatform.hpp [new file with mode: 0644]

index 77a5447..69e2f03 100644 (file)
@@ -130,6 +130,8 @@ if (NOT DEFINED TCUTIL_PLATFORM_SRCS)
                set(TCUTIL_PLATFORM_SRCS
                        osx/tcuOSXPlatform.cpp
                        osx/tcuOSXPlatform.hpp
+                       osx/tcuOSXVulkanPlatform.cpp
+                       osx/tcuOSXVulkanPlatform.hpp
                        )
 
        else ()
index 39ce626..d805852 100644 (file)
  *//*--------------------------------------------------------------------*/
 
 #include "tcuOSXPlatform.hpp"
+#include "tcuRenderTarget.hpp"
+
+#include "tcuOSXVulkanPlatform.hpp"
+
+#include "gluDefs.hpp"
+#include "gluPlatform.hpp"
 #include "gluRenderContext.hpp"
 #include "gluRenderConfig.hpp"
-#include "tcuRenderTarget.hpp"
 #include "glwFunctions.hpp"
 #include "glwInitFunctions.hpp"
 #include "deDynamicLibrary.hpp"
 #include "glwEnums.hpp"
-#include "gluDefs.hpp"
 
 #include <string>
 
 namespace tcu
 {
 
+class CGLRenderContext : public glu::RenderContext
+{
+public:
+                                                               CGLRenderContext                (const glu::RenderConfig& config);
+                                                               ~CGLRenderContext               (void);
+
+       glu::ContextType                        getType                                 (void) const { return m_type;                   }
+       const glw::Functions&           getFunctions                    (void) const { return m_functions;              }
+       const tcu::RenderTarget&        getRenderTarget                 (void) const { return m_renderTarget;   }
+       void                                            postIterate                             (void) {}
+
+private:
+       const glu::ContextType          m_type;
+       CGLContextObj                           m_context;
+       glw::Functions                          m_functions;
+       RenderTarget                            m_renderTarget;
+};
+
+class CGLContextFactory : public glu::ContextFactory
+{
+public:
+       CGLContextFactory (void)
+               : glu::ContextFactory("cgl", "CGL Context (surfaceless, use fbo)")
+       {
+       }
+
+       glu::RenderContext*     createContext (const glu::RenderConfig& config, const tcu::CommandLine&, const glu::RenderContext*) const
+       {
+               return new CGLRenderContext(config);
+       }
+};
+
+class OSXGLPlatform : public glu::Platform
+{
+public:
+       OSXGLPlatform(void)
+       {
+               m_contextFactoryRegistry.registerFactory(new CGLContextFactory());
+       }
+
+       ~OSXGLPlatform(void) {}
+};
+
+class OSXPlatform : public tcu::Platform
+{
+public:
+       OSXPlatform(void)
+               : m_gluPlatform(), m_vkPlatform()
+       {
+       }
+
+       ~OSXPlatform(void)
+       {
+       }
+
+       const glu::Platform&    getGLPlatform   (void) const { return m_gluPlatform; }
+       const vk::Platform&             getVulkanPlatform       (void) const { return m_vkPlatform; }
+
+private:
+       OSXGLPlatform m_gluPlatform;
+       osx::VulkanPlatform m_vkPlatform;
+};
+
 namespace
 {
 
@@ -66,24 +133,6 @@ private:
 
 } // anonymous
 
-class CGLRenderContext : public glu::RenderContext
-{
-public:
-                                                               CGLRenderContext                (const glu::RenderConfig& config);
-                                                               ~CGLRenderContext               (void);
-
-       glu::ContextType                        getType                                 (void) const { return m_type;                   }
-       const glw::Functions&           getFunctions                    (void) const { return m_functions;              }
-       const tcu::RenderTarget&        getRenderTarget                 (void) const { return m_renderTarget;   }
-       void                                            postIterate                             (void) {}
-
-private:
-       const glu::ContextType          m_type;
-       CGLContextObj                           m_context;
-       glw::Functions                          m_functions;
-       RenderTarget                            m_renderTarget;
-};
-
 static CGLOpenGLProfile getCGLProfile (glu::ContextType type)
 {
        if (type.getAPI().getProfile() != glu::PROFILE_CORE)
@@ -172,29 +221,6 @@ CGLRenderContext::~CGLRenderContext (void)
                CGLDestroyContext(m_context);
 }
 
-class CGLContextFactory : public glu::ContextFactory
-{
-public:
-       CGLContextFactory (void)
-               : glu::ContextFactory("cgl", "CGL Context (surfaceless, use fbo)")
-       {
-       }
-
-       glu::RenderContext*     createContext (const glu::RenderConfig& config, const tcu::CommandLine&) const
-       {
-               return new CGLRenderContext(config);
-       }
-};
-
-OSXPlatform::OSXPlatform (void)
-{
-       m_contextFactoryRegistry.registerFactory(new CGLContextFactory());
-}
-
-OSXPlatform::~OSXPlatform (void)
-{
-}
-
 } // tcu
 
 tcu::Platform* createPlatform (void)
index 9764424..bc28479 100644 (file)
  * \brief OS X platform.
  *//*--------------------------------------------------------------------*/
 
-#include "tcuDefs.hpp"
 #include "tcuPlatform.hpp"
-#include "gluPlatform.hpp"
 
-namespace tcu
-{
-
-class OSXPlatform : public tcu::Platform, private glu::Platform
-{
-public:
-                                                       OSXPlatform             (void);
-                                                       ~OSXPlatform    (void);
-
-       const glu::Platform&    getGLPlatform   (void) const { return static_cast<const glu::Platform&>(*this); }
-};
-
-} // tcu
+tcu::Platform* createPlatform (void);
 
 #endif // _TCUOSXPLATFORM_HPP
diff --git a/framework/platform/osx/tcuOSXVulkanPlatform.cpp b/framework/platform/osx/tcuOSXVulkanPlatform.cpp
new file mode 100644 (file)
index 0000000..b65def1
--- /dev/null
@@ -0,0 +1,105 @@
+/*-------------------------------------------------------------------------
+ * drawElements Quality Program Tester Core
+ * ----------------------------------------
+ *
+ * Copyright (c) 2018 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 OSX Vulkan Platform.
+ *//*--------------------------------------------------------------------*/
+
+#include "tcuOSXVulkanPlatform.hpp"
+#include "tcuOSXPlatform.hpp"
+#include "vkWsiPlatform.hpp"
+#include "gluPlatform.hpp"
+#include "tcuFunctionLibrary.hpp"
+#include "deUniquePtr.hpp"
+#include "deMemory.h"
+
+#include <sys/utsname.h>
+
+using de::MovePtr;
+using de::UniquePtr;
+
+namespace tcu
+{
+namespace osx
+{
+
+class VulkanLibrary : public vk::Library
+{
+public:
+       VulkanLibrary (void)
+               : m_library     ("libvulkan.dylib")
+               , m_driver      (m_library)
+       {
+       }
+
+       const vk::PlatformInterface& getPlatformInterface (void) const
+       {
+               return m_driver;
+       }
+
+private:
+       const DynamicFunctionLibrary    m_library;
+       const vk::PlatformDriver                m_driver;
+};
+
+VulkanPlatform::VulkanPlatform ()
+{
+}
+
+vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
+{
+       switch(wsiType)
+       {
+       //TODO: Core Graphics WSI
+       default:
+               TCU_THROW(NotSupportedError, "WSI type not supported");
+
+       };
+}
+
+vk::Library* VulkanPlatform::createLibrary (void) const
+{
+       return new VulkanLibrary();
+}
+
+void VulkanPlatform::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 VulkanPlatform::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;
+}
+
+} // osx
+} // tcu
+
diff --git a/framework/platform/osx/tcuOSXVulkanPlatform.hpp b/framework/platform/osx/tcuOSXVulkanPlatform.hpp
new file mode 100644 (file)
index 0000000..f288425
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef _TCUOSXVULKANPLATFORM_HPP
+#define _TCUOSXVULKANPLATFORM_HPP
+/*-------------------------------------------------------------------------
+ * drawElements Quality Program Tester Core
+ * ----------------------------------------
+ *
+ * Copyright (c) 2018 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 OSX Vulkan Platform.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkWsiPlatform.hpp"
+#include "vkPlatform.hpp"
+
+namespace tcu
+{
+namespace osx
+
+{
+
+class VulkanPlatform : public vk::Platform
+{
+public:
+                                               VulkanPlatform          ();
+       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;
+};
+
+
+} // osx
+} // tcu
+
+#endif // _TCUOSXVULKANPLATFORM_HPP