mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
Rename src/common macros NXT_* to DAWN_*
This commit is contained in:
committed by
Corentin Wallez
parent
33ca49614d
commit
83a9c9d6d9
@@ -22,5 +22,5 @@ void HandleAssertionFailure(const char* file,
|
||||
const char* condition) {
|
||||
std::cerr << "Assertion failure at " << file << ":" << line << " (" << function
|
||||
<< "): " << condition << std::endl;
|
||||
NXT_BREAKPOINT();
|
||||
DAWN_BREAKPOINT();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
// release it does nothing at runtime.
|
||||
//
|
||||
// In case of name clashes (with for example a testing library), you can define the
|
||||
// NXT_SKIP_ASSERT_SHORTHANDS to only define the NXT_ prefixed macros.
|
||||
// DAWN_SKIP_ASSERT_SHORTHANDS to only define the DAWN_ prefixed macros.
|
||||
//
|
||||
// These asserts feature:
|
||||
// - Logging of the error with file, line and function information.
|
||||
@@ -31,45 +31,45 @@
|
||||
|
||||
// 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(NXT_COMPILER_MSVC)
|
||||
# define NXT_ASSERT_LOOP_CONDITION (0, 0)
|
||||
#if defined(DAWN_COMPILER_MSVC)
|
||||
# define DAWN_ASSERT_LOOP_CONDITION (0, 0)
|
||||
#else
|
||||
# define NXT_ASSERT_LOOP_CONDITION (0)
|
||||
# define DAWN_ASSERT_LOOP_CONDITION (0)
|
||||
#endif
|
||||
|
||||
// NXT_ASSERT_CALLSITE_HELPER generates the actual assert code. In Debug it does what you would
|
||||
// DAWN_ASSERT_CALLSITE_HELPER generates the actual assert code. In Debug it does what you would
|
||||
// expect of an assert and in release it tries to give hints to make the compiler generate better
|
||||
// code.
|
||||
#if defined(NXT_ENABLE_ASSERTS)
|
||||
# define NXT_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
|
||||
#if defined(DAWN_ENABLE_ASSERTS)
|
||||
# define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
HandleAssertionFailure(file, func, line, #condition); \
|
||||
} \
|
||||
} while (NXT_ASSERT_LOOP_CONDITION)
|
||||
} while (DAWN_ASSERT_LOOP_CONDITION)
|
||||
#else
|
||||
# if defined(NXT_COMPILER_MSVC)
|
||||
# define NXT_ASSERT_CALLSITE_HELPER(file, func, line, condition) __assume(condition)
|
||||
# elif defined(NXT_COMPILER_CLANG) && defined(__builtin_assume)
|
||||
# define NXT_ASSERT_CALLSITE_HELPER(file, func, line, condition) __builtin_assume(condition)
|
||||
# if defined(DAWN_COMPILER_MSVC)
|
||||
# define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) __assume(condition)
|
||||
# elif defined(DAWN_COMPILER_CLANG) && defined(__builtin_assume)
|
||||
# define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) __builtin_assume(condition)
|
||||
# else
|
||||
# define NXT_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
|
||||
do { \
|
||||
NXT_UNUSED(sizeof(condition)); \
|
||||
} while (NXT_ASSERT_LOOP_CONDITION)
|
||||
# define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
|
||||
do { \
|
||||
DAWN_UNUSED(sizeof(condition)); \
|
||||
} while (DAWN_ASSERT_LOOP_CONDITION)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define NXT_ASSERT(condition) NXT_ASSERT_CALLSITE_HELPER(__FILE__, __func__, __LINE__, condition)
|
||||
#define NXT_UNREACHABLE() \
|
||||
do { \
|
||||
NXT_ASSERT(NXT_ASSERT_LOOP_CONDITION && "Unreachable code hit"); \
|
||||
NXT_BUILTIN_UNREACHABLE(); \
|
||||
} while (NXT_ASSERT_LOOP_CONDITION)
|
||||
#define DAWN_ASSERT(condition) DAWN_ASSERT_CALLSITE_HELPER(__FILE__, __func__, __LINE__, condition)
|
||||
#define DAWN_UNREACHABLE() \
|
||||
do { \
|
||||
DAWN_ASSERT(DAWN_ASSERT_LOOP_CONDITION && "Unreachable code hit"); \
|
||||
DAWN_BUILTIN_UNREACHABLE(); \
|
||||
} while (DAWN_ASSERT_LOOP_CONDITION)
|
||||
|
||||
#if !defined(NXT_SKIP_ASSERT_SHORTHANDS)
|
||||
# define ASSERT NXT_ASSERT
|
||||
# define UNREACHABLE NXT_UNREACHABLE
|
||||
#if !defined(DAWN_SKIP_ASSERT_SHORTHANDS)
|
||||
# define ASSERT DAWN_ASSERT
|
||||
# define UNREACHABLE DAWN_UNREACHABLE
|
||||
#endif
|
||||
|
||||
void HandleAssertionFailure(const char* file,
|
||||
|
||||
@@ -94,7 +94,7 @@ BitSetIterator<N, T>::Iterator::Iterator(const std::bitset<N>& bits)
|
||||
|
||||
template <size_t N, typename T>
|
||||
typename BitSetIterator<N, T>::Iterator& BitSetIterator<N, T>::Iterator::operator++() {
|
||||
NXT_ASSERT(mBits.any());
|
||||
DAWN_ASSERT(mBits.any());
|
||||
mBits.set(mCurrentBit - mOffset, 0);
|
||||
mCurrentBit = getNextBit();
|
||||
return *this;
|
||||
|
||||
@@ -16,31 +16,31 @@
|
||||
#define COMMON_COMPILER_H_
|
||||
|
||||
// Defines macros for compiler-specific functionality
|
||||
// - NXT_COMPILER_[CLANG|GCC|MSVC]: Compiler detection
|
||||
// - NXT_BREAKPOINT(): Raises an exception and breaks in the debugger
|
||||
// - NXT_BUILTIN_UNREACHABLE(): Hints the compiler that a code path is unreachable
|
||||
// - NXT_NO_DISCARD: An attribute that is C++17 [[nodiscard]] where available
|
||||
// - NXT_(UN)?LIKELY(EXPR): Where available, hints the compiler that the expression will be true
|
||||
// - DAWN_COMPILER_[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_NO_DISCARD: An attribute that is C++17 [[nodiscard]] where available
|
||||
// - DAWN_(UN)?LIKELY(EXPR): Where available, hints the compiler that the expression will be true
|
||||
// (resp. false) to help it generate code that leads to better branch prediction.
|
||||
// - NXT_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR.
|
||||
// - DAWN_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR.
|
||||
|
||||
// Clang and GCC
|
||||
#if defined(__GNUC__)
|
||||
# if defined(__clang__)
|
||||
# define NXT_COMPILER_CLANG
|
||||
# define DAWN_COMPILER_CLANG
|
||||
# else
|
||||
# define NXT_COMPILER_GCC
|
||||
# define DAWN_COMPILER_GCC
|
||||
# endif
|
||||
|
||||
# if defined(__i386__) || defined(__x86_64__)
|
||||
# define NXT_BREAKPOINT() __asm__ __volatile__("int $3\n\t")
|
||||
# define DAWN_BREAKPOINT() __asm__ __volatile__("int $3\n\t")
|
||||
# else
|
||||
# error "Implement BREAKPOINT on your platform"
|
||||
# endif
|
||||
|
||||
# define NXT_BUILTIN_UNREACHABLE() __builtin_unreachable()
|
||||
# define NXT_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
# define NXT_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
# define DAWN_BUILTIN_UNREACHABLE() __builtin_unreachable()
|
||||
# define DAWN_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
# define DAWN_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
# if !defined(__has_cpp_attribute)
|
||||
# define __has_cpp_attribute(name) 0
|
||||
@@ -50,23 +50,23 @@
|
||||
// Also avoid warn_unused_result with GCC because it is only a function attribute and not a type
|
||||
// attribute.
|
||||
# if __has_cpp_attribute(warn_unused_result) && defined(__clang__)
|
||||
# define NXT_NO_DISCARD __attribute__((warn_unused_result))
|
||||
# elif NXT_CPP_VERSION >= 17 && __has_cpp_attribute(nodiscard)
|
||||
# define NXT_NO_DISCARD [[nodiscard]]
|
||||
# define DAWN_NO_DISCARD __attribute__((warn_unused_result))
|
||||
# elif DAWN_CPP_VERSION >= 17 && __has_cpp_attribute(nodiscard)
|
||||
# define DAWN_NO_DISCARD [[nodiscard]]
|
||||
# endif
|
||||
|
||||
// MSVC
|
||||
#elif defined(_MSC_VER)
|
||||
# define NXT_COMPILER_MSVC
|
||||
# define DAWN_COMPILER_MSVC
|
||||
|
||||
extern void __cdecl __debugbreak(void);
|
||||
# define NXT_BREAKPOINT() __debugbreak()
|
||||
# define DAWN_BREAKPOINT() __debugbreak()
|
||||
|
||||
# define NXT_BUILTIN_UNREACHABLE() __assume(false)
|
||||
# define DAWN_BUILTIN_UNREACHABLE() __assume(false)
|
||||
|
||||
// Visual Studio 2017 15.3 adds support for [[nodiscard]]
|
||||
# if _MSC_VER >= 1911 && NXT_CPP_VERSION >= 17
|
||||
# define NXT_NO_DISCARD [[nodiscard]]
|
||||
# if _MSC_VER >= 1911 && DAWN_CPP_VERSION >= 17
|
||||
# define DAWN_NO_DISCARD [[nodiscard]]
|
||||
# endif
|
||||
|
||||
#else
|
||||
@@ -74,17 +74,17 @@ extern void __cdecl __debugbreak(void);
|
||||
#endif
|
||||
|
||||
// It seems that (void) EXPR works on all compilers to silence the unused variable warning.
|
||||
#define NXT_UNUSED(EXPR) (void)EXPR
|
||||
#define DAWN_UNUSED(EXPR) (void)EXPR
|
||||
|
||||
// Add noop replacements for macros for features that aren't supported by the compiler.
|
||||
#if !defined(NXT_LIKELY)
|
||||
# define NXT_LIKELY(X) X
|
||||
#if !defined(DAWN_LIKELY)
|
||||
# define DAWN_LIKELY(X) X
|
||||
#endif
|
||||
#if !defined(NXT_UNLIKELY)
|
||||
# define NXT_UNLIKELY(X) X
|
||||
#if !defined(DAWN_UNLIKELY)
|
||||
# define DAWN_UNLIKELY(X) X
|
||||
#endif
|
||||
#if !defined(NXT_NO_DISCARD)
|
||||
# define NXT_NO_DISCARD
|
||||
#if !defined(DAWN_NO_DISCARD)
|
||||
# define DAWN_NO_DISCARD
|
||||
#endif
|
||||
|
||||
#endif // COMMON_COMPILER_H_
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
#include "common/Platform.h"
|
||||
|
||||
#if NXT_PLATFORM_WINDOWS
|
||||
#if DAWN_PLATFORM_WINDOWS
|
||||
# include "common/windows_with_undefs.h"
|
||||
#elif NXT_PLATFORM_POSIX
|
||||
#elif DAWN_PLATFORM_POSIX
|
||||
# include <dlfcn.h>
|
||||
#else
|
||||
# error "Unsupported platform for DynamicLib"
|
||||
@@ -42,13 +42,13 @@ bool DynamicLib::Valid() const {
|
||||
}
|
||||
|
||||
bool DynamicLib::Open(const std::string& filename, std::string* error) {
|
||||
#if NXT_PLATFORM_WINDOWS
|
||||
#if DAWN_PLATFORM_WINDOWS
|
||||
mHandle = LoadLibraryA(filename.c_str());
|
||||
|
||||
if (mHandle == nullptr && error != nullptr) {
|
||||
*error = "Windows Error: " + std::to_string(GetLastError());
|
||||
}
|
||||
#elif NXT_PLATFORM_POSIX
|
||||
#elif DAWN_PLATFORM_POSIX
|
||||
mHandle = dlopen(filename.c_str(), RTLD_NOW);
|
||||
|
||||
if (mHandle == nullptr && error != nullptr) {
|
||||
@@ -66,9 +66,9 @@ void DynamicLib::Close() {
|
||||
return;
|
||||
}
|
||||
|
||||
#if NXT_PLATFORM_WINDOWS
|
||||
#if DAWN_PLATFORM_WINDOWS
|
||||
FreeLibrary(static_cast<HMODULE>(mHandle));
|
||||
#elif NXT_PLATFORM_POSIX
|
||||
#elif DAWN_PLATFORM_POSIX
|
||||
dlclose(mHandle);
|
||||
#else
|
||||
# error "Unsupported platform for DynamicLib"
|
||||
@@ -80,13 +80,13 @@ void DynamicLib::Close() {
|
||||
void* DynamicLib::GetProc(const std::string& procName, std::string* error) const {
|
||||
void* proc = nullptr;
|
||||
|
||||
#if NXT_PLATFORM_WINDOWS
|
||||
#if DAWN_PLATFORM_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 NXT_PLATFORM_POSIX
|
||||
#elif DAWN_PLATFORM_POSIX
|
||||
proc = reinterpret_cast<void*>(dlsym(mHandle, procName.c_str()));
|
||||
|
||||
if (proc == nullptr && error != nullptr) {
|
||||
|
||||
@@ -36,9 +36,9 @@ size_t Hash(const T& value) {
|
||||
// return hash;
|
||||
template <typename T>
|
||||
void HashCombine(size_t* hash, const T& value) {
|
||||
#if defined(NXT_PLATFORM_64_BIT)
|
||||
#if defined(DAWN_PLATFORM_64_BIT)
|
||||
const size_t offset = 0x9e3779b97f4a7c16;
|
||||
#elif defined(NXT_PLATFORM_32_BIT)
|
||||
#elif defined(DAWN_PLATFORM_32_BIT)
|
||||
const size_t offset = 0x9e3779b9;
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
#include "common/Assert.h"
|
||||
|
||||
#if defined(NXT_COMPILER_MSVC)
|
||||
#if defined(DAWN_COMPILER_MSVC)
|
||||
# include <intrin.h>
|
||||
#endif
|
||||
|
||||
uint32_t ScanForward(uint32_t bits) {
|
||||
ASSERT(bits != 0);
|
||||
#if defined(NXT_COMPILER_MSVC)
|
||||
#if defined(DAWN_COMPILER_MSVC)
|
||||
unsigned long firstBitIndex = 0ul;
|
||||
unsigned char ret = _BitScanForward(&firstBitIndex, bits);
|
||||
ASSERT(ret != 0);
|
||||
@@ -34,7 +34,7 @@ uint32_t ScanForward(uint32_t bits) {
|
||||
|
||||
uint32_t Log2(uint32_t value) {
|
||||
ASSERT(value != 0);
|
||||
#if defined(NXT_COMPILER_MSVC)
|
||||
#if defined(DAWN_COMPILER_MSVC)
|
||||
unsigned long firstBitIndex = 0ul;
|
||||
unsigned char ret = _BitScanReverse(&firstBitIndex, value);
|
||||
ASSERT(ret != 0);
|
||||
|
||||
@@ -16,22 +16,22 @@
|
||||
#define COMMON_PLATFORM_H_
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# define NXT_PLATFORM_WINDOWS 1
|
||||
# define DAWN_PLATFORM_WINDOWS 1
|
||||
#elif defined(__linux__)
|
||||
# define NXT_PLATFORM_LINUX 1
|
||||
# define NXT_PLATFORM_POSIX 1
|
||||
# define DAWN_PLATFORM_LINUX 1
|
||||
# define DAWN_PLATFORM_POSIX 1
|
||||
#elif defined(__APPLE__)
|
||||
# define NXT_PLATFORM_APPLE 1
|
||||
# define NXT_PLATFORM_POSIX 1
|
||||
# define DAWN_PLATFORM_APPLE 1
|
||||
# define DAWN_PLATFORM_POSIX 1
|
||||
#else
|
||||
# error "Unsupported platform."
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64) || defined(__aarch64__) || defined(__x86_64__)
|
||||
# define NXT_PLATFORM_64_BIT 1
|
||||
# define DAWN_PLATFORM_64_BIT 1
|
||||
static_assert(sizeof(sizeof(char)) == 8, "Expect sizeof(size_t) == 8");
|
||||
#elif defined(_WIN32) || defined(__i386__) || defined(__arm__)
|
||||
# define NXT_PLATFORM_32_BIT 1
|
||||
# define DAWN_PLATFORM_32_BIT 1
|
||||
static_assert(sizeof(sizeof(char)) == 4, "Expect sizeof(size_t) == 4");
|
||||
#else
|
||||
# error "Unsupported platform"
|
||||
|
||||
@@ -55,7 +55,7 @@ class Result;
|
||||
// Specialization of Result for returning errors only via pointers. It is basically a pointer
|
||||
// where nullptr is both Success and Empty.
|
||||
template <typename E>
|
||||
class NXT_NO_DISCARD Result<void, E*> {
|
||||
class DAWN_NO_DISCARD Result<void, E*> {
|
||||
public:
|
||||
Result();
|
||||
Result(E* error);
|
||||
@@ -85,7 +85,7 @@ constexpr size_t alignof_if_defined_else_default<T, Default, decltype(alignof(T)
|
||||
// Specialization of Result when both the error an success are pointers. It is implemented as a
|
||||
// tagged pointer. The tag for Success is 0 so that returning the value is fastest.
|
||||
template <typename T, typename E>
|
||||
class NXT_NO_DISCARD Result<T*, E*> {
|
||||
class DAWN_NO_DISCARD Result<T*, E*> {
|
||||
public:
|
||||
static_assert(alignof_if_defined_else_default<T, 4> >= 4,
|
||||
"Result<T*, E*> reserves two bits for tagging pointers");
|
||||
|
||||
@@ -117,7 +117,7 @@ class SerialQueue {
|
||||
|
||||
template <typename T>
|
||||
void SerialQueue<T>::Enqueue(const T& value, Serial serial) {
|
||||
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
DAWN_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
|
||||
if (Empty() || mStorage.back().first < serial) {
|
||||
mStorage.emplace_back(SerialPair(serial, {}));
|
||||
@@ -127,7 +127,7 @@ void SerialQueue<T>::Enqueue(const T& value, Serial serial) {
|
||||
|
||||
template <typename T>
|
||||
void SerialQueue<T>::Enqueue(T&& value, Serial serial) {
|
||||
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
DAWN_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
|
||||
if (Empty() || mStorage.back().first < serial) {
|
||||
mStorage.emplace_back(SerialPair(serial, {}));
|
||||
@@ -137,15 +137,15 @@ void SerialQueue<T>::Enqueue(T&& value, Serial serial) {
|
||||
|
||||
template <typename T>
|
||||
void SerialQueue<T>::Enqueue(const std::vector<T>& values, Serial serial) {
|
||||
NXT_ASSERT(values.size() > 0);
|
||||
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
DAWN_ASSERT(values.size() > 0);
|
||||
DAWN_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
mStorage.emplace_back(SerialPair(serial, {values}));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SerialQueue<T>::Enqueue(std::vector<T>&& values, Serial serial) {
|
||||
NXT_ASSERT(values.size() > 0);
|
||||
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
DAWN_ASSERT(values.size() > 0);
|
||||
DAWN_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||
mStorage.emplace_back(SerialPair(serial, {values}));
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ void SerialQueue<T>::ClearUpTo(Serial serial) {
|
||||
|
||||
template <typename T>
|
||||
Serial SerialQueue<T>::FirstSerial() const {
|
||||
NXT_ASSERT(!Empty());
|
||||
DAWN_ASSERT(!Empty());
|
||||
return mStorage.front().first;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class VkNonDispatchableHandle {
|
||||
|
||||
// Remove windows.h macros after vulkan_platform's include of windows.h
|
||||
#include "common/Platform.h"
|
||||
#if defined(NXT_PLATFORM_WINDOWS)
|
||||
#if defined(DAWN_PLATFORM_WINDOWS)
|
||||
# include "common/windows_with_undefs.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "common/Compiler.h"
|
||||
|
||||
#if !defined(NXT_PLATFORM_WINDOWS)
|
||||
#if !defined(DAWN_PLATFORM_WINDOWS)
|
||||
# error "windows_with_undefs.h included on non-Windows"
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user