From 8605d2eb861ff99847d1e79a8f47cb4a413d299f Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Wed, 17 Jul 2019 08:22:19 +0000 Subject: [PATCH] Enable Vulkan extensions for Linux, Windows, Android and Fuchsia. This CL ensures that when is included, the appropriate VK_USE_PLATFORM_XXX macro is defined to enable the declaration of platform-specific types and extensions. Note that for Linux, this requires an xlib_with_undefs.h header to remove annoying macros that are defined by (i.e. Success, Always, None) and which prevent compilation of other Dawn sources that use the same symbols as enum value names. Change-Id: I0c8d95fe8043d75ba3f74789e0fe2e3e4a477703 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8961 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: David Turner --- src/common/Platform.h | 3 +++ src/common/vulkan_platform.h | 18 ++++++++++++++++++ src/common/xlib_with_undefs.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/common/xlib_with_undefs.h diff --git a/src/common/Platform.h b/src/common/Platform.h index 7e767f1322..3951362f44 100644 --- a/src/common/Platform.h +++ b/src/common/Platform.h @@ -23,6 +23,9 @@ #elif defined(__APPLE__) # define DAWN_PLATFORM_APPLE 1 # define DAWN_PLATFORM_POSIX 1 +#elif defined(__Fuchsia__) +# define DAWN_PLATFORM_FUCHSIA 1 +# define DAWN_PLATFORM_POSIX 1 #else # error "Unsupported platform." #endif diff --git a/src/common/vulkan_platform.h b/src/common/vulkan_platform.h index 81f0406bc5..881335300f 100644 --- a/src/common/vulkan_platform.h +++ b/src/common/vulkan_platform.h @@ -145,6 +145,20 @@ class alignas(kNativeVkHandleAlignment) VkNonDispatchableHandle { static_assert(sizeof(object) == sizeof(object##Native), ""); \ static_assert(alignof(object) == kNativeVkHandleAlignment, ""); +// Ensure platform-specific extensions are declared appropriately. +#if defined(DAWN_PLATFORM_LINUX) +# define VK_USE_PLATFORM_XLIB_KHR +# define VK_USE_PLATFORM_XCB_KHR +// NOTE: For now the line below is undefined to take care of systems that don't +// have the Wayland headers installed on the system. +// # define VK_USE_PLATFORM_WAYLAND_KHR +#elif defined(DAWN_PLATFORM_WINDOWS) +# define VK_USE_PLATFORM_WIN32_KHR +#elif defined(DAWN_PLATFORM_ANDROID) +# define VK_USE_PLATFORM_ANDROID_KHR +#elif defined(DAWN_PLATFORM_FUCHSIA) +# define VK_USE_PLATFORM_FUCHSIA +#endif # include // VK_NULL_HANDLE is defined to 0 but we don't want our handle type to compare to arbitrary @@ -156,5 +170,9 @@ class alignas(kNativeVkHandleAlignment) VkNonDispatchableHandle { #if defined(DAWN_PLATFORM_WINDOWS) # include "common/windows_with_undefs.h" #endif +// Remove X11/Xlib.h macros after vulkan_platform's include of it. +#if defined(DAWN_PLATFORM_LINUX) +# include "common/xlib_with_undefs.h" +#endif #endif // COMMON_VULKANPLATFORM_H_ diff --git a/src/common/xlib_with_undefs.h b/src/common/xlib_with_undefs.h new file mode 100644 index 0000000000..794ce0fb49 --- /dev/null +++ b/src/common/xlib_with_undefs.h @@ -0,0 +1,33 @@ +// Copyright 2019 The Dawn Authors +// +// 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. + +#ifndef COMMON_XLIB_WITH_UNDEFS_H_ +#define COMMON_XLIB_WITH_UNDEFS_H_ + +#include "common/Platform.h" + +#if !defined(DAWN_PLATFORM_LINUX) +# error "xlib_with_undefs.h included on non-Linux" +#endif + +// This header includes but removes all the extra defines that conflict with +// identifiers in internal code. It should never be included in something that is part of the public +// interface. +#include + +#undef Success +#undef None +#undef Always + +#endif // COMMON_XLIB_WITH_UNDEFS_H_