瀏覽代碼

Fix the Linux build and move to wayland

Panagiotis Christopoulos Charitos 1 年之前
父節點
當前提交
ebbda6ebbf

+ 1 - 1
AnKi/Core/CMakeLists.txt

@@ -27,7 +27,7 @@ add_library(AnKiCore ${sources} ${headers})
 
 if(SDL)
 	if(LINUX)
-		set(extra_libs X11-xcb pthread dl)
+		set(extra_libs pthread dl)
 	endif()
 
 	set(extra_libs ${extra_libs} SDL2-static)

+ 2 - 4
AnKi/Gr/Vulkan/VkCommon.h

@@ -11,8 +11,7 @@
 #if ANKI_WINDOWING_SYSTEM_HEADLESS
 // Do nothing
 #elif ANKI_OS_LINUX
-#	define VK_USE_PLATFORM_XCB_KHR 1
-#	define VK_USE_PLATFORM_XLIB_KHR 1
+#	define VK_USE_PLATFORM_WAYLAND_KHR 1
 #elif ANKI_OS_WINDOWS
 #	define VK_USE_PLATFORM_WIN32_KHR 1
 #elif ANKI_OS_ANDROID
@@ -52,8 +51,7 @@ ANKI_PURE VkDevice getVkDevice();
 enum class VulkanExtensions : U64
 {
 	kNone = 0,
-	kKHR_xcb_surface = 1u << 1u,
-	kKHR_xlib_surface = 1u << 2u,
+	kKHR_wayland_surface = 1u << 1u,
 	kKHR_win32_surface = 1u << 3u,
 	kKHR_android_surface = 1u << 4u,
 	kEXT_headless_surface = 1u << 5u,

+ 8 - 13
AnKi/Gr/Vulkan/VkGrManager.cpp

@@ -602,15 +602,10 @@ Error GrManagerImpl::initInstance()
 				instExtensions[instExtensionCount++] = VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME;
 			}
 #elif ANKI_OS_LINUX
-			if(extensionName == VK_KHR_XCB_SURFACE_EXTENSION_NAME)
+			if(extensionName == VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME)
 			{
-				m_extensions |= VulkanExtensions::kKHR_xcb_surface;
-				instExtensions[instExtensionCount++] = VK_KHR_XCB_SURFACE_EXTENSION_NAME;
-			}
-			else if(extensionName == VK_KHR_XLIB_SURFACE_EXTENSION_NAME)
-			{
-				m_extensions |= VulkanExtensions::kKHR_xlib_surface;
-				instExtensions[instExtensionCount++] = VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
+				m_extensions |= VulkanExtensions::kKHR_wayland_surface;
+				instExtensions[instExtensionCount++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
 			}
 #elif ANKI_OS_WINDOWS
 			if(extensionName == VK_KHR_WIN32_SURFACE_EXTENSION_NAME)
@@ -641,8 +636,8 @@ Error GrManagerImpl::initInstance()
 		}
 
 		if(!(m_extensions
-			 & (VulkanExtensions::kEXT_headless_surface | VulkanExtensions::kKHR_xcb_surface | VulkanExtensions::kKHR_xlib_surface
-				| VulkanExtensions::kKHR_win32_surface | VulkanExtensions::kKHR_android_surface)))
+			 & (VulkanExtensions::kEXT_headless_surface | VulkanExtensions::kKHR_wayland_surface | VulkanExtensions::kKHR_win32_surface
+				| VulkanExtensions::kKHR_android_surface)))
 		{
 			ANKI_VK_LOGE("Couldn't find suitable surface extension");
 			return Error::kFunctionFailed;
@@ -1813,13 +1808,13 @@ Error GrManagerImpl::initSurface()
 	createInfo.sType = VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT;
 
 	ANKI_VK_CHECK(vkCreateHeadlessSurfaceEXT(m_instance, &createInfo, nullptr, &m_surface));
-
-	m_nativeWindowWidth = NativeWindow::getSingleton().getWidth();
-	m_nativeWindowHeight = NativeWindow::getSingleton().getHeight();
 #else
 #	error Unsupported
 #endif
 
+	m_nativeWindowWidth = NativeWindow::getSingleton().getWidth();
+	m_nativeWindowHeight = NativeWindow::getSingleton().getHeight();
+
 	return Error::kNone;
 }
 

+ 0 - 4
AnKi/Gr/Vulkan/VkGrManager.h

@@ -100,14 +100,12 @@ public:
 		return m_surface;
 	}
 
-#if ANKI_WINDOWING_SYSTEM_HEADLESS
 	void getNativeWindowSize(U32& width, U32& height) const
 	{
 		width = m_nativeWindowWidth;
 		height = m_nativeWindowHeight;
 		ANKI_ASSERT(width && height);
 	}
-#endif
 
 	/// @name Debug report
 	/// @{
@@ -174,10 +172,8 @@ private:
 	};
 
 	VkSurfaceKHR m_surface = VK_NULL_HANDLE;
-#if ANKI_WINDOWING_SYSTEM_HEADLESS
 	U32 m_nativeWindowWidth = 0;
 	U32 m_nativeWindowHeight = 0;
-#endif
 	MicroSwapchainPtr m_crntSwapchain;
 	U8 m_acquiredImageIdx = kMaxU8;
 

+ 13 - 16
AnKi/Gr/Vulkan/VkSwapchainFactory.cpp

