Enable Vulkan extensions for Linux, Windows, Android and Fuchsia.

This CL ensures that when <vulkan/vulkan.h> 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 <X11/X.h> (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 <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: David Turner <digit@google.com>
This commit is contained in:
David 'Digit' Turner 2019-07-17 08:22:19 +00:00 committed by Commit Bot service account
parent 6eb681cc54
commit 8605d2eb86
3 changed files with 54 additions and 0 deletions

View File

@ -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

View File

@ -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 <vulkan/vulkan.h>
// 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_

View File

@ -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 <X11/Xlib.h> 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 <X11/Xlib.h>
#undef Success
#undef None
#undef Always
#endif // COMMON_XLIB_WITH_UNDEFS_H_