DAWN_PLATFORM and DAWN_COMPILER macro improvements

Change #if DAWN_PLATFORM_XXX to #if DAWN_PLATFORM_IS(XXX)
To prevent #ifdef usage and reference without including
dawn/common/Platform.h

Also change #if DAWN_COMPILER_XXX to # if DAWN_COMPILER_IS(XXX)

Bug: dawn:1447
Change-Id: If6c9dab15fd2676f9a087507f5efcceeff468d33
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92625
Commit-Queue: Shrek Shao <shrekshao@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Shrek Shao 2022-06-08 19:52:42 +00:00 committed by Dawn LUCI CQ
parent 736e97c5e0
commit 7e74c21873
40 changed files with 260 additions and 188 deletions

View File

@ -69,7 +69,7 @@ struct ExternalImageExportInfoVk : ExternalImageExportInfo {
using ExternalImageExportInfo::ExternalImageExportInfo;
};
// Can't use DAWN_PLATFORM_LINUX since header included in both Dawn and Chrome
// Can't use DAWN_PLATFORM_IS(LINUX) since header included in both Dawn and Chrome
#ifdef __linux__
// Common properties of external images represented by FDs. On successful import the file

View File

@ -31,7 +31,7 @@
// MSVC triggers a warning in /W4 for do {} while(0). SDL worked around this by using (0,0) and
// points out that it looks like an owl face.
#if defined(DAWN_COMPILER_MSVC)
#if DAWN_COMPILER_IS(MSVC)
#define DAWN_ASSERT_LOOP_CONDITION (0, 0)
#else
#define DAWN_ASSERT_LOOP_CONDITION (0)
@ -48,9 +48,9 @@
} \
} while (DAWN_ASSERT_LOOP_CONDITION)
#else
#if defined(DAWN_COMPILER_MSVC)
#if DAWN_COMPILER_IS(MSVC)
#define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) __assume(condition)
#elif defined(DAWN_COMPILER_CLANG) && defined(__builtin_assume)
#elif DAWN_COMPILER_IS(CLANG) && defined(__builtin_assume)
#define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) __builtin_assume(condition)
#else
#define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) \

View File

@ -16,7 +16,7 @@
#define SRC_DAWN_COMMON_COMPILER_H_
// Defines macros for compiler-specific functionality
// - DAWN_COMPILER_[CLANG|GCC|MSVC]: Compiler detection
// - DAWN_COMPILER_IS(CLANG|GCC|MSVC): Compiler detection
// - DAWN_BREAKPOINT(): Raises an exception and breaks in the debugger
// - DAWN_BUILTIN_UNREACHABLE(): Hints the compiler that a code path is unreachable
// - DAWN_(UN)?LIKELY(EXPR): Where available, hints the compiler that the expression will be true
@ -30,9 +30,9 @@
// Clang and GCC, check for __clang__ too to catch clang-cl masquarading as MSVC
#if defined(__GNUC__) || defined(__clang__)
#if defined(__clang__)
#define DAWN_COMPILER_CLANG
#define DAWN_COMPILER_IS_CLANG 1
#else
#define DAWN_COMPILER_GCC
#define DAWN_COMPILER_IS_GCC 1
#endif
#if defined(__i386__) || defined(__x86_64__)
@ -58,7 +58,7 @@
// MSVC
#elif defined(_MSC_VER)
#define DAWN_COMPILER_MSVC
#define DAWN_COMPILER_IS_MSVC 1
extern void __cdecl __debugbreak(void);
#define DAWN_BREAKPOINT() __debugbreak()
@ -75,6 +75,23 @@ extern void __cdecl __debugbreak(void);
#error "Unsupported compiler"
#endif
// This section defines other compiler macros to 0 to avoid undefined macro usage error.
#if !defined(DAWN_COMPILER_IS_CLANG)
#define DAWN_COMPILER_IS_CLANG 0
#endif
#if !defined(DAWN_COMPILER_IS_GCC)
#define DAWN_COMPILER_IS_GCC 0
#endif
#if !defined(DAWN_COMPILER_IS_MSVC)
#define DAWN_COMPILER_IS_MSVC 0
#endif
// Use #if DAWN_COMPILER_IS(XXX) for compiler specific code.
// Do not use #ifdef or the naked macro DAWN_COMPILER_IS_XXX.
// This can help avoid common mistakes like not including "Compiler.h" and falling into unwanted
// code block as usage of undefined macro "function" will be blocked by the compiler.
#define DAWN_COMPILER_IS(X) (1 == DAWN_COMPILER_IS_##X)
// It seems that (void) EXPR works on all compilers to silence the unused variable warning.
#define DAWN_UNUSED(EXPR) (void)EXPR
// Likewise using static asserting on sizeof(&FUNC) seems to make it tagged as used

View File