@@ -6,6 +6,7 @@
 #include <AnKi/Gr/Vulkan/VkSwapchainFactory.h>
 #include <AnKi/Gr/Vulkan/VkGrManager.h>
 #include <AnKi/Gr/Vulkan/VkTexture.h>
+#include <AnKi/Math/Functions.h>
 
 namespace anki {
 
@@ -35,28 +36,24 @@ Error MicroSwapchain::initInternal()
 
 	// Get the surface size
 	VkSurfaceCapabilitiesKHR surfaceProperties;
+	U32 swapchainImages = 0;
 	U32 surfaceWidth = 0, surfaceHeight = 0;
 	{
 		ANKI_VK_CHECK(
 			vkGetPhysicalDeviceSurfaceCapabilitiesKHR(getGrManagerImpl().getPhysicalDevice(), getGrManagerImpl().getSurface(), &surfaceProperties));
 
-#if ANKI_WINDOWING_SYSTEM_HEADLESS
-		if(surfaceProperties.currentExtent.width != kMaxU32 || surfaceProperties.currentExtent.height != kMaxU32)
+		if(surfaceProperties.currentExtent.width == kMaxU32 && surfaceProperties.currentExtent.height == kMaxU32)
 		{
-			ANKI_VK_LOGE("Was expecting an indication that the surface size will be determined by the extent of a "
-						 "swapchain targeting the surface");
-			return Error::kFunctionFailed;
+			// On some platforms this isn't set for some reason (wayland & headless)
+			getGrManagerImpl().getNativeWindowSize(surfaceWidth, surfaceHeight);
 		}
-		getGrManagerImpl().getNativeWindowSize(surfaceWidth, surfaceHeight);
-#else
-		if(surfaceProperties.currentExtent.width == kMaxU32 || surfaceProperties.currentExtent.height == kMaxU32)
+		else
 		{
-			ANKI_VK_LOGE("Wrong surface size");
-			return Error::kFunctionFailed;
+			surfaceWidth = surfaceProperties.currentExtent.width;
+			surfaceHeight = surfaceProperties.currentExtent.height;
 		}
-		surfaceWidth = surfaceProperties.currentExtent.width;
-		surfaceHeight = surfaceProperties.currentExtent.height;
-#endif
+
+		swapchainImages = max<U32>(surfaceProperties.minImageCount, kMaxFramesInFlight);
 	}
 
 	// Get the surface format
@@ -185,7 +182,7 @@ Error MicroSwapchain::initInternal()
 		VkSwapchainCreateInfoKHR ci = {};
 		ci.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
 		ci.surface = getGrManagerImpl().getSurface();
-		ci.minImageCount = kMaxFramesInFlight;
+		ci.minImageCount = swapchainImages;
 		ci.imageFormat = surfaceFormat;
 		ci.imageColorSpace = colorspace;
 		ci.imageExtent.width = surfaceWidth;
@@ -208,9 +205,9 @@ Error MicroSwapchain::initInternal()
 	{
 		U32 count = 0;
 		ANKI_VK_CHECK(vkGetSwapchainImagesKHR(dev, m_swapchain, &count, nullptr));
-		if(count != kMaxFramesInFlight)
+		if(count != swapchainImages)
 		{
-			ANKI_VK_LOGI("Requested a swapchain with %u images but got one with %u", kMaxFramesInFlight, count);
+			ANKI_VK_LOGI("Requested a swapchain with %u images but got one with %u", swapchainImages, count);
 		}
 
 		m_textures.resize(count);

+ 3 - 3
AnKi/Util/String.h

@@ -14,6 +14,7 @@
 #include <cctype>
 #include <cinttypes> // For PRId8 etc
 #include <cstdarg> // For var args
+#include <cstdlib>
 
 namespace anki {
 
@@ -266,9 +267,8 @@ public:
 
 		if(len > 0)
 		{
-			PtrSize outSize;
-			[[maybe_unused]] const auto err = mbstowcs_s(&outSize, arr, arrSize, m_ptr, len);
-			ANKI_ASSERT(err == 0 && outSize == len + 1);
+			[[maybe_unused]] const PtrSize charsWritten = mbstowcs(arr, m_ptr, arrSize);
+			ANKI_ASSERT(charsWritten == len + 1);
 		}
 		else
 		{

+ 2 - 1
CMakeLists.txt

@@ -302,6 +302,7 @@ endif()
 # SDL
 if(SDL)
 	message("++ Configuring SDL2")
+	option(SDL_X11 OFF)
 	add_subdirectory(ThirdParty/Sdl2)
 	message("++ End configuring SDL2")
 
@@ -461,7 +462,7 @@ if(LINUX)
 	set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} pthread dl)
 
 	if(SDL)
-		set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} X11-xcb)
+		#set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} X11-xcb)
 	endif()
 endif()
 

二進制
ThirdParty/Bin/Linux64/dxc.bin


二進制
ThirdParty/Bin/Linux64/libdxcompiler.so


+ 1 - 1
Tools/Shader/ShaderProgramDependencies.py

@@ -31,7 +31,7 @@ def parse_file(fname):
     file = open(fname, mode="r")
     txt = file.read()
 
-    my_includes = re.findall("\s*#\s*include\ <(.*)>", txt)
+    my_includes = re.findall(r"\s*#\s*include\ <(.*)>", txt)
     agregated_includes = []
 
     for include in my_includes: