Large cleanup.
This commit is contained in:
parent
8769215437
commit
76a7927643
|
|
@ -17,8 +17,6 @@
|
|||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
|
||||
|
||||
#define EASTL_NO_EXCEPTIONS 1
|
||||
// ReSharper disable once CppInconsistentNaming
|
||||
#define _HAS_EXCEPTIONS 0
|
||||
|
||||
#if defined(NDEBUG)
|
||||
#define USE_OPTICK (0)
|
||||
|
|
|
|||
|
|
@ -30,19 +30,6 @@ using usize = size_t;
|
|||
using p64 = intptr_t;
|
||||
using cstr = const char *;
|
||||
|
||||
constexpr usize
|
||||
strlenC(const char *s)
|
||||
{
|
||||
usize len = 0;
|
||||
char c = '\0';
|
||||
do
|
||||
{
|
||||
c = s[len];
|
||||
len++;
|
||||
} while (c != '\0');
|
||||
return len;
|
||||
}
|
||||
|
||||
namespace ansi_color
|
||||
{
|
||||
constexpr auto Black = "\u001b[30m";
|
||||
|
|
@ -56,42 +43,42 @@ constexpr auto White = "\u001b[37m";
|
|||
constexpr auto Reset = "\u001b[0m";
|
||||
} // namespace ansi_color
|
||||
|
||||
template <typename TypeT, typename FromT>
|
||||
template <typename TType, typename TFrom>
|
||||
constexpr auto
|
||||
cast(FromT &&in)
|
||||
Cast(TFrom &&in)
|
||||
{
|
||||
return static_cast<TypeT>(std::forward<FromT>(in));
|
||||
return static_cast<TType>(std::forward<TFrom>(in));
|
||||
}
|
||||
|
||||
template <typename TypeT, typename FromT>
|
||||
template <typename TType, typename TFrom>
|
||||
constexpr auto
|
||||
recast(FromT &&in)
|
||||
Recast(TFrom &&in)
|
||||
{
|
||||
return reinterpret_cast<TypeT>(std::forward<FromT>(in));
|
||||
return reinterpret_cast<TType>(std::forward<TFrom>(in));
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_deg(long double degrees)
|
||||
{
|
||||
return glm::radians<f32>(cast<f32>(degrees));
|
||||
return glm::radians<f32>(Cast<f32>(degrees));
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_deg(unsigned long long int degrees)
|
||||
{
|
||||
return glm::radians<f32>(cast<f32>(degrees));
|
||||
return glm::radians<f32>(Cast<f32>(degrees));
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_rad(long double rads)
|
||||
{
|
||||
return cast<f32>(rads);
|
||||
return Cast<f32>(rads);
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_rad(unsigned long long int rads)
|
||||
{
|
||||
return cast<f32>(rads);
|
||||
return Cast<f32>(rads);
|
||||
}
|
||||
|
||||
using glm::ivec2;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ constexpr eastl::array VALIDATION_LAYERS = {
|
|||
};
|
||||
|
||||
VKAPI_ATTR b32 VKAPI_CALL
|
||||
DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||
DebugCallback(const VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
const VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT *callbackData, [[maybe_unused]] void *userData)
|
||||
{
|
||||
using Severity = vk::DebugUtilsMessageSeverityFlagsEXT;
|
||||
|
|
@ -37,7 +38,7 @@ DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUti
|
|||
return false;
|
||||
}
|
||||
|
||||
Context::Context(cstr appName, Version version, bool enableValidation)
|
||||
Context::Context(const cstr appName, const Version version, bool enableValidation)
|
||||
{
|
||||
INFO_IF(enableValidation, "Validation Layers enabled");
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ Context::Context(cstr appName, Version version, bool enableValidation)
|
|||
.apiVersion = ASTER_API_VERSION,
|
||||
};
|
||||
|
||||
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfo = {
|
||||
const vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfo = {
|
||||
.messageSeverity = vk::DebugUtilsMessageSeverityFlagBitsEXT::eError |
|
||||
vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
|
||||
vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo,
|
||||
|
|
@ -77,14 +78,14 @@ Context::Context(cstr appName, Version version, bool enableValidation)
|
|||
const auto instanceCreateInfo = vk::InstanceCreateInfo{
|
||||
.pNext = enableValidation ? &debugUtilsMessengerCreateInfo : nullptr,
|
||||
.pApplicationInfo = &appInfo,
|
||||
.enabledLayerCount = enableValidation ? cast<u32>(VALIDATION_LAYERS.size()) : 0,
|
||||
.enabledLayerCount = enableValidation ? Cast<u32>(VALIDATION_LAYERS.size()) : 0,
|
||||
.ppEnabledLayerNames = enableValidation ? VALIDATION_LAYERS.data() : nullptr,
|
||||
.enabledExtensionCount = cast<u32>(instanceExtensions.size()),
|
||||
.enabledExtensionCount = Cast<u32>(instanceExtensions.size()),
|
||||
.ppEnabledExtensionNames = instanceExtensions.data(),
|
||||
};
|
||||
|
||||
// May throw. Irrecoverable.
|
||||
vk::Result result = vk::createInstance(&instanceCreateInfo, nullptr, &m_Instance);
|
||||
vk::Result result = createInstance(&instanceCreateInfo, nullptr, &m_Instance);
|
||||
ERROR_IF(result, "Instance creation failed. Cause: {}", result)
|
||||
THEN_ABORT(result)
|
||||
ELSE_DEBUG("Instance Created.");
|
||||
|
|
|
|||
|
|
@ -41,15 +41,15 @@ Device::Device(const Context *context, PhysicalDevice *physicalDevice,
|
|||
}
|
||||
|
||||
vk::DeviceCreateInfo deviceCreateInfo = {
|
||||
.queueCreateInfoCount = cast<u32>(deviceQueueCreateInfos.size()),
|
||||
.queueCreateInfoCount = Cast<u32>(deviceQueueCreateInfos.size()),
|
||||
.pQueueCreateInfos = deviceQueueCreateInfos.data(),
|
||||
.enabledExtensionCount = cast<u32>(DEVICE_EXTENSIONS.size()),
|
||||
.enabledExtensionCount = Cast<u32>(DEVICE_EXTENSIONS.size()),
|
||||
.ppEnabledExtensionNames = DEVICE_EXTENSIONS.data(),
|
||||
.pEnabledFeatures = enabledFeatures,
|
||||
};
|
||||
|
||||
vk::Result result = m_PhysicalDevice.createDevice(&deviceCreateInfo, nullptr, &m_Device);
|
||||
ERROR_IF(failed(result), "Could not initialize Vulkan Device. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not initialize Vulkan Device. Cause: {}", result)
|
||||
THEN_ABORT(result)
|
||||
ELSE_DEBUG("{} ({}) Initialized.", m_Name, physicalDevice->m_DeviceProperties.deviceName.data());
|
||||
|
||||
|
|
@ -66,8 +66,8 @@ Device::Device(const Context *context, PhysicalDevice *physicalDevice,
|
|||
.vulkanApiVersion = ASTER_API_VERSION,
|
||||
};
|
||||
|
||||
result = cast<vk::Result>(vmaCreateAllocator(&allocatorCreateInfo, &m_Allocator));
|
||||
ERROR_IF(failed(result), "Memory allocator creation failed. Cause: {}", result)
|
||||
result = Cast<vk::Result>(vmaCreateAllocator(&allocatorCreateInfo, &m_Allocator));
|
||||
ERROR_IF(Failed(result), "Memory allocator creation failed. Cause: {}", result)
|
||||
DO(m_Device.destroy(nullptr))
|
||||
THEN_ABORT(result)
|
||||
ELSE_VERBOSE("Memory Allocator Created");
|
||||
|
|
|
|||
|
|
@ -35,72 +35,41 @@ constexpr u32 ASTER_API_VERSION = vk::ApiVersion13;
|
|||
#define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__)
|
||||
|
||||
[[nodiscard]] inline bool
|
||||
failed(const vk::Result result)
|
||||
Failed(const vk::Result result)
|
||||
{
|
||||
return result != vk::Result::eSuccess;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
concept IsVkEnum = requires(T t) {
|
||||
{
|
||||
std::is_enum_v<T>
|
||||
};
|
||||
{
|
||||
vk::to_string(t)
|
||||
} -> std::same_as<std::string>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
requires IsVkEnum<T>
|
||||
[[nodiscard]] const char *
|
||||
toCstr(const T &val)
|
||||
{
|
||||
static std::string buffer;
|
||||
buffer = vk::to_string(val);
|
||||
return buffer.c_str();
|
||||
}
|
||||
|
||||
using NameString = eastl::fixed_string<char, 32, false>;
|
||||
|
||||
// TODO: Check why inline namespaces aren't working in MSVC 19.27.29110
|
||||
using namespace std::literals::string_literals;
|
||||
using namespace std::literals::string_view_literals;
|
||||
|
||||
template <typename T>
|
||||
requires vk::isVulkanHandleType<T>::value
|
||||
[[nodiscard]] constexpr u64
|
||||
getVkHandle(const T &vkHandle) noexcept
|
||||
{
|
||||
return reinterpret_cast<u64>(cast<T::CType>(vkHandle));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
struct std::hash<vk::Flags<F>>
|
||||
template <typename TFlagBits>
|
||||
struct std::hash<vk::Flags<TFlagBits>> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
[[nodiscard]] usize
|
||||
operator()(const vk::Flags<F> &val)
|
||||
operator()(const vk::Flags<TFlagBits> &val)
|
||||
{
|
||||
return std::hash<u32>()(cast<u32>(val));
|
||||
return std::hash<u32>()(Cast<u32>(val));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] usize
|
||||
hashAny(const T &val)
|
||||
HashAny(const T &val)
|
||||
{
|
||||
return std::hash<std::remove_cvref_t<T>>()(val);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline usize
|
||||
hashCombine(const usize hash0, const usize hash1)
|
||||
HashCombine(const usize hash0, const usize hash1)
|
||||
{
|
||||
constexpr usize saltValue = 0x9e3779b9;
|
||||
return hash0 ^ (hash1 + saltValue + (hash0 << 6) + (hash0 >> 2));
|
||||
const usize tempVar = hash1 + saltValue + (hash0 << 6) + (hash0 >> 2);
|
||||
return hash0 ^ tempVar;
|
||||
}
|
||||
|
||||
struct Time
|
||||
{
|
||||
static constexpr f64 c_MaxDelta = 0.1;
|
||||
static constexpr f64 cMaxDelta = 0.1;
|
||||
|
||||
inline static f64 m_Elapsed{Qnan<f64>};
|
||||
inline static f64 m_Delta{Qnan<f64>};
|
||||
|
|
@ -118,13 +87,13 @@ struct Time
|
|||
{
|
||||
ERROR_IF(std::isnan(m_Elapsed), "Time not init.");
|
||||
const auto newElapsed = glfwGetTime();
|
||||
m_Delta = std::clamp(newElapsed - m_Elapsed, 0.0, c_MaxDelta);
|
||||
m_Delta = std::clamp(newElapsed - m_Elapsed, 0.0, cMaxDelta);
|
||||
m_Elapsed = newElapsed;
|
||||
}
|
||||
};
|
||||
|
||||
[[nodiscard]] inline usize
|
||||
closestMultiple(const usize val, const usize of)
|
||||
ClosestMultiple(const usize val, const usize of)
|
||||
{
|
||||
return of * ((val + of - 1) / of);
|
||||
}
|
||||
|
|
@ -141,12 +110,12 @@ struct fmt::formatter<vk::Result> : nested_formatter<std::string>
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T, usize N, bool B>
|
||||
struct fmt::formatter<eastl::fixed_string<T, N, B>> : nested_formatter<cstr>
|
||||
template <typename TType, usize TCount, bool TOverflow>
|
||||
struct fmt::formatter<eastl::fixed_string<TType, TCount, TOverflow>> : nested_formatter<cstr>
|
||||
{
|
||||
auto
|
||||
// ReSharper disable once CppInconsistentNaming
|
||||
format(const eastl::fixed_string<T, N, B> &str, format_context &ctx) const
|
||||
format(const eastl::fixed_string<TType, TCount, TOverflow> &str, format_context &ctx) const
|
||||
{
|
||||
return write_padded(ctx, [this, str](auto out) { return v10::format_to(out, "{}", nested(str.c_str())); });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,76 +20,76 @@ struct Logger
|
|||
eVerbose,
|
||||
};
|
||||
|
||||
u32 m_MinimumLoggingLevel{cast<u32>(LogType::eDebug)};
|
||||
u32 m_MinimumLoggingLevel{Cast<u32>(LogType::eDebug)};
|
||||
|
||||
void
|
||||
SetMinimumLoggingLevel(LogType logType)
|
||||
{
|
||||
m_MinimumLoggingLevel = cast<u32>(logType);
|
||||
m_MinimumLoggingLevel = Cast<u32>(logType);
|
||||
}
|
||||
|
||||
template <LogType LogLevel>
|
||||
template <LogType TLogLevel>
|
||||
constexpr static const char *
|
||||
ToCstr()
|
||||
{
|
||||
if constexpr (LogLevel == LogType::eError)
|
||||
if constexpr (TLogLevel == LogType::eError)
|
||||
return "[ERROR]:";
|
||||
if constexpr (LogLevel == LogType::eWarning)
|
||||
if constexpr (TLogLevel == LogType::eWarning)
|
||||
return "[WARN]: ";
|
||||
if constexpr (LogLevel == LogType::eInfo)
|
||||
if constexpr (TLogLevel == LogType::eInfo)
|
||||
return "[INFO]: ";
|
||||
if constexpr (LogLevel == LogType::eDebug)
|
||||
if constexpr (TLogLevel == LogType::eDebug)
|
||||
return "[DEBUG]:";
|
||||
if constexpr (LogLevel == LogType::eVerbose)
|
||||
if constexpr (TLogLevel == LogType::eVerbose)
|
||||
return "[VERB]: ";
|
||||
return "";
|
||||
}
|
||||
|
||||
template <LogType LogLevel>
|
||||
template <LogType TLogLevel>
|
||||
constexpr static const char *
|
||||
ToColorCstr()
|
||||
{
|
||||
if constexpr (LogLevel == LogType::eError)
|
||||
if constexpr (TLogLevel == LogType::eError)
|
||||
return ansi_color::Red;
|
||||
if constexpr (LogLevel == LogType::eWarning)
|
||||
if constexpr (TLogLevel == LogType::eWarning)
|
||||
return ansi_color::Yellow;
|
||||
if constexpr (LogLevel == LogType::eInfo)
|
||||
if constexpr (TLogLevel == LogType::eInfo)
|
||||
return ansi_color::Green;
|
||||
if constexpr (LogLevel == LogType::eDebug)
|
||||
if constexpr (TLogLevel == LogType::eDebug)
|
||||
return ansi_color::White;
|
||||
if constexpr (LogLevel == LogType::eVerbose)
|
||||
if constexpr (TLogLevel == LogType::eVerbose)
|
||||
return ansi_color::Blue;
|
||||
return ansi_color::White;
|
||||
}
|
||||
|
||||
template <LogType LogLevel>
|
||||
template <LogType TLogLevel>
|
||||
void
|
||||
Log(const std::string_view &message, const char *loc, u32 line) const
|
||||
{
|
||||
if (cast<u32>(LogLevel) <= m_MinimumLoggingLevel)
|
||||
if (Cast<u32>(TLogLevel) <= m_MinimumLoggingLevel)
|
||||
{
|
||||
fmt::println("{}{} {} {} at {}:{}{}", ToColorCstr<LogLevel>(), ToCstr<LogLevel>(), message.data(),
|
||||
fmt::println("{}{} {} {} at {}:{}{}", ToColorCstr<TLogLevel>(), ToCstr<TLogLevel>(), message.data(),
|
||||
ansi_color::Black, loc, line, ansi_color::Reset);
|
||||
}
|
||||
#if !defined(NDEBUG)
|
||||
if constexpr (LogLevel == LogType::eError)
|
||||
if constexpr (TLogLevel == LogType::eError)
|
||||
{
|
||||
debug_break();
|
||||
}
|
||||
#endif // !defined(NDEBUG)
|
||||
}
|
||||
|
||||
template <LogType LogLevel>
|
||||
template <LogType TLogLevel>
|
||||
void
|
||||
LogCond(const char *exprStr, const std::string_view &message, const char *loc, u32 line) const
|
||||
{
|
||||
if (cast<u32>(LogLevel) <= m_MinimumLoggingLevel)
|
||||
if (Cast<u32>(TLogLevel) <= m_MinimumLoggingLevel)
|
||||
{
|
||||
fmt::println("{}{} ({}) {} {} at {}:{}{}", ToColorCstr<LogLevel>(), ToCstr<LogLevel>(), exprStr,
|
||||
fmt::println("{}{} ({}) {} {} at {}:{}{}", ToColorCstr<TLogLevel>(), ToCstr<TLogLevel>(), exprStr,
|
||||
message.data(), ansi_color::Black, loc, line, ansi_color::Reset);
|
||||
}
|
||||
#if !defined(NDEBUG)
|
||||
if constexpr (LogLevel == LogType::eError)
|
||||
if constexpr (TLogLevel == LogType::eError)
|
||||
{
|
||||
debug_break();
|
||||
}
|
||||
|
|
@ -105,26 +105,26 @@ extern Logger g_Logger;
|
|||
#define INFO(...) g_Logger.Log<Logger::LogType::eInfo>(fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
|
||||
#define ERROR_IF(expr, ...) \
|
||||
if (cast<bool>(expr)) [[unlikely]] \
|
||||
if (Cast<bool>(expr)) [[unlikely]] \
|
||||
g_Logger.LogCond<Logger::LogType::eError>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define WARN_IF(expr, ...) \
|
||||
if (cast<bool>(expr)) [[unlikely]] \
|
||||
if (Cast<bool>(expr)) [[unlikely]] \
|
||||
g_Logger.LogCond<Logger::LogType::eWarning>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define INFO_IF(expr, ...) \
|
||||
if (cast<bool>(expr)) \
|
||||
if (Cast<bool>(expr)) \
|
||||
g_Logger.LogCond<Logger::LogType::eInfo>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
|
||||
#define ELSE_IF_ERROR(expr, ...) \
|
||||
; \
|
||||
else if (cast<bool>(expr)) \
|
||||
else if (Cast<bool>(expr)) \
|
||||
[[unlikely]] g_Logger.LogCond<Logger::LogType::eError>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define ELSE_IF_WARN(expr, ...) \
|
||||
; \
|
||||
else if (cast<bool>(expr)) \
|
||||
else if (Cast<bool>(expr)) \
|
||||
[[unlikely]] g_Logger.LogCond<Logger::LogType::eWarning>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define ELSE_IF_INFO(expr, ...) \
|
||||
; \
|
||||
else if (cast<bool>(expr)) \
|
||||
else if (Cast<bool>(expr)) \
|
||||
g_Logger.LogCond<Logger::LogType::eInfo>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
|
||||
#define ELSE_ERROR(...) \
|
||||
|
|
@ -141,11 +141,11 @@ extern Logger g_Logger;
|
|||
|
||||
#define DEBUG(...) g_Logger.Log<Logger::LogType::eDebug>(fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define DEBUG_IF(expr, ...) \
|
||||
if (cast<bool>(expr)) \
|
||||
if (Cast<bool>(expr)) \
|
||||
g_Logger.LogCond<Logger::LogType::eDebug>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define ELSE_IF_DEBUG(expr, ...) \
|
||||
; \
|
||||
else if (cast<bool>(expr)) \
|
||||
else if (Cast<bool>(expr)) \
|
||||
g_Logger.LogCond<Logger::LogType::eDebug>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define ELSE_DEBUG(...) \
|
||||
; \
|
||||
|
|
@ -174,11 +174,11 @@ extern Logger g_Logger;
|
|||
|
||||
#define VERBOSE(...) g_Logger.Log<Logger::LogType::eVerbose>(fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define VERBOSE_IF(expr, ...) \
|
||||
if (cast<bool>(expr)) \
|
||||
if (Cast<bool>(expr)) \
|
||||
g_Logger.LogCond<Logger::LogType::eVerbose>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define ELSE_IF_VERBOSE(expr, ...) \
|
||||
; \
|
||||
else if (cast<bool>(expr)) \
|
||||
else if (Cast<bool>(expr)) \
|
||||
g_Logger.LogCond<Logger::LogType::eVerbose>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
|
||||
#define ELSE_VERBOSE(...) \
|
||||
; \
|
||||
|
|
@ -204,5 +204,5 @@ extern Logger g_Logger;
|
|||
#endif // !defined(VERBOSE_LOG_DISABLED)
|
||||
|
||||
#define DO(code) , code
|
||||
#define ABORT(code) exit(cast<i32>(code))
|
||||
#define ABORT(code) exit(Cast<i32>(code))
|
||||
#define THEN_ABORT(code) , ABORT(code)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ GetSurfaceCapabilities(const vk::PhysicalDevice physicalDevice, const vk::Surfac
|
|||
vk::SurfaceCapabilitiesKHR surfaceCapabilities;
|
||||
|
||||
vk::Result result = physicalDevice.getSurfaceCapabilitiesKHR(surface, &surfaceCapabilities);
|
||||
ERROR_IF(failed(result), "Fetching surface capabilities failed. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Fetching surface capabilities failed. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
return surfaceCapabilities;
|
||||
|
|
@ -26,12 +26,12 @@ GetSurfaceFormats(const vk::PhysicalDevice physicalDevice, const vk::SurfaceKHR
|
|||
// vk::Result::eIncomplete should not occur in this function. The rest are errors. Thus, abort is allowed.
|
||||
u32 count = 0;
|
||||
vk::Result result = physicalDevice.getSurfaceFormatsKHR(surface, &count, nullptr);
|
||||
ERROR_IF(failed(result), "Could not get surface formats. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not get surface formats. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
eastl::vector<vk::SurfaceFormatKHR> surfaceFormats(count);
|
||||
result = physicalDevice.getSurfaceFormatsKHR(surface, &count, surfaceFormats.data());
|
||||
ERROR_IF(failed(result), "Could not get surface formats. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not get surface formats. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
return surfaceFormats;
|
||||
|
|
@ -43,23 +43,24 @@ GetSurfacePresentModes(const vk::PhysicalDevice physicalDevice, const vk::Surfac
|
|||
// vk::Result::eIncomplete should not occur in this function. The rest are errors. Thus, abort is allowed.
|
||||
u32 count = 0;
|
||||
vk::Result result = physicalDevice.getSurfacePresentModesKHR(surface, &count, nullptr);
|
||||
ERROR_IF(failed(result), "Could not get present modes. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not get present modes. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
eastl::vector<vk::PresentModeKHR> presentModes(count);
|
||||
result = physicalDevice.getSurfacePresentModesKHR(surface, &count, presentModes.data());
|
||||
ERROR_IF(failed(result), "Could not get present modes. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not get present modes. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
return presentModes;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool
|
||||
GetQueuePresentSupport(const u32 queueFamilyIndex, vk::SurfaceKHR surface, const vk::PhysicalDevice physicalDevice)
|
||||
GetQueuePresentSupport(const u32 queueFamilyIndex, const vk::SurfaceKHR surface,
|
||||
const vk::PhysicalDevice physicalDevice)
|
||||
{
|
||||
b32 supported = false;
|
||||
const vk::Result result = physicalDevice.getSurfaceSupportKHR(queueFamilyIndex, surface, &supported);
|
||||
ERROR_IF(failed(result), "Could not get queue family surface support. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not get queue family surface support. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
return supported;
|
||||
|
|
@ -142,12 +143,12 @@ EnumeratePhysicalDevices(const vk::Instance instance)
|
|||
{
|
||||
u32 count = 0;
|
||||
vk::Result result = instance.enumeratePhysicalDevices(&count, nullptr);
|
||||
ERROR_IF(failed(result), "Could not fetch vulkan devices. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not fetch vulkan devices. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
eastl::fixed_vector<vk::PhysicalDevice, 8> physicalDevices(count);
|
||||
result = instance.enumeratePhysicalDevices(&count, physicalDevices.data());
|
||||
ERROR_IF(failed(result), "Could not fetch vulkan devices. Cause: {}", result)
|
||||
ERROR_IF(Failed(result), "Could not fetch vulkan devices. Cause: {}", result)
|
||||
THEN_ABORT(result);
|
||||
|
||||
return physicalDevices;
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@ Swapchain::Create(const Window *window)
|
|||
if (swapchainFormat == vk::Format::eUndefined)
|
||||
{
|
||||
WARN("Preferred Swapchain format not found. Falling back.");
|
||||
auto surfaceFormat = surfaceFormats.front();
|
||||
swapchainFormat = surfaceFormat.format;
|
||||
swapchainColorSpace = surfaceFormat.colorSpace;
|
||||
auto [format, colorSpace] = surfaceFormats.front();
|
||||
swapchainFormat = format;
|
||||
swapchainColorSpace = colorSpace;
|
||||
}
|
||||
|
||||
vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo;
|
||||
for (auto presentMode : presentModes)
|
||||
for (const auto presentMode : presentModes)
|
||||
{
|
||||
if (presentMode == vk::PresentModeKHR::eMailbox)
|
||||
{
|
||||
|
|
@ -68,12 +68,12 @@ Swapchain::Create(const Window *window)
|
|||
}
|
||||
else
|
||||
{
|
||||
vk::Extent2D extent = window->GetSize();
|
||||
vk::Extent2D minExtent = surfaceCapabilities.minImageExtent;
|
||||
vk::Extent2D maxExtent = surfaceCapabilities.maxImageExtent;
|
||||
auto [width, height] = window->GetSize();
|
||||
auto [minWidth, minHeight] = surfaceCapabilities.minImageExtent;
|
||||
auto [maxWidth, maxHeight] = surfaceCapabilities.maxImageExtent;
|
||||
|
||||
swapchainExtent.width = glm::clamp(extent.width, minExtent.width, maxExtent.width);
|
||||
swapchainExtent.height = glm::clamp(extent.height, minExtent.height, maxExtent.height);
|
||||
swapchainExtent.width = glm::clamp(width, minWidth, maxWidth);
|
||||
swapchainExtent.height = glm::clamp(height, minHeight, maxHeight);
|
||||
}
|
||||
|
||||
u32 swapchainImageCount = 3;
|
||||
|
|
@ -103,7 +103,7 @@ Swapchain::Create(const Window *window)
|
|||
|
||||
vk::SwapchainKHR swapchain;
|
||||
vk::Result result = m_Device->m_Device.createSwapchainKHR(&swapchainCreateInfo, nullptr, &swapchain);
|
||||
ERROR_IF(failed(result), "Swapchain {} creation failed. Cause {}", m_Name, result)
|
||||
ERROR_IF(Failed(result), "Swapchain {} creation failed. Cause {}", m_Name, result)
|
||||
THEN_ABORT(result)
|
||||
ELSE_DEBUG("Created Swapchain '{}'", m_Name);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ Window::SetWindowSize(const vk::Extent2D &extent) const noexcept
|
|||
void
|
||||
Window::SetWindowSize(const u32 width, const u32 height) const noexcept
|
||||
{
|
||||
glfwSetWindowSize(m_Window, cast<i32>(width), cast<i32>(height));
|
||||
glfwSetWindowSize(m_Window, Cast<i32>(width), Cast<i32>(height));
|
||||
}
|
||||
|
||||
vk::Extent2D
|
||||
|
|
@ -27,10 +27,10 @@ Window::GetSize() const
|
|||
int width;
|
||||
int height;
|
||||
glfwGetWindowSize(m_Window, &width, &height);
|
||||
return {cast<u32>(width), cast<u32>(height)};
|
||||
return {Cast<u32>(width), Cast<u32>(height)};
|
||||
}
|
||||
|
||||
Window::Window(cstr title, Context *context, vk::Extent2D extent, b8 isFullScreen)
|
||||
Window::Window(const cstr title, Context *context, vk::Extent2D extent, const b8 isFullScreen)
|
||||
{
|
||||
m_Context = context;
|
||||
m_Name = title;
|
||||
|
|
@ -44,7 +44,7 @@ Window::Window(cstr title, Context *context, vk::Extent2D extent, b8 isFullScree
|
|||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_CENTER_CURSOR, GLFW_TRUE);
|
||||
|
||||
m_Window = glfwCreateWindow(cast<i32>(extent.width), cast<i32>(extent.height), m_Name.c_str(),
|
||||
m_Window = glfwCreateWindow(Cast<i32>(extent.width), Cast<i32>(extent.height), m_Name.c_str(),
|
||||
isFullScreen ? monitor : nullptr, nullptr);
|
||||
ERROR_IF(m_Window == nullptr, "Window creation failed")
|
||||
ELSE_DEBUG("Window '{}' created with resolution '{}x{}'", m_Name, extent.width, extent.height);
|
||||
|
|
@ -57,15 +57,15 @@ Window::Window(cstr title, Context *context, vk::Extent2D extent, b8 isFullScree
|
|||
|
||||
if (isFullScreen == false)
|
||||
{
|
||||
glfwSetWindowPos(m_Window, cast<i32>(windowWidth - extent.width) / 2,
|
||||
cast<i32>(windowHeight - extent.height) / 2);
|
||||
glfwSetWindowPos(m_Window, Cast<i32>(windowWidth - extent.width) / 2,
|
||||
Cast<i32>(windowHeight - extent.height) / 2);
|
||||
}
|
||||
glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
auto result =
|
||||
cast<vk::Result>(glfwCreateWindowSurface(cast<VkInstance>(m_Context->m_Instance), m_Window, nullptr, &surface));
|
||||
ERROR_IF(failed(result), "Failed to create Surface with {}", result)
|
||||
Cast<vk::Result>(glfwCreateWindowSurface(Cast<VkInstance>(m_Context->m_Instance), m_Window, nullptr, &surface));
|
||||
ERROR_IF(Failed(result), "Failed to create Surface with {}", result)
|
||||
THEN_ABORT(result)
|
||||
ELSE_DEBUG("Surface {} Created", m_Name);
|
||||
m_Surface = vk::SurfaceKHR(surface);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ constexpr QueueSupportFlags REQUIRED_QUEUE_SUPPORT = QueueSupportFlags{} | Queue
|
|||
QueueSupportFlagBits::eTransfer;
|
||||
|
||||
[[nodiscard]] bool
|
||||
isSuitableDevice(const PhysicalDevice *physicalDevice)
|
||||
IsSuitableDevice(const PhysicalDevice *physicalDevice)
|
||||
{
|
||||
const bool hasAllRequiredQueues =
|
||||
std::ranges::any_of(physicalDevice->m_QueueFamilies, [](const auto &queueFamilyProp) {
|
||||
|
|
@ -30,11 +30,11 @@ isSuitableDevice(const PhysicalDevice *physicalDevice)
|
|||
}
|
||||
|
||||
PhysicalDevice
|
||||
findSuitableDevice(const PhysicalDevices &physicalDevices)
|
||||
FindSuitableDevice(const PhysicalDevices &physicalDevices)
|
||||
{
|
||||
for (auto &physicalDevice : physicalDevices)
|
||||
{
|
||||
if (isSuitableDevice(&physicalDevice))
|
||||
if (IsSuitableDevice(&physicalDevice))
|
||||
{
|
||||
return physicalDevice;
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ findSuitableDevice(const PhysicalDevices &physicalDevices)
|
|||
}
|
||||
|
||||
QueueAllocation
|
||||
findAppropriateQueueAllocation(const PhysicalDevice *physicalDevice)
|
||||
FindAppropriateQueueAllocation(const PhysicalDevice *physicalDevice)
|
||||
{
|
||||
for (auto &queueFamilyInfo : physicalDevice->m_QueueFamilies)
|
||||
{
|
||||
|
|
@ -71,12 +71,12 @@ main(int, char **)
|
|||
Window window = {"Aster1", &context, {640, 480}};
|
||||
|
||||
PhysicalDevices physicalDevices = {&window, &context};
|
||||
PhysicalDevice deviceToUse = findSuitableDevice(physicalDevices);
|
||||
PhysicalDevice deviceToUse = FindSuitableDevice(physicalDevices);
|
||||
|
||||
INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data());
|
||||
|
||||
vk::PhysicalDeviceFeatures features = {};
|
||||
QueueAllocation queueAllocation = findAppropriateQueueAllocation(&deviceToUse);
|
||||
QueueAllocation queueAllocation = FindAppropriateQueueAllocation(&deviceToUse);
|
||||
|
||||
Device device = {&context, &deviceToUse, &features, {queueAllocation}, "Primary Device"};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue