Remove Cast and Recast.

This commit is contained in:
Anish Bhobe 2025-05-07 17:39:47 +02:00
parent 3dc6501246
commit 1db942f1a9
38 changed files with 292 additions and 329 deletions

View File

@ -106,7 +106,7 @@ concept AnyBuffer = std::derived_from<T, Buffer>;
template <typename T, typename TInto> template <typename T, typename TInto>
concept BufferInto = std::derived_from<T, Buffer> and std::derived_from<TInto, Buffer> and concept BufferInto = std::derived_from<T, Buffer> and std::derived_from<TInto, Buffer> and
(Cast<bool>(T::FLAGS & TInto::FLAGS) or std::same_as<Buffer, TInto>); (static_cast<bool>(T::FLAGS & TInto::FLAGS) or std::same_as<Buffer, TInto>);
template <typename T> template <typename T>
concept AnyBufferRef = Deref<T> and AnyBuffer<DerefType<T>>; concept AnyBufferRef = Deref<T> and AnyBuffer<DerefType<T>>;

View File

@ -44,42 +44,28 @@ constexpr auto White = "\u001b[37m";
constexpr auto Reset = "\u001b[0m"; constexpr auto Reset = "\u001b[0m";
} // namespace ansi_color } // namespace ansi_color
template <typename TType, typename TFrom>
constexpr auto
Cast(TFrom &&in)
{
return static_cast<TType>(std::forward<TFrom>(in));
}
template <typename TType, typename TFrom>
constexpr auto
Recast(TFrom &&in)
{
return reinterpret_cast<TType>(std::forward<TFrom>(in));
}
constexpr f32 constexpr f32
operator""_deg(long double degrees) operator""_deg(long double degrees)
{ {
return glm::radians<f32>(Cast<f32>(degrees)); return glm::radians<f32>(static_cast<f32>(degrees));
} }
constexpr f32 constexpr f32
operator""_deg(unsigned long long int degrees) operator""_deg(unsigned long long int degrees)
{ {
return glm::radians<f32>(Cast<f32>(degrees)); return glm::radians<f32>(static_cast<f32>(degrees));
} }
constexpr f32 constexpr f32
operator""_rad(long double rads) operator""_rad(long double rads)
{ {
return Cast<f32>(rads); return static_cast<f32>(rads);
} }
constexpr f32 constexpr f32
operator""_rad(unsigned long long int rads) operator""_rad(unsigned long long int rads)
{ {
return Cast<f32>(rads); return static_cast<f32>(rads);
} }
using glm::ivec2; using glm::ivec2;

View File

