From 1db942f1a94bef04ccc840a46fddf8393b1bcff3 Mon Sep 17 00:00:00 2001 From: Anish Bhobe Date: Wed, 7 May 2025 17:39:47 +0200 Subject: [PATCH] Remove Cast and Recast. --- aster/include/aster/core/buffer.h | 2 +- aster/include/aster/core/constants.h | 22 ++----- aster/include/aster/core/device.h | 2 +- aster/include/aster/core/global.h | 8 +-- aster/include/aster/core/image.h | 6 +- aster/include/aster/core/image_view.h | 2 +- aster/include/aster/systems/commit_manager.h | 4 +- aster/include/aster/systems/device.h | 10 ++-- aster/include/aster/util/freelist.h | 4 +- aster/include/aster/util/logger.h | 30 +++++----- aster/src/aster/core/buffer.cpp | 8 +-- aster/src/aster/core/device.cpp | 6 +- aster/src/aster/core/global.cpp | 8 +-- aster/src/aster/core/image.cpp | 18 +++--- aster/src/aster/core/instance.cpp | 2 +- aster/src/aster/core/surface.cpp | 4 +- aster/src/aster/core/window.cpp | 10 ++-- aster/src/aster/systems/commit_manager.cpp | 37 +++--------- aster/src/aster/systems/device.cpp | 58 +++++++++--------- samples/00_util/frame.cpp | 2 +- samples/00_util/gui.cpp | 2 +- samples/00_util/helpers.h | 6 +- samples/01_triangle/triangle.cpp | 8 +-- samples/02_box/box.cpp | 26 ++++---- samples/03_model_render/asset_loader.cpp | 52 ++++++++-------- samples/03_model_render/ibl_helpers.cpp | 8 +-- samples/03_model_render/light_manager.cpp | 18 +++--- samples/03_model_render/light_manager.h | 2 +- samples/03_model_render/model_render.cpp | 44 +++++++------- samples/03_model_render/nodes.cpp | 2 +- samples/03_model_render/pipeline_utils.cpp | 16 ++--- samples/04_scenes/asset_loader.cpp | 58 +++++++++--------- samples/04_scenes/ibl_helpers.cpp | 8 +-- samples/04_scenes/light_manager.cpp | 18 +++--- samples/04_scenes/light_manager.h | 2 +- samples/04_scenes/main.cpp | 32 +++++----- samples/04_scenes/pipeline_utils.cpp | 16 ++--- samples/04_scenes/render_resource_manager.cpp | 60 +++++++++---------- 38 files changed, 292 insertions(+), 329 deletions(-) diff --git a/aster/include/aster/core/buffer.h b/aster/include/aster/core/buffer.h index ebaeda0..f491ea3 100644 --- a/aster/include/aster/core/buffer.h +++ b/aster/include/aster/core/buffer.h @@ -106,7 +106,7 @@ concept AnyBuffer = std::derived_from; template concept BufferInto = std::derived_from and std::derived_from and - (Cast(T::FLAGS & TInto::FLAGS) or std::same_as); + (static_cast(T::FLAGS & TInto::FLAGS) or std::same_as); template concept AnyBufferRef = Deref and AnyBuffer>; diff --git a/aster/include/aster/core/constants.h b/aster/include/aster/core/constants.h index d729172..fe4b587 100644 --- a/aster/include/aster/core/constants.h +++ b/aster/include/aster/core/constants.h @@ -44,42 +44,28 @@ constexpr auto White = "\u001b[37m"; constexpr auto Reset = "\u001b[0m"; } // namespace ansi_color -template -constexpr auto -Cast(TFrom &&in) -{ - return static_cast(std::forward(in)); -} - -template -constexpr auto -Recast(TFrom &&in) -{ - return reinterpret_cast(std::forward(in)); -} - constexpr f32 operator""_deg(long double degrees) { - return glm::radians(Cast(degrees)); + return glm::radians(static_cast(degrees)); } constexpr f32 operator""_deg(unsigned long long int degrees) { - return glm::radians(Cast(degrees)); + return glm::radians(static_cast(degrees)); } constexpr f32 operator""_rad(long double rads) { - return Cast(rads); + return static_cast(rads); } constexpr f32 operator""_rad(unsigned long long int rads) { - return Cast(rads); + return static_cast(rads); } using glm::ivec2; diff --git a/aster/include/aster/core/device.h b/aster/include/aster/core/device.h index 2ba8c83..5f18d51 100644 --- a/aster/include/aster/core/device.h +++ b/aster/include/aster/core/device.h @@ -60,7 +60,7 @@ Device::SetName(const T &object, cstr name) const if (!m_ValidationEnabled || !name || !object) return; - auto handle = Recast(Cast(object)); + auto handle = reinterpret_cast(static_cast(object)); const vk::DebugUtilsObjectNameInfoEXT objectNameInfo = { .objectType = object.objectType, .objectHandle = handle, diff --git a/aster/include/aster/core/global.h b/aster/include/aster/core/global.h index c2665ba..9865316 100644 --- a/aster/include/aster/core/global.h +++ b/aster/include/aster/core/global.h @@ -59,7 +59,7 @@ constexpr u32 ASTER_API_VERSION = VK_API_VERSION_1_3; do \ { \ vk::Result _checkResultValue_; \ - ERROR_IF(Failed(_checkResultValue_ = Cast(RESULT)), "Cause: {}", _checkResultValue_) \ + ERROR_IF(Failed(_checkResultValue_ = static_cast(RESULT)), "Cause: {}", _checkResultValue_) \ THEN_ABORT(_checkResultValue_); \ } while (false) @@ -67,14 +67,14 @@ constexpr u32 ASTER_API_VERSION = VK_API_VERSION_1_3; do \ { \ vk::Result _checkResultValue_; \ - ERROR_IF(Failed(_checkResultValue_ = Cast(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \ + ERROR_IF(Failed(_checkResultValue_ = static_cast(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \ THEN_ABORT(_checkResultValue_); \ } while (false) #define AbortIfFailedM(RESULT, MSG) \ do \ { \ - auto _checkResultValue_ = Cast(RESULT); \ + auto _checkResultValue_ = static_cast(RESULT); \ ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \ } while (false) @@ -98,7 +98,7 @@ struct eastl::hash> // NOLINT(*-dcl58-cpp) [[nodiscard]] usize operator()(const vk::Flags &val) { - return std::hash()(Cast(val)); + return std::hash()(static_cast(val)); } }; diff --git a/aster/include/aster/core/image.h b/aster/include/aster/core/image.h index 66bfa37..96fc02f 100644 --- a/aster/include/aster/core/image.h +++ b/aster/include/aster/core/image.h @@ -25,13 +25,13 @@ ToExtent3D(const vk::Extent2D &extent, const u32 depth) [[nodiscard]] inline vk::Offset2D ToOffset2D(const vk::Extent3D &extent) { - return {Cast(extent.width), Cast(extent.height)}; + return {static_cast(extent.width), static_cast(extent.height)}; } [[nodiscard]] inline vk::Offset3D ToOffset3D(const vk::Extent3D &extent) { - return {Cast(extent.width), Cast(extent.height), Cast(extent.depth)}; + return {static_cast(extent.width), static_cast(extent.height), static_cast(extent.depth)}; } struct Image @@ -121,7 +121,7 @@ concept AnyImage = std::derived_from; template concept ImageInto = std::derived_from and std::derived_from and - (Cast(T::FLAGS & TInto::FLAGS) or std::same_as); + (static_cast(T::FLAGS & TInto::FLAGS) or std::same_as); template concept AnyImageRef = Deref and AnyImage>; diff --git a/aster/include/aster/core/image_view.h b/aster/include/aster/core/image_view.h index 452a8fe..8c1a32f 100644 --- a/aster/include/aster/core/image_view.h +++ b/aster/include/aster/core/image_view.h @@ -30,7 +30,7 @@ struct View [[nodiscard]] bool IsValid() const { - return Cast(m_Image); + return static_cast(m_Image); } View(Ref image, const vk::ImageView view, const vk::Extent3D extent, const u8 baseLayer, const u8 layerCount, diff --git a/aster/include/aster/systems/commit_manager.h b/aster/include/aster/systems/commit_manager.h index 99afcfb..1645e20 100644 --- a/aster/include/aster/systems/commit_manager.h +++ b/aster/include/aster/systems/commit_manager.h @@ -63,7 +63,7 @@ class CommitManager Entry * Next() { - return Recast(this->mpNext); + return reinterpret_cast(this->mpNext); } void @@ -174,7 +174,7 @@ class CommitManager u32 GetIndex(const Entry &entry) { - return Cast(&entry - m_Data.begin()); + return static_cast(&entry - m_Data.begin()); } void diff --git a/aster/include/aster/systems/device.h b/aster/include/aster/systems/device.h index c9e6cb2..1cebc2e 100644 --- a/aster/include/aster/systems/device.h +++ b/aster/include/aster/systems/device.h @@ -42,17 +42,17 @@ struct eastl::hash hash = HashCombine(hash, HashAny(createInfo.addressModeU)); hash = HashCombine(hash, HashAny(createInfo.addressModeV)); hash = HashCombine(hash, HashAny(createInfo.addressModeW)); - hash = HashCombine(hash, HashAny(Cast(createInfo.mipLodBias * 1000))); // Resolution of 10^-3 + hash = HashCombine(hash, HashAny(static_cast(createInfo.mipLodBias * 1000))); // Resolution of 10^-3 hash = HashCombine(hash, HashAny(createInfo.anisotropyEnable)); hash = HashCombine(hash, - HashAny(Cast(createInfo.maxAnisotropy * 0x20))); // 32:1 Anisotropy is enough resolution + HashAny(static_cast(createInfo.maxAnisotropy * 0x20))); // 32:1 Anisotropy is enough resolution hash = HashCombine(hash, HashAny(createInfo.compareEnable)); hash = HashCombine(hash, HashAny(createInfo.compareOp)); - hash = HashCombine(hash, HashAny(Cast(createInfo.minLod * 1000))); // 0.001 resolution is enough. + hash = HashCombine(hash, HashAny(static_cast(createInfo.minLod * 1000))); // 0.001 resolution is enough. hash = HashCombine(hash, - HashAny(Cast(createInfo.maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp) + HashAny(static_cast(createInfo.maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp) hash = HashCombine(hash, HashAny(createInfo.borderColor)); hash = HashCombine(hash, HashAny(createInfo.unnormalizedCoordinates)); @@ -334,7 +334,7 @@ enum class ShaderType constexpr static u32 ShaderTypeCount = 8; -static_assert(Cast(ShaderType::eMax) == 1 + (1 << (ShaderTypeCount - 1))); +static_assert(static_cast(ShaderType::eMax) == 1 + (1 << (ShaderTypeCount - 1))); struct ShaderInfo { diff --git a/aster/include/aster/util/freelist.h b/aster/include/aster/util/freelist.h index 7b6a47d..54aed20 100644 --- a/aster/include/aster/util/freelist.h +++ b/aster/include/aster/util/freelist.h @@ -61,7 +61,7 @@ struct FreeList Pop() { assert(m_Top); - Reference ref = *Recast(m_Top); + Reference ref = *reinterpret_cast(m_Top); m_Top = m_Top->m_Next; return ref; } @@ -69,7 +69,7 @@ struct FreeList void Push(Reference ref) { - auto next = Recast(&ref); + auto next = reinterpret_cast(&ref); next->m_Next = m_Top; m_Top = next; } diff --git a/aster/include/aster/util/logger.h b/aster/include/aster/util/logger.h index f4726f8..f5f8de5 100644 --- a/aster/include/aster/util/logger.h +++ b/aster/include/aster/util/logger.h @@ -20,12 +20,12 @@ struct Logger eVerbose, }; - u32 m_MinimumLoggingLevel{Cast(LogType::eDebug)}; + u32 m_MinimumLoggingLevel{static_cast(LogType::eDebug)}; void SetMinimumLoggingLevel(LogType logType) { - m_MinimumLoggingLevel = Cast(logType); + m_MinimumLoggingLevel = static_cast(logType); } template @@ -64,7 +64,7 @@ struct Logger void Log(const std::string_view &message, const char *loc, u32 line) const { - if (Cast(TLogLevel) <= m_MinimumLoggingLevel) + if (static_cast(TLogLevel) <= m_MinimumLoggingLevel) { fmt::println("{}{} {} {} at {}:{}{}", ToColorCstr(), ToCstr(), message.data(), ansi_color::Black, loc, line, ansi_color::Reset); @@ -81,7 +81,7 @@ struct Logger void LogCond(const char *exprStr, const std::string_view &message, const char *loc, u32 line) const { - if (Cast(TLogLevel) <= m_MinimumLoggingLevel) + if (static_cast(TLogLevel) <= m_MinimumLoggingLevel) { fmt::println("{}{} ({}) {} {} at {}:{}{}", ToColorCstr(), ToCstr(), exprStr, message.data(), ansi_color::Black, loc, line, ansi_color::Reset); @@ -103,26 +103,26 @@ extern Logger g_Logger; #define INFO(...) g_Logger.Log(fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ERROR_IF(expr, ...) \ - if (Cast(expr)) [[unlikely]] \ + if (static_cast(expr)) [[unlikely]] \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define WARN_IF(expr, ...) \ - if (Cast(expr)) [[unlikely]] \ + if (static_cast(expr)) [[unlikely]] \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define INFO_IF(expr, ...) \ - if (Cast(expr)) \ + if (static_cast(expr)) \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_IF_ERROR(expr, ...) \ ; \ - else if (Cast(expr)) \ + else if (static_cast(expr)) \ [[unlikely]] g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_IF_WARN(expr, ...) \ ; \ - else if (Cast(expr)) \ + else if (static_cast(expr)) \ [[unlikely]] g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_IF_INFO(expr, ...) \ ; \ - else if (Cast(expr)) \ + else if (static_cast(expr)) \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_ERROR(...) \ @@ -139,11 +139,11 @@ extern Logger g_Logger; #define DEBUG(...) g_Logger.Log(fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define DEBUG_IF(expr, ...) \ - if (Cast(expr)) \ + if (static_cast(expr)) \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_IF_DEBUG(expr, ...) \ ; \ - else if (Cast(expr)) \ + else if (static_cast(expr)) \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_DEBUG(...) \ ; \ @@ -174,11 +174,11 @@ extern Logger g_Logger; #define VERBOSE(...) g_Logger.Log(fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define VERBOSE_IF(expr, ...) \ - if (Cast(expr)) \ + if (static_cast(expr)) \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_IF_VERBOSE(expr, ...) \ ; \ - else if (Cast(expr)) \ + else if (static_cast(expr)) \ g_Logger.LogCond(#expr, fmt::format(__VA_ARGS__), __FILE__, __LINE__) #define ELSE_VERBOSE(...) \ ; \ @@ -207,5 +207,5 @@ extern Logger g_Logger; #endif // !defined(VERBOSE_LOG_DISABLED) #define DO(code) , code -#define ABORT(code) exit(Cast(code)) +#define ABORT(code) exit(static_cast(code)) #define THEN_ABORT(code) , ABORT(code) \ No newline at end of file diff --git a/aster/src/aster/core/buffer.cpp b/aster/src/aster/core/buffer.cpp index ebfefbc..a86569f 100644 --- a/aster/src/aster/core/buffer.cpp +++ b/aster/src/aster/core/buffer.cpp @@ -27,7 +27,7 @@ Buffer::Buffer(const Device *device, const usize size, const vk::BufferUsageFlag VkBuffer buffer; VmaAllocation allocation; VmaAllocationInfo allocationInfo; - auto result = Cast(vmaCreateBuffer(device->m_Allocator, Recast(&bufferCreateInfo), + auto result = static_cast(vmaCreateBuffer(device->m_Allocator, reinterpret_cast(&bufferCreateInfo), &allocationCreateInfo, &buffer, &allocation, &allocationInfo)); 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(&memoryPropertyFlags)); // TODO: Actually track Host Access - // bool hostAccessible = Cast(memoryPropertyFlags & vk::MemoryPropertyFlagBits::eHostVisible); + // bool hostAccessible = static_cast(memoryPropertyFlags & vk::MemoryPropertyFlagBits::eHostVisible); m_Buffer = buffer; m_Size = size; m_Allocation = allocation; - m_Mapped = Cast(allocationInfo.pMappedData); + m_Mapped = static_cast(allocationInfo.pMappedData); m_Flags = {}; if (bufferUsage & vk::BufferUsageFlagBits::eTransferSrc) 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); // TODO: Debug this. - // auto result = Cast(vmaCopyMemoryToAllocation(device->m_Allocator, &data, m_Allocation, 0, size)); + // auto result = static_cast(vmaCopyMemoryToAllocation(device->m_Allocator, &data, m_Allocation, 0, size)); // ERROR_IF(Failed(result), "Writing to buffer failed. Cause: {}", result) THEN_ABORT(result); } \ No newline at end of file diff --git a/aster/src/aster/core/device.cpp b/aster/src/aster/core/device.cpp index 4b99fe7..558b9c8 100644 --- a/aster/src/aster/core/device.cpp +++ b/aster/src/aster/core/device.cpp @@ -55,9 +55,9 @@ Device::Device(const Instance &context, PhysicalDevice &physicalDevice, Features vk::DeviceCreateInfo deviceCreateInfo = { .pNext = vulkan11Features, - .queueCreateInfoCount = Cast(deviceQueueCreateInfos.size()), + .queueCreateInfoCount = static_cast(deviceQueueCreateInfos.size()), .pQueueCreateInfos = deviceQueueCreateInfos.data(), - .enabledExtensionCount = Cast(DEVICE_EXTENSIONS.size()), + .enabledExtensionCount = static_cast(DEVICE_EXTENSIONS.size()), .ppEnabledExtensionNames = DEVICE_EXTENSIONS.data(), .pEnabledFeatures = deviceFeatures, }; @@ -83,7 +83,7 @@ Device::Device(const Instance &context, PhysicalDevice &physicalDevice, Features .vulkanApiVersion = ASTER_API_VERSION, }; - result = Cast(vmaCreateAllocator(&allocatorCreateInfo, &m_Allocator)); + result = static_cast(vmaCreateAllocator(&allocatorCreateInfo, &m_Allocator)); ERROR_IF(Failed(result), "Memory allocator creation failed. Cause: {}", result) DO(m_Device.destroy(nullptr)) THEN_ABORT(result) diff --git a/aster/src/aster/core/global.cpp b/aster/src/aster/core/global.cpp index 1009ea5..b93c0bd 100644 --- a/aster/src/aster/core/global.cpp +++ b/aster/src/aster/core/global.cpp @@ -30,7 +30,7 @@ struct MemorySize m_Kilobytes = totalKb % 1024; const usize totalMb = m_Megabytes + totalKb / 1024; m_Megabytes = totalMb % 1024; - m_Gigabytes += Cast(totalMb / 1024); + m_Gigabytes += static_cast(totalMb / 1024); return *this; } @@ -56,15 +56,15 @@ struct fmt::formatter // return format_to(ctx.out(), "({}, {})", foo.a, foo.b); // --== KEY LINE ==-- if (mem.m_Gigabytes > 0) { - return v11::format_to(ctx.out(), "{}.{} GB", mem.m_Gigabytes, Cast(mem.m_Megabytes / 1024.0)); + return v11::format_to(ctx.out(), "{}.{} GB", mem.m_Gigabytes, static_cast(mem.m_Megabytes / 1024.0)); } if (mem.m_Megabytes > 0) { - return v11::format_to(ctx.out(), "{}.{} MB", mem.m_Megabytes, Cast(mem.m_Kilobytes / 1024.0)); + return v11::format_to(ctx.out(), "{}.{} MB", mem.m_Megabytes, static_cast(mem.m_Kilobytes / 1024.0)); } if (mem.m_Kilobytes > 0) { - return v11::format_to(ctx.out(), "{}.{} KB", mem.m_Kilobytes, Cast(mem.m_Bytes / 1024.0)); + return v11::format_to(ctx.out(), "{}.{} KB", mem.m_Kilobytes, static_cast(mem.m_Bytes / 1024.0)); } return v11::format_to(ctx.out(), "{} Bytes", mem.m_Bytes); diff --git a/aster/src/aster/core/image.cpp b/aster/src/aster/core/image.cpp index d78410f..86d4c82 100644 --- a/aster/src/aster/core/image.cpp +++ b/aster/src/aster/core/image.cpp @@ -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)", // extent.width, extent.height, name ? name : ""); // -// const u8 mipLevels = isMipMapped ? 1 + Cast(floor(log2(eastl::max(extent.width, extent.height)))) : 1; +// const u8 mipLevels = isMipMapped ? 1 + static_cast(floor(log2(eastl::max(extent.width, extent.height)))) : 1; // // auto usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst; // if (isMipMapped) @@ -75,7 +75,7 @@ Image::DestroyView(const vk::ImageView imageView) const // // VkImage image; // VmaAllocation allocation; -// auto result = Cast(vmaCreateImage(device->m_Allocator, Recast(&imageCreateInfo), +// auto result = static_cast(vmaCreateImage(device->m_Allocator, reinterpret_cast(&imageCreateInfo), // &allocationCreateInfo, &image, &allocation, nullptr)); // 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, // name ? name : ""); // -// const u8 mipLevels = isMipMapped ? 1 + Cast(floor(log2(cubeSide))) : 1; +// const u8 mipLevels = isMipMapped ? 1 + static_cast(floor(log2(cubeSide))) : 1; // // auto usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst; // if (isMipMapped) @@ -162,7 +162,7 @@ Image::DestroyView(const vk::ImageView imageView) const // // VkImage image; // VmaAllocation allocation; -// auto result = Cast(vmaCreateImage(device->m_Allocator, Recast(&imageCreateInfo), +// auto result = static_cast(vmaCreateImage(device->m_Allocator, reinterpret_cast(&imageCreateInfo), // &allocationCreateInfo, &image, &allocation, nullptr)); // 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; // VmaAllocation allocation; -// auto result = Cast(vmaCreateImage(device->m_Allocator, Recast(&imageCreateInfo), +// auto result = static_cast(vmaCreateImage(device->m_Allocator, reinterpret_cast(&imageCreateInfo), // &allocationCreateInfo, &image, &allocation, nullptr)); // 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; // VmaAllocation allocation; -// auto result = Cast(vmaCreateImage(device->m_Allocator, Recast(&imageCreateInfo), +// auto result = static_cast(vmaCreateImage(device->m_Allocator, reinterpret_cast(&imageCreateInfo), // &allocationCreateInfo, &image, &allocation, nullptr)); // 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; // VmaAllocation allocation; -// auto result = Cast(vmaCreateImage(device->m_Allocator, Recast(&imageCreateInfo), +// auto result = static_cast(vmaCreateImage(device->m_Allocator, reinterpret_cast(&imageCreateInfo), // &allocationCreateInfo, &image, &allocation, nullptr)); // 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; // } // -// const u8 mipLevels = isMipMapped ? 1 + Cast(floor(log2(cubeSide))) : 1; +// const u8 mipLevels = isMipMapped ? 1 + static_cast(floor(log2(cubeSide))) : 1; // // vk::ImageCreateInfo imageCreateInfo = { // .flags = vk::ImageCreateFlagBits::eCubeCompatible, @@ -417,7 +417,7 @@ Image::DestroyView(const vk::ImageView imageView) const // // VkImage image; // VmaAllocation allocation; -// auto result = Cast(vmaCreateImage(device->m_Allocator, Recast(&imageCreateInfo), +// auto result = static_cast(vmaCreateImage(device->m_Allocator, reinterpret_cast(&imageCreateInfo), // &allocationCreateInfo, &image, &allocation, nullptr)); // ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", name, result) THEN_ABORT(result); // diff --git a/aster/src/aster/core/instance.cpp b/aster/src/aster/core/instance.cpp index 5659d50..66ae6c4 100644 --- a/aster/src/aster/core/instance.cpp +++ b/aster/src/aster/core/instance.cpp @@ -75,7 +75,7 @@ Instance::Instance(const cstr appName, const Version version, bool enableValidat const auto instanceCreateInfo = vk::InstanceCreateInfo{ .pNext = enableValidation ? &debugUtilsMessengerCreateInfo : nullptr, .pApplicationInfo = &appInfo, - .enabledExtensionCount = Cast(instanceExtensions.size()), + .enabledExtensionCount = static_cast(instanceExtensions.size()), .ppEnabledExtensionNames = instanceExtensions.data(), }; diff --git a/aster/src/aster/core/surface.cpp b/aster/src/aster/core/surface.cpp index daa39a2..da49170 100644 --- a/aster/src/aster/core/surface.cpp +++ b/aster/src/aster/core/surface.cpp @@ -12,8 +12,8 @@ Surface::Surface(Instance &context, const Window &window) : m_Context(&context) { VkSurfaceKHR surface; - auto result = Cast( - glfwCreateWindowSurface(Cast(m_Context->m_Instance), window.m_Window, nullptr, &surface)); + auto result = static_cast( + glfwCreateWindowSurface(static_cast(m_Context->m_Instance), window.m_Window, nullptr, &surface)); ERROR_IF(Failed(result), "Failed to create Surface with {}", result) THEN_ABORT(result) ELSE_DEBUG("Surface {} Created", m_Name); diff --git a/aster/src/aster/core/window.cpp b/aster/src/aster/core/window.cpp index f4beea3..b519f78 100644 --- a/aster/src/aster/core/window.cpp +++ b/aster/src/aster/core/window.cpp @@ -50,7 +50,7 @@ Window::SetWindowSize(const vk::Extent2D &extent) const noexcept void Window::SetWindowSize(const u32 width, const u32 height) const noexcept { - glfwSetWindowSize(m_Window, Cast(width), Cast(height)); + glfwSetWindowSize(m_Window, static_cast(width), static_cast(height)); } Size2D @@ -59,7 +59,7 @@ Window::GetSize() const int width; int height; glfwGetFramebufferSize(m_Window, &width, &height); - return {Cast(width), Cast(height)}; + return {static_cast(width), static_cast(height)}; } 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_CENTER_CURSOR, GLFW_TRUE); - m_Window = glfwCreateWindow(Cast(extent.m_Width), Cast(extent.m_Height), m_Name.c_str(), + m_Window = glfwCreateWindow(static_cast(extent.m_Width), static_cast(extent.m_Height), m_Name.c_str(), isFullScreen ? monitor : nullptr, nullptr); ERROR_IF(m_Window == nullptr, "Window creation failed") ELSE_DEBUG("Window '{}' created with resolution '{}x{}'", m_Name, extent.m_Width, extent.m_Height); @@ -91,8 +91,8 @@ Window::Window(const cstr title, Size2D extent, const b8 isFullScreen) if (isFullScreen == false) { - glfwSetWindowPos(m_Window, Cast(windowWidth - extent.m_Width) / 2, - Cast(windowHeight - extent.m_Height) / 2); + glfwSetWindowPos(m_Window, static_cast(windowWidth - extent.m_Width) / 2, + static_cast(windowHeight - extent.m_Height) / 2); } glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); diff --git a/aster/src/aster/systems/commit_manager.cpp b/aster/src/aster/systems/commit_manager.cpp index 09d6421..0141214 100644 --- a/aster/src/aster/systems/commit_manager.cpp +++ b/aster/src/aster/systems/commit_manager.cpp @@ -9,29 +9,6 @@ #include "core/device.h" #include "core/image_view.h" -#define AbortIfFailed(RESULT) \ - do \ - { \ - vk::Result _checkResultValue_; \ - ERROR_IF(Failed(_checkResultValue_ = Cast(RESULT)), "Cause: {}", _checkResultValue_) \ - THEN_ABORT(_checkResultValue_); \ - } while (false) - -#define AbortIfFailedMV(RESULT, MSG, EXTRA) \ - do \ - { \ - vk::Result _checkResultValue_; \ - ERROR_IF(Failed(_checkResultValue_ = Cast(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \ - THEN_ABORT(_checkResultValue_); \ - } while (false) - -#define AbortIfFailedM(RESULT, MSG) \ - do \ - { \ - auto _checkResultValue_ = Cast(RESULT); \ - ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \ - } while (false) - using namespace systems; CommitManager *CommitManager::m_Instance = nullptr; @@ -64,7 +41,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u const vk::DescriptorPoolCreateInfo poolCreateInfo = { .flags = vk::DescriptorPoolCreateFlagBits::eUpdateAfterBind, .maxSets = 1, - .poolSizeCount = Cast(poolSizes.size()), + .poolSizeCount = static_cast(poolSizes.size()), .pPoolSizes = poolSizes.data(), }; 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{ .binding = BUFFER_BINDING_INDEX, .descriptorType = vk::DescriptorType::eStorageBuffer, - .descriptorCount = Cast(maxBuffers), + .descriptorCount = static_cast(maxBuffers), .stageFlags = vk::ShaderStageFlagBits::eAll, }, vk::DescriptorSetLayoutBinding{ .binding = IMAGE_BINDING_INDEX, .descriptorType = vk::DescriptorType::eCombinedImageSampler, - .descriptorCount = Cast(maxImages), + .descriptorCount = static_cast(maxImages), .stageFlags = vk::ShaderStageFlagBits::eAll, }, vk::DescriptorSetLayoutBinding{ .binding = STORAGE_IMAGE_BINDING_INDEX, .descriptorType = vk::DescriptorType::eStorageImage, - .descriptorCount = Cast(maxStorageImages), + .descriptorCount = static_cast(maxStorageImages), .stageFlags = vk::ShaderStageFlagBits::eAll, }, }; @@ -97,7 +74,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u layoutBindingFlags.fill(bindingFlags); vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = { - .bindingCount = Cast(layoutBindingFlags.size()), + .bindingCount = static_cast(layoutBindingFlags.size()), .pBindingFlags = layoutBindingFlags.data(), }; @@ -105,7 +82,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { .pNext = &bindingFlagsCreateInfo, .flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool, - .bindingCount = Cast(descriptorLayoutBindings.size()), + .bindingCount = static_cast(descriptorLayoutBindings.size()), .pBindings = descriptorLayoutBindings.data(), }; AbortIfFailed(device->m_Device.createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout)); @@ -250,7 +227,7 @@ CommitManager::Update() // Descriptor Updates if (!m_Writes.empty()) { - m_Device->m_Device.updateDescriptorSets(Cast(m_Writes.size()), m_Writes.data(), 0, nullptr); + m_Device->m_Device.updateDescriptorSets(static_cast(m_Writes.size()), m_Writes.data(), 0, nullptr); m_Writes.clear(); m_WriteInfos.clear(); diff --git a/aster/src/aster/systems/device.cpp b/aster/src/aster/systems/device.cpp index dcecad4..8ffa063 100644 --- a/aster/src/aster/systems/device.cpp +++ b/aster/src/aster/systems/device.cpp @@ -125,14 +125,14 @@ systems::Device::CreateTexture2D(const Texture2DCreateInfo &createInfo) VkImage rawImage; VmaAllocation allocation; vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); - auto result = Cast(vmaCreateImage(m_Device.m_Allocator, Recast(&imageCreateInfo), + auto result = static_cast(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast(&imageCreateInfo), &allocationCreateInfo, &rawImage, &allocation, nullptr)); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); vk::Image image = rawImage; - u8 layerCount = Cast(imageCreateInfo.arrayLayers); - u8 mipLevels = Cast(imageCreateInfo.mipLevels); + u8 layerCount = static_cast(imageCreateInfo.arrayLayers); + u8 mipLevels = static_cast(imageCreateInfo.mipLevels); Image::Flags flags = {}; if (createInfo.m_IsSampled) flags |= Image::FlagBits::eSampled; @@ -156,14 +156,14 @@ systems::Device::CreateTextureCube(const TextureCubeCreateInfo &createInfo) VkImage rawImage; VmaAllocation allocation; vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); - auto result = Cast(vmaCreateImage(m_Device.m_Allocator, Recast(&imageCreateInfo), + auto result = static_cast(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast(&imageCreateInfo), &allocationCreateInfo, &rawImage, &allocation, nullptr)); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); vk::Image image = rawImage; - u8 layerCount = Cast(imageCreateInfo.arrayLayers); - u8 mipLevels = Cast(imageCreateInfo.mipLevels); + u8 layerCount = static_cast(imageCreateInfo.arrayLayers); + u8 mipLevels = static_cast(imageCreateInfo.mipLevels); Image::Flags flags = Image::FlagBits::eCube; if (createInfo.m_IsSampled) flags |= Image::FlagBits::eSampled; @@ -187,14 +187,14 @@ systems::Device::CreateAttachment(const AttachmentCreateInfo &createInfo) VkImage rawImage; VmaAllocation allocation; vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); - auto result = Cast(vmaCreateImage(m_Device.m_Allocator, Recast(&imageCreateInfo), + auto result = static_cast(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast(&imageCreateInfo), &allocationCreateInfo, &rawImage, &allocation, nullptr)); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); vk::Image image = rawImage; - u8 layerCount = Cast(imageCreateInfo.arrayLayers); - u8 mipLevels = Cast(imageCreateInfo.mipLevels); + u8 layerCount = static_cast(imageCreateInfo.arrayLayers); + u8 mipLevels = static_cast(imageCreateInfo.mipLevels); m_Device.SetName(image, createInfo.m_Name); @@ -213,14 +213,14 @@ systems::Device::CreateDepthStencilImage(const DepthStencilImageCreateInfo &crea VkImage rawImage; VmaAllocation allocation; vk::ImageCreateInfo imageCreateInfo = ToImageCreateInfo(createInfo); - auto result = Cast(vmaCreateImage(m_Device.m_Allocator, Recast(&imageCreateInfo), + auto result = static_cast(vmaCreateImage(m_Device.m_Allocator, reinterpret_cast(&imageCreateInfo), &allocationCreateInfo, &rawImage, &allocation, nullptr)); ERROR_IF(Failed(result), "Could not allocate image {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); vk::Image image = rawImage; - u8 layerCount = Cast(imageCreateInfo.arrayLayers); - u8 mipLevels = Cast(imageCreateInfo.mipLevels); + u8 layerCount = static_cast(imageCreateInfo.arrayLayers); + u8 mipLevels = static_cast(imageCreateInfo.mipLevels); 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)", extent.width, extent.height, name ? name : ""); - const u8 mipLevels = isMipMapped ? 1 + Cast(floor(log2(eastl::max(extent.width, extent.height)))) : 1; + const u8 mipLevels = isMipMapped ? 1 + static_cast(floor(log2(eastl::max(extent.width, extent.height)))) : 1; auto usage = vk::ImageUsageFlags{}; 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 : ""); - const u8 mipLevels = isMipMapped ? 1 + Cast(floor(log2(side))) : 1; + const u8 mipLevels = isMipMapped ? 1 + static_cast(floor(log2(side))) : 1; auto usage = vk::ImageUsageFlags{}; if (isSampled) @@ -336,7 +336,7 @@ systems::Device::CreateView(const ViewCreateInfo &createInfo) THEN_ABORT(-1); vk::ImageView view; - const auto imageViewCreateInfo = Cast(createInfo); + const auto imageViewCreateInfo = static_cast(createInfo); auto result = m_Device.m_Device.createImageView(&imageViewCreateInfo, nullptr, &view); ERROR_IF(Failed(result), "Could not create image view {}. Cause: {}", createInfo.m_Name, result) THEN_ABORT(result); @@ -406,7 +406,7 @@ systems::Device::CreateDepthStencilImageWithView(const DepthStencilImageCreateIn Ref systems::Device::CreateSampler(const SamplerCreateInfo &createInfo) { - auto vkCreateInfo = Cast(createInfo); + auto vkCreateInfo = static_cast(createInfo); if (const auto iter = m_HashToSamplerIdx.find(vkCreateInfo); iter != m_HashToSamplerIdx.end() && !iter->second.expired()) @@ -460,9 +460,9 @@ systems::Device::CreatePipeline(Pipeline &pipelineOut, const GraphicsPipelineCre } vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = { - .vertexBindingDescriptionCount = Cast(inputBindingDescriptions.size()), + .vertexBindingDescriptionCount = static_cast(inputBindingDescriptions.size()), .pVertexBindingDescriptions = inputBindingDescriptions.data(), - .vertexAttributeDescriptionCount = Cast(inputAttributeDescriptions.size()), + .vertexAttributeDescriptionCount = static_cast(inputAttributeDescriptions.size()), .pVertexAttributeDescriptions = inputAttributeDescriptions.data(), }; vk::PipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = { @@ -515,7 +515,7 @@ systems::Device::CreatePipeline(Pipeline &pipelineOut, const GraphicsPipelineCre }; vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { - .dynamicStateCount = Cast(dynamicStates.size()), + .dynamicStateCount = static_cast(dynamicStates.size()), .pDynamicStates = dynamicStates.data(), }; @@ -527,7 +527,7 @@ systems::Device::CreatePipeline(Pipeline &pipelineOut, const GraphicsPipelineCre vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { .pNext = &renderingCreateInfo, - .stageCount = Cast(shaders.size()), + .stageCount = static_cast(shaders.size()), .pStages = shaders.data(), .pVertexInputState = &vertexInputStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo, @@ -636,7 +636,7 @@ systems::Device::CreateShaders( shaderModule = m_SlangSession->loadModule(shaderInfo.m_ShaderFile.data(), shaderDiagnostics.writeRef()); if (shaderDiagnostics) { - ERROR("{}", Cast(shaderDiagnostics->getBufferPointer())); + ERROR("{}", static_cast(shaderDiagnostics->getBufferPointer())); return SLANG_FAIL; } @@ -650,7 +650,7 @@ systems::Device::CreateShaders( slang::ProgramLayout *entryProgramLayout = actualEntryPoint->getLayout(0, shaderDiagnostics.writeRef()); if (shaderDiagnostics) { - ERROR("{}", Cast(shaderDiagnostics->getBufferPointer())); + ERROR("{}", static_cast(shaderDiagnostics->getBufferPointer())); return SLANG_FAIL; } switch (entryProgramLayout->getEntryPointByIndex(0)->getStage()) @@ -709,7 +709,7 @@ systems::Device::CreateShaders( } ComPtr pipelineComposite; - auto slangResult = m_SlangSession->createCompositeComponentType(components.data(), Cast(components.size()), + auto slangResult = m_SlangSession->createCompositeComponentType(components.data(), static_cast(components.size()), pipelineComposite.writeRef()); if (slangResult < 0) @@ -721,7 +721,7 @@ systems::Device::CreateShaders( if (slangResult < 0) { - ERROR("{}", Cast(shaderDiagnostics->getBufferPointer())); + ERROR("{}", static_cast(shaderDiagnostics->getBufferPointer())); return slangResult; } @@ -734,7 +734,7 @@ systems::Device::CreateShaders( slangResult = program->getEntryPointCode(entryPoint, 0, kernelCode.writeRef(), shaderDiagnostics.writeRef()); if (slangResult < 0) { - ERROR("{}", Cast(shaderDiagnostics->getBufferPointer())); + ERROR("{}", static_cast(shaderDiagnostics->getBufferPointer())); return slangResult; } @@ -749,7 +749,7 @@ systems::Device::CreateShaders( const vk::ShaderModuleCreateInfo shaderModuleCreateInfo = { .codeSize = kernelCode->getBufferSize(), - .pCode = Cast(kernelCode->getBufferPointer()), + .pCode = static_cast(kernelCode->getBufferPointer()), }; 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()); if (layoutDiagnostics) { - ERROR_IF(!layout, "{}", Cast(layoutDiagnostics->getBufferPointer())); + ERROR_IF(!layout, "{}", static_cast(layoutDiagnostics->getBufferPointer())); return SLANG_FAIL; } @@ -869,7 +869,7 @@ systems::Device::Device(const DeviceCreateInfo &createInfo) .targets = &spirvTargetDesc, .targetCount = 1, .searchPaths = createInfo.m_ShaderSearchPaths.data(), - .searchPathCount = Cast(createInfo.m_ShaderSearchPaths.size()), + .searchPathCount = static_cast(createInfo.m_ShaderSearchPaths.size()), }; result = m_GlobalSlangSession->createSession(sessionDesc, m_SlangSession.writeRef()); 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; NameString name = "Frame "; - name += Cast(frameIndex + '0'); + name += static_cast(frameIndex + '0'); const vk::CommandPoolCreateInfo commandPoolCreateInfo = { .flags = vk::CommandPoolCreateFlagBits::eTransient, diff --git a/samples/00_util/frame.cpp b/samples/00_util/frame.cpp index 913e8ad..5e93df6 100644 --- a/samples/00_util/frame.cpp +++ b/samples/00_util/frame.cpp @@ -17,7 +17,7 @@ Frame::Frame(const Device *device, const u32 queueFamilyIndex, const u32 frameCo m_Device = device; eastl::fixed_string name = "Frame "; - name += Cast('0' + frameCount); + name += static_cast('0' + frameCount); const vk::CommandPoolCreateInfo commandPoolCreateInfo = { .flags = vk::CommandPoolCreateFlagBits::eTransient, .queueFamilyIndex = queueFamilyIndex, diff --git a/samples/00_util/gui.cpp b/samples/00_util/gui.cpp index 8d64729..e94a880 100644 --- a/samples/00_util/gui.cpp +++ b/samples/00_util/gui.cpp @@ -48,7 +48,7 @@ Init(const Instance *context, const Device *device, const Window *window, vk::Fo const vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = { .flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, .maxSets = 1000, - .poolSizeCount = Cast(poolSizes.size()), + .poolSizeCount = static_cast(poolSizes.size()), .pPoolSizes = poolSizes.data(), }; diff --git a/samples/00_util/helpers.h b/samples/00_util/helpers.h index 3471a02..0ef08ed 100644 --- a/samples/00_util/helpers.h +++ b/samples/00_util/helpers.h @@ -26,7 +26,7 @@ using StackString = eastl::fixed_string; do \ { \ vk::Result _checkResultValue_; \ - ERROR_IF(Failed(_checkResultValue_ = Cast(RESULT)), "Cause: {}", _checkResultValue_) \ + ERROR_IF(Failed(_checkResultValue_ = static_cast(RESULT)), "Cause: {}", _checkResultValue_) \ THEN_ABORT(_checkResultValue_); \ } while (false) @@ -34,13 +34,13 @@ using StackString = eastl::fixed_string; do \ { \ vk::Result _checkResultValue_; \ - ERROR_IF(Failed(_checkResultValue_ = Cast(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \ + ERROR_IF(Failed(_checkResultValue_ = static_cast(RESULT)), MSG " Cause: {}", EXTRA, _checkResultValue_) \ THEN_ABORT(_checkResultValue_); \ } while (false) #define AbortIfFailedM(RESULT, MSG) \ do \ { \ - auto _checkResultValue_ = Cast(RESULT); \ + auto _checkResultValue_ = static_cast(RESULT); \ ERROR_IF(Failed(_checkResultValue_), MSG " Cause: {}", _checkResultValue_) THEN_ABORT(_checkResultValue_); \ } while (false) \ No newline at end of file diff --git a/samples/01_triangle/triangle.cpp b/samples/01_triangle/triangle.cpp index 1bfb6fd..55ceb94 100644 --- a/samples/01_triangle/triangle.cpp +++ b/samples/01_triangle/triangle.cpp @@ -133,16 +133,16 @@ main(int, char **) vk::Viewport viewport = { .x = 0, - .y = Cast(swapchainSize.m_Height), - .width = Cast(swapchainSize.m_Width), - .height = -Cast(swapchainSize.m_Height), + .y = static_cast(swapchainSize.m_Height), + .width = static_cast(swapchainSize.m_Width), + .height = -static_cast(swapchainSize.m_Height), .minDepth = 0.0, .maxDepth = 1.0, }; vk::Rect2D scissor = { .offset = {0, 0}, - .extent = Cast(swapchainSize), + .extent = static_cast(swapchainSize), }; auto context = currentFrame.CreateGraphicsContext(); diff --git a/samples/02_box/box.cpp b/samples/02_box/box.cpp index e4791de..9e4311b 100644 --- a/samples/02_box/box.cpp +++ b/samples/02_box/box.cpp @@ -66,7 +66,7 @@ ImageFile::Load(cstr fileName) usize ImageFile::GetSize() const { - return Cast(m_Width) * m_Height * m_NumChannels; + return static_cast(m_Width) * m_Height * m_NumChannels; } ImageFile::~ImageFile() @@ -141,7 +141,7 @@ main(int, char **) .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_Perspective = glm::perspective( - 70_deg, Cast(swapchain.m_Extent.width) / Cast(swapchain.m_Extent.height), 0.1f, 100.0f), + 70_deg, static_cast(swapchain.m_Extent.width) / static_cast(swapchain.m_Extent.height), 0.1f, 100.0f), }; vk::CommandPool copyPool; @@ -325,9 +325,9 @@ main(int, char **) // Persistent variables vk::Viewport viewport = { .x = 0, - .y = Cast(swapchain.m_Extent.height), - .width = Cast(swapchain.m_Extent.width), - .height = -Cast(swapchain.m_Extent.height), + .y = static_cast(swapchain.m_Extent.height), + .width = static_cast(swapchain.m_Extent.width), + .height = -static_cast(swapchain.m_Extent.height), .minDepth = 0.0, .maxDepth = 1.0, }; @@ -338,9 +338,9 @@ main(int, char **) }; auto resizeViewportScissor = [&viewport, &scissor](vk::Extent2D extent) { - viewport.y = Cast(extent.height); - viewport.width = Cast(extent.width); - viewport.height = -Cast(extent.height); + viewport.y = static_cast(extent.height); + viewport.width = static_cast(extent.width); + viewport.height = -static_cast(extent.height); scissor.extent = extent; }; swapchain.RegisterResizeCallback(resizeViewportScissor); @@ -425,7 +425,7 @@ main(int, char **) Time::Update(); commitManager.Update(); - camera.m_Model *= rotate(mat4{1.0f}, Cast(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f)); + camera.m_Model *= rotate(mat4{1.0f}, static_cast(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f)); ubo->Write(0, sizeof camera, &camera); Frame *currentFrame = frameManager.GetNextFrame(&swapchain, &surface, window.GetSize()); @@ -468,7 +468,7 @@ main(int, char **) vk::RenderingInfo renderingInfo = { .renderArea = {.extent = swapchain.m_Extent}, .layerCount = 1, - .colorAttachmentCount = Cast(attachmentInfos.size()), + .colorAttachmentCount = static_cast(attachmentInfos.size()), .pColorAttachments = attachmentInfos.data(), .pDepthAttachment = &depthAttachment, }; @@ -481,7 +481,7 @@ main(int, char **) cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1, &commitManager.GetDescriptorSet(), 0, nullptr); cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAllGraphics, 0, 12, &pcb); - cmd.draw(Cast(vertices.size()), 1, 0, 0); + cmd.draw(static_cast(vertices.size()), 1, 0, 0); cmd.endRendering(); @@ -600,7 +600,7 @@ CreatePipeline(const systems::CommitManager *resourceManager, const Swapchain *s }; vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { - .dynamicStateCount = Cast(dynamicStates.size()), + .dynamicStateCount = static_cast(dynamicStates.size()), .pDynamicStates = dynamicStates.data(), }; @@ -613,7 +613,7 @@ CreatePipeline(const systems::CommitManager *resourceManager, const Swapchain *s vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { .pNext = &renderingCreateInfo, - .stageCount = Cast(shaderStages.size()), + .stageCount = static_cast(shaderStages.size()), .pStages = shaderStages.data(), .pVertexInputState = &vertexInputStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo, diff --git a/samples/03_model_render/asset_loader.cpp b/samples/03_model_render/asset_loader.cpp index 7f0e6a2..6bdf686 100644 --- a/samples/03_model_render/asset_loader.cpp +++ b/samples/03_model_render/asset_loader.cpp @@ -62,8 +62,8 @@ AssetLoader::LoadHdrImage(cstr path, cstr name) const ERROR_IF(!data, "Could not load {}", path) THEN_ABORT(-1); - u32 width = Cast(x); - u32 height = Cast(y); + u32 width = static_cast(x); + u32 height = static_cast(y); auto texture = m_ResourceManager->CombinedImageViews().CreateTexture2D({ .m_Format = vk::Format::eR32G32B32A32Sfloat, @@ -248,7 +248,7 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, const Ref &texture, vk } vk::DependencyInfo imageStartDependency = { - .imageMemoryBarrierCount = Cast(startBarriers.size()), + .imageMemoryBarrierCount = static_cast(startBarriers.size()), .pImageMemoryBarriers = startBarriers.data(), }; @@ -331,8 +331,8 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, const Ref &texture, vk commandBuffer.pipelineBarrier2(&imageStartDependency); - i32 prevMipWidth = Cast(texture->m_Extent.width); - i32 prevMipHeight = Cast(texture->m_Extent.height); + i32 prevMipWidth = static_cast(texture->m_Extent.width); + i32 prevMipHeight = static_cast(texture->m_Extent.height); u32 maxPrevMip = texture->GetMipLevels() - 1; for (u32 prevMipLevel = 0; prevMipLevel < maxPrevMip; ++prevMipLevel) @@ -382,8 +382,8 @@ AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name) cons #endif - u32 height = Cast(image->height); - u32 width = Cast(image->width); + u32 height = static_cast(image->height); + u32 width = static_cast(image->width); 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 = { .bufferOffset = 0, - .bufferRowLength = Cast(image->width), - .bufferImageHeight = Cast(image->height), + .bufferRowLength = static_cast(image->width), + .bufferImageHeight = static_cast(image->height), .imageSubresource = { .aspectMask = vk::ImageAspectFlagBits::eColor, @@ -583,8 +583,8 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) materials.push_back({ .m_AlbedoFactor = VectorToVec4(material.pbrMetallicRoughness.baseColorFactor), .m_EmissionFactor = VectorToVec3(material.emissiveFactor), - .m_MetalFactor = Cast(material.pbrMetallicRoughness.metallicFactor), - .m_RoughFactor = Cast(material.pbrMetallicRoughness.roughnessFactor), + .m_MetalFactor = static_cast(material.pbrMetallicRoughness.metallicFactor), + .m_RoughFactor = static_cast(material.pbrMetallicRoughness.roughnessFactor), .m_AlbedoTex = getTextureHandle(material.pbrMetallicRoughness.baseColorTexture.index, true), .m_NormalTex = getTextureHandle(material.normalTexture.index, false), .m_MetalRoughTex = @@ -643,17 +643,17 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) tinygltf::Buffer *posBuffer = &model.buffers[posBufferView->buffer]; usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset); - vertexCount = Cast(posAccessor->count); + vertexCount = static_cast(posAccessor->count); vertexPositions.reserve(vertexOffset + vertexCount); if (posAccessor->type == TINYGLTF_TYPE_VEC4) { - auto data = Recast(posBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(posBuffer->data.data() + byteOffset); vertexPositions.insert(vertexPositions.end(), data, data + vertexCount); } else if (posAccessor->type == TINYGLTF_TYPE_VEC3) { - auto data = Recast(posBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(posBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { 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) { - auto data = Recast(posBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(posBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { 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) { - auto data = Recast(normBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(normBuffer->data.data() + byteOffset); vec4 *end = data + vertexCount; u32 idx = vertexOffset; @@ -697,7 +697,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) } else if (normAccessor->type == TINYGLTF_TYPE_VEC3) { - auto data = Recast(normBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(normBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { auto norm = vec4(data[i], 0.0f); @@ -706,7 +706,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) } else if (normAccessor->type == TINYGLTF_TYPE_VEC2) { - auto data = Recast(normBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(normBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { 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 && uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); { - auto data = Recast(uvBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(uvBuffer->data.data() + byteOffset); vec2 *end = data + vertexCount; u32 idx = vertexOffset; vec2 *it = data; @@ -752,7 +752,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) if (colorAccessor->type == TINYGLTF_TYPE_VEC4) { - auto data = Recast(colorBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(colorBuffer->data.data() + byteOffset); vec4 *end = data + vertexCount; u32 idx = vertexOffset; @@ -764,7 +764,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) } else if (colorAccessor->type == TINYGLTF_TYPE_VEC3) { - auto data = Recast(colorBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(colorBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { auto color = vec4(data[i], 1.0f); @@ -785,22 +785,22 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) tinygltf::Buffer *indexBuffer = &model.buffers[indexBufferView->buffer]; usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset); - indexCount = Cast(indexAccessor->count); + indexCount = static_cast(indexAccessor->count); indices.reserve(indexOffset + indexCount); if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT) { - auto data = Recast(indexBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(indexBuffer->data.data() + byteOffset); indices.insert(indices.end(), data, data + indexCount); } else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) { - auto data = Recast(indexBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(indexBuffer->data.data() + byteOffset); indices.insert(indices.end(), data, data + indexCount); } else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE) { - auto data = Recast(indexBuffer->data.data() + byteOffset); + auto data = reinterpret_cast(indexBuffer->data.data() + byteOffset); 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) * scale(mat4(1.0f), nodeScale) * nodeMatrix; - const i32 nodeArrayIndex = Cast(nodes.Add(transform, parent)); + const i32 nodeArrayIndex = static_cast(nodes.Add(transform, parent)); if (node->mesh >= 0) { auto [start, count] = meshPrimRanges[node->mesh]; diff --git a/samples/03_model_render/ibl_helpers.cpp b/samples/03_model_render/ibl_helpers.cpp index 1414a5f..04bbd9c 100644 --- a/samples/03_model_render/ibl_helpers.cpp +++ b/samples/03_model_render/ibl_helpers.cpp @@ -132,7 +132,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 readyToWriteBarriers[3].subresourceRange = lutSubresRange; vk::DependencyInfo readyToWriteDependency = { - .imageMemoryBarrierCount = Cast(readyToWriteBarriers.size()), + .imageMemoryBarrierCount = static_cast(readyToWriteBarriers.size()), .pImageMemoryBarriers = readyToWriteBarriers.data(), }; @@ -209,7 +209,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 .stageFlags = vk::ShaderStageFlagBits::eCompute, .offset = 0, .size = - Cast(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)), + static_cast(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)), eastl::max(sizeof(DiffuseIrradiancePushConstants), sizeof(PrefilterPushConstants)))), }; @@ -267,7 +267,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 eastl::array pipelines; AbortIfFailed( - pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, Cast(computePipelineCreateInfo.size()), + pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, static_cast(computePipelineCreateInfo.size()), computePipelineCreateInfo.data(), nullptr, pipelines.data())); vk::Pipeline eqRectToCubePipeline = pipelines[0]; @@ -345,7 +345,7 @@ CreateCubeFromHdrEnv(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 { prefilterPushConstants.m_OutputTexture = tex; prefilterPushConstants.m_CubeSide = mipSize; - prefilterPushConstants.m_Roughness = Cast(mipCount) / Cast(prefilterMipCountMax - 1); + prefilterPushConstants.m_Roughness = static_cast(mipCount) / static_cast(prefilterMipCountMax - 1); cmd.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eCompute, 0, sizeof prefilterPushConstants, &prefilterPushConstants); u32 groupCount = eastl::max(mipSize / 16u, 1u); diff --git a/samples/03_model_render/light_manager.cpp b/samples/03_model_render/light_manager.cpp index 7321d41..d04dc40 100644 --- a/samples/03_model_render/light_manager.cpp +++ b/samples/03_model_render/light_manager.cpp @@ -36,10 +36,10 @@ static_assert(Light::COLOR_MASK == 0xFFFFFF00); inline u32 ToColor32(const vec4 &col) { - const u32 r = Cast(eastl::min(col.r, 1.0f) * 255.99f); - const u32 g = Cast(eastl::min(col.g, 1.0f) * 255.99f); - const u32 b = Cast(eastl::min(col.b, 1.0f) * 255.99f); - const u32 a = Cast(eastl::min(col.a, 1.0f) * 255.99f); + const u32 r = static_cast(eastl::min(col.r, 1.0f) * 255.99f); + const u32 g = static_cast(eastl::min(col.g, 1.0f) * 255.99f); + const u32 b = static_cast(eastl::min(col.b, 1.0f) * 255.99f); + const u32 a = static_cast(eastl::min(col.a, 1.0f) * 255.99f); return r << 24 | g << 16 | b << 8 | a; } @@ -47,9 +47,9 @@ ToColor32(const vec4 &col) inline u32 ToColor32(const vec3 &col) { - const u32 r = Cast(eastl::min(col.r, 1.0f) * 255.99f); - const u32 g = Cast(eastl::min(col.g, 1.0f) * 255.99f); - const u32 b = Cast(eastl::min(col.b, 1.0f) * 255.99f); + const u32 r = static_cast(eastl::min(col.r, 1.0f) * 255.99f); + const u32 g = static_cast(eastl::min(col.g, 1.0f) * 255.99f); + const u32 b = static_cast(eastl::min(col.b, 1.0f) * 255.99f); constexpr u32 a = 255; 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; - return {Light::TYPE_POINT, gen, Cast(index)}; + return {Light::TYPE_POINT, gen, static_cast(index)}; } ++light; } @@ -207,7 +207,7 @@ LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius void LightManager::Update() { - const u16 requiredBufferCapacity = eastl::min(Cast(m_Lights.capacity()), MAX_LIGHTS); + const u16 requiredBufferCapacity = eastl::min(static_cast(m_Lights.capacity()), MAX_LIGHTS); if ((m_GpuBufferCapacity_ & CAPACITY_MASK) < requiredBufferCapacity) { auto newBuffer = m_ResourceManager->Buffers().CreateStorageBuffer(requiredBufferCapacity * sizeof m_Lights[0], diff --git a/samples/03_model_render/light_manager.h b/samples/03_model_render/light_manager.h index 9823df7..0608675 100644 --- a/samples/03_model_render/light_manager.h +++ b/samples/03_model_render/light_manager.h @@ -98,7 +98,7 @@ struct LightManager // Using lower bit. Capacity can be directly a multiple of 2 // Thus, range is up to MaxValue constexpr static u16 UPDATE_REQUIRED_BIT = 1; - constexpr static u16 CAPACITY_MASK = Cast(~UPDATE_REQUIRED_BIT); + constexpr static u16 CAPACITY_MASK = static_cast(~UPDATE_REQUIRED_BIT); LightHandle AddDirectional(const vec3 &direction, const vec3 &color, f32 intensity); LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius, f32 intensity); diff --git a/samples/03_model_render/model_render.cpp b/samples/03_model_render/model_render.cpp index 28f4e30..e9e735b 100644 --- a/samples/03_model_render/model_render.cpp +++ b/samples/03_model_render/model_render.cpp @@ -216,7 +216,7 @@ main(int, char **) }, }; vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = { - .maxSets = 1, .poolSizeCount = Cast(poolSizes.size()), .pPoolSizes = poolSizes.data()}; + .maxSets = 1, .poolSizeCount = static_cast(poolSizes.size()), .pPoolSizes = poolSizes.data()}; AbortIfFailed(device.m_Device.createDescriptorPool(&descriptorPoolCreateInfo, nullptr, &descriptorPool)); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo = { @@ -230,7 +230,7 @@ main(int, char **) vk::Extent2D internalResolution = {1920, 1080}; CameraController cameraController = {vec3{0.0f, 0.0f, 2.0f}, vec3{0.0f}, 70_deg, - Cast(swapchain.m_Extent.width) / Cast(swapchain.m_Extent.height)}; + static_cast(swapchain.m_Extent.width) / static_cast(swapchain.m_Extent.height)}; usize uboSize = 0; usize cameraSize = sizeof cameraController.m_Camera; @@ -277,16 +277,16 @@ main(int, char **) .pBufferInfo = &lightingBufferInfo, }, }; - device.m_Device.updateDescriptorSets(Cast(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr); + device.m_Device.updateDescriptorSets(static_cast(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr); commitManager.Update(); // Persistent variables vk::Viewport viewport = { .x = 0, - .y = Cast(internalResolution.height), - .width = Cast(internalResolution.width), - .height = -Cast(internalResolution.height), + .y = static_cast(internalResolution.height), + .width = static_cast(internalResolution.width), + .height = -static_cast(internalResolution.height), .minDepth = 0.0, .maxDepth = 1.0, }; @@ -347,7 +347,7 @@ main(int, char **) acquireToTransferDstBarrier, }; vk::DependencyInfo postRenderDependencies = { - .imageMemoryBarrierCount = Cast(postRenderBarriers.size()), + .imageMemoryBarrierCount = static_cast(postRenderBarriers.size()), .pImageMemoryBarriers = postRenderBarriers.data(), }; @@ -403,7 +403,7 @@ main(int, char **) })); } - gui::Init(&context, &device, &window, swapchain.m_Format, Cast(swapchain.m_ImageViews.size()), + gui::Init(&context, &device, &window, swapchain.m_Format, static_cast(swapchain.m_ImageViews.size()), queueAllocation.m_Family, graphicsQueue); bool rotating = false; bool lockToScreen = true; @@ -417,14 +417,14 @@ main(int, char **) constexpr static u32 SHOW_DIFFUSE_BIT = 1 << 2; constexpr static u32 SHOW_PREFILTER_BIT = 1 << 3; - i32 height = Cast(internalResolution.height); + i32 height = static_cast(internalResolution.height); f32 camPitch = glm::degrees(cameraController.m_Pitch); f32 camYaw = glm::degrees(cameraController.m_Yaw); vec3 camPosition = cameraController.m_Camera.m_Position; vk::Extent2D inputResolution = internalResolution; swapchain.RegisterResizeCallback([&cameraController](vk::Extent2D extent) { - cameraController.SetAspectRatio(Cast(extent.width) / Cast(extent.height)); + cameraController.SetAspectRatio(static_cast(extent.width) / static_cast(extent.height)); }); Time::Init(); @@ -449,7 +449,7 @@ main(int, char **) } inputResolution.height = height; - inputResolution.width = Cast(cameraController.m_AspectRatio * Cast(inputResolution.height)); + inputResolution.width = static_cast(cameraController.m_AspectRatio * static_cast(inputResolution.height)); if (gui::Button("Change Resolution")) { @@ -457,9 +457,9 @@ main(int, char **) inputResolution.height != internalResolution.height) { internalResolution = inputResolution; - viewport.width = Cast(internalResolution.width); - viewport.height = -Cast(internalResolution.height); - viewport.y = Cast(internalResolution.height); + viewport.width = static_cast(internalResolution.width); + viewport.height = -static_cast(internalResolution.height); + viewport.y = static_cast(internalResolution.height); scissor.extent = internalResolution; } } @@ -470,9 +470,9 @@ main(int, char **) swapchain.m_Extent.height != internalResolution.height) { internalResolution = swapchain.m_Extent; - viewport.width = Cast(internalResolution.width); - viewport.height = -Cast(internalResolution.height); - viewport.y = Cast(internalResolution.height); + viewport.width = static_cast(internalResolution.width); + viewport.height = -static_cast(internalResolution.height); + viewport.y = static_cast(internalResolution.height); scissor.extent = internalResolution; } } @@ -488,7 +488,7 @@ main(int, char **) camYaw = camYaw - floor((camYaw + 180.0f) / 360.0f) * 360.0f; cameraController.SetPitchYaw(glm::radians(camPitch), glm::radians(camYaw)); } - if (gui::InputFloat3("Camera Position", Recast(&camPosition))) + if (gui::InputFloat3("Camera Position", reinterpret_cast(&camPosition))) { cameraController.SetPosition(camPosition); } @@ -512,7 +512,7 @@ main(int, char **) if (rotating) { model.SetModelTransform( - rotate(model.GetModelTransform(), Cast(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f))); + rotate(model.GetModelTransform(), static_cast(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f))); } model.Update(); cameraController.m_Camera.CalculateInverses(); @@ -584,7 +584,7 @@ main(int, char **) vk::RenderingInfo renderingInfo = { .renderArea = {.extent = ToExtent2D(currentAttachment->m_Extent)}, .layerCount = 1, - .colorAttachmentCount = Cast(attachmentInfos.size()), + .colorAttachmentCount = static_cast(attachmentInfos.size()), .pColorAttachments = attachmentInfos.data(), .pDepthAttachment = &depthAttachment, }; @@ -637,7 +637,7 @@ main(int, char **) cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, innerPcbOffset, sizeof prim.m_TransformIdx, &prim.m_TransformIdx); innerPcbOffset += sizeof prim.m_TransformIdx; - cmd.drawIndexed(prim.m_IndexCount, 1, prim.m_FirstIndex, Cast(prim.m_VertexOffset), 0); + cmd.drawIndexed(prim.m_IndexCount, 1, prim.m_FirstIndex, static_cast(prim.m_VertexOffset), 0); } cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, backGroundPipeline.m_Pipeline); @@ -670,7 +670,7 @@ main(int, char **) .dstOffsets = std::array{ vk::Offset3D{0, 0, 0}, - vk::Offset3D{Cast(swapchain.m_Extent.width), Cast(swapchain.m_Extent.height), 1}, + vk::Offset3D{static_cast(swapchain.m_Extent.width), static_cast(swapchain.m_Extent.height), 1}, }, }; cmd.blitImage(currentImage, postRenderBarriers[0].newLayout, currentSwapchainImage, diff --git a/samples/03_model_render/nodes.cpp b/samples/03_model_render/nodes.cpp index 4b93735..bef72c5 100644 --- a/samples/03_model_render/nodes.cpp +++ b/samples/03_model_render/nodes.cpp @@ -49,7 +49,7 @@ Nodes::operator[](const u32 index) u32 Nodes::Count() const { - return Cast(m_Transforms.size()); + return static_cast(m_Transforms.size()); } usize diff --git a/samples/03_model_render/pipeline_utils.cpp b/samples/03_model_render/pipeline_utils.cpp index 78aaf2e..b970c25 100644 --- a/samples/03_model_render/pipeline_utils.cpp +++ b/samples/03_model_render/pipeline_utils.cpp @@ -60,7 +60,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems: }, }; vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { - .bindingCount = Cast(descriptorSetLayoutBindings.size()), + .bindingCount = static_cast(descriptorSetLayoutBindings.size()), .pBindings = descriptorSetLayoutBindings.data(), }; vk::DescriptorSetLayout descriptorSetLayout; @@ -76,7 +76,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems: }; vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { - .setLayoutCount = Cast(descriptorSetLayouts.size()), + .setLayoutCount = static_cast(descriptorSetLayouts.size()), .pSetLayouts = descriptorSetLayouts.data(), .pushConstantRangeCount = 1, .pPushConstantRanges = &pushConstantRange, @@ -139,7 +139,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems: }; vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { - .dynamicStateCount = Cast(dynamicStates.size()), + .dynamicStateCount = static_cast(dynamicStates.size()), .pDynamicStates = dynamicStates.data(), }; @@ -152,7 +152,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const systems: vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { .pNext = &renderingCreateInfo, - .stageCount = Cast(shaderStages.size()), + .stageCount = static_cast(shaderStages.size()), .pStages = shaderStages.data(), .pVertexInputState = &vertexInputStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo, @@ -221,7 +221,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons }, }; vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { - .bindingCount = Cast(descriptorSetLayoutBindings.size()), + .bindingCount = static_cast(descriptorSetLayoutBindings.size()), .pBindings = descriptorSetLayoutBindings.data(), }; vk::DescriptorSetLayout descriptorSetLayout; @@ -237,7 +237,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons }; vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { - .setLayoutCount = Cast(descriptorSetLayouts.size()), + .setLayoutCount = static_cast(descriptorSetLayouts.size()), .pSetLayouts = descriptorSetLayouts.data(), .pushConstantRangeCount = 1, .pPushConstantRanges = &pushConstantRange, @@ -300,7 +300,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons }; vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { - .dynamicStateCount = Cast(dynamicStates.size()), + .dynamicStateCount = static_cast(dynamicStates.size()), .pDynamicStates = dynamicStates.data(), }; @@ -313,7 +313,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { .pNext = &renderingCreateInfo, - .stageCount = Cast(shaderStages.size()), + .stageCount = static_cast(shaderStages.size()), .pStages = shaderStages.data(), .pVertexInputState = &vertexInputStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo, diff --git a/samples/04_scenes/asset_loader.cpp b/samples/04_scenes/asset_loader.cpp index 88280e3..12224a5 100644 --- a/samples/04_scenes/asset_loader.cpp +++ b/samples/04_scenes/asset_loader.cpp @@ -102,8 +102,8 @@ AssetLoader::LoadHdrImage(Texture *texture, cstr path, cstr name) const ERROR_IF(!data, "Could not load {}", path) THEN_ABORT(-1); assert(nChannels == 3); - u32 width = Cast(x); - u32 height = Cast(y); + u32 width = static_cast(x); + u32 height = static_cast(y); StagingBuffer stagingBuffer; 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 = { - .imageMemoryBarrierCount = Cast(startBarriers.size()), + .imageMemoryBarrierCount = static_cast(startBarriers.size()), .pImageMemoryBarriers = startBarriers.data(), }; @@ -362,8 +362,8 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, Texture *texture, vk::ImageLayo commandBuffer.pipelineBarrier2(&imageStartDependency); - i32 prevMipWidth = Cast(texture->m_Extent.width); - i32 prevMipHeight = Cast(texture->m_Extent.height); + i32 prevMipWidth = static_cast(texture->m_Extent.width); + i32 prevMipHeight = static_cast(texture->m_Extent.height); u32 maxPrevMip = texture->GetMipLevels() - 1; for (u32 prevMipLevel = 0; prevMipLevel < maxPrevMip; ++prevMipLevel) @@ -404,8 +404,8 @@ AssetLoader::LoadImageToGpu(StagingBuffer *stagingBuffer, tinygltf::Image *image assert(image->component == 4); assert(image->height > 0 && image->width > 0); - u32 height = Cast(image->height); - u32 width = Cast(image->width); + u32 height = static_cast(image->height); + u32 width = static_cast(image->width); vk::Format imageFormat = isSrgb ? vk::Format::eR8G8B8A8Srgb : vk::Format::eR8G8B8A8Unorm; @@ -481,8 +481,8 @@ AssetLoader::LoadImageToGpu(StagingBuffer *stagingBuffer, tinygltf::Image *image vk::BufferImageCopy2 imageCopy = { .bufferOffset = 0, - .bufferRowLength = Cast(image->width), - .bufferImageHeight = Cast(image->height), + .bufferRowLength = static_cast(image->width), + .bufferImageHeight = static_cast(image->height), .imageSubresource = { .aspectMask = vk::ImageAspectFlagBits::eColor, @@ -558,8 +558,8 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi if (node->mesh >= 0) { auto *mesh = &model->meshes[node->mesh]; - u32 vertexOffset = Cast(vertexPositions->size()); - u32 indexOffset = Cast(indices->size()); + u32 vertexOffset = static_cast(vertexPositions->size()); + u32 indexOffset = static_cast(indices->size()); for (auto &prim : mesh->primitives) { u32 vertexCount = 0; @@ -577,17 +577,17 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi tinygltf::Buffer *posBuffer = &model->buffers[posBufferView->buffer]; usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset); - vertexCount = Cast(posAccessor->count); + vertexCount = static_cast(posAccessor->count); vertexPositions->reserve(vertexOffset + vertexCount); if (posAccessor->type == TINYGLTF_TYPE_VEC4) { - vec4 *data = Recast(posBuffer->data.data() + byteOffset); + vec4 *data = reinterpret_cast(posBuffer->data.data() + byteOffset); vertexPositions->insert(vertexPositions->end(), data, data + vertexCount); } else if (posAccessor->type == TINYGLTF_TYPE_VEC3) { - vec3 *data = Recast(posBuffer->data.data() + byteOffset); + vec3 *data = reinterpret_cast(posBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { vertexPositions->push_back(vec4(data[i], 1.0f)); @@ -595,7 +595,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi } else if (posAccessor->type == TINYGLTF_TYPE_VEC2) { - vec2 *data = Recast(posBuffer->data.data() + byteOffset); + vec2 *data = reinterpret_cast(posBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { vertexPositions->push_back(vec4(data[i], 0.0f, 1.0f)); @@ -619,7 +619,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi if (normAccessor->type == TINYGLTF_TYPE_VEC4) { - vec4 *data = Recast(normBuffer->data.data() + byteOffset); + vec4 *data = reinterpret_cast(normBuffer->data.data() + byteOffset); vec4 *end = data + vertexCount; u32 idx = vertexOffset; @@ -631,7 +631,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi } else if (normAccessor->type == TINYGLTF_TYPE_VEC3) { - vec3 *data = Recast(normBuffer->data.data() + byteOffset); + vec3 *data = reinterpret_cast(normBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { auto norm = vec4(data[i], 0.0f); @@ -640,7 +640,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi } else if (normAccessor->type == TINYGLTF_TYPE_VEC2) { - vec2 *data = Recast(normBuffer->data.data() + byteOffset); + vec2 *data = reinterpret_cast(normBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { auto norm = vec4(data[i], 0.0f, 0.0f); @@ -663,7 +663,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi assert(uvAccessor->type == TINYGLTF_TYPE_VEC2 && uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); { - vec2 *data = Recast(uvBuffer->data.data() + byteOffset); + vec2 *data = reinterpret_cast(uvBuffer->data.data() + byteOffset); vec2 *end = data + vertexCount; u32 idx = vertexOffset; vec2 *it = data; @@ -686,7 +686,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi if (colorAccessor->type == TINYGLTF_TYPE_VEC4) { - vec4 *data = Recast(colorBuffer->data.data() + byteOffset); + vec4 *data = reinterpret_cast(colorBuffer->data.data() + byteOffset); vec4 *end = data + vertexCount; u32 idx = vertexOffset; @@ -698,7 +698,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi } else if (colorAccessor->type == TINYGLTF_TYPE_VEC3) { - vec3 *data = Recast(colorBuffer->data.data() + byteOffset); + vec3 *data = reinterpret_cast(colorBuffer->data.data() + byteOffset); for (u32 i = 0; i < vertexCount; ++i) { auto color = vec4(data[i], 1.0f); @@ -719,22 +719,22 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi tinygltf::Buffer *indexBuffer = &model->buffers[indexBufferView->buffer]; usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset); - indexCount = Cast(indexAccessor->count); + indexCount = static_cast(indexAccessor->count); indices->reserve(indexOffset + indexCount); if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT) { - u32 *data = Recast(indexBuffer->data.data() + byteOffset); + u32 *data = reinterpret_cast(indexBuffer->data.data() + byteOffset); indices->insert(indices->end(), data, data + indexCount); } else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) { - u16 *data = Recast(indexBuffer->data.data() + byteOffset); + u16 *data = reinterpret_cast(indexBuffer->data.data() + byteOffset); indices->insert(indices->end(), data, data + indexCount); } else if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE) { - u8 *data = Recast(indexBuffer->data.data() + byteOffset); + u8 *data = reinterpret_cast(indexBuffer->data.data() + byteOffset); indices->insert(indices->end(), data, data + indexCount); } } @@ -860,7 +860,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) return materialFind->second; } - u32 index = Cast(materials.size()); + u32 index = static_cast(materials.size()); auto *material = &model.materials[materialIdx]; f32 alphaBlendValue = -1; @@ -870,14 +870,14 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name) } else if (material->alphaMode == "MASK") { - alphaBlendValue = Cast(material->alphaCutoff); + alphaBlendValue = static_cast(material->alphaCutoff); } materials.push_back({ .m_AlbedoFactor = VectorToVec4(material->pbrMetallicRoughness.baseColorFactor), .m_EmissionFactor = VectorToVec3(material->emissiveFactor), - .m_MetalFactor = Cast(material->pbrMetallicRoughness.metallicFactor), - .m_RoughFactor = Cast(material->pbrMetallicRoughness.roughnessFactor), + .m_MetalFactor = static_cast(material->pbrMetallicRoughness.metallicFactor), + .m_RoughFactor = static_cast(material->pbrMetallicRoughness.roughnessFactor), .m_AlbedoTex = getTextureHandle(material->pbrMetallicRoughness.baseColorTexture.index, true), .m_NormalTex = getTextureHandle(material->normalTexture.index, false), .m_MetalRoughTex = getTextureHandle(material->pbrMetallicRoughness.metallicRoughnessTexture.index, false), diff --git a/samples/04_scenes/ibl_helpers.cpp b/samples/04_scenes/ibl_helpers.cpp index e6a5270..2c54d73 100644 --- a/samples/04_scenes/ibl_helpers.cpp +++ b/samples/04_scenes/ibl_helpers.cpp @@ -121,7 +121,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu readyToWriteBarriers[3].subresourceRange = lutSubresRange; vk::DependencyInfo readyToWriteDependency = { - .imageMemoryBarrierCount = Cast(readyToWriteBarriers.size()), + .imageMemoryBarrierCount = static_cast(readyToWriteBarriers.size()), .pImageMemoryBarriers = readyToWriteBarriers.data(), }; @@ -197,7 +197,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu vk::PushConstantRange pcr = { .stageFlags = vk::ShaderStageFlagBits::eCompute, .offset = 0, - .size = Cast(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)), + .size = static_cast(eastl::max(eastl::max(sizeof(SkyboxPushConstants), sizeof(BrdfLutPushConstants)), eastl::max(sizeof(DiffuseIrradiancePushConstants), sizeof(PrefilterPushConstants)))), }; @@ -254,7 +254,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu }; eastl::array pipelines; - AbortIfFailed(pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, Cast(computePipelineCreateInfo.size()), + AbortIfFailed(pDevice->m_Device.createComputePipelines(pDevice->m_PipelineCache, static_cast(computePipelineCreateInfo.size()), computePipelineCreateInfo.data(), nullptr, pipelines.data())); @@ -331,7 +331,7 @@ CreateEnvironment(AssetLoader *assetLoader, vk::Queue computeQueue, const u32 cu { prefilterPushConstants.m_OutputTexture = tex; prefilterPushConstants.m_CubeSide = mipSize; - prefilterPushConstants.m_Roughness = Cast(mipCount) / Cast(prefilterMipCountMax); + prefilterPushConstants.m_Roughness = static_cast(mipCount) / static_cast(prefilterMipCountMax); cmd.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eCompute, 0, sizeof prefilterPushConstants, &prefilterPushConstants); u32 groupCount = eastl::max(mipSize / 16u, 1u); diff --git a/samples/04_scenes/light_manager.cpp b/samples/04_scenes/light_manager.cpp index 4b0c838..6d64cdf 100644 --- a/samples/04_scenes/light_manager.cpp +++ b/samples/04_scenes/light_manager.cpp @@ -56,10 +56,10 @@ static_assert(Light::COLOR_MASK == 0xFFFFFF00); inline u32 ToColor32(const vec4 &col) { - const u32 r = Cast(eastl::min(col.r, 1.0f) * 255.99f); - const u32 g = Cast(eastl::min(col.g, 1.0f) * 255.99f); - const u32 b = Cast(eastl::min(col.b, 1.0f) * 255.99f); - const u32 a = Cast(eastl::min(col.a, 1.0f) * 255.99f); + const u32 r = static_cast(eastl::min(col.r, 1.0f) * 255.99f); + const u32 g = static_cast(eastl::min(col.g, 1.0f) * 255.99f); + const u32 b = static_cast(eastl::min(col.b, 1.0f) * 255.99f); + const u32 a = static_cast(eastl::min(col.a, 1.0f) * 255.99f); return r << 24 | g << 16 | b << 8 | a; } @@ -67,9 +67,9 @@ ToColor32(const vec4 &col) inline u32 ToColor32(const vec3 &col) { - const u32 r = Cast(eastl::min(col.r, 1.0f) * 255.99f); - const u32 g = Cast(eastl::min(col.g, 1.0f) * 255.99f); - const u32 b = Cast(eastl::min(col.b, 1.0f) * 255.99f); + const u32 r = static_cast(eastl::min(col.r, 1.0f) * 255.99f); + const u32 g = static_cast(eastl::min(col.g, 1.0f) * 255.99f); + const u32 b = static_cast(eastl::min(col.b, 1.0f) * 255.99f); constexpr u32 a = 255; 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; - return {Light::TYPE_POINT, gen, Cast(index)}; + return {Light::TYPE_POINT, gen, static_cast(index)}; } ++light; } @@ -236,7 +236,7 @@ LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius void LightManager::Update() { - const u16 requiredBufferCapacity = eastl::min(Cast(m_Lights.capacity()), MAX_LIGHTS); + const u16 requiredBufferCapacity = eastl::min(static_cast(m_Lights.capacity()), MAX_LIGHTS); if ((m_GpuBufferCapacity_ & CAPACITY_MASK) < requiredBufferCapacity) { m_GpuBufferCapacity_ = requiredBufferCapacity | UPDATE_REQUIRED_BIT; diff --git a/samples/04_scenes/light_manager.h b/samples/04_scenes/light_manager.h index a123334..a378387 100644 --- a/samples/04_scenes/light_manager.h +++ b/samples/04_scenes/light_manager.h @@ -73,7 +73,7 @@ struct LightManager // Using lower bit. Capacity can be directly a multiple of 2 // Thus, range is up to MaxValue constexpr static u16 UPDATE_REQUIRED_BIT = 1; - constexpr static u16 CAPACITY_MASK = Cast(~UPDATE_REQUIRED_BIT); + constexpr static u16 CAPACITY_MASK = static_cast(~UPDATE_REQUIRED_BIT); LightHandle AddDirectional(const vec3 &direction, const vec3 &color, f32 intensity); LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius, f32 intensity); diff --git a/samples/04_scenes/main.cpp b/samples/04_scenes/main.cpp index 1cbea3a..72f0cb4 100644 --- a/samples/04_scenes/main.cpp +++ b/samples/04_scenes/main.cpp @@ -49,7 +49,7 @@ main(int, char *[]) 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, - Cast(internalResolution.width) / Cast(internalResolution.height)}; + static_cast(internalResolution.width) / static_cast(internalResolution.height)}; INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data()); @@ -138,7 +138,7 @@ main(int, char *[]) }, }; vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo = { - .maxSets = 1, .poolSizeCount = Cast(poolSizes.size()), .pPoolSizes = poolSizes.data()}; + .maxSets = 1, .poolSizeCount = static_cast(poolSizes.size()), .pPoolSizes = poolSizes.data()}; AbortIfFailed(device.m_Device.createDescriptorPool(&descriptorPoolCreateInfo, nullptr, &descriptorPool)); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo = { @@ -164,14 +164,14 @@ main(int, char *[]) .pBufferInfo = &camLightBufferInfo, }, }; - device.m_Device.updateDescriptorSets(Cast(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr); + device.m_Device.updateDescriptorSets(static_cast(writeDescriptors.size()), writeDescriptors.data(), 0, nullptr); // Persistent variables vk::Viewport viewport = { .x = 0, - .y = Cast(internalResolution.height), - .width = Cast(internalResolution.width), - .height = -Cast(internalResolution.height), + .y = static_cast(internalResolution.height), + .width = static_cast(internalResolution.width), + .height = -static_cast(internalResolution.height), .minDepth = 0.0, .maxDepth = 1.0, }; @@ -232,7 +232,7 @@ main(int, char *[]) acquireToTransferDstBarrier, }; vk::DependencyInfo postRenderDependencies = { - .imageMemoryBarrierCount = Cast(postRenderBarriers.size()), + .imageMemoryBarrierCount = static_cast(postRenderBarriers.size()), .pImageMemoryBarriers = postRenderBarriers.data(), }; @@ -314,13 +314,13 @@ main(int, char *[]) swapchain.RegisterResizeCallback( [&cameraController, &internalResolution, &viewport, &scissor](vk::Extent2D extent) { - cameraController.SetAspectRatio(Cast(extent.width) / Cast(extent.height)); + cameraController.SetAspectRatio(static_cast(extent.width) / static_cast(extent.height)); - internalResolution.width = Cast(Cast(internalResolution.height) * cameraController.m_AspectRatio); + internalResolution.width = static_cast(static_cast(internalResolution.height) * cameraController.m_AspectRatio); - viewport.y = Cast(internalResolution.height); - viewport.width = Cast(internalResolution.width); - viewport.height = -Cast(internalResolution.height); + viewport.y = static_cast(internalResolution.height); + viewport.width = static_cast(internalResolution.width); + viewport.height = -static_cast(internalResolution.height); scissor.extent = internalResolution; }); @@ -354,7 +354,7 @@ main(int, char *[]) // for (auto [entity, dynTrans] : rootModel.each()) //{ // dynTrans.m_Rotation = - // glm::rotate(dynTrans.m_Rotation, Cast(30_deg * (++index) * Time::m_Delta), vec3{0.0f, 1.0f, + // glm::rotate(dynTrans.m_Rotation, static_cast(30_deg * (++index) * Time::m_Delta), vec3{0.0f, 1.0f, // 0.0f}); // } @@ -417,7 +417,7 @@ main(int, char *[]) registry.get(parent.m_ParentEntity).m_Transform * translation * rotation * scale; } - u32 objectCount = Cast(renderableObjectsGroup.size()); + u32 objectCount = static_cast(renderableObjectsGroup.size()); nodeData.clear(); nodeDrawInfo.clear(); nodeData.reserve(objectCount); @@ -474,7 +474,7 @@ main(int, char *[]) vk::RenderingInfo renderingInfo = { .renderArea = {.extent = ToExtent2D(currentAttachment->m_Extent)}, .layerCount = 1, - .colorAttachmentCount = Cast(attachmentInfos.size()), + .colorAttachmentCount = static_cast(attachmentInfos.size()), .pColorAttachments = attachmentInfos.data(), .pDepthAttachment = &depthAttachment, }; @@ -531,7 +531,7 @@ main(int, char *[]) .dstOffsets = std::array{ vk::Offset3D{0, 0, 0}, - vk::Offset3D{Cast(swapchain.m_Extent.width), Cast(swapchain.m_Extent.height), 1}, + vk::Offset3D{static_cast(swapchain.m_Extent.width), static_cast(swapchain.m_Extent.height), 1}, }, }; cmd.blitImage(currentImage, postRenderBarriers[0].newLayout, currentSwapchainImage, diff --git a/samples/04_scenes/pipeline_utils.cpp b/samples/04_scenes/pipeline_utils.cpp index 528cf80..6586364 100644 --- a/samples/04_scenes/pipeline_utils.cpp +++ b/samples/04_scenes/pipeline_utils.cpp @@ -46,7 +46,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe }, }; vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { - .bindingCount = Cast(descriptorSetLayoutBindings.size()), + .bindingCount = static_cast(descriptorSetLayoutBindings.size()), .pBindings = descriptorSetLayoutBindings.data(), }; vk::DescriptorSetLayout descriptorSetLayout; @@ -62,7 +62,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe }; vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { - .setLayoutCount = Cast(descriptorSetLayouts.size()), + .setLayoutCount = static_cast(descriptorSetLayouts.size()), .pSetLayouts = descriptorSetLayouts.data(), .pushConstantRangeCount = 1, .pPushConstantRanges = &pushConstantRange, @@ -125,7 +125,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe }; vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { - .dynamicStateCount = Cast(dynamicStates.size()), + .dynamicStateCount = static_cast(dynamicStates.size()), .pDynamicStates = dynamicStates.data(), }; @@ -138,7 +138,7 @@ CreatePipeline(const Device *device, vk::Format attachmentFormat, const RenderRe vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { .pNext = &renderingCreateInfo, - .stageCount = Cast(shaderStages.size()), + .stageCount = static_cast(shaderStages.size()), .pStages = shaderStages.data(), .pVertexInputState = &vertexInputStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo, @@ -197,7 +197,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons }, }; vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { - .bindingCount = Cast(descriptorSetLayoutBindings.size()), + .bindingCount = static_cast(descriptorSetLayoutBindings.size()), .pBindings = descriptorSetLayoutBindings.data(), }; vk::DescriptorSetLayout descriptorSetLayout; @@ -213,7 +213,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons }; vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = { - .setLayoutCount = Cast(descriptorSetLayouts.size()), + .setLayoutCount = static_cast(descriptorSetLayouts.size()), .pSetLayouts = descriptorSetLayouts.data(), .pushConstantRangeCount = 1, .pPushConstantRanges = &pushConstantRange, @@ -276,7 +276,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons }; vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo = { - .dynamicStateCount = Cast(dynamicStates.size()), + .dynamicStateCount = static_cast(dynamicStates.size()), .pDynamicStates = dynamicStates.data(), }; @@ -289,7 +289,7 @@ CreateBackgroundPipeline(const Device *device, vk::Format attachmentFormat, cons vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { .pNext = &renderingCreateInfo, - .stageCount = Cast(shaderStages.size()), + .stageCount = static_cast(shaderStages.size()), .pStages = shaderStages.data(), .pVertexInputState = &vertexInputStateCreateInfo, .pInputAssemblyState = &inputAssemblyStateCreateInfo, diff --git a/samples/04_scenes/render_resource_manager.cpp b/samples/04_scenes/render_resource_manager.cpp index bfa4544..693c50b 100644 --- a/samples/04_scenes/render_resource_manager.cpp +++ b/samples/04_scenes/render_resource_manager.cpp @@ -33,7 +33,7 @@ TextureManager::Commit(Texture *texture) Texture *allocatedTexture = &m_Textures[index]; assert(!allocatedTexture->IsValid()); - m_FreeHead = *Recast(allocatedTexture); + m_FreeHead = *reinterpret_cast(allocatedTexture); // Ensure it is copyable. static_assert(std::is_trivially_copyable_v); @@ -45,7 +45,7 @@ TextureManager::Commit(Texture *texture) return {index}; } - const u32 index = Cast(m_Textures.size()); + const u32 index = static_cast(m_Textures.size()); if (index < m_MaxCapacity) { Texture *allocatedTexture = &m_Textures.push_back(); @@ -79,7 +79,7 @@ TextureManager::Release(const Device *device, const TextureHandle handle) allocatedTexture->Destroy(device); assert(!allocatedTexture->IsValid()); - *Recast(allocatedTexture) = m_FreeHead; + *reinterpret_cast(allocatedTexture) = m_FreeHead; m_FreeHead = handle.m_Index; } @@ -104,10 +104,10 @@ BufferManager::Init(const u32 maxCapacity) Buffer *pIter = m_Buffers; for (u32 i = 1; i < m_MaxCapacity; ++i) { - *Recast(pIter) = i; + *reinterpret_cast(pIter) = i; ++pIter; } - *Recast(pIter) = GpuResourceHandle::INVALID_HANDLE; + *reinterpret_cast(pIter) = GpuResourceHandle::INVALID_HANDLE; } BufferHandle @@ -132,7 +132,7 @@ BufferManager::Commit_(StorageBuffer *buffer) Buffer *allocatedBuffer = &m_Buffers[index]; assert(!allocatedBuffer->IsValid()); - m_FreeHead = *Recast(allocatedBuffer); + m_FreeHead = *reinterpret_cast(allocatedBuffer); // Ensure it is copyable. static_assert(std::is_trivially_copyable_v); @@ -149,7 +149,7 @@ BufferManager::Fetch(const BufferHandle handle) { assert(!handle.IsInvalid()); - return Recast(&m_Buffers[handle.m_Index]); + return reinterpret_cast(&m_Buffers[handle.m_Index]); } void @@ -161,7 +161,7 @@ BufferManager::Release(const Device *device, const BufferHandle handle) allocatedBuffer->Destroy(device); assert(!allocatedBuffer->IsValid()); - *Recast(allocatedBuffer) = m_FreeHead; + *reinterpret_cast(allocatedBuffer) = m_FreeHead; m_FreeHead = handle.m_Index; } @@ -196,7 +196,7 @@ StorageTextureManager::Fetch(const StorageTextureHandle handle) { assert(!handle.IsInvalid()); - return Recast(&m_Textures[handle.m_Index]); + return reinterpret_cast(&m_Textures[handle.m_Index]); } void @@ -215,15 +215,15 @@ HashSamplerCreateInfo(const vk::SamplerCreateInfo *createInfo) hash = HashCombine(hash, HashAny(createInfo->addressModeU)); hash = HashCombine(hash, HashAny(createInfo->addressModeV)); hash = HashCombine(hash, HashAny(createInfo->addressModeW)); - hash = HashCombine(hash, HashAny(Cast(createInfo->mipLodBias * 1000))); // Resolution of 10^-3 + hash = HashCombine(hash, HashAny(static_cast(createInfo->mipLodBias * 1000))); // Resolution of 10^-3 hash = HashCombine(hash, HashAny(createInfo->anisotropyEnable)); hash = HashCombine(hash, - HashAny(Cast(createInfo->maxAnisotropy * 0x10))); // 16:1 Anisotropy is enough resolution + HashAny(static_cast(createInfo->maxAnisotropy * 0x10))); // 16:1 Anisotropy is enough resolution hash = HashCombine(hash, HashAny(createInfo->compareEnable)); hash = HashCombine(hash, HashAny(createInfo->compareOp)); - hash = HashCombine(hash, HashAny(Cast(createInfo->minLod * 1000))); // 0.001 resolution is enough. + hash = HashCombine(hash, HashAny(static_cast(createInfo->minLod * 1000))); // 0.001 resolution is enough. hash = HashCombine(hash, - HashAny(Cast(createInfo->maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp) + HashAny(static_cast(createInfo->maxLod * 1000))); // 0.001 resolution is enough. (1 == NO Clamp) hash = HashCombine(hash, HashAny(createInfo->borderColor)); hash = HashCombine(hash, HashAny(createInfo->unnormalizedCoordinates)); @@ -253,7 +253,7 @@ SamplerManager::Create(const Device *device, const vk::SamplerCreateInfo *create vk::Sampler sampler; AbortIfFailed(device->m_Device.createSampler(createInfo, nullptr, &sampler)); - const u32 index = Cast(m_SamplerHashes.size()); + const u32 index = static_cast(m_SamplerHashes.size()); m_SamplerHashes.push_back(hash); m_Samplers.push_back(sampler); return {index}; @@ -293,7 +293,7 @@ VirtualizedBufferPool::InitStorage(const Device *device, usize bufferMaxSize) const VmaVirtualBlockCreateInfo virtualBlockCreateInfo = { .size = bufferMaxSize, }; - AbortIfFailed(Cast(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block))); + AbortIfFailed(static_cast(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block))); } void @@ -311,7 +311,7 @@ VirtualizedBufferPool::InitIndex(const Device *device, usize bufferMaxSize) const VmaVirtualBlockCreateInfo virtualBlockCreateInfo = { .size = bufferMaxSize, }; - AbortIfFailed(Cast(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block))); + AbortIfFailed(static_cast(vmaCreateVirtualBlock(&virtualBlockCreateInfo, &m_Block))); } void @@ -343,11 +343,11 @@ VirtualizedBufferPool::Create(usize size, usize alignment) index = m_FreeHead; allocVBuf = &m_VirtualBuffers[index]; - m_FreeHead = *Recast(allocVBuf); + m_FreeHead = *reinterpret_cast(allocVBuf); } else { - index = Cast(m_VirtualBuffers.size()); + index = static_cast(m_VirtualBuffers.size()); allocVBuf = &m_VirtualBuffers.push_back(); } @@ -374,7 +374,7 @@ VirtualizedBufferPool::Release(VirtualizedBufferHandle handle) VirtualBuffer *virtualBuffer = &m_VirtualBuffers[handle.m_Index]; vmaVirtualFree(m_Block, virtualBuffer->m_Allocation); - *Recast(virtualBuffer) = m_FreeHead; + *reinterpret_cast(virtualBuffer) = m_FreeHead; m_FreeHead = handle.m_Index; } @@ -656,7 +656,7 @@ RenderResourceManager::Update() // Descriptor Updates if (!m_Writes.empty()) { - m_Device->m_Device.updateDescriptorSets(Cast(m_Writes.size()), m_Writes.data(), 0, nullptr); + m_Device->m_Device.updateDescriptorSets(static_cast(m_Writes.size()), m_Writes.data(), 0, nullptr); m_Writes.clear(); m_WriteInfos.clear(); @@ -674,10 +674,10 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u vk::PhysicalDeviceProperties properties; m_Device->m_PhysicalDevice.getProperties(&properties); - u32 buffersCount = eastl::min(properties.limits.maxPerStageDescriptorStorageBuffers - 1024, Cast(maxSize)); - u32 texturesCount = eastl::min(properties.limits.maxPerStageDescriptorSampledImages - 1024, Cast(maxSize)); + u32 buffersCount = eastl::min(properties.limits.maxPerStageDescriptorStorageBuffers - 1024, static_cast(maxSize)); + u32 texturesCount = eastl::min(properties.limits.maxPerStageDescriptorSampledImages - 1024, static_cast(maxSize)); u32 storageTexturesCount = - eastl::min(properties.limits.maxPerStageDescriptorStorageImages - 1024, Cast(maxSize)); + eastl::min(properties.limits.maxPerStageDescriptorStorageImages - 1024, static_cast(maxSize)); INFO("Max Buffer Count: {}", buffersCount); INFO("Max Texture Count: {}", texturesCount); @@ -728,7 +728,7 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u const vk::DescriptorPoolCreateInfo poolCreateInfo = { .flags = vk::DescriptorPoolCreateFlagBits::eUpdateAfterBind, .maxSets = 1, - .poolSizeCount = Cast(poolSizes.size()), + .poolSizeCount = static_cast(poolSizes.size()), .pPoolSizes = poolSizes.data(), }; AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool)); @@ -742,7 +742,7 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u }; vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = { - .bindingCount = Cast(layoutBindingFlags.size()), + .bindingCount = static_cast(layoutBindingFlags.size()), .pBindingFlags = layoutBindingFlags.data(), }; @@ -750,19 +750,19 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u vk::DescriptorSetLayoutBinding{ .binding = BUFFER_BINDING_INDEX, .descriptorType = vk::DescriptorType::eStorageBuffer, - .descriptorCount = Cast(buffersCount), + .descriptorCount = static_cast(buffersCount), .stageFlags = vk::ShaderStageFlagBits::eAll, }, vk::DescriptorSetLayoutBinding{ .binding = TEXTURE_BINDING_INDEX, .descriptorType = vk::DescriptorType::eCombinedImageSampler, - .descriptorCount = Cast(texturesCount), + .descriptorCount = static_cast(texturesCount), .stageFlags = vk::ShaderStageFlagBits::eAll, }, vk::DescriptorSetLayoutBinding{ .binding = STORAGE_TEXTURE_BINDING_INDEX, .descriptorType = vk::DescriptorType::eStorageImage, - .descriptorCount = Cast(storageTexturesCount), + .descriptorCount = static_cast(storageTexturesCount), .stageFlags = vk::ShaderStageFlagBits::eAll, }, }; @@ -770,7 +770,7 @@ RenderResourceManager::RenderResourceManager(Device *device, u16 maxSize, bool u const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = { .pNext = &bindingFlagsCreateInfo, .flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool, - .bindingCount = Cast(descriptorLayoutBindings.size()), + .bindingCount = static_cast(descriptorLayoutBindings.size()), .pBindings = descriptorLayoutBindings.data(), }; AbortIfFailed(device->m_Device.createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout)); @@ -960,7 +960,7 @@ RenderResourceManager::CreateIndexBuffer(usize size, usize alignment, u32 *first u32 RenderResourceManager::FetchIndex(IndexHandle handle) { - return Cast(m_Index.FetchOffset(handle) / sizeof(u32)); + return static_cast(m_Index.FetchOffset(handle) / sizeof(u32)); } void