@ -18,12 +18,12 @@
#include "dawn/common/Platform.h"
#if DAWN_PLATFORM_WINDOWS
#if DAWN_PLATFORM_IS(WINDOWS)
#include "dawn/common/windows_with_undefs.h"
#if DAWN_PLATFORM_WINUWP
#if DAWN_PLATFORM_IS(WINUWP)
#include "dawn/common/WindowsUtils.h"
#endif
#elif DAWN_PLATFORM_POSIX
#elif DAWN_PLATFORM_IS(POSIX)
#include <dlfcn.h>
#else
#error "Unsupported platform for DynamicLib"
@ -47,8 +47,8 @@ bool DynamicLib::Valid() const {
}
bool DynamicLib::Open(const std::string& filename, std::string* error) {
#if DAWN_PLATFORM_WINDOWS
#if DAWN_PLATFORM_WINUWP
#if DAWN_PLATFORM_IS(WINDOWS)
#if DAWN_PLATFORM_IS(WINUWP)
mHandle = LoadPackagedLibrary(UTF8ToWStr(filename.c_str()).c_str(), 0);
#else
mHandle = LoadLibraryA(filename.c_str());
@ -56,7 +56,7 @@ bool DynamicLib::Open(const std::string& filename, std::string* error) {
if (mHandle == nullptr && error != nullptr) {
*error = "Windows Error: " + std::to_string(GetLastError());
}
#elif DAWN_PLATFORM_POSIX
#elif DAWN_PLATFORM_IS(POSIX)
mHandle = dlopen(filename.c_str(), RTLD_NOW);
if (mHandle == nullptr && error != nullptr) {
@ -74,9 +74,9 @@ void DynamicLib::Close() {
return;
}
#if DAWN_PLATFORM_WINDOWS
#if DAWN_PLATFORM_IS(WINDOWS)
FreeLibrary(static_cast<HMODULE>(mHandle));
#elif DAWN_PLATFORM_POSIX
#elif DAWN_PLATFORM_IS(POSIX)
dlclose(mHandle);
#else
#error "Unsupported platform for DynamicLib"
@ -88,13 +88,13 @@ void DynamicLib::Close() {
void* DynamicLib::GetProc(const std::string& procName, std::string* error) const {
void* proc = nullptr;
#if DAWN_PLATFORM_WINDOWS
#if DAWN_PLATFORM_IS(WINDOWS)
proc = reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(mHandle), procName.c_str()));
if (proc == nullptr && error != nullptr) {
*error = "Windows Error: " + std::to_string(GetLastError());
}
#elif DAWN_PLATFORM_POSIX
#elif DAWN_PLATFORM_IS(POSIX)
proc = reinterpret_cast<void*>(dlsym(mHandle, procName.c_str()));
if (proc == nullptr && error != nullptr) {

View File

@ -45,9 +45,9 @@ size_t Hash(const TypedInteger<Tag, T>& value) {
// return hash;
template <typename T>
void HashCombine(size_t* hash, const T& value) {
#if defined(DAWN_PLATFORM_64_BIT)
#if DAWN_PLATFORM_IS(64_BIT)
const size_t offset = 0x9e3779b97f4a7c16;
#elif defined(DAWN_PLATFORM_32_BIT)
#elif DAWN_PLATFORM_IS(32_BIT)
const size_t offset = 0x9e3779b9;
#else
#error "Unsupported platform"

View File

@ -20,7 +20,7 @@
#include "dawn/common/Assert.h"
#include "dawn/common/Platform.h"
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
#include <android/log.h>
#endif
@ -44,7 +44,7 @@ const char* SeverityName(LogSeverity severity) {
}
}
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
android_LogPriority AndroidLogPriority(LogSeverity severity) {
switch (severity) {
case LogSeverity::Debug:
@ -60,7 +60,7 @@ android_LogPriority AndroidLogPriority(LogSeverity severity) {
return ANDROID_LOG_ERROR;
}
}
#endif // defined(DAWN_PLATFORM_ANDROID)
#endif // DAWN_PLATFORM_IS(ANDROID)
} // anonymous namespace
@ -85,10 +85,10 @@ LogMessage::~LogMessage() {
const char* severityName = SeverityName(mSeverity);
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
android_LogPriority androidPriority = AndroidLogPriority(mSeverity);
__android_log_print(androidPriority, "Dawn", "%s: %s\n", severityName, fullMessage.c_str());
#else // defined(DAWN_PLATFORM_ANDROID)
#else // DAWN_PLATFORM_IS(ANDROID)
FILE* outputStream = stdout;
if (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) {
outputStream = stderr;
@ -97,7 +97,7 @@ LogMessage::~LogMessage() {
// Note: we use fprintf because <iostream> includes static initializers.
fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str());
fflush(outputStream);
#endif // defined(DAWN_PLATFORM_ANDROID)
#endif // DAWN_PLATFORM_IS(ANDROID)
}
LogMessage DebugLog() {

View File

@ -21,13 +21,13 @@
#include "dawn/common/Assert.h"
#include "dawn/common/Platform.h"
#if defined(DAWN_COMPILER_MSVC)
#if DAWN_COMPILER_IS(MSVC)
#include <intrin.h>
#endif
uint32_t ScanForward(uint32_t bits) {
ASSERT(bits != 0);
#if defined(DAWN_COMPILER_MSVC)
#if DAWN_COMPILER_IS(MSVC)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanForward(&firstBitIndex, bits);
@ -40,7 +40,7 @@ uint32_t ScanForward(uint32_t bits) {
uint32_t Log2(uint32_t value) {
ASSERT(value != 0);
#if defined(DAWN_COMPILER_MSVC)
#if DAWN_COMPILER_IS(MSVC)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse(&firstBitIndex, value);
@ -53,14 +53,14 @@ uint32_t Log2(uint32_t value) {
uint32_t Log2(uint64_t value) {
ASSERT(value != 0);
#if defined(DAWN_COMPILER_MSVC)
#if defined(DAWN_PLATFORM_64_BIT)
#if DAWN_COMPILER_IS(MSVC)
#if DAWN_PLATFORM_IS(64_BIT)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse64(&firstBitIndex, value);
ASSERT(ret != 0);
return firstBitIndex;
#else // defined(DAWN_PLATFORM_64_BIT)
#else // DAWN_PLATFORM_IS(64_BIT)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul;
if (_BitScanReverse(&firstBitIndex, value >> 32)) {
@ -69,10 +69,10 @@ uint32_t Log2(uint64_t value) {
unsigned char ret = _BitScanReverse(&firstBitIndex, value & 0xFFFFFFFF);
ASSERT(ret != 0);
return firstBitIndex;
#endif // defined(DAWN_PLATFORM_64_BIT)
#else // defined(DAWN_COMPILER_MSVC)
#endif // DAWN_PLATFORM_IS(64_BIT)
#else // DAWN_COMPILER_IS(MSVC)
return 63 - static_cast<uint32_t>(__builtin_clzll(value));
#endif // defined(DAWN_COMPILER_MSVC)
#endif // DAWN_COMPILER_IS(MSVC)
}
uint64_t NextPowerOfTwo(uint64_t n) {

View File

@ -17,41 +17,41 @@
#if defined(_WIN32) || defined(_WIN64)
#include <winapifamily.h>
#define DAWN_PLATFORM_WINDOWS 1
#define DAWN_PLATFORM_IS_WINDOWS 1
#if WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
#define DAWN_PLATFORM_WIN32 1
#define DAWN_PLATFORM_IS_WIN32 1
#elif WINAPI_FAMILY == WINAPI_FAMILY_PC_APP
#define DAWN_PLATFORM_WINUWP 1
#define DAWN_PLATFORM_IS_WINUWP 1
#else
#error "Unsupported Windows platform."
#endif
#elif defined(__linux__)
#define DAWN_PLATFORM_LINUX 1
#define DAWN_PLATFORM_POSIX 1
#define DAWN_PLATFORM_IS_LINUX 1
#define DAWN_PLATFORM_IS_POSIX 1
#if defined(__ANDROID__)
#define DAWN_PLATFORM_ANDROID 1
#define DAWN_PLATFORM_IS_ANDROID 1
#endif
#elif defined(__APPLE__)
#define DAWN_PLATFORM_APPLE 1
#define DAWN_PLATFORM_POSIX 1
#define DAWN_PLATFORM_IS_APPLE 1
#define DAWN_PLATFORM_IS_POSIX 1
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#define DAWN_PLATFORM_IOS
#define DAWN_PLATFORM_IS_IOS 1
#elif TARGET_OS_MAC
#define DAWN_PLATFORM_MACOS
#define DAWN_PLATFORM_IS_MACOS 1
#else
#error "Unsupported Apple platform."
#endif
#elif defined(__Fuchsia__)
#define DAWN_PLATFORM_FUCHSIA 1
#define DAWN_PLATFORM_POSIX 1
#define DAWN_PLATFORM_IS_FUCHSIA 1
#define DAWN_PLATFORM_IS_POSIX 1
#elif defined(__EMSCRIPTEN__)
#define DAWN_PLATFORM_EMSCRIPTEN 1
#define DAWN_PLATFORM_POSIX 1
#define DAWN_PLATFORM_IS_EMSCRIPTEN 1
#define DAWN_PLATFORM_IS_POSIX 1
#else
#error "Unsupported platform."
@ -69,14 +69,66 @@
#if defined(_WIN64) || defined(__aarch64__) || defined(__x86_64__) || defined(__mips64__) || \
defined(__s390x__) || defined(__PPC64__)
#define DAWN_PLATFORM_64_BIT 1
#define DAWN_PLATFORM_IS_64_BIT 1
static_assert(sizeof(sizeof(char)) == 8, "Expect sizeof(size_t) == 8");
#elif defined(_WIN32) || defined(__arm__) || defined(__i386__) || defined(__mips32__) || \
defined(__s390__) || defined(__EMSCRIPTEN__)
#define DAWN_PLATFORM_32_BIT 1
#define DAWN_PLATFORM_IS_32_BIT 1
static_assert(sizeof(sizeof(char)) == 4, "Expect sizeof(size_t) == 4");
#else
#error "Unsupported platform"
#endif
// This section define other platform macros to 0 to avoid undefined macro usage error.
#if !defined(DAWN_PLATFORM_IS_WINDOWS)
#define DAWN_PLATFORM_IS_WINDOWS 0
#endif
#if !defined(DAWN_PLATFORM_IS_WIN32)
#define DAWN_PLATFORM_IS_WIN32 0
#endif
#if !defined(DAWN_PLATFORM_IS_WINUWP)
#define DAWN_PLATFORM_IS_WINUWP 0
#endif
#if !defined(DAWN_PLATFORM_IS_POSIX)
#define DAWN_PLATFORM_IS_POSIX 0
#endif
#if !defined(DAWN_PLATFORM_IS_LINUX)
#define DAWN_PLATFORM_IS_LINUX 0
#endif
#if !defined(DAWN_PLATFORM_IS_ANDROID)
#define DAWN_PLATFORM_IS_ANDROID 0
#endif
#if !defined(DAWN_PLATFORM_IS_APPLE)
#define DAWN_PLATFORM_IS_APPLE 0
#endif
#if !defined(DAWN_PLATFORM_IS_IOS)
#define DAWN_PLATFORM_IS_IOS 0
#endif
#if !defined(DAWN_PLATFORM_IS_MACOS)
#define DAWN_PLATFORM_IS_MACOS 0
#endif
#if !defined(DAWN_PLATFORM_IS_FUCHSIA)
#define DAWN_PLATFORM_IS_FUCHSIA 0
#endif
#if !defined(DAWN_PLATFORM_IS_EMSCRIPTEN)
#define DAWN_PLATFORM_IS_EMSCRIPTEN 0
#endif
#if !defined(DAWN_PLATFORM_IS_64_BIT)
#define DAWN_PLATFORM_IS_64_BIT 0
#endif
#if !defined(DAWN_PLATFORM_IS_32_BIT)
#define DAWN_PLATFORM_IS_32_BIT 0
#endif
// Use #if DAWN_PLATFORM_IS(XXX) for platform specific code.
// Do not use #ifdef or the naked macro DAWN_PLATFORM_IS_XXX.
// This can help avoid common mistakes like not including "Platform.h" and falling into unwanted
// code block as usage of undefined macro "function" will be blocked by the compiler.
#define DAWN_PLATFORM_IS(X) (1 == DAWN_PLATFORM_IS_##X)
#endif // SRC_DAWN_COMMON_PLATFORM_H_

View File

@ -51,7 +51,7 @@ class StackAllocator : public std::allocator<T> {
// constructors and destructors to be automatically called. Define a POD
// buffer of the right size instead.
alignas(T) char stack_buffer_[sizeof(T[stack_capacity])];
#if defined(DAWN_COMPILER_GCC) && !defined(__x86_64__) && !defined(__i386__)
#if DAWN_COMPILER_IS(GCC) && !defined(__x86_64__) && !defined(__i386__)
static_assert(alignof(T) <= 16, "http://crbug.com/115612");
#endif

View File

@ -17,15 +17,15 @@
#include "dawn/common/Assert.h"
#include "dawn/common/Log.h"
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#include <Windows.h>
#include <vector>
#elif defined(DAWN_PLATFORM_LINUX)
#elif DAWN_PLATFORM_IS(LINUX)
#include <dlfcn.h>
#include <limits.h>
#include <unistd.h>
#include <cstdlib>
#elif defined(DAWN_PLATFORM_MACOS) || defined(DAWN_PLATFORM_IOS)
#elif DAWN_PLATFORM_IS(MACOS) || DAWN_PLATFORM_IS(IOS)
#include <dlfcn.h>
#include <mach-o/dyld.h>
#include <vector>
@ -33,7 +33,7 @@
#include <array>
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
const char* GetPathSeparator() {
return "\\";
}
@ -66,7 +66,7 @@ std::pair<std::string, bool> GetEnvironmentVar(const char* variableName) {
bool SetEnvironmentVar(const char* variableName, const char* value) {
return SetEnvironmentVariableA(variableName, value) == TRUE;
}
#elif defined(DAWN_PLATFORM_POSIX)
#elif DAWN_PLATFORM_IS(POSIX)
const char* GetPathSeparator() {
return "/";
}
@ -87,7 +87,7 @@ bool SetEnvironmentVar(const char* variableName, const char* value) {
#error "Implement Get/SetEnvironmentVar for your platform."
#endif
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
std::optional<std::string> GetHModulePath(HMODULE module) {
std::array<char, MAX_PATH> executableFileBuf;
DWORD executablePathLen = GetModuleFileNameA(nullptr, executableFileBuf.data(),
@ -100,7 +100,7 @@ std::optional<std::string> GetHModulePath(HMODULE module) {
std::optional<std::string> GetExecutablePath() {
return GetHModulePath(nullptr);
}
#elif defined(DAWN_PLATFORM_LINUX)
#elif DAWN_PLATFORM_IS(LINUX)
std::optional<std::string> GetExecutablePath() {
std::array<char, PATH_MAX> path;
ssize_t result = readlink("/proc/self/exe", path.data(), PATH_MAX - 1);
@ -111,7 +111,7 @@ std::optional<std::string> GetExecutablePath() {
path[result] = '\0';
return path.data();
}
#elif defined(DAWN_PLATFORM_MACOS) || defined(DAWN_PLATFORM_IOS)
#elif DAWN_PLATFORM_IS(MACOS) || DAWN_PLATFORM_IS(IOS)
std::optional<std::string> GetExecutablePath() {
uint32_t size = 0;
_NSGetExecutablePath(nullptr, &size);
@ -124,12 +124,12 @@ std::optional<std::string> GetExecutablePath() {
buffer[size] = '\0';
return buffer.data();
}
#elif defined(DAWN_PLATFORM_FUCHSIA)
#elif DAWN_PLATFORM_IS(FUCHSIA)
std::optional<std::string> GetExecutablePath() {
// UNIMPLEMENTED
return {};
}
#elif defined(DAWN_PLATFORM_EMSCRIPTEN)
#elif DAWN_PLATFORM_IS(EMSCRIPTEN)
std::optional<std::string> GetExecutablePath() {
return {};
}
@ -149,7 +149,7 @@ std::optional<std::string> GetExecutableDirectory() {
return exePath->substr(0, lastPathSepLoc + 1);
}
#if defined(DAWN_PLATFORM_LINUX) || defined(DAWN_PLATFORM_MACOS) || defined(DAWN_PLATFORM_IOS)
#if DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(MACOS) || DAWN_PLATFORM_IS(IOS)
std::optional<std::string> GetModulePath() {
static int placeholderSymbol = 0;
Dl_info dlInfo;
@ -163,7 +163,7 @@ std::optional<std::string> GetModulePath() {
}
return absolutePath.data();
}
#elif defined(DAWN_PLATFORM_WINDOWS)
#elif DAWN_PLATFORM_IS(WINDOWS)
std::optional<std::string> GetModulePath() {
static int placeholderSymbol = 0;
HMODULE module = nullptr;
@ -179,11 +179,11 @@ std::optional<std::string> GetModulePath() {
#endif
return GetHModulePath(module);
}
#elif defined(DAWN_PLATFORM_FUCHSIA)
#elif DAWN_PLATFORM_IS(FUCHSIA)
std::optional<std::string> GetModulePath() {
return {};
}
#elif defined(DAWN_PLATFORM_EMSCRIPTEN)
#elif DAWN_PLATFORM_IS(EMSCRIPTEN)
std::optional<std::string> GetModulePath() {
return {};
}

View File

@ -33,7 +33,7 @@ bool SetEnvironmentVar(const char* variableName, const char* value);
std::optional<std::string> GetExecutableDirectory();
std::optional<std::string> GetModuleDirectory();
#ifdef DAWN_PLATFORM_MACOS
#if DAWN_PLATFORM_IS(MACOS)
void GetMacOSVersion(int32_t* majorVersion, int32_t* minorVersion = nullptr);
bool IsMacOSVersionAtLeast(uint32_t majorVersion, uint32_t minorVersion = 0);
#endif

View File

@ -16,6 +16,7 @@
#define SRC_DAWN_COMMON_ITYP_BITSET_H_
#include "dawn/common/BitSetIterator.h"
#include "dawn/common/Platform.h"
#include "dawn/common/TypedInteger.h"
#include "dawn/common/UnderlyingType.h"
@ -124,9 +125,9 @@ class bitset : private std::bitset<N> {
template <typename Index, size_t N>
Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
using I = UnderlyingType<Index>;
#if defined(DAWN_COMPILER_MSVC)
#if DAWN_COMPILER_IS(MSVC)
if constexpr (N > 32) {
#if defined(DAWN_PLATFORM_64_BIT)
#if DAWN_PLATFORM_IS(64_BIT)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse64(&firstBitIndex, bitset.to_ullong());
@ -134,7 +135,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
return Index(static_cast<I>(0));
}
return Index(static_cast<I>(firstBitIndex + 1));
#else // defined(DAWN_PLATFORM_64_BIT)
#else // DAWN_PLATFORM_IS(64_BIT)
if (bitset.none()) {
return Index(static_cast<I>(0));
}
@ -144,7 +145,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
}
}
UNREACHABLE();
#endif // defined(DAWN_PLATFORM_64_BIT)
#endif // DAWN_PLATFORM_IS(64_BIT)
} else {
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul;
@ -154,7 +155,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
}
return Index(static_cast<I>(firstBitIndex + 1));
}
#else // defined(DAWN_COMPILER_MSVC)
#else // DAWN_COMPILER_IS(MSVC)
if (bitset.none()) {
return Index(static_cast<I>(0));
}
@ -164,7 +165,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
} else {
return Index(static_cast<I>(32 - static_cast<uint32_t>(__builtin_clz(bitset.to_ulong()))));
}
#endif // defined(DAWN_COMPILER_MSVC)
#endif // DAWN_COMPILER_IS(MSVC)
}
#endif // SRC_DAWN_COMMON_ITYP_BITSET_H_

View File

@ -35,7 +35,7 @@
// redefined to be nullptr). This keeps the type-safety of having the handles be different types
// (like vulkan.h on 64 bit) but makes sure the types are different on 32 bit architectures.
#if defined(DAWN_PLATFORM_64_BIT)
#if DAWN_PLATFORM_IS(64_BIT)
#define DAWN_DEFINE_NATIVE_NON_DISPATCHABLE_HANDLE(object) using object = struct object##_T*;
// This function is needed because MSVC doesn't accept reinterpret_cast from uint64_t from uint64_t
// TODO(cwallez@chromium.org): Remove this once we rework vulkan_platform.h
@ -43,7 +43,7 @@ template <typename T>
T NativeNonDispatachableHandleFromU64(uint64_t u64) {
return reinterpret_cast<T>(u64);
}
#elif defined(DAWN_PLATFORM_32_BIT)
#elif DAWN_PLATFORM_IS(32_BIT)
#define DAWN_DEFINE_NATIVE_NON_DISPATCHABLE_HANDLE(object) using object = uint64_t;
template <typename T>
T NativeNonDispatachableHandleFromU64(uint64_t u64) {
@ -138,12 +138,12 @@ HandleType* AsVkArray(detail::VkHandle<Tag, HandleType>* handle) {
// headers that vulkan.h includes that we have "undefs" for. Note that some of the VK_USE_PLATFORM_*
// defines are defined already in the Vulkan-Header BUILD.gn, but are needed when building with
// CMake, hence they cannot be removed at the moment.
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#ifndef VK_USE_PLATFORM_WIN32_KHR
#define VK_USE_PLATFORM_WIN32_KHR
#endif
#include "dawn/common/windows_with_undefs.h"
#endif // DAWN_PLATFORM_WINDOWS
#endif // DAWN_PLATFORM_IS(WINDOWS)
#if defined(DAWN_USE_X11)
#define VK_USE_PLATFORM_XLIB_KHR
@ -165,17 +165,17 @@ HandleType* AsVkArray(detail::VkHandle<Tag, HandleType>* handle) {
#endif
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
#ifndef VK_USE_PLATFORM_ANDROID_KHR
#define VK_USE_PLATFORM_ANDROID_KHR
#endif
#endif // defined(DAWN_PLATFORM_ANDROID)
#endif // DAWN_PLATFORM_IS(ANDROID)
#if defined(DAWN_PLATFORM_FUCHSIA)
#if DAWN_PLATFORM_IS(FUCHSIA)
#ifndef VK_USE_PLATFORM_FUCHSIA
#define VK_USE_PLATFORM_FUCHSIA
#endif
#endif // defined(DAWN_PLATFORM_FUCHSIA)
#endif // DAWN_PLATFORM_IS(FUCHSIA)
// The actual inclusion of vulkan.h!
#define VK_NO_PROTOTYPES

View File

@ -17,7 +17,7 @@
#include "dawn/common/Platform.h"
#if !defined(DAWN_PLATFORM_WINDOWS)
#if !DAWN_PLATFORM_IS(WINDOWS)
#error "windows_with_undefs.h included on non-Windows"
#endif

View File

@ -17,7 +17,7 @@
#include "dawn/common/Platform.h"
#if !defined(DAWN_PLATFORM_LINUX)
#if !DAWN_PLATFORM_IS(LINUX)
#error "xlib_with_undefs.h included on non-Linux"
#endif

View File

@ -19,10 +19,10 @@
#include "dawn/native/Instance.h"
#include "dawn/native/SwapChain.h"
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#include <windows.ui.core.h>
#include <windows.ui.xaml.controls.h>
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
#if defined(DAWN_USE_X11)
#include "dawn/common/xlib_with_undefs.h"
@ -87,7 +87,7 @@ MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance,
}
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
const SurfaceDescriptorFromAndroidNativeWindow* androidDesc = nullptr;
FindInChain(descriptor->nextInChain, &androidDesc);
// Currently the best validation we can do since it's not possible to check if the pointer
@ -96,17 +96,17 @@ MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance,
DAWN_INVALID_IF(androidDesc->window == nullptr, "Android window is not set.");
return {};
}
#endif // defined(DAWN_PLATFORM_ANDROID)
#endif // DAWN_PLATFORM_IS(ANDROID)
#if defined(DAWN_PLATFORM_WINDOWS)
#if defined(DAWN_PLATFORM_WIN32)
#if DAWN_PLATFORM_IS(WINDOWS)
#if DAWN_PLATFORM_IS(WIN32)
const SurfaceDescriptorFromWindowsHWND* hwndDesc = nullptr;
FindInChain(descriptor->nextInChain, &hwndDesc);
if (hwndDesc) {
DAWN_INVALID_IF(IsWindow(static_cast<HWND>(hwndDesc->hwnd)) == 0, "Invalid HWND");
return {};
}
#endif // defined(DAWN_PLATFORM_WIN32)
#endif // DAWN_PLATFORM_IS(WIN32)
const SurfaceDescriptorFromWindowsCoreWindow* coreWindowDesc = nullptr;
FindInChain(descriptor->nextInChain, &coreWindowDesc);
if (coreWindowDesc) {
@ -129,7 +129,7 @@ MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance,
"Invalid SwapChainPanel");
return {};
}
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
#if defined(DAWN_USE_WAYLAND)
const SurfaceDescriptorFromWaylandSurface* waylandDesc = nullptr;
@ -203,15 +203,15 @@ Surface::Surface(InstanceBase* instance, const SurfaceDescriptor* descriptor)
mHInstance = hwndDesc->hinstance;
mHWND = hwndDesc->hwnd;
} else if (coreWindowDesc) {
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
mType = Type::WindowsCoreWindow;
mCoreWindow = static_cast<IUnknown*>(coreWindowDesc->coreWindow);
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
} else if (swapChainPanelDesc) {
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
mType = Type::WindowsSwapChainPanel;
mSwapChainPanel = static_cast<IUnknown*>(swapChainPanelDesc->swapChainPanel);
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
} else if (xDesc) {
mType = Type::XlibWindow;
mXDisplay = xDesc->display;
@ -283,7 +283,7 @@ void* Surface::GetHWND() const {
IUnknown* Surface::GetCoreWindow() const {
ASSERT(!IsError());
ASSERT(mType == Type::WindowsCoreWindow);
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
return mCoreWindow.Get();
#else
return nullptr;
@ -293,7 +293,7 @@ IUnknown* Surface::GetCoreWindow() const {
IUnknown* Surface::GetSwapChainPanel() const {
ASSERT(!IsError());
ASSERT(mType == Type::WindowsSwapChainPanel);
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
return mSwapChainPanel.Get();
#else
return nullptr;

View File

@ -23,9 +23,9 @@
#include "dawn/common/Platform.h"
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#include "dawn/native/d3d12/d3d12_platform.h"
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
// Forward declare IUnknown
// GetCoreWindow needs to return an IUnknown pointer
@ -112,13 +112,13 @@ class Surface final : public ErrorMonad {
void* mHInstance = nullptr;
void* mHWND = nullptr;
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
// WindowsCoreWindow
ComPtr<IUnknown> mCoreWindow;
// WindowsSwapChainPanel
ComPtr<IUnknown> mSwapChainPanel;
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
// Xlib
void* mXDisplay = nullptr;

View File

@ -73,11 +73,11 @@ MaybeError ValidateSwapChainDescriptor(const DeviceBase* device,
// TODO(crbug.com/dawn/160): Lift this restriction once wgpu::Instance::GetPreferredSurfaceFormat is
// implemented.
// TODO(dawn:286):
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::RGBA8Unorm;
#else
constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::BGRA8Unorm;
#endif // !defined(DAWN_PLATFORM_ANDROID)
#endif // !DAWN_PLATFORM_IS(ANDROID)
DAWN_INVALID_IF(descriptor->format != kRequireSwapChainFormat,
"Format (%s) is not %s, which is (currently) the only accepted format.",
descriptor->format, kRequireSwapChainFormat);

View File

@ -111,7 +111,7 @@ MaybeError PlatformFunctions::LoadFunctions() {
}
MaybeError PlatformFunctions::LoadD3D12() {
#if DAWN_PLATFORM_WINUWP
#if DAWN_PLATFORM_IS(WINUWP)
d3d12CreateDevice = &D3D12CreateDevice;
d3d12GetDebugInterface = &D3D12GetDebugInterface;
d3d12SerializeRootSignature = &D3D12SerializeRootSignature;
@ -138,7 +138,7 @@ MaybeError PlatformFunctions::LoadD3D12() {
}
MaybeError PlatformFunctions::LoadD3D11() {
#if DAWN_PLATFORM_WINUWP
#if DAWN_PLATFORM_IS(WINUWP)
d3d11on12CreateDevice = &D3D11On12CreateDevice;
#else
std::string error;
@ -152,7 +152,7 @@ MaybeError PlatformFunctions::LoadD3D11() {
}
MaybeError PlatformFunctions::LoadDXGI() {
#if DAWN_PLATFORM_WINUWP
#if DAWN_PLATFORM_IS(WINUWP)
#if defined(_DEBUG)
// DXGIGetDebugInterface1 is tagged as a development-only capability
// which implies that linking to this function will cause
@ -226,7 +226,7 @@ void PlatformFunctions::LoadDXCompiler(const std::string& baseWindowsSDKPath) {
}
MaybeError PlatformFunctions::LoadFXCompiler() {
#if DAWN_PLATFORM_WINUWP
#if DAWN_PLATFORM_IS(WINUWP)
d3dCompile = &D3DCompile;
d3dDisassemble = &D3DDisassemble;
#else

View File

@ -25,7 +25,7 @@
#include "dawn/native/metal/BufferMTL.h"
#include "dawn/native/metal/DeviceMTL.h"
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
#import <IOKit/IOKitLib.h>
#include "dawn/common/IOKitRef.h"
#endif
@ -46,7 +46,7 @@ struct Vendor {
uint32_t vendorId;
};
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
const Vendor kVendors[] = {{"AMD", gpu_info::kVendorID_AMD},
{"Radeon", gpu_info::kVendorID_AMD},
{"Intel", gpu_info::kVendorID_Intel},
@ -159,7 +159,7 @@ bool IsMetalSupported() {
// TODO(dawn:1181): Dawn native should allow non-conformant WebGPU on macOS 10.11
return IsMacOSVersionAtLeast(10, 12);
}
#elif defined(DAWN_PLATFORM_IOS)
#elif DAWN_PLATFORM_IS(IOS)
MaybeError GetDevicePCIInfo(id<MTLDevice> device, PCIIDs* ids) {
DAWN_UNUSED(device);
*ids = PCIIDs{0, 0};
@ -277,10 +277,10 @@ class Adapter : public AdapterBase {
mDeviceId = ids.deviceId;
}
#if defined(DAWN_PLATFORM_IOS)
#if DAWN_PLATFORM_IS(IOS)
mAdapterType = wgpu::AdapterType::IntegratedGPU;
const char* systemName = "iOS ";
#elif defined(DAWN_PLATFORM_MACOS)
#elif DAWN_PLATFORM_IS(MACOS)
if ([device isLowPower]) {
mAdapterType = wgpu::AdapterType::IntegratedGPU;
} else {
@ -310,12 +310,12 @@ class Adapter : public AdapterBase {
MaybeError InitializeSupportedFeaturesImpl() override {
// Check compressed texture format with deprecated MTLFeatureSet way.
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
if ([*mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) {
mSupportedFeatures.EnableFeature(Feature::TextureCompressionBC);
}
#endif
#if defined(DAWN_PLATFORM_IOS)
#if DAWN_PLATFORM_IS(IOS)
if ([*mDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v1]) {
mSupportedFeatures.EnableFeature(Feature::TextureCompressionETC2);
}
@ -350,7 +350,7 @@ class Adapter : public AdapterBase {
{MTLCommonCounterTimestamp})) {
bool enableTimestampQuery = true;
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
// Disable timestamp query on < macOS 11.0 on AMD GPU because WriteTimestamp
// fails to call without any copy commands on MTLBlitCommandEncoder. This issue
// has been fixed on macOS 11.0. See crbug.com/dawn/545.
@ -379,7 +379,7 @@ class Adapter : public AdapterBase {
mSupportedFeatures.EnableFeature(Feature::MultiPlanarFormats);
}
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
// MTLPixelFormatDepth24Unorm_Stencil8 is only available on macOS 10.11+
if ([*mDevice isDepth24Stencil8PixelFormatSupported]) {
mSupportedFeatures.EnableFeature(Feature::Depth24UnormStencil8);
@ -628,7 +628,7 @@ ResultOrError<std::vector<Ref<AdapterBase>>> Backend::DiscoverAdapters(
std::vector<Ref<AdapterBase>> adapters;
BOOL supportedVersion = NO;
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
if (@available(macOS 10.11, *)) {
supportedVersion = YES;
@ -643,7 +643,7 @@ ResultOrError<std::vector<Ref<AdapterBase>>> Backend::DiscoverAdapters(
}
#endif
#if defined(DAWN_PLATFORM_IOS)
#if DAWN_PLATFORM_IS(IOS)
if (@available(iOS 8.0, *)) {
supportedVersion = YES;
// iOS only has a single device so MTLCopyAllDevices doesn't exist there.

View File

@ -15,6 +15,7 @@
#include "dawn/native/metal/BufferMTL.h"
#include "dawn/common/Math.h"
#include "dawn/common/Platform.h"
#include "dawn/native/CommandBuffer.h"
#include "dawn/native/metal/CommandRecordingContext.h"
#include "dawn/native/metal/DeviceMTL.h"
@ -41,7 +42,7 @@ uint64_t Buffer::QueryMaxBufferLength(id<MTLDevice> mtlDevice) {
// Earlier versions of Metal had maximums defined in the Metal feature set tables
// https://metalbyexample.com/wp-content/uploads/Metal-Feature-Set-Tables-2018.pdf
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
// 10.12 and 10.13 have a 1Gb limit.
if (@available(macOS 10.12, *)) {
// |maxBufferLength| isn't always available on older systems. If available, use
@ -72,7 +73,7 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) {
}
uint32_t alignment = 1;
#ifdef DAWN_PLATFORM_MACOS
#if DAWN_PLATFORM_IS(MACOS)
// [MTLBlitCommandEncoder fillBuffer] requires the size to be a multiple of 4 on MacOS.
alignment = 4;
#endif

View File

@ -158,26 +158,26 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
void Device::InitTogglesFromDriver() {
{
bool haveStoreAndMSAAResolve = false;
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
if (@available(macOS 10.12, *)) {
haveStoreAndMSAAResolve =
[*mMtlDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
}
#elif defined(DAWN_PLATFORM_IOS)
#elif DAWN_PLATFORM_IS(IOS)
haveStoreAndMSAAResolve = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v2];
#endif
// On tvOS, we would need MTLFeatureSet_tvOS_GPUFamily2_v1.
SetToggle(Toggle::EmulateStoreAndMSAAResolve, !haveStoreAndMSAAResolve);
bool haveSamplerCompare = true;
#if defined(DAWN_PLATFORM_IOS)
#if DAWN_PLATFORM_IS(IOS)
haveSamplerCompare = [*mMtlDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1];
#endif
// TODO(crbug.com/dawn/342): Investigate emulation -- possibly expensive.
SetToggle(Toggle::MetalDisableSamplerCompare, !haveSamplerCompare);
bool haveBaseVertexBaseInstance = true;
#if defined(DAWN_PLATFORM_IOS)
#if DAWN_PLATFORM_IS(IOS)
haveBaseVertexBaseInstance =
[*mMtlDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1];
#endif

View File

@ -108,11 +108,11 @@ MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
[*mLayer setDevice:ToBackend(GetDevice())->GetMTLDevice()];
[*mLayer setPixelFormat:MetalPixelFormat(GetFormat())];
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
if (@available(macos 10.13, *)) {
[*mLayer setDisplaySyncEnabled:(GetPresentMode() != wgpu::PresentMode::Immediate)];
}
#endif // defined(DAWN_PLATFORM_MACOS)
#endif // DAWN_PLATFORM_IS(MACOS)
// There is no way to control Fifo vs. Mailbox in Metal.

View File

@ -156,7 +156,7 @@ bool AllowFormatReinterpretationWithoutFlag(MTLPixelFormat origin,
case MTLPixelFormatBGRA8Unorm_sRGB:
return reinterpretation == MTLPixelFormatRGBA8Unorm_sRGB ||
reinterpretation == MTLPixelFormatBGRA8Unorm;
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
case MTLPixelFormatBC1_RGBA:
return reinterpretation == MTLPixelFormatBC1_RGBA_sRGB;
case MTLPixelFormatBC1_RGBA_sRGB:
@ -216,9 +216,9 @@ uint32_t GetIOSurfacePlane(wgpu::TextureAspect aspect) {
}
}
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
MTLStorageMode kIOSurfaceStorageMode = MTLStorageModeManaged;
#elif defined(DAWN_PLATFORM_IOS)
#elif DAWN_PLATFORM_IS(IOS)
MTLStorageMode kIOSurfaceStorageMode = MTLStorageModePrivate;
#else
#error "Unsupported Apple platform."
@ -321,7 +321,7 @@ MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format) {
case wgpu::TextureFormat::Stencil8:
return MTLPixelFormatStencil8;
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
case wgpu::TextureFormat::Depth24UnormStencil8:
return MTLPixelFormatDepth24Unorm_Stencil8;
@ -1069,7 +1069,7 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) {
if (textureFormat == MTLPixelFormatDepth32Float_Stencil8) {
viewFormat = MTLPixelFormatX32_Stencil8;
}
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
else if (textureFormat == MTLPixelFormatDepth24Unorm_Stencil8) {
viewFormat = MTLPixelFormatX24_Stencil8;
}

View File

@ -29,7 +29,7 @@
#include "dawn/native/opengl/OpenGLFunctions.h"
// Remove windows.h macros after glad's include of windows.h
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#include "dawn/common/windows_with_undefs.h"
#endif

View File

@ -30,28 +30,28 @@
// TODO(crbug.com/dawn/283): Link against the Vulkan Loader and remove this.
#if defined(DAWN_ENABLE_SWIFTSHADER)
#if defined(DAWN_PLATFORM_LINUX) || defined(DAWN_PLATFORM_FUSCHIA)
#if DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(FUSCHIA)
constexpr char kSwiftshaderLibName[] = "libvk_swiftshader.so";
#elif defined(DAWN_PLATFORM_WINDOWS)
#elif DAWN_PLATFORM_IS(WINDOWS)
constexpr char kSwiftshaderLibName[] = "vk_swiftshader.dll";
#elif defined(DAWN_PLATFORM_MACOS)
#elif DAWN_PLATFORM_IS(MACOS)
constexpr char kSwiftshaderLibName[] = "libvk_swiftshader.dylib";
#else
#error "Unimplemented Swiftshader Vulkan backend platform"
#endif
#endif
#if defined(DAWN_PLATFORM_LINUX)
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(LINUX)
#if DAWN_PLATFORM_IS(ANDROID)
constexpr char kVulkanLibName[] = "libvulkan.so";
#else
constexpr char kVulkanLibName[] = "libvulkan.so.1";
#endif
#elif defined(DAWN_PLATFORM_WINDOWS)
#elif DAWN_PLATFORM_IS(WINDOWS)
constexpr char kVulkanLibName[] = "vulkan-1.dll";
#elif defined(DAWN_PLATFORM_MACOS)
#elif DAWN_PLATFORM_IS(MACOS)
constexpr char kVulkanLibName[] = "libvulkan.dylib";
#elif defined(DAWN_PLATFORM_FUCHSIA)
#elif DAWN_PLATFORM_IS(FUCHSIA)
constexpr char kVulkanLibName[] = "libvulkan.so";
#else
#error "Unimplemented Vulkan backend platform"
@ -445,12 +445,12 @@ ResultOrError<std::vector<Ref<AdapterBase>>> Backend::DiscoverAdapters(
InstanceBase* instance = GetInstance();
for (ICD icd : kICDs) {
#if defined(DAWN_PLATFORM_MACOS)
#if DAWN_PLATFORM_IS(MACOS)
// On Mac, we don't expect non-Swiftshader Vulkan to be available.
if (icd == ICD::None) {
continue;
}
#endif // defined(DAWN_PLATFORM_MACOS)
#endif // DAWN_PLATFORM_IS(MACOS)
if (options->forceSwiftShader && icd != ICD::SwiftShader) {
continue;
}

View File

@ -19,12 +19,12 @@
namespace dawn::native::vulkan {
#if DAWN_PLATFORM_LINUX
#if DAWN_PLATFORM_IS(LINUX)
// File descriptor
using ExternalMemoryHandle = int;
// File descriptor
using ExternalSemaphoreHandle = int;
#elif DAWN_PLATFORM_FUCHSIA
#elif DAWN_PLATFORM_IS(FUCHSIA)
// Really a Zircon vmo handle.
using ExternalMemoryHandle = zx_handle_t;
// Really a Zircon event handle.

View File

@ -184,7 +184,7 @@ DawnSwapChainError NativeSwapChainImpl::GetNextTexture(DawnSwapChainNextTexture*
}
nextTexture->texture.u64 =
#if defined(DAWN_PLATFORM_64_BIT)
#if DAWN_PLATFORM_IS(64_BIT)
reinterpret_cast<uint64_t>
#endif
(*mSwapChainImages[mLastImageIndex]);

View File

@ -115,7 +115,7 @@ ResultOrError<VkSurfaceKHR> CreateVulkanSurface(Adapter* adapter, Surface* surfa
break;
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
case Surface::Type::WindowsHWND:
if (info.HasExt(InstanceExt::Win32Surface)) {
VkWin32SurfaceCreateInfoKHR createInfo;
@ -132,9 +132,9 @@ ResultOrError<VkSurfaceKHR> CreateVulkanSurface(Adapter* adapter, Surface* surfa
return vkSurface;
}
break;
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
case Surface::Type::AndroidWindow: {
if (info.HasExt(InstanceExt::AndroidSurface)) {
ASSERT(surface->GetAndroidNativeWindow() != nullptr);
@ -156,7 +156,7 @@ ResultOrError<VkSurfaceKHR> CreateVulkanSurface(Adapter* adapter, Surface* surfa
break;
}
#endif // defined(DAWN_PLATFORM_ANDROID)
#endif // DAWN_PLATFORM_IS(ANDROID)
#if defined(DAWN_USE_WAYLAND)
case Surface::Type::WaylandSurface: {
@ -449,7 +449,7 @@ ResultOrError<SwapChain::Config> SwapChain::ChooseConfig(
config.transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
config.alphaMode = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
#if !defined(DAWN_PLATFORM_ANDROID)
#if !DAWN_PLATFORM_IS(ANDROID)
DAWN_INVALID_IF(
(surfaceInfo.capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) == 0,
"Vulkan SwapChain must support opaque alpha.");
@ -467,7 +467,7 @@ ResultOrError<SwapChain::Config> SwapChain::ChooseConfig(
break;
}
}
#endif // #if !defined(DAWN_PLATFORM_ANDROID)
#endif // #if !DAWN_PLATFORM_IS(ANDROID)
// Choose the number of images for the swapchain= and clamp it to the min and max from the
// surface capabilities. maxImageCount = 0 means there is no limit.

View File

@ -60,7 +60,7 @@ WGPUTextureFormat GetNativeSwapChainPreferredFormat(const DawnSwapChainImplement
AdapterDiscoveryOptions::AdapterDiscoveryOptions()
: AdapterDiscoveryOptionsBase(WGPUBackendType_Vulkan) {}
#if defined(DAWN_PLATFORM_LINUX)
#if DAWN_PLATFORM_IS(LINUX)
ExternalImageDescriptorOpaqueFD::ExternalImageDescriptorOpaqueFD()
: ExternalImageDescriptorFD(ExternalImageType::OpaqueFD) {}
@ -72,10 +72,10 @@ ExternalImageExportInfoOpaqueFD::ExternalImageExportInfoOpaqueFD()
ExternalImageExportInfoDmaBuf::ExternalImageExportInfoDmaBuf()
: ExternalImageExportInfoFD(ExternalImageType::DmaBuf) {}
#endif // DAWN_PLATFORM_LINUX
#endif // DAWN_PLATFORM_IS(LINUX)
WGPUTexture WrapVulkanImage(WGPUDevice device, const ExternalImageDescriptorVk* descriptor) {
#if defined(DAWN_PLATFORM_LINUX)
#if DAWN_PLATFORM_IS(LINUX)
switch (descriptor->GetType()) {
case ExternalImageType::OpaqueFD:
case ExternalImageType::DmaBuf: {
@ -91,7 +91,7 @@ WGPUTexture WrapVulkanImage(WGPUDevice device, const ExternalImageDescriptorVk*
}
#else
return nullptr;
#endif // DAWN_PLATFORM_LINUX
#endif // DAWN_PLATFORM_IS(LINUX)
}
bool ExportVulkanImage(WGPUTexture texture,
@ -100,7 +100,7 @@ bool ExportVulkanImage(WGPUTexture texture,
if (texture == nullptr) {
return false;
}
#if defined(DAWN_PLATFORM_LINUX)
#if DAWN_PLATFORM_IS(LINUX)
switch (info->GetType()) {
case ExternalImageType::OpaqueFD:
case ExternalImageType::DmaBuf: {
@ -116,7 +116,7 @@ bool ExportVulkanImage(WGPUTexture texture,
}
#else
return false;
#endif // DAWN_PLATFORM_LINUX
#endif // DAWN_PLATFORM_IS(LINUX)
}
} // namespace dawn::native::vulkan

View File

@ -195,18 +195,18 @@ MaybeError VulkanFunctions::LoadInstanceProcs(VkInstance instance,
}
#endif // defined(DAWN_USE_WAYLAND)
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
if (globalInfo.HasExt(InstanceExt::Win32Surface)) {
GET_INSTANCE_PROC(CreateWin32SurfaceKHR);
GET_INSTANCE_PROC(GetPhysicalDeviceWin32PresentationSupportKHR);
}
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
if (globalInfo.HasExt(InstanceExt::AndroidSurface)) {
GET_INSTANCE_PROC(CreateAndroidSurfaceKHR);
}
#endif // defined(DAWN_PLATFORM_ANDROID)
#endif // DAWN_PLATFORM_IS(ANDROID)
#if defined(DAWN_USE_X11)
if (globalInfo.HasExt(InstanceExt::XlibSurface)) {

View File

@ -15,6 +15,7 @@
#ifndef SRC_DAWN_NATIVE_VULKAN_VULKANFUNCTIONS_H_
#define SRC_DAWN_NATIVE_VULKAN_VULKANFUNCTIONS_H_
#include "dawn/common/Compiler.h"
#include "dawn/common/vulkan_platform.h"
#include "dawn/native/Error.h"
@ -26,7 +27,7 @@ namespace dawn::native::vulkan {
struct VulkanGlobalInfo;
struct VulkanDeviceInfo;
#if defined(UNDEFINED_SANITIZER) && defined(DAWN_COMPILER_CLANG)
#if defined(UNDEFINED_SANITIZER) && DAWN_COMPILER_IS(CLANG)
#define DAWN_NO_SANITIZE_VK_FN 1
#else
#define DAWN_NO_SANITIZE_VK_FN 0
@ -156,16 +157,16 @@ struct VulkanFunctions {
GetPhysicalDeviceWaylandPresentationSupportKHR = nullptr;
#endif // defined(DAWN_USE_WAYLAND)
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
// KHR_win32_surface
VkFn<PFN_vkCreateWin32SurfaceKHR> CreateWin32SurfaceKHR = nullptr;
VkFn<PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR>
GetPhysicalDeviceWin32PresentationSupportKHR = nullptr;
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
#if defined(DAWN_PLATFORM_ANDROID)
#if DAWN_PLATFORM_IS(ANDROID)
VkFn<PFN_vkCreateAndroidSurfaceKHR> CreateAndroidSurfaceKHR = nullptr;
#endif // defined(DAWN_PLATFORM_ANDROID)
#endif // DAWN_PLATFORM_IS(ANDROID)
#if defined(DAWN_USE_X11)
// KHR_xlib_surface

View File

@ -452,7 +452,7 @@ std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDi
if (!mANGLEBackend.empty()) {
platform = mANGLEBackend.c_str();
} else {
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
platform = "d3d11";
#else
platform = "swiftshader";
@ -851,7 +851,7 @@ bool DawnTestBase::IsWARP() const {
}
bool DawnTestBase::IsWindows() const {
#ifdef DAWN_PLATFORM_WINDOWS
#if DAWN_PLATFORM_IS(WINDOWS)
return true;
#else
return false;
@ -859,7 +859,7 @@ bool DawnTestBase::IsWindows() const {
}
bool DawnTestBase::IsLinux() const {
#ifdef DAWN_PLATFORM_LINUX
#if DAWN_PLATFORM_IS(LINUX)
return true;
#else
return false;
@ -867,7 +867,7 @@ bool DawnTestBase::IsLinux() const {
}
bool DawnTestBase::IsMacOS(int32_t majorVersion, int32_t minorVersion) const {
#ifdef DAWN_PLATFORM_MACOS
#if DAWN_PLATFORM_IS(MACOS)
if (majorVersion == -1 && minorVersion == -1) {
return true;
}

View File

@ -214,7 +214,7 @@ TEST_P(ComputeDispatchTests, DirectNoop) {
// Test basic indirect
TEST_P(ComputeDispatchTests, IndirectBasic) {
#ifdef DAWN_PLATFORM_32_BIT
#if DAWN_PLATFORM_IS(32_BIT)
// TODO(crbug.com/dawn/1196): Fails on Chromium's Quadro P400 bots
DAWN_SUPPRESS_TEST_IF(IsD3D12() && IsNvidia());
#endif
@ -246,7 +246,7 @@ TEST_P(ComputeDispatchTests, IndirectNoop) {
// Test indirect with buffer offset
TEST_P(ComputeDispatchTests, IndirectOffset) {
#ifdef DAWN_PLATFORM_32_BIT
#if DAWN_PLATFORM_IS(32_BIT)
// TODO(crbug.com/dawn/1196): Fails on Chromium's Quadro P400 bots
DAWN_SUPPRESS_TEST_IF(IsD3D12() && IsNvidia());
#endif
@ -263,7 +263,7 @@ TEST_P(ComputeDispatchTests, IndirectOffsetWithoutNumWorkgroups) {
// Test indirect dispatches at max limit.
TEST_P(ComputeDispatchTests, MaxWorkgroups) {
#ifdef DAWN_PLATFORM_32_BIT
#if DAWN_PLATFORM_IS(32_BIT)
// TODO(crbug.com/dawn/1196): Fails on Chromium's Quadro P400 bots
DAWN_SUPPRESS_TEST_IF(IsD3D12() && IsNvidia());
#endif

View File

@ -122,7 +122,7 @@ TEST_P(MaxLimitTests, MaxBufferBindingSize) {
maxBufferBindingSize =
std::min(maxBufferBindingSize, uint64_t(2) * 1024 * 1024 * 1024);
// With WARP or on 32-bit platforms, such large buffer allocations often fail.
#ifdef DAWN_PLATFORM_32_BIT
#if DAWN_PLATFORM_IS(32_BIT)
if (IsWindows()) {
continue;
}

View File

@ -24,9 +24,9 @@
#include "gtest/gtest.h"
// Include windows.h before GLFW so GLFW's APIENTRY macro doesn't conflict with windows.h's.
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#include "dawn/common/windows_with_undefs.h"
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
#include "GLFW/glfw3.h"
@ -139,7 +139,7 @@ TEST_F(WindowSurfaceInstanceTests, TwoChainedDescriptors) {
AssertSurfaceCreation(&descriptor, false);
}
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
// Tests that GLFWUtils returns a descriptor of HWND type
TEST_F(WindowSurfaceInstanceTests, CorrectSTypeHWND) {
@ -160,7 +160,7 @@ TEST_F(WindowSurfaceInstanceTests, InvalidHWND) {
AssertSurfaceCreation(&descriptor, false);
}
#else // defined(DAWN_PLATFORM_WINDOWS)
#else // DAWN_PLATFORM_IS(WINDOWS)
// Test using HWND when it is not supported
TEST_F(WindowSurfaceInstanceTests, HWNDSurfacesAreInvalid) {
@ -173,7 +173,7 @@ TEST_F(WindowSurfaceInstanceTests, HWNDSurfacesAreInvalid) {
AssertSurfaceCreation(&descriptor, false);
}
#endif // defined(DAWN_PLATFORM_WINDOWS)
#endif // DAWN_PLATFORM_IS(WINDOWS)
#if defined(DAWN_USE_X11)

View File

@ -123,7 +123,7 @@ TEST(StackContainer, BufferAlignment) {
aligned16->push_back(AlignedData<16>());
EXPECT_ALIGNED(&aligned16[0], 16);
#if !defined(DAWN_COMPILER_GCC) || defined(__x86_64__) || defined(__i386__)
#if !DAWN_COMPILER_IS(GCC) || defined(__x86_64__) || defined(__i386__)
// It seems that non-X86 gcc doesn't respect greater than 16 byte alignment.
// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33721 for details.
// TODO(sbc): Re-enable this if GCC starts respecting higher alignments.

View File

@ -29,9 +29,9 @@ namespace {
class EGLFunctions {
public:
EGLFunctions() {
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
const char* eglLib = "libEGL.dll";
#elif defined(DAWN_PLATFORM_MACOS)
#elif DAWN_PLATFORM_IS(MACOS)
const char* eglLib = "libEGL.dylib";
#else
const char* eglLib = "libEGL.so";

View File

@ -19,7 +19,7 @@
#include "dawn/common/Platform.h"
#include "dawn/utils/GLFWUtils.h"
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#define GLFW_EXPOSE_NATIVE_WIN32
#endif
#if defined(DAWN_USE_X11)
@ -68,7 +68,7 @@ std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorCocoa(GLF
std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window) {
switch (glfwGetPlatform()) {
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
case GLFW_PLATFORM_WIN32: {
std::unique_ptr<wgpu::SurfaceDescriptorFromWindowsHWND> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();

View File

@ -16,9 +16,9 @@
#include "dawn/common/Platform.h"
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
#include <Windows.h>
#elif defined(DAWN_PLATFORM_POSIX)
#elif DAWN_PLATFORM_IS(POSIX)
#include <unistd.h>
#else
#error "Unsupported platform."
@ -26,11 +26,11 @@
namespace utils {
#if defined(DAWN_PLATFORM_WINDOWS)
#if DAWN_PLATFORM_IS(WINDOWS)
void USleep(unsigned int usecs) {
Sleep(static_cast<DWORD>(usecs / 1000));
}
#elif defined(DAWN_PLATFORM_POSIX)
#elif DAWN_PLATFORM_IS(POSIX)
void USleep(unsigned int usecs) {
usleep(usecs);
}