@ -60,7 +60,7 @@ Device::SetName(const T &object, cstr name) const
if (!m_ValidationEnabled || !name || !object) if (!m_ValidationEnabled || !name || !object)
return; return;
auto handle = Recast<u64>(Cast<typename T::NativeType>(object)); auto handle = reinterpret_cast<u64>(static_cast<typename T::NativeType>(object));
const vk::DebugUtilsObjectNameInfoEXT objectNameInfo = { const vk::DebugUtilsObjectNameInfoEXT objectNameInfo = {
.objectType = object.objectType, .objectType = object.objectType,
.objectHandle = handle, .objectHandle = handle,

View File

@ -59,7 +59,7 @@ constexpr u32 ASTER_API_VERSION = VK_API_VERSION_1_3;
do \ do \
{ \ { \
vk::Result _checkResultValue_; \ vk::Result _checkResultValue_; \
ERROR_IF(Failed(_checkResultValue_ = Cast<vk::Result>(RESULT)), "Cause: {}", _checkResultValue_) \ ERROR_IF(Failed(_checkResultValue_ = static_cast<vk::Result>(RESULT)), "Cause: {}", _checkResultValue_) \
THEN_ABORT(_checkResultValue_); \ THEN_ABORT(_checkResultValue_); \
} while (false) } while (false)
@ -67,14 +67,14 @@ constexpr u32 ASTER_API_VERSION = VK_API_VERSION_1_3;
do \ do \
{ \ { \
vk::Result _checkResultValue_; \ vk::Result _checkResultValue_; \
ERROR_IF(Failed(_checkResultValue_ = Cast<vk::Result>(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \ ERROR_IF(Failed(_checkResultValue_ = static_cast<vk::Result>(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \
THEN_ABORT(_checkResultValue_); \ THEN_ABORT(_checkResultValue_); \
} while (false) } while (false)
#define AbortIfFailedM(RESULT, MSG) \ #define AbortIfFailedM(RESULT, MSG) \
do \ do \
{ \ { \
auto _checkResultValue_ = Cast<vk::Result>(RESULT); \ auto _checkResultValue_ = static_cast<vk::Result>(RESULT); \
ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \ ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \
} while (false) } while (false)
@ -98,7 +98,7 @@ struct eastl::hash<vk::Flags<TFlagBits>> // NOLINT(*-dcl58-cpp)
[[nodiscard]] usize [[nodiscard]] usize
operator()(const vk::Flags<TFlagBits> &val) operator()(const vk::Flags<TFlagBits> &val)
{ {
return std::hash<u32>()(Cast<u32>(val)); return std::hash<u32>()(static_cast<u32>(val));
} }
}; };

View File

@ -25,13 +25,13 @@ ToExtent3D(const vk::Extent2D &extent, const u32 depth)
[[nodiscard]] inline vk::Offset2D [[nodiscard]] inline vk::Offset2D
ToOffset2D(const vk::Extent3D &extent) ToOffset2D(const vk::Extent3D &extent)
{ {
return {Cast<i32>(extent.width), Cast<i32>(extent.height)}; return {static_cast<i32>(extent.width), static_cast<i32>(extent.height)};
} }
[[nodiscard]] inline vk::Offset3D [[nodiscard]] inline vk::Offset3D
ToOffset3D(const vk::Extent3D &extent) ToOffset3D(const vk::Extent3D &extent)
{ {
return {Cast<i32>(extent.width), Cast<i32>(extent.height), Cast<i32>(extent.depth)}; return {static_cast<i32>(extent.width), static_cast<i32>(extent.height), static_cast<i32>(extent.depth)};
} }
struct Image struct Image
@ -121,7 +121,7 @@ concept AnyImage = std::derived_from<T, Image>;
template <typename T, typename TInto> template <typename T, typename TInto>
concept ImageInto = std::derived_from<T, Image> and std::derived_from<TInto, Image> and concept ImageInto = std::derived_from<T, Image> and std::derived_from<TInto, Image> and
(Cast<bool>(T::FLAGS & TInto::FLAGS) or std::same_as<Image, TInto>); (static_cast<bool>(T::FLAGS & TInto::FLAGS) or std::same_as<Image, TInto>);
template <typename T> template <typename T>
concept AnyImageRef = Deref<T> and AnyImage<DerefType<T>>; concept AnyImageRef = Deref<T> and AnyImage<DerefType<T>>;

View File

@ -30,7 +30,7 @@ struct View
[[nodiscard]] bool [[nodiscard]] bool
IsValid() const IsValid() const
{ {
return Cast<bool>(m_Image); return static_cast<bool>(m_Image);
} }
View(Ref<Image> image, const vk::ImageView view, const vk::Extent3D extent, const u8 baseLayer, const u8 layerCount, View(Ref<Image> image, const vk::ImageView view, const vk::Extent3D extent, const u8 baseLayer, const u8 layerCount,

View File

@ -63,7 +63,7 @@ class CommitManager
Entry * Entry *
Next() Next()
{ {
return Recast<Entry *>(this->mpNext); return reinterpret_cast<Entry *>(this->mpNext);
} }
void void
@ -174,7 +174,7 @@ class CommitManager
u32 u32
GetIndex(const Entry &entry) GetIndex(const Entry &entry)
{ {
return Cast<u32>(&entry - m_Data.begin()); return static_cast<u32>(&entry - m_Data.begin());
} }
void void

View File

@ -42,17 +42,17 @@ struct eastl::hash<vk::SamplerCreateInfo>
hash = HashCombine(hash, HashAny(createInfo.addressModeU)); hash = HashCombine(hash, HashAny(createInfo.addressModeU));
hash = HashCombine(hash, HashAny(createInfo.addressModeV)); hash = HashCombine(hash, HashAny(createInfo.addressModeV));
hash = HashCombine(hash, HashAny(createInfo.addressModeW)); hash = HashCombine(hash, HashAny(createInfo.addressModeW));
hash = HashCombine(hash, HashAny(Cast<usize>(createInfo.mipLodBias * 1000))); // Resolution of 10^-3 hash = HashCombine(hash, HashAny(static_cast<usize>(createInfo.mipLodBias * 1000))); // Resolution of 10^-3
hash = HashCombine(hash, HashAny(createInfo.anisotropyEnable)); hash = HashCombine(hash, HashAny(createInfo.anisotropyEnable));
hash = hash =
HashCombine(hash, HashCombine(hash,
HashAny(Cast<usize>(createInfo.maxAnisotropy * 0x20))); // 32:1 Anisotropy is enough resolution HashAny(static_cast<usize>(createInfo.maxAnisotropy * 0x20))); // 32:1 Anisotropy is enough resolution
hash = HashCombine(hash, HashAny(createInfo.compareEnable)); hash = HashCombine(hash, HashAny(createInfo.compareEnable));
hash = HashCombine(hash, HashAny(createInfo.compareOp)); hash = HashCombine(hash, HashAny(createInfo.compareOp));
hash = HashCombine(hash, HashAny(Cast<usize>(createInfo.minLod * 1000))); // 0.001 resolution is enough. hash = HashCombine(hash, HashAny(static_cast<usize>(createInfo.minLod * 1000))); // 0.001 resolution is enough.
hash = hash =
HashCombine(hash, HashCombine(hash,
HashAny(Cast<usize>(createInfo.maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp) HashAny(static_cast<usize>(createInfo.maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp)
hash = HashCombine(hash, HashAny(createInfo.borderColor)); hash = HashCombine(hash, HashAny(createInfo.borderColor));
hash = HashCombine(hash, HashAny(createInfo.unnormalizedCoordinates)); hash = HashCombine(hash, HashAny(createInfo.unnormalizedCoordinates));
@ -334,7 +334,7 @@ enum class ShaderType
constexpr static u32 ShaderTypeCount = 8; constexpr static u32 ShaderTypeCount = 8;
static_assert(Cast<u32>(ShaderType::eMax) == 1 + (1 << (ShaderTypeCount - 1))); static_assert(static_cast<u32>(ShaderType::eMax) == 1 + (1 << (ShaderTypeCount - 1)));
struct ShaderInfo struct ShaderInfo
{ {

View File

@ -61,7 +61,7 @@ struct FreeList
Pop() Pop()
{ {
assert(m_Top); assert(m_Top);
Reference ref = *Recast<Pointer>(m_Top); Reference ref = *reinterpret_cast<Pointer>(m_Top);
m_Top = m_Top->m_Next; m_Top = m_Top->m_Next;
return ref; return ref;
} }
@ -69,7 +69,7 @@ struct FreeList
void void
Push(Reference ref) Push(Reference ref)
{ {
auto next = Recast<FreeListNode *>(&ref); auto next = reinterpret_cast<FreeListNode *>(&ref);
next->m_Next = m_Top; next->m_Next = m_Top;
m_Top = next; m_Top = next;
} }

View File

@ -20,12 +20,12 @@ struct Logger
eVerbose, eVerbose,
}; };
u32 m_MinimumLoggingLevel{Cast<u32>(LogType::eDebug)}; u32 m_MinimumLoggingLevel{static_cast<u32>(LogType::eDebug)};
void void
SetMinimumLoggingLevel(LogType logType) SetMinimumLoggingLevel(LogType logType)
{ {
m_MinimumLoggingLevel = Cast<u32>(logType); m_MinimumLoggingLevel = static_cast<u32>(logType);
} }
template <LogType TLogLevel> template <LogType TLogLevel>
@ -64,7 +64,7 @@ struct Logger
void void
Log(const std::string_view &message, const char *loc, u32 line) const Log(const std::string_view &message, const char *loc, u32 line) const
{ {
if (Cast<u32>(TLogLevel) <= m_MinimumLoggingLevel) if (static_cast<u32>(TLogLevel) <= m_MinimumLoggingLevel)
{ {
fmt::println("{}{} {} {} at {}:{}{}", ToColorCstr<TLogLevel>(), ToCstr<TLogLevel>(), message.data(), fmt::println("{}{} {} {} at {}:{}{}", ToColorCstr<TLogLevel>(), ToCstr<TLogLevel>(), message.data(),
ansi_color::Black, loc, line, ansi_color::Reset); ansi_color::Black, loc, line, ansi_color::Reset);
@ -81,7 +81,7 @@ struct Logger
void void
LogCond(const char *exprStr, const std::string_view &message, const char *loc, u32 line) const LogCond(const char *exprStr, const std::string_view &message, const char *loc, u32 line) const
{ {
if (Cast<u32>(TLogLevel) <= m_MinimumLoggingLevel) if (static_cast<u32>(TLogLevel) <= m_MinimumLoggingLevel)
{ {
fmt::println("{}{} ({}) {} {} at {}:{}{}", ToColorCstr<TLogLevel>(), ToCstr<TLogLevel>(), exprStr, fmt::println("{}{} ({}) {} {} at {}:{}{}", ToColorCstr<TLogLevel>(), ToCstr<TLogLevel>(), exprStr,
message.data(), ansi_color::Black, loc, line, ansi_color::Reset); message.data(), ansi_color::Black, loc, line, ansi_color::Reset);
@ -103,26 +103,26 @@ extern Logger g_Logger;
#define INFO(...) g_Logger.Log<Logger::LogType::eInfo>(fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define INFO(...) g_Logger.Log<Logger::LogType::eInfo>(fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ERROR_IF(expr, ...) \ #define ERROR_IF(expr, ...) \
if (Cast<bool>(expr)) [[unlikely]] \ if (static_cast<bool>(expr)) [[unlikely]] \
g_Logger.LogCond<Logger::LogType::eError>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eError>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define WARN_IF(expr, ...) \ #define WARN_IF(expr, ...) \
if (Cast<bool>(expr)) [[unlikely]] \ if (static_cast<bool>(expr)) [[unlikely]] \
g_Logger.LogCond<Logger::LogType::eWarning>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eWarning>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define INFO_IF(expr, ...) \ #define INFO_IF(expr, ...) \
if (Cast<bool>(expr)) \ if (static_cast<bool>(expr)) \
g_Logger.LogCond<Logger::LogType::eInfo>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eInfo>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_IF_ERROR(expr, ...) \ #define ELSE_IF_ERROR(expr, ...) \
; \ ; \
else if (Cast<bool>(expr)) \ else if (static_cast<bool>(expr)) \
[[unlikely]] g_Logger.LogCond<Logger::LogType::eError>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) [[unlikely]] g_Logger.LogCond<Logger::LogType::eError>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_IF_WARN(expr, ...) \ #define ELSE_IF_WARN(expr, ...) \
; \ ; \
else if (Cast<bool>(expr)) \ else if (static_cast<bool>(expr)) \
[[unlikely]] g_Logger.LogCond<Logger::LogType::eWarning>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) [[unlikely]] g_Logger.LogCond<Logger::LogType::eWarning>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_IF_INFO(expr, ...) \ #define ELSE_IF_INFO(expr, ...) \
; \ ; \
else if (Cast<bool>(expr)) \ else if (static_cast<bool>(expr)) \
g_Logger.LogCond<Logger::LogType::eInfo>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eInfo>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_ERROR(...) \ #define ELSE_ERROR(...) \
@ -139,11 +139,11 @@ extern Logger g_Logger;
#define DEBUG(...) g_Logger.Log<Logger::LogType::eDebug>(fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define DEBUG(...) g_Logger.Log<Logger::LogType::eDebug>(fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define DEBUG_IF(expr, ...) \ #define DEBUG_IF(expr, ...) \
if (Cast<bool>(expr)) \ if (static_cast<bool>(expr)) \
g_Logger.LogCond<Logger::LogType::eDebug>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eDebug>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_IF_DEBUG(expr, ...) \ #define ELSE_IF_DEBUG(expr, ...) \
; \ ; \
else if (Cast<bool>(expr)) \ else if (static_cast<bool>(expr)) \
g_Logger.LogCond<Logger::LogType::eDebug>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eDebug>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_DEBUG(...) \ #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(...) g_Logger.Log<Logger::LogType::eVerbose>(fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define VERBOSE_IF(expr, ...) \ #define VERBOSE_IF(expr, ...) \
if (Cast<bool>(expr)) \ if (static_cast<bool>(expr)) \
g_Logger.LogCond<Logger::LogType::eVerbose>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eVerbose>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_IF_VERBOSE(expr, ...) \ #define ELSE_IF_VERBOSE(expr, ...) \
; \ ; \
else if (Cast<bool>(expr)) \ else if (static_cast<bool>(expr)) \
g_Logger.LogCond<Logger::LogType::eVerbose>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) g_Logger.LogCond<Logger::LogType::eVerbose>(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__)
#define ELSE_VERBOSE(...) \ #define ELSE_VERBOSE(...) \
; \ ; \
@ -207,5 +207,5 @@ extern Logger g_Logger;
#endif // !defined(VERBOSE_LOG_DISABLED) #endif // !defined(VERBOSE_LOG_DISABLED)
#define DO(code) , code #define DO(code) , code
#define ABORT(code) exit(Cast<i32>(code)) #define ABORT(code) exit(static_cast<i32>(code))
#define THEN_ABORT(code) , ABORT(code) #define THEN_ABORT(code) , ABORT(code)

View File

@ -27,7 +27,7 @@ Buffer::Buffer(const Device *device, const usize size, const vk::BufferUsageFlag
VkBuffer buffer; VkBuffer buffer;
VmaAllocation allocation; VmaAllocation allocation;
VmaAllocationInfo allocationInfo; VmaAllocationInfo allocationInfo;
auto result = Cast<vk::Result>(vmaCreateBuffer(device->m_Allocator, Recast<VkBufferCreateInfo *>(&bufferCreateInfo), auto result = static_cast<vk::Result>(vmaCreateBuffer(device->m_Allocator, reinterpret_cast<VkBufferCreateInfo *>(&bufferCreateInfo),
&allocationCreateInfo, &buffer, &allocation, &allocationInfo)); &allocationCreateInfo, &buffer, &allocation, &allocationInfo));
ERROR_IF(Failed(result), "Could not allocate buffer. Cause: {}", result) THEN_ABORT(result); ERROR_IF(Failed(result), "Could not allocate buffer. Cause: {}", result) THEN_ABORT(result);
@ -35,12 +35,12 @@ Buffer::Buffer(const Device *device, const usize size, const vk::BufferUsageFlag
// vmaGetAllocationMemoryProperties(device->m_Allocator, allocation, Recast<VkMemoryPropertyFlags // vmaGetAllocationMemoryProperties(device->m_Allocator, allocation, Recast<VkMemoryPropertyFlags
// *>(&memoryPropertyFlags)); // *>(&memoryPropertyFlags));
// TODO: Actually track Host Access // TODO: Actually track Host Access
// bool hostAccessible = Cast<bool>(memoryPropertyFlags & vk::MemoryPropertyFlagBits::eHostVisible); // bool hostAccessible = static_cast<bool>(memoryPropertyFlags & vk::MemoryPropertyFlagBits::eHostVisible);
m_Buffer = buffer; m_Buffer = buffer;
m_Size = size; m_Size = size;
m_Allocation = allocation; m_Allocation = allocation;
m_Mapped = Cast<u8 *>(allocationInfo.pMappedData); m_Mapped = static_cast<u8 *>(allocationInfo.pMappedData);
m_Flags = {}; m_Flags = {};
if (bufferUsage & vk::BufferUsageFlagBits::eTransferSrc) if (bufferUsage & vk::BufferUsageFlagBits::eTransferSrc)
m_Flags |= FlagBits::eStaging; m_Flags |= FlagBits::eStaging;
@ -104,6 +104,6 @@ Buffer::Write(const usize offset, const usize size, const void *data) const
memcpy(m_Mapped + offset, data, size); memcpy(m_Mapped + offset, data, size);
// TODO: Debug this. // TODO: Debug this.
// auto result = Cast<vk::Result>(vmaCopyMemoryToAllocation(device->m_Allocator, &data, m_Allocation, 0, size)); // auto result = static_cast<vk::Result>(vmaCopyMemoryToAllocation(device->m_Allocator, &data, m_Allocation, 0, size));
// ERROR_IF(Failed(result), "Writing to buffer failed. Cause: {}", result) THEN_ABORT(result); // ERROR_IF(Failed(result), "Writing to buffer failed. Cause: {}", result) THEN_ABORT(result);
} }

View File

@ -55,9 +55,9 @@ Device::Device(const Instance &context, PhysicalDevice &physicalDevice, Features
vk::DeviceCreateInfo deviceCreateInfo = { vk::DeviceCreateInfo deviceCreateInfo = {
.pNext = vulkan11Features, .pNext = vulkan11Features,
.queueCreateInfoCount = Cast<u32>(deviceQueueCreateInfos.size()), .queueCreateInfoCount = static_cast<u32>(deviceQueueCreateInfos.size()),
.pQueueCreateInfos = deviceQueueCreateInfos.data(), .pQueueCreateInfos = deviceQueueCreateInfos.data(),
.enabledExtensionCount = Cast<u32>(DEVICE_EXTENSIONS.size()), .enabledExtensionCount = static_cast<u32>(DEVICE_EXTENSIONS.size()),
.ppEnabledExtensionNames = DEVICE_EXTENSIONS.data(), .ppEnabledExtensionNames = DEVICE_EXTENSIONS.data(),
.pEnabledFeatures = deviceFeatures, .pEnabledFeatures = deviceFeatures,
}; };
@ -83,7 +83,7 @@ Device::Device(const Instance &context, PhysicalDevice &physicalDevice, Features
.vulkanApiVersion = ASTER_API_VERSION, .vulkanApiVersion = ASTER_API_VERSION,
}; };
result = Cast<vk::Result>(vmaCreateAllocator(&allocatorCreateInfo, &m_Allocator)); result = static_cast<vk::Result>(vmaCreateAllocator(&allocatorCreateInfo, &m_Allocator));
ERROR_IF(Failed(result), "Memory allocator creation failed. Cause: {}", result) ERROR_IF(Failed(result), "Memory allocator creation failed. Cause: {}", result)
DO(m_Device.destroy(nullptr)) DO(m_Device.destroy(nullptr))
THEN_ABORT(result) THEN_ABORT(result)

View File

@ -30,7 +30,7 @@ struct MemorySize
m_Kilobytes = totalKb % 1024; m_Kilobytes = totalKb % 1024;
const usize totalMb = m_Megabytes + totalKb / 1024; const usize totalMb = m_Megabytes + totalKb / 1024;
m_Megabytes = totalMb % 1024; m_Megabytes = totalMb % 1024;
m_Gigabytes += Cast<u16>(totalMb / 1024); m_Gigabytes += static_cast<u16>(totalMb / 1024);
return *this; return *this;
} }
@ -56,15 +56,15 @@ struct fmt::formatter<MemorySize>
// return format_to(ctx.out(), "({}, {})", foo.a, foo.b); // --== KEY LINE ==-- // return format_to(ctx.out(), "({}, {})", foo.a, foo.b); // --== KEY LINE ==--
if (mem.m_Gigabytes > 0) if (mem.m_Gigabytes > 0)
{ {
return v11::format_to(ctx.out(), "{}.{} GB", mem.m_Gigabytes, Cast<u16>(mem.m_Megabytes / 1024.0)); return v11::format_to(ctx.out(), "{}.{} GB", mem.m_Gigabytes, static_cast<u16>(mem.m_Megabytes / 1024.0));
} }
if (mem.m_Megabytes > 0) if (mem.m_Megabytes > 0)
{ {
return v11::format_to(ctx.out(), "{}.{} MB", mem.m_Megabytes, Cast<u16>(mem.m_Kilobytes / 1024.0)); return v11::format_to(ctx.out(), "{}.{} MB", mem.m_Megabytes, static_cast<u16>(mem.m_Kilobytes / 1024.0));
} }
if (mem.m_Kilobytes > 0) if (mem.m_Kilobytes > 0)
{ {
return v11::format_to(ctx.out(), "{}.{} KB", mem.m_Kilobytes, Cast<u16>(mem.m_Bytes / 1024.0)); return v11::format_to(ctx.out(), "{}.{} KB", mem.m_Kilobytes, static_cast<u16>(mem.m_Bytes / 1024.0));
} }
return v11::format_to(ctx.out(), "{} Bytes", mem.m_Bytes); return v11::format_to(ctx.out(), "{} Bytes", mem.m_Bytes);

View File

@ -48,7 +48,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// WARN_IF(!IsPowerOfTwo(extent.width) || !IsPowerOfTwo(extent.width), "Image {2} is {0}x{1} (Non Power of Two)", // WARN_IF(!IsPowerOfTwo(extent.width) || !IsPowerOfTwo(extent.width), "Image {2} is {0}x{1} (Non Power of Two)",
// extent.width, extent.height, name ? name : "<unnamed>"); // extent.width, extent.height, name ? name : "<unnamed>");
// //
// const u8 mipLevels = isMipMapped ? 1 + Cast<u8>(floor(log2(eastl::max(extent.width, extent.height)))) : 1; // const u8 mipLevels = isMipMapped ? 1 + static_cast<u8>(floor(log2(eastl::max(extent.width, extent.height)))) : 1;
// //
// auto usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst; // auto usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst;
// if (isMipMapped) // if (isMipMapped)
@ -75,7 +75,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// //
// VkImage image; // VkImage image;
// VmaAllocation allocation; // VmaAllocation allocation;
// auto result = Cast<vk::Result>(vmaCreateImage(device->m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), // auto result = static_cast<vk::Result>(vmaCreateImage(device->m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
// &allocationCreateInfo, &image, &allocation, nullptr)); // &allocationCreateInfo, &image, &allocation, nullptr));
// ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result); // ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result);
// //
@ -132,7 +132,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// WARN_IF(!IsPowerOfTwo(cubeSide), "Image Cube {1} has side {0}x{0} (Non Power of Two)", cubeSide, // WARN_IF(!IsPowerOfTwo(cubeSide), "Image Cube {1} has side {0}x{0} (Non Power of Two)", cubeSide,
// name ? name : "<unnamed>"); // name ? name : "<unnamed>");
// //
// const u8 mipLevels = isMipMapped ? 1 + Cast<u8>(floor(log2(cubeSide))) : 1; // const u8 mipLevels = isMipMapped ? 1 + static_cast<u8>(floor(log2(cubeSide))) : 1;
// //
// auto usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst; // auto usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst;
// if (isMipMapped) // if (isMipMapped)
@ -162,7 +162,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// //
// VkImage image; // VkImage image;
// VmaAllocation allocation; // VmaAllocation allocation;
// auto result = Cast<vk::Result>(vmaCreateImage(device->m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), // auto result = static_cast<vk::Result>(vmaCreateImage(device->m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
// &allocationCreateInfo, &image, &allocation, nullptr)); // &allocationCreateInfo, &image, &allocation, nullptr));
// ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result); // ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result);
// //
@ -217,7 +217,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// //
// VkImage image; // VkImage image;
// VmaAllocation allocation; // VmaAllocation allocation;
// auto result = Cast<vk::Result>(vmaCreateImage(device->m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), // auto result = static_cast<vk::Result>(vmaCreateImage(device->m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
// &allocationCreateInfo, &image, &allocation, nullptr)); // &allocationCreateInfo, &image, &allocation, nullptr));
// ERROR_IF(Failed(result), "Could not allocate depth buffer. Cause: {}", result) THEN_ABORT(result); // ERROR_IF(Failed(result), "Could not allocate depth buffer. Cause: {}", result) THEN_ABORT(result);
// //
@ -274,7 +274,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// //
// VkImage image; // VkImage image;
// VmaAllocation allocation; // VmaAllocation allocation;
// auto result = Cast<vk::Result>(vmaCreateImage(device->m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), // auto result = static_cast<vk::Result>(vmaCreateImage(device->m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
// &allocationCreateInfo, &image, &allocation, nullptr)); // &allocationCreateInfo, &image, &allocation, nullptr));
// ERROR_IF(Failed(result), "Could not allocate depth buffer. Cause: {}", result) THEN_ABORT(result); // ERROR_IF(Failed(result), "Could not allocate depth buffer. Cause: {}", result) THEN_ABORT(result);
// //
@ -344,7 +344,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// //
// VkImage image; // VkImage image;
// VmaAllocation allocation; // VmaAllocation allocation;
// auto result = Cast<vk::Result>(vmaCreateImage(device->m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), // auto result = static_cast<vk::Result>(vmaCreateImage(device->m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
// &allocationCreateInfo, &image, &allocation, nullptr)); // &allocationCreateInfo, &image, &allocation, nullptr));
// ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result); // ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result);
// //
@ -395,7 +395,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// usage |= vk::ImageUsageFlagBits::eSampled; // usage |= vk::ImageUsageFlagBits::eSampled;
// } // }
// //
// const u8 mipLevels = isMipMapped ? 1 + Cast<u8>(floor(log2(cubeSide))) : 1; // const u8 mipLevels = isMipMapped ? 1 + static_cast<u8>(floor(log2(cubeSide))) : 1;
// //
// vk::ImageCreateInfo imageCreateInfo = { // vk::ImageCreateInfo imageCreateInfo = {
// .flags = vk::ImageCreateFlagBits::eCubeCompatible, // .flags = vk::ImageCreateFlagBits::eCubeCompatible,
@ -417,7 +417,7 @@ Image::DestroyView(const vk::ImageView imageView) const
// //
// VkImage image; // VkImage image;
// VmaAllocation allocation; // VmaAllocation allocation;
// auto result = Cast<vk::Result>(vmaCreateImage(device->m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), // auto result = static_cast<vk::Result>(vmaCreateImage(device->m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
// &allocationCreateInfo, &image, &allocation, nullptr)); // &allocationCreateInfo, &image, &allocation, nullptr));
// ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result); // ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result);
// //

View File

@ -75,7 +75,7 @@ Instance::Instance(const cstr appName, const Version version, bool enableValidat
const auto instanceCreateInfo = vk::InstanceCreateInfo{ const auto instanceCreateInfo = vk::InstanceCreateInfo{
.pNext = enableValidation ? &debugUtilsMessengerCreateInfo : nullptr, .pNext = enableValidation ? &debugUtilsMessengerCreateInfo : nullptr,
.pApplicationInfo = &appInfo, .pApplicationInfo = &appInfo,
.enabledExtensionCount = Cast<u32>(instanceExtensions.size()), .enabledExtensionCount = static_cast<u32>(instanceExtensions.size()),
.ppEnabledExtensionNames = instanceExtensions.data(), .ppEnabledExtensionNames = instanceExtensions.data(),
}; };

View File

@ -12,8 +12,8 @@ Surface::Surface(Instance &context, const Window &window)
: m_Context(&context) : m_Context(&context)
{ {
VkSurfaceKHR surface; VkSurfaceKHR surface;
auto result = Cast<vk::Result>( auto result = static_cast<vk::Result>(
glfwCreateWindowSurface(Cast<VkInstance>(m_Context->m_Instance), window.m_Window, nullptr, &surface)); glfwCreateWindowSurface(static_cast<VkInstance>(m_Context->m_Instance), window.m_Window, nullptr, &surface));
ERROR_IF(Failed(result), "Failed to create Surface with {}", result) ERROR_IF(Failed(result), "Failed to create Surface with {}", result)
THEN_ABORT(result) THEN_ABORT(result)
ELSE_DEBUG("Surface {} Created", m_Name); ELSE_DEBUG("Surface {} Created", m_Name);

View File

@ -50,7 +50,7 @@ Window::SetWindowSize(const vk::Extent2D &extent) const noexcept
void void
Window::SetWindowSize(const u32 width, const u32 height) const noexcept Window::SetWindowSize(const u32 width, const u32 height) const noexcept
{ {
glfwSetWindowSize(m_Window, Cast<i32>(width), Cast<i32>(height)); glfwSetWindowSize(m_Window, static_cast<i32>(width), static_cast<i32>(height));
} }
Size2D Size2D
@ -59,7 +59,7 @@ Window::GetSize() const
int width; int width;
int height; int height;
glfwGetFramebufferSize(m_Window, &width, &height); glfwGetFramebufferSize(m_Window, &width, &height);
return {Cast<u32>(width), Cast<u32>(height)}; return {static_cast<u32>(width), static_cast<u32>(height)};
} }
Window::Window(const cstr title, Size2D extent, const b8 isFullScreen) Window::Window(const cstr title, Size2D extent, const b8 isFullScreen)
@ -77,7 +77,7 @@ Window::Window(const cstr title, Size2D extent, const b8 isFullScreen)
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_CENTER_CURSOR, GLFW_TRUE); glfwWindowHint(GLFW_CENTER_CURSOR, GLFW_TRUE);
m_Window = glfwCreateWindow(Cast<i32>(extent.m_Width), Cast<i32>(extent.m_Height), m_Name.c_str(), m_Window = glfwCreateWindow(static_cast<i32>(extent.m_Width), static_cast<i32>(extent.m_Height), m_Name.c_str(),
isFullScreen ? monitor : nullptr, nullptr); isFullScreen ? monitor : nullptr, nullptr);
ERROR_IF(m_Window == nullptr, "Window creation failed") ERROR_IF(m_Window == nullptr, "Window creation failed")
ELSE_DEBUG("Window '{}' created with resolution '{}x{}'", m_Name, extent.m_Width, extent.m_Height); ELSE_DEBUG("Window '{}' created with resolution '{}x{}'", m_Name, extent.m_Width, extent.m_Height);
@ -91,8 +91,8 @@ Window::Window(const cstr title, Size2D extent, const b8 isFullScreen)
if (isFullScreen == false) if (isFullScreen == false)
{ {
glfwSetWindowPos(m_Window, Cast<i32>(windowWidth - extent.m_Width) / 2, glfwSetWindowPos(m_Window, static_cast<i32>(windowWidth - extent.m_Width) / 2,
Cast<i32>(windowHeight - extent.m_Height) / 2); static_cast<i32>(windowHeight - extent.m_Height) / 2);
} }
glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);

View File

@ -9,29 +9,6 @@
#include "core/device.h" #include "core/device.h"
#include "core/image_view.h" #include "core/image_view.h"
#define AbortIfFailed(RESULT) \
do \
{ \
vk::Result _checkResultValue_; \
ERROR_IF(Failed(_checkResultValue_ = Cast<vk::Result>(RESULT)), "Cause: {}", _checkResultValue_) \
THEN_ABORT(_checkResultValue_); \
} while (false)
#define AbortIfFailedMV(RESULT, MSG, EXTRA) \
do \
{ \
vk::Result _checkResultValue_; \
ERROR_IF(Failed(_checkResultValue_ = Cast<vk::Result>(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \
THEN_ABORT(_checkResultValue_); \
} while (false)
#define AbortIfFailedM(RESULT, MSG) \
do \
{ \
auto _checkResultValue_ = Cast<vk::Result>(RESULT); \
ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \
} while (false)
using namespace systems; using namespace systems;
CommitManager *CommitManager::m_Instance = nullptr; CommitManager *CommitManager::m_Instance = nullptr;
@ -64,7 +41,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
const vk::DescriptorPoolCreateInfo poolCreateInfo = { const vk::DescriptorPoolCreateInfo poolCreateInfo = {
.flags = vk::DescriptorPoolCreateFlagBits::eUpdateAfterBind, .flags = vk::DescriptorPoolCreateFlagBits::eUpdateAfterBind,
.maxSets = 1, .maxSets = 1,
.poolSizeCount = Cast<u32>(poolSizes.size()), .poolSizeCount = static_cast<u32>(poolSizes.size()),
.pPoolSizes = poolSizes.data(), .pPoolSizes = poolSizes.data(),
}; };
AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool)); AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool));
@ -73,19 +50,19 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
vk::DescriptorSetLayoutBinding{ vk::DescriptorSetLayoutBinding{
.binding = BUFFER_BINDING_INDEX, .binding = BUFFER_BINDING_INDEX,
.descriptorType = vk::DescriptorType::eStorageBuffer, .descriptorType = vk::DescriptorType::eStorageBuffer,
.descriptorCount = Cast<u32>(maxBuffers), .descriptorCount = static_cast<u32>(maxBuffers),
.stageFlags = vk::ShaderStageFlagBits::eAll, .stageFlags = vk::ShaderStageFlagBits::eAll,
}, },
vk::DescriptorSetLayoutBinding{ vk::DescriptorSetLayoutBinding{
.binding = IMAGE_BINDING_INDEX, .binding = IMAGE_BINDING_INDEX,
.descriptorType = vk::DescriptorType::eCombinedImageSampler, .descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = Cast<u32>(maxImages), .descriptorCount = static_cast<u32>(maxImages),
.stageFlags = vk::ShaderStageFlagBits::eAll, .stageFlags = vk::ShaderStageFlagBits::eAll,
}, },
vk::DescriptorSetLayoutBinding{ vk::DescriptorSetLayoutBinding{
.binding = STORAGE_IMAGE_BINDING_INDEX, .binding = STORAGE_IMAGE_BINDING_INDEX,
.descriptorType = vk::DescriptorType::eStorageImage, .descriptorType = vk::DescriptorType::eStorageImage,
.descriptorCount = Cast<u32>(maxStorageImages), .descriptorCount = static_cast<u32>(maxStorageImages),
.stageFlags = vk::ShaderStageFlagBits::eAll, .stageFlags = vk::ShaderStageFlagBits::eAll,
}, },
}; };
@ -97,7 +74,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
layoutBindingFlags.fill(bindingFlags); layoutBindingFlags.fill(bindingFlags);
vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = { vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = {
.bindingCount = Cast<u32>(layoutBindingFlags.size()), .bindingCount = static_cast<u32>(layoutBindingFlags.size()),
.pBindingFlags = layoutBindingFlags.data(), .pBindingFlags = layoutBindingFlags.data(),
}; };
@ -105,7 +82,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {
.pNext = &bindingFlagsCreateInfo, .pNext = &bindingFlagsCreateInfo,
.flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool, .flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool,
.bindingCount = Cast<u32>(descriptorLayoutBindings.size()), .bindingCount = static_cast<u32>(descriptorLayoutBindings.size()),
.pBindings = descriptorLayoutBindings.data(), .pBindings = descriptorLayoutBindings.data(),
}; };
AbortIfFailed(device->m_Device.createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout)); AbortIfFailed(device->m_Device.createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout));
@ -250,7 +227,7 @@ CommitManager::Update()
// Descriptor Updates // Descriptor Updates
if (!m_Writes.empty()) if (!m_Writes.empty())
{ {
m_Device->m_Device.updateDescriptorSets(Cast<u32>(m_Writes.size()), m_Writes.data(), 0, nullptr); m_Device->m_Device.updateDescriptorSets(static_cast<u32>(m_Writes.size()), m_Writes.data(), 0, nullptr);
m_Writes.clear(); m_Writes.clear();
m_WriteInfos.clear(); m_WriteInfos.clear();

View File

@ -125,14 +125,14 @@ systems::Device::CreateTexture2D(const Texture2DCreateInfo &createInfo)
VkImage rawImage; VkImage rawImage;
VmaAllocation allocation; VmaAllocation allocation;
vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo);
auto result = Cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), auto result = static_cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
&allocationCreateInfo, &rawImage, &allocation, nullptr)); &allocationCreateInfo, &rawImage, &allocation, nullptr));
ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result);
vk::Image image = rawImage; vk::Image image = rawImage;
u8 layerCount = Cast<u8>(imageCreateInfo.arrayLayers); u8 layerCount = static_cast<u8>(imageCreateInfo.arrayLayers);
u8 mipLevels = Cast<u8>(imageCreateInfo.mipLevels); u8 mipLevels = static_cast<u8>(imageCreateInfo.mipLevels);
Image::Flags flags = {}; Image::Flags flags = {};
if (createInfo.m_IsSampled) if (createInfo.m_IsSampled)
flags |= Image::FlagBits::eSampled; flags |= Image::FlagBits::eSampled;
@ -156,14 +156,14 @@ systems::Device::CreateTextureCube(const TextureCubeCreateInfo &createInfo)
VkImage rawImage; VkImage rawImage;
VmaAllocation allocation; VmaAllocation allocation;
vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo);
auto result = Cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), auto result = static_cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
&allocationCreateInfo, &rawImage, &allocation, nullptr)); &allocationCreateInfo, &rawImage, &allocation, nullptr));
ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result);
vk::Image image = rawImage; vk::Image image = rawImage;
u8 layerCount = Cast<u8>(imageCreateInfo.arrayLayers); u8 layerCount = static_cast<u8>(imageCreateInfo.arrayLayers);
u8 mipLevels = Cast<u8>(imageCreateInfo.mipLevels); u8 mipLevels = static_cast<u8>(imageCreateInfo.mipLevels);
Image::Flags flags = Image::FlagBits::eCube; Image::Flags flags = Image::FlagBits::eCube;
if (createInfo.m_IsSampled) if (createInfo.m_IsSampled)
flags |= Image::FlagBits::eSampled; flags |= Image::FlagBits::eSampled;
@ -187,14 +187,14 @@ systems::Device::CreateAttachment(const AttachmentCreateInfo &createInfo)
VkImage rawImage; VkImage rawImage;
VmaAllocation allocation; VmaAllocation allocation;
vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo);
auto result = Cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), auto result = static_cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
&allocationCreateInfo, &rawImage, &allocation, nullptr)); &allocationCreateInfo, &rawImage, &allocation, nullptr));
ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result);
vk::Image image = rawImage; vk::Image image = rawImage;
u8 layerCount = Cast<u8>(imageCreateInfo.arrayLayers); u8 layerCount = static_cast<u8>(imageCreateInfo.arrayLayers);
u8 mipLevels = Cast<u8>(imageCreateInfo.mipLevels); u8 mipLevels = static_cast<u8>(imageCreateInfo.mipLevels);
m_Device.SetName(image, createInfo.m_Name); m_Device.SetName(image, createInfo.m_Name);
@ -213,14 +213,14 @@ systems::Device::CreateDepthStencilImage(const DepthStencilImageCreateInfo &crea
VkImage rawImage; VkImage rawImage;
VmaAllocation allocation; VmaAllocation allocation;
vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo);
auto result = Cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, Recast<VkImageCreateInfo *>(&imageCreateInfo), auto result = static_cast<vk::Result>(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast<VkImageCreateInfo *>(&imageCreateInfo),
&allocationCreateInfo, &rawImage, &allocation, nullptr)); &allocationCreateInfo, &rawImage, &allocation, nullptr));
ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result);
vk::Image image = rawImage; vk::Image image = rawImage;
u8 layerCount = Cast<u8>(imageCreateInfo.arrayLayers); u8 layerCount = static_cast<u8>(imageCreateInfo.arrayLayers);
u8 mipLevels = Cast<u8>(imageCreateInfo.mipLevels); u8 mipLevels = static_cast<u8>(imageCreateInfo.mipLevels);
m_Device.SetName(image, createInfo.m_Name); m_Device.SetName(image, createInfo.m_Name);
@ -236,7 +236,7 @@ ToImageCreateInfo(const systems::Texture2DCreateInfo &createInfo)
WARN_IF(!IsPowerOfTwo(extent.width) || !IsPowerOfTwo(extent.width), "Image {2} is {0}x{1} (Non Power of Two)", WARN_IF(!IsPowerOfTwo(extent.width) || !IsPowerOfTwo(extent.width), "Image {2} is {0}x{1} (Non Power of Two)",
extent.width, extent.height, name ? name : "<unnamed>"); extent.width, extent.height, name ? name : "<unnamed>");
const u8 mipLevels = isMipMapped ? 1 + Cast<u8>(floor(log2(eastl::max(extent.width, extent.height)))) : 1; const u8 mipLevels = isMipMapped ? 1 + static_cast<u8>(floor(log2(eastl::max(extent.width, extent.height)))) : 1;
auto usage = vk::ImageUsageFlags{}; auto usage = vk::ImageUsageFlags{};
if (isSampled) if (isSampled)
@ -263,7 +263,7 @@ ToImageCreateInfo(const systems::TextureCubeCreateInfo &createInfo)
WARN_IF(!IsPowerOfTwo(side), "ImageCube {1} is {0}x{0} (Non Power of Two)", side, name ? name : "<unnamed>"); WARN_IF(!IsPowerOfTwo(side), "ImageCube {1} is {0}x{0} (Non Power of Two)", side, name ? name : "<unnamed>");
const u8 mipLevels = isMipMapped ? 1 + Cast<u8>(floor(log2(side))) : 1; const u8 mipLevels = isMipMapped ? 1 + static_cast<u8>(floor(log2(side))) : 1;
auto usage = vk::ImageUsageFlags{}; auto usage = vk::ImageUsageFlags{};
if (isSampled) if (isSampled)
@ -336,7 +336,7 @@ systems::Device::CreateView(const ViewCreateInfo<Image> &createInfo)
THEN_ABORT(-1); THEN_ABORT(-1);
vk::ImageView view; vk::ImageView view;
const auto imageViewCreateInfo = Cast<vk::ImageViewCreateInfo>(createInfo); const auto imageViewCreateInfo = static_cast<vk::ImageViewCreateInfo>(createInfo);
auto result = m_Device.m_Device.createImageView(&imageViewCreateInfo, nullptr, &view); auto result = m_Device.m_Device.createImageView(&imageViewCreateInfo, nullptr, &view);
ERROR_IF(Failed(result), "Could not create image view {}. Cause: {}", createInfo.m_Name, result) ERROR_IF(Failed(result), "Could not create image view {}. Cause: {}", createInfo.m_Name, result)
THEN_ABORT(result); THEN_ABORT(result);
@ -406,7 +406,7 @@ systems::Device::CreateDepthStencilImageWithView(const DepthStencilImageCreateIn
Ref<Sampler> Ref<Sampler>
systems::Device::CreateSampler(const SamplerCreateInfo &createInfo) systems::Device::CreateSampler(const SamplerCreateInfo &createInfo)
{ {
auto vkCreateInfo = Cast<vk::SamplerCreateInfo>(createInfo); auto vkCreateInfo = static_cast<vk::SamplerCreateInfo>(createInfo);
if (const auto iter = m_HashToSamplerIdx.find(vkCreateInfo); if (const auto iter = m_HashToSamplerIdx.find(vkCreateInfo);
iter != m_HashToSamplerIdx.end() && !iter->second.expired()) iter != m_HashToSamplerIdx.end() && !iter->second.expired())
@ -460,9 +460,9 @@ systems::Device::CreatePipeline(Pipeline &pipelineOut, const GraphicsPipelineCre
} }
vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = { vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = {
.vertexBindingDescriptionCount = Cast<u32>(inputBindingDescriptions.size()), .vertexBindingDescriptionCount = static_cast<u32>(inputBindingDescriptions.size()),
.pVertexBindingDescriptions = inputBindingDescriptions.data(), .pVertexBindingDescriptions = inputBindingDescriptions.data(),
.vertexAttributeDescriptionCount = Cast<u32>(inputAttributeDescriptions.size()), .vertexAttributeDescriptionCount = static_cast<u32>(inputAttributeDescriptions.size()),
.pVertexAttributeDescriptions = inputAttributeDescriptions.data(), .pVertexAttributeDescriptions = inputAttributeDescriptions.data(),
}; };
vk::PipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = { vk::PipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = {
@ -515,7 +515,7 @@ systems::Device::CreatePipeline(Pipeline &pipelineOut, const GraphicsPipelineCre
}; };
vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = {
.dynamicStateCount = Cast<u32>(dynamicStates.size()), .dynamicStateCount = static_cast<u32>(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(), .pDynamicStates = dynamicStates.data(),
}; };
@ -527,7 +527,7 @@ systems::Device::CreatePipeline(Pipeline &pipelineOut, const GraphicsPipelineCre
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
.pNext = &renderingCreateInfo, .pNext = &renderingCreateInfo,
.stageCount = Cast<u32>(shaders.size()), .stageCount = static_cast<u32>(shaders.size()),
.pStages = shaders.data(), .pStages = shaders.data(),
.pVertexInputState = &vertexInputStateCreateInfo, .pVertexInputState = &vertexInputStateCreateInfo,
.pInputAssemblyState = &inputAssemblyStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo,
@ -636,7 +636,7 @@ systems::Device::CreateShaders(
shaderModule = m_SlangSession->loadModule(shaderInfo.m_ShaderFile.data(), shaderDiagnostics.writeRef()); shaderModule = m_SlangSession->loadModule(shaderInfo.m_ShaderFile.data(), shaderDiagnostics.writeRef());
if (shaderDiagnostics) if (shaderDiagnostics)
{ {
ERROR("{}", Cast<cstr>(shaderDiagnostics->getBufferPointer())); ERROR("{}", static_cast<cstr>(shaderDiagnostics->getBufferPointer()));
return SLANG_FAIL; return SLANG_FAIL;
} }
@ -650,7 +650,7 @@ systems::Device::CreateShaders(
slang::ProgramLayout *entryProgramLayout = actualEntryPoint->getLayout(0, shaderDiagnostics.writeRef()); slang::ProgramLayout *entryProgramLayout = actualEntryPoint->getLayout(0, shaderDiagnostics.writeRef());
if (shaderDiagnostics) if (shaderDiagnostics)
{ {
ERROR("{}", Cast<cstr>(shaderDiagnostics->getBufferPointer())); ERROR("{}", static_cast<cstr>(shaderDiagnostics->getBufferPointer()));
return SLANG_FAIL; return SLANG_FAIL;
} }
switch (entryProgramLayout->getEntryPointByIndex(0)->getStage()) switch (entryProgramLayout->getEntryPointByIndex(0)->getStage())
@ -709,7 +709,7 @@ systems::Device::CreateShaders(
} }
ComPtr<slang::IComponentType> pipelineComposite; ComPtr<slang::IComponentType> pipelineComposite;
auto slangResult = m_SlangSession->createCompositeComponentType(components.data(), Cast<u32>(components.size()), auto slangResult = m_SlangSession->createCompositeComponentType(components.data(), static_cast<u32>(components.size()),
pipelineComposite.writeRef()); pipelineComposite.writeRef());
if (slangResult < 0) if (slangResult < 0)
@ -721,7 +721,7 @@ systems::Device::CreateShaders(
if (slangResult < 0) if (slangResult < 0)
{ {
ERROR("{}", Cast<cstr>(shaderDiagnostics->getBufferPointer())); ERROR("{}", static_cast<cstr>(shaderDiagnostics->getBufferPointer()));
return slangResult; return slangResult;
} }
@ -734,7 +734,7 @@ systems::Device::CreateShaders(
slangResult = program->getEntryPointCode(entryPoint, 0, kernelCode.writeRef(), shaderDiagnostics.writeRef()); slangResult = program->getEntryPointCode(entryPoint, 0, kernelCode.writeRef(), shaderDiagnostics.writeRef());
if (slangResult < 0) if (slangResult < 0)
{ {
ERROR("{}", Cast<cstr>(shaderDiagnostics->getBufferPointer())); ERROR("{}", static_cast<cstr>(shaderDiagnostics->getBufferPointer()));
return slangResult; return slangResult;
} }
@ -749,7 +749,7 @@ systems::Device::CreateShaders(
const vk::ShaderModuleCreateInfo shaderModuleCreateInfo = { const vk::ShaderModuleCreateInfo shaderModuleCreateInfo = {
.codeSize = kernelCode->getBufferSize(), .codeSize = kernelCode->getBufferSize(),
.pCode = Cast<const u32 *>(kernelCode->getBufferPointer()), .pCode = static_cast<const u32 *>(kernelCode->getBufferPointer()),
}; };
result = m_Device.m_Device.createShaderModule(&shaderModuleCreateInfo, nullptr, &outShader.module); result = m_Device.m_Device.createShaderModule(&shaderModuleCreateInfo, nullptr, &outShader.module);
@ -785,7 +785,7 @@ systems::Device::CreatePipelineLayout(vk::PipelineLayout &pipelineLayout,
slang::ProgramLayout *layout = program->getLayout(0, layoutDiagnostics.writeRef()); slang::ProgramLayout *layout = program->getLayout(0, layoutDiagnostics.writeRef());
if (layoutDiagnostics) if (layoutDiagnostics)
{ {
ERROR_IF(!layout, "{}", Cast<cstr>(layoutDiagnostics->getBufferPointer())); ERROR_IF(!layout, "{}", static_cast<cstr>(layoutDiagnostics->getBufferPointer()));
return SLANG_FAIL; return SLANG_FAIL;
} }
@ -869,7 +869,7 @@ systems::Device::Device(const DeviceCreateInfo &createInfo)
.targets = &spirvTargetDesc, .targets = &spirvTargetDesc,
.targetCount = 1, .targetCount = 1,
.searchPaths = createInfo.m_ShaderSearchPaths.data(), .searchPaths = createInfo.m_ShaderSearchPaths.data(),
.searchPathCount = Cast<u32>(createInfo.m_ShaderSearchPaths.size()), .searchPathCount = static_cast<u32>(createInfo.m_ShaderSearchPaths.size()),
}; };
result = m_GlobalSlangSession->createSession(sessionDesc, m_SlangSession.writeRef()); result = m_GlobalSlangSession->createSession(sessionDesc, m_SlangSession.writeRef());
ERROR_IF(result < 0, "Could not create a slang session.") THEN_ABORT(result); ERROR_IF(result < 0, "Could not create a slang session.") THEN_ABORT(result);
@ -906,7 +906,7 @@ systems::Device::CreateFrame(u32 frameIndex)
vk::Semaphore finished; vk::Semaphore finished;
NameString name = "Frame "; NameString name = "Frame ";
name += Cast<char>(frameIndex + '0'); name += static_cast<char>(frameIndex + '0');
const vk::CommandPoolCreateInfo commandPoolCreateInfo = { const vk::CommandPoolCreateInfo commandPoolCreateInfo = {
.flags = vk::CommandPoolCreateFlagBits::eTransient, .flags = vk::CommandPoolCreateFlagBits::eTransient,

View File

@ -17,7 +17,7 @@ Frame::Frame(const Device *device, const u32 queueFamilyIndex, const u32 frameCo
m_Device = device; m_Device = device;
eastl::fixed_string<char, 50, false> name = "Frame "; eastl::fixed_string<char, 50, false> name = "Frame ";
name += Cast<char>('0' + frameCount); name += static_cast<char>('0' + frameCount);
const vk::CommandPoolCreateInfo commandPoolCreateInfo = { const vk::CommandPoolCreateInfo commandPoolCreateInfo = {
.flags = vk::CommandPoolCreateFlagBits::eTransient, .flags = vk::CommandPoolCreateFlagBits::eTransient,
.queueFamilyIndex = queueFamilyIndex, .queueFamilyIndex = queueFamilyIndex,

View File

@ -48,7 +48,7 @@ Init(const Instance *context, const Device *device, const Window *window, vk::Fo
const vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = { const vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = {
.flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, .flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
.maxSets = 1000, .maxSets = 1000,
.poolSizeCount = Cast<u32>(poolSizes.size()), .poolSizeCount = static_cast<u32>(poolSizes.size()),
.pPoolSizes = poolSizes.data(), .pPoolSizes = poolSizes.data(),
}; };

View File

@ -26,7 +26,7 @@ using StackString = eastl::fixed_string<char, TSize, false>;
do \ do \
{ \ { \
vk::Result _checkResultValue_; \ vk::Result _checkResultValue_; \
ERROR_IF(Failed(_checkResultValue_ = Cast<vk::Result>(RESULT)), "Cause: {}", _checkResultValue_) \ ERROR_IF(Failed(_checkResultValue_ = static_cast<vk::Result>(RESULT)), "Cause: {}", _checkResultValue_) \
THEN_ABORT(_checkResultValue_); \ THEN_ABORT(_checkResultValue_); \
} while (false) } while (false)
@ -34,13 +34,13 @@ using StackString = eastl::fixed_string<char, TSize, false>;
do \ do \
{ \ { \
vk::Result _checkResultValue_; \ vk::Result _checkResultValue_; \
ERROR_IF(Failed(_checkResultValue_ = Cast<vk::Result>(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \ ERROR_IF(Failed(_checkResultValue_ = static_cast<vk::Result>(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \
THEN_ABORT(_checkResultValue_); \ THEN_ABORT(_checkResultValue_); \
} while (false) } while (false)
#define AbortIfFailedM(RESULT, MSG) \ #define AbortIfFailedM(RESULT, MSG) \
do \ do \
{ \ { \
auto _checkResultValue_ = Cast<vk::Result>(RESULT); \ auto _checkResultValue_ = static_cast<vk::Result>(RESULT); \
ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \ ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \
} while (false) } while (false)

View File

@ -133,16 +133,16 @@ main(int, char **)
vk::Viewport viewport = { vk::Viewport viewport = {
.x = 0, .x = 0,
.y = Cast<f32>(swapchainSize.m_Height), .y = static_cast<f32>(swapchainSize.m_Height),
.width = Cast<f32>(swapchainSize.m_Width), .width = static_cast<f32>(swapchainSize.m_Width),
.height = -Cast<f32>(swapchainSize.m_Height), .height = -static_cast<f32>(swapchainSize.m_Height),
.minDepth = 0.0, .minDepth = 0.0,
.maxDepth = 1.0, .maxDepth = 1.0,
}; };
vk::Rect2D scissor = { vk::Rect2D scissor = {
.offset = {0, 0}, .offset = {0, 0},
.extent = Cast<vk::Extent2D>(swapchainSize), .extent = static_cast<vk::Extent2D>(swapchainSize),
}; };
auto context = currentFrame.CreateGraphicsContext(); auto context = currentFrame.CreateGraphicsContext();

View File

@ -66,7 +66,7 @@ ImageFile::Load(cstr fileName)
usize usize
ImageFile::GetSize() const ImageFile::GetSize() const
{ {
return Cast<usize>(m_Width) * m_Height * m_NumChannels; return static_cast<usize>(m_Width) * m_Height * m_NumChannels;
} }
ImageFile::~ImageFile() ImageFile::~ImageFile()
@ -141,7 +141,7 @@ main(int, char **)
.m_Model = {1.0f}, .m_Model = {1.0f},
.m_View = lookAt(vec3(0.0f, 2.0f, 2.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)), .m_View = lookAt(vec3(0.0f, 2.0f, 2.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)),
.m_Perspective = glm::perspective( .m_Perspective = glm::perspective(
70_deg, Cast<f32>(swapchain.m_Extent.width) / Cast<f32>(swapchain.m_Extent.height), 0.1f, 100.0f), 70_deg, static_cast<f32>(swapchain.m_Extent.width) / static_cast<f32>(swapchain.m_Extent.height), 0.1f, 100.0f),
}; };
vk::CommandPool copyPool; vk::CommandPool copyPool;
@ -325,9 +325,9 @@ main(int, char **)
// Persistent variables // Persistent variables
vk::Viewport viewport = { vk::Viewport viewport = {
.x = 0, .x = 0,
.y = Cast<f32>(swapchain.m_Extent.height), .y = static_cast<f32>(swapchain.m_Extent.height),
.width = Cast<f32>(swapchain.m_Extent.width), .width = static_cast<f32>(swapchain.m_Extent.width),
.height = -Cast<f32>(swapchain.m_Extent.height), .height = -static_cast<f32>(swapchain.m_Extent.height),
.minDepth = 0.0, .minDepth = 0.0,
.maxDepth = 1.0, .maxDepth = 1.0,
}; };
@ -338,9 +338,9 @@ main(int, char **)
}; };
auto resizeViewportScissor = [&viewport, &scissor](vk::Extent2D extent) { auto resizeViewportScissor = [&viewport, &scissor](vk::Extent2D extent) {
viewport.y = Cast<f32>(extent.height); viewport.y = static_cast<f32>(extent.height);
viewport.width = Cast<f32>(extent.width); viewport.width = static_cast<f32>(extent.width);
viewport.height = -Cast<f32>(extent.height); viewport.height = -static_cast<f32>(extent.height);
scissor.extent = extent; scissor.extent = extent;
}; };
swapchain.RegisterResizeCallback(resizeViewportScissor); swapchain.RegisterResizeCallback(resizeViewportScissor);
@ -425,7 +425,7 @@ main(int, char **)
Time::Update(); Time::Update();
commitManager.Update(); commitManager.Update();
camera.m_Model *= rotate(mat4{1.0f}, Cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f)); camera.m_Model *= rotate(mat4{1.0f}, static_cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f));
ubo->Write(0, sizeof camera, &camera); ubo->Write(0, sizeof camera, &camera);
Frame *currentFrame = frameManager.GetNextFrame(&swapchain, &surface, window.GetSize()); Frame *currentFrame = frameManager.GetNextFrame(&swapchain, &surface, window.GetSize());
@ -468,7 +468,7 @@ main(int, char **)
vk::RenderingInfo renderingInfo = { vk::RenderingInfo renderingInfo = {
.renderArea = {.extent = swapchain.m_Extent}, .renderArea = {.extent = swapchain.m_Extent},
.layerCount = 1, .layerCount = 1,
.colorAttachmentCount = Cast<u32>(attachmentInfos.size()), .colorAttachmentCount = static_cast<u32>(attachmentInfos.size()),
.pColorAttachments = attachmentInfos.data(), .pColorAttachments = attachmentInfos.data(),
.pDepthAttachment = &depthAttachment, .pDepthAttachment = &depthAttachment,
}; };
@ -481,7 +481,7 @@ main(int, char **)
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1, cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1,
&commitManager.GetDescriptorSet(), 0, nullptr); &commitManager.GetDescriptorSet(), 0, nullptr);
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAllGraphics, 0, 12, &pcb); cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAllGraphics, 0, 12, &pcb);
cmd.draw(Cast<u32>(vertices.size()), 1, 0, 0); cmd.draw(static_cast<u32>(vertices.size()), 1, 0, 0);
cmd.endRendering(); cmd.endRendering();
@ -600,7 +600,7 @@ CreatePipeline(const systems::CommitManager *resourceManager, const Swapchain *s
}; };
vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = {
.dynamicStateCount = Cast<u32>(dynamicStates.size()), .dynamicStateCount = static_cast<u32>(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(), .pDynamicStates = dynamicStates.data(),
}; };
@ -613,7 +613,7 @@ CreatePipeline(const systems::CommitManager *resourceManager, const Swapchain *s
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
.pNext = &renderingCreateInfo, .pNext = &renderingCreateInfo,
.stageCount = Cast<u32>(shaderStages.size()), .stageCount = static_cast<u32>(shaderStages.size()),
.pStages = shaderStages.data(), .pStages = shaderStages.data(),
.pVertexInputState = &vertexInputStateCreateInfo, .pVertexInputState = &vertexInputStateCreateInfo,
.pInputAssemblyState = &inputAssemblyStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo,

View File

@ -62,8 +62,8 @@ AssetLoader::LoadHdrImage(cstr path, cstr name) const
ERROR_IF(!data, "Could not load {}", path) THEN_ABORT(-1); ERROR_IF(!data, "Could not load {}", path) THEN_ABORT(-1);
u32 width = Cast<u32>(x); u32 width = static_cast<u32>(x);
u32 height = Cast<u32>(y); u32 height = static_cast<u32>(y);
auto texture = m_ResourceManager->CombinedImageViews().CreateTexture2D<TextureView>({ auto texture = m_ResourceManager->CombinedImageViews().CreateTexture2D<TextureView>({
.m_Format = vk::Format::eR32G32B32A32Sfloat, .m_Format = vk::Format::eR32G32B32A32Sfloat,
@ -248,7 +248,7 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, const Ref<Texture> &texture, vk
} }
vk::DependencyInfo imageStartDependency = { vk::DependencyInfo imageStartDependency = {
.imageMemoryBarrierCount = Cast<u32>(startBarriers.size()), .imageMemoryBarrierCount = static_cast<u32>(startBarriers.size()),
.pImageMemoryBarriers = startBarriers.data(), .pImageMemoryBarriers = startBarriers.data(),
}; };
@ -331,8 +331,8 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, const Ref<Texture> &texture, vk
commandBuffer.pipelineBarrier2(&imageStartDependency); commandBuffer.pipelineBarrier2(&imageStartDependency);
i32 prevMipWidth = Cast<i32>(texture->m_Extent.width); i32 prevMipWidth = static_cast<i32>(texture->m_Extent.width);
i32 prevMipHeight = Cast<i32>(texture->m_Extent.height); i32 prevMipHeight = static_cast<i32>(texture->m_Extent.height);
u32 maxPrevMip = texture->GetMipLevels() - 1; u32 maxPrevMip = texture->GetMipLevels() - 1;
for (u32 prevMipLevel = 0; prevMipLevel < maxPrevMip; ++prevMipLevel) for (u32 prevMipLevel = 0; prevMipLevel < maxPrevMip; ++prevMipLevel)
@ -382,8 +382,8 @@ AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name) cons
#endif #endif
u32 height = Cast<u32>(image->height); u32 height = static_cast<u32>(image->height);
u32 width = Cast<u32>(image->width); u32 width = static_cast<u32>(image->width);
vk::Format imageFormat = isSrgb ? vk::Format::eR8G8B8A8Srgb : vk::Format::eR8G8B8A8Unorm; vk::Format imageFormat = isSrgb ? vk::Format::eR8G8B8A8Srgb : vk::Format::eR8G8B8A8Unorm;
@ -465,8 +465,8 @@ AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name) cons
vk::BufferImageCopy2 imageCopy = { vk::BufferImageCopy2 imageCopy = {
.bufferOffset = 0, .bufferOffset = 0,
.bufferRowLength = Cast<u32>(image->width), .bufferRowLength = static_cast<u32>(image->width),
.bufferImageHeight = Cast<u32>(image->height), .bufferImageHeight = static_cast<u32>(image->height),
.imageSubresource = .imageSubresource =
{ {
.aspectMask = vk::ImageAspectFlagBits::eColor, .aspectMask = vk::ImageAspectFlagBits::eColor,
@ -583,8 +583,8 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
materials.push_back({ materials.push_back({
.m_AlbedoFactor = VectorToVec4(material.pbrMetallicRoughness.baseColorFactor), .m_AlbedoFactor = VectorToVec4(material.pbrMetallicRoughness.baseColorFactor),
.m_EmissionFactor = VectorToVec3(material.emissiveFactor), .m_EmissionFactor = VectorToVec3(material.emissiveFactor),
.m_MetalFactor = Cast<f32>(material.pbrMetallicRoughness.metallicFactor), .m_MetalFactor = static_cast<f32>(material.pbrMetallicRoughness.metallicFactor),
.m_RoughFactor = Cast<f32>(material.pbrMetallicRoughness.roughnessFactor), .m_RoughFactor = static_cast<f32>(material.pbrMetallicRoughness.roughnessFactor),
.m_AlbedoTex = getTextureHandle(material.pbrMetallicRoughness.baseColorTexture.index, true), .m_AlbedoTex = getTextureHandle(material.pbrMetallicRoughness.baseColorTexture.index, true),
.m_NormalTex = getTextureHandle(material.normalTexture.index, false), .m_NormalTex = getTextureHandle(material.normalTexture.index, false),
.m_MetalRoughTex = .m_MetalRoughTex =
@ -643,17 +643,17 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
tinygltf::Buffer *posBuffer = &model.buffers[posBufferView->buffer]; tinygltf::Buffer *posBuffer = &model.buffers[posBufferView->buffer];
usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset); usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset);
vertexCount = Cast<u32>(posAccessor->count); vertexCount = static_cast<u32>(posAccessor->count);
vertexPositions.reserve(vertexOffset + vertexCount); vertexPositions.reserve(vertexOffset + vertexCount);
if (posAccessor->type == TINYGLTF_TYPE_VEC4) if (posAccessor->type == TINYGLTF_TYPE_VEC4)
{ {
auto data = Recast<vec4 *>(posBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec4 *>(posBuffer->data.data() + byteOffset);
vertexPositions.insert(vertexPositions.end(), data, data + vertexCount); vertexPositions.insert(vertexPositions.end(), data, data + vertexCount);
} }
else if (posAccessor->type == TINYGLTF_TYPE_VEC3) else if (posAccessor->type == TINYGLTF_TYPE_VEC3)
{ {
auto data = Recast<vec3 *>(posBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec3 *>(posBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
vertexPositions.push_back(vec4(data[i], 1.0f)); vertexPositions.push_back(vec4(data[i], 1.0f));
@ -661,7 +661,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
} }
else if (posAccessor->type == TINYGLTF_TYPE_VEC2) else if (posAccessor->type == TINYGLTF_TYPE_VEC2)
{ {
auto data = Recast<vec2 *>(posBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec2 *>(posBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
vertexPositions.push_back(vec4(data[i], 0.0f, 1.0f)); vertexPositions.push_back(vec4(data[i], 0.0f, 1.0f));
@ -685,7 +685,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
if (normAccessor->type == TINYGLTF_TYPE_VEC4) if (normAccessor->type == TINYGLTF_TYPE_VEC4)
{ {
auto data = Recast<vec4 *>(normBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec4 *>(normBuffer->data.data() + byteOffset);
vec4 *end = data + vertexCount; vec4 *end = data + vertexCount;
u32 idx = vertexOffset; u32 idx = vertexOffset;
@ -697,7 +697,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
} }
else if (normAccessor->type == TINYGLTF_TYPE_VEC3) else if (normAccessor->type == TINYGLTF_TYPE_VEC3)
{ {
auto data = Recast<vec3 *>(normBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec3 *>(normBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
auto norm = vec4(data[i], 0.0f); auto norm = vec4(data[i], 0.0f);
@ -706,7 +706,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
} }
else if (normAccessor->type == TINYGLTF_TYPE_VEC2) else if (normAccessor->type == TINYGLTF_TYPE_VEC2)
{ {
auto data = Recast<vec2 *>(normBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec2 *>(normBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
auto norm = vec4(data[i], 0.0f, 0.0f); auto norm = vec4(data[i], 0.0f, 0.0f);
@ -729,7 +729,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
assert(uvAccessor->type == TINYGLTF_TYPE_VEC2 && assert(uvAccessor->type == TINYGLTF_TYPE_VEC2 &&
uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT);
{ {
auto data = Recast<vec2 *>(uvBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec2 *>(uvBuffer->data.data() + byteOffset);
vec2 *end = data + vertexCount; vec2 *end = data + vertexCount;
u32 idx = vertexOffset; u32 idx = vertexOffset;
vec2 *it = data; vec2 *it = data;
@ -752,7 +752,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
if (colorAccessor->type == TINYGLTF_TYPE_VEC4) if (colorAccessor->type == TINYGLTF_TYPE_VEC4)
{ {
auto data = Recast<vec4 *>(colorBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec4 *>(colorBuffer->data.data() + byteOffset);
vec4 *end = data + vertexCount; vec4 *end = data + vertexCount;
u32 idx = vertexOffset; u32 idx = vertexOffset;
@ -764,7 +764,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
} }
else if (colorAccessor->type == TINYGLTF_TYPE_VEC3) else if (colorAccessor->type == TINYGLTF_TYPE_VEC3)
{ {
auto data = Recast<vec3 *>(colorBuffer->data.data() + byteOffset); auto data = reinterpret_cast<vec3 *>(colorBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
auto color = vec4(data[i], 1.0f); auto color = vec4(data[i], 1.0f);
@ -785,22 +785,22 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
tinygltf::Buffer *indexBuffer = &model.buffers[indexBufferView->buffer]; tinygltf::Buffer *indexBuffer = &model.buffers[indexBufferView->buffer];
usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset); usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset);
indexCount = Cast<u32>(indexAccessor->count); indexCount = static_cast<u32>(indexAccessor->count);
indices.reserve(indexOffset + indexCount); indices.reserve(indexOffset + indexCount);
if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT) if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT)
{ {
auto data = Recast<u32 *>(indexBuffer->data.data() + byteOffset); auto data = reinterpret_cast<u32 *>(indexBuffer->data.data() + byteOffset);
indices.insert(indices.end(), data, data + indexCount); indices.insert(indices.end(), data, data + indexCount);
} }
else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT)
{ {
auto data = Recast<u16 *>(indexBuffer->data.data() + byteOffset); auto data = reinterpret_cast<u16 *>(indexBuffer->data.data() + byteOffset);
indices.insert(indices.end(), data, data + indexCount); indices.insert(indices.end(), data, data + indexCount);
} }
else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE) else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE)
{ {
auto data = Recast<u8 *>(indexBuffer->data.data() + byteOffset); auto data = reinterpret_cast<u8 *>(indexBuffer->data.data() + byteOffset);
indices.insert(indices.end(), data, data + indexCount); indices.insert(indices.end(), data, data + indexCount);
} }
} }
@ -861,7 +861,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
const mat4 transform = translate(mat4(1.0f), nodeTranslation) * mat4_cast(nodeRotation) * const mat4 transform = translate(mat4(1.0f), nodeTranslation) * mat4_cast(nodeRotation) *
scale(mat4(1.0f), nodeScale) * nodeMatrix; scale(mat4(1.0f), nodeScale) * nodeMatrix;
const i32 nodeArrayIndex = Cast<i32>(nodes.Add(transform, parent)); const i32 nodeArrayIndex = static_cast<i32>(nodes.Add(transform, parent));
if (node->mesh >= 0) if (node->mesh >= 0)
{ {
auto [start, count] = meshPrimRanges[node->mesh]; auto [start, count] = meshPrimRanges[node->mesh];

View File

@ -132,7 +132,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32
readyToWriteBarriers[3].subresourceRange = lutSubresRange; readyToWriteBarriers[3].subresourceRange = lutSubresRange;
vk::DependencyInfo readyToWriteDependency = { vk::DependencyInfo readyToWriteDependency = {
.imageMemoryBarrierCount = Cast<u32>(readyToWriteBarriers.size()), .imageMemoryBarrierCount = static_cast<u32>(readyToWriteBarriers.size()),
.pImageMemoryBarriers = readyToWriteBarriers.data(), .pImageMemoryBarriers = readyToWriteBarriers.data(),
}; };
@ -209,7 +209,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32
.stageFlags = vk::ShaderStageFlagBits::eCompute, .stageFlags = vk::ShaderStageFlagBits::eCompute,
.offset = 0, .offset = 0,
.size = .size =
Cast<u32>(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)), static_cast<u32>(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)),
eastl::max(sizeof(DiffuseIrradiancePushConstants), sizeof(PrefilterPushConstants)))), eastl::max(sizeof(DiffuseIrradiancePushConstants), sizeof(PrefilterPushConstants)))),
}; };
@ -267,7 +267,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32
eastl::array<vk::Pipeline, computePipelineCreateInfo.size()> pipelines; eastl::array<vk::Pipeline, computePipelineCreateInfo.size()> pipelines;
AbortIfFailed( AbortIfFailed(
pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, Cast<u32>(computePipelineCreateInfo.size()), pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, static_cast<u32>(computePipelineCreateInfo.size()),
computePipelineCreateInfo.data(), nullptr, pipelines.data())); computePipelineCreateInfo.data(), nullptr, pipelines.data()));
vk::Pipeline eqRectToCubePipeline = pipelines[0]; vk::Pipeline eqRectToCubePipeline = pipelines[0];
@ -345,7 +345,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32
{ {
prefilterPushConstants.m_OutputTexture = tex; prefilterPushConstants.m_OutputTexture = tex;
prefilterPushConstants.m_CubeSide = mipSize; prefilterPushConstants.m_CubeSide = mipSize;
prefilterPushConstants.m_Roughness = Cast<f32>(mipCount) / Cast<f32>(prefilterMipCountMax - 1); prefilterPushConstants.m_Roughness = static_cast<f32>(mipCount) / static_cast<f32>(prefilterMipCountMax - 1);
cmd.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eCompute, 0, sizeof prefilterPushConstants, cmd.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eCompute, 0, sizeof prefilterPushConstants,
&prefilterPushConstants); &prefilterPushConstants);
u32 groupCount = eastl::max(mipSize / 16u, 1u); u32 groupCount = eastl::max(mipSize / 16u, 1u);

View File

@ -36,10 +36,10 @@ static_assert(Light::COLOR_MASK == 0xFFFFFF00);
inline u32 inline u32
ToColor32(const vec4 &col) ToColor32(const vec4 &col)
{ {
const u32 r = Cast<u32>(eastl::min(col.r, 1.0f) * 255.99f); const u32 r = static_cast<u32>(eastl::min(col.r, 1.0f) * 255.99f);
const u32 g = Cast<u32>(eastl::min(col.g, 1.0f) * 255.99f); const u32 g = static_cast<u32>(eastl::min(col.g, 1.0f) * 255.99f);
const u32 b = Cast<u32>(eastl::min(col.b, 1.0f) * 255.99f); const u32 b = static_cast<u32>(eastl::min(col.b, 1.0f) * 255.99f);
const u32 a = Cast<u32>(eastl::min(col.a, 1.0f) * 255.99f); const u32 a = static_cast<u32>(eastl::min(col.a, 1.0f) * 255.99f);
return r << 24 | g << 16 | b << 8 | a; return r << 24 | g << 16 | b << 8 | a;
} }
@ -47,9 +47,9 @@ ToColor32(const vec4 &col)
inline u32 inline u32
ToColor32(const vec3 &col) ToColor32(const vec3 &col)
{ {
const u32 r = Cast<u32>(eastl::min(col.r, 1.0f) * 255.99f); const u32 r = static_cast<u32>(eastl::min(col.r, 1.0f) * 255.99f);
const u32 g = Cast<u32>(eastl::min(col.g, 1.0f) * 255.99f); const u32 g = static_cast<u32>(eastl::min(col.g, 1.0f) * 255.99f);
const u32 b = Cast<u32>(eastl::min(col.b, 1.0f) * 255.99f); const u32 b = static_cast<u32>(eastl::min(col.b, 1.0f) * 255.99f);
constexpr u32 a = 255; constexpr u32 a = 255;
return r << 24 | g << 16 | b << 8 | a; return r << 24 | g << 16 | b << 8 | a;
@ -177,7 +177,7 @@ LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius
m_GpuBufferCapacity_ |= UPDATE_REQUIRED_BIT; m_GpuBufferCapacity_ |= UPDATE_REQUIRED_BIT;
return {Light::TYPE_POINT, gen, Cast<u16>(index)}; return {Light::TYPE_POINT, gen, static_cast<u16>(index)};
} }
++light; ++light;
} }
@ -207,7 +207,7 @@ LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius
void void
LightManager::Update() LightManager::Update()
{ {
const u16 requiredBufferCapacity = eastl::min(Cast<u16>(m_Lights.capacity()), MAX_LIGHTS); const u16 requiredBufferCapacity = eastl::min(static_cast<u16>(m_Lights.capacity()), MAX_LIGHTS);
if ((m_GpuBufferCapacity_ & CAPACITY_MASK) < requiredBufferCapacity) if ((m_GpuBufferCapacity_ & CAPACITY_MASK) < requiredBufferCapacity)
{ {
auto newBuffer = m_ResourceManager->Buffers().CreateStorageBuffer(requiredBufferCapacity * sizeof m_Lights[0], auto newBuffer = m_ResourceManager->Buffers().CreateStorageBuffer(requiredBufferCapacity * sizeof m_Lights[0],

View File

@ -98,7 +98,7 @@ struct LightManager
// Using lower bit. Capacity can be directly a multiple of 2 // Using lower bit. Capacity can be directly a multiple of 2
// Thus, range is up to MaxValue<u16> // Thus, range is up to MaxValue<u16>
constexpr static u16 UPDATE_REQUIRED_BIT = 1; constexpr static u16 UPDATE_REQUIRED_BIT = 1;
constexpr static u16 CAPACITY_MASK = Cast<u16>(~UPDATE_REQUIRED_BIT); constexpr static u16 CAPACITY_MASK = static_cast<u16>(~UPDATE_REQUIRED_BIT);
LightHandle AddDirectional(const vec3 &direction, const vec3 &color, f32 intensity); LightHandle AddDirectional(const vec3 &direction, const vec3 &color, f32 intensity);
LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius, f32 intensity); LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius, f32 intensity);

View File

@ -216,7 +216,7 @@ main(int, char **)
}, },
}; };
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = { vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = {
.maxSets = 1, .poolSizeCount = Cast<u32>(poolSizes.size()), .pPoolSizes = poolSizes.data()}; .maxSets = 1, .poolSizeCount = static_cast<u32>(poolSizes.size()), .pPoolSizes = poolSizes.data()};
AbortIfFailed(device.m_Device.createDescriptorPool(&descriptorPoolCreateInfo, nullptr, &descriptorPool)); AbortIfFailed(device.m_Device.createDescriptorPool(&descriptorPoolCreateInfo, nullptr, &descriptorPool));
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo = { vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo = {
@ -230,7 +230,7 @@ main(int, char **)
vk::Extent2D internalResolution = {1920, 1080}; vk::Extent2D internalResolution = {1920, 1080};
CameraController cameraController = {vec3{0.0f, 0.0f, 2.0f}, vec3{0.0f}, 70_deg, CameraController cameraController = {vec3{0.0f, 0.0f, 2.0f}, vec3{0.0f}, 70_deg,
Cast<f32>(swapchain.m_Extent.width) / Cast<f32>(swapchain.m_Extent.height)}; static_cast<f32>(swapchain.m_Extent.width) / static_cast<f32>(swapchain.m_Extent.height)};
usize uboSize = 0; usize uboSize = 0;
usize cameraSize = sizeof cameraController.m_Camera; usize cameraSize = sizeof cameraController.m_Camera;
@ -277,16 +277,16 @@ main(int, char **)
.pBufferInfo = &lightingBufferInfo, .pBufferInfo = &lightingBufferInfo,
}, },
}; };
device.m_Device.updateDescriptorSets(Cast<u32>(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr); device.m_Device.updateDescriptorSets(static_cast<u32>(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr);
commitManager.Update(); commitManager.Update();
// Persistent variables // Persistent variables
vk::Viewport viewport = { vk::Viewport viewport = {
.x = 0, .x = 0,
.y = Cast<f32>(internalResolution.height), .y = static_cast<f32>(internalResolution.height),
.width = Cast<f32>(internalResolution.width), .width = static_cast<f32>(internalResolution.width),
.height = -Cast<f32>(internalResolution.height), .height = -static_cast<f32>(internalResolution.height),
.minDepth = 0.0, .minDepth = 0.0,
.maxDepth = 1.0, .maxDepth = 1.0,
}; };
@ -347,7 +347,7 @@ main(int, char **)
acquireToTransferDstBarrier, acquireToTransferDstBarrier,
}; };
vk::DependencyInfo postRenderDependencies = { vk::DependencyInfo postRenderDependencies = {
.imageMemoryBarrierCount = Cast<u32>(postRenderBarriers.size()), .imageMemoryBarrierCount = static_cast<u32>(postRenderBarriers.size()),
.pImageMemoryBarriers = postRenderBarriers.data(), .pImageMemoryBarriers = postRenderBarriers.data(),
}; };
@ -403,7 +403,7 @@ main(int, char **)
})); }));
} }
gui::Init(&context, &device, &window, swapchain.m_Format, Cast<u32>(swapchain.m_ImageViews.size()), gui::Init(&context, &device, &window, swapchain.m_Format, static_cast<u32>(swapchain.m_ImageViews.size()),
queueAllocation.m_Family, graphicsQueue); queueAllocation.m_Family, graphicsQueue);
bool rotating = false; bool rotating = false;
bool lockToScreen = true; bool lockToScreen = true;
@ -417,14 +417,14 @@ main(int, char **)
constexpr static u32 SHOW_DIFFUSE_BIT = 1 << 2; constexpr static u32 SHOW_DIFFUSE_BIT = 1 << 2;
constexpr static u32 SHOW_PREFILTER_BIT = 1 << 3; constexpr static u32 SHOW_PREFILTER_BIT = 1 << 3;
i32 height = Cast<i32>(internalResolution.height); i32 height = static_cast<i32>(internalResolution.height);
f32 camPitch = glm::degrees(cameraController.m_Pitch); f32 camPitch = glm::degrees(cameraController.m_Pitch);
f32 camYaw = glm::degrees(cameraController.m_Yaw); f32 camYaw = glm::degrees(cameraController.m_Yaw);
vec3 camPosition = cameraController.m_Camera.m_Position; vec3 camPosition = cameraController.m_Camera.m_Position;
vk::Extent2D inputResolution = internalResolution; vk::Extent2D inputResolution = internalResolution;
swapchain.RegisterResizeCallback([&cameraController](vk::Extent2D extent) { swapchain.RegisterResizeCallback([&cameraController](vk::Extent2D extent) {
cameraController.SetAspectRatio(Cast<f32>(extent.width) / Cast<f32>(extent.height)); cameraController.SetAspectRatio(static_cast<f32>(extent.width) / static_cast<f32>(extent.height));
}); });
Time::Init(); Time::Init();
@ -449,7 +449,7 @@ main(int, char **)
} }
inputResolution.height = height; inputResolution.height = height;
inputResolution.width = Cast<i32>(cameraController.m_AspectRatio * Cast<f32>(inputResolution.height)); inputResolution.width = static_cast<i32>(cameraController.m_AspectRatio * static_cast<f32>(inputResolution.height));
if (gui::Button("Change Resolution")) if (gui::Button("Change Resolution"))
{ {
@ -457,9 +457,9 @@ main(int, char **)
inputResolution.height != internalResolution.height) inputResolution.height != internalResolution.height)
{ {
internalResolution = inputResolution; internalResolution = inputResolution;
viewport.width = Cast<f32>(internalResolution.width); viewport.width = static_cast<f32>(internalResolution.width);
viewport.height = -Cast<f32>(internalResolution.height); viewport.height = -static_cast<f32>(internalResolution.height);
viewport.y = Cast<f32>(internalResolution.height); viewport.y = static_cast<f32>(internalResolution.height);
scissor.extent = internalResolution; scissor.extent = internalResolution;
} }
} }
@ -470,9 +470,9 @@ main(int, char **)
swapchain.m_Extent.height != internalResolution.height) swapchain.m_Extent.height != internalResolution.height)
{ {
internalResolution = swapchain.m_Extent; internalResolution = swapchain.m_Extent;
viewport.width = Cast<f32>(internalResolution.width); viewport.width = static_cast<f32>(internalResolution.width);
viewport.height = -Cast<f32>(internalResolution.height); viewport.height = -static_cast<f32>(internalResolution.height);
viewport.y = Cast<f32>(internalResolution.height); viewport.y = static_cast<f32>(internalResolution.height);
scissor.extent = internalResolution; scissor.extent = internalResolution;
} }
} }
@ -488,7 +488,7 @@ main(int, char **)
camYaw = camYaw - floor((camYaw + 180.0f) / 360.0f) * 360.0f; camYaw = camYaw - floor((camYaw + 180.0f) / 360.0f) * 360.0f;
cameraController.SetPitchYaw(glm::radians(camPitch), glm::radians(camYaw)); cameraController.SetPitchYaw(glm::radians(camPitch), glm::radians(camYaw));
} }
if (gui::InputFloat3("Camera Position", Recast<f32 *>(&camPosition))) if (gui::InputFloat3("Camera Position", reinterpret_cast<f32 *>(&camPosition)))
{ {
cameraController.SetPosition(camPosition); cameraController.SetPosition(camPosition);
} }
@ -512,7 +512,7 @@ main(int, char **)
if (rotating) if (rotating)
{ {
model.SetModelTransform( model.SetModelTransform(
rotate(model.GetModelTransform(), Cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f))); rotate(model.GetModelTransform(), static_cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f)));
} }
model.Update(); model.Update();
cameraController.m_Camera.CalculateInverses(); cameraController.m_Camera.CalculateInverses();
@ -584,7 +584,7 @@ main(int, char **)
vk::RenderingInfo renderingInfo = { vk::RenderingInfo renderingInfo = {
.renderArea = {.extent = ToExtent2D(currentAttachment->m_Extent)}, .renderArea = {.extent = ToExtent2D(currentAttachment->m_Extent)},
.layerCount = 1, .layerCount = 1,
.colorAttachmentCount = Cast<u32>(attachmentInfos.size()), .colorAttachmentCount = static_cast<u32>(attachmentInfos.size()),
.pColorAttachments = attachmentInfos.data(), .pColorAttachments = attachmentInfos.data(),
.pDepthAttachment = &depthAttachment, .pDepthAttachment = &depthAttachment,
}; };
@ -637,7 +637,7 @@ main(int, char **)
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, innerPcbOffset, cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, innerPcbOffset,
sizeof prim.m_TransformIdx, &prim.m_TransformIdx); sizeof prim.m_TransformIdx, &prim.m_TransformIdx);
innerPcbOffset += sizeof prim.m_TransformIdx; innerPcbOffset += sizeof prim.m_TransformIdx;
cmd.drawIndexed(prim.m_IndexCount, 1, prim.m_FirstIndex, Cast<i32>(prim.m_VertexOffset), 0); cmd.drawIndexed(prim.m_IndexCount, 1, prim.m_FirstIndex, static_cast<i32>(prim.m_VertexOffset), 0);
} }
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, backGroundPipeline.m_Pipeline); cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, backGroundPipeline.m_Pipeline);
@ -670,7 +670,7 @@ main(int, char **)
.dstOffsets = .dstOffsets =
std::array{ std::array{
vk::Offset3D{0, 0, 0}, vk::Offset3D{0, 0, 0},
vk::Offset3D{Cast<i32>(swapchain.m_Extent.width), Cast<i32>(swapchain.m_Extent.height), 1}, vk::Offset3D{static_cast<i32>(swapchain.m_Extent.width), static_cast<i32>(swapchain.m_Extent.height), 1},
}, },
}; };
cmd.blitImage(currentImage, postRenderBarriers[0].newLayout, currentSwapchainImage, cmd.blitImage(currentImage, postRenderBarriers[0].newLayout, currentSwapchainImage,

View File

@ -49,7 +49,7 @@ Nodes::operator[](const u32 index)
u32 u32
Nodes::Count() const Nodes::Count() const
{ {
return Cast<u32>(m_Transforms.size()); return static_cast<u32>(m_Transforms.size());
} }
usize usize

View File

@ -60,7 +60,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems:
}, },
}; };
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {
.bindingCount = Cast<u32>(descriptorSetLayoutBindings.size()), .bindingCount = static_cast<u32>(descriptorSetLayoutBindings.size()),
.pBindings = descriptorSetLayoutBindings.data(), .pBindings = descriptorSetLayoutBindings.data(),
}; };
vk::DescriptorSetLayout descriptorSetLayout; vk::DescriptorSetLayout descriptorSetLayout;
@ -76,7 +76,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems:
}; };
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = {
.setLayoutCount = Cast<u32>(descriptorSetLayouts.size()), .setLayoutCount = static_cast<u32>(descriptorSetLayouts.size()),
.pSetLayouts = descriptorSetLayouts.data(), .pSetLayouts = descriptorSetLayouts.data(),
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &pushConstantRange, .pPushConstantRanges = &pushConstantRange,
@ -139,7 +139,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems:
}; };
vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = {
.dynamicStateCount = Cast<u32>(dynamicStates.size()), .dynamicStateCount = static_cast<u32>(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(), .pDynamicStates = dynamicStates.data(),
}; };
@ -152,7 +152,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems:
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
.pNext = &renderingCreateInfo, .pNext = &renderingCreateInfo,
.stageCount = Cast<u32>(shaderStages.size()), .stageCount = static_cast<u32>(shaderStages.size()),
.pStages = shaderStages.data(), .pStages = shaderStages.data(),
.pVertexInputState = &vertexInputStateCreateInfo, .pVertexInputState = &vertexInputStateCreateInfo,
.pInputAssemblyState = &inputAssemblyStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo,
@ -221,7 +221,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
}, },
}; };
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {
.bindingCount = Cast<u32>(descriptorSetLayoutBindings.size()), .bindingCount = static_cast<u32>(descriptorSetLayoutBindings.size()),
.pBindings = descriptorSetLayoutBindings.data(), .pBindings = descriptorSetLayoutBindings.data(),
}; };
vk::DescriptorSetLayout descriptorSetLayout; vk::DescriptorSetLayout descriptorSetLayout;
@ -237,7 +237,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
}; };
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = {
.setLayoutCount = Cast<u32>(descriptorSetLayouts.size()), .setLayoutCount = static_cast<u32>(descriptorSetLayouts.size()),
.pSetLayouts = descriptorSetLayouts.data(), .pSetLayouts = descriptorSetLayouts.data(),
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &pushConstantRange, .pPushConstantRanges = &pushConstantRange,
@ -300,7 +300,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
}; };
vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = {
.dynamicStateCount = Cast<u32>(dynamicStates.size()), .dynamicStateCount = static_cast<u32>(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(), .pDynamicStates = dynamicStates.data(),
}; };
@ -313,7 +313,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
.pNext = &renderingCreateInfo, .pNext = &renderingCreateInfo,
.stageCount = Cast<u32>(shaderStages.size()), .stageCount = static_cast<u32>(shaderStages.size()),
.pStages = shaderStages.data(), .pStages = shaderStages.data(),
.pVertexInputState = &vertexInputStateCreateInfo, .pVertexInputState = &vertexInputStateCreateInfo,
.pInputAssemblyState = &inputAssemblyStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo,

View File

@ -102,8 +102,8 @@ AssetLoader::LoadHdrImage(Texture *texture, cstr path, cstr name) const
ERROR_IF(!data, "Could not load {}", path) THEN_ABORT(-1); ERROR_IF(!data, "Could not load {}", path) THEN_ABORT(-1);
assert(nChannels == 3); assert(nChannels == 3);
u32 width = Cast<u32>(x); u32 width = static_cast<u32>(x);
u32 height = Cast<u32>(y); u32 height = static_cast<u32>(y);
StagingBuffer stagingBuffer; StagingBuffer stagingBuffer;
texture->Init(m_ResourceManager->m_Device, {width, height}, vk::Format::eR32G32B32A32Sfloat, false, path); texture->Init(m_ResourceManager->m_Device, {width, height}, vk::Format::eR32G32B32A32Sfloat, false, path);
@ -279,7 +279,7 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, Texture *texture, vk::ImageLayo
} }
vk::DependencyInfo imageStartDependency = { vk::DependencyInfo imageStartDependency = {
.imageMemoryBarrierCount = Cast<u32>(startBarriers.size()), .imageMemoryBarrierCount = static_cast<u32>(startBarriers.size()),
.pImageMemoryBarriers = startBarriers.data(), .pImageMemoryBarriers = startBarriers.data(),
}; };
@ -362,8 +362,8 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, Texture *texture, vk::ImageLayo
commandBuffer.pipelineBarrier2(&imageStartDependency); commandBuffer.pipelineBarrier2(&imageStartDependency);
i32 prevMipWidth = Cast<i32>(texture->m_Extent.width); i32 prevMipWidth = static_cast<i32>(texture->m_Extent.width);
i32 prevMipHeight = Cast<i32>(texture->m_Extent.height); i32 prevMipHeight = static_cast<i32>(texture->m_Extent.height);
u32 maxPrevMip = texture->GetMipLevels() - 1; u32 maxPrevMip = texture->GetMipLevels() - 1;
for (u32 prevMipLevel = 0; prevMipLevel < maxPrevMip; ++prevMipLevel) for (u32 prevMipLevel = 0; prevMipLevel < maxPrevMip; ++prevMipLevel)
@ -404,8 +404,8 @@ AssetLoader::LoadImageToGpu(StagingBuffer *stagingBuffer, tinygltf::Image *image
assert(image->component == 4); assert(image->component == 4);
assert(image->height > 0 && image->width > 0); assert(image->height > 0 && image->width > 0);
u32 height = Cast<u32>(image->height); u32 height = static_cast<u32>(image->height);
u32 width = Cast<u32>(image->width); u32 width = static_cast<u32>(image->width);
vk::Format imageFormat = isSrgb ? vk::Format::eR8G8B8A8Srgb : vk::Format::eR8G8B8A8Unorm; vk::Format imageFormat = isSrgb ? vk::Format::eR8G8B8A8Srgb : vk::Format::eR8G8B8A8Unorm;
@ -481,8 +481,8 @@ AssetLoader::LoadImageToGpu(StagingBuffer *stagingBuffer, tinygltf::Image *image
vk::BufferImageCopy2 imageCopy = { vk::BufferImageCopy2 imageCopy = {
.bufferOffset = 0, .bufferOffset = 0,
.bufferRowLength = Cast<u32>(image->width), .bufferRowLength = static_cast<u32>(image->width),
.bufferImageHeight = Cast<u32>(image->height), .bufferImageHeight = static_cast<u32>(image->height),
.imageSubresource = .imageSubresource =
{ {
.aspectMask = vk::ImageAspectFlagBits::eColor, .aspectMask = vk::ImageAspectFlagBits::eColor,
@ -558,8 +558,8 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
if (node->mesh >= 0) if (node->mesh >= 0)
{ {
auto *mesh = &model->meshes[node->mesh]; auto *mesh = &model->meshes[node->mesh];
u32 vertexOffset = Cast<u32>(vertexPositions->size()); u32 vertexOffset = static_cast<u32>(vertexPositions->size());
u32 indexOffset = Cast<u32>(indices->size()); u32 indexOffset = static_cast<u32>(indices->size());
for (auto &prim : mesh->primitives) for (auto &prim : mesh->primitives)
{ {
u32 vertexCount = 0; u32 vertexCount = 0;
@ -577,17 +577,17 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
tinygltf::Buffer *posBuffer = &model->buffers[posBufferView->buffer]; tinygltf::Buffer *posBuffer = &model->buffers[posBufferView->buffer];
usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset); usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset);
vertexCount = Cast<u32>(posAccessor->count); vertexCount = static_cast<u32>(posAccessor->count);
vertexPositions->reserve(vertexOffset + vertexCount); vertexPositions->reserve(vertexOffset + vertexCount);
if (posAccessor->type == TINYGLTF_TYPE_VEC4) if (posAccessor->type == TINYGLTF_TYPE_VEC4)
{ {
vec4 *data = Recast<vec4 *>(posBuffer->data.data() + byteOffset); vec4 *data = reinterpret_cast<vec4 *>(posBuffer->data.data() + byteOffset);
vertexPositions->insert(vertexPositions->end(), data, data + vertexCount); vertexPositions->insert(vertexPositions->end(), data, data + vertexCount);
} }
else if (posAccessor->type == TINYGLTF_TYPE_VEC3) else if (posAccessor->type == TINYGLTF_TYPE_VEC3)
{ {
vec3 *data = Recast<vec3 *>(posBuffer->data.data() + byteOffset); vec3 *data = reinterpret_cast<vec3 *>(posBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
vertexPositions->push_back(vec4(data[i], 1.0f)); vertexPositions->push_back(vec4(data[i], 1.0f));
@ -595,7 +595,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
} }
else if (posAccessor->type == TINYGLTF_TYPE_VEC2) else if (posAccessor->type == TINYGLTF_TYPE_VEC2)
{ {
vec2 *data = Recast<vec2 *>(posBuffer->data.data() + byteOffset); vec2 *data = reinterpret_cast<vec2 *>(posBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
vertexPositions->push_back(vec4(data[i], 0.0f, 1.0f)); vertexPositions->push_back(vec4(data[i], 0.0f, 1.0f));
@ -619,7 +619,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
if (normAccessor->type == TINYGLTF_TYPE_VEC4) if (normAccessor->type == TINYGLTF_TYPE_VEC4)
{ {
vec4 *data = Recast<vec4 *>(normBuffer->data.data() + byteOffset); vec4 *data = reinterpret_cast<vec4 *>(normBuffer->data.data() + byteOffset);
vec4 *end = data + vertexCount; vec4 *end = data + vertexCount;
u32 idx = vertexOffset; u32 idx = vertexOffset;
@ -631,7 +631,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
} }
else if (normAccessor->type == TINYGLTF_TYPE_VEC3) else if (normAccessor->type == TINYGLTF_TYPE_VEC3)
{ {
vec3 *data = Recast<vec3 *>(normBuffer->data.data() + byteOffset); vec3 *data = reinterpret_cast<vec3 *>(normBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
auto norm = vec4(data[i], 0.0f); auto norm = vec4(data[i], 0.0f);
@ -640,7 +640,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
} }
else if (normAccessor->type == TINYGLTF_TYPE_VEC2) else if (normAccessor->type == TINYGLTF_TYPE_VEC2)
{ {
vec2 *data = Recast<vec2 *>(normBuffer->data.data() + byteOffset); vec2 *data = reinterpret_cast<vec2 *>(normBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
auto norm = vec4(data[i], 0.0f, 0.0f); auto norm = vec4(data[i], 0.0f, 0.0f);
@ -663,7 +663,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
assert(uvAccessor->type == TINYGLTF_TYPE_VEC2 && assert(uvAccessor->type == TINYGLTF_TYPE_VEC2 &&
uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT);
{ {
vec2 *data = Recast<vec2 *>(uvBuffer->data.data() + byteOffset); vec2 *data = reinterpret_cast<vec2 *>(uvBuffer->data.data() + byteOffset);
vec2 *end = data + vertexCount; vec2 *end = data + vertexCount;
u32 idx = vertexOffset; u32 idx = vertexOffset;
vec2 *it = data; vec2 *it = data;
@ -686,7 +686,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
if (colorAccessor->type == TINYGLTF_TYPE_VEC4) if (colorAccessor->type == TINYGLTF_TYPE_VEC4)
{ {
vec4 *data = Recast<vec4 *>(colorBuffer->data.data() + byteOffset); vec4 *data = reinterpret_cast<vec4 *>(colorBuffer->data.data() + byteOffset);
vec4 *end = data + vertexCount; vec4 *end = data + vertexCount;
u32 idx = vertexOffset; u32 idx = vertexOffset;
@ -698,7 +698,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
} }
else if (colorAccessor->type == TINYGLTF_TYPE_VEC3) else if (colorAccessor->type == TINYGLTF_TYPE_VEC3)
{ {
vec3 *data = Recast<vec3 *>(colorBuffer->data.data() + byteOffset); vec3 *data = reinterpret_cast<vec3 *>(colorBuffer->data.data() + byteOffset);
for (u32 i = 0; i < vertexCount; ++i) for (u32 i = 0; i < vertexCount; ++i)
{ {
auto color = vec4(data[i], 1.0f); auto color = vec4(data[i], 1.0f);
@ -719,22 +719,22 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector<vec4> *vertexPosi
tinygltf::Buffer *indexBuffer = &model->buffers[indexBufferView->buffer]; tinygltf::Buffer *indexBuffer = &model->buffers[indexBufferView->buffer];
usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset); usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset);
indexCount = Cast<u32>(indexAccessor->count); indexCount = static_cast<u32>(indexAccessor->count);
indices->reserve(indexOffset + indexCount); indices->reserve(indexOffset + indexCount);
if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT) if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT)
{ {
u32 *data = Recast<u32 *>(indexBuffer->data.data() + byteOffset); u32 *data = reinterpret_cast<u32 *>(indexBuffer->data.data() + byteOffset);
indices->insert(indices->end(), data, data + indexCount); indices->insert(indices->end(), data, data + indexCount);
} }
else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT)
{ {
u16 *data = Recast<u16 *>(indexBuffer->data.data() + byteOffset); u16 *data = reinterpret_cast<u16 *>(indexBuffer->data.data() + byteOffset);
indices->insert(indices->end(), data, data + indexCount); indices->insert(indices->end(), data, data + indexCount);
} }
else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE) else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE)
{ {
u8 *data = Recast<u8 *>(indexBuffer->data.data() + byteOffset); u8 *data = reinterpret_cast<u8 *>(indexBuffer->data.data() + byteOffset);
indices->insert(indices->end(), data, data + indexCount); indices->insert(indices->end(), data, data + indexCount);
} }
} }
@ -860,7 +860,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
return materialFind->second; return materialFind->second;
} }
u32 index = Cast<u32>(materials.size()); u32 index = static_cast<u32>(materials.size());
auto *material = &model.materials[materialIdx]; auto *material = &model.materials[materialIdx];
f32 alphaBlendValue = -1; f32 alphaBlendValue = -1;
@ -870,14 +870,14 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
} }
else if (material->alphaMode == "MASK") else if (material->alphaMode == "MASK")
{ {
alphaBlendValue = Cast<f32>(material->alphaCutoff); alphaBlendValue = static_cast<f32>(material->alphaCutoff);
} }
materials.push_back({ materials.push_back({
.m_AlbedoFactor = VectorToVec4(material->pbrMetallicRoughness.baseColorFactor), .m_AlbedoFactor = VectorToVec4(material->pbrMetallicRoughness.baseColorFactor),
.m_EmissionFactor = VectorToVec3(material->emissiveFactor), .m_EmissionFactor = VectorToVec3(material->emissiveFactor),
.m_MetalFactor = Cast<f32>(material->pbrMetallicRoughness.metallicFactor), .m_MetalFactor = static_cast<f32>(material->pbrMetallicRoughness.metallicFactor),
.m_RoughFactor = Cast<f32>(material->pbrMetallicRoughness.roughnessFactor), .m_RoughFactor = static_cast<f32>(material->pbrMetallicRoughness.roughnessFactor),
.m_AlbedoTex = getTextureHandle(material->pbrMetallicRoughness.baseColorTexture.index, true), .m_AlbedoTex = getTextureHandle(material->pbrMetallicRoughness.baseColorTexture.index, true),
.m_NormalTex = getTextureHandle(material->normalTexture.index, false), .m_NormalTex = getTextureHandle(material->normalTexture.index, false),
.m_MetalRoughTex = getTextureHandle(material->pbrMetallicRoughness.metallicRoughnessTexture.index, false), .m_MetalRoughTex = getTextureHandle(material->pbrMetallicRoughness.metallicRoughnessTexture.index, false),

View File

@ -121,7 +121,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu
readyToWriteBarriers[3].subresourceRange = lutSubresRange; readyToWriteBarriers[3].subresourceRange = lutSubresRange;
vk::DependencyInfo readyToWriteDependency = { vk::DependencyInfo readyToWriteDependency = {
.imageMemoryBarrierCount = Cast<u32>(readyToWriteBarriers.size()), .imageMemoryBarrierCount = static_cast<u32>(readyToWriteBarriers.size()),
.pImageMemoryBarriers = readyToWriteBarriers.data(), .pImageMemoryBarriers = readyToWriteBarriers.data(),
}; };
@ -197,7 +197,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu
vk::PushConstantRange pcr = { vk::PushConstantRange pcr = {
.stageFlags = vk::ShaderStageFlagBits::eCompute, .stageFlags = vk::ShaderStageFlagBits::eCompute,
.offset = 0, .offset = 0,
.size = Cast<u32>(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)), .size = static_cast<u32>(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)),
eastl::max(sizeof(DiffuseIrradiancePushConstants), sizeof(PrefilterPushConstants)))), eastl::max(sizeof(DiffuseIrradiancePushConstants), sizeof(PrefilterPushConstants)))),
}; };
@ -254,7 +254,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu
}; };
eastl::array<vk::Pipeline, computePipelineCreateInfo.size()> pipelines; eastl::array<vk::Pipeline, computePipelineCreateInfo.size()> pipelines;
AbortIfFailed(pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, Cast<u32>(computePipelineCreateInfo.size()), AbortIfFailed(pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, static_cast<u32>(computePipelineCreateInfo.size()),
computePipelineCreateInfo.data(), nullptr, computePipelineCreateInfo.data(), nullptr,
pipelines.data())); pipelines.data()));
@ -331,7 +331,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu
{ {
prefilterPushConstants.m_OutputTexture = tex; prefilterPushConstants.m_OutputTexture = tex;
prefilterPushConstants.m_CubeSide = mipSize; prefilterPushConstants.m_CubeSide = mipSize;
prefilterPushConstants.m_Roughness = Cast<f32>(mipCount) / Cast<f32>(prefilterMipCountMax); prefilterPushConstants.m_Roughness = static_cast<f32>(mipCount) / static_cast<f32>(prefilterMipCountMax);
cmd.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eCompute, 0, sizeof prefilterPushConstants, cmd.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eCompute, 0, sizeof prefilterPushConstants,
&prefilterPushConstants); &prefilterPushConstants);
u32 groupCount = eastl::max(mipSize / 16u, 1u); u32 groupCount = eastl::max(mipSize / 16u, 1u);

View File

@ -56,10 +56,10 @@ static_assert(Light::COLOR_MASK == 0xFFFFFF00);
inline u32 inline u32
ToColor32(const vec4 &col) ToColor32(const vec4 &col)
{ {
const u32 r = Cast<u32>(eastl::min(col.r, 1.0f) * 255.99f); const u32 r = static_cast<u32>(eastl::min(col.r, 1.0f) * 255.99f);
const u32 g = Cast<u32>(eastl::min(col.g, 1.0f) * 255.99f); const u32 g = static_cast<u32>(eastl::min(col.g, 1.0f) * 255.99f);
const u32 b = Cast<u32>(eastl::min(col.b, 1.0f) * 255.99f); const u32 b = static_cast<u32>(eastl::min(col.b, 1.0f) * 255.99f);
const u32 a = Cast<u32>(eastl::min(col.a, 1.0f) * 255.99f); const u32 a = static_cast<u32>(eastl::min(col.a, 1.0f) * 255.99f);
return r << 24 | g << 16 | b << 8 | a; return r << 24 | g << 16 | b << 8 | a;
} }
@ -67,9 +67,9 @@ ToColor32(const vec4 &col)
inline u32 inline u32
ToColor32(const vec3 &col) ToColor32(const vec3 &col)
{ {
const u32 r = Cast<u32>(eastl::min(col.r, 1.0f) * 255.99f); const u32 r = static_cast<u32>(eastl::min(col.r, 1.0f) * 255.99f);
const u32 g = Cast<u32>(eastl::min(col.g, 1.0f) * 255.99f); const u32 g = static_cast<u32>(eastl::min(col.g, 1.0f) * 255.99f);
const u32 b = Cast<u32>(eastl::min(col.b, 1.0f) * 255.99f); const u32 b = static_cast<u32>(eastl::min(col.b, 1.0f) * 255.99f);
constexpr u32 a = 255; constexpr u32 a = 255;
return r << 24 | g << 16 | b << 8 | a; return r << 24 | g << 16 | b << 8 | a;
@ -206,7 +206,7 @@ LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius
m_GpuBufferCapacity_ |= UPDATE_REQUIRED_BIT; m_GpuBufferCapacity_ |= UPDATE_REQUIRED_BIT;
return {Light::TYPE_POINT, gen, Cast<u16>(index)}; return {Light::TYPE_POINT, gen, static_cast<u16>(index)};
} }
++light; ++light;
} }
@ -236,7 +236,7 @@ LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius
void void
LightManager::Update() LightManager::Update()
{ {
const u16 requiredBufferCapacity = eastl::min(Cast<u16>(m_Lights.capacity()), MAX_LIGHTS); const u16 requiredBufferCapacity = eastl::min(static_cast<u16>(m_Lights.capacity()), MAX_LIGHTS);
if ((m_GpuBufferCapacity_ & CAPACITY_MASK) < requiredBufferCapacity) if ((m_GpuBufferCapacity_ & CAPACITY_MASK) < requiredBufferCapacity)
{ {
m_GpuBufferCapacity_ = requiredBufferCapacity | UPDATE_REQUIRED_BIT; m_GpuBufferCapacity_ = requiredBufferCapacity | UPDATE_REQUIRED_BIT;

View File

@ -73,7 +73,7 @@ struct LightManager
// Using lower bit. Capacity can be directly a multiple of 2 // Using lower bit. Capacity can be directly a multiple of 2
// Thus, range is up to MaxValue<u16> // Thus, range is up to MaxValue<u16>
constexpr static u16 UPDATE_REQUIRED_BIT = 1; constexpr static u16 UPDATE_REQUIRED_BIT = 1;
constexpr static u16 CAPACITY_MASK = Cast<u16>(~UPDATE_REQUIRED_BIT); constexpr static u16 CAPACITY_MASK = static_cast<u16>(~UPDATE_REQUIRED_BIT);
LightHandle AddDirectional(const vec3 &direction, const vec3 &color, f32 intensity); LightHandle AddDirectional(const vec3 &direction, const vec3 &color, f32 intensity);
LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius, f32 intensity); LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius, f32 intensity);

View File

@ -49,7 +49,7 @@ main(int, char *[])
internalResolution.width = (internalResolution.height * INIT_WIDTH) / INIT_HEIGHT; internalResolution.width = (internalResolution.height * INIT_WIDTH) / INIT_HEIGHT;
CameraController cameraController = {vec3{0.0f, 1.0f, 4.0f}, vec3{0.0f, 0.0f, 0.0f}, 70_deg, CameraController cameraController = {vec3{0.0f, 1.0f, 4.0f}, vec3{0.0f, 0.0f, 0.0f}, 70_deg,
Cast<f32>(internalResolution.width) / Cast<f32>(internalResolution.height)}; static_cast<f32>(internalResolution.width) / static_cast<f32>(internalResolution.height)};
INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data()); INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data());
@ -138,7 +138,7 @@ main(int, char *[])
}, },
}; };
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = { vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = {
.maxSets = 1, .poolSizeCount = Cast<u32>(poolSizes.size()), .pPoolSizes = poolSizes.data()}; .maxSets = 1, .poolSizeCount = static_cast<u32>(poolSizes.size()), .pPoolSizes = poolSizes.data()};
AbortIfFailed(device.m_Device.createDescriptorPool(&descriptorPoolCreateInfo, nullptr, &descriptorPool)); AbortIfFailed(device.m_Device.createDescriptorPool(&descriptorPoolCreateInfo, nullptr, &descriptorPool));
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo = { vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo = {
@ -164,14 +164,14 @@ main(int, char *[])
.pBufferInfo = &camLightBufferInfo, .pBufferInfo = &camLightBufferInfo,
}, },
}; };
device.m_Device.updateDescriptorSets(Cast<u32>(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr); device.m_Device.updateDescriptorSets(static_cast<u32>(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr);
// Persistent variables // Persistent variables
vk::Viewport viewport = { vk::Viewport viewport = {
.x = 0, .x = 0,
.y = Cast<f32>(internalResolution.height), .y = static_cast<f32>(internalResolution.height),
.width = Cast<f32>(internalResolution.width), .width = static_cast<f32>(internalResolution.width),
.height = -Cast<f32>(internalResolution.height), .height = -static_cast<f32>(internalResolution.height),
.minDepth = 0.0, .minDepth = 0.0,
.maxDepth = 1.0, .maxDepth = 1.0,
}; };
@ -232,7 +232,7 @@ main(int, char *[])
acquireToTransferDstBarrier, acquireToTransferDstBarrier,
}; };
vk::DependencyInfo postRenderDependencies = { vk::DependencyInfo postRenderDependencies = {
.imageMemoryBarrierCount = Cast<u32>(postRenderBarriers.size()), .imageMemoryBarrierCount = static_cast<u32>(postRenderBarriers.size()),
.pImageMemoryBarriers = postRenderBarriers.data(), .pImageMemoryBarriers = postRenderBarriers.data(),
}; };
@ -314,13 +314,13 @@ main(int, char *[])
swapchain.RegisterResizeCallback( swapchain.RegisterResizeCallback(
[&cameraController, &internalResolution, &viewport, &scissor](vk::Extent2D extent) { [&cameraController, &internalResolution, &viewport, &scissor](vk::Extent2D extent) {
cameraController.SetAspectRatio(Cast<f32>(extent.width) / Cast<f32>(extent.height)); cameraController.SetAspectRatio(static_cast<f32>(extent.width) / static_cast<f32>(extent.height));
internalResolution.width = Cast<u32>(Cast<f32>(internalResolution.height) * cameraController.m_AspectRatio); internalResolution.width = static_cast<u32>(static_cast<f32>(internalResolution.height) * cameraController.m_AspectRatio);
viewport.y = Cast<f32>(internalResolution.height); viewport.y = static_cast<f32>(internalResolution.height);
viewport.width = Cast<f32>(internalResolution.width); viewport.width = static_cast<f32>(internalResolution.width);
viewport.height = -Cast<f32>(internalResolution.height); viewport.height = -static_cast<f32>(internalResolution.height);
scissor.extent = internalResolution; scissor.extent = internalResolution;
}); });
@ -354,7 +354,7 @@ main(int, char *[])
// for (auto [entity, dynTrans] : rootModel.each()) // for (auto [entity, dynTrans] : rootModel.each())
//{ //{
// dynTrans.m_Rotation = // dynTrans.m_Rotation =
// glm::rotate(dynTrans.m_Rotation, Cast<f32>(30_deg * (++index) * Time::m_Delta), vec3{0.0f, 1.0f, // glm::rotate(dynTrans.m_Rotation, static_cast<f32>(30_deg * (++index) * Time::m_Delta), vec3{0.0f, 1.0f,
// 0.0f}); // 0.0f});
// } // }
@ -417,7 +417,7 @@ main(int, char *[])
registry.get<CGlobalTransform>(parent.m_ParentEntity).m_Transform * translation * rotation * scale; registry.get<CGlobalTransform>(parent.m_ParentEntity).m_Transform * translation * rotation * scale;
} }
u32 objectCount = Cast<u32>(renderableObjectsGroup.size()); u32 objectCount = static_cast<u32>(renderableObjectsGroup.size());
nodeData.clear(); nodeData.clear();
nodeDrawInfo.clear(); nodeDrawInfo.clear();
nodeData.reserve(objectCount); nodeData.reserve(objectCount);
@ -474,7 +474,7 @@ main(int, char *[])
vk::RenderingInfo renderingInfo = { vk::RenderingInfo renderingInfo = {
.renderArea = {.extent = ToExtent2D(currentAttachment->m_Extent)}, .renderArea = {.extent = ToExtent2D(currentAttachment->m_Extent)},
.layerCount = 1, .layerCount = 1,
.colorAttachmentCount = Cast<u32>(attachmentInfos.size()), .colorAttachmentCount = static_cast<u32>(attachmentInfos.size()),
.pColorAttachments = attachmentInfos.data(), .pColorAttachments = attachmentInfos.data(),
.pDepthAttachment = &depthAttachment, .pDepthAttachment = &depthAttachment,
}; };
@ -531,7 +531,7 @@ main(int, char *[])
.dstOffsets = .dstOffsets =
std::array{ std::array{
vk::Offset3D{0, 0, 0}, vk::Offset3D{0, 0, 0},
vk::Offset3D{Cast<i32>(swapchain.m_Extent.width), Cast<i32>(swapchain.m_Extent.height), 1}, vk::Offset3D{static_cast<i32>(swapchain.m_Extent.width), static_cast<i32>(swapchain.m_Extent.height), 1},
}, },
}; };
cmd.blitImage(currentImage, postRenderBarriers[0].newLayout, currentSwapchainImage, cmd.blitImage(currentImage, postRenderBarriers[0].newLayout, currentSwapchainImage,

View File

@ -46,7 +46,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe
}, },
}; };
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {
.bindingCount = Cast<u32>(descriptorSetLayoutBindings.size()), .bindingCount = static_cast<u32>(descriptorSetLayoutBindings.size()),
.pBindings = descriptorSetLayoutBindings.data(), .pBindings = descriptorSetLayoutBindings.data(),
}; };
vk::DescriptorSetLayout descriptorSetLayout; vk::DescriptorSetLayout descriptorSetLayout;
@ -62,7 +62,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe
}; };
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = {
.setLayoutCount = Cast<u32>(descriptorSetLayouts.size()), .setLayoutCount = static_cast<u32>(descriptorSetLayouts.size()),
.pSetLayouts = descriptorSetLayouts.data(), .pSetLayouts = descriptorSetLayouts.data(),
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &pushConstantRange, .pPushConstantRanges = &pushConstantRange,
@ -125,7 +125,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe
}; };
vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = {
.dynamicStateCount = Cast<u32>(dynamicStates.size()), .dynamicStateCount = static_cast<u32>(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(), .pDynamicStates = dynamicStates.data(),
}; };
@ -138,7 +138,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
.pNext = &renderingCreateInfo, .pNext = &renderingCreateInfo,
.stageCount = Cast<u32>(shaderStages.size()), .stageCount = static_cast<u32>(shaderStages.size()),
.pStages = shaderStages.data(), .pStages = shaderStages.data(),
.pVertexInputState = &vertexInputStateCreateInfo, .pVertexInputState = &vertexInputStateCreateInfo,
.pInputAssemblyState = &inputAssemblyStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo,
@ -197,7 +197,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
}, },
}; };
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {
.bindingCount = Cast<u32>(descriptorSetLayoutBindings.size()), .bindingCount = static_cast<u32>(descriptorSetLayoutBindings.size()),
.pBindings = descriptorSetLayoutBindings.data(), .pBindings = descriptorSetLayoutBindings.data(),
}; };
vk::DescriptorSetLayout descriptorSetLayout; vk::DescriptorSetLayout descriptorSetLayout;
@ -213,7 +213,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
}; };
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = {
.setLayoutCount = Cast<u32>(descriptorSetLayouts.size()), .setLayoutCount = static_cast<u32>(descriptorSetLayouts.size()),
.pSetLayouts = descriptorSetLayouts.data(), .pSetLayouts = descriptorSetLayouts.data(),
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &pushConstantRange, .pPushConstantRanges = &pushConstantRange,
@ -276,7 +276,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
}; };
vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = {
.dynamicStateCount = Cast<u32>(dynamicStates.size()), .dynamicStateCount = static_cast<u32>(dynamicStates.size()),
.pDynamicStates = dynamicStates.data(), .pDynamicStates = dynamicStates.data(),
}; };
@ -289,7 +289,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { vk::GraphicsPipelineCreateInfo pipelineCreateInfo = {
.pNext = &renderingCreateInfo, .pNext = &renderingCreateInfo,
.stageCount = Cast<u32>(shaderStages.size()), .stageCount = static_cast<u32>(shaderStages.size()),
.pStages = shaderStages.data(), .pStages = shaderStages.data(),
.pVertexInputState = &vertexInputStateCreateInfo, .pVertexInputState = &vertexInputStateCreateInfo,
.pInputAssemblyState = &inputAssemblyStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo,

View File

@ -33,7 +33,7 @@ TextureManager::Commit(Texture *texture)
Texture *allocatedTexture = &m_Textures[index]; Texture *allocatedTexture = &m_Textures[index];
assert(!allocatedTexture->IsValid()); assert(!allocatedTexture->IsValid());
m_FreeHead = *Recast<u32 *>(allocatedTexture); m_FreeHead = *reinterpret_cast<u32 *>(allocatedTexture);
// Ensure it is copyable. // Ensure it is copyable.
static_assert(std::is_trivially_copyable_v<Texture>); static_assert(std::is_trivially_copyable_v<Texture>);
@ -45,7 +45,7 @@ TextureManager::Commit(Texture *texture)
return {index}; return {index};
} }
const u32 index = Cast<u32>(m_Textures.size()); const u32 index = static_cast<u32>(m_Textures.size());
if (index < m_MaxCapacity) if (index < m_MaxCapacity)
{ {
Texture *allocatedTexture = &m_Textures.push_back(); Texture *allocatedTexture = &m_Textures.push_back();
@ -79,7 +79,7 @@ TextureManager::Release(const Device *device, const TextureHandle handle)
allocatedTexture->Destroy(device); allocatedTexture->Destroy(device);
assert(!allocatedTexture->IsValid()); assert(!allocatedTexture->IsValid());
*Recast<u32 *>(allocatedTexture) = m_FreeHead; *reinterpret_cast<u32 *>(allocatedTexture) = m_FreeHead;
m_FreeHead = handle.m_Index; m_FreeHead = handle.m_Index;
} }
@ -104,10 +104,10 @@ BufferManager::Init(const u32 maxCapacity)
Buffer *pIter = m_Buffers; Buffer *pIter = m_Buffers;
for (u32 i = 1; i < m_MaxCapacity; ++i) for (u32 i = 1; i < m_MaxCapacity; ++i)
{ {
*Recast<u32 *>(pIter) = i; *reinterpret_cast<u32 *>(pIter) = i;
++pIter; ++pIter;
} }
*Recast<u32 *>(pIter) = GpuResourceHandle::INVALID_HANDLE; *reinterpret_cast<u32 *>(pIter) = GpuResourceHandle::INVALID_HANDLE;
} }
BufferHandle BufferHandle
@ -132,7 +132,7 @@ BufferManager::Commit_(StorageBuffer *buffer)
Buffer *allocatedBuffer = &m_Buffers[index]; Buffer *allocatedBuffer = &m_Buffers[index];
assert(!allocatedBuffer->IsValid()); assert(!allocatedBuffer->IsValid());
m_FreeHead = *Recast<u32 *>(allocatedBuffer); m_FreeHead = *reinterpret_cast<u32 *>(allocatedBuffer);
// Ensure it is copyable. // Ensure it is copyable.
static_assert(std::is_trivially_copyable_v<StorageBuffer>); static_assert(std::is_trivially_copyable_v<StorageBuffer>);
@ -149,7 +149,7 @@ BufferManager::Fetch(const BufferHandle handle)
{ {
assert(!handle.IsInvalid()); assert(!handle.IsInvalid());
return Recast<StorageBuffer *>(&m_Buffers[handle.m_Index]); return reinterpret_cast<StorageBuffer *>(&m_Buffers[handle.m_Index]);
} }
void void
@ -161,7 +161,7 @@ BufferManager::Release(const Device *device, const BufferHandle handle)
allocatedBuffer->Destroy(device); allocatedBuffer->Destroy(device);
assert(!allocatedBuffer->IsValid()); assert(!allocatedBuffer->IsValid());
*Recast<u32 *>(allocatedBuffer) = m_FreeHead; *reinterpret_cast<u32 *>(allocatedBuffer) = m_FreeHead;
m_FreeHead = handle.m_Index; m_FreeHead = handle.m_Index;
} }
@ -196,7 +196,7 @@ StorageTextureManager::Fetch(const StorageTextureHandle handle)
{ {
assert(!handle.IsInvalid()); assert(!handle.IsInvalid());
return Recast<StorageTexture *>(&m_Textures[handle.m_Index]); return reinterpret_cast<StorageTexture *>(&m_Textures[handle.m_Index]);
} }
void void
@ -215,15 +215,15 @@ HashSamplerCreateInfo(const vk::SamplerCreateInfo *createInfo)
hash = HashCombine(hash, HashAny(createInfo->addressModeU)); hash = HashCombine(hash, HashAny(createInfo->addressModeU));
hash = HashCombine(hash, HashAny(createInfo->addressModeV)); hash = HashCombine(hash, HashAny(createInfo->addressModeV));
hash = HashCombine(hash, HashAny(createInfo->addressModeW)); hash = HashCombine(hash, HashAny(createInfo->addressModeW));
hash = HashCombine(hash, HashAny(Cast<usize>(createInfo->mipLodBias * 1000))); // Resolution of 10^-3 hash = HashCombine(hash, HashAny(static_cast<usize>(createInfo->mipLodBias * 1000))); // Resolution of 10^-3
hash = HashCombine(hash, HashAny(createInfo->anisotropyEnable)); hash = HashCombine(hash, HashAny(createInfo->anisotropyEnable));
hash = HashCombine(hash, hash = HashCombine(hash,
HashAny(Cast<usize>(createInfo->maxAnisotropy * 0x10))); // 16:1 Anisotropy is enough resolution HashAny(static_cast<usize>(createInfo->maxAnisotropy * 0x10))); // 16:1 Anisotropy is enough resolution
hash = HashCombine(hash, HashAny(createInfo->compareEnable)); hash = HashCombine(hash, HashAny(createInfo->compareEnable));
hash = HashCombine(hash, HashAny(createInfo->compareOp)); hash = HashCombine(hash, HashAny(createInfo->compareOp));
hash = HashCombine(hash, HashAny(Cast<usize>(createInfo->minLod * 1000))); // 0.001 resolution is enough. hash = HashCombine(hash, HashAny(static_cast<usize>(createInfo->minLod * 1000))); // 0.001 resolution is enough.
hash = HashCombine(hash, hash = HashCombine(hash,
HashAny(Cast<usize>(createInfo->maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp) HashAny(static_cast<usize>(createInfo->maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp)
hash = HashCombine(hash, HashAny(createInfo->borderColor)); hash = HashCombine(hash, HashAny(createInfo->borderColor));
hash = HashCombine(hash, HashAny(createInfo->unnormalizedCoordinates)); hash = HashCombine(hash, HashAny(createInfo->unnormalizedCoordinates));
@ -253,7 +253,7 @@ SamplerManager::Create(const Device *device, const vk::SamplerCreateInfo *create
vk::Sampler sampler; vk::Sampler sampler;
AbortIfFailed(device->m_Device.createSampler(createInfo, nullptr, &sampler)); AbortIfFailed(device->m_Device.createSampler(createInfo, nullptr, &sampler));
const u32 index = Cast<u32>(m_SamplerHashes.size()); const u32 index = static_cast<u32>(m_SamplerHashes.size());
m_SamplerHashes.push_back(hash); m_SamplerHashes.push_back(hash);
m_Samplers.push_back(sampler); m_Samplers.push_back(sampler);
return {index}; return {index};
@ -293,7 +293,7 @@ VirtualizedBufferPool::InitStorage(const Device *device, usize bufferMaxSize)
const VmaVirtualBlockCreateInfo virtualBlockCreateInfo = { const VmaVirtualBlockCreateInfo virtualBlockCreateInfo = {
.size = bufferMaxSize, .size = bufferMaxSize,
}; };
AbortIfFailed(Cast<vk::Result>(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block))); AbortIfFailed(static_cast<vk::Result>(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block)));
} }
void void
@ -311,7 +311,7 @@ VirtualizedBufferPool::InitIndex(const Device *device, usize bufferMaxSize)
const VmaVirtualBlockCreateInfo virtualBlockCreateInfo = { const VmaVirtualBlockCreateInfo virtualBlockCreateInfo = {
.size = bufferMaxSize, .size = bufferMaxSize,
}; };
AbortIfFailed(Cast<vk::Result>(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block))); AbortIfFailed(static_cast<vk::Result>(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block)));
} }
void void
@ -343,11 +343,11 @@ VirtualizedBufferPool::Create(usize size, usize alignment)
index = m_FreeHead; index = m_FreeHead;
allocVBuf = &m_VirtualBuffers[index]; allocVBuf = &m_VirtualBuffers[index];
m_FreeHead = *Recast<u32 *>(allocVBuf); m_FreeHead = *reinterpret_cast<u32 *>(allocVBuf);
} }
else else
{ {
index = Cast<u32>(m_VirtualBuffers.size()); index = static_cast<u32>(m_VirtualBuffers.size());
allocVBuf = &m_VirtualBuffers.push_back(); allocVBuf = &m_VirtualBuffers.push_back();
} }
@ -374,7 +374,7 @@ VirtualizedBufferPool::Release(VirtualizedBufferHandle handle)
VirtualBuffer *virtualBuffer = &m_VirtualBuffers[handle.m_Index]; VirtualBuffer *virtualBuffer = &m_VirtualBuffers[handle.m_Index];
vmaVirtualFree(m_Block, virtualBuffer->m_Allocation); vmaVirtualFree(m_Block, virtualBuffer->m_Allocation);
*Recast<u32 *>(virtualBuffer) = m_FreeHead; *reinterpret_cast<u32 *>(virtualBuffer) = m_FreeHead;
m_FreeHead = handle.m_Index; m_FreeHead = handle.m_Index;
} }
@ -656,7 +656,7 @@ RenderResourceManager::Update()
// Descriptor Updates // Descriptor Updates
if (!m_Writes.empty()) if (!m_Writes.empty())
{ {
m_Device->m_Device.updateDescriptorSets(Cast<u32>(m_Writes.size()), m_Writes.data(), 0, nullptr); m_Device->m_Device.updateDescriptorSets(static_cast<u32>(m_Writes.size()), m_Writes.data(), 0, nullptr);
m_Writes.clear(); m_Writes.clear();
m_WriteInfos.clear(); m_WriteInfos.clear();
@ -674,10 +674,10 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u
vk::PhysicalDeviceProperties properties; vk::PhysicalDeviceProperties properties;
m_Device->m_PhysicalDevice.getProperties(&properties); m_Device->m_PhysicalDevice.getProperties(&properties);
u32 buffersCount = eastl::min(properties.limits.maxPerStageDescriptorStorageBuffers - 1024, Cast<u32>(maxSize)); u32 buffersCount = eastl::min(properties.limits.maxPerStageDescriptorStorageBuffers - 1024, static_cast<u32>(maxSize));
u32 texturesCount = eastl::min(properties.limits.maxPerStageDescriptorSampledImages - 1024, Cast<u32>(maxSize)); u32 texturesCount = eastl::min(properties.limits.maxPerStageDescriptorSampledImages - 1024, static_cast<u32>(maxSize));
u32 storageTexturesCount = u32 storageTexturesCount =
eastl::min(properties.limits.maxPerStageDescriptorStorageImages - 1024, Cast<u32>(maxSize)); eastl::min(properties.limits.maxPerStageDescriptorStorageImages - 1024, static_cast<u32>(maxSize));
INFO("Max Buffer Count: {}", buffersCount); INFO("Max Buffer Count: {}", buffersCount);
INFO("Max Texture Count: {}", texturesCount); INFO("Max Texture Count: {}", texturesCount);
@ -728,7 +728,7 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u
const vk::DescriptorPoolCreateInfo poolCreateInfo = { const vk::DescriptorPoolCreateInfo poolCreateInfo = {
.flags = vk::DescriptorPoolCreateFlagBits::eUpdateAfterBind, .flags = vk::DescriptorPoolCreateFlagBits::eUpdateAfterBind,
.maxSets = 1, .maxSets = 1,
.poolSizeCount = Cast<u32>(poolSizes.size()), .poolSizeCount = static_cast<u32>(poolSizes.size()),
.pPoolSizes = poolSizes.data(), .pPoolSizes = poolSizes.data(),
}; };
AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool)); AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool));
@ -742,7 +742,7 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u
}; };
vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = { vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = {
.bindingCount = Cast<u32>(layoutBindingFlags.size()), .bindingCount = static_cast<u32>(layoutBindingFlags.size()),
.pBindingFlags = layoutBindingFlags.data(), .pBindingFlags = layoutBindingFlags.data(),
}; };
@ -750,19 +750,19 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u
vk::DescriptorSetLayoutBinding{ vk::DescriptorSetLayoutBinding{
.binding = BUFFER_BINDING_INDEX, .binding = BUFFER_BINDING_INDEX,
.descriptorType = vk::DescriptorType::eStorageBuffer, .descriptorType = vk::DescriptorType::eStorageBuffer,
.descriptorCount = Cast<u32>(buffersCount), .descriptorCount = static_cast<u32>(buffersCount),
.stageFlags = vk::ShaderStageFlagBits::eAll, .stageFlags = vk::ShaderStageFlagBits::eAll,
}, },
vk::DescriptorSetLayoutBinding{ vk::DescriptorSetLayoutBinding{
.binding = TEXTURE_BINDING_INDEX, .binding = TEXTURE_BINDING_INDEX,
.descriptorType = vk::DescriptorType::eCombinedImageSampler, .descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = Cast<u32>(texturesCount), .descriptorCount = static_cast<u32>(texturesCount),
.stageFlags = vk::ShaderStageFlagBits::eAll, .stageFlags = vk::ShaderStageFlagBits::eAll,
}, },
vk::DescriptorSetLayoutBinding{ vk::DescriptorSetLayoutBinding{
.binding = STORAGE_TEXTURE_BINDING_INDEX, .binding = STORAGE_TEXTURE_BINDING_INDEX,
.descriptorType = vk::DescriptorType::eStorageImage, .descriptorType = vk::DescriptorType::eStorageImage,
.descriptorCount = Cast<u32>(storageTexturesCount), .descriptorCount = static_cast<u32>(storageTexturesCount),
.stageFlags = vk::ShaderStageFlagBits::eAll, .stageFlags = vk::ShaderStageFlagBits::eAll,
}, },
}; };
@ -770,7 +770,7 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u
const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {
.pNext = &bindingFlagsCreateInfo, .pNext = &bindingFlagsCreateInfo,
.flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool, .flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool,
.bindingCount = Cast<u32>(descriptorLayoutBindings.size()), .bindingCount = static_cast<u32>(descriptorLayoutBindings.size()),
.pBindings = descriptorLayoutBindings.data(), .pBindings = descriptorLayoutBindings.data(),
}; };
AbortIfFailed(device->m_Device.createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout)); AbortIfFailed(device->m_Device.createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout));
@ -960,7 +960,7 @@ RenderResourceManager::CreateIndexBuffer(usize size, usize alignment, u32 *first
u32 u32
RenderResourceManager::FetchIndex(IndexHandle handle) RenderResourceManager::FetchIndex(IndexHandle handle)
{ {
return Cast<u32>(m_Index.FetchOffset(handle) / sizeof(u32)); return static_cast<u32>(m_Index.FetchOffset(handle) / sizeof(u32));
} }
void void