diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index e61ef4508..3845524b3 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -5,30 +5,6 @@ add_subdirectory(cpuinfo) set(SDL_SHARED OFF CACHE BOOL "" FORCE) add_subdirectory(SDL2) -add_library(vulkan-1 UNKNOWN IMPORTED GLOBAL) - -if(MINGW) - find_library(Vulkan_Lib NAMES libvulkan-1.dll.a vulkan-1 - PATHS "$ENV{VULKAN_SDK}/Lib" "$ENV{VULKAN_SDK}/Lib32" NO_DEFAULT_PATH) - if(NOT Vulkan_Lib) - find_library(Vulkan_Lib NAMES libvulkan-1.dll.a vulkan-1) - endif() -elseif(WIN32) - find_library(Vulkan_Lib NAMES vulkan-1 - PATHS "$ENV{VULKAN_SDK}/Lib" "$ENV{VULKAN_SDK}/Lib32" NO_DEFAULT_PATH) - if(NOT Vulkan_Lib) - find_library(Vulkan_Lib NAMES vulkan-1) - endif() -elseif(LINUX) - find_library(Vulkan_Lib vulkan) -endif() - -if(NOT Vulkan_Lib OR Vulkan_Lib MATCHES "-NOTFOUND$") - message(FATAL_ERROR "Vulkan library was not found") -endif() - -set_target_properties(vulkan-1 PROPERTIES IMPORTED_LOCATION "${Vulkan_Lib}") - set(SPIRV_SKIP_TESTS ON CACHE BOOL "" FORCE) set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE) set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "" FORCE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2114bf05a..d8ac8fe4a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -180,7 +180,7 @@ if (KYTY_CLANG_CL) set_source_files_properties(${kyty_emulator_src} PROPERTIES COMPILE_FLAGS "-Wno-pragma-pack -Wno-deprecated-declarations -D_TIMESPEC_DEFINED") endif() -set(kyty_emulator_link_libraries common vulkan-1 spirv-tools-opt spirv-tools SDL2-static xxhash FFmpeg::ffmpeg fmt::fmt nlohmann_json::nlohmann_json LibAtrac9) +set(kyty_emulator_link_libraries common spirv-tools-opt spirv-tools SDL2-static xxhash FFmpeg::ffmpeg fmt::fmt nlohmann_json::nlohmann_json LibAtrac9) set(inc_headers ${CMAKE_CURRENT_SOURCE_DIR} @@ -194,10 +194,6 @@ set(inc_headers ${KYTY_THIRD_PARTY_DIR}/stb ) -if(DEFINED ENV{VULKAN_SDK}) - list(APPEND inc_headers $ENV{VULKAN_SDK}/Include) -endif() - if (KYTY_CLANG_CL) list(APPEND kyty_emulator_link_libraries winpthread) list(APPEND inc_headers diff --git a/src/graphics/guest_gpu/gpu_format.cpp b/src/graphics/guest_gpu/gpu_format.cpp index 704587583..786dc6deb 100644 --- a/src/graphics/guest_gpu/gpu_format.cpp +++ b/src/graphics/guest_gpu/gpu_format.cpp @@ -8,80 +8,81 @@ namespace Libs::Graphics::Prospero { namespace { constexpr FormatInfo kFormatInfo[] = { - {GpuEnumValue(BufferFormat::k8UNorm), VK_FORMAT_R8_UNORM, 1, 0, 1, true, false}, - {GpuEnumValue(BufferFormat::k8SNorm), VK_FORMAT_UNDEFINED, 0, 0, 1, false, false}, - {GpuEnumValue(BufferFormat::k8UInt), VK_FORMAT_R8_UINT, 1, 0, 1, true, true}, - {GpuEnumValue(BufferFormat::k16UNorm), VK_FORMAT_R16_UNORM, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k16SNorm), VK_FORMAT_R16_SNORM, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k16UInt), VK_FORMAT_R16_UINT, 2, 0, 2, true, true}, - {GpuEnumValue(BufferFormat::k16SInt), VK_FORMAT_R16_SINT, 2, 0, 2, false, false}, - {GpuEnumValue(BufferFormat::k16Float), VK_FORMAT_R16_SFLOAT, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k8_8UNorm), VK_FORMAT_R8G8_UNORM, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k8_8SNorm), VK_FORMAT_R8G8_SNORM, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k8_8UInt), VK_FORMAT_R8G8_UINT, 2, 0, 2, true, true}, - {GpuEnumValue(BufferFormat::k8_8SInt), VK_FORMAT_R8G8_SINT, 2, 0, 2, false, false}, - {GpuEnumValue(BufferFormat::k32UInt), VK_FORMAT_R32_UINT, 4, 0, 4, true, true}, - {GpuEnumValue(BufferFormat::k32SInt), VK_FORMAT_R32_SINT, 4, 0, 4, false, false}, - {GpuEnumValue(BufferFormat::k32Float), VK_FORMAT_R32_SFLOAT, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k16_16UNorm), VK_FORMAT_R16G16_UNORM, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k16_16SNorm), VK_FORMAT_R16G16_SNORM, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k16_16UInt), VK_FORMAT_R16G16_UINT, 4, 0, 4, true, true}, - {GpuEnumValue(BufferFormat::k16_16SInt), VK_FORMAT_R16G16_SINT, 4, 0, 4, false, false}, - {GpuEnumValue(BufferFormat::k16_16Float), VK_FORMAT_R16G16_SFLOAT, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k11_11_10Float), VK_FORMAT_B10G11R11_UFLOAT_PACK32, 4, 0, 4, true, + {GpuEnumValue(BufferFormat::k8UNorm), vk::Format::eR8Unorm, 1, 0, 1, true, false}, + {GpuEnumValue(BufferFormat::k8SNorm), vk::Format::eUndefined, 0, 0, 1, false, false}, + {GpuEnumValue(BufferFormat::k8UInt), vk::Format::eR8Uint, 1, 0, 1, true, true}, + {GpuEnumValue(BufferFormat::k16UNorm), vk::Format::eR16Unorm, 2, 0, 2, true, false}, + {GpuEnumValue(BufferFormat::k16SNorm), vk::Format::eR16Snorm, 2, 0, 2, true, false}, + {GpuEnumValue(BufferFormat::k16UInt), vk::Format::eR16Uint, 2, 0, 2, true, true}, + {GpuEnumValue(BufferFormat::k16SInt), vk::Format::eR16Sint, 2, 0, 2, false, false}, + {GpuEnumValue(BufferFormat::k16Float), vk::Format::eR16Sfloat, 2, 0, 2, true, false}, + {GpuEnumValue(BufferFormat::k8_8UNorm), vk::Format::eR8G8Unorm, 2, 0, 2, true, false}, + {GpuEnumValue(BufferFormat::k8_8SNorm), vk::Format::eR8G8Snorm, 2, 0, 2, true, false}, + {GpuEnumValue(BufferFormat::k8_8UInt), vk::Format::eR8G8Uint, 2, 0, 2, true, true}, + {GpuEnumValue(BufferFormat::k8_8SInt), vk::Format::eR8G8Sint, 2, 0, 2, false, false}, + {GpuEnumValue(BufferFormat::k32UInt), vk::Format::eR32Uint, 4, 0, 4, true, true}, + {GpuEnumValue(BufferFormat::k32SInt), vk::Format::eR32Sint, 4, 0, 4, false, false}, + {GpuEnumValue(BufferFormat::k32Float), vk::Format::eR32Sfloat, 4, 0, 4, true, false}, + {GpuEnumValue(BufferFormat::k16_16UNorm), vk::Format::eR16G16Unorm, 4, 0, 4, true, false}, + {GpuEnumValue(BufferFormat::k16_16SNorm), vk::Format::eR16G16Snorm, 4, 0, 4, true, false}, + {GpuEnumValue(BufferFormat::k16_16UInt), vk::Format::eR16G16Uint, 4, 0, 4, true, true}, + {GpuEnumValue(BufferFormat::k16_16SInt), vk::Format::eR16G16Sint, 4, 0, 4, false, false}, + {GpuEnumValue(BufferFormat::k16_16Float), vk::Format::eR16G16Sfloat, 4, 0, 4, true, false}, + {GpuEnumValue(BufferFormat::k11_11_10Float), vk::Format::eB10G11R11UfloatPack32, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k10_10_10_2UNorm), VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4, 0, 4, + {GpuEnumValue(BufferFormat::k10_10_10_2UNorm), vk::Format::eA2B10G10R10UnormPack32, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k8_8_8_8UNorm), VK_FORMAT_R8G8B8A8_UNORM, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k8_8_8_8SNorm), VK_FORMAT_R8G8B8A8_SNORM, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k8_8_8_8UInt), VK_FORMAT_R8G8B8A8_UINT, 4, 0, 4, true, true}, - {GpuEnumValue(BufferFormat::k8_8_8_8SInt), VK_FORMAT_R8G8B8A8_SINT, 4, 0, 4, false, false}, - {GpuEnumValue(BufferFormat::k32_32UInt), VK_FORMAT_R32G32_UINT, 8, 0, 8, true, true}, - {GpuEnumValue(BufferFormat::k32_32SInt), VK_FORMAT_R32G32_SINT, 8, 0, 8, false, false}, - {GpuEnumValue(BufferFormat::k32_32Float), VK_FORMAT_R32G32_SFLOAT, 8, 0, 8, true, false}, - {GpuEnumValue(BufferFormat::k16_16_16_16UNorm), VK_FORMAT_R16G16B16A16_UNORM, 8, 0, 8, true, + {GpuEnumValue(BufferFormat::k8_8_8_8UNorm), vk::Format::eR8G8B8A8Unorm, 4, 0, 4, true, false}, + {GpuEnumValue(BufferFormat::k8_8_8_8SNorm), vk::Format::eR8G8B8A8Snorm, 4, 0, 4, true, false}, + {GpuEnumValue(BufferFormat::k8_8_8_8UInt), vk::Format::eR8G8B8A8Uint, 4, 0, 4, true, true}, + {GpuEnumValue(BufferFormat::k8_8_8_8SInt), vk::Format::eR8G8B8A8Sint, 4, 0, 4, false, false}, + {GpuEnumValue(BufferFormat::k32_32UInt), vk::Format::eR32G32Uint, 8, 0, 8, true, true}, + {GpuEnumValue(BufferFormat::k32_32SInt), vk::Format::eR32G32Sint, 8, 0, 8, false, false}, + {GpuEnumValue(BufferFormat::k32_32Float), vk::Format::eR32G32Sfloat, 8, 0, 8, true, false}, + {GpuEnumValue(BufferFormat::k16_16_16_16UNorm), vk::Format::eR16G16B16A16Unorm, 8, 0, 8, true, false}, - {GpuEnumValue(BufferFormat::k16_16_16_16SNorm), VK_FORMAT_R16G16B16A16_SNORM, 8, 0, 8, true, + {GpuEnumValue(BufferFormat::k16_16_16_16SNorm), vk::Format::eR16G16B16A16Snorm, 8, 0, 8, true, false}, - {GpuEnumValue(BufferFormat::k16_16_16_16UInt), VK_FORMAT_R16G16B16A16_UINT, 8, 0, 8, true, + {GpuEnumValue(BufferFormat::k16_16_16_16UInt), vk::Format::eR16G16B16A16Uint, 8, 0, 8, true, true}, - {GpuEnumValue(BufferFormat::k16_16_16_16SInt), VK_FORMAT_R16G16B16A16_SINT, 8, 0, 8, false, + {GpuEnumValue(BufferFormat::k16_16_16_16SInt), vk::Format::eR16G16B16A16Sint, 8, 0, 8, false, false}, - {GpuEnumValue(BufferFormat::k16_16_16_16Float), VK_FORMAT_R16G16B16A16_SFLOAT, 8, 0, 8, true, + {GpuEnumValue(BufferFormat::k16_16_16_16Float), vk::Format::eR16G16B16A16Sfloat, 8, 0, 8, true, false}, - {GpuEnumValue(BufferFormat::k32_32_32UInt), VK_FORMAT_R32G32B32_UINT, 12, 0, 12, true, true}, - {GpuEnumValue(BufferFormat::k32_32_32SInt), VK_FORMAT_R32G32B32_SINT, 12, 0, 12, false, false}, - {GpuEnumValue(BufferFormat::k32_32_32Float), VK_FORMAT_R32G32B32_SFLOAT, 12, 0, 12, true, + {GpuEnumValue(BufferFormat::k32_32_32UInt), vk::Format::eR32G32B32Uint, 12, 0, 12, true, true}, + {GpuEnumValue(BufferFormat::k32_32_32SInt), vk::Format::eR32G32B32Sint, 12, 0, 12, false, false}, - {GpuEnumValue(BufferFormat::k32_32_32_32UInt), VK_FORMAT_R32G32B32A32_UINT, 16, 0, 16, true, + {GpuEnumValue(BufferFormat::k32_32_32Float), vk::Format::eR32G32B32Sfloat, 12, 0, 12, true, + false}, + {GpuEnumValue(BufferFormat::k32_32_32_32UInt), vk::Format::eR32G32B32A32Uint, 16, 0, 16, true, true}, - {GpuEnumValue(BufferFormat::k32_32_32_32SInt), VK_FORMAT_R32G32B32A32_SINT, 16, 0, 16, false, + {GpuEnumValue(BufferFormat::k32_32_32_32SInt), vk::Format::eR32G32B32A32Sint, 16, 0, 16, false, false}, - {GpuEnumValue(BufferFormat::k32_32_32_32Float), VK_FORMAT_R32G32B32A32_SFLOAT, 16, 0, 16, true, + {GpuEnumValue(BufferFormat::k32_32_32_32Float), vk::Format::eR32G32B32A32Sfloat, 16, 0, 16, + true, false}, + {GpuEnumValue(BufferFormat::k8_8_8_8Srgb), vk::Format::eR8G8B8A8Srgb, 4, 0, 4, true, false}, + {GpuEnumValue(BufferFormat::k9_9_9_5Float), vk::Format::eE5B9G9R9UfloatPack32, 4, 0, 0, true, false}, - {GpuEnumValue(BufferFormat::k8_8_8_8Srgb), VK_FORMAT_R8G8B8A8_SRGB, 4, 0, 4, true, false}, - {GpuEnumValue(BufferFormat::k9_9_9_5Float), VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, 4, 0, 0, true, + {GpuEnumValue(BufferFormat::k5_6_5UNorm), vk::Format::eB5G6R5UnormPack16, 2, 0, 2, true, false}, + {GpuEnumValue(BufferFormat::k5_5_5_1UNorm), vk::Format::eR5G5B5A1UnormPack16, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k5_6_5UNorm), VK_FORMAT_B5G6R5_UNORM_PACK16, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k5_5_5_1UNorm), VK_FORMAT_R5G5B5A1_UNORM_PACK16, 2, 0, 2, true, + {GpuEnumValue(BufferFormat::k4_4_4_4UNorm), vk::Format::eR4G4B4A4UnormPack16, 2, 0, 2, true, false}, - {GpuEnumValue(BufferFormat::k4_4_4_4UNorm), VK_FORMAT_R4G4B4A4_UNORM_PACK16, 2, 0, 2, true, - false}, - {GpuEnumValue(BufferFormat::kFmask8_S4_F4), VK_FORMAT_R32_SFLOAT, 1, 0, 1, true, false}, - {GpuEnumValue(BufferFormat::kBc1UNorm), VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 0, 8, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc1Srgb), VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 0, 8, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc2UNorm), VK_FORMAT_BC2_UNORM_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc2Srgb), VK_FORMAT_BC2_SRGB_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc3UNorm), VK_FORMAT_BC3_UNORM_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc3Srgb), VK_FORMAT_BC3_SRGB_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc4UNorm), VK_FORMAT_BC4_UNORM_BLOCK, 0, 8, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc4SNorm), VK_FORMAT_BC4_SNORM_BLOCK, 0, 8, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc5UNorm), VK_FORMAT_BC5_UNORM_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc5SNorm), VK_FORMAT_BC5_SNORM_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc6UFloat), VK_FORMAT_BC6H_UFLOAT_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc6SFloat), VK_FORMAT_BC6H_SFLOAT_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc7UNorm), VK_FORMAT_BC7_UNORM_BLOCK, 0, 16, 0, true, false}, - {GpuEnumValue(BufferFormat::kBc7Srgb), VK_FORMAT_BC7_SRGB_BLOCK, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kFmask8_S4_F4), vk::Format::eR32Sfloat, 1, 0, 1, true, false}, + {GpuEnumValue(BufferFormat::kBc1UNorm), vk::Format::eBc1RgbaUnormBlock, 0, 8, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc1Srgb), vk::Format::eBc1RgbaSrgbBlock, 0, 8, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc2UNorm), vk::Format::eBc2UnormBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc2Srgb), vk::Format::eBc2SrgbBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc3UNorm), vk::Format::eBc3UnormBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc3Srgb), vk::Format::eBc3SrgbBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc4UNorm), vk::Format::eBc4UnormBlock, 0, 8, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc4SNorm), vk::Format::eBc4SnormBlock, 0, 8, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc5UNorm), vk::Format::eBc5UnormBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc5SNorm), vk::Format::eBc5SnormBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc6UFloat), vk::Format::eBc6HUfloatBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc6SFloat), vk::Format::eBc6HSfloatBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc7UNorm), vk::Format::eBc7UnormBlock, 0, 16, 0, true, false}, + {GpuEnumValue(BufferFormat::kBc7Srgb), vk::Format::eBc7SrgbBlock, 0, 16, 0, true, false}, }; constexpr auto MakeFormatInfoLookup() { @@ -105,9 +106,9 @@ const FormatInfo* FindFormatInfo(uint32_t format) { return format < kFormatInfoLookup.size() ? kFormatInfoLookup[format] : nullptr; } -VkFormat SurfaceFormat(uint32_t format) { +vk::Format SurfaceFormat(uint32_t format) { const auto* info = FindFormatInfo(format); - return info != nullptr ? info->vk_format : VK_FORMAT_UNDEFINED; + return info != nullptr ? info->vk_format : vk::Format::eUndefined; } uint32_t NumBytesPerElement(uint32_t format) { diff --git a/src/graphics/guest_gpu/gpu_format.h b/src/graphics/guest_gpu/gpu_format.h index b90f5ccd1..a096c254b 100644 --- a/src/graphics/guest_gpu/gpu_format.h +++ b/src/graphics/guest_gpu/gpu_format.h @@ -2,25 +2,25 @@ #define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_GUEST_GPU_GPU_FORMAT_H_ #include "common/common.h" +#include "graphics/host_gpu/vulkanCommon.h" #include -#include namespace Libs::Graphics::Prospero { struct FormatInfo { - uint32_t format = 0; - VkFormat vk_format = VK_FORMAT_UNDEFINED; - uint32_t bytes_per_element = 0; - uint32_t block_compressed_bytes_per_block = 0; - uint32_t render_target_bytes_per_element = 0; - bool supported_sampled_texture_format = false; - bool unsigned_integer_texture_format = false; + uint32_t format = 0; + vk::Format vk_format = vk::Format::eUndefined; + uint32_t bytes_per_element = 0; + uint32_t block_compressed_bytes_per_block = 0; + uint32_t render_target_bytes_per_element = 0; + bool supported_sampled_texture_format = false; + bool unsigned_integer_texture_format = false; }; std::span Formats(); const FormatInfo* FindFormatInfo(uint32_t format); -VkFormat SurfaceFormat(uint32_t format); +vk::Format SurfaceFormat(uint32_t format); uint32_t NumBytesPerElement(uint32_t format); uint32_t BlockCompressedBytesPerBlock(uint32_t format); uint32_t RenderTargetBytesPerElement(uint32_t format); diff --git a/src/graphics/host_gpu/graphicContext.h b/src/graphics/host_gpu/graphicContext.h index dfb58b6b0..61bf62610 100644 --- a/src/graphics/host_gpu/graphicContext.h +++ b/src/graphics/host_gpu/graphicContext.h @@ -4,13 +4,13 @@ #include "common/abi.h" #include "common/common.h" #include "common/threads.h" +#include "graphics/host_gpu/vulkanCommon.h" // IWYU pragma: export #include "graphics/host_gpu/vulkanInstance.h" #include #include #include #include -#include // IWYU pragma: export namespace Libs::Graphics { @@ -19,26 +19,26 @@ class CommandBuffer; struct VulkanSwapchain { ~VulkanSwapchain(); - VkSwapchainKHR swapchain = nullptr; - VkFormat swapchain_format = VK_FORMAT_UNDEFINED; - VkExtent2D swapchain_extent = {}; - std::unique_ptr swapchain_images; - std::unique_ptr swapchain_image_views; - uint32_t swapchain_images_count = 0; - std::unique_ptr image_acquired_semaphores; - std::unique_ptr render_complete_semaphores; - uint32_t current_index = 0; - uint32_t present_frame = 0; + vk::SwapchainKHR swapchain = nullptr; + vk::Format swapchain_format = vk::Format::eUndefined; + vk::Extent2D swapchain_extent = {}; + std::unique_ptr swapchain_images; + std::unique_ptr swapchain_image_views; + uint32_t swapchain_images_count = 0; + std::unique_ptr image_acquired_semaphores; + std::unique_ptr render_complete_semaphores; + uint32_t current_index = 0; + uint32_t present_frame = 0; }; struct VulkanCommandPool { - Common::Mutex mutex; - VkCommandPool pool = nullptr; - std::unique_ptr buffers; - std::unique_ptr fences; - std::unique_ptr semaphores; - std::unique_ptr busy; - uint32_t buffers_count = 0; + Common::Mutex mutex; + vk::CommandPool pool = nullptr; + std::unique_ptr buffers; + std::unique_ptr fences; + std::unique_ptr semaphores; + std::unique_ptr busy; + uint32_t buffers_count = 0; }; struct GraphicContext: public VulkanInstance { @@ -47,14 +47,14 @@ struct GraphicContext: public VulkanInstance { }; struct VulkanMemory { - VkMemoryRequirements requirements = {}; - VkMemoryPropertyFlags property = 0; - VkDeviceMemory memory = nullptr; - VmaAllocation allocation = nullptr; - VmaAllocationInfo allocation_info = {}; - VkDeviceSize offset = 0; - uint32_t type = 0; - uint64_t unique_id = 0; + vk::MemoryRequirements requirements = {}; + vk::MemoryPropertyFlags property = {}; + vk::DeviceMemory memory = nullptr; + VmaAllocation allocation = nullptr; + VmaAllocationInfo allocation_info = {}; + vk::DeviceSize offset = 0; + uint32_t type = 0; + uint64_t unique_id = 0; }; enum class VulkanImageType { @@ -67,22 +67,22 @@ enum class VulkanImageType { }; struct ImageViewInfo { - VkFormat format = VK_FORMAT_UNDEFINED; - VkImageViewType type = VK_IMAGE_VIEW_TYPE_2D; - VkImageAspectFlags aspect = 0; - uint32_t base_level = 0; - uint32_t level_count = 0; - uint32_t base_layer = 0; - uint32_t layer_count = 1; - uint32_t swizzle = 0; - VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT; + vk::Format format = vk::Format::eUndefined; + vk::ImageViewType type = vk::ImageViewType::e2D; + vk::ImageAspectFlags aspect = {}; + uint32_t base_level = 0; + uint32_t level_count = 0; + uint32_t base_layer = 0; + uint32_t layer_count = 1; + uint32_t swizzle = 0; + vk::ImageUsageFlags usage = vk::ImageUsageFlagBits::eSampled; bool operator==(const ImageViewInfo&) const = default; }; struct CachedImageView { ImageViewInfo info; - VkImageView view = nullptr; + vk::ImageView view = nullptr; }; struct ImageViewCache { @@ -104,14 +104,14 @@ struct VulkanImage { KYTY_CLASS_NO_COPY(VulkanImage); VulkanImageType type = VulkanImageType::Unknown; - VkFormat format = VK_FORMAT_UNDEFINED; - VkExtent2D extent = {}; + vk::Format format = vk::Format::eUndefined; + vk::Extent2D extent = {}; uint32_t guest_pitch = 0; uint32_t layers = 1; uint32_t mip_levels = 1; - VkImage image = nullptr; - VkImageView image_view[VIEW_MAX] = {}; - VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED; + vk::Image image = nullptr; + vk::ImageView image_view[VIEW_MAX] = {}; + vk::ImageLayout layout = vk::ImageLayout::eUndefined; Graphics::VulkanMemory memory; ImageViewCache view_cache; }; @@ -142,10 +142,10 @@ struct RenderTextureVulkanImage: public VulkanImage { }; struct VulkanBuffer { - VkBuffer buffer = nullptr; - VulkanMemory memory; - VkBufferUsageFlags usage = 0; - uint64_t buffer_size = 0; + vk::Buffer buffer = nullptr; + VulkanMemory memory; + vk::BufferUsageFlags usage = {}; + uint64_t buffer_size = 0; }; struct StorageVulkanBuffer: public VulkanBuffer {}; diff --git a/src/graphics/host_gpu/objects/label.cpp b/src/graphics/host_gpu/objects/label.cpp index 27ccf616e..98454c4d3 100644 --- a/src/graphics/host_gpu/objects/label.cpp +++ b/src/graphics/host_gpu/objects/label.cpp @@ -25,12 +25,12 @@ struct LabelCallbacks { }; struct LabelEvent final { - VkDevice device = nullptr; - VkEvent event = nullptr; + vk::Device device = nullptr; + vk::Event event = nullptr; ~LabelEvent() { if (event != nullptr) { - vkDestroyEvent(device, event, nullptr); + device.destroyEvent(event, nullptr); } } }; @@ -41,7 +41,7 @@ struct LabelSubmission { }; struct Label { - VkDevice device = nullptr; + vk::Device device = nullptr; LabelStatus status = LabelStatus::New; LabelCallbacks callbacks; std::vector submissions; @@ -115,14 +115,14 @@ void LabelManager::ThreadRun(void* data) { it->completion->event == nullptr) { EXIT("GPU label submission has no completion event\n"); } - const auto status = vkGetEventStatus(it->completion->device, it->completion->event); + const auto status = it->completion->device.getEventStatus(it->completion->event); switch (status) { - case VK_EVENT_SET: + case vk::Result::eEventSet: fired_labels.push_back(it->callbacks); finished_submissions.push_back(*it); it = label->submissions.erase(it); break; - case VK_EVENT_RESET: ++it; break; + case vk::Result::eEventReset: ++it; break; default: EXIT("vkGetEventStatus returned an unexpected result\n"); } } @@ -270,24 +270,24 @@ void LabelManager::Set(CommandBuffer* buffer, Label* label) { submission.completion = std::make_shared(); submission.completion->device = label->device; - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; EXIT_NOT_IMPLEMENTED(vk_buffer == nullptr); - VkEventCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; + vk::EventCreateInfo create_info {}; + create_info.sType = vk::StructureType::eEventCreateInfo; create_info.pNext = nullptr; - create_info.flags = 0; + create_info.flags = {}; - vkCreateEvent(label->device, &create_info, nullptr, &submission.completion->event); + label->device.createEvent(&create_info, nullptr, &submission.completion->event); EXIT_NOT_IMPLEMENTED(submission.completion->event == nullptr); buffer->RetainResourceUntilFence(submission.completion); // Labels can be reused before an earlier end-of-pipe event has been // observed by the polling thread. Capture a separate Vulkan event and // callback snapshot for each set so older writes are not lost. - vkResetEvent(label->device, submission.completion->event); - vkCmdSetEvent(vk_buffer, submission.completion->event, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT); + label->device.resetEvent(submission.completion->event); + vk_buffer.setEvent(submission.completion->event, vk::PipelineStageFlagBits::eBottomOfPipe); label->submissions.push_back(submission); diff --git a/src/graphics/host_gpu/objects/textureCommon.cpp b/src/graphics/host_gpu/objects/textureCommon.cpp index 6bf79cb89..ab4242758 100644 --- a/src/graphics/host_gpu/objects/textureCommon.cpp +++ b/src/graphics/host_gpu/objects/textureCommon.cpp @@ -28,115 +28,115 @@ RenderTargetFormatInfo TextureGetRenderTargetFormat(uint32_t raw_layout, uint32_ if (layout == Prospero::ChannelLayout::k8 && type == Prospero::ChannelType::kUNorm && raw_order <= Prospero::GpuEnumValue(Prospero::ChannelOrder::kAltReversed)) { - return {VK_FORMAT_R8_UNORM, 1}; + return {vk::Format::eR8Unorm, 1}; } if (is(Prospero::ChannelLayout::k8_8, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R8G8_UNORM, 2}; + return {vk::Format::eR8G8Unorm, 2}; } if (is(Prospero::ChannelLayout::k8_8_8_8, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R8G8B8A8_UNORM, 4}; + return {vk::Format::eR8G8B8A8Unorm, 4}; } if (is(Prospero::ChannelLayout::k8_8_8_8, Prospero::ChannelType::kSNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R8G8B8A8_SNORM, 4}; + return {vk::Format::eR8G8B8A8Snorm, 4}; } if (is(Prospero::ChannelLayout::k8_8_8_8, Prospero::ChannelType::kSrgb, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R8G8B8A8_SRGB, 4}; + return {vk::Format::eR8G8B8A8Srgb, 4}; } if (is(Prospero::ChannelLayout::k8_8_8_8, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kAlt)) { - return {VK_FORMAT_B8G8R8A8_UNORM, 4}; + return {vk::Format::eB8G8R8A8Unorm, 4}; } if (is(Prospero::ChannelLayout::k8_8_8_8, Prospero::ChannelType::kSNorm, Prospero::ChannelOrder::kAlt)) { - return {VK_FORMAT_B8G8R8A8_SNORM, 4}; + return {vk::Format::eB8G8R8A8Snorm, 4}; } if (is(Prospero::ChannelLayout::k8_8_8_8, Prospero::ChannelType::kSrgb, Prospero::ChannelOrder::kAlt)) { - return {VK_FORMAT_B8G8R8A8_SRGB, 4}; + return {vk::Format::eB8G8R8A8Srgb, 4}; } if (is(Prospero::ChannelLayout::k5_5_5_1, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R5G5B5A1_UNORM_PACK16, 2}; + return {vk::Format::eR5G5B5A1UnormPack16, 2}; } if (is(Prospero::ChannelLayout::k4_4_4_4, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kReversed)) { - return {VK_FORMAT_B4G4R4A4_UNORM_PACK16, 2}; + return {vk::Format::eB4G4R4A4UnormPack16, 2}; } if (is(Prospero::ChannelLayout::k10_10_10_2, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4}; + return {vk::Format::eA2B10G10R10UnormPack32, 4}; } if (is(Prospero::ChannelLayout::k10_10_10_2, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kAlt)) { - return {VK_FORMAT_A2R10G10B10_UNORM_PACK32, 4}; + return {vk::Format::eA2R10G10B10UnormPack32, 4}; } if (is(Prospero::ChannelLayout::k11_11_10, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_B10G11R11_UFLOAT_PACK32, 4}; + return {vk::Format::eB10G11R11UfloatPack32, 4}; } if (is(Prospero::ChannelLayout::k16, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16_UNORM, 2}; + return {vk::Format::eR16Unorm, 2}; } if (is(Prospero::ChannelLayout::k16, Prospero::ChannelType::kUInt, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16_UINT, 2}; + return {vk::Format::eR16Uint, 2}; } if (is(Prospero::ChannelLayout::k16, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16_SFLOAT, 2}; + return {vk::Format::eR16Sfloat, 2}; } if (is(Prospero::ChannelLayout::k16_16, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16G16_UNORM, 4}; + return {vk::Format::eR16G16Unorm, 4}; } if (is(Prospero::ChannelLayout::k16_16, Prospero::ChannelType::kSNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16G16_SNORM, 4}; + return {vk::Format::eR16G16Snorm, 4}; } if (is(Prospero::ChannelLayout::k16_16, Prospero::ChannelType::kUInt, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16G16_UINT, 4}; + return {vk::Format::eR16G16Uint, 4}; } if (is(Prospero::ChannelLayout::k16_16, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16G16_SFLOAT, 4}; + return {vk::Format::eR16G16Sfloat, 4}; } if (is(Prospero::ChannelLayout::k16_16_16_16, Prospero::ChannelType::kUNorm, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16G16B16A16_UNORM, 8}; + return {vk::Format::eR16G16B16A16Unorm, 8}; } if (is(Prospero::ChannelLayout::k16_16_16_16, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R16G16B16A16_SFLOAT, 8}; + return {vk::Format::eR16G16B16A16Sfloat, 8}; } if (is(Prospero::ChannelLayout::k16_16_16_16, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kAlt)) { - return {VK_FORMAT_R16G16B16A16_SFLOAT, 8, Prospero::ColorMappingBgra}; + return {vk::Format::eR16G16B16A16Sfloat, 8, Prospero::ColorMappingBgra}; } if (is(Prospero::ChannelLayout::k16_16_16_16, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kReversed)) { - return {VK_FORMAT_R16G16B16A16_SFLOAT, 8, Prospero::ColorMappingAbgr}; + return {vk::Format::eR16G16B16A16Sfloat, 8, Prospero::ColorMappingAbgr}; } if (is(Prospero::ChannelLayout::k32, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R32_SFLOAT, 4}; + return {vk::Format::eR32Sfloat, 4}; } if (is(Prospero::ChannelLayout::k32_32, Prospero::ChannelType::kUInt, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R32G32_UINT, 8}; + return {vk::Format::eR32G32Uint, 8}; } if (is(Prospero::ChannelLayout::k32_32, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R32G32_SFLOAT, 8}; + return {vk::Format::eR32G32Sfloat, 8}; } if (is(Prospero::ChannelLayout::k32_32_32_32, Prospero::ChannelType::kFloat, Prospero::ChannelOrder::kStandard)) { - return {VK_FORMAT_R32G32B32A32_SFLOAT, 16}; + return {vk::Format::eR32G32B32A32Sfloat, 16}; } EXIT("unsupported render-target format combination: layout=%u type=%u order=%u\n", raw_layout, raw_type, raw_order); @@ -209,7 +209,7 @@ void TextureCopyBufferBytes(GraphicContext* ctx, VulkanBuffer* src_buffer, return; } - if ((src_buffer->memory.property & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) { + if (src_buffer->memory.property & vk::MemoryPropertyFlagBits::eHostVisible) { void* data = nullptr; VulkanMapMemory(ctx, &src_buffer->memory, &data); std::memcpy(dst->Data(), static_cast(data) + src_buffer_offset, available); @@ -218,10 +218,10 @@ void TextureCopyBufferBytes(GraphicContext* ctx, VulkanBuffer* src_buffer, } VulkanBuffer readback {}; - readback.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; - readback.memory.property = static_cast(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + readback.usage = vk::BufferUsageFlagBits::eTransferDst; + readback.memory.property = vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent | + vk::MemoryPropertyFlagBits::eHostCached; VulkanCreateBuffer(ctx, (src_buffer_offset + available + 3u) & ~uint64_t {3}, &readback); UtilCopyBuffer(src_buffer, &readback, src_buffer_offset + available); @@ -233,25 +233,25 @@ void TextureCopyBufferBytes(GraphicContext* ctx, VulkanBuffer* src_buffer, VulkanDeleteBuffer(ctx, &readback); } -VkComponentSwizzle TextureGetComponentSwizzle(uint8_t s) { +vk::ComponentSwizzle TextureGetComponentSwizzle(uint8_t s) { switch (static_cast(s)) { - case Prospero::CompSwizzle::kZero: return VK_COMPONENT_SWIZZLE_ZERO; - case Prospero::CompSwizzle::kOne: return VK_COMPONENT_SWIZZLE_ONE; - case Prospero::CompSwizzle::kRed: return VK_COMPONENT_SWIZZLE_R; - case Prospero::CompSwizzle::kGreen: return VK_COMPONENT_SWIZZLE_G; - case Prospero::CompSwizzle::kBlue: return VK_COMPONENT_SWIZZLE_B; - case Prospero::CompSwizzle::kAlpha: return VK_COMPONENT_SWIZZLE_A; + case Prospero::CompSwizzle::kZero: return vk::ComponentSwizzle::eZero; + case Prospero::CompSwizzle::kOne: return vk::ComponentSwizzle::eOne; + case Prospero::CompSwizzle::kRed: return vk::ComponentSwizzle::eR; + case Prospero::CompSwizzle::kGreen: return vk::ComponentSwizzle::eG; + case Prospero::CompSwizzle::kBlue: return vk::ComponentSwizzle::eB; + case Prospero::CompSwizzle::kAlpha: return vk::ComponentSwizzle::eA; default: EXIT("unknown swizzle: %d\n", static_cast(s)); } - return VK_COMPONENT_SWIZZLE_IDENTITY; + return vk::ComponentSwizzle::eIdentity; } static uint32_t TextureGetDstSel(uint32_t swizzle, uint32_t channel) { return (swizzle >> (channel * 3u)) & 0x7u; } -VkComponentMapping TextureGetComponentMapping(uint32_t swizzle) { - VkComponentMapping components {}; +vk::ComponentMapping TextureGetComponentMapping(uint32_t swizzle) { + vk::ComponentMapping components {}; components.r = TextureGetComponentSwizzle(static_cast(TextureGetDstSel(swizzle, 0))); components.g = TextureGetComponentSwizzle(static_cast(TextureGetDstSel(swizzle, 1))); components.b = TextureGetComponentSwizzle(static_cast(TextureGetDstSel(swizzle, 2))); @@ -259,57 +259,63 @@ VkComponentMapping TextureGetComponentMapping(uint32_t swizzle) { return components; } -bool TextureCheckFormat(GraphicContext* ctx, VkImageCreateInfo* image_info) { - VkImageFormatProperties props {}; +bool TextureCheckFormat(GraphicContext* ctx, vk::ImageCreateInfo* image_info) { + vk::ImageFormatProperties props {}; if (ctx->GetImageFormatProperties(image_info->format, image_info->imageType, image_info->tiling, image_info->usage, image_info->flags, - &props) == VK_ERROR_FORMAT_NOT_SUPPORTED) { - auto apply_fallback = [&](VkFormat replacement, const char* message) { + &props) == vk::Result::eErrorFormatNotSupported) { + auto apply_fallback = [&](vk::Format replacement, const char* message) { image_info->format = replacement; const bool result = TextureCheckFormat(ctx, image_info); LOGF("%s [%s]\n", message, (!result ? "FAIL" : "SUCCESS")); return result; }; - if (image_info->format == VK_FORMAT_R8G8B8A8_SRGB) { + if (image_info->format == vk::Format::eR8G8B8A8Srgb) { // TODO() convert SRGB -> LINEAR in shader - return apply_fallback(VK_FORMAT_R8G8B8A8_UNORM, - "replace VK_FORMAT_R8G8B8A8_SRGB => VK_FORMAT_R8G8B8A8_UNORM"); + return apply_fallback( + vk::Format::eR8G8B8A8Unorm, + "replace vk::Format::eR8G8B8A8Srgb => vk::Format::eR8G8B8A8Unorm"); } - if (image_info->format == VK_FORMAT_B8G8R8A8_SRGB) { + if (image_info->format == vk::Format::eB8G8R8A8Srgb) { // TODO() convert SRGB -> LINEAR in shader - return apply_fallback(VK_FORMAT_B8G8R8A8_UNORM, - "replace VK_FORMAT_B8G8R8A8_SRGB => VK_FORMAT_B8G8R8A8_UNORM"); + return apply_fallback( + vk::Format::eB8G8R8A8Unorm, + "replace vk::Format::eB8G8R8A8Srgb => vk::Format::eB8G8R8A8Unorm"); } return false; } return true; } -static bool TextureCheckFormatExact(GraphicContext* ctx, const VkImageCreateInfo& image_info) { - VkImageFormatProperties props {}; +static bool TextureCheckFormatExact(GraphicContext* ctx, const vk::ImageCreateInfo& image_info) { + vk::ImageFormatProperties props {}; return ctx->GetImageFormatProperties(image_info.format, image_info.imageType, image_info.tiling, image_info.usage, image_info.flags, - &props) != VK_ERROR_FORMAT_NOT_SUPPORTED; + &props) != vk::Result::eErrorFormatNotSupported; } -bool TextureCheckStorageSwizzle(VkImageCreateInfo* image_info, VkComponentMapping* components) { - if ((image_info->usage & VK_IMAGE_USAGE_STORAGE_BIT) != 0) { - if (components->r == VK_COMPONENT_SWIZZLE_R && components->g == VK_COMPONENT_SWIZZLE_G && - components->b == VK_COMPONENT_SWIZZLE_B && components->a == VK_COMPONENT_SWIZZLE_A) { +bool TextureCheckStorageSwizzle(vk::ImageCreateInfo* image_info, vk::ComponentMapping* components) { + if (image_info->usage & vk::ImageUsageFlagBits::eStorage) { + if (components->r == vk::ComponentSwizzle::eR && + components->g == vk::ComponentSwizzle::eG && + components->b == vk::ComponentSwizzle::eB && + components->a == vk::ComponentSwizzle::eA) { return true; } - if (components->r == VK_COMPONENT_SWIZZLE_B && components->g == VK_COMPONENT_SWIZZLE_G && - components->b == VK_COMPONENT_SWIZZLE_R && components->a == VK_COMPONENT_SWIZZLE_A && - image_info->format == VK_FORMAT_R8G8B8A8_SRGB) { - LOGF("replace VK_FORMAT_R8G8B8A8_SRGB => VK_FORMAT_B8G8R8A8_SRGB\n"); + if (components->r == vk::ComponentSwizzle::eB && + components->g == vk::ComponentSwizzle::eG && + components->b == vk::ComponentSwizzle::eR && + components->a == vk::ComponentSwizzle::eA && + image_info->format == vk::Format::eR8G8B8A8Srgb) { + LOGF("replace vk::Format::eR8G8B8A8Srgb => vk::Format::eB8G8R8A8Srgb\n"); - components->r = VK_COMPONENT_SWIZZLE_R; - components->g = VK_COMPONENT_SWIZZLE_G; - components->b = VK_COMPONENT_SWIZZLE_B; - components->a = VK_COMPONENT_SWIZZLE_A; - image_info->format = VK_FORMAT_B8G8R8A8_SRGB; + components->r = vk::ComponentSwizzle::eR; + components->g = vk::ComponentSwizzle::eG; + components->b = vk::ComponentSwizzle::eB; + components->a = vk::ComponentSwizzle::eA; + image_info->format = vk::Format::eB8G8R8A8Srgb; return true; } @@ -320,35 +326,36 @@ bool TextureCheckStorageSwizzle(VkImageCreateInfo* image_info, VkComponentMappin return true; } -VkImageUsageFlags TextureGetUsage(TextureFormatUsage usage) { - VkImageUsageFlags vk_usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; +vk::ImageUsageFlags TextureGetUsage(TextureFormatUsage usage) { + vk::ImageUsageFlags vk_usage = + vk::ImageUsageFlagBits::eTransferDst | vk::ImageUsageFlagBits::eTransferSrc; if (TextureHasFormatUsage(usage, TextureFormatUsage::Sampled)) { - vk_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; + vk_usage |= vk::ImageUsageFlagBits::eSampled; } if (TextureHasFormatUsage(usage, TextureFormatUsage::Storage)) { - vk_usage |= VK_IMAGE_USAGE_STORAGE_BIT; + vk_usage |= vk::ImageUsageFlagBits::eStorage; } return vk_usage; } -VkImageUsageFlags TextureGetViewUsage(TextureFormatUsage usage) { - VkImageUsageFlags vk_usage = 0; +vk::ImageUsageFlags TextureGetViewUsage(TextureFormatUsage usage) { + vk::ImageUsageFlags vk_usage = {}; if (TextureHasFormatUsage(usage, TextureFormatUsage::Sampled)) { - vk_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; + vk_usage |= vk::ImageUsageFlagBits::eSampled; } if (TextureHasFormatUsage(usage, TextureFormatUsage::Storage)) { - vk_usage |= VK_IMAGE_USAGE_STORAGE_BIT; + vk_usage |= vk::ImageUsageFlagBits::eStorage; } return vk_usage; } -VkFormat TextureGetFormat(uint32_t fmt, [[maybe_unused]] TextureFormatUsage usage) { +vk::Format TextureGetFormat(uint32_t fmt, [[maybe_unused]] TextureFormatUsage usage) { const auto vk_format = Prospero::SurfaceFormat(fmt); - if (vk_format != VK_FORMAT_UNDEFINED) { + if (vk_format != vk::Format::eUndefined) { return vk_format; } EXIT("unknown format: fmt = %u\n", fmt); - return VK_FORMAT_UNDEFINED; + return vk::Format::eUndefined; } static uint32_t AlignUpU32(uint32_t value, uint32_t alignment) { @@ -426,13 +433,13 @@ static bool CalcStandard4kbVolumeMipLayout(uint32_t format, uint32_t pitch, uint return out->block_slice_size != 0; } -uint32_t TextureGetAtlasSliceYStride(VkFormat format, uint32_t mip_height, uint32_t depth, +uint32_t TextureGetAtlasSliceYStride(vk::Format format, uint32_t mip_height, uint32_t depth, uint64_t levels) { return (depth > 1 && levels > 1 && UtilIsBcFormat(format) ? AlignUpU32(mip_height, 4u) : mip_height); } -uint32_t TextureCalcStackedImageHeight(VkFormat format, uint32_t height, uint32_t depth, +uint32_t TextureCalcStackedImageHeight(vk::Format format, uint32_t height, uint32_t depth, uint64_t levels) { auto image_height = height * depth; if (depth <= 1 || levels <= 1 || !UtilIsBcFormat(format)) { @@ -452,7 +459,7 @@ uint32_t TextureCalcStackedImageHeight(VkFormat format, uint32_t height, uint32_ return image_height; } -uint32_t TextureCalcMipmapAtlasImageHeight(VkFormat format, uint32_t width, uint32_t height, +uint32_t TextureCalcMipmapAtlasImageHeight(vk::Format format, uint32_t width, uint32_t height, uint32_t depth, uint64_t levels) { auto image_height = height * depth; if (levels <= 1) { @@ -495,8 +502,8 @@ bool TextureCanCreateCubeView(uint64_t type, uint32_t base_array, uint32_t layer layer_count % 6u == 0; } -VkComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, VulkanMemory* mem, - const TextureImageCreateParams& params) { +vk::ComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, VulkanMemory* mem, + const TextureImageCreateParams& params) { EXIT_IF(ctx == nullptr); EXIT_IF(vk_obj == nullptr); EXIT_IF(mem == nullptr); @@ -506,7 +513,7 @@ VkComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, const bool volume_texture = TextureIs3DTexture(params.type); auto pixel_format = TextureGetFormat(params.fmt, params.format_usage); - EXIT_NOT_IMPLEMENTED(pixel_format == VK_FORMAT_UNDEFINED); + EXIT_NOT_IMPLEMENTED(pixel_format == vk::Format::eUndefined); EXIT_NOT_IMPLEMENTED(params.width == 0); EXIT_NOT_IMPLEMENTED(params.height == 0); EXIT_NOT_IMPLEMENTED(params.levels == 0 || params.levels > 16); @@ -529,30 +536,31 @@ VkComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, image_mips = static_cast(params.levels); } - VkComponentMapping components = + vk::ComponentMapping components = TextureGetComponentMapping(static_cast(params.swizzle)); - VkImageCreateInfo image_info {}; - image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + vk::ImageCreateInfo image_info {}; + image_info.sType = vk::StructureType::eImageCreateInfo; image_info.pNext = nullptr; image_info.flags = (params.allow_cube_view && TextureCanCreateCubeView(params.type, 0, params.depth) - ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT - : 0) | - (volume_texture ? VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT : 0) | - (params.compatible_format_views ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0); - image_info.imageType = (volume_texture ? VK_IMAGE_TYPE_3D : VK_IMAGE_TYPE_2D); + ? vk::ImageCreateFlagBits::eCubeCompatible + : vk::ImageCreateFlags {}) | + (volume_texture ? vk::ImageCreateFlagBits::e2DArrayCompatible : vk::ImageCreateFlags {}) | + (params.compatible_format_views ? vk::ImageCreateFlagBits::eMutableFormat + : vk::ImageCreateFlags {}); + image_info.imageType = (volume_texture ? vk::ImageType::e3D : vk::ImageType::e2D); image_info.extent.width = static_cast(params.width); image_info.extent.height = image_height; image_info.extent.depth = (volume_texture ? params.depth : 1); image_info.mipLevels = image_mips; image_info.arrayLayers = (array_texture ? params.depth : 1); image_info.format = pixel_format; - image_info.tiling = VK_IMAGE_TILING_OPTIMAL; - image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + image_info.tiling = vk::ImageTiling::eOptimal; + image_info.initialLayout = vk::ImageLayout::eUndefined; image_info.usage = TextureGetUsage(params.format_usage); - image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - image_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_info.sharingMode = vk::SharingMode::eExclusive; + image_info.samples = vk::SampleCountFlagBits::e1; const bool storage_view = TextureHasFormatUsage(params.view_usage, TextureFormatUsage::Storage); if (storage_view && !TextureCheckStorageSwizzle(&image_info, &components)) { @@ -565,10 +573,10 @@ VkComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, LOGF("\t %s swizzle 0x%08" PRIx64 " is not supported, using identity mapping\n", params.owner, params.swizzle); } - components.r = VK_COMPONENT_SWIZZLE_R; - components.g = VK_COMPONENT_SWIZZLE_G; - components.b = VK_COMPONENT_SWIZZLE_B; - components.a = VK_COMPONENT_SWIZZLE_A; + components.r = vk::ComponentSwizzle::eR; + components.g = vk::ComponentSwizzle::eG; + components.b = vk::ComponentSwizzle::eB; + components.a = vk::ComponentSwizzle::eA; } const auto view_checked_format = image_info.format; @@ -612,7 +620,7 @@ VkComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, UtilResetImageViews(vk_obj); - mem->property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + mem->property = vk::MemoryPropertyFlagBits::eDeviceLocal; bool created = VulkanCreateImage(ctx, &image_info, vk_obj, mem); EXIT_NOT_IMPLEMENTED(!created); @@ -623,7 +631,7 @@ VkComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, } void TextureCreateImageViews(GraphicContext* ctx, VulkanImage* vk_obj, - VkComponentMapping components, uint64_t type, uint32_t base_array, + vk::ComponentMapping components, uint64_t type, uint32_t base_array, uint32_t base_level, uint32_t level_count, uint32_t depth, bool allow_cube_view, TextureFormatUsage view_usage) { EXIT_IF(ctx == nullptr); @@ -635,44 +643,44 @@ void TextureCreateImageViews(GraphicContext* ctx, VulkanImage* vk_obj, const auto layer_count = (layered_texture && base_array < depth ? depth - base_array : 1u); const auto volume_slices = std::max(depth >> base_level, 1u); - VkImageViewUsageCreateInfo usage_info {}; - usage_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO; + vk::ImageViewUsageCreateInfo usage_info {}; + usage_info.sType = vk::StructureType::eImageViewUsageCreateInfo; usage_info.pNext = nullptr; usage_info.usage = TextureGetViewUsage(view_usage); - VkImageViewCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - create_info.pNext = (usage_info.usage != 0 ? &usage_info : nullptr); - create_info.flags = 0; + vk::ImageViewCreateInfo create_info {}; + create_info.sType = vk::StructureType::eImageViewCreateInfo; + create_info.pNext = (usage_info.usage ? &usage_info : nullptr); + create_info.flags = {}; create_info.image = vk_obj->image; - create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + create_info.viewType = vk::ImageViewType::e2D; create_info.format = vk_obj->format; create_info.components = components; - create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + create_info.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; create_info.subresourceRange.baseArrayLayer = (layered_texture ? base_array : 0); create_info.subresourceRange.baseMipLevel = base_level; create_info.subresourceRange.layerCount = layer_count; create_info.subresourceRange.levelCount = level_count; if (volume_texture) { - create_info.viewType = VK_IMAGE_VIEW_TYPE_3D; + create_info.viewType = vk::ImageViewType::e3D; create_info.subresourceRange.baseArrayLayer = 0; create_info.subresourceRange.layerCount = 1; } else if (allow_cube_view && TextureCanCreateCubeView(type, base_array, layer_count)) { create_info.viewType = - (layer_count > 6 ? VK_IMAGE_VIEW_TYPE_CUBE_ARRAY : VK_IMAGE_VIEW_TYPE_CUBE); + (layer_count > 6 ? vk::ImageViewType::eCubeArray : vk::ImageViewType::eCube); } else if (layered_texture) { - create_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; + create_info.viewType = vk::ImageViewType::e2DArray; } - vkCreateImageView(ctx->device, &create_info, nullptr, - &vk_obj->image_view[VulkanImage::VIEW_DEFAULT]); + ctx->device.createImageView(&create_info, nullptr, + &vk_obj->image_view[VulkanImage::VIEW_DEFAULT]); EXIT_NOT_IMPLEMENTED(vk_obj->image_view[VulkanImage::VIEW_DEFAULT] == nullptr); if (!volume_texture || depth >= 1) { - create_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; + create_info.viewType = vk::ImageViewType::e2DArray; create_info.subresourceRange.layerCount = (volume_texture ? volume_slices : layer_count); - vkCreateImageView(ctx->device, &create_info, nullptr, - &vk_obj->image_view[VulkanImage::VIEW_DEFAULT_ARRAY]); + ctx->device.createImageView(&create_info, nullptr, + &vk_obj->image_view[VulkanImage::VIEW_DEFAULT_ARRAY]); EXIT_NOT_IMPLEMENTED(vk_obj->image_view[VulkanImage::VIEW_DEFAULT_ARRAY] == nullptr); } } @@ -827,11 +835,10 @@ TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint64_t width, uint64 return layout; } -std::vector -TextureBuildUploadRegions(const TextureUploadLayout& layout, VkFormat image_format, uint32_t width, - uint32_t height, uint32_t depth, uint64_t levels, bool array_texture, - bool volume_texture, TextureUploadDestination destination, - TextureUploadSliceLayout slice_layout) { +std::vector TextureBuildUploadRegions( + const TextureUploadLayout& layout, vk::Format image_format, uint32_t width, uint32_t height, + uint32_t depth, uint64_t levels, bool array_texture, bool volume_texture, + TextureUploadDestination destination, TextureUploadSliceLayout slice_layout) { uint32_t mip_width = width; uint32_t mip_height = height; uint32_t mip_pitch = layout.pitch; @@ -930,8 +937,8 @@ static uint64_t FmaskRegionCopySize(const BufferImageCopy& region) { } static void UploadFmaskIdentity(GraphicContext* ctx, VulkanImage* vk_obj, - const std::vector& regions, uint64_t dst_layout, - const char* owner) { + const std::vector& regions, + vk::ImageLayout dst_layout, const char* owner) { constexpr uint32_t kIdentityFmaskPattern = 0x76543210u; std::vector upload_regions = regions; @@ -961,7 +968,7 @@ void TextureUploadGuestImage(GraphicContext* ctx, VulkanImage* vk_obj, const voi const TextureUploadLayout& layout, uint32_t fmt, uint64_t width, uint64_t height, uint32_t depth, uint64_t levels, TextureUploadSliceLayout source_slice_layout, const char* owner, - uint64_t dst_layout) { + vk::ImageLayout dst_layout) { if (fmt == 0) { EXIT("%s: legacy texture upload format unsupported: fmt=0 tile=%u size=%" PRIu64 " extent=%" PRIu64 "x%" PRIu64 " depth=%u pitch=%u levels=%" PRIu64 "\n", diff --git a/src/graphics/host_gpu/objects/textureCommon.h b/src/graphics/host_gpu/objects/textureCommon.h index 42e3b9511..7842cd14a 100644 --- a/src/graphics/host_gpu/objects/textureCommon.h +++ b/src/graphics/host_gpu/objects/textureCommon.h @@ -6,9 +6,9 @@ #include "graphics/guest_gpu/gpu_defs.h" #include "graphics/guest_gpu/tile.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include -#include namespace Libs::Graphics { @@ -48,7 +48,7 @@ enum class TextureUploadDestination { MipLevels, MipAtlas }; enum class TextureUploadSliceLayout { MipChainPerSlice, MipLevelPerSlice }; struct RenderTargetFormatInfo { - VkFormat format = VK_FORMAT_UNDEFINED; + vk::Format format = vk::Format::eUndefined; uint32_t bytes_per_element = 0; Prospero::ColorComponentMapping export_mapping; }; @@ -87,28 +87,28 @@ struct TextureImageCreateParams { const char* owner = nullptr; }; -VkComponentSwizzle TextureGetComponentSwizzle(uint8_t s); -VkComponentMapping TextureGetComponentMapping(uint32_t swizzle); -bool TextureCheckFormat(GraphicContext* ctx, VkImageCreateInfo* image_info); -bool TextureCheckStorageSwizzle(VkImageCreateInfo* image_info, VkComponentMapping* components); -VkImageUsageFlags TextureGetUsage(TextureFormatUsage usage); -VkImageUsageFlags TextureGetViewUsage(TextureFormatUsage usage); -VkFormat TextureGetFormat(uint32_t fmt, TextureFormatUsage usage); +vk::ComponentSwizzle TextureGetComponentSwizzle(uint8_t s); +vk::ComponentMapping TextureGetComponentMapping(uint32_t swizzle); +bool TextureCheckFormat(GraphicContext* ctx, vk::ImageCreateInfo* image_info); +bool TextureCheckStorageSwizzle(vk::ImageCreateInfo* image_info, vk::ComponentMapping* components); +vk::ImageUsageFlags TextureGetUsage(TextureFormatUsage usage); +vk::ImageUsageFlags TextureGetViewUsage(TextureFormatUsage usage); +vk::Format TextureGetFormat(uint32_t fmt, TextureFormatUsage usage); RenderTargetFormatInfo TextureGetRenderTargetFormat(uint32_t layout, uint32_t type, uint32_t order); -uint32_t TextureGetAtlasSliceYStride(VkFormat format, uint32_t mip_height, uint32_t depth, +uint32_t TextureGetAtlasSliceYStride(vk::Format format, uint32_t mip_height, uint32_t depth, uint64_t levels); -uint32_t TextureCalcStackedImageHeight(VkFormat format, uint32_t height, uint32_t depth, +uint32_t TextureCalcStackedImageHeight(vk::Format format, uint32_t height, uint32_t depth, uint64_t levels); -uint32_t TextureCalcMipmapAtlasImageHeight(VkFormat format, uint32_t width, uint32_t height, +uint32_t TextureCalcMipmapAtlasImageHeight(vk::Format format, uint32_t width, uint32_t height, uint32_t depth, uint64_t levels); bool TextureIs3DTexture(uint64_t type); bool TextureIsCubeTexture(uint64_t type); bool TextureIsLayeredTexture(uint64_t type); bool TextureCanCreateCubeView(uint64_t type, uint32_t base_array, uint32_t layer_count); -VkComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, VulkanMemory* mem, - const TextureImageCreateParams& params); +vk::ComponentMapping TextureCreateImage(GraphicContext* ctx, VulkanImage* vk_obj, VulkanMemory* mem, + const TextureImageCreateParams& params); void TextureCreateImageViews(GraphicContext* ctx, VulkanImage* vk_obj, - VkComponentMapping components, uint64_t type, uint32_t base_array, + vk::ComponentMapping components, uint64_t type, uint32_t base_array, uint32_t base_level, uint32_t level_count, uint32_t depth, bool allow_cube_view, TextureFormatUsage view_usage); TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint64_t width, uint64_t height, @@ -123,11 +123,10 @@ uint64_t TextureUploadSliceSourceOffset(const TextureUploadLayout& layout, uint3 uint64_t TextureCalcUploadSize(const TextureUploadLayout& layout, const std::vector& regions, uint64_t levels, uint32_t depth, TextureUploadSliceLayout source_slice_layout); -std::vector -TextureBuildUploadRegions(const TextureUploadLayout& layout, VkFormat image_format, uint32_t width, - uint32_t height, uint32_t depth, uint64_t levels, bool array_texture, - bool volume_texture, TextureUploadDestination destination, - TextureUploadSliceLayout slice_layout); +std::vector TextureBuildUploadRegions( + const TextureUploadLayout& layout, vk::Format image_format, uint32_t width, uint32_t height, + uint32_t depth, uint64_t levels, bool array_texture, bool volume_texture, + TextureUploadDestination destination, TextureUploadSliceLayout slice_layout); void TextureCopyBufferBytes(GraphicContext* ctx, VulkanBuffer* src_buffer, uint64_t src_buffer_offset, uint64_t copy_size, UtilScratchBuffer* dst); void TextureUploadGuestImage(GraphicContext* ctx, VulkanImage* vk_obj, const void* src_data, @@ -135,7 +134,7 @@ void TextureUploadGuestImage(GraphicContext* ctx, VulkanImage* vk_obj, const voi const TextureUploadLayout& layout, uint32_t fmt, uint64_t width, uint64_t height, uint32_t depth, uint64_t levels, TextureUploadSliceLayout source_slice_layout, const char* owner, - uint64_t dst_layout); + vk::ImageLayout dst_layout); } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/bufferCache.cpp b/src/graphics/host_gpu/renderer/bufferCache.cpp index 3bf02a739..f749f398d 100644 --- a/src/graphics/host_gpu/renderer/bufferCache.cpp +++ b/src/graphics/host_gpu/renderer/bufferCache.cpp @@ -421,10 +421,10 @@ struct BufferCache::ReadbackWorker { i, family, ctx->queues[i].family); } } - readback.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; - readback.memory.property = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + readback.usage = vk::BufferUsageFlagBits::eTransferDst; + readback.memory.property = vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent | + vk::MemoryPropertyFlagBits::eHostCached; VulkanCreateBuffer(ctx, READBACK_CAPACITY, &readback); VulkanMapMemory(ctx, &readback.memory, &mapped); command = std::make_unique(GraphicContext::QUEUE_UTIL); @@ -456,9 +456,9 @@ struct BufferCache::ReadbackWorker { " page=0x%016" PRIx64 " buffer=0x%016" PRIx64 " size=0x%016" PRIx64 "\n", vaddr, page, cached.vaddr, cached.size); } - uint32_t data_offset = 0; - std::array copies {}; - std::array barriers {}; + uint32_t data_offset = 0; + std::array copies {}; + std::array barriers {}; cache.m_gpu_modified_ranges.ForEachIntersection( page, TRACKER_PAGE_SIZE, [&](RangeSet::Range range) { if (range_count == MAX_RANGES || (range.address - cached.vaddr) % 4 != 0 || @@ -475,9 +475,9 @@ struct BufferCache::ReadbackWorker { .dstOffset = data_offset, .size = range.size}; auto& barrier = barriers[range_count]; - barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; - barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + barrier.sType = vk::StructureType::eBufferMemoryBarrier; + barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite; + barrier.dstAccessMask = vk::AccessFlagBits::eTransferRead; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.buffer = cached.buffer->buffer; @@ -498,13 +498,13 @@ struct BufferCache::ReadbackWorker { " count=%u bytes=%u\n", page, range_count, data_offset); } - auto* vk_buffer = command->GetPool()->buffers[command->GetIndex()]; + auto vk_buffer = command->GetPool()->buffers[command->GetIndex()]; command->Begin(); - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, range_count, - barriers.data(), 0, nullptr); - vkCmdCopyBuffer(vk_buffer, cached.buffer->buffer, readback.buffer, range_count, - copies.data()); + vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer, vk::DependencyFlags {}, + 0, nullptr, range_count, barriers.data(), 0, nullptr); + vk_buffer.copyBuffer(cached.buffer->buffer, readback.buffer, range_count, + copies.data()); command->End(); command->Execute(); command->WaitForFenceAndReset(); @@ -687,10 +687,10 @@ std::pair BufferCache::ObtainBuffer(CommandBuffer* com !texture_region.gpu_metadata_bytes) { std::array guest_data; if (Libs::LibKernel::Memory::TryReadBacking(vaddr, guest_data.data(), size)) { - VulkanBuffer* stream_buffer = nullptr; - VkDeviceSize stream_offset = 0; - VkDeviceSize stream_range = 0; - const auto stream_alignment = std::max(ctx->StorageMinAlignment(), 16); + VulkanBuffer* stream_buffer = nullptr; + vk::DeviceSize stream_offset = 0; + vk::DeviceSize stream_range = 0; + const auto stream_alignment = std::max(ctx->StorageMinAlignment(), 16); if (UploadHostData(command, ctx, guest_data.data(), size, stream_alignment, &stream_buffer, &stream_offset, &stream_range)) { return {stream_buffer, stream_offset}; @@ -795,20 +795,20 @@ std::pair BufferCache::ObtainBuffer(CommandBuffer* com cached->ctx = ctx; cached->buffer = MakeSharedVulkanBuffer(ctx); cached->buffer->usage = - VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | - VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - cached->buffer->memory.property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst | + vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer | + vk::BufferUsageFlagBits::eStorageBuffer; + cached->buffer->memory.property = vk::MemoryPropertyFlagBits::eDeviceLocal; VulkanCreateBuffer(ctx, cached->size, cached->buffer.get()); if (!overlaps.empty()) { - auto* vk_buffer = command->GetPool()->buffers[command->GetIndex()]; - std::vector before; + auto vk_buffer = command->GetPool()->buffers[command->GetIndex()]; + std::vector before; before.reserve(overlaps.size() + 1); for (const auto& overlap: overlaps) { - VkBufferMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; - barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + vk::BufferMemoryBarrier barrier {}; + barrier.sType = vk::StructureType::eBufferMemoryBarrier; + barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite; + barrier.dstAccessMask = vk::AccessFlagBits::eTransferRead; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.buffer = overlap->second->buffer->buffer; @@ -816,37 +816,38 @@ std::pair BufferCache::ObtainBuffer(CommandBuffer* com barrier.size = overlap->second->size; before.push_back(barrier); } - VkBufferMemoryBarrier destination {}; - destination.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; - destination.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + vk::BufferMemoryBarrier destination {}; + destination.sType = vk::StructureType::eBufferMemoryBarrier; + destination.dstAccessMask = vk::AccessFlagBits::eTransferWrite; destination.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; destination.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; destination.buffer = cached->buffer->buffer; destination.offset = 0; destination.size = cached->size; before.push_back(destination); - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, - nullptr, static_cast(before.size()), before.data(), 0, - nullptr); + vk_buffer.pipelineBarrier( + vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eTransfer, + vk::DependencyFlagBits::eByRegion, 0, nullptr, static_cast(before.size()), + before.data(), 0, nullptr); for (const auto& overlap: overlaps) { - const auto& old = *overlap->second; - const VkBufferCopy copy { + const auto& old = *overlap->second; + const vk::BufferCopy copy { .srcOffset = 0, .dstOffset = old.vaddr - cached->vaddr, .size = old.size}; - vkCmdCopyBuffer(vk_buffer, old.buffer->buffer, cached->buffer->buffer, 1, ©); + vk_buffer.copyBuffer(old.buffer->buffer, cached->buffer->buffer, 1, ©); } - VkBufferMemoryBarrier after {}; - after.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; - after.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - after.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; + vk::BufferMemoryBarrier after {}; + after.sType = vk::StructureType::eBufferMemoryBarrier; + after.srcAccessMask = vk::AccessFlagBits::eTransferWrite; + after.dstAccessMask = + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; after.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; after.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; after.buffer = cached->buffer->buffer; after.offset = 0; after.size = cached->size; - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, - nullptr, 1, &after, 0, nullptr); + vk_buffer.pipelineBarrier( + vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eAllCommands, + vk::DependencyFlagBits::eByRegion, 0, nullptr, 1, &after, 0, nullptr); for (const auto& overlap: overlaps) { command->RetainResourceUntilFence(overlap->second->buffer); m_buffers.erase(overlap); @@ -896,12 +897,13 @@ VulkanBuffer* BufferCache::ObtainNullBuffer(CommandBuffer* command, GraphicConte if (m_null_buffer == nullptr) { // robustBufferAccess makes every fetch safe; TODO: Use a // persistent 16-byte fallback when Vulkan null vertex descriptors are unavailable. - auto buffer = MakeSharedVulkanBuffer(ctx); - buffer->usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | - VK_BUFFER_USAGE_INDEX_BUFFER_BIT; - buffer->memory.property = static_cast(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + auto buffer = MakeSharedVulkanBuffer(ctx); + buffer->usage = vk::BufferUsageFlagBits::eStorageBuffer | + vk::BufferUsageFlagBits::eVertexBuffer | + vk::BufferUsageFlagBits::eIndexBuffer; + buffer->memory.property = vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent | + vk::MemoryPropertyFlagBits::eHostCached; VulkanCreateBuffer(ctx, 16, buffer.get()); void* data = nullptr; VulkanMapMemory(ctx, &buffer->memory, &data); @@ -1040,8 +1042,8 @@ BufferImageCopySource BufferCache::ObtainBufferForImage(uint64_t vaddr, uint64_t } namespace { -VkBufferMemoryBarrier MakeDmaBarrier(VulkanBuffer* buffer, uint64_t offset, uint64_t size, - VkAccessFlags source, VkAccessFlags destination) { +vk::BufferMemoryBarrier MakeDmaBarrier(VulkanBuffer* buffer, uint64_t offset, uint64_t size, + vk::AccessFlags source, vk::AccessFlags destination) { if (buffer == nullptr || buffer->buffer == nullptr || size == 0 || offset > buffer->buffer_size || size > buffer->buffer_size - offset) { EXIT("BufferCache: invalid DMA barrier, buffer=%p handle=%p offset=0x%016" PRIx64 @@ -1050,8 +1052,8 @@ VkBufferMemoryBarrier MakeDmaBarrier(VulkanBuffer* buffer, uint64_t offset, uint buffer == nullptr ? nullptr : static_cast(buffer->buffer), offset, size, buffer == nullptr ? 0 : buffer->buffer_size); } - VkBufferMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; + vk::BufferMemoryBarrier barrier {}; + barrier.sType = vk::StructureType::eBufferMemoryBarrier; barrier.srcAccessMask = source; barrier.dstAccessMask = destination; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; @@ -1062,7 +1064,7 @@ VkBufferMemoryBarrier MakeDmaBarrier(VulkanBuffer* buffer, uint64_t offset, uint return barrier; } -VkCommandBuffer GetDmaCommandBuffer(CommandBuffer* command) { +vk::CommandBuffer GetDmaCommandBuffer(CommandBuffer* command) { if (command == nullptr || command->IsInvalid() || command->GetPool() == nullptr || command->GetIndex() >= command->GetPool()->buffers_count) { EXIT("BufferCache: invalid DMA command buffer, command=%p\n", @@ -1113,19 +1115,20 @@ void BufferCache::FillBuffer(CommandBuffer* command, GraphicContext* ctx, uint64 } } const auto [dst, dst_offset] = ObtainBuffer(command, ctx, vaddr, size, true, false); - const auto before = MakeDmaBarrier(dst, dst_offset, size, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT); + const auto before = MakeDmaBarrier( + dst, dst_offset, size, vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eTransferWrite); const auto vk_buffer = GetDmaCommandBuffer(command); - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 1, - &before, 0, nullptr); - vkCmdFillBuffer(vk_buffer, dst->buffer, dst_offset, size, value); - const auto after = MakeDmaBarrier(dst, dst_offset, size, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT); - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, - nullptr, 1, &after, 0, nullptr); + vk_buffer.pipelineBarrier( + vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eTransfer, + vk::DependencyFlagBits::eByRegion, 0, nullptr, 1, &before, 0, nullptr); + vk_buffer.fillBuffer(dst->buffer, dst_offset, size, value); + const auto after = + MakeDmaBarrier(dst, dst_offset, size, vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite); + vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eAllCommands, + vk::DependencyFlagBits::eByRegion, 0, nullptr, 1, &after, 0, nullptr); } void BufferCache::CopyBuffer(CommandBuffer* command, GraphicContext* ctx, uint64_t dst_vaddr, @@ -1200,28 +1203,28 @@ void BufferCache::CopyBuffer(CommandBuffer* command, GraphicContext* ctx, uint64 " dst_offset=0x%016" PRIx64 " size=0x%016" PRIx64 "\n", src_offset, dst_offset, size); } - const VkBufferMemoryBarrier before[] = { + const vk::BufferMemoryBarrier before[] = { MakeDmaBarrier(dst, dst_offset, size, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT), - MakeDmaBarrier(src, src_offset, size, VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_READ_BIT), + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eTransferWrite), + MakeDmaBarrier(src, src_offset, size, vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eTransferRead), }; const auto vk_buffer = GetDmaCommandBuffer(command); - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 2, - before, 0, nullptr); - const VkBufferCopy copy {src_offset, dst_offset, size}; - vkCmdCopyBuffer(vk_buffer, src->buffer, dst->buffer, 1, ©); - const VkBufferMemoryBarrier after[] = { - MakeDmaBarrier(dst, dst_offset, size, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT), - MakeDmaBarrier(src, src_offset, size, VK_ACCESS_TRANSFER_READ_BIT, - VK_ACCESS_MEMORY_WRITE_BIT), + vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer, + vk::DependencyFlagBits::eByRegion, 0, nullptr, 2, before, 0, nullptr); + const vk::BufferCopy copy {src_offset, dst_offset, size}; + vk_buffer.copyBuffer(src->buffer, dst->buffer, 1, ©); + const vk::BufferMemoryBarrier after[] = { + MakeDmaBarrier(dst, dst_offset, size, vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite), + MakeDmaBarrier(src, src_offset, size, vk::AccessFlagBits::eTransferRead, + vk::AccessFlagBits::eMemoryWrite), }; - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, - nullptr, 2, after, 0, nullptr); + vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eAllCommands, + vk::DependencyFlagBits::eByRegion, 0, nullptr, 2, after, 0, nullptr); } bool BufferCache::HasPageOverlap(uint64_t vaddr, uint64_t size) { diff --git a/src/graphics/host_gpu/renderer/colorRenderTarget.cpp b/src/graphics/host_gpu/renderer/colorRenderTarget.cpp index 9218c67a3..cfdf75f2d 100644 --- a/src/graphics/host_gpu/renderer/colorRenderTarget.cpp +++ b/src/graphics/host_gpu/renderer/colorRenderTarget.cpp @@ -17,6 +17,7 @@ #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/displayBuffer.h" #include @@ -25,7 +26,6 @@ #include #include #include -#include namespace Libs::Graphics { @@ -71,11 +71,11 @@ static float ColorClearF16(uint32_t value) { std::ldexp(static_cast(0x400u | mantissa), static_cast(exponent) - 25); } -[[maybe_unused]] static VkClearColorValue ColorClearValue(const HW::RenderTarget& rt) { +[[maybe_unused]] static vk::ClearColorValue ColorClearValue(const HW::RenderTarget& rt) { const uint32_t c0 = rt.clear_word0.word0; const uint32_t c1 = rt.clear_word1.word1; - VkClearColorValue color {}; + vk::ClearColorValue color {}; switch (static_cast(rt.info.channel_type)) { case Prospero::ChannelType::kUNorm: @@ -312,7 +312,7 @@ void ResolveRenderColorTarget(uint64_t submit_id, CommandBuffer* buffer, const H r->base_addr = 0; r->vulkan_buffer = nullptr; r->vulkan_view = nullptr; - r->format = VK_FORMAT_UNDEFINED; + r->format = vk::Format::eUndefined; r->extent = {}; r->base_mip_level = 0; r->buffer_size = 0; @@ -480,8 +480,8 @@ void ResolveRenderColorTarget(uint64_t submit_id, CommandBuffer* buffer, const H if (!render_to_texture && (levels != 1 || rt.view.current_mip_level != 0)) { EXIT("mipmapped display render targets are unsupported\n"); } - const VkExtent2D view_extent = {std::max(width >> rt.view.current_mip_level, 1u), - std::max(height >> rt.view.current_mip_level, 1u)}; + const vk::Extent2D view_extent = {std::max(width >> rt.view.current_mip_level, 1u), + std::max(height >> rt.view.current_mip_level, 1u)}; auto decision_log_id = g_render_color_log_count.fetch_add(1); if (decision_log_id < 128 || !render_to_texture) { diff --git a/src/graphics/host_gpu/renderer/colorRenderTarget.h b/src/graphics/host_gpu/renderer/colorRenderTarget.h index 1ffe056e7..9e9b66c87 100644 --- a/src/graphics/host_gpu/renderer/colorRenderTarget.h +++ b/src/graphics/host_gpu/renderer/colorRenderTarget.h @@ -3,9 +3,9 @@ #include "graphics/guest_gpu/gpu_defs.h" #include "graphics/host_gpu/renderer/renderTarget.h" +#include "graphics/host_gpu/vulkanCommon.h" #include -#include namespace Libs::Graphics { @@ -25,9 +25,9 @@ enum class RenderColorType { struct RenderColorInfo { RenderColorType type = RenderColorType::NoColorOutput; VulkanImage* vulkan_buffer = nullptr; - VkImageView vulkan_view = nullptr; - VkFormat format = VK_FORMAT_UNDEFINED; - VkExtent2D extent = {}; + vk::ImageView vulkan_view = nullptr; + vk::Format format = vk::Format::eUndefined; + vk::Extent2D extent = {}; uint32_t base_mip_level = 0; uint32_t base_array_layer = 0; uint64_t base_addr = 0; @@ -35,7 +35,7 @@ struct RenderColorInfo { uint32_t target_slot = 0; Prospero::ColorComponentMapping export_mapping; bool color_clear_enable = false; - VkClearColorValue color_clear_value {}; + vk::ClearColorValue color_clear_value {}; }; void ResolveRenderColorTarget(uint64_t submit_id, CommandBuffer* buffer, const HW::Context& hw, diff --git a/src/graphics/host_gpu/renderer/context.cpp b/src/graphics/host_gpu/renderer/context.cpp index cf7031318..d815a8cd6 100644 --- a/src/graphics/host_gpu/renderer/context.cpp +++ b/src/graphics/host_gpu/renderer/context.cpp @@ -14,13 +14,13 @@ #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/utils.h" #include "graphics/host_gpu/vma.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/window.h" #include #include #include #include -#include namespace Libs::Graphics { static std::atomic g_command_buffer_submit_seq = 0; class CommandPool { @@ -103,51 +103,53 @@ void CommandPool::Create(int id) { pool = new VulkanCommandPool; - VkCommandPoolCreateInfo pool_info {}; - pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + vk::CommandPoolCreateInfo pool_info {}; + pool_info.sType = vk::StructureType::eCommandPoolCreateInfo; pool_info.pNext = nullptr; pool_info.queueFamilyIndex = ctx->queues[id].family; - pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + pool_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; - vkCreateCommandPool(ctx->device, &pool_info, nullptr, &pool->pool); + ctx->device.createCommandPool(&pool_info, nullptr, &pool->pool); EXIT_NOT_IMPLEMENTED(pool->pool == nullptr); pool->buffers_count = 8; - pool->buffers = std::make_unique(pool->buffers_count); - pool->fences = std::make_unique(pool->buffers_count); - pool->semaphores = std::make_unique(pool->buffers_count); + pool->buffers = std::make_unique(pool->buffers_count); + pool->fences = std::make_unique(pool->buffers_count); + pool->semaphores = std::make_unique(pool->buffers_count); pool->busy = std::make_unique(pool->buffers_count); - VkCommandBufferAllocateInfo alloc_info {}; - alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + vk::CommandBufferAllocateInfo alloc_info {}; + alloc_info.sType = vk::StructureType::eCommandBufferAllocateInfo; alloc_info.commandPool = pool->pool; - alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + alloc_info.level = vk::CommandBufferLevel::ePrimary; alloc_info.commandBufferCount = pool->buffers_count; - if (vkAllocateCommandBuffers(ctx->device, &alloc_info, pool->buffers.get()) != VK_SUCCESS) { + if (ctx->device.allocateCommandBuffers(&alloc_info, pool->buffers.get()) != + vk::Result::eSuccess) { EXIT("Can't allocate command buffers"); } for (uint32_t i = 0; i < pool->buffers_count; i++) { pool->busy[i] = false; - VkFenceCreateInfo fence_info {}; - fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + vk::FenceCreateInfo fence_info {}; + fence_info.sType = vk::StructureType::eFenceCreateInfo; fence_info.pNext = nullptr; - fence_info.flags = VK_FENCE_CREATE_SIGNALED_BIT; + fence_info.flags = vk::FenceCreateFlagBits::eSignaled; - if (vkCreateFence(ctx->device, &fence_info, nullptr, &pool->fences[i]) != VK_SUCCESS) { + if (ctx->device.createFence(&fence_info, nullptr, &pool->fences[i]) != + vk::Result::eSuccess) { EXIT("Can't create fence"); } - VkSemaphoreCreateInfo semaphore_info {}; - semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + vk::SemaphoreCreateInfo semaphore_info {}; + semaphore_info.sType = vk::StructureType::eSemaphoreCreateInfo; semaphore_info.pNext = nullptr; - semaphore_info.flags = 0; + semaphore_info.flags = {}; - if (vkCreateSemaphore(ctx->device, &semaphore_info, nullptr, &pool->semaphores[i]) != - VK_SUCCESS) { + if (ctx->device.createSemaphore(&semaphore_info, nullptr, &pool->semaphores[i]) != + vk::Result::eSuccess) { EXIT("Can't create semaphore"); } @@ -166,13 +168,13 @@ void CommandPool::DeleteAll() { EXIT_IF(ctx->device == nullptr); for (uint32_t i = 0; i < pool->buffers_count; i++) { - vkDestroySemaphore(ctx->device, pool->semaphores[i], nullptr); - vkDestroyFence(ctx->device, pool->fences[i], nullptr); + ctx->device.destroySemaphore(pool->semaphores[i], nullptr); + ctx->device.destroyFence(pool->fences[i], nullptr); } - vkFreeCommandBuffers(ctx->device, pool->pool, pool->buffers_count, pool->buffers.get()); + ctx->device.freeCommandBuffers(pool->pool, pool->buffers_count, pool->buffers.get()); - vkDestroyCommandPool(ctx->device, pool->pool, nullptr); + ctx->device.destroyCommandPool(pool->pool, nullptr); delete pool; pool = nullptr; @@ -202,7 +204,7 @@ void CommandBuffer::Allocate() { for (uint32_t i = 0; i < m_pool->buffers_count; i++) { if (!m_pool->busy[i]) { m_pool->busy[i] = true; - vkResetCommandBuffer(m_pool->buffers[i], VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); + m_pool->buffers[i].reset(vk::CommandBufferResetFlagBits::eReleaseResources); m_index = i; break; } @@ -221,7 +223,7 @@ void CommandBuffer::Free() { m_host_stream.Release(); m_pool->busy[m_index] = false; - vkResetCommandBuffer(m_pool->buffers[m_index], VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); + m_pool->buffers[m_index].reset(vk::CommandBufferResetFlagBits::eReleaseResources); RecycleDescriptorsAfterFence(); m_fence_resources.ReleaseAfterFence(); m_index = static_cast(-1); @@ -258,27 +260,27 @@ void CommandBuffer::RecycleDescriptorsAfterFence() { void CommandBuffer::Begin() const { EXIT_IF(IsInvalid()); - auto* buffer = m_pool->buffers[m_index]; + auto buffer = m_pool->buffers[m_index]; - VkCommandBufferBeginInfo begin_info {}; - begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + vk::CommandBufferBeginInfo begin_info {}; + begin_info.sType = vk::StructureType::eCommandBufferBeginInfo; begin_info.pNext = nullptr; - begin_info.flags = 0; + begin_info.flags = {}; begin_info.pInheritanceInfo = nullptr; - auto result = vkBeginCommandBuffer(buffer, &begin_info); + auto result = buffer.begin(&begin_info); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } void CommandBuffer::End() const { EXIT_IF(IsInvalid()); - auto* buffer = m_pool->buffers[m_index]; + auto buffer = m_pool->buffers[m_index]; - auto result = vkEndCommandBuffer(buffer); + auto result = buffer.end(); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } void CommandBuffer::SetDebugInfo(uint32_t op, uint64_t submit_id, uint32_t arg0, uint32_t arg1, @@ -296,11 +298,11 @@ void CommandBuffer::Execute() { EXIT_IF(IsInvalid()); EXIT_IF(m_execute); - auto* buffer = m_pool->buffers[m_index]; - auto* fence = m_pool->fences[m_index]; + auto buffer = m_pool->buffers[m_index]; + auto fence = m_pool->fences[m_index]; - VkSubmitInfo submit_info {}; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + vk::SubmitInfo submit_info {}; + submit_info.sType = vk::StructureType::eSubmitInfo; submit_info.pNext = nullptr; submit_info.waitSemaphoreCount = 0; submit_info.pWaitSemaphores = nullptr; @@ -314,12 +316,12 @@ void CommandBuffer::Execute() { const auto& queue = g_render_ctx->GetGraphicCtx()->queues[m_queue]; - auto result = vkResetFences(g_render_ctx->GetGraphicCtx()->device, 1, &fence); - if (result != VK_SUCCESS) { - LOGF("vkResetFences failed before submit: %s (%d)\n", string_VkResult(result), + auto result = g_render_ctx->GetGraphicCtx()->device.resetFences(1, &fence); + if (result != vk::Result::eSuccess) { + LOGF("vkResetFences failed before submit: %s (%d)\n", VulkanToString(result).c_str(), static_cast(result)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); if (queue.mutex != nullptr) { queue.mutex->Lock(); @@ -332,7 +334,7 @@ void CommandBuffer::Execute() { m_debug_arg2, m_debug_arg3, m_debug_arg4); } - result = vkQueueSubmit(queue.vk_queue, 1, &submit_info, fence); + result = queue.vk_queue.submit(1, &submit_info, fence); if (queue.mutex != nullptr) { queue.mutex->Unlock(); @@ -342,29 +344,29 @@ void CommandBuffer::Execute() { m_fence_waited = false; m_submit_seq = g_command_buffer_submit_seq.fetch_add(1, std::memory_order_relaxed) + 1; - if (result != VK_SUCCESS) { + if (result != vk::Result::eSuccess) { LOGF("vkQueueSubmit failed: %s (%d), queue=%d index=%u submit_seq=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64 " args=%u,%u,%u,%u,0x%016" PRIx64 "\n", - string_VkResult(result), static_cast(result), m_queue, m_index, m_submit_seq, - m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, m_debug_arg3, - m_debug_arg4); + VulkanToString(result).c_str(), static_cast(result), m_queue, m_index, + m_submit_seq, m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, + m_debug_arg3, m_debug_arg4); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } -void CommandBuffer::ExecuteWithSemaphore(VkSemaphore signal_semaphore) { +void CommandBuffer::ExecuteWithSemaphore(vk::Semaphore signal_semaphore) { EXIT_IF(IsInvalid()); EXIT_IF(m_execute); - auto* buffer = m_pool->buffers[m_index]; - auto* fence = m_pool->fences[m_index]; + auto buffer = m_pool->buffers[m_index]; + auto fence = m_pool->fences[m_index]; if (signal_semaphore == nullptr) { signal_semaphore = m_pool->semaphores[m_index]; } - VkSubmitInfo submit_info {}; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + vk::SubmitInfo submit_info {}; + submit_info.sType = vk::StructureType::eSubmitInfo; submit_info.pNext = nullptr; submit_info.waitSemaphoreCount = 0; submit_info.pWaitSemaphores = nullptr; @@ -378,12 +380,12 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore signal_semaphore) { const auto& queue = g_render_ctx->GetGraphicCtx()->queues[m_queue]; - auto result = vkResetFences(g_render_ctx->GetGraphicCtx()->device, 1, &fence); - if (result != VK_SUCCESS) { - LOGF("vkResetFences failed before submit: %s (%d)\n", string_VkResult(result), + auto result = g_render_ctx->GetGraphicCtx()->device.resetFences(1, &fence); + if (result != vk::Result::eSuccess) { + LOGF("vkResetFences failed before submit: %s (%d)\n", VulkanToString(result).c_str(), static_cast(result)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); if (queue.mutex != nullptr) { queue.mutex->Lock(); @@ -396,7 +398,7 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore signal_semaphore) { m_debug_arg0, m_debug_arg1, m_debug_arg2, m_debug_arg3, m_debug_arg4); } - result = vkQueueSubmit(queue.vk_queue, 1, &submit_info, fence); + result = queue.vk_queue.submit(1, &submit_info, fence); if (queue.mutex != nullptr) { queue.mutex->Unlock(); @@ -406,32 +408,32 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore signal_semaphore) { m_fence_waited = false; m_submit_seq = g_command_buffer_submit_seq.fetch_add(1, std::memory_order_relaxed) + 1; - if (result != VK_SUCCESS) { + if (result != vk::Result::eSuccess) { LOGF("vkQueueSubmit failed: %s (%d), queue=%d index=%u submit_seq=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64 " args=%u,%u,%u,%u,0x%016" PRIx64 "\n", - string_VkResult(result), static_cast(result), m_queue, m_index, m_submit_seq, - m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, m_debug_arg3, - m_debug_arg4); + VulkanToString(result).c_str(), static_cast(result), m_queue, m_index, + m_submit_seq, m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, + m_debug_arg3, m_debug_arg4); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } -void CommandBuffer::ExecuteWithSemaphore(VkSemaphore wait_semaphore, - VkPipelineStageFlags wait_stage, - VkSemaphore signal_semaphore) { +void CommandBuffer::ExecuteWithSemaphore(vk::Semaphore wait_semaphore, + vk::PipelineStageFlags wait_stage, + vk::Semaphore signal_semaphore) { EXIT_IF(IsInvalid()); EXIT_IF(m_execute); EXIT_IF(wait_semaphore == nullptr); - auto* buffer = m_pool->buffers[m_index]; - auto* fence = m_pool->fences[m_index]; + auto buffer = m_pool->buffers[m_index]; + auto fence = m_pool->fences[m_index]; if (signal_semaphore == nullptr) { signal_semaphore = m_pool->semaphores[m_index]; } - VkSubmitInfo submit_info {}; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + vk::SubmitInfo submit_info {}; + submit_info.sType = vk::StructureType::eSubmitInfo; submit_info.pNext = nullptr; submit_info.waitSemaphoreCount = 1; submit_info.pWaitSemaphores = &wait_semaphore; @@ -445,12 +447,12 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore wait_semaphore, const auto& queue = g_render_ctx->GetGraphicCtx()->queues[m_queue]; - auto result = vkResetFences(g_render_ctx->GetGraphicCtx()->device, 1, &fence); - if (result != VK_SUCCESS) { - LOGF("vkResetFences failed before submit: %s (%d)\n", string_VkResult(result), + auto result = g_render_ctx->GetGraphicCtx()->device.resetFences(1, &fence); + if (result != vk::Result::eSuccess) { + LOGF("vkResetFences failed before submit: %s (%d)\n", VulkanToString(result).c_str(), static_cast(result)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); if (queue.mutex != nullptr) { queue.mutex->Lock(); @@ -464,7 +466,7 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore wait_semaphore, m_debug_arg1, m_debug_arg2, m_debug_arg3, m_debug_arg4); } - result = vkQueueSubmit(queue.vk_queue, 1, &submit_info, fence); + result = queue.vk_queue.submit(1, &submit_info, fence); if (queue.mutex != nullptr) { queue.mutex->Unlock(); @@ -474,14 +476,14 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore wait_semaphore, m_fence_waited = false; m_submit_seq = g_command_buffer_submit_seq.fetch_add(1, std::memory_order_relaxed) + 1; - if (result != VK_SUCCESS) { + if (result != vk::Result::eSuccess) { LOGF("vkQueueSubmit failed: %s (%d), queue=%d index=%u submit_seq=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64 " args=%u,%u,%u,%u,0x%016" PRIx64 "\n", - string_VkResult(result), static_cast(result), m_queue, m_index, m_submit_seq, - m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, m_debug_arg3, - m_debug_arg4); + VulkanToString(result).c_str(), static_cast(result), m_queue, m_index, + m_submit_seq, m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, + m_debug_arg3, m_debug_arg4); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } void CommandBuffer::WaitForFence() { @@ -505,16 +507,16 @@ void CommandBuffer::WaitForFenceOnly() { if (!m_execute || m_fence_waited) { return; } - auto* device = g_render_ctx->GetGraphicCtx()->device; - auto result = vkWaitForFences(device, 1, &m_pool->fences[m_index], VK_TRUE, UINT64_MAX); - if (result != VK_SUCCESS) { + auto device = g_render_ctx->GetGraphicCtx()->device; + auto result = device.waitForFences(1, &m_pool->fences[m_index], VK_TRUE, UINT64_MAX); + if (result != vk::Result::eSuccess) { LOGF("vkWaitForFences failed: %s (%d), queue=%d index=%u submit_seq=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64 " args=%u,%u,%u,%u,0x%016" PRIx64 "\n", - string_VkResult(result), static_cast(result), m_queue, m_index, m_submit_seq, - m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, m_debug_arg3, - m_debug_arg4); + VulkanToString(result).c_str(), static_cast(result), m_queue, m_index, + m_submit_seq, m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, + m_debug_arg3, m_debug_arg4); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); m_fence_waited = true; } @@ -524,8 +526,7 @@ void CommandBuffer::WaitForFenceAndReset() { if (was_executed) { m_execute = false; m_fence_waited = false; - vkResetCommandBuffer(m_pool->buffers[m_index], - VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); + m_pool->buffers[m_index].reset(vk::CommandBufferResetFlagBits::eReleaseResources); m_recording_generation++; } m_host_stream.Reset(); @@ -544,13 +545,13 @@ void CommandBuffer::BeginRenderPass(VulkanFramebuffer* framebuffer, RenderColorI uint32_t requested_color_count, RenderDepthInfo* depth) const { EXIT_IF(IsInvalid()); - auto* buffer = m_pool->buffers[m_index]; + auto buffer = m_pool->buffers[m_index]; EXIT_IF(framebuffer == nullptr); EXIT_IF(colors == nullptr); EXIT_IF(requested_color_count > RENDER_COLOR_ATTACHMENTS_MAX); - bool with_depth = (depth->format != VK_FORMAT_UNDEFINED && depth->vulkan_buffer != nullptr); + bool with_depth = (depth->format != vk::Format::eUndefined && depth->vulkan_buffer != nullptr); uint32_t color_count = 0; for (uint32_t i = 0; i < requested_color_count; i++) { if (colors[i].vulkan_buffer == nullptr) { @@ -562,16 +563,16 @@ void CommandBuffer::BeginRenderPass(VulkanFramebuffer* framebuffer, RenderColorI EXIT_NOT_IMPLEMENTED(!with_depth && !with_color); - VkClearValue clears[RENDER_COLOR_ATTACHMENTS_MAX + 1] = {}; + vk::ClearValue clears[RENDER_COLOR_ATTACHMENTS_MAX + 1] = {}; for (uint32_t i = 0; i < color_count; i++) { clears[i].color = colors[i].color_clear_value; } clears[color_count].depthStencil = {depth->depth_clear_value, depth->stencil_clear_value}; - VkExtent2D extent = (with_color ? colors[0].extent : depth->vulkan_buffer->extent); + vk::Extent2D extent = (with_color ? colors[0].extent : depth->vulkan_buffer->extent); - VkRenderPassBeginInfo render_pass_info {}; - render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + vk::RenderPassBeginInfo render_pass_info {}; + render_pass_info.sType = vk::StructureType::eRenderPassBeginInfo; render_pass_info.pNext = nullptr; render_pass_info.renderPass = framebuffer->render_pass; render_pass_info.framebuffer = framebuffer->framebuffer; @@ -585,55 +586,57 @@ void CommandBuffer::BeginRenderPass(VulkanFramebuffer* framebuffer, RenderColorI if (colors[i].vulkan_buffer->layout != color_initial_layout) { if (graphics_debug_dump_enabled()) { LOGF("BeginRenderPass: color%u initial barrier image=%p mem=%" PRIu64 " %s -> %s\n", - i, reinterpret_cast(colors[i].vulkan_buffer->image), + i, VulkanHandleToPointer(colors[i].vulkan_buffer->image), colors[i].vulkan_buffer->memory.unique_id, - string_VkImageLayout(colors[i].vulkan_buffer->layout), - string_VkImageLayout(color_initial_layout)); + VulkanToString(colors[i].vulkan_buffer->layout).c_str(), + VulkanToString(color_initial_layout).c_str()); } - VkImageMemoryBarrier image_memory_barrier {}; - image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = nullptr; - image_memory_barrier.srcAccessMask = 0; - image_memory_barrier.dstAccessMask = - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; - image_memory_barrier.oldLayout = colors[i].vulkan_buffer->layout; - image_memory_barrier.newLayout = color_initial_layout; - image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - image_memory_barrier.image = colors[i].vulkan_buffer->image; - image_memory_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + vk::ImageMemoryBarrier image_memory_barrier {}; + image_memory_barrier.sType = vk::StructureType::eImageMemoryBarrier; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = {}; + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentRead | + vk::AccessFlagBits::eColorAttachmentWrite; + image_memory_barrier.oldLayout = colors[i].vulkan_buffer->layout; + image_memory_barrier.newLayout = color_initial_layout; + image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.image = colors[i].vulkan_buffer->image; + image_memory_barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; image_memory_barrier.subresourceRange.baseArrayLayer = 0; image_memory_barrier.subresourceRange.layerCount = colors[i].vulkan_buffer->layers; - vkCmdPipelineBarrier(buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0, 0, nullptr, 0, - nullptr, 1, &image_memory_barrier); + buffer.pipelineBarrier(vk::PipelineStageFlagBits::eTopOfPipe, + vk::PipelineStageFlagBits::eColorAttachmentOutput, + vk::DependencyFlags {}, 0, nullptr, 0, nullptr, 1, + &image_memory_barrier); colors[i].vulkan_buffer->layout = image_memory_barrier.newLayout; } else if (graphics_debug_dump_enabled()) { LOGF("BeginRenderPass: color%u initial image=%p mem=%" PRIu64 " layout=%s\n", i, - reinterpret_cast(colors[i].vulkan_buffer->image), + VulkanHandleToPointer(colors[i].vulkan_buffer->image), colors[i].vulkan_buffer->memory.unique_id, - string_VkImageLayout(colors[i].vulkan_buffer->layout)); + VulkanToString(colors[i].vulkan_buffer->layout).c_str()); } } const auto depth_layout = (with_depth && framebuffer != nullptr ? framebuffer->depth_layout - : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + : vk::ImageLayout::eDepthStencilAttachmentOptimal); if (with_depth && depth->vulkan_buffer->layout != depth_layout) { - VkImageMemoryBarrier image_memory_barrier {}; - image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = nullptr; - image_memory_barrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; + vk::ImageMemoryBarrier image_memory_barrier {}; + image_memory_barrier.sType = vk::StructureType::eImageMemoryBarrier; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; image_memory_barrier.dstAccessMask = - (depth_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL - ? VK_ACCESS_MEMORY_READ_BIT - : VK_ACCESS_MEMORY_WRITE_BIT); + (depth_layout == vk::ImageLayout::eDepthStencilReadOnlyOptimal + ? vk::AccessFlagBits::eMemoryRead + : vk::AccessFlagBits::eMemoryWrite); image_memory_barrier.oldLayout = depth->vulkan_buffer->layout; image_memory_barrier.newLayout = depth_layout; image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; @@ -646,15 +649,15 @@ void CommandBuffer::BeginRenderPass(VulkanFramebuffer* framebuffer, RenderColorI image_memory_barrier.subresourceRange.baseArrayLayer = 0; image_memory_barrier.subresourceRange.layerCount = depth->vulkan_buffer->layers; - vkCmdPipelineBarrier( - buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, - nullptr, 0, nullptr, 1, &image_memory_barrier); + buffer.pipelineBarrier( + vk::PipelineStageFlagBits::eAllGraphics | vk::PipelineStageFlagBits::eComputeShader, + vk::PipelineStageFlagBits::eAllGraphics | vk::PipelineStageFlagBits::eComputeShader, + vk::DependencyFlags {}, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); depth->vulkan_buffer->layout = image_memory_barrier.newLayout; } - vkCmdBeginRenderPass(buffer, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE); + buffer.beginRenderPass(&render_pass_info, vk::SubpassContents::eInline); for (uint32_t i = 0; i < color_count; i++) { colors[i].vulkan_buffer->layout = RENDER_COLOR_IMAGE_LAYOUT; @@ -664,9 +667,9 @@ void CommandBuffer::BeginRenderPass(VulkanFramebuffer* framebuffer, RenderColorI void CommandBuffer::EndRenderPass() const { EXIT_IF(IsInvalid()); - auto* buffer = m_pool->buffers[m_index]; + auto buffer = m_pool->buffers[m_index]; - vkCmdEndRenderPass(buffer); + buffer.endRenderPass(); } } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/debug.cpp b/src/graphics/host_gpu/renderer/debug.cpp index 012b67c9e..613fe220e 100644 --- a/src/graphics/host_gpu/renderer/debug.cpp +++ b/src/graphics/host_gpu/renderer/debug.cpp @@ -1168,7 +1168,7 @@ static bool ScissorClipRuleToIntersectionMask(uint16_t rule, uint8_t* mask) { } ScissorRect calc_final_scissor(const HW::ScreenViewport& vp, const HW::ScanModeControl& smc, - VkExtent2D extent) { + vk::Extent2D extent) { ScissorRect screen {vp.screen_scissor_left, vp.screen_scissor_top, vp.screen_scissor_right, vp.screen_scissor_bottom}; ScissorRect final = screen; diff --git a/src/graphics/host_gpu/renderer/debug.h b/src/graphics/host_gpu/renderer/debug.h index 06ef50311..29b46d810 100644 --- a/src/graphics/host_gpu/renderer/debug.h +++ b/src/graphics/host_gpu/renderer/debug.h @@ -1,10 +1,11 @@ #ifndef EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_DEBUG_H_ #define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_DEBUG_H_ +#include "graphics/host_gpu/vulkanCommon.h" + #include #include #include -#include namespace Libs::Graphics { @@ -37,7 +38,7 @@ void hw_print(const HW::Context& hw); void hw_check(const HW::Context& hw); void LogDrawPhase(const char* draw_name, const char* phase); ScissorRect calc_final_scissor(const HW::ScreenViewport& vp, const HW::ScanModeControl& smc, - VkExtent2D extent); + vk::Extent2D extent); } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp index f43a2739c..193541143 100644 --- a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp +++ b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp @@ -17,6 +17,7 @@ #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/displayBuffer.h" #include @@ -25,7 +26,6 @@ #include #include #include -#include namespace Libs::Graphics { @@ -40,17 +40,17 @@ namespace Libs::Graphics { EXIT("unsupported render state; details were printed above\n"); } -static VkStencilOp ConvertStencilOp(uint8_t value) { +static vk::StencilOp ConvertStencilOp(uint8_t value) { switch (static_cast(value)) { - case Prospero::StencilOp::kKeep: return VK_STENCIL_OP_KEEP; - case Prospero::StencilOp::kZero: return VK_STENCIL_OP_ZERO; + case Prospero::StencilOp::kKeep: return vk::StencilOp::eKeep; + case Prospero::StencilOp::kZero: return vk::StencilOp::eZero; case Prospero::StencilOp::kReplaceTest: - case Prospero::StencilOp::kReplaceOp: return VK_STENCIL_OP_REPLACE; - case Prospero::StencilOp::kAddClamp: return VK_STENCIL_OP_INCREMENT_AND_CLAMP; - case Prospero::StencilOp::kSubClamp: return VK_STENCIL_OP_DECREMENT_AND_CLAMP; - case Prospero::StencilOp::kInvert: return VK_STENCIL_OP_INVERT; - case Prospero::StencilOp::kAddWrap: return VK_STENCIL_OP_INCREMENT_AND_WRAP; - case Prospero::StencilOp::kSubWrap: return VK_STENCIL_OP_DECREMENT_AND_WRAP; + case Prospero::StencilOp::kReplaceOp: return vk::StencilOp::eReplace; + case Prospero::StencilOp::kAddClamp: return vk::StencilOp::eIncrementAndClamp; + case Prospero::StencilOp::kSubClamp: return vk::StencilOp::eDecrementAndClamp; + case Prospero::StencilOp::kInvert: return vk::StencilOp::eInvert; + case Prospero::StencilOp::kAddWrap: return vk::StencilOp::eIncrementAndWrap; + case Prospero::StencilOp::kSubWrap: return vk::StencilOp::eDecrementAndWrap; default: DepthFatal("unsupported stencil operation"); } } @@ -61,9 +61,9 @@ static bool UsesStencilOpValue(uint8_t fail, uint8_t pass, uint8_t depth_fail) { depth_fail == Prospero::GpuEnumValue(Prospero::StencilOp::kReplaceOp); } -[[nodiscard]] static VkFormat ResolveHostDepthAttachmentFormat(GraphicContext* ctx, - const DepthFormatPolicy& policy, - bool has_stencil) { +[[nodiscard]] static vk::Format ResolveHostDepthAttachmentFormat(GraphicContext* ctx, + const DepthFormatPolicy& policy, + bool has_stencil) { if (!has_stencil) { return policy.depth_attachment_format; } @@ -71,19 +71,20 @@ static bool UsesStencilOpValue(uint8_t fail, uint8_t pass, uint8_t depth_fail) { case Prospero::DepthFormat::kZ32F: return policy.stencil_attachment_formats.front(); case Prospero::DepthFormat::kZ16: { if (ctx == nullptr) { - return VK_FORMAT_UNDEFINED; + return vk::Format::eUndefined; } for (const auto format: policy.stencil_attachment_formats) { - VkImageFormatProperties properties {}; - if (ctx->GetImageFormatProperties(format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, - DepthTargetImageUsage(), 0, - &properties) == VK_SUCCESS) { + vk::ImageFormatProperties properties {}; + if (ctx->GetImageFormatProperties(format, vk::ImageType::e2D, + vk::ImageTiling::eOptimal, + DepthTargetImageUsage(), vk::ImageCreateFlags {}, + &properties) == vk::Result::eSuccess) { return format; } } - return VK_FORMAT_UNDEFINED; + return vk::Format::eUndefined; } - default: return VK_FORMAT_UNDEFINED; + default: return vk::Format::eUndefined; } } @@ -172,7 +173,7 @@ void ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer* buffer, const H z.htile_surface.prefetch_width != 0 || z.htile_surface.prefetch_height != 0 || z.htile_surface.dst_outside_zero_to_one != 0 || z.z_read_base_addr == 0 || z.z_write_base_addr != z.z_read_base_addr || (z.z_read_base_addr & 0xffffu) != 0 || - dc.zfunc > static_cast(VK_COMPARE_OP_ALWAYS)) { + dc.zfunc > static_cast(vk::CompareOp::eAlways)) { DepthFatal("unsupported depth register state"); } if (msaa_compat) { @@ -237,9 +238,9 @@ void ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer* buffer, const H const auto ideal_format = DepthAttachmentFormat(*policy, has_stencil); r->format = ResolveHostDepthAttachmentFormat(g_render_ctx->GetGraphicCtx(), *policy, has_stencil); - if (r->format == VK_FORMAT_UNDEFINED) { + if (r->format == vk::Format::eUndefined) { DepthFatal("no host depth/stencil format supports required usage for %s", - string_VkFormat(ideal_format)); + VulkanToString(ideal_format).c_str()); } const uint32_t guest_format = Prospero::GpuEnumValue(policy->guest_format); const uint32_t bytes = policy->bytes_per_element; @@ -324,7 +325,7 @@ void ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer* buffer, const H r->depth_clear_value = hw.GetDepthClearValue(); r->depth_test_enable = dc.z_enable; r->depth_write_enable = dc.z_write_enable && !z.depth_view.depth_write_disable; - r->depth_compare_op = static_cast(dc.zfunc); + r->depth_compare_op = static_cast(dc.zfunc); r->depth_bounds_test_enable = dc.depth_bounds_enable; r->depth_min_bounds = hw.GetDepthBoundsMin(); @@ -334,9 +335,9 @@ void ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer* buffer, const H r->stencil_clear_value = hw.GetStencilClearValue(); r->stencil_test_enable = dc.stencil_enable; if (dc.stencil_enable) { - if (dc.stencilfunc > static_cast(VK_COMPARE_OP_ALWAYS) || + if (dc.stencilfunc > static_cast(vk::CompareOp::eAlways) || (dc.backface_enable && - dc.stencilfunc_bf > static_cast(VK_COMPARE_OP_ALWAYS)) || + dc.stencilfunc_bf > static_cast(vk::CompareOp::eAlways)) || (UsesStencilOpValue(sc.stencil_fail, sc.stencil_zpass, sc.stencil_zfail) && sm.stencil_opval != sm.stencil_testval) || (dc.backface_enable && @@ -346,14 +347,15 @@ void ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer* buffer, const H } r->stencil_static_front = { ConvertStencilOp(sc.stencil_fail), ConvertStencilOp(sc.stencil_zpass), - ConvertStencilOp(sc.stencil_zfail), static_cast(dc.stencilfunc)}; + ConvertStencilOp(sc.stencil_zfail), static_cast(dc.stencilfunc)}; r->stencil_dynamic_front = {sm.stencil_mask, rc.stencil_clear_enable ? 0u : sm.stencil_writemask, sm.stencil_testval}; if (dc.backface_enable) { - r->stencil_static_back = { - ConvertStencilOp(sc.stencil_fail_bf), ConvertStencilOp(sc.stencil_zpass_bf), - ConvertStencilOp(sc.stencil_zfail_bf), static_cast(dc.stencilfunc_bf)}; + r->stencil_static_back = {ConvertStencilOp(sc.stencil_fail_bf), + ConvertStencilOp(sc.stencil_zpass_bf), + ConvertStencilOp(sc.stencil_zfail_bf), + static_cast(dc.stencilfunc_bf)}; r->stencil_dynamic_back = {sm.stencil_mask_bf, rc.stencil_clear_enable ? 0u : sm.stencil_writemask_bf, sm.stencil_testval_bf}; @@ -402,7 +404,8 @@ void ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer* buffer, const H } void MarkRenderTargetGpuWritten(const RenderDepthInfo& target) { - const bool with_depth = target.format != VK_FORMAT_UNDEFINED && target.vulkan_buffer != nullptr; + const bool with_depth = + target.format != vk::Format::eUndefined && target.vulkan_buffer != nullptr; if (with_depth && !depth_attachment_read_only(&target)) { g_render_ctx->GetTextureCache()->MarkGpuWritten(target.vulkan_buffer); diff --git a/src/graphics/host_gpu/renderer/depthRenderTarget.h b/src/graphics/host_gpu/renderer/depthRenderTarget.h index 022fd2a6e..799cd1295 100644 --- a/src/graphics/host_gpu/renderer/depthRenderTarget.h +++ b/src/graphics/host_gpu/renderer/depthRenderTarget.h @@ -3,9 +3,9 @@ #include "common/assert.h" #include "graphics/host_gpu/renderer/renderTarget.h" +#include "graphics/host_gpu/vulkanCommon.h" #include -#include namespace Libs::Graphics { @@ -22,7 +22,7 @@ inline constexpr bool depth_htile_stencil_acceleration_compatible(bool has_stenc } struct RenderDepthInfo { - VkFormat format = VK_FORMAT_UNDEFINED; + vk::Format format = vk::Format::eUndefined; uint32_t width = 0; uint32_t height = 0; bool htile = false; @@ -41,7 +41,7 @@ struct RenderDepthInfo { float depth_clear_value = 0.0f; bool depth_test_enable = false; bool depth_write_enable = false; - VkCompareOp depth_compare_op = VK_COMPARE_OP_NEVER; + vk::CompareOp depth_compare_op = vk::CompareOp::eNever; bool depth_bounds_test_enable = false; float depth_min_bounds = 0.0f; float depth_max_bounds = 0.0f; @@ -53,7 +53,7 @@ struct RenderDepthInfo { PipelineStencilDynamicState stencil_dynamic_front; PipelineStencilDynamicState stencil_dynamic_back; DepthStencilVulkanImage* vulkan_buffer = nullptr; - VkImageView vulkan_view = nullptr; + vk::ImageView vulkan_view = nullptr; uint64_t vaddr[3] = {}; uint64_t size[3] = {}; int vaddr_num = 0; @@ -68,9 +68,9 @@ inline bool depth_attachment_read_only(const RenderDepthInfo* depth) { !depth->depth_write_enable && !stencil_write; } -inline VkImageLayout depth_attachment_layout(const RenderDepthInfo* depth) { - return depth_attachment_read_only(depth) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL - : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; +inline vk::ImageLayout depth_attachment_layout(const RenderDepthInfo* depth) { + return depth_attachment_read_only(depth) ? vk::ImageLayout::eDepthStencilReadOnlyOptimal + : vk::ImageLayout::eDepthStencilAttachmentOptimal; } void ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer* buffer, const HW::Context& hw, diff --git a/src/graphics/host_gpu/renderer/descriptorCache.cpp b/src/graphics/host_gpu/renderer/descriptorCache.cpp index 392042161..2525a2e86 100644 --- a/src/graphics/host_gpu/renderer/descriptorCache.cpp +++ b/src/graphics/host_gpu/renderer/descriptorCache.cpp @@ -12,11 +12,11 @@ namespace { using BindingKind = ShaderRecompiler::IR::DescriptorBindingKind; -VkShaderStageFlags StageFlags(DescriptorCache::Stage stage) { +vk::ShaderStageFlags StageFlags(DescriptorCache::Stage stage) { switch (stage) { - case DescriptorCache::Stage::Vertex: return VK_SHADER_STAGE_VERTEX_BIT; - case DescriptorCache::Stage::Pixel: return VK_SHADER_STAGE_FRAGMENT_BIT; - case DescriptorCache::Stage::Compute: return VK_SHADER_STAGE_COMPUTE_BIT; + case DescriptorCache::Stage::Vertex: return vk::ShaderStageFlagBits::eVertex; + case DescriptorCache::Stage::Pixel: return vk::ShaderStageFlagBits::eFragment; + case DescriptorCache::Stage::Compute: return vk::ShaderStageFlagBits::eCompute; default: EXIT("unknown descriptor stage\n"); } } @@ -45,17 +45,17 @@ bool IsStorageImage(BindingKind kind) { } } -VkDescriptorType DescriptorType(BindingKind kind) { +vk::DescriptorType DescriptorType(BindingKind kind) { if (kind == BindingKind::Samplers) { - return VK_DESCRIPTOR_TYPE_SAMPLER; + return vk::DescriptorType::eSampler; } if (IsSampledImage(kind)) { - return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + return vk::DescriptorType::eSampledImage; } if (IsStorageImage(kind)) { - return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + return vk::DescriptorType::eStorageImage; } - return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + return vk::DescriptorType::eStorageBuffer; } uint32_t DescriptorCount(const ShaderRecompiler::IR::DescriptorBinding& binding) { @@ -76,23 +76,23 @@ std::vector LayoutKey(DescriptorCache::Stage stage, return key; } -VkImageLayout SampledLayout(const VulkanImage* image) { +vk::ImageLayout SampledLayout(const VulkanImage* image) { EXIT_IF(image == nullptr); switch (image->layout) { - case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: - case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: return VK_IMAGE_LAYOUT_GENERAL; + case vk::ImageLayout::eTransferDstOptimal: + case vk::ImageLayout::eTransferSrcOptimal: + case vk::ImageLayout::eColorAttachmentOptimal: return vk::ImageLayout::eGeneral; default: return image->layout; } } -VkDescriptorBufferInfo BufferInfo(const BufferView& view) { +vk::DescriptorBufferInfo BufferInfo(const BufferView& view) { EXIT_IF(view.buffer == nullptr || view.buffer->buffer == nullptr); return {view.buffer->buffer, view.offset, view.range}; } -VkDescriptorImageInfo MakeDescriptorImageInfo(const DescriptorCache::TextureBinding& texture, - VkImageLayout layout) { +vk::DescriptorImageInfo MakeDescriptorImageInfo(const DescriptorCache::TextureBinding& texture, + vk::ImageLayout layout) { EXIT_IF(texture.image == nullptr || texture.view < 0 || texture.view >= VulkanImage::VIEW_MAX); const auto view = texture.image_view != nullptr ? texture.image_view : texture.image->image_view[texture.view]; @@ -106,7 +106,7 @@ void DescriptorCache::Init() { m_initialized = true; } -VkDescriptorSetLayout +vk::DescriptorSetLayout DescriptorCache::GetDescriptorSetLayoutInternal(GraphicContext* gctx, Stage stage, const ShaderRecompiler::IR::Program& program) { EXIT_IF(gctx == nullptr); @@ -117,7 +117,7 @@ DescriptorCache::GetDescriptorSetLayoutInternal(GraphicContext* gctx, Stage stag return found->second; } - std::vector bindings; + std::vector bindings; bindings.reserve(program.bindings.descriptors.size()); for (const auto& descriptor: program.bindings.descriptors) { bindings.push_back({descriptor.binding, DescriptorType(descriptor.kind), @@ -127,12 +127,12 @@ DescriptorCache::GetDescriptorSetLayoutInternal(GraphicContext* gctx, Stage stag return nullptr; } - VkDescriptorSetLayoutCreateInfo info {}; - info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - info.bindingCount = static_cast(bindings.size()); - info.pBindings = bindings.data(); - VkDescriptorSetLayout layout = nullptr; - vkCreateDescriptorSetLayout(gctx->device, &info, nullptr, &layout); + vk::DescriptorSetLayoutCreateInfo info {}; + info.sType = vk::StructureType::eDescriptorSetLayoutCreateInfo; + info.bindingCount = static_cast(bindings.size()); + info.pBindings = bindings.data(); + vk::DescriptorSetLayout layout = nullptr; + gctx->device.createDescriptorSetLayout(&info, nullptr, &layout); EXIT_NOT_IMPLEMENTED(layout == nullptr); m_descriptor_set_layouts.emplace(key, layout); return layout; @@ -141,23 +141,23 @@ DescriptorCache::GetDescriptorSetLayoutInternal(GraphicContext* gctx, Stage stag void DescriptorCache::CreatePool(GraphicContext* gctx) { KYTY_PROFILER_FUNCTION(); EXIT_IF(gctx == nullptr); - constexpr uint32_t MaxSets = 512; - const VkDescriptorPoolSize sizes[] = { - {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + constexpr uint32_t MaxSets = 512; + const vk::DescriptorPoolSize sizes[] = { + {vk::DescriptorType::eStorageBuffer, MaxSets * (ShaderRecompiler::IR::ShaderInfo::MaxBuffers + ShaderRecompiler::IR::ShaderInfo::MaxAddresses + 3u)}, - {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MaxSets * ShaderRecompiler::IR::ShaderInfo::MaxImages}, - {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MaxSets * ShaderRecompiler::IR::ShaderInfo::MaxImages}, - {VK_DESCRIPTOR_TYPE_SAMPLER, MaxSets * ShaderRecompiler::IR::ShaderInfo::MaxSamplers}, + {vk::DescriptorType::eSampledImage, MaxSets * ShaderRecompiler::IR::ShaderInfo::MaxImages}, + {vk::DescriptorType::eStorageImage, MaxSets * ShaderRecompiler::IR::ShaderInfo::MaxImages}, + {vk::DescriptorType::eSampler, MaxSets * ShaderRecompiler::IR::ShaderInfo::MaxSamplers}, }; - VkDescriptorPoolCreateInfo info {}; - info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + vk::DescriptorPoolCreateInfo info {}; + info.sType = vk::StructureType::eDescriptorPoolCreateInfo; info.poolSizeCount = static_cast(std::size(sizes)); info.pPoolSizes = sizes; info.maxSets = MaxSets; const auto pool_id = static_cast(m_pools.size()); auto& pool = m_pools.emplace_back(); - vkCreateDescriptorPool(gctx->device, &info, nullptr, &pool.pool); + gctx->device.createDescriptorPool(&info, nullptr, &pool.pool); EXIT_NOT_IMPLEMENTED(pool.pool == nullptr); pool.next_free_pool = m_first_free_pool; m_first_free_pool = pool_id; @@ -182,16 +182,16 @@ VulkanDescriptorSet* DescriptorCache::Allocate(Stage for (int attempt = 0; attempt < 2; attempt++) { for (int pool_id = m_first_free_pool; pool_id != -1; pool_id = m_pools[pool_id].next_free_pool) { - auto& pool = m_pools[pool_id]; - std::array layouts; + auto& pool = m_pools[pool_id]; + std::array layouts; layouts.fill(layout); - std::array sets {}; - VkDescriptorSetAllocateInfo info {}; - info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + std::array sets {}; + vk::DescriptorSetAllocateInfo info {}; + info.sType = vk::StructureType::eDescriptorSetAllocateInfo; info.descriptorPool = pool.pool; info.descriptorSetCount = Batch; info.pSetLayouts = layouts.data(); - if (vkAllocateDescriptorSets(gctx->device, &info, sets.data()) == VK_SUCCESS) { + if (gctx->device.allocateDescriptorSets(&info, sets.data()) == vk::Result::eSuccess) { free_sets.reserve(free_sets.size() + Batch - 1u); for (uint32_t i = 0; i + 1u < Batch; i++) { free_sets.push_back(new VulkanDescriptorSet {sets[i], layout, pool_id}); @@ -228,16 +228,16 @@ VulkanDescriptorSet* DescriptorCache::GetDescriptor(Stage const auto descriptor_count = program.info.buffers.size() + program.info.images.size() + program.info.samplers.size() + program.info.addresses.size() + 3u; - std::vector buffer_infos; - std::vector image_infos; - std::vector writes; + std::vector buffer_infos; + std::vector image_infos; + std::vector writes; buffer_infos.reserve(descriptor_count); image_infos.reserve(descriptor_count); writes.reserve(program.bindings.descriptors.size()); for (const auto& binding: program.bindings.descriptors) { - VkWriteDescriptorSet write {}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write {}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = set->set; write.dstBinding = binding.binding; write.descriptorType = DescriptorType(binding.kind); @@ -264,12 +264,12 @@ VulkanDescriptorSet* DescriptorCache::GetDescriptor(Stage for (const auto resource: binding.resources) { const auto sampler = data.samplers.at(resource); EXIT_IF(sampler == nullptr); - image_infos.push_back({sampler, nullptr, VK_IMAGE_LAYOUT_UNDEFINED}); + image_infos.push_back({sampler, nullptr, vk::ImageLayout::eUndefined}); } break; default: { - const auto layout = IsStorageImage(binding.kind) ? VK_IMAGE_LAYOUT_GENERAL - : VK_IMAGE_LAYOUT_UNDEFINED; + const auto layout = IsStorageImage(binding.kind) ? vk::ImageLayout::eGeneral + : vk::ImageLayout::eUndefined; for (const auto resource: binding.resources) { const auto& texture = data.images.at(resource); image_infos.push_back(MakeDescriptorImageInfo( @@ -287,12 +287,12 @@ VulkanDescriptorSet* DescriptorCache::GetDescriptor(Stage } writes.push_back(write); } - vkUpdateDescriptorSets(gctx->device, static_cast(writes.size()), writes.data(), 0, - nullptr); + gctx->device.updateDescriptorSets(static_cast(writes.size()), writes.data(), 0, + nullptr); return set; } -VkDescriptorSetLayout +vk::DescriptorSetLayout DescriptorCache::GetDescriptorSetLayout(Stage stage, const ShaderRecompiler::IR::Program& program) { auto* gctx = g_render_ctx->GetGraphicCtx(); EXIT_IF(gctx == nullptr); diff --git a/src/graphics/host_gpu/renderer/descriptorCache.h b/src/graphics/host_gpu/renderer/descriptorCache.h index 1f2080fc4..de1a77060 100644 --- a/src/graphics/host_gpu/renderer/descriptorCache.h +++ b/src/graphics/host_gpu/renderer/descriptorCache.h @@ -6,12 +6,12 @@ #include "common/common.h" #include "common/threads.h" #include "graphics/host_gpu/graphicContext.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/shaderBindings.h" #include #include #include -#include namespace Libs::Graphics { @@ -23,19 +23,19 @@ class CommandBuffer; struct ShaderStageRuntime; struct VulkanDescriptor { - VkDescriptorSet descriptor_set = nullptr; + vk::DescriptorSet descriptor_set = nullptr; }; struct VulkanDescriptorSet { - VkDescriptorSet set = nullptr; - VkDescriptorSetLayout layout = nullptr; - int pool_id = -1; + vk::DescriptorSet set = nullptr; + vk::DescriptorSetLayout layout = nullptr; + int pool_id = -1; }; struct BufferView { - VulkanBuffer* buffer = nullptr; - VkDeviceSize offset = 0; - VkDeviceSize range = VK_WHOLE_SIZE; + VulkanBuffer* buffer = nullptr; + vk::DeviceSize offset = 0; + vk::DeviceSize range = VK_WHOLE_SIZE; }; struct ShaderAddressWriteRange { @@ -49,9 +49,9 @@ public: enum class Stage { Unknown, Vertex, Pixel, Compute }; struct TextureBinding { - VulkanImage* image = nullptr; - int view = VulkanImage::VIEW_DEFAULT; - VkImageView image_view = nullptr; + VulkanImage* image = nullptr; + int view = VulkanImage::VIEW_DEFAULT; + vk::ImageView image_view = nullptr; }; enum class TextureVariant : int { @@ -66,7 +66,7 @@ public: struct NativeDescriptors { std::vector buffers; std::vector images; - std::vector samplers; + std::vector samplers; std::vector addresses; BufferView gds; BufferView flattened_srt; @@ -77,41 +77,43 @@ public: virtual ~DescriptorCache() { KYTY_NOT_IMPLEMENTED; } KYTY_CLASS_NO_COPY(DescriptorCache); - VkDescriptorSetLayout GetDescriptorSetLayout(Stage stage, - const ShaderRecompiler::IR::Program& program); - void Recycle(VulkanDescriptorSet* set); - VulkanDescriptorSet* GetDescriptor(Stage stage, const ShaderRecompiler::IR::Program& program, - const NativeDescriptors& descriptors); + vk::DescriptorSetLayout GetDescriptorSetLayout(Stage stage, + const ShaderRecompiler::IR::Program& program); + void Recycle(VulkanDescriptorSet* set); + VulkanDescriptorSet* GetDescriptor(Stage stage, const ShaderRecompiler::IR::Program& program, + const NativeDescriptors& descriptors); private: struct Pool { - VkDescriptorPool pool = nullptr; - int next_free_pool = -1; - bool free = true; + vk::DescriptorPool pool = nullptr; + int next_free_pool = -1; + bool free = true; }; void Init(); void CreatePool(GraphicContext* gctx); VulkanDescriptorSet* Allocate(Stage stage, const ShaderRecompiler::IR::Program& program); - VkDescriptorSetLayout + vk::DescriptorSetLayout GetDescriptorSetLayoutInternal(GraphicContext* gctx, Stage stage, const ShaderRecompiler::IR::Program& program); Common::Mutex m_mutex; std::vector m_pools; int m_first_free_pool = -1; - std::unordered_map> - m_free_sets_by_layout; - std::map, VkDescriptorSetLayout> m_descriptor_set_layouts; - bool m_initialized = false; + std::unordered_map> + m_free_sets_by_layout; + std::map, vk::DescriptorSetLayout> m_descriptor_set_layouts; + bool m_initialized = false; }; -const char* storage_usage_name(ShaderStorageUsage usage); -VkImageAspectFlags DepthStencilAspectMask(VkFormat format); -std::vector -BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, VkPipelineBindPoint pipeline_bind_point, - VkPipelineLayout layout, const ShaderStageRuntime& runtime, - VkShaderStageFlags vk_stage, DescriptorCache::Stage stage); +const char* storage_usage_name(ShaderStorageUsage usage); +vk::ImageAspectFlags DepthStencilAspectMask(vk::Format format); +std::vector BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, + vk::PipelineBindPoint pipeline_bind_point, + vk::PipelineLayout layout, + const ShaderStageRuntime& runtime, + vk::ShaderStageFlags vk_stage, + DescriptorCache::Stage stage); } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/descriptors.cpp b/src/graphics/host_gpu/renderer/descriptors.cpp index 282027687..556e2eb5f 100644 --- a/src/graphics/host_gpu/renderer/descriptors.cpp +++ b/src/graphics/host_gpu/renderer/descriptors.cpp @@ -25,6 +25,7 @@ #include "graphics/host_gpu/renderer/shaderResourceBarrier.h" #include "graphics/host_gpu/utils.h" #include "graphics/host_gpu/vma.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/displayBuffer.h" #include "graphics/shader/recompiler/BindingLayout.h" #include "graphics/shader/recompiler/ResourceMaterialization.h" @@ -36,7 +37,6 @@ #include #include #include -#include #ifdef min #undef min @@ -71,10 +71,10 @@ static const char* VulkanImageTypeName(VulkanImageType type) { } } -VkImageAspectFlags DepthStencilAspectMask(VkFormat format) { - auto ret = static_cast(VK_IMAGE_ASPECT_DEPTH_BIT); - if (format == VK_FORMAT_D24_UNORM_S8_UINT || format == VK_FORMAT_D32_SFLOAT_S8_UINT) { - ret |= VK_IMAGE_ASPECT_STENCIL_BIT; +vk::ImageAspectFlags DepthStencilAspectMask(vk::Format format) { + auto ret = static_cast(vk::ImageAspectFlagBits::eDepth); + if (format == vk::Format::eD24UnormS8Uint || format == vk::Format::eD32SfloatS8Uint) { + ret |= vk::ImageAspectFlagBits::eStencil; } return ret; } @@ -229,7 +229,7 @@ static BufferView NativeStorageBuffer(uint64_t submit_id, CommandBuffer* command } result.buffer = binding.first; result.offset = binding.second; - result.range = static_cast(size); + result.range = static_cast(size); return result; } @@ -267,7 +267,7 @@ NativeAddressBuffer(uint64_t submit_id, CommandBuffer* command_buffer, address.binding_base, size); result.buffer = binding.first; result.offset = binding.second; - result.range = static_cast(size); + result.range = static_cast(size); return result; } @@ -306,16 +306,16 @@ TargetTextureViewInfo ResolveTargetTextureView(const ShaderRecompiler::IR::Image case Prospero::ImageType::kColor2D: return resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2D && base_layer == 0 && image_layers == 1 - ? TargetTextureViewInfo {VK_IMAGE_VIEW_TYPE_2D, 0, 1} + ? TargetTextureViewInfo {vk::ImageViewType::e2D, 0, 1} : TargetTextureViewInfo {}; case Prospero::ImageType::kColor2DArray: if (resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2D && base_layer == 0 && image_layers == 1) { - return {VK_IMAGE_VIEW_TYPE_2D, 0, 1}; + return {vk::ImageViewType::e2D, 0, 1}; } return resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2DArray && base_layer < image_layers - ? TargetTextureViewInfo {VK_IMAGE_VIEW_TYPE_2D_ARRAY, base_layer, + ? TargetTextureViewInfo {vk::ImageViewType::e2DArray, base_layer, image_layers - base_layer} : TargetTextureViewInfo {}; default: return {}; @@ -365,7 +365,7 @@ static bool IsSupportedDepthTextureEncoding(const ShaderTextureResource& descrip static void ValidateDepthTargetBinding(const ShaderRecompiler::IR::ImageResource& resource, const ShaderTextureResource& descriptor, - const VulkanImage* image, VkFormat view_format, + const VulkanImage* image, vk::Format view_format, uint64_t size) { const bool resource_ok = IsSupportedSampledDepthResource(resource); const bool descriptor_ok = @@ -389,7 +389,8 @@ static void ValidateDepthTargetBinding(const ShaderRecompiler::IR::ImageResource static_cast(resource.dimension), static_cast(resource.mip_mode), resource.read, resource.written, resource.atomic, resource.depth_compare, descriptor.Format(), descriptor.DstSelXYZW(), - image == nullptr ? static_cast(VK_FORMAT_UNDEFINED) : static_cast(image->format), + image == nullptr ? static_cast(vk::Format::eUndefined) + : static_cast(image->format), static_cast(view_format), image == nullptr ? 0u : image->layers, descriptor.Type(), descriptor.BaseArray5(), descriptor.Depth(), descriptor_pitch, image == nullptr ? 0u : image->guest_pitch, descriptor.Base40(), size, @@ -559,11 +560,11 @@ NativeTexture(uint64_t submit_id, CommandBuffer* command_buffer, resource.written); } - VulkanImage* image = nullptr; - int view = VulkanImage::VIEW_DEFAULT; - VkImageView image_view = nullptr; - const bool check_depth = static_cast(tile) == Prospero::TileMode::kDepth || - descriptor.MsaaDepth(); + VulkanImage* image = nullptr; + int view = VulkanImage::VIEW_DEFAULT; + vk::ImageView image_view = nullptr; + const bool check_depth = static_cast(tile) == Prospero::TileMode::kDepth || + descriptor.MsaaDepth(); if (image == nullptr) { if (check_depth) { image = g_render_ctx->GetTextureCache()->FindDepthTargetByRange(command_buffer, address, @@ -592,7 +593,8 @@ NativeTexture(uint64_t submit_id, CommandBuffer* command_buffer, const auto depth_view = ResolveTargetTextureView( resource, type, descriptor.BaseArray5(), image->layers); ValidateDepthTargetBinding(resource, descriptor, image, view_format, size.size); - if (depth_view.type == VK_IMAGE_VIEW_TYPE_MAX_ENUM) { + if (depth_view.type == + static_cast(VK_IMAGE_VIEW_TYPE_MAX_ENUM)) { EXIT("unsupported sampled depth target view: dimension=%u " "descriptor_type=%u " "base_array=%u image_layers=%u\n", @@ -611,7 +613,8 @@ NativeTexture(uint64_t submit_id, CommandBuffer* command_buffer, height != image->extent.height || (storage ? levels != image->mip_levels || base_level != 0 : levels != image->mip_levels || base_level >= levels) || - target_view.type == VK_IMAGE_VIEW_TYPE_MAX_ENUM || + target_view.type == + static_cast(VK_IMAGE_VIEW_TYPE_MAX_ENUM) || target_view.base_layer >= image->layers || target_view.layer_count > image->layers - target_view.base_layer) { EXIT("unsupported cached render-target image view: storage=%d resource=%u " @@ -656,13 +659,13 @@ NativeTexture(uint64_t submit_id, CommandBuffer* command_buffer, resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2D && !resource.read && resource.written && !resource.atomic && format == Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UInt) && - view_format == VK_FORMAT_R8G8B8A8_UINT && swizzle == DstSel(6, 5, 4, 7) && + view_format == vk::Format::eR8G8B8A8Uint && swizzle == DstSel(6, 5, 4, 7) && width == video.image->extent.width && height == video.image->extent.height && depth == 1 && levels == 1 && base_level == 0 && view_levels == 1 && type == Prospero::ImageType::kColor2D && video.size == size.size && video.pitch == pitch && - (video.image->format == VK_FORMAT_R8G8B8A8_SRGB || - video.image->format == VK_FORMAT_B8G8R8A8_SRGB) && + (video.image->format == vk::Format::eR8G8B8A8Srgb || + video.image->format == vk::Format::eB8G8R8A8Srgb) && video.image->image_view[VulkanImage::VIEW_STORAGE] != nullptr; if (!exact) { EXIT("unsupported storage access to video-out surface: format=%u view=%d" @@ -693,7 +696,7 @@ NativeTexture(uint64_t submit_id, CommandBuffer* command_buffer, image = video.image; image_view = g_render_ctx->GetTextureCache()->GetSampledColorView( g_render_ctx->GetGraphicCtx(), video.image, view_format, swizzle, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + vk::ImageViewType::e2D, 0, 1); } } } @@ -749,8 +752,8 @@ NativeTexture(uint64_t submit_id, CommandBuffer* command_buffer, return {image, view, image_view}; } -static VkSampler NativeSampler(const ShaderRecompiler::IR::Program& program, uint32_t index, - const ShaderRecompiler::IR::DescriptorValue& value) { +static vk::Sampler NativeSampler(const ShaderRecompiler::IR::Program& program, uint32_t index, + const ShaderRecompiler::IR::DescriptorValue& value) { auto descriptor = NativeSamplerDescriptor(value); const bool depth_compare = std::any_of(program.info.sampled_pairs.begin(), program.info.sampled_pairs.end(), [&](const auto& pair) { @@ -773,10 +776,12 @@ static BufferView NativeUpload(CommandBuffer* command_buffer, std::span -BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, VkPipelineBindPoint pipeline_bind_point, - VkPipelineLayout layout, const ShaderStageRuntime& runtime, - VkShaderStageFlags vk_stage, DescriptorCache::Stage stage) { +std::vector BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, + vk::PipelineBindPoint pipeline_bind_point, + vk::PipelineLayout layout, + const ShaderStageRuntime& runtime, + vk::ShaderStageFlags vk_stage, + DescriptorCache::Stage stage) { KYTY_PROFILER_FUNCTION(); EXIT_IF(buffer == nullptr || !runtime); const auto& program = *runtime.program; @@ -785,7 +790,7 @@ BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, VkPipelineBindPoint p if (!ShaderRecompiler::IR::ValidateResourceSpecialization(program, snapshot, &error)) { EXIT("invalid native shader runtime snapshot: %s\n", error.c_str()); } - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; const auto shader_stages = ShaderPipelineStages(vk_stage); DescriptorCache::NativeDescriptors descriptors; @@ -800,7 +805,7 @@ BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, VkPipelineBindPoint p const auto kind = program.info.images[i].kind; if ((kind == ShaderRecompiler::IR::ResourceKind::StorageImage || kind == ShaderRecompiler::IR::ResourceKind::StorageImageUint) && - vk_stage != VK_SHADER_STAGE_COMPUTE_BIT) { + vk_stage != vk::ShaderStageFlagBits::eCompute) { EXIT("storage images are unsupported outside compute shaders\n"); } descriptors.images.push_back( @@ -843,11 +848,10 @@ BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, VkPipelineBindPoint p descriptors.gds.buffer = g_render_ctx->GetGdsBuffer()->GetBuffer(g_render_ctx->GetGraphicCtx()); const auto barrier = MakeGdsDependency(*descriptors.gds.buffer); - vkCmdPipelineBarrier(vk_buffer, - VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT | - VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - shader_stages, 0, 0, nullptr, 1, &barrier, 0, nullptr); + vk_buffer.pipelineBarrier( + vk::PipelineStageFlagBits::eHost | vk::PipelineStageFlagBits::eTransfer | + vk::PipelineStageFlagBits::eAllGraphics | vk::PipelineStageFlagBits::eComputeShader, + shader_stages, vk::DependencyFlags {}, 0, nullptr, 1, &barrier, 0, nullptr); } for (uint32_t i = 0; i < program.info.images.size(); i++) { @@ -871,23 +875,23 @@ BindDescriptors(uint64_t submit_id, CommandBuffer* buffer, VkPipelineBindPoint p } else { const auto barrier = MakeStorageImageDependency(*image, resource.read, resource.written); - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, shader_stages, 0, 0, - nullptr, 0, nullptr, 1, &barrier); - image->layout = VK_IMAGE_LAYOUT_GENERAL; + vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, shader_stages, + vk::DependencyFlags {}, 0, nullptr, 0, nullptr, 1, &barrier); + image->layout = vk::ImageLayout::eGeneral; } } if (!program.bindings.descriptors.empty()) { auto* set = g_render_ctx->GetDescriptorCache()->GetDescriptor(stage, program, descriptors); EXIT_IF(set == nullptr); - vkCmdBindDescriptorSets(vk_buffer, pipeline_bind_point, layout, - program.bindings.descriptor_set, 1, &set->set, 0, nullptr); + vk_buffer.bindDescriptorSets(pipeline_bind_point, layout, program.bindings.descriptor_set, + 1, &set->set, 0, nullptr); buffer->RecycleDescriptorAfterFence(set); } if (program.bindings.push_constant_size != 0) { EXIT_IF(program.bindings.push_constant_size != user_data.size() * sizeof(uint32_t)); - vkCmdPushConstants(vk_buffer, layout, vk_stage, program.bindings.push_constant_offset, - program.bindings.push_constant_size, user_data.data()); + vk_buffer.pushConstants(layout, vk_stage, program.bindings.push_constant_offset, + program.bindings.push_constant_size, user_data.data()); } return address_writes; } diff --git a/src/graphics/host_gpu/renderer/descriptors.h b/src/graphics/host_gpu/renderer/descriptors.h index ff5ea2f6c..5d9a5d438 100644 --- a/src/graphics/host_gpu/renderer/descriptors.h +++ b/src/graphics/host_gpu/renderer/descriptors.h @@ -1,20 +1,20 @@ #ifndef EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_DESCRIPTORS_H_ #define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_DESCRIPTORS_H_ +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/recompiler/ShaderIR.h" #include "graphics/shader/shaderBindings.h" #include -#include namespace Libs::Graphics { struct VulkanImage; struct TargetTextureViewInfo { - VkImageViewType type = VK_IMAGE_VIEW_TYPE_MAX_ENUM; - uint32_t base_layer = 0; - uint32_t layer_count = 0; + vk::ImageViewType type = static_cast(VK_IMAGE_VIEW_TYPE_MAX_ENUM); + uint32_t base_layer = 0; + uint32_t layer_count = 0; }; [[nodiscard]] TargetTextureViewInfo diff --git a/src/graphics/host_gpu/renderer/framebufferCache.cpp b/src/graphics/host_gpu/renderer/framebufferCache.cpp index 8f4e8d515..b660a7f94 100644 --- a/src/graphics/host_gpu/renderer/framebufferCache.cpp +++ b/src/graphics/host_gpu/renderer/framebufferCache.cpp @@ -7,10 +7,10 @@ #include "graphics/host_gpu/renderer/depthRenderTarget.h" #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include #include -#include namespace Libs::Graphics { @@ -26,11 +26,11 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, EXIT_IF(g_render_ctx == nullptr); EXIT_IF(requested_color_count > RENDER_COLOR_ATTACHMENTS_MAX); - bool with_depth = (depth->format != VK_FORMAT_UNDEFINED && depth->vulkan_buffer != nullptr); - bool with_color[RENDER_COLOR_ATTACHMENTS_MAX] = {}; - uint32_t color_count = 0; - VulkanImage* first_color = nullptr; - VkExtent2D first_color_extent = {}; + bool with_depth = (depth->format != vk::Format::eUndefined && depth->vulkan_buffer != nullptr); + bool with_color[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + uint32_t color_count = 0; + VulkanImage* first_color = nullptr; + vk::Extent2D first_color_extent = {}; for (uint32_t i = 0; i < requested_color_count; i++) { with_color[i] = (colors[i].vulkan_buffer != nullptr); if (!with_color[i]) { @@ -50,14 +50,14 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, } color_count++; } - VkImageLayout color_layout[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::ImageLayout color_layout[RENDER_COLOR_ATTACHMENTS_MAX] = {}; for (auto& layout: color_layout) { layout = RENDER_COLOR_IMAGE_LAYOUT; } auto depth_layout = (with_depth ? depth_attachment_layout(depth) - : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + : vk::ImageLayout::eDepthStencilAttachmentOptimal); auto depth_read_only = - (with_depth && depth_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL); + (with_depth && depth_layout == vk::ImageLayout::eDepthStencilReadOnlyOptimal); if (with_depth && first_color != nullptr && (first_color_extent.width != depth->vulkan_buffer->extent.width || @@ -68,9 +68,9 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, "depth=%ux%u format=%s\n", first_color_extent.width, first_color_extent.height, depth->vulkan_buffer->extent.width, depth->vulkan_buffer->extent.height, - string_VkFormat(depth->format)); + VulkanToString(depth->format).c_str()); } - depth->format = VK_FORMAT_UNDEFINED; + depth->format = vk::Format::eUndefined; depth->vulkan_buffer = nullptr; depth->vulkan_view = nullptr; depth->depth_test_enable = false; @@ -81,7 +81,7 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, depth->depth_load_clear_enable = false; depth->stencil_clear_enable = false; with_depth = false; - depth_layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + depth_layout = vk::ImageLayout::eDepthStencilAttachmentOptimal; depth_read_only = false; } @@ -131,51 +131,53 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, first_color_extent.height != depth->vulkan_buffer->extent.height)); if (first_color == nullptr) { - first_color = CreateDummyBuffer(VK_FORMAT_B8G8R8A8_SRGB, depth->vulkan_buffer->extent.width, - depth->vulkan_buffer->extent.height); + first_color = + CreateDummyBuffer(vk::Format::eB8G8R8A8Srgb, depth->vulkan_buffer->extent.width, + depth->vulkan_buffer->extent.height); first_color_extent = first_color->extent; } - VkAttachmentDescription attachments[RENDER_COLOR_ATTACHMENTS_MAX + 1] = {}; + vk::AttachmentDescription attachments[RENDER_COLOR_ATTACHMENTS_MAX + 1] = {}; for (uint32_t i = 0; i < color_count; i++) { - attachments[i].flags = 0; - attachments[i].format = colors[i].format; - attachments[i].samples = VK_SAMPLE_COUNT_1_BIT; - attachments[i].loadOp = (colors[i].color_clear_enable ? VK_ATTACHMENT_LOAD_OP_CLEAR - : VK_ATTACHMENT_LOAD_OP_LOAD); - attachments[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE; - attachments[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachments[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachments[i].flags = {}; + attachments[i].format = colors[i].format; + attachments[i].samples = vk::SampleCountFlagBits::e1; + attachments[i].loadOp = (colors[i].color_clear_enable ? vk::AttachmentLoadOp::eClear + : vk::AttachmentLoadOp::eLoad); + attachments[i].storeOp = vk::AttachmentStoreOp::eStore; + attachments[i].stencilLoadOp = vk::AttachmentLoadOp::eDontCare; + attachments[i].stencilStoreOp = vk::AttachmentStoreOp::eDontCare; attachments[i].initialLayout = color_layout[i]; attachments[i].finalLayout = RENDER_COLOR_IMAGE_LAYOUT; } const uint32_t depth_attachment = color_count; - attachments[depth_attachment].flags = 0; + attachments[depth_attachment].flags = {}; attachments[depth_attachment].format = depth->format; - attachments[depth_attachment].samples = VK_SAMPLE_COUNT_1_BIT; + attachments[depth_attachment].samples = vk::SampleCountFlagBits::e1; attachments[depth_attachment].loadOp = - (depth->depth_load_clear_enable ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD); - attachments[depth_attachment].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + (depth->depth_load_clear_enable ? vk::AttachmentLoadOp::eClear + : vk::AttachmentLoadOp::eLoad); + attachments[depth_attachment].storeOp = vk::AttachmentStoreOp::eStore; attachments[depth_attachment].stencilLoadOp = - (depth->stencil_clear_enable ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD); - attachments[depth_attachment].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; + (depth->stencil_clear_enable ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad); + attachments[depth_attachment].stencilStoreOp = vk::AttachmentStoreOp::eStore; attachments[depth_attachment].initialLayout = depth_layout; attachments[depth_attachment].finalLayout = depth_layout; - VkAttachmentReference color_attachment_ref[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::AttachmentReference color_attachment_ref[RENDER_COLOR_ATTACHMENTS_MAX] = {}; for (uint32_t i = 0; i < RENDER_COLOR_ATTACHMENTS_MAX; i++) { color_attachment_ref[i].attachment = (i < color_count ? i : VK_ATTACHMENT_UNUSED); color_attachment_ref[i].layout = RENDER_COLOR_IMAGE_LAYOUT; } - VkAttachmentReference depth_attachment_ref {}; + vk::AttachmentReference depth_attachment_ref {}; depth_attachment_ref.attachment = depth_attachment; depth_attachment_ref.layout = depth_layout; - VkSubpassDescription subpass {}; - subpass.flags = 0; - subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + vk::SubpassDescription subpass {}; + subpass.flags = {}; + subpass.pipelineBindPoint = vk::PipelineBindPoint::eGraphics; subpass.inputAttachmentCount = 0; subpass.pInputAttachments = nullptr; subpass.colorAttachmentCount = color_count; @@ -185,34 +187,38 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, subpass.preserveAttachmentCount = 0; subpass.pPreserveAttachments = nullptr; - const auto attachment_stage_mask = static_cast( - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | - VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT); - const auto attachment_access_mask = static_cast( - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT); + const auto attachment_stage_mask = + static_cast(vk::PipelineStageFlagBits::eColorAttachmentOutput | + vk::PipelineStageFlagBits::eEarlyFragmentTests | + vk::PipelineStageFlagBits::eLateFragmentTests); + const auto attachment_access_mask = static_cast( + vk::AccessFlagBits::eColorAttachmentRead | vk::AccessFlagBits::eColorAttachmentWrite | + vk::AccessFlagBits::eDepthStencilAttachmentRead | + vk::AccessFlagBits::eDepthStencilAttachmentWrite); - VkSubpassDependency dependencies[2] = {}; - dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; - dependencies[0].dstSubpass = 0; - dependencies[0].srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; - dependencies[0].dstStageMask = attachment_stage_mask; - dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; - dependencies[0].dstAccessMask = attachment_access_mask; - dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; + vk::SubpassDependency dependencies[2] = {}; + dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; + dependencies[0].dstSubpass = 0; + dependencies[0].srcStageMask = vk::PipelineStageFlagBits::eAllCommands; + dependencies[0].dstStageMask = attachment_stage_mask; + dependencies[0].srcAccessMask = + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; + dependencies[0].dstAccessMask = attachment_access_mask; + dependencies[0].dependencyFlags = vk::DependencyFlagBits::eByRegion; - dependencies[1].srcSubpass = 0; - dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL; - dependencies[1].srcStageMask = attachment_stage_mask; - dependencies[1].dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; - dependencies[1].srcAccessMask = attachment_access_mask; - dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; - dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; + dependencies[1].srcSubpass = 0; + dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL; + dependencies[1].srcStageMask = attachment_stage_mask; + dependencies[1].dstStageMask = vk::PipelineStageFlagBits::eAllCommands; + dependencies[1].srcAccessMask = attachment_access_mask; + dependencies[1].dstAccessMask = + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; + dependencies[1].dependencyFlags = vk::DependencyFlagBits::eByRegion; - VkRenderPassCreateInfo render_pass_info {}; - render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + vk::RenderPassCreateInfo render_pass_info {}; + render_pass_info.sType = vk::StructureType::eRenderPassCreateInfo; render_pass_info.pNext = nullptr; - render_pass_info.flags = 0; + render_pass_info.flags = {}; render_pass_info.attachmentCount = color_count + (with_depth ? 1u : 0u); render_pass_info.pAttachments = attachments; render_pass_info.subpassCount = 1; @@ -221,10 +227,10 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, render_pass_info.pDependencies = dependencies; auto result = - vkCreateRenderPass(gctx->device, &render_pass_info, nullptr, &framebuffer->render_pass); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + gctx->device.createRenderPass(&render_pass_info, nullptr, &framebuffer->render_pass); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); - VkFormat color_formats[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::Format color_formats[RENDER_COLOR_ATTACHMENTS_MAX] = {}; for (uint32_t i = 0; i < color_count; i++) { color_formats[i] = colors[i].format; } @@ -233,7 +239,7 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, EXIT_NOT_IMPLEMENTED(framebuffer->render_pass == nullptr); - VkImageView views[RENDER_COLOR_ATTACHMENTS_MAX + 1] = {}; + vk::ImageView views[RENDER_COLOR_ATTACHMENTS_MAX + 1] = {}; for (uint32_t i = 0; i < color_count; i++) { if (colors[i].vulkan_view == nullptr) { EXIT("Framebuffer: color attachment view is missing at slot %u\n", i); @@ -247,10 +253,10 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, views[color_count] = depth->vulkan_view; } - VkFramebufferCreateInfo framebuffer_info {}; - framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + vk::FramebufferCreateInfo framebuffer_info {}; + framebuffer_info.sType = vk::StructureType::eFramebufferCreateInfo; framebuffer_info.pNext = nullptr; - framebuffer_info.flags = 0; + framebuffer_info.flags = {}; framebuffer_info.renderPass = framebuffer->render_pass; framebuffer_info.attachmentCount = color_count + (with_depth ? 1u : 0u); framebuffer_info.pAttachments = views; @@ -258,9 +264,8 @@ VulkanFramebuffer* FramebufferCache::CreateFramebuffer(RenderColorInfo* colors, framebuffer_info.height = first_color_extent.height; framebuffer_info.layers = 1; - result = - vkCreateFramebuffer(gctx->device, &framebuffer_info, nullptr, &framebuffer->framebuffer); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + result = gctx->device.createFramebuffer(&framebuffer_info, nullptr, &framebuffer->framebuffer); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(framebuffer->framebuffer == nullptr); @@ -316,9 +321,9 @@ void FramebufferCache::FreeFramebufferByColor(VulkanImage* image) { EXIT_IF(gctx == nullptr); - vkDestroyFramebuffer(gctx->device, f.framebuffer->framebuffer, nullptr); + gctx->device.destroyFramebuffer(f.framebuffer->framebuffer, nullptr); - vkDestroyRenderPass(gctx->device, f.framebuffer->render_pass, nullptr); + gctx->device.destroyRenderPass(f.framebuffer->render_pass, nullptr); delete f.framebuffer; @@ -339,9 +344,9 @@ void FramebufferCache::FreeFramebufferByDepth(DepthStencilVulkanImage* image) { EXIT_IF(gctx == nullptr); - vkDestroyFramebuffer(gctx->device, f.framebuffer->framebuffer, nullptr); + gctx->device.destroyFramebuffer(f.framebuffer->framebuffer, nullptr); - vkDestroyRenderPass(gctx->device, f.framebuffer->render_pass, nullptr); + gctx->device.destroyRenderPass(f.framebuffer->render_pass, nullptr); delete f.framebuffer; @@ -350,7 +355,7 @@ void FramebufferCache::FreeFramebufferByDepth(DepthStencilVulkanImage* image) { } } -VideoOutVulkanImage* FramebufferCache::CreateDummyBuffer(VkFormat format, uint32_t width, +VideoOutVulkanImage* FramebufferCache::CreateDummyBuffer(vk::Format format, uint32_t width, uint32_t height) { for (auto* b: m_dummy_buffers) { if (b->extent.width == width && b->extent.height == height && b->format == format) { @@ -368,55 +373,55 @@ VideoOutVulkanImage* FramebufferCache::CreateDummyBuffer(VkFormat format, uint32 vk_obj->extent.height = height; vk_obj->format = format; vk_obj->image = nullptr; - vk_obj->layout = VK_IMAGE_LAYOUT_UNDEFINED; + vk_obj->layout = vk::ImageLayout::eUndefined; UtilResetImageViews(vk_obj); - VkImageCreateInfo image_info {}; - image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + vk::ImageCreateInfo image_info {}; + image_info.sType = vk::StructureType::eImageCreateInfo; image_info.pNext = nullptr; - image_info.flags = 0; - image_info.imageType = VK_IMAGE_TYPE_2D; + image_info.flags = {}; + image_info.imageType = vk::ImageType::e2D; image_info.extent.width = vk_obj->extent.width; image_info.extent.height = vk_obj->extent.height; image_info.extent.depth = 1; image_info.mipLevels = 1; image_info.arrayLayers = 1; image_info.format = vk_obj->format; - image_info.tiling = VK_IMAGE_TILING_OPTIMAL; + image_info.tiling = vk::ImageTiling::eOptimal; image_info.initialLayout = vk_obj->layout; - image_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - image_info.samples = VK_SAMPLE_COUNT_1_BIT; + image_info.usage = vk::ImageUsageFlagBits::eColorAttachment; + image_info.sharingMode = vk::SharingMode::eExclusive; + image_info.samples = vk::SampleCountFlagBits::e1; VulkanMemory mem; - mem.property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + mem.property = vk::MemoryPropertyFlagBits::eDeviceLocal; bool created = VulkanCreateImage(ctx, &image_info, vk_obj, &mem); EXIT_NOT_IMPLEMENTED(!created); vk_obj->memory = mem; - VkImageViewCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + vk::ImageViewCreateInfo create_info {}; + create_info.sType = vk::StructureType::eImageViewCreateInfo; create_info.pNext = nullptr; - create_info.flags = 0; + create_info.flags = {}; create_info.image = vk_obj->image; - create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + create_info.viewType = vk::ImageViewType::e2D; create_info.format = vk_obj->format; - create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + create_info.components.r = vk::ComponentSwizzle::eIdentity; + create_info.components.g = vk::ComponentSwizzle::eIdentity; + create_info.components.b = vk::ComponentSwizzle::eIdentity; + create_info.components.a = vk::ComponentSwizzle::eIdentity; + create_info.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; create_info.subresourceRange.baseArrayLayer = 0; create_info.subresourceRange.baseMipLevel = 0; create_info.subresourceRange.layerCount = 1; create_info.subresourceRange.levelCount = 1; - vkCreateImageView(ctx->device, &create_info, nullptr, - &vk_obj->image_view[VulkanImage::VIEW_DEFAULT]); + ctx->device.createImageView(&create_info, nullptr, + &vk_obj->image_view[VulkanImage::VIEW_DEFAULT]); EXIT_NOT_IMPLEMENTED(vk_obj->image_view[VulkanImage::VIEW_DEFAULT] == nullptr); diff --git a/src/graphics/host_gpu/renderer/framebufferCache.h b/src/graphics/host_gpu/renderer/framebufferCache.h index 5314d79af..c8825465e 100644 --- a/src/graphics/host_gpu/renderer/framebufferCache.h +++ b/src/graphics/host_gpu/renderer/framebufferCache.h @@ -7,28 +7,28 @@ #include "common/threads.h" #include "graphics/host_gpu/graphicContext.h" #include "graphics/host_gpu/renderer/renderTarget.h" +#include "graphics/host_gpu/vulkanCommon.h" #include -#include namespace Libs::Graphics { struct RenderColorInfo; struct RenderDepthInfo; -static constexpr VkImageLayout RENDER_COLOR_IMAGE_LAYOUT = VK_IMAGE_LAYOUT_GENERAL; +static constexpr vk::ImageLayout RENDER_COLOR_IMAGE_LAYOUT = vk::ImageLayout::eGeneral; struct VulkanFramebuffer { - VkRenderPass render_pass = nullptr; - uint64_t render_pass_id = 0; - VkFramebuffer framebuffer = nullptr; - VkImageLayout color_layout[RENDER_COLOR_ATTACHMENTS_MAX] = {}; - VkImageLayout depth_layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + vk::RenderPass render_pass = nullptr; + uint64_t render_pass_id = 0; + vk::Framebuffer framebuffer = nullptr; + vk::ImageLayout color_layout[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::ImageLayout depth_layout = vk::ImageLayout::eDepthStencilAttachmentOptimal; }; -inline uint64_t render_pass_compat_id(uint32_t color_count, const VkFormat* color_formats, - bool with_depth, VkFormat depth_format, - VkImageLayout depth_layout) { +inline uint64_t render_pass_compat_id(uint32_t color_count, const vk::Format* color_formats, + bool with_depth, vk::Format depth_format, + vk::ImageLayout depth_layout) { uint64_t id = 0xcbf29ce484222325ull; auto mix = [&id](uint64_t v) { id ^= v; @@ -42,7 +42,7 @@ inline uint64_t render_pass_compat_id(uint32_t color_count, const VkFormat* colo mix(with_depth ? 1u : 0u); mix(static_cast(depth_format)); mix(static_cast(depth_layout)); - mix(VK_SAMPLE_COUNT_1_BIT); + mix(static_cast(vk::SampleCountFlagBits::e1)); return id; } @@ -59,16 +59,16 @@ public: void FreeFramebufferByDepth(DepthStencilVulkanImage* image); private: - VideoOutVulkanImage* CreateDummyBuffer(VkFormat format, uint32_t width, uint32_t height); + VideoOutVulkanImage* CreateDummyBuffer(vk::Format format, uint32_t width, uint32_t height); struct Framebuffer { VulkanFramebuffer* framebuffer = nullptr; uint64_t image_id[RENDER_COLOR_ATTACHMENTS_MAX] = {}; - VkImageView color_view[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::ImageView color_view[RENDER_COLOR_ATTACHMENTS_MAX] = {}; uint64_t depth_id = 0; - VkImageView depth_view = nullptr; + vk::ImageView depth_view = nullptr; bool color_clear_enable[RENDER_COLOR_ATTACHMENTS_MAX] = {}; - VkImageLayout color_layout[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::ImageLayout color_layout[RENDER_COLOR_ATTACHMENTS_MAX] = {}; bool depth_clear_enable = false; bool stencil_clear_enable = false; bool depth_read_only = false; diff --git a/src/graphics/host_gpu/renderer/gdsBuffer.cpp b/src/graphics/host_gpu/renderer/gdsBuffer.cpp index f389905e6..970911a0f 100644 --- a/src/graphics/host_gpu/renderer/gdsBuffer.cpp +++ b/src/graphics/host_gpu/renderer/gdsBuffer.cpp @@ -10,10 +10,10 @@ void GdsBuffer::Init(GraphicContext* ctx) { if (m_buffer == nullptr) { m_buffer = std::make_unique(); - m_buffer->usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - m_buffer->memory.property = static_cast(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + m_buffer->usage = vk::BufferUsageFlagBits::eStorageBuffer; + m_buffer->memory.property = vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent | + vk::MemoryPropertyFlagBits::eHostCached; VulkanCreateBuffer(ctx, DW_SIZE * 4, m_buffer.get()); } } diff --git a/src/graphics/host_gpu/renderer/image.cpp b/src/graphics/host_gpu/renderer/image.cpp index 7cde47fc3..2df401a7a 100644 --- a/src/graphics/host_gpu/renderer/image.cpp +++ b/src/graphics/host_gpu/renderer/image.cpp @@ -47,42 +47,43 @@ TextureImageCreateParams MakeImageParams(const ImageInfo& info, bool storage) { return params; } -bool RenderTargetSupportsStorage(GraphicContext* ctx, VkFormat format, VkImageCreateFlags flags) { +bool RenderTargetSupportsStorage(GraphicContext* ctx, vk::Format format, + vk::ImageCreateFlags flags) { const auto compatible = SrgbStorageViewFormat(format); const auto required_flags = - VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT; + vk::ImageCreateFlagBits::eMutableFormat | vk::ImageCreateFlagBits::eExtendedUsage; const bool compatible_views = (flags & required_flags) == required_flags; return ImageViewOps::FormatSupportsStorage(ctx, format) || - (compatible_views && compatible != VK_FORMAT_UNDEFINED && + (compatible_views && compatible != vk::Format::eUndefined && ImageViewOps::FormatSupportsStorage(ctx, compatible)); } -VkImageCreateFlags RenderTargetCreateFlags(VkFormat format) { +vk::ImageCreateFlags RenderTargetCreateFlags(vk::Format format) { const bool compatible_format_view = IsRgba8SrgbViewFormat(format) || - BgraToRgbaSampledViewFormat(format) != VK_FORMAT_UNDEFINED || - format == VK_FORMAT_R8G8B8A8_UINT || format == VK_FORMAT_R16G16B16A16_SFLOAT || - format == VK_FORMAT_R16G16B16A16_UINT; + BgraToRgbaSampledViewFormat(format) != vk::Format::eUndefined || + format == vk::Format::eR8G8B8A8Uint || format == vk::Format::eR16G16B16A16Sfloat || + format == vk::Format::eR16G16B16A16Uint; return compatible_format_view - ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT - : VkImageCreateFlags {0}; + ? vk::ImageCreateFlagBits::eMutableFormat | vk::ImageCreateFlagBits::eExtendedUsage + : vk::ImageCreateFlags {0}; } -VkImageUsageFlags RenderTargetUsage(GraphicContext* ctx, VkFormat format, - VkImageCreateFlags flags) { - auto usage = static_cast(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) | - static_cast(VK_IMAGE_USAGE_TRANSFER_SRC_BIT) | - static_cast(VK_IMAGE_USAGE_TRANSFER_DST_BIT) | - static_cast(VK_IMAGE_USAGE_SAMPLED_BIT); +vk::ImageUsageFlags RenderTargetUsage(GraphicContext* ctx, vk::Format format, + vk::ImageCreateFlags flags) { + auto usage = static_cast(vk::ImageUsageFlagBits::eColorAttachment) | + static_cast(vk::ImageUsageFlagBits::eTransferSrc) | + static_cast(vk::ImageUsageFlagBits::eTransferDst) | + static_cast(vk::ImageUsageFlagBits::eSampled); if (RenderTargetSupportsStorage(ctx, format, flags)) { - usage |= VK_IMAGE_USAGE_STORAGE_BIT; + usage |= vk::ImageUsageFlagBits::eStorage; } - VkImageFormatProperties properties {}; - if (ctx->GetImageFormatProperties(format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, usage, - flags, &properties) != VK_SUCCESS) { + vk::ImageFormatProperties properties {}; + if (ctx->GetImageFormatProperties(format, vk::ImageType::e2D, vk::ImageTiling::eOptimal, usage, + flags, &properties) != vk::Result::eSuccess) { EXIT("TextureCache: render-target format does not support required usage, format=%d " "usage=0x%x\n", - static_cast(format), usage); + static_cast(format), static_cast(usage)); } return usage; } @@ -139,7 +140,7 @@ uint32_t RenderTargetTransferFormat(uint32_t bytes_per_element) { } GpuTextureVulkanImage* CreateTexture(GraphicContext* ctx, const ImageInfo& info, bool storage, - VulkanMemory* memory, VkComponentMapping* components) { + VulkanMemory* memory, vk::ComponentMapping* components) { if (components == nullptr) { EXIT("TextureCache: invalid texture component output\n"); } @@ -150,7 +151,7 @@ GpuTextureVulkanImage* CreateTexture(GraphicContext* ctx, const ImageInfo& info, } void CreateTextureViews(GraphicContext* ctx, GpuTextureVulkanImage* image, const ImageInfo& info, - bool storage, VkComponentMapping components) { + bool storage, vk::ComponentMapping components) { if (storage) { TextureCreateImageViews(ctx, image, components, info.type, 0, 0, 1, info.depth, false, TextureFormatUsage::Sampled | TextureFormatUsage::Storage); @@ -195,11 +196,11 @@ void UploadRenderTargetLayers(GraphicContext* ctx, RenderTextureVulkanImage* ima region.dst_layer += base_layer; } const auto source_address = info.address + slice_size * base_layer; - TextureUploadGuestImage( - ctx, image, reinterpret_cast(source_address), upload_size, regions, layout, - format, info.width, info.height, layer_count, info.levels, - TextureUploadSliceLayout::MipChainPerSlice, "TextureCache render target", - static_cast(VK_IMAGE_LAYOUT_GENERAL)); + TextureUploadGuestImage(ctx, image, reinterpret_cast(source_address), + upload_size, regions, layout, format, info.width, info.height, + layer_count, info.levels, + TextureUploadSliceLayout::MipChainPerSlice, + "TextureCache render target", vk::ImageLayout::eGeneral); return; } if (info.tile_mode == Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && @@ -209,10 +210,10 @@ void UploadRenderTargetLayers(GraphicContext* ctx, RenderTextureVulkanImage* ima scratch.Data(), reinterpret_cast(info.address), info.width, info.height, info.pitch, info.bytes_per_element, slice_size); UtilFillImage(ctx, image, scratch.Data(), slice_size, info.pitch, - static_cast(VK_IMAGE_LAYOUT_GENERAL)); + vk::ImageLayout::eGeneral); } else { UtilFillImage(ctx, image, reinterpret_cast(info.address), slice_size, - info.pitch, static_cast(VK_IMAGE_LAYOUT_GENERAL)); + info.pitch, vk::ImageLayout::eGeneral); } } @@ -229,22 +230,22 @@ RenderTextureVulkanImage* CreateRenderTarget(GraphicContext* ctx, const RenderTa image->format = info.format; image->mip_levels = info.levels; image->layers = info.layers; - image->layout = VK_IMAGE_LAYOUT_UNDEFINED; + image->layout = vk::ImageLayout::eUndefined; UtilResetImageViews(image); - VkImageCreateInfo create {}; - create.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + vk::ImageCreateInfo create {}; + create.sType = vk::StructureType::eImageCreateInfo; create.flags = RenderTargetCreateFlags(info.format); - create.imageType = VK_IMAGE_TYPE_2D; + create.imageType = vk::ImageType::e2D; create.extent = {info.width, info.height, 1}; create.mipLevels = info.levels; create.arrayLayers = info.layers; create.format = info.format; - create.tiling = VK_IMAGE_TILING_OPTIMAL; - create.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + create.tiling = vk::ImageTiling::eOptimal; + create.initialLayout = vk::ImageLayout::eUndefined; create.usage = RenderTargetUsage(ctx, info.format, create.flags); - create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - create.samples = VK_SAMPLE_COUNT_1_BIT; - memory->property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + create.sharingMode = vk::SharingMode::eExclusive; + create.samples = vk::SampleCountFlagBits::e1; + memory->property = vk::MemoryPropertyFlagBits::eDeviceLocal; if (!VulkanCreateImage(ctx, &create, image, memory)) { EXIT("TextureCache: failed to create render target, addr=0x%016" PRIx64 " extent=%ux%u format=%d\n", @@ -257,23 +258,25 @@ RenderTextureVulkanImage* CreateRenderTarget(GraphicContext* ctx, const RenderTa DepthStencilVulkanImage* CreateDepthTarget(GraphicContext* ctx, const DepthTargetInfo& info, VulkanMemory* memory) { - VkImageCreateInfo create {}; - create.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - create.imageType = VK_IMAGE_TYPE_2D; + vk::ImageCreateInfo create {}; + create.sType = vk::StructureType::eImageCreateInfo; + create.imageType = vk::ImageType::e2D; create.extent = {info.width, info.height, 1}; create.mipLevels = 1; create.arrayLayers = info.layers; create.format = info.format; - create.tiling = VK_IMAGE_TILING_OPTIMAL; - create.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + create.tiling = vk::ImageTiling::eOptimal; + create.initialLayout = vk::ImageLayout::eUndefined; create.usage = DepthTargetImageUsage(); - create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - create.samples = VK_SAMPLE_COUNT_1_BIT; - VkImageFormatProperties properties {}; - if (ctx->GetImageFormatProperties(info.format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, - create.usage, 0, &properties) != VK_SUCCESS) { + create.sharingMode = vk::SharingMode::eExclusive; + create.samples = vk::SampleCountFlagBits::e1; + vk::ImageFormatProperties properties {}; + if (ctx->GetImageFormatProperties(info.format, vk::ImageType::e2D, vk::ImageTiling::eOptimal, + create.usage, vk::ImageCreateFlags {}, + &properties) != vk::Result::eSuccess) { EXIT("TextureCache: depth format does not support required usage, format=%d usage=0x%x\n", - static_cast(info.format), create.usage); + static_cast(info.format), + static_cast(create.usage)); } auto* image = new DepthStencilVulkanImage; image->extent.width = info.width; @@ -281,10 +284,10 @@ DepthStencilVulkanImage* CreateDepthTarget(GraphicContext* ctx, const DepthTarge image->guest_pitch = info.pitch; image->layers = info.layers; image->format = info.format; - image->layout = VK_IMAGE_LAYOUT_UNDEFINED; + image->layout = vk::ImageLayout::eUndefined; image->compressed = false; UtilResetImageViews(image); - memory->property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + memory->property = vk::MemoryPropertyFlagBits::eDeviceLocal; if (!VulkanCreateImage(ctx, &create, image, memory)) { EXIT("TextureCache: failed to create depth target, addr=0x%016" PRIx64 " extent=%ux%u format=%d\n", @@ -328,7 +331,7 @@ void ValidateVideoOut(GraphicContext* ctx, const VideoOutInfo& info) { " pitch=%u\n", info.address, info.size, exact.size, exact.align, info.pitch); } - (void)RenderTargetUsage(ctx, info.format, 0); + (void)RenderTargetUsage(ctx, info.format, vk::ImageCreateFlags {}); } VideoOutVulkanImage* CreateVideoOut(GraphicContext* ctx, const VideoOutInfo& info, @@ -337,22 +340,22 @@ VideoOutVulkanImage* CreateVideoOut(GraphicContext* ctx, const VideoOutInfo& inf image->extent.width = info.width; image->extent.height = info.height; image->format = info.format; - image->layout = VK_IMAGE_LAYOUT_UNDEFINED; + image->layout = vk::ImageLayout::eUndefined; UtilResetImageViews(image); - VkImageCreateInfo create {}; - create.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - create.imageType = VK_IMAGE_TYPE_2D; + vk::ImageCreateInfo create {}; + create.sType = vk::StructureType::eImageCreateInfo; + create.imageType = vk::ImageType::e2D; create.extent = {info.width, info.height, 1}; create.mipLevels = 1; create.arrayLayers = 1; create.format = info.format; - create.tiling = VK_IMAGE_TILING_OPTIMAL; - create.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + create.tiling = vk::ImageTiling::eOptimal; + create.initialLayout = vk::ImageLayout::eUndefined; create.flags = RenderTargetCreateFlags(info.format); create.usage = RenderTargetUsage(ctx, info.format, create.flags); - create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - create.samples = VK_SAMPLE_COUNT_1_BIT; - memory->property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + create.sharingMode = vk::SharingMode::eExclusive; + create.samples = vk::SampleCountFlagBits::e1; + memory->property = vk::MemoryPropertyFlagBits::eDeviceLocal; if (!VulkanCreateImage(ctx, &create, image, memory)) { EXIT("TextureCache: failed to create video-out image, addr=0x%016" PRIx64 " extent=%ux%u format=%d\n", @@ -373,7 +376,7 @@ void UploadVideoOut(GraphicContext* ctx, VideoOutVulkanImage* image, const Video if (refresh) { VulkanDeviceWaitIdle(ctx); } - image->layout = VK_IMAGE_LAYOUT_UNDEFINED; + image->layout = vk::ImageLayout::eUndefined; UtilScratchBuffer scratch(info.size); TileConvertTiledToLinearRenderTarget( scratch.Data(), reinterpret_cast(info.address), info.width, info.height, @@ -384,8 +387,7 @@ void UploadVideoOut(GraphicContext* ctx, VideoOutVulkanImage* image, const Video std::swap(pixels[i], pixels[i + 2]); } } - UtilFillImage(ctx, image, scratch.Data(), info.size, info.pitch, - static_cast(VK_IMAGE_LAYOUT_GENERAL)); + UtilFillImage(ctx, image, scratch.Data(), info.size, info.pitch, vk::ImageLayout::eGeneral); } GpuTextureVulkanImage* CreateDummyTexture(GraphicContext* ctx, bool uint_format, bool image_3d, @@ -398,14 +400,14 @@ GpuTextureVulkanImage* CreateDummyTexture(GraphicContext* ctx, bool uint_format, auto* image = storage ? static_cast(new StorageTextureVulkanImage) : new TextureVulkanImage; auto usage = storage ? TextureFormatUsage::Storage : TextureFormatUsage::Sampled; - auto layout = storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + auto layout = storage ? vk::ImageLayout::eGeneral : vk::ImageLayout::eShaderReadOnlyOptimal; auto owner = storage ? "DummyStorageTexture" : "DummySampledTexture"; auto params = MakeDummyTextureParams(uint_format, image_3d, usage, owner); auto components = TextureCreateImage(ctx, image, memory, params); static constexpr uint32_t zero = 0; - UtilFillImage(ctx, image, &zero, sizeof(zero), 1, static_cast(layout)); + UtilFillImage(ctx, image, &zero, sizeof(zero), 1, layout); TextureCreateImageViews(ctx, image, components, params.type, 0, params.base_level, params.levels, params.depth, params.allow_cube_view, params.view_usage); return image; diff --git a/src/graphics/host_gpu/renderer/image.h b/src/graphics/host_gpu/renderer/image.h index 0da90c634..17c46f9a2 100644 --- a/src/graphics/host_gpu/renderer/image.h +++ b/src/graphics/host_gpu/renderer/image.h @@ -102,9 +102,9 @@ namespace ImageOps { [[nodiscard]] GpuTextureVulkanImage* CreateTexture(GraphicContext* ctx, const ImageInfo& info, bool storage, VulkanMemory* memory, - VkComponentMapping* components); + vk::ComponentMapping* components); void CreateTextureViews(GraphicContext* ctx, GpuTextureVulkanImage* image, const ImageInfo& info, - bool storage, VkComponentMapping components); + bool storage, vk::ComponentMapping components); [[nodiscard]] RenderTextureVulkanImage* CreateRenderTarget(GraphicContext* ctx, const RenderTargetInfo& info, VulkanMemory* memory); diff --git a/src/graphics/host_gpu/renderer/imageInfo.h b/src/graphics/host_gpu/renderer/imageInfo.h index f89def2b0..239573cc1 100644 --- a/src/graphics/host_gpu/renderer/imageInfo.h +++ b/src/graphics/host_gpu/renderer/imageInfo.h @@ -4,12 +4,12 @@ #include "common/assert.h" #include "graphics/guest_gpu/gpu_defs.h" #include "graphics/host_gpu/regionDefinitions.h" +#include "graphics/host_gpu/vulkanCommon.h" #include #include #include #include -#include namespace Libs::Graphics { @@ -31,34 +31,34 @@ struct ImageInfo { }; struct RenderTargetInfo { - uint64_t address = 0; - uint64_t size = 0; - VkFormat format = VK_FORMAT_UNDEFINED; - uint32_t width = 0; - uint32_t height = 0; - uint32_t pitch = 0; - uint32_t bytes_per_element = 0; - uint32_t tile_mode = 0; - uint32_t levels = 1; - uint32_t layers = 1; + uint64_t address = 0; + uint64_t size = 0; + vk::Format format = vk::Format::eUndefined; + uint32_t width = 0; + uint32_t height = 0; + uint32_t pitch = 0; + uint32_t bytes_per_element = 0; + uint32_t tile_mode = 0; + uint32_t levels = 1; + uint32_t layers = 1; }; // Common image-to-buffer copy description. Storage images and render targets keep distinct // cache records today, but downloads should consume one normalized layout just as uploads do. struct ColorImageTransferInfo { - uint64_t address = 0; - uint64_t size = 0; - VkFormat format = VK_FORMAT_UNDEFINED; - uint32_t width = 0; - uint32_t height = 0; - uint32_t pitch = 0; - uint32_t bytes_per_element = 0; - uint32_t tile_mode = 0; - uint32_t levels = 1; + uint64_t address = 0; + uint64_t size = 0; + vk::Format format = vk::Format::eUndefined; + uint32_t width = 0; + uint32_t height = 0; + uint32_t pitch = 0; + uint32_t bytes_per_element = 0; + uint32_t tile_mode = 0; + uint32_t levels = 1; }; [[nodiscard]] inline ColorImageTransferInfo -MakeColorImageTransferInfo(const ImageInfo& info, VkFormat format, +MakeColorImageTransferInfo(const ImageInfo& info, vk::Format format, uint32_t bytes_per_element) noexcept { return {info.address, info.size, format, info.width, info.height, info.pitch, bytes_per_element, info.tile, info.levels}; @@ -72,48 +72,48 @@ MakeColorImageTransferInfo(const RenderTargetInfo& info) noexcept { } struct DepthTargetInfo { - uint64_t address = 0; - uint64_t size = 0; - uint64_t stencil_address = 0; - uint64_t stencil_size = 0; - uint64_t htile_address = 0; - uint64_t htile_size = 0; - VkFormat format = VK_FORMAT_UNDEFINED; - uint32_t guest_format = 0; - uint32_t width = 0; - uint32_t height = 0; - uint32_t pitch = 0; - uint32_t bytes_per_element = 0; - uint32_t tile_mode = 0; - uint32_t layers = 1; - bool depth_load_clear = false; - bool stencil_load_clear = false; - bool stencil_access = false; - bool stencil_htile_compressed = false; + uint64_t address = 0; + uint64_t size = 0; + uint64_t stencil_address = 0; + uint64_t stencil_size = 0; + uint64_t htile_address = 0; + uint64_t htile_size = 0; + vk::Format format = vk::Format::eUndefined; + uint32_t guest_format = 0; + uint32_t width = 0; + uint32_t height = 0; + uint32_t pitch = 0; + uint32_t bytes_per_element = 0; + uint32_t tile_mode = 0; + uint32_t layers = 1; + bool depth_load_clear = false; + bool stencil_load_clear = false; + bool stencil_access = false; + bool stencil_htile_compressed = false; }; struct DepthFormatPolicy { - Prospero::DepthFormat depth_format; - Prospero::BufferFormat guest_format; - uint32_t bytes_per_element; - VkFormat sampled_view_format; - VkFormat depth_attachment_format; - std::array stencil_attachment_formats; + Prospero::DepthFormat depth_format; + Prospero::BufferFormat guest_format; + uint32_t bytes_per_element; + vk::Format sampled_view_format; + vk::Format depth_attachment_format; + std::array stencil_attachment_formats; }; inline constexpr std::array DEPTH_FORMAT_POLICIES {{ {Prospero::DepthFormat::kZ16, Prospero::BufferFormat::k16UNorm, 2, - VK_FORMAT_R16_UNORM, - VK_FORMAT_D16_UNORM, - {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT}}, + vk::Format::eR16Unorm, + vk::Format::eD16Unorm, + {vk::Format::eD16UnormS8Uint, vk::Format::eD24UnormS8Uint, vk::Format::eD32SfloatS8Uint}}, {Prospero::DepthFormat::kZ32F, Prospero::BufferFormat::k32Float, 4, - VK_FORMAT_R32_SFLOAT, - VK_FORMAT_D32_SFLOAT, - {VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED}}, + vk::Format::eR32Sfloat, + vk::Format::eD32Sfloat, + {vk::Format::eD32SfloatS8Uint, vk::Format::eUndefined, vk::Format::eUndefined}}, }}; [[nodiscard]] inline constexpr const DepthFormatPolicy* @@ -137,53 +137,53 @@ FindGuestDepthFormatPolicy(uint32_t guest_format) noexcept { } [[nodiscard]] inline constexpr bool IsStencilAttachmentFormat(const DepthFormatPolicy& policy, - VkFormat format) noexcept { + vk::Format format) noexcept { for (const auto candidate: policy.stencil_attachment_formats) { - if (candidate != VK_FORMAT_UNDEFINED && candidate == format) { + if (candidate != vk::Format::eUndefined && candidate == format) { return true; } } return false; } -[[nodiscard]] inline constexpr VkFormat DepthAttachmentFormat(const DepthFormatPolicy& policy, - bool has_stencil) noexcept { +[[nodiscard]] inline constexpr vk::Format DepthAttachmentFormat(const DepthFormatPolicy& policy, + bool has_stencil) noexcept { return has_stencil ? policy.stencil_attachment_formats.front() : policy.depth_attachment_format; } -[[nodiscard]] inline constexpr VkFormat DepthAttachmentFormat(uint32_t depth_format, - uint32_t stencil_format) noexcept { +[[nodiscard]] inline constexpr vk::Format DepthAttachmentFormat(uint32_t depth_format, + uint32_t stencil_format) noexcept { bool has_stencil = false; switch (static_cast(stencil_format)) { case Prospero::StencilFormat::kInvalid: break; case Prospero::StencilFormat::k8UInt: has_stencil = true; break; - default: return VK_FORMAT_UNDEFINED; + default: return vk::Format::eUndefined; } const auto* policy = FindDepthFormatPolicy(depth_format); - return policy == nullptr ? VK_FORMAT_UNDEFINED : DepthAttachmentFormat(*policy, has_stencil); + return policy == nullptr ? vk::Format::eUndefined : DepthAttachmentFormat(*policy, has_stencil); } -[[nodiscard]] inline constexpr VkImageUsageFlags DepthTargetImageUsage() noexcept { - return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; +[[nodiscard]] inline constexpr vk::ImageUsageFlags DepthTargetImageUsage() noexcept { + return vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eSampled | + vk::ImageUsageFlagBits::eTransferSrc | vk::ImageUsageFlagBits::eTransferDst; } -[[nodiscard]] inline constexpr VkFormat DepthAspectTransferFormat(VkFormat format) noexcept { +[[nodiscard]] inline constexpr vk::Format DepthAspectTransferFormat(vk::Format format) noexcept { switch (format) { - case VK_FORMAT_D16_UNORM: - case VK_FORMAT_D16_UNORM_S8_UINT: return VK_FORMAT_D16_UNORM; - case VK_FORMAT_D24_UNORM_S8_UINT: return VK_FORMAT_X8_D24_UNORM_PACK32; - case VK_FORMAT_D32_SFLOAT: - case VK_FORMAT_D32_SFLOAT_S8_UINT: return VK_FORMAT_D32_SFLOAT; - default: return VK_FORMAT_UNDEFINED; + case vk::Format::eD16Unorm: + case vk::Format::eD16UnormS8Uint: return vk::Format::eD16Unorm; + case vk::Format::eD24UnormS8Uint: return vk::Format::eX8D24UnormPack32; + case vk::Format::eD32Sfloat: + case vk::Format::eD32SfloatS8Uint: return vk::Format::eD32Sfloat; + default: return vk::Format::eUndefined; } } -[[nodiscard]] inline constexpr uint32_t DepthAspectTransferBytes(VkFormat format) noexcept { +[[nodiscard]] inline constexpr uint32_t DepthAspectTransferBytes(vk::Format format) noexcept { switch (DepthAspectTransferFormat(format)) { - case VK_FORMAT_D16_UNORM: return 2; - case VK_FORMAT_X8_D24_UNORM_PACK32: - case VK_FORMAT_D32_SFLOAT: return 4; + case vk::Format::eD16Unorm: return 2; + case vk::Format::eX8D24UnormPack32: + case vk::Format::eD32Sfloat: return 4; default: return 0; } } @@ -197,17 +197,17 @@ FindGuestDepthFormatPolicy(uint32_t guest_format) noexcept { return std::bit_cast(static_cast(value) / 65535.0f); } -[[nodiscard]] inline constexpr bool IsSupportedSampledDepthFormat(VkFormat image_format, - uint32_t guest_format, - VkFormat view_format) noexcept { +[[nodiscard]] inline constexpr bool IsSupportedSampledDepthFormat(vk::Format image_format, + uint32_t guest_format, + vk::Format view_format) noexcept { const auto* policy = FindGuestDepthFormatPolicy(guest_format); return policy != nullptr && view_format == policy->sampled_view_format && (image_format == policy->depth_attachment_format || IsStencilAttachmentFormat(*policy, image_format)); } -[[nodiscard]] inline constexpr bool IsSupportedSampledDepthFormat(VkFormat image_format, - VkFormat view_format) noexcept { +[[nodiscard]] inline constexpr bool IsSupportedSampledDepthFormat(vk::Format image_format, + vk::Format view_format) noexcept { for (const auto& policy: DEPTH_FORMAT_POLICIES) { if (IsSupportedSampledDepthFormat(image_format, Prospero::GpuEnumValue(policy.guest_format), view_format)) { @@ -231,7 +231,7 @@ struct VideoOutInfo { uint64_t address = 0; uint64_t size = 0; uint64_t metadata_address = 0; - VkFormat format = VK_FORMAT_UNDEFINED; + vk::Format format = vk::Format::eUndefined; uint32_t guest_format = 0; uint32_t width = 0; uint32_t height = 0; @@ -272,10 +272,10 @@ CanUseVideoOutNativeWithoutUpload(VideoOutCompression compression, bool render_t } struct VideoOutPixelFormatInfo { - VkFormat format = VK_FORMAT_UNDEFINED; - uint32_t guest_format = 0; - uint32_t bytes_per_element = 0; - bool bgra16 = false; + vk::Format format = vk::Format::eUndefined; + uint32_t guest_format = 0; + uint32_t bytes_per_element = 0; + bool bgra16 = false; }; struct VideoOutFormatPolicy { @@ -285,22 +285,22 @@ struct VideoOutFormatPolicy { inline constexpr std::array VIDEO_OUT_FORMAT_POLICIES {{ {0x8000000022000000ull, - {VK_FORMAT_R8G8B8A8_SRGB, Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb), 4, + {vk::Format::eR8G8B8A8Srgb, Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb), 4, false}}, {0x8000000000000000ull, - {VK_FORMAT_B8G8R8A8_SRGB, Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb), 4, + {vk::Format::eB8G8R8A8Srgb, Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb), 4, false}}, {0x8100000022000000ull, - {VK_FORMAT_A2B10G10R10_UNORM_PACK32, + {vk::Format::eA2B10G10R10UnormPack32, Prospero::GpuEnumValue(Prospero::BufferFormat::k10_10_10_2UNorm), 4, false}}, {0x8100000000000000ull, - {VK_FORMAT_A2R10G10B10_UNORM_PACK32, + {vk::Format::eA2R10G10B10UnormPack32, Prospero::GpuEnumValue(Prospero::BufferFormat::k10_10_10_2UNorm), 4, false}}, {0xc001000622000000ull, - {VK_FORMAT_R16G16B16A16_SFLOAT, + {vk::Format::eR16G16B16A16Sfloat, Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float), 8, false}}, {0xc001000600000000ull, - {VK_FORMAT_R16G16B16A16_SFLOAT, + {vk::Format::eR16G16B16A16Sfloat, Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float), 8, true}}, }}; @@ -384,12 +384,12 @@ enum class MetaImageOverlap : uint8_t { RetainSampled, RetireTarget, Unsupported } [[nodiscard]] inline constexpr bool -IsDepthUintTextureReinterpretation(VkFormat image_format, uint32_t guest_format, - VkFormat view_format) noexcept { +IsDepthUintTextureReinterpretation(vk::Format image_format, uint32_t guest_format, + vk::Format view_format) noexcept { switch (image_format) { - case VK_FORMAT_D32_SFLOAT: + case vk::Format::eD32Sfloat: return guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt) && - view_format == VK_FORMAT_R32_UINT; + view_format == vk::Format::eR32Uint; default: return false; } } @@ -479,45 +479,45 @@ SelectDepthTransitionSource(bool depth_load_clear, bool sampled_native_available return encoded <= 0.04045f ? encoded / 12.92f : std::pow((encoded + 0.055f) / 1.055f, 2.4f); } -[[nodiscard]] inline bool DecodePackedColorClear(VkFormat format, uint32_t packed, - VkClearColorValue* clear) { +[[nodiscard]] inline bool DecodePackedColorClear(vk::Format format, uint32_t packed, + vk::ClearColorValue* clear) { if (clear == nullptr) { return false; } - VkClearColorValue next {}; + vk::ClearColorValue next {}; const auto unorm8 = [](uint32_t value) { return static_cast(value & 0xffu) / 255.0f; }; switch (format) { - case VK_FORMAT_R8G8B8A8_SRGB: + case vk::Format::eR8G8B8A8Srgb: next.float32[0] = DecodeSrgbClearComponent(packed); next.float32[1] = DecodeSrgbClearComponent(packed >> 8u); next.float32[2] = DecodeSrgbClearComponent(packed >> 16u); next.float32[3] = unorm8(packed >> 24u); break; - case VK_FORMAT_B8G8R8A8_SRGB: + case vk::Format::eB8G8R8A8Srgb: next.float32[0] = DecodeSrgbClearComponent(packed >> 16u); next.float32[1] = DecodeSrgbClearComponent(packed >> 8u); next.float32[2] = DecodeSrgbClearComponent(packed); next.float32[3] = unorm8(packed >> 24u); break; - case VK_FORMAT_R8G8B8A8_UNORM: + case vk::Format::eR8G8B8A8Unorm: next.float32[0] = unorm8(packed); next.float32[1] = unorm8(packed >> 8u); next.float32[2] = unorm8(packed >> 16u); next.float32[3] = unorm8(packed >> 24u); break; - case VK_FORMAT_B8G8R8A8_UNORM: + case vk::Format::eB8G8R8A8Unorm: next.float32[0] = unorm8(packed >> 16u); next.float32[1] = unorm8(packed >> 8u); next.float32[2] = unorm8(packed); next.float32[3] = unorm8(packed >> 24u); break; - case VK_FORMAT_A2B10G10R10_UNORM_PACK32: + case vk::Format::eA2B10G10R10UnormPack32: next.float32[0] = static_cast(packed & 0x3ffu) / 1023.0f; next.float32[1] = static_cast((packed >> 10u) & 0x3ffu) / 1023.0f; next.float32[2] = static_cast((packed >> 20u) & 0x3ffu) / 1023.0f; next.float32[3] = static_cast((packed >> 30u) & 0x3u) / 3.0f; break; - case VK_FORMAT_A2R10G10B10_UNORM_PACK32: + case vk::Format::eA2R10G10B10UnormPack32: next.float32[0] = static_cast((packed >> 20u) & 0x3ffu) / 1023.0f; next.float32[1] = static_cast((packed >> 10u) & 0x3ffu) / 1023.0f; next.float32[2] = static_cast(packed & 0x3ffu) / 1023.0f; @@ -541,9 +541,9 @@ SelectDepthTransitionSource(bool depth_load_clear, bool sampled_native_available return true; } -[[nodiscard]] inline bool DecodePackedDepthClear(VkFormat format, uint32_t packed, float* clear) { +[[nodiscard]] inline bool DecodePackedDepthClear(vk::Format format, uint32_t packed, float* clear) { if (clear == nullptr || - (format != VK_FORMAT_D32_SFLOAT && format != VK_FORMAT_D32_SFLOAT_S8_UINT)) { + (format != vk::Format::eD32Sfloat && format != vk::Format::eD32SfloatS8Uint)) { return false; } const auto value = std::bit_cast(packed); @@ -557,7 +557,7 @@ SelectDepthTransitionSource(bool depth_load_clear, bool sampled_native_available [[nodiscard]] inline bool CanNativeClearDepthFromBuffer(const DepthTargetInfo& target, uint64_t address, uint64_t size) { const bool d32 = - target.format == VK_FORMAT_D32_SFLOAT || target.format == VK_FORMAT_D32_SFLOAT_S8_UINT; + target.format == vk::Format::eD32Sfloat || target.format == vk::Format::eD32SfloatS8Uint; return address == target.address && size == target.size && target.layers == 1 && d32 && target.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) && target.bytes_per_element == 4 && @@ -621,31 +621,32 @@ SelectDepthTransitionSource(bool depth_load_clear, bool sampled_native_available : SampledOverlap::Unsupported; } -[[nodiscard]] inline bool IsRgba8SrgbReinterpretation(VkFormat cached, VkFormat requested) noexcept; +[[nodiscard]] inline bool IsRgba8SrgbReinterpretation(vk::Format cached, + vk::Format requested) noexcept; -[[nodiscard]] inline bool IsR32UintFloatReinterpretation(VkFormat cached, - VkFormat requested) noexcept { +[[nodiscard]] inline bool IsR32UintFloatReinterpretation(vk::Format cached, + vk::Format requested) noexcept { switch (cached) { - case VK_FORMAT_R32_UINT: return requested == VK_FORMAT_R32_SFLOAT; - case VK_FORMAT_R32_SFLOAT: return requested == VK_FORMAT_R32_UINT; + case vk::Format::eR32Uint: return requested == vk::Format::eR32Sfloat; + case vk::Format::eR32Sfloat: return requested == vk::Format::eR32Uint; default: return false; } } -[[nodiscard]] inline bool IsRgba16UintFloatReinterpretation(VkFormat cached, - VkFormat requested) noexcept { +[[nodiscard]] inline bool IsRgba16UintFloatReinterpretation(vk::Format cached, + vk::Format requested) noexcept { switch (cached) { - case VK_FORMAT_R16G16B16A16_SFLOAT: return requested == VK_FORMAT_R16G16B16A16_UINT; - case VK_FORMAT_R16G16B16A16_UINT: return requested == VK_FORMAT_R16G16B16A16_SFLOAT; + case vk::Format::eR16G16B16A16Sfloat: return requested == vk::Format::eR16G16B16A16Uint; + case vk::Format::eR16G16B16A16Uint: return requested == vk::Format::eR16G16B16A16Sfloat; default: return false; } } -[[nodiscard]] inline bool IsRgba8UnormUintReinterpretation(VkFormat cached, - VkFormat requested) noexcept { +[[nodiscard]] inline bool IsRgba8UnormUintReinterpretation(vk::Format cached, + vk::Format requested) noexcept { switch (cached) { - case VK_FORMAT_R8G8B8A8_UNORM: return requested == VK_FORMAT_R8G8B8A8_UINT; - case VK_FORMAT_R8G8B8A8_UINT: return requested == VK_FORMAT_R8G8B8A8_UNORM; + case vk::Format::eR8G8B8A8Unorm: return requested == vk::Format::eR8G8B8A8Uint; + case vk::Format::eR8G8B8A8Uint: return requested == vk::Format::eR8G8B8A8Unorm; default: return false; } } @@ -658,7 +659,7 @@ SelectDepthTransitionSource(bool depth_load_clear, bool sampled_native_available sampled.size == target.size * sampled.depth && sampled.width == target.width && sampled.height == target.height && sampled.pitch == target.pitch; return sampled.address == target.address && sampled.size > target.size && - sampled.format == target.guest_format && target.format == VK_FORMAT_D32_SFLOAT && + sampled.format == target.guest_format && target.format == vk::Format::eD32Sfloat && target.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) && target.bytes_per_element == 4 && target.stencil_address == 0 && target.stencil_size == 0 && target.htile_address == 0 && target.htile_size == 0 && @@ -669,7 +670,7 @@ SelectDepthTransitionSource(bool depth_load_clear, bool sampled_native_available [[nodiscard]] inline StorageSampledOverlap ClassifyStorageSampledOverlap(const ImageInfo& requested, const ImageInfo& cached, - VkFormat requested_view_format, VkFormat cached_image_format, + vk::Format requested_view_format, vk::Format cached_image_format, bool cached_gpu_modified, bool cached_cpu_dirty, bool same_context) { if (!ImagePageRangesOverlap(requested.address, requested.size, cached.address, cached.size)) { return StorageSampledOverlap::None; @@ -854,7 +855,7 @@ ClassifyRenderTargetOverlap(const ImageInfo& sampled, bool sampled_gpu_modified, } [[nodiscard]] inline RenderTargetOverlap -ClassifyStorageRenderTargetOverlap(const ImageInfo& storage, VkFormat storage_format, +ClassifyStorageRenderTargetOverlap(const ImageInfo& storage, vk::Format storage_format, bool storage_gpu_modified, bool storage_buffer_modified, bool storage_cpu_dirty, bool same_context, const RenderTargetInfo& target) { @@ -875,18 +876,18 @@ ClassifyStorageRenderTargetOverlap(const ImageInfo& storage, VkFormat storage_fo : RenderTargetOverlap::Unsupported; } -[[nodiscard]] inline bool IsRgba8SrgbViewFormat(VkFormat format) noexcept { - return format == VK_FORMAT_R8G8B8A8_UNORM || format == VK_FORMAT_R8G8B8A8_SRGB || - format == VK_FORMAT_B8G8R8A8_UNORM || format == VK_FORMAT_B8G8R8A8_SRGB; +[[nodiscard]] inline bool IsRgba8SrgbViewFormat(vk::Format format) noexcept { + return format == vk::Format::eR8G8B8A8Unorm || format == vk::Format::eR8G8B8A8Srgb || + format == vk::Format::eB8G8R8A8Unorm || format == vk::Format::eB8G8R8A8Srgb; } -[[nodiscard]] inline bool IsRgba8SrgbReinterpretation(VkFormat cached, - VkFormat requested) noexcept { +[[nodiscard]] inline bool IsRgba8SrgbReinterpretation(vk::Format cached, + vk::Format requested) noexcept { switch (cached) { - case VK_FORMAT_R8G8B8A8_UNORM: return requested == VK_FORMAT_R8G8B8A8_SRGB; - case VK_FORMAT_R8G8B8A8_SRGB: return requested == VK_FORMAT_R8G8B8A8_UNORM; - case VK_FORMAT_B8G8R8A8_UNORM: return requested == VK_FORMAT_B8G8R8A8_SRGB; - case VK_FORMAT_B8G8R8A8_SRGB: return requested == VK_FORMAT_B8G8R8A8_UNORM; + case vk::Format::eR8G8B8A8Unorm: return requested == vk::Format::eR8G8B8A8Srgb; + case vk::Format::eR8G8B8A8Srgb: return requested == vk::Format::eR8G8B8A8Unorm; + case vk::Format::eB8G8R8A8Unorm: return requested == vk::Format::eB8G8R8A8Srgb; + case vk::Format::eB8G8R8A8Srgb: return requested == vk::Format::eB8G8R8A8Unorm; default: return false; } } diff --git a/src/graphics/host_gpu/renderer/imageView.cpp b/src/graphics/host_gpu/renderer/imageView.cpp index 9d84d2d59..02ccb6ef9 100644 --- a/src/graphics/host_gpu/renderer/imageView.cpp +++ b/src/graphics/host_gpu/renderer/imageView.cpp @@ -12,13 +12,13 @@ namespace Libs::Graphics { namespace { void CreateRenderTargetView(GraphicContext* ctx, VulkanImage* image, int index, - VkComponentSwizzle r, VkComponentSwizzle g, VkComponentSwizzle b, - VkComponentSwizzle a, VkImageViewType type = VK_IMAGE_VIEW_TYPE_2D, - VkFormat view_format = VK_FORMAT_UNDEFINED, - VkImageUsageFlags view_usage = 0, uint32_t level_count = 0) { - const auto layer_count = type == VK_IMAGE_VIEW_TYPE_2D_ARRAY ? image->layers : 1u; - UtilCreateImageView(ctx, image, index, type, VK_IMAGE_ASPECT_COLOR_BIT, {r, g, b, a}, 0, 0, - layer_count, level_count == 0 ? image->mip_levels : level_count, + vk::ComponentSwizzle r, vk::ComponentSwizzle g, vk::ComponentSwizzle b, + vk::ComponentSwizzle a, vk::ImageViewType type = vk::ImageViewType::e2D, + vk::Format view_format = vk::Format::eUndefined, + vk::ImageUsageFlags view_usage = {}, uint32_t level_count = 0) { + const auto layer_count = type == vk::ImageViewType::e2DArray ? image->layers : 1u; + UtilCreateImageView(ctx, image, index, type, vk::ImageAspectFlagBits::eColor, {r, g, b, a}, 0, + 0, layer_count, level_count == 0 ? image->mip_levels : level_count, view_format, view_usage); } @@ -26,61 +26,67 @@ void CreateRenderTargetView(GraphicContext* ctx, VulkanImage* image, int index, namespace ImageViewOps { -VkImageAspectFlags DepthAspectMask(VkFormat format) noexcept { - return VK_IMAGE_ASPECT_DEPTH_BIT | - (format == VK_FORMAT_D16_UNORM_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT || - format == VK_FORMAT_D32_SFLOAT_S8_UINT - ? VK_IMAGE_ASPECT_STENCIL_BIT - : 0u); +vk::ImageAspectFlags DepthAspectMask(vk::Format format) noexcept { + auto aspects = vk::ImageAspectFlags {vk::ImageAspectFlagBits::eDepth}; + if (format == vk::Format::eD16UnormS8Uint || format == vk::Format::eD24UnormS8Uint || + format == vk::Format::eD32SfloatS8Uint) { + aspects |= vk::ImageAspectFlagBits::eStencil; + } + return aspects; } -bool FormatSupportsStorage(GraphicContext* ctx, VkFormat format) { +bool FormatSupportsStorage(GraphicContext* ctx, vk::Format format) { const auto properties = ctx->GetFormatProperties(format); - return (properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0; + return static_cast(properties.optimalTilingFeatures & + vk::FormatFeatureFlagBits::eStorageImage); } void CreateRenderTargetViews(GraphicContext* ctx, RenderTextureVulkanImage* image) { - CreateRenderTargetView(ctx, image, VulkanImage::VIEW_DEFAULT, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY); + CreateRenderTargetView(ctx, image, VulkanImage::VIEW_DEFAULT, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity); if (image->layers > 1) { CreateRenderTargetView(ctx, image, VulkanImage::VIEW_DEFAULT_ARRAY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_IMAGE_VIEW_TYPE_2D_ARRAY); + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ImageViewType::e2DArray); } if (FormatSupportsStorage(ctx, image->format)) { - CreateRenderTargetView(ctx, image, VulkanImage::VIEW_STORAGE, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_IMAGE_VIEW_TYPE_2D, - VK_FORMAT_UNDEFINED, 0, 1); + CreateRenderTargetView(ctx, image, VulkanImage::VIEW_STORAGE, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ImageViewType::e2D, vk::Format::eUndefined, + vk::ImageUsageFlags {}, 1); if (image->layers > 1) { CreateRenderTargetView(ctx, image, VulkanImage::VIEW_STORAGE_ARRAY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_FORMAT_UNDEFINED, 0, 1); + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ImageViewType::e2DArray, vk::Format::eUndefined, + vk::ImageUsageFlags {}, 1); } } } void CreateDepthViews(GraphicContext* ctx, DepthStencilVulkanImage* image) { - UtilCreateImageView(ctx, image, VulkanImage::VIEW_DEFAULT, VK_IMAGE_VIEW_TYPE_2D, + UtilCreateImageView(ctx, image, VulkanImage::VIEW_DEFAULT, vk::ImageViewType::e2D, DepthAspectMask(image->format), - {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}, + {vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity}, 0, 0, 1, 1); } void CreateVideoOutViews(GraphicContext* ctx, VideoOutVulkanImage* image) { - CreateRenderTargetView(ctx, image, VulkanImage::VIEW_DEFAULT, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY); - if ((image->format == VK_FORMAT_R8G8B8A8_SRGB || image->format == VK_FORMAT_B8G8R8A8_SRGB) && - FormatSupportsStorage(ctx, VK_FORMAT_R8G8B8A8_UINT)) { - CreateRenderTargetView(ctx, image, VulkanImage::VIEW_STORAGE, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_IMAGE_VIEW_TYPE_2D, - VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_STORAGE_BIT, 1); + CreateRenderTargetView(ctx, image, VulkanImage::VIEW_DEFAULT, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity); + if ((image->format == vk::Format::eR8G8B8A8Srgb || + image->format == vk::Format::eB8G8R8A8Srgb) && + FormatSupportsStorage(ctx, vk::Format::eR8G8B8A8Uint)) { + CreateRenderTargetView(ctx, image, VulkanImage::VIEW_STORAGE, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ImageViewType::e2D, vk::Format::eR8G8B8A8Uint, + vk::ImageUsageFlagBits::eStorage, 1); } } @@ -90,14 +96,14 @@ void DestroyViews(GraphicContext* ctx, VulkanImage* image) { for (auto& cached: image->view_cache.views) { if (cached.view != nullptr) { - vkDestroyImageView(ctx->device, cached.view, nullptr); + ctx->device.destroyImageView(cached.view, nullptr); cached.view = nullptr; } } image->view_cache.views.clear(); for (auto& view: image->image_view) { if (view != nullptr) { - vkDestroyImageView(ctx->device, view, nullptr); + ctx->device.destroyImageView(view, nullptr); view = nullptr; } } @@ -105,12 +111,13 @@ void DestroyViews(GraphicContext* ctx, VulkanImage* image) { } // namespace ImageViewOps -VkImageView TextureCache::GetRenderTargetAttachmentView(GraphicContext* ctx, - RenderTextureVulkanImage* image, - VkFormat format, uint32_t level, - uint32_t base_layer, uint32_t layer_count) { +vk::ImageView TextureCache::GetRenderTargetAttachmentView(GraphicContext* ctx, + RenderTextureVulkanImage* image, + vk::Format format, uint32_t level, + uint32_t base_layer, + uint32_t layer_count) { if (ctx == nullptr || image == nullptr || image->image == nullptr || - format == VK_FORMAT_UNDEFINED || level >= image->mip_levels || level >= 16 || + format == vk::Format::eUndefined || level >= image->mip_levels || level >= 16 || layer_count == 0 || base_layer >= image->layers || layer_count > image->layers - base_layer) { EXIT("TextureCache: invalid render-target attachment view, image=%p format=%d" @@ -127,14 +134,15 @@ VkImageView TextureCache::GetRenderTargetAttachmentView(GraphicContext* return GetImageView(ctx, image, {format, - layer_count == 1 ? VK_IMAGE_VIEW_TYPE_2D : VK_IMAGE_VIEW_TYPE_2D_ARRAY, - VK_IMAGE_ASPECT_COLOR_BIT, level, 1, base_layer, layer_count, - DstSel(4, 5, 6, 7), VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT}); + layer_count == 1 ? vk::ImageViewType::e2D : vk::ImageViewType::e2DArray, + vk::ImageAspectFlagBits::eColor, level, 1, base_layer, layer_count, + DstSel(4, 5, 6, 7), vk::ImageUsageFlagBits::eColorAttachment}); } -VkImageView TextureCache::GetDepthTargetAttachmentView(GraphicContext* ctx, - DepthStencilVulkanImage* image, - uint32_t base_layer, uint32_t layer_count) { +vk::ImageView TextureCache::GetDepthTargetAttachmentView(GraphicContext* ctx, + DepthStencilVulkanImage* image, + uint32_t base_layer, + uint32_t layer_count) { if (ctx == nullptr || image == nullptr || image->image == nullptr || layer_count == 0 || base_layer >= image->layers || layer_count > image->layers - base_layer) { EXIT("TextureCache: invalid depth-target attachment view, image=%p base_layer=%u " @@ -144,26 +152,26 @@ VkImageView TextureCache::GetDepthTargetAttachmentView(GraphicContext* } return GetImageView( ctx, image, - {image->format, layer_count == 1 ? VK_IMAGE_VIEW_TYPE_2D : VK_IMAGE_VIEW_TYPE_2D_ARRAY, + {image->format, layer_count == 1 ? vk::ImageViewType::e2D : vk::ImageViewType::e2DArray, ImageViewOps::DepthAspectMask(image->format), 0, 1, base_layer, layer_count, - DstSel(4, 5, 6, 7), VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT}); + DstSel(4, 5, 6, 7), vk::ImageUsageFlagBits::eDepthStencilAttachment}); } -VkImageView TextureCache::GetImageView(GraphicContext* ctx, VulkanImage* image, - const ImageViewInfo& info) { - const bool supported_type = info.type == VK_IMAGE_VIEW_TYPE_2D || - info.type == VK_IMAGE_VIEW_TYPE_2D_ARRAY || - info.type == VK_IMAGE_VIEW_TYPE_3D; - const bool supported_usage = info.usage == VK_IMAGE_USAGE_SAMPLED_BIT || - info.usage == VK_IMAGE_USAGE_STORAGE_BIT || - info.usage == VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT || - info.usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; +vk::ImageView TextureCache::GetImageView(GraphicContext* ctx, VulkanImage* image, + const ImageViewInfo& info) { + const bool supported_type = info.type == vk::ImageViewType::e2D || + info.type == vk::ImageViewType::e2DArray || + info.type == vk::ImageViewType::e3D; + const bool supported_usage = info.usage == vk::ImageUsageFlagBits::eSampled || + info.usage == vk::ImageUsageFlagBits::eStorage || + info.usage == vk::ImageUsageFlagBits::eColorAttachment || + info.usage == vk::ImageUsageFlagBits::eDepthStencilAttachment; const bool valid_shape = - (info.type == VK_IMAGE_VIEW_TYPE_2D && info.layer_count == 1) || - info.type == VK_IMAGE_VIEW_TYPE_2D_ARRAY || - (info.type == VK_IMAGE_VIEW_TYPE_3D && info.base_layer == 0 && info.layer_count == 1); + (info.type == vk::ImageViewType::e2D && info.layer_count == 1) || + info.type == vk::ImageViewType::e2DArray || + (info.type == vk::ImageViewType::e3D && info.base_layer == 0 && info.layer_count == 1); if (ctx == nullptr || image == nullptr || image->image == nullptr || - info.format == VK_FORMAT_UNDEFINED || info.aspect == 0 || info.level_count == 0 || + info.format == vk::Format::eUndefined || !info.aspect || info.level_count == 0 || info.base_level >= (image != nullptr ? image->mip_levels : 0) || info.level_count > image->mip_levels - info.base_level || info.layer_count == 0 || info.base_layer >= image->layers || info.layer_count > image->layers - info.base_layer || @@ -171,10 +179,11 @@ VkImageView TextureCache::GetImageView(GraphicContext* ctx, VulkanImage* image, EXIT("TextureCache: invalid dynamic image view, image=%p format=%d aspect=0x%x" " swizzle=0x%03x mip=%u+%u layer=%u+%u type=%d usage=0x%x" " image_levels=%u image_layers=%u\n", - static_cast(image), static_cast(info.format), info.aspect, - info.swizzle, info.base_level, info.level_count, info.base_layer, info.layer_count, - static_cast(info.type), info.usage, image != nullptr ? image->mip_levels : 0, - image != nullptr ? image->layers : 0); + static_cast(image), static_cast(info.format), + static_cast(info.aspect), info.swizzle, + info.base_level, info.level_count, info.base_layer, info.layer_count, + static_cast(info.type), static_cast(info.usage), + image != nullptr ? image->mip_levels : 0, image != nullptr ? image->layers : 0); } auto& cache = image->view_cache; @@ -185,67 +194,69 @@ VkImageView TextureCache::GetImageView(GraphicContext* ctx, VulkanImage* image, } } - VkImageViewUsageCreateInfo usage {}; - usage.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO; + vk::ImageViewUsageCreateInfo usage {}; + usage.sType = vk::StructureType::eImageViewUsageCreateInfo; usage.usage = info.usage; - VkImageViewCreateInfo create {}; - create.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + vk::ImageViewCreateInfo create {}; + create.sType = vk::StructureType::eImageViewCreateInfo; create.pNext = &usage; create.image = image->image; create.viewType = info.type; create.format = info.format; - create.components = info.usage == VK_IMAGE_USAGE_SAMPLED_BIT + create.components = info.usage == vk::ImageUsageFlagBits::eSampled ? TextureGetComponentMapping(info.swizzle) - : VkComponentMapping {}; + : vk::ComponentMapping {}; create.subresourceRange.aspectMask = info.aspect; create.subresourceRange.baseMipLevel = info.base_level; create.subresourceRange.levelCount = info.level_count; create.subresourceRange.baseArrayLayer = info.base_layer; create.subresourceRange.layerCount = info.layer_count; - VkImageView view = nullptr; - const auto result = vkCreateImageView(ctx->device, &create, nullptr, &view); - if (result != VK_SUCCESS || view == nullptr) { + vk::ImageView view = nullptr; + const auto result = ctx->device.createImageView(&create, nullptr, &view); + if (result != vk::Result::eSuccess || view == nullptr) { EXIT("TextureCache: failed to create dynamic image view, result=%d format=%d" " aspect=0x%x swizzle=0x%03x mip=%u+%u layer=%u+%u type=%d usage=0x%x\n", - static_cast(result), static_cast(info.format), info.aspect, info.swizzle, + static_cast(result), static_cast(info.format), + static_cast(info.aspect), info.swizzle, info.base_level, info.level_count, info.base_layer, info.layer_count, - static_cast(info.type), info.usage); + static_cast(info.type), static_cast(info.usage)); } cache.views.push_back({info, view}); return view; } -VkImageView TextureCache::GetDepthTargetSampledView(GraphicContext* ctx, - DepthStencilVulkanImage* image, - VkFormat view_format, uint32_t swizzle, - uint32_t base_level, uint32_t level_count, - VkImageViewType type, uint32_t base_layer, - uint32_t layer_count) { +vk::ImageView TextureCache::GetDepthTargetSampledView(GraphicContext* ctx, + DepthStencilVulkanImage* image, + vk::Format view_format, uint32_t swizzle, + uint32_t base_level, uint32_t level_count, + vk::ImageViewType type, uint32_t base_layer, + uint32_t layer_count) { if (ctx == nullptr || image == nullptr || image->image == nullptr || - view_format == VK_FORMAT_UNDEFINED || + view_format == vk::Format::eUndefined || !IsSupportedSampledDepthView(image->format, view_format, swizzle)) { EXIT("TextureCache: invalid sampled depth-target view, image=%p image_format=%d" " view_format=%d swizzle=0x%03x mip=%u+%u layer=%u+%u type=%d" " image_levels=%u image_layers=%u\n", static_cast(image), - image != nullptr ? static_cast(image->format) : VK_FORMAT_UNDEFINED, + image != nullptr ? static_cast(image->format) + : static_cast(vk::Format::eUndefined), static_cast(view_format), swizzle, base_level, level_count, base_layer, layer_count, static_cast(type), image != nullptr ? image->mip_levels : 0, image != nullptr ? image->layers : 0); } return GetImageView(ctx, image, - {image->format, type, VK_IMAGE_ASPECT_DEPTH_BIT, base_level, level_count, - base_layer, layer_count, swizzle}); + {image->format, type, vk::ImageAspectFlagBits::eDepth, base_level, + level_count, base_layer, layer_count, swizzle}); } -VkImageView TextureCache::GetSampledColorView(GraphicContext* ctx, VulkanImage* image, - VkFormat view_format, uint32_t swizzle, - uint32_t base_level, uint32_t level_count, - VkImageViewType type, uint32_t base_layer, - uint32_t layer_count) { +vk::ImageView TextureCache::GetSampledColorView(GraphicContext* ctx, VulkanImage* image, + vk::Format view_format, uint32_t swizzle, + uint32_t base_level, uint32_t level_count, + vk::ImageViewType type, uint32_t base_layer, + uint32_t layer_count) { if (ctx == nullptr || image == nullptr || image->image == nullptr || - view_format == VK_FORMAT_UNDEFINED || base_level >= 16 || - (type != VK_IMAGE_VIEW_TYPE_2D && type != VK_IMAGE_VIEW_TYPE_2D_ARRAY) || + view_format == vk::Format::eUndefined || base_level >= 16 || + (type != vk::ImageViewType::e2D && type != vk::ImageViewType::e2DArray) || !IsSupportedSampledColorView(image->format, view_format, swizzle)) { EXIT("TextureCache: invalid sampled color view, image=%p swizzle=0x%03x" " view_format=%d mip=%u+%u layer=%u+%u type=%d image_levels=%u image_layers=%u\n", @@ -253,29 +264,29 @@ VkImageView TextureCache::GetSampledColorView(GraphicContext* ctx, VulkanImage* level_count, base_layer, layer_count, static_cast(type), image != nullptr ? image->mip_levels : 0, image != nullptr ? image->layers : 0); } - const auto precreated_view = type == VK_IMAGE_VIEW_TYPE_2D_ARRAY + const auto precreated_view = type == vk::ImageViewType::e2DArray ? VulkanImage::VIEW_DEFAULT_ARRAY : VulkanImage::VIEW_DEFAULT; const bool full_view = base_level == 0 && level_count == image->mip_levels && base_layer == 0 && - layer_count == (type == VK_IMAGE_VIEW_TYPE_2D_ARRAY ? image->layers : 1u); + layer_count == (type == vk::ImageViewType::e2DArray ? image->layers : 1u); if (view_format == image->format && swizzle == DstSel(4, 5, 6, 7) && full_view && image->image_view[precreated_view] != nullptr) { return image->image_view[precreated_view]; } return GetImageView(ctx, image, - {view_format, type, VK_IMAGE_ASPECT_COLOR_BIT, base_level, level_count, - base_layer, layer_count, swizzle}); + {view_format, type, vk::ImageAspectFlagBits::eColor, base_level, + level_count, base_layer, layer_count, swizzle}); } -VkImageView TextureCache::GetRenderTargetStorageView(GraphicContext* ctx, - RenderTextureVulkanImage* image, - VkFormat view_format, uint32_t base_level, - uint32_t level_count, VkImageViewType type, - uint32_t base_layer, uint32_t layer_count) { +vk::ImageView TextureCache::GetRenderTargetStorageView(GraphicContext* ctx, + RenderTextureVulkanImage* image, + vk::Format view_format, uint32_t base_level, + uint32_t level_count, vk::ImageViewType type, + uint32_t base_layer, uint32_t layer_count) { if (ctx == nullptr || image == nullptr || image->image == nullptr || - view_format == VK_FORMAT_UNDEFINED || - (type != VK_IMAGE_VIEW_TYPE_2D && type != VK_IMAGE_VIEW_TYPE_2D_ARRAY)) { + view_format == vk::Format::eUndefined || + (type != vk::ImageViewType::e2D && type != vk::ImageViewType::e2DArray)) { EXIT("TextureCache: invalid render-target storage view, image=%p view_format=%d" " mip=%u+%u layer=%u+%u type=%d image_levels=%u image_layers=%u\n", static_cast(image), static_cast(view_format), base_level, @@ -291,11 +302,11 @@ VkImageView TextureCache::GetRenderTargetStorageView(GraphicContext* c level_count); } if (exact) { - const auto index = type == VK_IMAGE_VIEW_TYPE_2D_ARRAY ? VulkanImage::VIEW_STORAGE_ARRAY + const auto index = type == vk::ImageViewType::e2DArray ? VulkanImage::VIEW_STORAGE_ARRAY : VulkanImage::VIEW_STORAGE; const bool full_view = base_level == 0 && level_count == 1 && base_layer == 0 && - layer_count == (type == VK_IMAGE_VIEW_TYPE_2D_ARRAY ? image->layers : 1u); + layer_count == (type == vk::ImageViewType::e2DArray ? image->layers : 1u); if (full_view && image->image_view[index] != nullptr) { return image->image_view[index]; } @@ -308,13 +319,14 @@ VkImageView TextureCache::GetRenderTargetStorageView(GraphicContext* c level_count); } return GetImageView(ctx, image, - {view_format, type, VK_IMAGE_ASPECT_COLOR_BIT, base_level, level_count, - base_layer, layer_count, DstSel(4, 5, 6, 7), VK_IMAGE_USAGE_STORAGE_BIT}); + {view_format, type, vk::ImageAspectFlagBits::eColor, base_level, + level_count, base_layer, layer_count, DstSel(4, 5, 6, 7), + vk::ImageUsageFlagBits::eStorage}); } -VkImageView TextureCache::GetStorageTextureSampledView(GraphicContext* ctx, - StorageTextureVulkanImage* image, - const ImageInfo& info) { +vk::ImageView TextureCache::GetStorageTextureSampledView(GraphicContext* ctx, + StorageTextureVulkanImage* image, + const ImageInfo& info) { const auto shape = SelectStorageSampledViewShape(info.type, info.depth, image != nullptr ? image->layers : 0); if (ctx == nullptr || image == nullptr || image->image == nullptr || @@ -334,23 +346,23 @@ VkImageView TextureCache::GetStorageTextureSampledView(GraphicContext* static_cast(image->format), static_cast(view_format), info.swizzle); } - VkImageViewType type = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + vk::ImageViewType type = static_cast(VK_IMAGE_VIEW_TYPE_MAX_ENUM); switch (shape) { - case StorageSampledViewShape::Image2D: type = VK_IMAGE_VIEW_TYPE_2D; break; - case StorageSampledViewShape::Image2DArray: type = VK_IMAGE_VIEW_TYPE_2D_ARRAY; break; - case StorageSampledViewShape::Image3D: type = VK_IMAGE_VIEW_TYPE_3D; break; + case StorageSampledViewShape::Image2D: type = vk::ImageViewType::e2D; break; + case StorageSampledViewShape::Image2DArray: type = vk::ImageViewType::e2DArray; break; + case StorageSampledViewShape::Image3D: type = vk::ImageViewType::e3D; break; case StorageSampledViewShape::Unsupported: EXIT("TextureCache: unsupported sampled storage-image view shape\n"); } const auto layer_count = shape == StorageSampledViewShape::Image2DArray ? info.depth : 1u; return GetImageView(ctx, image, - {view_format, type, VK_IMAGE_ASPECT_COLOR_BIT, info.base_level, + {view_format, type, vk::ImageAspectFlagBits::eColor, info.base_level, info.view_levels, 0, layer_count, info.swizzle}); } -VkImageView TextureCache::GetStorageTextureStorageView(GraphicContext* ctx, - StorageTextureVulkanImage* image, - uint32_t base_level) { +vk::ImageView TextureCache::GetStorageTextureStorageView(GraphicContext* ctx, + StorageTextureVulkanImage* image, + uint32_t base_level) { if (ctx == nullptr || image == nullptr || image->image == nullptr || base_level >= (image != nullptr ? image->mip_levels : 0)) { EXIT("TextureCache: invalid storage-texture mip view, image=%p level=%u levels=%u\n", @@ -360,8 +372,9 @@ VkImageView TextureCache::GetStorageTextureStorageView(GraphicContext* return image->image_view[VulkanImage::VIEW_DEFAULT]; } return GetImageView(ctx, image, - {image->format, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, - base_level, 1, 0, 1, DstSel(4, 5, 6, 7), VK_IMAGE_USAGE_STORAGE_BIT}); + {image->format, vk::ImageViewType::e2D, vk::ImageAspectFlagBits::eColor, + base_level, 1, 0, 1, DstSel(4, 5, 6, 7), + vk::ImageUsageFlagBits::eStorage}); } } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/imageView.h b/src/graphics/host_gpu/renderer/imageView.h index 3afd539ad..99a74a920 100644 --- a/src/graphics/host_gpu/renderer/imageView.h +++ b/src/graphics/host_gpu/renderer/imageView.h @@ -40,47 +40,48 @@ namespace Libs::Graphics { height != 0 && depth == 1); } -[[noreturn]] inline void UnsupportedColorView(const char* usage, VkFormat image_format, - VkFormat view_format, uint32_t swizzle) noexcept { +[[noreturn]] inline void UnsupportedColorView(const char* usage, vk::Format image_format, + vk::Format view_format, uint32_t swizzle) noexcept { EXIT("unsupported %s color image view: image_format=%d view_format=%d swizzle=0x%03x\n", usage, static_cast(image_format), static_cast(view_format), swizzle); } -[[nodiscard]] inline VkFormat BgraToRgbaSampledViewFormat(VkFormat image_format) noexcept { +[[nodiscard]] inline vk::Format BgraToRgbaSampledViewFormat(vk::Format image_format) noexcept { switch (image_format) { - case VK_FORMAT_B8G8R8A8_UNORM: return VK_FORMAT_R8G8B8A8_UNORM; - case VK_FORMAT_B8G8R8A8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB; - case VK_FORMAT_A2R10G10B10_UNORM_PACK32: return VK_FORMAT_A2B10G10R10_UNORM_PACK32; - default: return VK_FORMAT_UNDEFINED; + case vk::Format::eB8G8R8A8Unorm: return vk::Format::eR8G8B8A8Unorm; + case vk::Format::eB8G8R8A8Srgb: return vk::Format::eR8G8B8A8Srgb; + case vk::Format::eA2R10G10B10UnormPack32: return vk::Format::eA2B10G10R10UnormPack32; + default: return vk::Format::eUndefined; } } -[[nodiscard]] inline bool IsBgraToRgbaSampledView(VkFormat image_format, - VkFormat view_format) noexcept { +[[nodiscard]] inline bool IsBgraToRgbaSampledView(vk::Format image_format, + vk::Format view_format) noexcept { switch (image_format) { - case VK_FORMAT_B8G8R8A8_UNORM: - case VK_FORMAT_B8G8R8A8_SRGB: + case vk::Format::eB8G8R8A8Unorm: + case vk::Format::eB8G8R8A8Srgb: switch (view_format) { - case VK_FORMAT_R8G8B8A8_UNORM: - case VK_FORMAT_R8G8B8A8_SRGB: return true; + case vk::Format::eR8G8B8A8Unorm: + case vk::Format::eR8G8B8A8Srgb: return true; default: return false; } - case VK_FORMAT_A2R10G10B10_UNORM_PACK32: - return view_format == VK_FORMAT_A2B10G10R10_UNORM_PACK32; + case vk::Format::eA2R10G10B10UnormPack32: + return view_format == vk::Format::eA2B10G10R10UnormPack32; default: return false; } } -[[nodiscard]] inline VkFormat BgraSrgbStorageViewFormat(VkFormat image_format) noexcept { - return image_format == VK_FORMAT_B8G8R8A8_SRGB ? VK_FORMAT_R8G8B8A8_UNORM : VK_FORMAT_UNDEFINED; +[[nodiscard]] inline vk::Format BgraSrgbStorageViewFormat(vk::Format image_format) noexcept { + return image_format == vk::Format::eB8G8R8A8Srgb ? vk::Format::eR8G8B8A8Unorm + : vk::Format::eUndefined; } -[[nodiscard]] inline VkFormat SrgbStorageViewFormat(VkFormat image_format) noexcept { - return image_format == VK_FORMAT_R8G8B8A8_SRGB ? VK_FORMAT_R8G8B8A8_UNORM - : BgraSrgbStorageViewFormat(image_format); +[[nodiscard]] inline vk::Format SrgbStorageViewFormat(vk::Format image_format) noexcept { + return image_format == vk::Format::eR8G8B8A8Srgb ? vk::Format::eR8G8B8A8Unorm + : BgraSrgbStorageViewFormat(image_format); } -[[nodiscard]] inline bool IsBgraSrgbStorageView(VkFormat image_format, VkFormat view_format, +[[nodiscard]] inline bool IsBgraSrgbStorageView(vk::Format image_format, vk::Format view_format, uint32_t swizzle) noexcept { return view_format == BgraSrgbStorageViewFormat(image_format) && swizzle == DstSel(6, 5, 4, 7); } @@ -103,8 +104,9 @@ namespace Libs::Graphics { return true; } -[[nodiscard]] inline bool IsSupportedSampledColorView(VkFormat image_format, VkFormat view_format, - uint32_t swizzle) noexcept { +[[nodiscard]] inline bool IsSupportedSampledColorView(vk::Format image_format, + vk::Format view_format, + uint32_t swizzle) noexcept { if (!IsValidSampledColorSwizzle(swizzle)) { return false; } @@ -119,16 +121,17 @@ namespace Libs::Graphics { return IsBgraToRgbaSampledView(image_format, view_format) && swizzle == DstSel(6, 5, 4, 7); } -[[nodiscard]] inline uint32_t SelectSampledColorView(VkFormat image_format, VkFormat view_format, - uint32_t swizzle) noexcept { +[[nodiscard]] inline uint32_t +SelectSampledColorView(vk::Format image_format, vk::Format view_format, uint32_t swizzle) noexcept { if (IsSupportedSampledColorView(image_format, view_format, swizzle)) { return swizzle; } UnsupportedColorView("sampled", image_format, view_format, swizzle); } -[[nodiscard]] inline bool IsSupportedSampledDepthView(VkFormat image_format, VkFormat view_format, - uint32_t swizzle) noexcept { +[[nodiscard]] inline bool IsSupportedSampledDepthView(vk::Format image_format, + vk::Format view_format, + uint32_t swizzle) noexcept { if (!IsSupportedSampledDepthFormat(image_format, view_format)) { return false; } @@ -140,8 +143,8 @@ namespace Libs::Graphics { } } -[[nodiscard]] inline uint32_t SelectSampledDepthView(VkFormat image_format, VkFormat view_format, - uint32_t swizzle) noexcept { +[[nodiscard]] inline uint32_t +SelectSampledDepthView(vk::Format image_format, vk::Format view_format, uint32_t swizzle) noexcept { if (IsSupportedSampledDepthView(image_format, view_format, swizzle)) { return swizzle; } @@ -166,20 +169,20 @@ IsSupportedSampledDepthUintResource(const ShaderRecompiler::IR::ImageResource& r !resource.written && !resource.atomic && !resource.depth_compare; } -[[nodiscard]] inline int SelectStorageColorView(VkFormat image_format, VkFormat view_format, +[[nodiscard]] inline int SelectStorageColorView(vk::Format image_format, vk::Format view_format, uint32_t swizzle) noexcept { const bool single_channel = - view_format == VK_FORMAT_R8_UNORM || view_format == VK_FORMAT_R8_UINT || - view_format == VK_FORMAT_R16_UINT || view_format == VK_FORMAT_R32_UINT || - view_format == VK_FORMAT_R16_SFLOAT || view_format == VK_FORMAT_R32_SFLOAT; + view_format == vk::Format::eR8Unorm || view_format == vk::Format::eR8Uint || + view_format == vk::Format::eR16Uint || view_format == vk::Format::eR32Uint || + view_format == vk::Format::eR16Sfloat || view_format == vk::Format::eR32Sfloat; const bool swizzle_ok = swizzle == DstSel(4, 5, 6, 7) || (single_channel && (swizzle == DstSel(4, 0, 0, 0) || swizzle == DstSel(4, 0, 0, 1) || swizzle == DstSel(4, 4, 4, 4))) || - (view_format == VK_FORMAT_R32G32_UINT && swizzle == DstSel(4, 5, 0, 1)) || - ((view_format == VK_FORMAT_R8G8B8A8_UNORM || view_format == VK_FORMAT_R8G8B8A8_UINT) && + (view_format == vk::Format::eR32G32Uint && swizzle == DstSel(4, 5, 0, 1)) || + ((view_format == vk::Format::eR8G8B8A8Unorm || view_format == vk::Format::eR8G8B8A8Uint) && (swizzle == DstSel(4, 5, 6, 1) || swizzle == DstSel(6, 5, 4, 7))) || - (view_format == VK_FORMAT_R32G32B32A32_SFLOAT && swizzle == DstSel(5, 6, 7, 4)); + (view_format == vk::Format::eR32G32B32A32Sfloat && swizzle == DstSel(5, 6, 7, 4)); if ((image_format != view_format && !IsBgraSrgbStorageView(image_format, view_format, swizzle)) || !swizzle_ok) { @@ -212,8 +215,8 @@ ValidateStorageImageResource(const ShaderRecompiler::IR::ImageResource& resource namespace ImageViewOps { -[[nodiscard]] VkImageAspectFlags DepthAspectMask(VkFormat format) noexcept; -[[nodiscard]] bool FormatSupportsStorage(GraphicContext* ctx, VkFormat format); +[[nodiscard]] vk::ImageAspectFlags DepthAspectMask(vk::Format format) noexcept; +[[nodiscard]] bool FormatSupportsStorage(GraphicContext* ctx, vk::Format format); void CreateRenderTargetViews(GraphicContext* ctx, RenderTextureVulkanImage* image); void CreateDepthViews(GraphicContext* ctx, DepthStencilVulkanImage* image); diff --git a/src/graphics/host_gpu/renderer/pipelineCache.cpp b/src/graphics/host_gpu/renderer/pipelineCache.cpp index d19e73db3..a23df54e6 100644 --- a/src/graphics/host_gpu/renderer/pipelineCache.cpp +++ b/src/graphics/host_gpu/renderer/pipelineCache.cpp @@ -57,8 +57,8 @@ void PipelineCache::DeletePipelineInternal(Pipeline* p) { EXIT_IF(gctx == nullptr); VulkanDeviceWaitIdle(gctx); - vkDestroyPipeline(gctx->device, p->pipeline, nullptr); - vkDestroyPipelineLayout(gctx->device, p->pipeline_layout, nullptr); + gctx->device.destroyPipeline(p->pipeline, nullptr); + gctx->device.destroyPipelineLayout(p->pipeline_layout, nullptr); p->pipeline = nullptr; p->pipeline_layout = nullptr; @@ -67,7 +67,7 @@ void PipelineCache::DeletePipelineInternal(Pipeline* p) { PipelineCache::GraphicsPipeline* PipelineCache::CreateGraphicsPipeline( VulkanFramebuffer* framebuffer, RenderColorInfo* colors, uint32_t color_count, RenderDepthInfo* depth, ShaderVertexInputInfo* vs_input_info, HW::Context* ctx, - HW::Shader* sh_ctx, ShaderPixelInputInfo* ps_input_info, VkPrimitiveTopology topology, + HW::Shader* sh_ctx, ShaderPixelInputInfo* ps_input_info, vk::PrimitiveTopology topology, bool ps_active, std::span vs_spirv, std::span ps_spirv) { KYTY_PROFILER_BLOCK("PipelineCache::CreatePipeline(Gfx)", profiler::colors::DeepOrangeA200); @@ -116,7 +116,7 @@ PipelineCache::GraphicsPipeline* PipelineCache::CreateGraphicsPipeline( static_params.negative_one_to_one = !ctx->GetClipControl().dx_clip_space; static_params.topology = topology; static_params.with_depth = - (depth->format != VK_FORMAT_UNDEFINED && depth->vulkan_buffer != nullptr); + (depth->format != vk::Format::eUndefined && depth->vulkan_buffer != nullptr); static_params.depth_test_enable = depth->depth_test_enable; static_params.depth_write_enable = (depth->depth_write_enable && !depth->depth_clear_enable); static_params.depth_compare_op = depth->depth_compare_op; diff --git a/src/graphics/host_gpu/renderer/pipelineCache.h b/src/graphics/host_gpu/renderer/pipelineCache.h index caef2cedc..3b0dd26dc 100644 --- a/src/graphics/host_gpu/renderer/pipelineCache.h +++ b/src/graphics/host_gpu/renderer/pipelineCache.h @@ -7,6 +7,7 @@ #include "common/file.h" #include "common/threads.h" #include "graphics/host_gpu/renderer/renderTarget.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/shader.h" #include @@ -15,7 +16,6 @@ #include #include #include -#include namespace Libs::Graphics { @@ -36,11 +36,11 @@ struct PipelineStaticParameters { float viewport_offset[3] = {}; bool negative_one_to_one = false; int scissor_ltrb[4] = {0}; - VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + vk::PrimitiveTopology topology = vk::PrimitiveTopology::ePointList; bool with_depth = false; bool depth_test_enable = false; bool depth_write_enable = false; - VkCompareOp depth_compare_op = VK_COMPARE_OP_NEVER; + vk::CompareOp depth_compare_op = vk::CompareOp::eNever; bool depth_bounds_test_enable = false; float depth_min_bounds = 0.0f; float depth_max_bounds = 0.0f; @@ -76,7 +76,7 @@ static_assert(std::is_standard_layout_v); static_assert(alignof(PipelineStaticParameters) == 1); static_assert(sizeof(PipelineStaticParameters) == sizeof(float[3]) + sizeof(float[3]) + sizeof(bool) + sizeof(int[4]) + - sizeof(VkPrimitiveTopology) + sizeof(bool) * 3 + sizeof(VkCompareOp) + + sizeof(vk::PrimitiveTopology) + sizeof(bool) * 3 + sizeof(vk::CompareOp) + sizeof(bool) + sizeof(float) * 2 + sizeof(bool) + sizeof(PipelineStencilStaticState) * 2 + sizeof(uint32_t) + sizeof(uint32_t[RENDER_COLOR_ATTACHMENTS_MAX]) + sizeof(bool) * 3 + @@ -90,8 +90,8 @@ public: KYTY_CLASS_NO_COPY(PipelineCache); struct Pipeline { - VkPipelineLayout pipeline_layout = nullptr; - VkPipeline pipeline = nullptr; + vk::PipelineLayout pipeline_layout = nullptr; + vk::Pipeline pipeline = nullptr; }; struct GraphicsPipeline: Pipeline { @@ -107,7 +107,7 @@ public: GraphicsPipeline* CreateGraphicsPipeline( VulkanFramebuffer* framebuffer, RenderColorInfo* colors, uint32_t color_count, RenderDepthInfo* depth, ShaderVertexInputInfo* vs_input_info, HW::Context* ctx, - HW::Shader* sh_ctx, ShaderPixelInputInfo* ps_input_info, VkPrimitiveTopology topology, + HW::Shader* sh_ctx, ShaderPixelInputInfo* ps_input_info, vk::PrimitiveTopology topology, bool ps_active, std::span vs_spirv, std::span ps_spirv); ComputePipeline* CreateComputePipeline(ShaderComputeInputInfo* input_info, const HW::ComputeShaderInfo* cs_regs, @@ -192,7 +192,7 @@ private: void LogPipelineTrace(const char* phase, uint32_t vs_hash0, uint32_t vs_crc32, uint32_t ps_hash0, uint32_t ps_crc32); -void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderPass render_pass, +void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, vk::RenderPass render_pass, const ShaderVertexInputInfo* vs_input_info, std::span vs_shader, const ShaderPixelInputInfo* ps_input_info, diff --git a/src/graphics/host_gpu/renderer/render.h b/src/graphics/host_gpu/renderer/render.h index fa889bdef..f40a2dedb 100644 --- a/src/graphics/host_gpu/renderer/render.h +++ b/src/graphics/host_gpu/renderer/render.h @@ -4,10 +4,10 @@ #include "common/abi.h" #include "common/common.h" #include "graphics/host_gpu/renderer/streamBuffer.h" +#include "graphics/host_gpu/vulkanCommon.h" #include #include -#include namespace Libs::Graphics { @@ -80,9 +80,9 @@ public: void Begin() const; void End() const; void Execute(); - void ExecuteWithSemaphore(VkSemaphore signal_semaphore = nullptr); - void ExecuteWithSemaphore(VkSemaphore wait_semaphore, VkPipelineStageFlags wait_stage, - VkSemaphore signal_semaphore); + void ExecuteWithSemaphore(vk::Semaphore signal_semaphore = nullptr); + void ExecuteWithSemaphore(vk::Semaphore wait_semaphore, vk::PipelineStageFlags wait_stage, + vk::Semaphore signal_semaphore); void SetDebugInfo(uint32_t op, uint64_t submit_id, uint32_t arg0 = 0, uint32_t arg1 = 0, uint32_t arg2 = 0, uint32_t arg3 = 0, uint64_t arg4 = 0); void BeginRenderPass(VulkanFramebuffer* framebuffer, RenderColorInfo* colors, diff --git a/src/graphics/host_gpu/renderer/renderCompute.cpp b/src/graphics/host_gpu/renderer/renderCompute.cpp index 2370454ad..7c02ecf56 100644 --- a/src/graphics/host_gpu/renderer/renderCompute.cpp +++ b/src/graphics/host_gpu/renderer/renderCompute.cpp @@ -23,6 +23,7 @@ #include "graphics/host_gpu/renderer/shaderResourceBarrier.h" #include "graphics/host_gpu/renderer/shaderSubgroup.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/recompiler/ResourceMaterialization.h" #include "graphics/shader/recompiler/ShaderIR.h" #include "graphics/shader/shader.h" @@ -38,9 +39,6 @@ #include #include #include -#include - -// IWYU pragma: no_forward_declare VkImageView_T namespace Libs::Graphics { static uint64_t BufferDescriptorSize(const ShaderBufferResource& descriptor) { @@ -530,20 +528,20 @@ void RenderDispatchDirect(uint64_t submit_id, CommandBuffer* buffer, HW::Context for (;;) { const auto recording_generation = buffer->GetRecordingGeneration(); - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; auto* pipeline = g_render_ctx->GetPipelineCache()->CreateComputePipeline( &input_info, &sh_ctx->GetCs(), cs_shader); - vkCmdBindPipeline(vk_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->pipeline); + vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline->pipeline); const auto address_writes = BindDescriptors( - submit_id, buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->pipeline_layout, - input_info.stage, VK_SHADER_STAGE_COMPUTE_BIT, DescriptorCache::Stage::Compute); + submit_id, buffer, vk::PipelineBindPoint::eCompute, pipeline->pipeline_layout, + input_info.stage, vk::ShaderStageFlagBits::eCompute, DescriptorCache::Stage::Compute); if (buffer->GetRecordingGeneration() != recording_generation) { continue; } - vkCmdDispatch(vk_buffer, thread_group_x, thread_group_y, thread_group_z); + vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z); bool has_storage_writes = HasShaderBufferWrites(input_info.stage); has_storage_writes = MarkShaderAddressWrites(address_writes) || has_storage_writes; @@ -557,7 +555,7 @@ void RenderDispatchDirect(uint64_t submit_id, CommandBuffer* buffer, HW::Context }) || has_storage_writes; if (has_storage_writes) { - ShaderWriteBarrier(vk_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + ShaderWriteBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader); } break; } diff --git a/src/graphics/host_gpu/renderer/renderDraw.cpp b/src/graphics/host_gpu/renderer/renderDraw.cpp index d23ce60f0..bf80c5ac0 100644 --- a/src/graphics/host_gpu/renderer/renderDraw.cpp +++ b/src/graphics/host_gpu/renderer/renderDraw.cpp @@ -27,6 +27,7 @@ #include "graphics/host_gpu/renderer/shaderResourceBarrier.h" #include "graphics/host_gpu/renderer/shaderSubgroup.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/recompiler/ResourceMaterialization.h" #include "graphics/shader/recompiler/ShaderIR.h" #include "graphics/shader/shader.h" @@ -43,9 +44,6 @@ #include #include #include -#include - -// IWYU pragma: no_forward_declare VkImageView_T namespace Libs::Graphics { @@ -88,7 +86,7 @@ static void LogFramebufferSkip(const char* draw_name, const RenderColorInfo& col " color_image=%s depth_format=%s depth_image=%s depth_vaddr_num=%d target_mask=0x%08" PRIx32 " prim=%u index_count=%u flags=0x%08" PRIx32 "\n", log_id, draw_name, RenderColorTypeName(color.type), color.base_addr, color.buffer_size, - color.vulkan_buffer != nullptr ? "yes" : "no", string_VkFormat(depth.format), + color.vulkan_buffer != nullptr ? "yes" : "no", VulkanToString(depth.format).c_str(), depth.vulkan_buffer != nullptr ? "yes" : "no", depth.vaddr_num, ctx != nullptr ? ctx->GetRenderTargetMask() : 0, ucfg != nullptr ? ucfg->GetPrimType() : 0, index_count, flags); @@ -184,8 +182,8 @@ static void LogDrawTargetState(const char* draw_name, const RenderColorInfo& col image.kind == ShaderRecompiler::IR::ResourceKind::ImageUint; }); - VkExtent2D extent = color.vulkan_buffer != nullptr ? color.extent : VkExtent2D {}; - auto sc = calc_final_scissor(vp, ctx->GetScanModeControl(), extent); + vk::Extent2D extent = color.vulkan_buffer != nullptr ? color.extent : vk::Extent2D {}; + auto sc = calc_final_scissor(vp, ctx->GetScanModeControl(), extent); LOGF( "DrawTargetState[%u]: frame=%d %s target=%s addr=0x%010" PRIx64 @@ -350,20 +348,16 @@ static void LogDrawInputState(const RenderColorInfo& color, } } -static void VulkanCmdSetColorWriteEnableEXT(GraphicContext* ctx, VkCommandBuffer command_buffer, - uint32_t attachment_count, - const VkBool32* p_color_write_enables) { +static void VulkanCmdSetColorWriteEnableEXT(GraphicContext* ctx, vk::CommandBuffer command_buffer, + uint32_t attachment_count, + const vk::Bool32* p_color_write_enables) { EXIT_IF(ctx == nullptr); - EXIT_IF(ctx->instance == nullptr); + EXIT_IF(ctx->device == nullptr); - static auto func = reinterpret_cast( - vkGetInstanceProcAddr(ctx->instance, "vkCmdSetColorWriteEnableEXT")); - - if (func != nullptr) { - func(command_buffer, attachment_count, p_color_write_enables); - } else { + if (VULKAN_HPP_DEFAULT_DISPATCHER.vkCmdSetColorWriteEnableEXT == nullptr) { EXIT("vkCmdSetColorWriteEnableEXT not present\n"); } + command_buffer.setColorWriteEnableEXT(attachment_count, p_color_write_enables); } static PipelineDynamicParameters BuildGraphicsDynamicParams(const HW::Context& ctx, @@ -376,8 +370,8 @@ static PipelineDynamicParameters BuildGraphicsDynamicParams(const HW::Context& ret.color_write_count = color_count; ret.stencil_test_enable = depth.stencil_test_enable; - const auto& vp = ctx.GetScreenViewport(); - VkExtent2D framebuffer_extent {}; + const auto& vp = ctx.GetScreenViewport(); + vk::Extent2D framebuffer_extent {}; if (color_count > 0 && colors[0].vulkan_buffer != nullptr) { framebuffer_extent = colors[0].extent; } else if (depth.vulkan_buffer != nullptr) { @@ -411,25 +405,25 @@ static PipelineDynamicParameters BuildGraphicsDynamicParams(const HW::Context& return ret; } -static void SetDynamicParams(VkCommandBuffer vk_buffer, +static void SetDynamicParams(vk::CommandBuffer vk_buffer, const PipelineDynamicParameters& dynamic_params) { KYTY_PROFILER_FUNCTION(); - VkViewport viewport {}; + vk::Viewport viewport {}; viewport.x = dynamic_params.viewport_offset[0] - dynamic_params.viewport_scale[0]; viewport.y = dynamic_params.viewport_offset[1] - dynamic_params.viewport_scale[1]; viewport.width = dynamic_params.viewport_scale[0] * 2.0f; viewport.height = dynamic_params.viewport_scale[1] * 2.0f; viewport.minDepth = dynamic_params.viewport_offset[2]; viewport.maxDepth = dynamic_params.viewport_scale[2] + dynamic_params.viewport_offset[2]; - vkCmdSetViewport(vk_buffer, 0, 1, &viewport); + vk_buffer.setViewport(0, 1, &viewport); - VkRect2D scissor {}; + vk::Rect2D scissor {}; scissor.offset = {dynamic_params.scissor_ltrb[0], dynamic_params.scissor_ltrb[1]}; scissor.extent = { static_cast(dynamic_params.scissor_ltrb[2] - dynamic_params.scissor_ltrb[0]), static_cast(dynamic_params.scissor_ltrb[3] - dynamic_params.scissor_ltrb[1])}; - vkCmdSetScissor(vk_buffer, 0, 1, &scissor); + vk_buffer.setScissor(0, 1, &scissor); float line_width = dynamic_params.line_width; if (line_width != 1.0f) { @@ -442,24 +436,24 @@ static void SetDynamicParams(VkCommandBuffer vk_buffer, } line_width = 1.0f; } - vkCmdSetLineWidth(vk_buffer, line_width); + vk_buffer.setLineWidth(line_width); if (dynamic_params.stencil_test_enable) { - vkCmdSetStencilCompareMask(vk_buffer, VK_STENCIL_FACE_FRONT_BIT, - dynamic_params.stencil_front.compareMask); - vkCmdSetStencilCompareMask(vk_buffer, VK_STENCIL_FACE_BACK_BIT, - dynamic_params.stencil_back.compareMask); - vkCmdSetStencilWriteMask(vk_buffer, VK_STENCIL_FACE_FRONT_BIT, - dynamic_params.stencil_front.writeMask); - vkCmdSetStencilWriteMask(vk_buffer, VK_STENCIL_FACE_BACK_BIT, - dynamic_params.stencil_back.writeMask); - vkCmdSetStencilReference(vk_buffer, VK_STENCIL_FACE_FRONT_BIT, - dynamic_params.stencil_front.reference); - vkCmdSetStencilReference(vk_buffer, VK_STENCIL_FACE_BACK_BIT, - dynamic_params.stencil_back.reference); + vk_buffer.setStencilCompareMask(vk::StencilFaceFlagBits::eFront, + dynamic_params.stencil_front.compareMask); + vk_buffer.setStencilCompareMask(vk::StencilFaceFlagBits::eBack, + dynamic_params.stencil_back.compareMask); + vk_buffer.setStencilWriteMask(vk::StencilFaceFlagBits::eFront, + dynamic_params.stencil_front.writeMask); + vk_buffer.setStencilWriteMask(vk::StencilFaceFlagBits::eBack, + dynamic_params.stencil_back.writeMask); + vk_buffer.setStencilReference(vk::StencilFaceFlagBits::eFront, + dynamic_params.stencil_front.reference); + vk_buffer.setStencilReference(vk::StencilFaceFlagBits::eBack, + dynamic_params.stencil_back.reference); } - VkBool32 enable[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::Bool32 enable[RENDER_COLOR_ATTACHMENTS_MAX] = {}; for (uint32_t i = 0; i < dynamic_params.color_write_count; i++) { enable[i] = (dynamic_params.color_write_enable[i] ? VK_TRUE : VK_FALSE); } @@ -544,7 +538,7 @@ struct DrawRenderState { uint32_t color_count = 0; bool ps_active = true; VulkanFramebuffer* framebuffer = nullptr; - VkCommandBuffer vk_buffer = nullptr; + vk::CommandBuffer vk_buffer = nullptr; ShaderVertexInputInfo vs_input_info; ShaderPixelInputInfo ps_input_info; std::span vs_shader; @@ -566,7 +560,7 @@ static bool DrawHasActivePixelShader(const HW::Context* ctx, const HW::Shader* s EXIT_IF(sh_ctx == nullptr); EXIT_IF(draw.name == nullptr); - const bool with_depth = (state.depth_info.format != VK_FORMAT_UNDEFINED && + const bool with_depth = (state.depth_info.format != vk::Format::eUndefined && state.depth_info.vulkan_buffer != nullptr); if (state.color_count != 0 || !with_depth) { return true; @@ -607,11 +601,11 @@ struct DrawEmitInfo { }; struct DrawIndexBufferSource { - bool enabled = false; - uint64_t address = 0; - const void* host_data = nullptr; - uint64_t size = 0; - VkIndexType type = VK_INDEX_TYPE_UINT16; + bool enabled = false; + uint64_t address = 0; + const void* host_data = nullptr; + uint64_t size = 0; + vk::IndexType type = vk::IndexType::eUint16; }; static uint64_t VertexBufferDescriptorSize(const ShaderVertexInputBuffer& buffer) { @@ -629,42 +623,44 @@ static void SetDrawDebugPhase(CommandBuffer* buffer, uint64_t submit_id, const D } static bool GetDrawTopology(const HW::UserConfig* ucfg, bool auto_draw, bool use_ngg_rectlist_draw, - VkPrimitiveTopology* topology) { + vk::PrimitiveTopology* topology) { EXIT_IF(ucfg == nullptr); EXIT_IF(topology == nullptr); - *topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + *topology = vk::PrimitiveTopology::ePointList; switch (static_cast(ucfg->GetPrimType())) { case Prospero::PrimitiveType::kNone: return false; case Prospero::PrimitiveType::kPointList: - *topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + *topology = vk::PrimitiveTopology::ePointList; + break; + case Prospero::PrimitiveType::kLineList: + *topology = vk::PrimitiveTopology::eLineList; break; - case Prospero::PrimitiveType::kLineList: *topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; break; case Prospero::PrimitiveType::kLineStrip: - *topology = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP; + *topology = vk::PrimitiveTopology::eLineStrip; break; case Prospero::PrimitiveType::kTriList: - *topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + *topology = vk::PrimitiveTopology::eTriangleList; break; case Prospero::PrimitiveType::kTriFan: - *topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN; + *topology = vk::PrimitiveTopology::eTriangleFan; break; case Prospero::PrimitiveType::kTriStrip: - *topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + *topology = vk::PrimitiveTopology::eTriangleStrip; break; case Prospero::PrimitiveType::kRectList: - *topology = (auto_draw && use_ngg_rectlist_draw ? VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP - : VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); + *topology = (auto_draw && use_ngg_rectlist_draw ? vk::PrimitiveTopology::eTriangleStrip + : vk::PrimitiveTopology::eTriangleList); break; case Prospero::PrimitiveType::kRectListLegacy: if (!auto_draw) { EXIT("unknown primitive type: %u\n", ucfg->GetPrimType()); } - *topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + *topology = vk::PrimitiveTopology::eTriangleStrip; break; case Prospero::PrimitiveType::kQuadListLegacy: - *topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN; + *topology = vk::PrimitiveTopology::eTriangleFan; break; default: EXIT("unknown primitive type: %u\n", ucfg->GetPrimType()); } @@ -711,7 +707,7 @@ static bool PrepareDrawRenderState(uint64_t submit_id, CommandBuffer* buffer, HW } } - const bool with_depth = (state->depth_info.format != VK_FORMAT_UNDEFINED && + const bool with_depth = (state->depth_info.format != vk::Format::eUndefined && state->depth_info.vulkan_buffer != nullptr); if (state->color_count == 0 && !with_depth) { LogFramebufferSkip(draw.name, state->color_info[0], state->depth_info, ctx, ucfg, @@ -784,7 +780,7 @@ static void RefreshShaders(HW::Context* ctx, HW::Shader* sh_ctx, const DrawCallI } static void BindDrawVertexBuffers(uint64_t submit_id, CommandBuffer* buffer, - const DrawCallInfo& draw, VkCommandBuffer vk_buffer, + const DrawCallInfo& draw, vk::CommandBuffer vk_buffer, const ShaderVertexInputInfo& vs_input_info) { EXIT_IF(buffer == nullptr); EXIT_IF(draw.name == nullptr); @@ -792,11 +788,11 @@ static void BindDrawVertexBuffers(uint64_t submit_id, CommandBuffer* buffer, LogDrawPhase(draw.name, "BindVertexBuffers"); for (int i = 0; i < vs_input_info.buffers_num; i++) { - const auto& b = vs_input_info.buffers[i]; - uint64_t addr = b.addr; - uint64_t size = VertexBufferDescriptorSize(b); - VulkanBuffer* vertices = nullptr; - VkDeviceSize offset = 0; + const auto& b = vs_input_info.buffers[i]; + uint64_t addr = b.addr; + uint64_t size = VertexBufferDescriptorSize(b); + VulkanBuffer* vertices = nullptr; + vk::DeviceSize offset = 0; if (size == 0) { vertices = g_render_ctx->GetBufferCache()->ObtainNullBuffer( @@ -809,21 +805,21 @@ static void BindDrawVertexBuffers(uint64_t submit_id, CommandBuffer* buffer, } EXIT_NOT_IMPLEMENTED(vertices == nullptr); - vkCmdBindVertexBuffers(vk_buffer, i, 1, &vertices->buffer, &offset); + vk_buffer.bindVertexBuffers(i, 1, &vertices->buffer, &offset); } } -static void BindDrawIndexBuffer(CommandBuffer* buffer, VkCommandBuffer vk_buffer, +static void BindDrawIndexBuffer(CommandBuffer* buffer, vk::CommandBuffer vk_buffer, const DrawIndexBufferSource& source) { if (!source.enabled) { return; } EXIT_IF(source.size == 0); - VulkanBuffer* index_buffer = nullptr; - VkDeviceSize index_offset = 0; + VulkanBuffer* index_buffer = nullptr; + vk::DeviceSize index_offset = 0; if (source.host_data != nullptr) { - VkDeviceSize range = 0; + vk::DeviceSize range = 0; if (!g_render_ctx->GetBufferCache()->UploadHostData(buffer, g_render_ctx->GetGraphicCtx(), source.host_data, source.size, 16, &index_buffer, &index_offset, &range)) { @@ -836,7 +832,7 @@ static void BindDrawIndexBuffer(CommandBuffer* buffer, VkCommandBuffer vk_buffer index_offset = binding.second; } EXIT_IF(index_buffer == nullptr); - vkCmdBindIndexBuffer(vk_buffer, index_buffer->buffer, index_offset, source.type); + vk_buffer.bindIndexBuffer(index_buffer->buffer, index_offset, source.type); } static void LogDrawStateIfNeeded(HW::Context* ctx, HW::UserConfig* ucfg, const DrawCallInfo& draw, @@ -876,7 +872,7 @@ static bool IsHostExpandedRectListDrawSupported(const ShaderVertexInputInfo& vs_ return draw.index_count == 3 || draw.index_count == emit.draw_vertex_count; } -static void EmitDrawPrimitives(const HW::UserConfig* ucfg, VkCommandBuffer vk_buffer, +static void EmitDrawPrimitives(const HW::UserConfig* ucfg, vk::CommandBuffer vk_buffer, const ShaderVertexInputInfo& vs_input_info, const DrawCallInfo& draw, const DrawEmitInfo& emit) { EXIT_IF(ucfg == nullptr); @@ -890,22 +886,22 @@ static void EmitDrawPrimitives(const HW::UserConfig* ucfg, VkCommandBuffer vk_bu case Prospero::PrimitiveType::kTriFan: case Prospero::PrimitiveType::kTriStrip: if (emit.indexed) { - vkCmdDrawIndexed(vk_buffer, draw.index_count, draw.instance_count, 0, - emit.vertex_offset, draw.first_instance); + vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset, + draw.first_instance); } else { - vkCmdDraw(vk_buffer, draw.index_count, draw.instance_count, emit.first_vertex, - draw.first_instance); + vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex, + draw.first_instance); } break; case Prospero::PrimitiveType::kRectList: if (emit.indexed) { - vkCmdDrawIndexed(vk_buffer, draw.index_count, draw.instance_count, 0, - emit.vertex_offset, draw.first_instance); + vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset, + draw.first_instance); } else { EXIT_NOT_IMPLEMENTED( !IsHostExpandedRectListDrawSupported(vs_input_info, draw, emit)); - vkCmdDraw(vk_buffer, emit.draw_vertex_count, draw.instance_count, emit.first_vertex, - draw.first_instance); + vk_buffer.draw(emit.draw_vertex_count, draw.instance_count, emit.first_vertex, + draw.first_instance); } break; case Prospero::PrimitiveType::kRectListLegacy: @@ -914,17 +910,17 @@ static void EmitDrawPrimitives(const HW::UserConfig* ucfg, VkCommandBuffer vk_bu } // Sarah EXIT_NOT_IMPLEMENTED(!(draw.index_count == 3 && vs_input_info.buffers_num == 0)); - vkCmdDraw(vk_buffer, 4, draw.instance_count, emit.first_vertex, draw.first_instance); + vk_buffer.draw(4, draw.instance_count, emit.first_vertex, draw.first_instance); break; case Prospero::PrimitiveType::kQuadListLegacy: EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0); for (uint32_t i = 0; i < draw.index_count; i += 4) { if (emit.indexed) { - vkCmdDrawIndexed(vk_buffer, 4, draw.instance_count, i, emit.vertex_offset, - draw.first_instance); + vk_buffer.drawIndexed(4, draw.instance_count, i, emit.vertex_offset, + draw.first_instance); } else { - vkCmdDraw(vk_buffer, 4, draw.instance_count, i + emit.first_vertex, - draw.first_instance); + vk_buffer.draw(4, draw.instance_count, i + emit.first_vertex, + draw.first_instance); } } break; @@ -934,7 +930,7 @@ static void EmitDrawPrimitives(const HW::UserConfig* ucfg, VkCommandBuffer vk_bu static void ExecutePreparedDraw(uint64_t submit_id, CommandBuffer* buffer, HW::Context* ctx, HW::UserConfig* ucfg, HW::Shader* sh_ctx, const DrawCallInfo& draw, - DrawRenderState* state, VkPrimitiveTopology topology, + DrawRenderState* state, vk::PrimitiveTopology topology, const DrawEmitInfo& emit, const DrawIndexBufferSource& index_source, bool log_pipeline_phase, bool set_bind_debug, bool set_auto_debug) { EXIT_IF(buffer == nullptr); @@ -957,7 +953,7 @@ static void ExecutePreparedDraw(uint64_t submit_id, CommandBuffer* buffer, HW::C if (set_bind_debug) { SetDrawDebugPhase(buffer, submit_id, draw, 0x100u); } - vkCmdBindPipeline(state->vk_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); + state->vk_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline->pipeline); const auto dynamic_params = BuildGraphicsDynamicParams( *ctx, state->color_info, state->color_count, state->depth_info); SetDynamicParams(state->vk_buffer, dynamic_params); @@ -969,9 +965,10 @@ static void ExecutePreparedDraw(uint64_t submit_id, CommandBuffer* buffer, HW::C if (set_auto_debug) { SetDrawDebugPhase(buffer, submit_id, draw, 0x200u); } - const auto vs_address_writes = BindDescriptors( - submit_id, buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline_layout, - state->vs_input_info.stage, VK_SHADER_STAGE_VERTEX_BIT, DescriptorCache::Stage::Vertex); + const auto vs_address_writes = + BindDescriptors(submit_id, buffer, vk::PipelineBindPoint::eGraphics, + pipeline->pipeline_layout, state->vs_input_info.stage, + vk::ShaderStageFlagBits::eVertex, DescriptorCache::Stage::Vertex); std::vector ps_address_writes; if (state->ps_active) { @@ -980,9 +977,9 @@ static void ExecutePreparedDraw(uint64_t submit_id, CommandBuffer* buffer, HW::C SetDrawDebugPhase(buffer, submit_id, draw, 0x300u); } ps_address_writes = - BindDescriptors(submit_id, buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + BindDescriptors(submit_id, buffer, vk::PipelineBindPoint::eGraphics, pipeline->pipeline_layout, state->ps_input_info.stage, - VK_SHADER_STAGE_FRAGMENT_BIT, DescriptorCache::Stage::Pixel); + vk::ShaderStageFlagBits::eFragment, DescriptorCache::Stage::Pixel); } if (buffer->GetRecordingGeneration() != recording_generation) { continue; @@ -1010,20 +1007,20 @@ static void ExecutePreparedDraw(uint64_t submit_id, CommandBuffer* buffer, HW::C SetDrawDebugPhase(buffer, submit_id, draw, 0x600u); } buffer->EndRenderPass(); - VkPipelineStageFlags shader_write_stages = 0; - const bool vs_wrote_buffers = HasShaderBufferWrites(state->vs_input_info.stage); - const bool vs_wrote_addresses = MarkShaderAddressWrites(vs_address_writes); + vk::PipelineStageFlags shader_write_stages = {}; + const bool vs_wrote_buffers = HasShaderBufferWrites(state->vs_input_info.stage); + const bool vs_wrote_addresses = MarkShaderAddressWrites(vs_address_writes); if (vs_wrote_buffers || vs_wrote_addresses) { - shader_write_stages |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT; + shader_write_stages |= vk::PipelineStageFlagBits::eVertexShader; } if (state->ps_active) { const bool ps_wrote_buffers = HasShaderBufferWrites(state->ps_input_info.stage); const bool ps_wrote_addresses = MarkShaderAddressWrites(ps_address_writes); if (ps_wrote_buffers || ps_wrote_addresses) { - shader_write_stages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; + shader_write_stages |= vk::PipelineStageFlagBits::eFragmentShader; } } - if (shader_write_stages != 0) { + if (shader_write_stages) { ShaderWriteBarrier(state->vk_buffer, shader_write_stages); } LogDrawPhase(draw.name, "EndRenderPass"); @@ -1094,27 +1091,27 @@ void RenderDrawIndex(uint64_t submit_id, CommandBuffer* buffer, HW::Context* ctx hw_check(*ctx); - VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + vk::PrimitiveTopology topology = vk::PrimitiveTopology::ePointList; if (!GetDrawTopology(ucfg, false, false, &topology)) { return; } - VkIndexType index_type = VK_INDEX_TYPE_UINT16; - uint64_t index_size = 0; - bool expand_index8_to_u16 = false; + vk::IndexType index_type = vk::IndexType::eUint16; + uint64_t index_size = 0; + bool expand_index8_to_u16 = false; switch (static_cast(index_type_and_size)) { case Prospero::IndexType::kIndex16: - index_type = VK_INDEX_TYPE_UINT16; + index_type = vk::IndexType::eUint16; index_size = 2 * static_cast(index_count); break; case Prospero::IndexType::kIndex32: - index_type = VK_INDEX_TYPE_UINT32; + index_type = vk::IndexType::eUint32; index_size = 4 * static_cast(index_count); break; // Some games use it - need vulkan extension case Prospero::IndexType::kIndex8: - index_type = VK_INDEX_TYPE_UINT16; + index_type = vk::IndexType::eUint16; index_size = static_cast(index_count); expand_index8_to_u16 = true; break; @@ -1238,8 +1235,8 @@ void RenderDrawIndexAuto(uint64_t submit_id, CommandBuffer* buffer, HW::Context* return; } - VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; - const bool use_ngg_rectlist_draw = Config::NggRectlistDrawEnabled(); + vk::PrimitiveTopology topology = vk::PrimitiveTopology::ePointList; + const bool use_ngg_rectlist_draw = Config::NggRectlistDrawEnabled(); if (!GetDrawTopology(ucfg, true, use_ngg_rectlist_draw, &topology)) { return; diff --git a/src/graphics/host_gpu/renderer/renderTarget.h b/src/graphics/host_gpu/renderer/renderTarget.h index de9c9e692..c6b3584dd 100644 --- a/src/graphics/host_gpu/renderer/renderTarget.h +++ b/src/graphics/host_gpu/renderer/renderTarget.h @@ -1,9 +1,10 @@ #ifndef EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_RENDERTARGET_H_ #define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_RENDERTARGET_H_ +#include "graphics/host_gpu/vulkanCommon.h" + #include #include -#include namespace Libs::Graphics { @@ -40,10 +41,10 @@ inline constexpr TargetViewInfo ResolveTargetViewInfo(uint32_t base_layer, uint3 #pragma pack(push, 1) struct PipelineStencilStaticState { - VkStencilOp failOp = VK_STENCIL_OP_KEEP; - VkStencilOp passOp = VK_STENCIL_OP_KEEP; - VkStencilOp depthFailOp = VK_STENCIL_OP_KEEP; - VkCompareOp compareOp = VK_COMPARE_OP_NEVER; + vk::StencilOp failOp = vk::StencilOp::eKeep; + vk::StencilOp passOp = vk::StencilOp::eKeep; + vk::StencilOp depthFailOp = vk::StencilOp::eKeep; + vk::CompareOp compareOp = vk::CompareOp::eNever; }; struct PipelineStencilDynamicState { @@ -56,16 +57,17 @@ struct PipelineStencilDynamicState { inline constexpr bool stencil_face_accesses_attachment(const PipelineStencilStaticState& state, const PipelineStencilDynamicState& dynamic) { - return state.compareOp != VK_COMPARE_OP_ALWAYS || + return state.compareOp != vk::CompareOp::eAlways || (dynamic.writeMask != 0 && - (state.failOp != VK_STENCIL_OP_KEEP || state.passOp != VK_STENCIL_OP_KEEP || - state.depthFailOp != VK_STENCIL_OP_KEEP)); + (state.failOp != vk::StencilOp::eKeep || state.passOp != vk::StencilOp::eKeep || + state.depthFailOp != vk::StencilOp::eKeep)); } static_assert(std::is_trivially_copyable_v); static_assert(std::is_standard_layout_v); static_assert(alignof(PipelineStencilStaticState) == 1); -static_assert(sizeof(PipelineStencilStaticState) == sizeof(VkStencilOp) * 3 + sizeof(VkCompareOp)); +static_assert(sizeof(PipelineStencilStaticState) == + sizeof(vk::StencilOp) * 3 + sizeof(vk::CompareOp)); static_assert(std::is_trivially_copyable_v); static_assert(std::is_standard_layout_v); static_assert(alignof(PipelineStencilDynamicState) == 1); diff --git a/src/graphics/host_gpu/renderer/renderTargetBarriers.cpp b/src/graphics/host_gpu/renderer/renderTargetBarriers.cpp index f738ea0f2..95a7c05b0 100644 --- a/src/graphics/host_gpu/renderer/renderTargetBarriers.cpp +++ b/src/graphics/host_gpu/renderer/renderTargetBarriers.cpp @@ -16,6 +16,7 @@ #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/displayBuffer.h" #include @@ -24,7 +25,6 @@ #include #include #include -#include namespace Libs::Graphics { @@ -34,123 +34,127 @@ void GraphicsRenderMemoryBarrier(CommandBuffer* buffer) { Common::LockGuard lock(g_render_ctx->GetMutex()); - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; - VkMemoryBarrier mem_barrier {}; - mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; + VulkanMemoryBarrier mem_barrier {}; + mem_barrier.sType = vk::StructureType::eMemoryBarrier; mem_barrier.pNext = nullptr; - mem_barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; - mem_barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; + mem_barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite; + mem_barrier.dstAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1, &mem_barrier, 0, nullptr, 0, - nullptr); + vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eAllCommands, vk::DependencyFlags {}, 1, + &mem_barrier, 0, nullptr, 0, nullptr); } -void GraphicsRenderTextureBarrier(VkCommandBuffer vk_buffer, VulkanImage* image) { +void GraphicsRenderTextureBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image) { EXIT_IF(image == nullptr); - VkImageMemoryBarrier image_memory_barrier {}; - image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = nullptr; - image_memory_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | - VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT | - VK_ACCESS_MEMORY_READ_BIT; - image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - image_memory_barrier.oldLayout = image->layout; - image_memory_barrier.newLayout = RENDER_COLOR_IMAGE_LAYOUT; + vk::ImageMemoryBarrier image_memory_barrier {}; + image_memory_barrier.sType = vk::StructureType::eImageMemoryBarrier; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = + vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eTransferWrite | + vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eMemoryRead; + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead; + image_memory_barrier.oldLayout = image->layout; + image_memory_barrier.newLayout = RENDER_COLOR_IMAGE_LAYOUT; image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = image->image; - image_memory_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + image_memory_barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; image_memory_barrier.subresourceRange.baseArrayLayer = 0; image_memory_barrier.subresourceRange.layerCount = image->layers; - vkCmdPipelineBarrier( - vk_buffer, - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | - VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); + vk_buffer.pipelineBarrier( + vk::PipelineStageFlagBits::eColorAttachmentOutput | + vk::PipelineStageFlagBits::eComputeShader | vk::PipelineStageFlagBits::eTransfer | + vk::PipelineStageFlagBits::eFragmentShader, + vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader | + vk::PipelineStageFlagBits::eComputeShader, + vk::DependencyFlags {}, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); image->layout = image_memory_barrier.newLayout; } -void GraphicsRenderColorImageBarrier(VkCommandBuffer vk_buffer, VulkanImage* image, - VkImageLayout new_layout) { +void GraphicsRenderColorImageBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image, + vk::ImageLayout new_layout) { EXIT_IF(image == nullptr); if (image->layout != new_layout) { if (image->type == VulkanImageType::VideoOut && - image->layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { + image->layout == vk::ImageLayout::eTransferDstOptimal) { static std::atomic log_count {0}; if (log_count.fetch_add(1, std::memory_order_relaxed) < 128) { LOGF("GraphicsRenderColorImageBarrier: image=%p type=%d layout=%s -> %s\n", - reinterpret_cast(image->image), static_cast(image->type), - string_VkImageLayout(image->layout), string_VkImageLayout(new_layout)); + VulkanHandleToPointer(image->image), static_cast(image->type), + VulkanToString(image->layout).c_str(), VulkanToString(new_layout).c_str()); } } - VkImageMemoryBarrier image_memory_barrier {}; - image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = nullptr; - image_memory_barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_MEMORY_READ_BIT; - image_memory_barrier.dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_MEMORY_READ_BIT; - image_memory_barrier.oldLayout = image->layout; - image_memory_barrier.newLayout = new_layout; + vk::ImageMemoryBarrier image_memory_barrier {}; + image_memory_barrier.sType = vk::StructureType::eImageMemoryBarrier; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = + vk::AccessFlagBits::eMemoryWrite | vk::AccessFlagBits::eMemoryRead; + image_memory_barrier.dstAccessMask = + vk::AccessFlagBits::eMemoryWrite | vk::AccessFlagBits::eMemoryRead; + image_memory_barrier.oldLayout = image->layout; + image_memory_barrier.newLayout = new_layout; image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = image->image; - image_memory_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + image_memory_barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; image_memory_barrier.subresourceRange.baseArrayLayer = 0; image_memory_barrier.subresourceRange.layerCount = image->layers; - const auto stages = static_cast(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | - VK_PIPELINE_STAGE_TRANSFER_BIT); - vkCmdPipelineBarrier(vk_buffer, stages, stages, 0, 0, nullptr, 0, nullptr, 1, - &image_memory_barrier); + const auto stages = static_cast( + vk::PipelineStageFlagBits::eAllGraphics | vk::PipelineStageFlagBits::eComputeShader | + vk::PipelineStageFlagBits::eTransfer); + vk_buffer.pipelineBarrier(stages, stages, vk::DependencyFlags {}, 0, nullptr, 0, nullptr, 1, + &image_memory_barrier); image->layout = image_memory_barrier.newLayout; } } -VkImageAspectFlags DepthStencilAspectMask(VkFormat format); +vk::ImageAspectFlags DepthStencilAspectMask(vk::Format format); -void GraphicsRenderDepthStencilImageBarrier(VkCommandBuffer vk_buffer, VulkanImage* image, - VkImageLayout new_layout) { +void GraphicsRenderDepthStencilImageBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image, + vk::ImageLayout new_layout) { EXIT_IF(image == nullptr); EXIT_IF(image->type != VulkanImageType::DepthStencil); - if (new_layout == VK_IMAGE_LAYOUT_UNDEFINED || new_layout == VK_IMAGE_LAYOUT_PREINITIALIZED) { + if (new_layout == vk::ImageLayout::eUndefined || + new_layout == vk::ImageLayout::ePreinitialized) { EXIT("invalid destination depth/stencil image layout: %s\n", - string_VkImageLayout(new_layout)); + VulkanToString(new_layout).c_str()); } if (image->layout == new_layout) { return; } - VkImageMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - barrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; - barrier.oldLayout = image->layout; - barrier.newLayout = new_layout; + vk::ImageMemoryBarrier barrier {}; + barrier.sType = vk::StructureType::eImageMemoryBarrier; + barrier.srcAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; + barrier.dstAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; + barrier.oldLayout = image->layout; + barrier.newLayout = new_layout; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.image = image->image; barrier.subresourceRange = {DepthStencilAspectMask(image->format), 0, VK_REMAINING_MIP_LEVELS, 0, image->layers}; - const auto stages = static_cast(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | - VK_PIPELINE_STAGE_TRANSFER_BIT); - vkCmdPipelineBarrier(vk_buffer, stages, stages, 0, 0, nullptr, 0, nullptr, 1, &barrier); + const auto stages = static_cast( + vk::PipelineStageFlagBits::eAllGraphics | vk::PipelineStageFlagBits::eComputeShader | + vk::PipelineStageFlagBits::eTransfer); + vk_buffer.pipelineBarrier(stages, stages, vk::DependencyFlags {}, 0, nullptr, 0, nullptr, 1, + &barrier); image->layout = new_layout; } -void GraphicsRenderDepthStencilBarrier(VkCommandBuffer vk_buffer, VulkanImage* image) { +void GraphicsRenderDepthStencilBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image) { EXIT_IF(image == nullptr); EXIT_IF(image->type != VulkanImageType::DepthStencil); @@ -161,35 +165,35 @@ void GraphicsRenderDepthStencilBarrier(VkCommandBuffer vk_buffer, VulkanImage* i if (log_count.fetch_add(1, std::memory_order_relaxed) < 16) { LOGF( "DepthTexture: decompressing depth target for shader read format=%s extent=%ux%u\n", - string_VkFormat(depth->format), depth->extent.width, depth->extent.height); + VulkanToString(depth->format).c_str(), depth->extent.width, depth->extent.height); } depth->compressed = false; } - if (image->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) { - VkImageMemoryBarrier image_memory_barrier {}; - image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - image_memory_barrier.pNext = nullptr; - image_memory_barrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; - image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - image_memory_barrier.oldLayout = image->layout; - image_memory_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; - image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - image_memory_barrier.image = image->image; + if (image->layout != vk::ImageLayout::eDepthStencilReadOnlyOptimal) { + vk::ImageMemoryBarrier image_memory_barrier {}; + image_memory_barrier.sType = vk::StructureType::eImageMemoryBarrier; + image_memory_barrier.pNext = nullptr; + image_memory_barrier.srcAccessMask = + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead; + image_memory_barrier.oldLayout = image->layout; + image_memory_barrier.newLayout = vk::ImageLayout::eDepthStencilReadOnlyOptimal; + image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + image_memory_barrier.image = image->image; image_memory_barrier.subresourceRange.aspectMask = DepthStencilAspectMask(image->format); image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; image_memory_barrier.subresourceRange.baseArrayLayer = 0; image_memory_barrier.subresourceRange.layerCount = image->layers; - vkCmdPipelineBarrier( - vk_buffer, - VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | - VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); + vk_buffer.pipelineBarrier( + vk::PipelineStageFlagBits::eAllGraphics | vk::PipelineStageFlagBits::eComputeShader | + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader | + vk::PipelineStageFlagBits::eComputeShader, + vk::DependencyFlags {}, 0, nullptr, 0, nullptr, 1, &image_memory_barrier); image->layout = image_memory_barrier.newLayout; } @@ -201,7 +205,7 @@ void GraphicsRenderTextureBarrier(CommandBuffer* buffer, uint64_t vaddr, uint64_ Common::LockGuard lock(g_render_ctx->GetMutex()); - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; auto* native = g_render_ctx->GetTextureCache()->FindRenderTargetByRange(buffer, vaddr, size); if (native == nullptr) { @@ -216,7 +220,7 @@ void GraphicsRenderDepthStencilBarrier(CommandBuffer* buffer, uint64_t vaddr, ui Common::LockGuard lock(g_render_ctx->GetMutex()); - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; auto* native = g_render_ctx->GetTextureCache()->FindDepthTargetByRange(buffer, vaddr, size); if (native == nullptr) { EXIT("depth-target barrier range has no cached image\n"); diff --git a/src/graphics/host_gpu/renderer/renderTargetBarriers.h b/src/graphics/host_gpu/renderer/renderTargetBarriers.h index 5f9477902..c24a5189b 100644 --- a/src/graphics/host_gpu/renderer/renderTargetBarriers.h +++ b/src/graphics/host_gpu/renderer/renderTargetBarriers.h @@ -1,18 +1,18 @@ #ifndef EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_RENDERTARGETBARRIERS_H_ #define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_RENDERTARGETBARRIERS_H_ -#include +#include "graphics/host_gpu/vulkanCommon.h" namespace Libs::Graphics { struct VulkanImage; -void GraphicsRenderTextureBarrier(VkCommandBuffer vk_buffer, VulkanImage* image); -void GraphicsRenderColorImageBarrier(VkCommandBuffer vk_buffer, VulkanImage* image, - VkImageLayout new_layout); -void GraphicsRenderDepthStencilImageBarrier(VkCommandBuffer vk_buffer, VulkanImage* image, - VkImageLayout new_layout); -void GraphicsRenderDepthStencilBarrier(VkCommandBuffer vk_buffer, VulkanImage* image); +void GraphicsRenderTextureBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image); +void GraphicsRenderColorImageBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image, + vk::ImageLayout new_layout); +void GraphicsRenderDepthStencilImageBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image, + vk::ImageLayout new_layout); +void GraphicsRenderDepthStencilBarrier(vk::CommandBuffer vk_buffer, VulkanImage* image); } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/samplerCache.cpp b/src/graphics/host_gpu/renderer/samplerCache.cpp index c320add11..b93bbcb8f 100644 --- a/src/graphics/host_gpu/renderer/samplerCache.cpp +++ b/src/graphics/host_gpu/renderer/samplerCache.cpp @@ -7,7 +7,7 @@ namespace Libs::Graphics { -VkSampler SamplerCache::GetSampler(const ShaderSamplerResource& r) { +vk::Sampler SamplerCache::GetSampler(const ShaderSamplerResource& r) { Common::LockGuard lock(m_mutex); const SamplerKey key {r.fields[0], r.fields[1], r.fields[2], r.fields[3]}; @@ -33,12 +33,12 @@ VkSampler SamplerCache::GetSampler(const ShaderSamplerResource& r) { auto to_vk_filter = [](uint8_t filter) { switch (static_cast(filter)) { case Prospero::SamplerFilter::kPoint: - case Prospero::SamplerFilter::kAnisoPoint: return VK_FILTER_NEAREST; + case Prospero::SamplerFilter::kAnisoPoint: return vk::Filter::eNearest; case Prospero::SamplerFilter::kBilinear: - case Prospero::SamplerFilter::kAnisoLinear: return VK_FILTER_LINEAR; + case Prospero::SamplerFilter::kAnisoLinear: return vk::Filter::eLinear; default: EXIT("unknown sampler filter: %u\n", filter); } - return VK_FILTER_NEAREST; + return vk::Filter::eNearest; }; const bool aniso = is_aniso_filter(mag_filter) || is_aniso_filter(min_filter); @@ -61,60 +61,60 @@ VkSampler SamplerCache::GetSampler(const ShaderSamplerResource& r) { max_lod = static_cast(r.MaxLod()) / 256.0f; } - VkSamplerCreateInfo sampler_info {}; + vk::SamplerCreateInfo sampler_info {}; auto to_vk_address_mode = [](uint8_t clamp) { switch (static_cast(clamp)) { - case Prospero::SamplerClampMode::kWrap: return VK_SAMPLER_ADDRESS_MODE_REPEAT; + case Prospero::SamplerClampMode::kWrap: return vk::SamplerAddressMode::eRepeat; case Prospero::SamplerClampMode::kMirror: - return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; + return vk::SamplerAddressMode::eMirroredRepeat; case Prospero::SamplerClampMode::kClampLastTexel: - return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + return vk::SamplerAddressMode::eClampToEdge; case Prospero::SamplerClampMode::kMirrorOnceLastTexel: - return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; + return vk::SamplerAddressMode::eMirrorClampToEdge; case Prospero::SamplerClampMode::kClampHalfBorder: - return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; + return vk::SamplerAddressMode::eClampToBorder; case Prospero::SamplerClampMode::kMirrorOnceHalfBorder: - return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; + return vk::SamplerAddressMode::eMirrorClampToEdge; case Prospero::SamplerClampMode::kClampBorder: - return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; + return vk::SamplerAddressMode::eClampToBorder; case Prospero::SamplerClampMode::kMirrorOnceBorder: - return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; + return vk::SamplerAddressMode::eMirrorClampToEdge; default: EXIT("unknown clamp: %u\n", clamp); } - return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; + return vk::SamplerAddressMode::eClampToBorder; }; - VkBorderColor border = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK; + vk::BorderColor border = vk::BorderColor::eIntTransparentBlack; switch (static_cast(r.BorderColorType())) { case Prospero::SamplerBorderColor::kTransBlack: - border = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK; + border = vk::BorderColor::eIntTransparentBlack; break; case Prospero::SamplerBorderColor::kOpaqueBlack: - border = VK_BORDER_COLOR_INT_OPAQUE_BLACK; + border = vk::BorderColor::eIntOpaqueBlack; break; case Prospero::SamplerBorderColor::kOpaqueWhite: - border = VK_BORDER_COLOR_INT_OPAQUE_WHITE; + border = vk::BorderColor::eIntOpaqueWhite; break; case Prospero::SamplerBorderColor::kFromTable: LOGF( "temporary: approximating table border color as transparent black, index = %" PRIu16 "\n", r.BorderColorPtr()); - border = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK; + border = vk::BorderColor::eIntTransparentBlack; break; default: EXIT("unknown border color: %d", static_cast(r.BorderColorType())); } - sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler_info.sType = vk::StructureType::eSamplerCreateInfo; sampler_info.pNext = nullptr; - sampler_info.flags = 0; + sampler_info.flags = {}; sampler_info.magFilter = to_vk_filter(mag_filter); sampler_info.minFilter = to_vk_filter(min_filter); sampler_info.mipmapMode = (static_cast(mip_filter) == Prospero::SamplerMipFilter::kLinear - ? VK_SAMPLER_MIPMAP_MODE_LINEAR - : VK_SAMPLER_MIPMAP_MODE_NEAREST); + ? vk::SamplerMipmapMode::eLinear + : vk::SamplerMipmapMode::eNearest); sampler_info.addressModeU = to_vk_address_mode(r.ClampX()); sampler_info.addressModeV = to_vk_address_mode(r.ClampY()); sampler_info.addressModeW = to_vk_address_mode(r.ClampZ()); @@ -123,17 +123,17 @@ VkSampler SamplerCache::GetSampler(const ShaderSamplerResource& r) { sampler_info.anisotropyEnable = (aniso ? VK_TRUE : VK_FALSE); sampler_info.maxAnisotropy = aniso_ratio; sampler_info.compareEnable = (r.DepthCompareFunc() != 0 ? VK_TRUE : VK_FALSE); - sampler_info.compareOp = static_cast(r.DepthCompareFunc()); + sampler_info.compareOp = static_cast(r.DepthCompareFunc()); sampler_info.minLod = min_lod; sampler_info.maxLod = max_lod; sampler_info.borderColor = border; sampler_info.unnormalizedCoordinates = (r.ForceUnormCoords() ? VK_TRUE : VK_FALSE); if (r.ForceUnormCoords()) { - sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; + sampler_info.addressModeU = vk::SamplerAddressMode::eClampToEdge; + sampler_info.addressModeV = vk::SamplerAddressMode::eClampToEdge; + sampler_info.addressModeW = vk::SamplerAddressMode::eClampToEdge; + sampler_info.mipmapMode = vk::SamplerMipmapMode::eNearest; sampler_info.minLod = 0.0f; sampler_info.maxLod = 0.0f; sampler_info.anisotropyEnable = VK_FALSE; @@ -142,8 +142,8 @@ VkSampler SamplerCache::GetSampler(const ShaderSamplerResource& r) { sampler_info.mipLodBias = 0.0f; } - VkSampler vk_sampler = nullptr; - vkCreateSampler(g_render_ctx->GetGraphicCtx()->device, &sampler_info, nullptr, &vk_sampler); + vk::Sampler vk_sampler = nullptr; + g_render_ctx->GetGraphicCtx()->device.createSampler(&sampler_info, nullptr, &vk_sampler); EXIT_NOT_IMPLEMENTED(vk_sampler == nullptr); m_samplers.emplace(key, vk_sampler); diff --git a/src/graphics/host_gpu/renderer/samplerCache.h b/src/graphics/host_gpu/renderer/samplerCache.h index 65301842f..b4a8dc965 100644 --- a/src/graphics/host_gpu/renderer/samplerCache.h +++ b/src/graphics/host_gpu/renderer/samplerCache.h @@ -5,12 +5,12 @@ #include "common/assert.h" #include "common/common.h" #include "common/threads.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/shaderBindings.h" #include #include #include -#include namespace Libs::Graphics { @@ -20,7 +20,7 @@ public: virtual ~SamplerCache() { KYTY_NOT_IMPLEMENTED; } KYTY_CLASS_NO_COPY(SamplerCache); - VkSampler GetSampler(const ShaderSamplerResource& r); + vk::Sampler GetSampler(const ShaderSamplerResource& r); private: using SamplerKey = std::array; @@ -37,8 +37,8 @@ private: } }; - Common::Mutex m_mutex; - std::unordered_map m_samplers; + Common::Mutex m_mutex; + std::unordered_map m_samplers; }; } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/shaderResourceBarrier.cpp b/src/graphics/host_gpu/renderer/shaderResourceBarrier.cpp index 9219def8a..74fc49447 100644 --- a/src/graphics/host_gpu/renderer/shaderResourceBarrier.cpp +++ b/src/graphics/host_gpu/renderer/shaderResourceBarrier.cpp @@ -9,63 +9,70 @@ namespace Libs::Graphics { -VkPipelineStageFlags ShaderPipelineStages(VkShaderStageFlags stages) { - VkPipelineStageFlags result = 0; - if ((stages & VK_SHADER_STAGE_VERTEX_BIT) != 0) { - result |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT; +vk::PipelineStageFlags ShaderPipelineStages(vk::ShaderStageFlags stages) { + vk::PipelineStageFlags result = {}; + if (stages & vk::ShaderStageFlagBits::eVertex) { + result |= vk::PipelineStageFlagBits::eVertexShader; } - if ((stages & VK_SHADER_STAGE_FRAGMENT_BIT) != 0) { - result |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; + if (stages & vk::ShaderStageFlagBits::eFragment) { + result |= vk::PipelineStageFlagBits::eFragmentShader; } - if ((stages & VK_SHADER_STAGE_COMPUTE_BIT) != 0) { - result |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; + if (stages & vk::ShaderStageFlagBits::eCompute) { + result |= vk::PipelineStageFlagBits::eComputeShader; } - EXIT_IF(result == 0); + EXIT_IF(!result); return result; } -VkMemoryBarrier MakeShaderWriteDependency() { - VkMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; - barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT | - VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_INDEX_READ_BIT | - VK_ACCESS_UNIFORM_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT | - VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; +VulkanMemoryBarrier MakeShaderWriteDependency() { + VulkanMemoryBarrier barrier {}; + barrier.sType = vk::StructureType::eMemoryBarrier; + barrier.srcAccessMask = vk::AccessFlagBits::eShaderWrite; + barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite | + vk::AccessFlagBits::eVertexAttributeRead | + vk::AccessFlagBits::eIndexRead | vk::AccessFlagBits::eUniformRead | + vk::AccessFlagBits::eTransferRead | vk::AccessFlagBits::eTransferWrite | + vk::AccessFlagBits::eColorAttachmentRead | + vk::AccessFlagBits::eColorAttachmentWrite; return barrier; } -VkImageMemoryBarrier MakeStorageImageDependency(const VulkanImage& image, bool read, bool written) { +vk::ImageMemoryBarrier MakeStorageImageDependency(const VulkanImage& image, bool read, + bool written) { EXIT_IF(image.image == nullptr || image.type == VulkanImageType::DepthStencil); - VkImageMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; - barrier.dstAccessMask = - (read ? VK_ACCESS_SHADER_READ_BIT : 0) | (written ? VK_ACCESS_SHADER_WRITE_BIT : 0); + vk::ImageMemoryBarrier barrier {}; + barrier.sType = vk::StructureType::eImageMemoryBarrier; + barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite; + barrier.dstAccessMask = {}; + if (read) { + barrier.dstAccessMask |= vk::AccessFlagBits::eShaderRead; + } + if (written) { + barrier.dstAccessMask |= vk::AccessFlagBits::eShaderWrite; + } barrier.oldLayout = image.layout; - barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL; + barrier.newLayout = vk::ImageLayout::eGeneral; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.image = image.image; - barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; barrier.subresourceRange.baseMipLevel = 0; barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; barrier.subresourceRange.baseArrayLayer = 0; barrier.subresourceRange.layerCount = image.layers; - EXIT_IF(barrier.dstAccessMask == 0 || barrier.subresourceRange.layerCount == 0); + EXIT_IF(!barrier.dstAccessMask || barrier.subresourceRange.layerCount == 0); return barrier; } -VkBufferMemoryBarrier MakeGdsDependency(const VulkanBuffer& buffer) { +vk::BufferMemoryBarrier MakeGdsDependency(const VulkanBuffer& buffer) { EXIT_IF(buffer.buffer == nullptr); - VkBufferMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; - barrier.srcAccessMask = - VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + vk::BufferMemoryBarrier barrier {}; + barrier.sType = vk::StructureType::eBufferMemoryBarrier; + barrier.srcAccessMask = vk::AccessFlagBits::eHostWrite | vk::AccessFlagBits::eTransferWrite | + vk::AccessFlagBits::eShaderWrite; + barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.buffer = buffer.buffer; @@ -113,15 +120,16 @@ bool HasShaderBufferWrites(const ShaderStageRuntime& runtime) { return !CollectShaderBufferWrites(*runtime.program, *runtime.resources).empty(); } -void ShaderWriteBarrier(VkCommandBuffer vk_buffer, VkPipelineStageFlags source_stages) { - EXIT_IF(vk_buffer == nullptr || source_stages == 0); +void ShaderWriteBarrier(vk::CommandBuffer vk_buffer, vk::PipelineStageFlags source_stages) { + EXIT_IF(vk_buffer == nullptr || !source_stages); const auto barrier = MakeShaderWriteDependency(); - vkCmdPipelineBarrier( - vk_buffer, source_stages, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | - VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - 0, 1, &barrier, 0, nullptr, 0, nullptr); + vk_buffer.pipelineBarrier( + source_stages, + vk::PipelineStageFlagBits::eComputeShader | vk::PipelineStageFlagBits::eVertexInput | + vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader | + vk::PipelineStageFlagBits::eTransfer | + vk::PipelineStageFlagBits::eColorAttachmentOutput, + vk::DependencyFlags {}, 1, &barrier, 0, nullptr, 0, nullptr); } } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/shaderResourceBarrier.h b/src/graphics/host_gpu/renderer/shaderResourceBarrier.h index 2ed32359d..7e6bf0426 100644 --- a/src/graphics/host_gpu/renderer/shaderResourceBarrier.h +++ b/src/graphics/host_gpu/renderer/shaderResourceBarrier.h @@ -18,16 +18,17 @@ struct ShaderBufferWriteRange { bool operator==(const ShaderBufferWriteRange& other) const = default; }; -VkPipelineStageFlags ShaderPipelineStages(VkShaderStageFlags stages); -VkMemoryBarrier MakeShaderWriteDependency(); -VkImageMemoryBarrier MakeStorageImageDependency(const VulkanImage& image, bool read, bool written); -VkBufferMemoryBarrier MakeGdsDependency(const VulkanBuffer& buffer); +vk::PipelineStageFlags ShaderPipelineStages(vk::ShaderStageFlags stages); +VulkanMemoryBarrier MakeShaderWriteDependency(); +vk::ImageMemoryBarrier MakeStorageImageDependency(const VulkanImage& image, bool read, + bool written); +vk::BufferMemoryBarrier MakeGdsDependency(const VulkanBuffer& buffer); std::vector CollectShaderBufferWrites(const ShaderRecompiler::IR::Program& program, const ShaderRecompiler::IR::ResourceSnapshot& resources); bool MarkShaderAddressWrites(const std::vector& writes); bool HasShaderBufferWrites(const ShaderStageRuntime& runtime); -void ShaderWriteBarrier(VkCommandBuffer vk_buffer, VkPipelineStageFlags source_stages); +void ShaderWriteBarrier(vk::CommandBuffer vk_buffer, vk::PipelineStageFlags source_stages); } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/shaderSubgroup.cpp b/src/graphics/host_gpu/renderer/shaderSubgroup.cpp index c301c65c7..d4d6ee4b6 100644 --- a/src/graphics/host_gpu/renderer/shaderSubgroup.cpp +++ b/src/graphics/host_gpu/renderer/shaderSubgroup.cpp @@ -17,13 +17,13 @@ ShaderLaneMaskMode SelectGraphicsLaneMaskMode(const GraphicContext& context, } ShaderSubgroupConfiguration ConfigureShaderSubgroup(const GraphicContext& context, - VkShaderStageFlagBits stage, + vk::ShaderStageFlagBits stage, const ShaderRecompiler::IR::Program& program) { const auto guest_wave_size = program.wave_size; if (guest_wave_size != 32u && guest_wave_size != 64u) { return {}; } - if (stage != VK_SHADER_STAGE_COMPUTE_BIT) { + if (stage != vk::ShaderStageFlagBits::eCompute) { const auto expected = SelectGraphicsLaneMaskMode(context, guest_wave_size); if (program.lane_mask_mode != expected || (context.subgroup_size != guest_wave_size && expected != ShaderLaneMaskMode::PerInvocation)) { @@ -40,8 +40,7 @@ ShaderSubgroupConfiguration ConfigureShaderSubgroup(const GraphicContext& if (context.subgroup_size == guest_wave_size) { return {ShaderSubgroupMode::Natural, 0}; } - if (context.subgroup_size_control_enabled && - (context.required_subgroup_size_stages & stage) != 0 && + if (context.subgroup_size_control_enabled && (context.required_subgroup_size_stages & stage) && guest_wave_size >= context.min_subgroup_size && guest_wave_size <= context.max_subgroup_size) { return {ShaderSubgroupMode::Controlled, guest_wave_size}; diff --git a/src/graphics/host_gpu/renderer/shaderSubgroup.h b/src/graphics/host_gpu/renderer/shaderSubgroup.h index 499530a31..7e0ace565 100644 --- a/src/graphics/host_gpu/renderer/shaderSubgroup.h +++ b/src/graphics/host_gpu/renderer/shaderSubgroup.h @@ -23,7 +23,7 @@ ShaderLaneMaskMode SelectGraphicsLaneMaskMode(const GraphicContext& context, uint32_t guest_wave_size); ShaderSubgroupConfiguration ConfigureShaderSubgroup(const GraphicContext& context, - VkShaderStageFlagBits stage, + vk::ShaderStageFlagBits stage, const ShaderRecompiler::IR::Program& program); } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/shaders.cpp b/src/graphics/host_gpu/renderer/shaders.cpp index 5a17684b5..0c712d94b 100644 --- a/src/graphics/host_gpu/renderer/shaders.cpp +++ b/src/graphics/host_gpu/renderer/shaders.cpp @@ -12,20 +12,20 @@ #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/renderer/renderTarget.h" #include "graphics/host_gpu/renderer/shaderSubgroup.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/recompiler/ShaderIR.h" #include "graphics/shader/shader.h" #include #include #include -#include namespace Libs::Graphics { // IDK: maybe we can remove it? constexpr uint32_t kTemporaryPs5BufferFormat121 = 121u; -static bool NarrowInputFormat(VkFormat* format, uint32_t* size, uint32_t used_components) { +static bool NarrowInputFormat(vk::Format* format, uint32_t* size, uint32_t used_components) { EXIT_IF(format == nullptr); EXIT_IF(size == nullptr); @@ -34,50 +34,50 @@ static bool NarrowInputFormat(VkFormat* format, uint32_t* size, uint32_t used_co } switch (*format) { - case VK_FORMAT_R32G32B32A32_SFLOAT: + case vk::Format::eR32G32B32A32Sfloat: switch (used_components) { - case 1: *format = VK_FORMAT_R32_SFLOAT; break; - case 2: *format = VK_FORMAT_R32G32_SFLOAT; break; - case 3: *format = VK_FORMAT_R32G32B32_SFLOAT; break; + case 1: *format = vk::Format::eR32Sfloat; break; + case 2: *format = vk::Format::eR32G32Sfloat; break; + case 3: *format = vk::Format::eR32G32B32Sfloat; break; default: return false; } *size = used_components; return true; - case VK_FORMAT_R32G32B32_SFLOAT: + case vk::Format::eR32G32B32Sfloat: switch (used_components) { - case 1: *format = VK_FORMAT_R32_SFLOAT; break; - case 2: *format = VK_FORMAT_R32G32_SFLOAT; break; + case 1: *format = vk::Format::eR32Sfloat; break; + case 2: *format = vk::Format::eR32G32Sfloat; break; default: return false; } *size = used_components; return true; - case VK_FORMAT_R16G16B16A16_SFLOAT: + case vk::Format::eR16G16B16A16Sfloat: switch (used_components) { - case 1: *format = VK_FORMAT_R16_SFLOAT; break; - case 2: *format = VK_FORMAT_R16G16_SFLOAT; break; + case 1: *format = vk::Format::eR16Sfloat; break; + case 2: *format = vk::Format::eR16G16Sfloat; break; default: return false; } *size = used_components; return true; - case VK_FORMAT_R8G8B8A8_UNORM: + case vk::Format::eR8G8B8A8Unorm: switch (used_components) { - case 1: *format = VK_FORMAT_R8_UNORM; break; - case 2: *format = VK_FORMAT_R8G8_UNORM; break; + case 1: *format = vk::Format::eR8Unorm; break; + case 2: *format = vk::Format::eR8G8Unorm; break; default: return false; } *size = used_components; return true; - case VK_FORMAT_R8G8B8A8_SNORM: + case vk::Format::eR8G8B8A8Snorm: if (used_components != 2) { return false; } - *format = VK_FORMAT_R8G8_SNORM; + *format = vk::Format::eR8G8Snorm; *size = 2; return true; - case VK_FORMAT_R8G8B8A8_UINT: + case vk::Format::eR8G8B8A8Uint: switch (used_components) { - case 1: *format = VK_FORMAT_R8_UINT; break; - case 2: *format = VK_FORMAT_R8G8_UINT; break; + case 1: *format = vk::Format::eR8Uint; break; + case 2: *format = vk::Format::eR8G8Uint; break; default: return false; } *size = used_components; @@ -88,7 +88,7 @@ static bool NarrowInputFormat(VkFormat* format, uint32_t* size, uint32_t used_co return false; } -static void GetInputFormat(const ShaderBufferResource& res, VkFormat* format, uint32_t* size, +static void GetInputFormat(const ShaderBufferResource& res, vk::Format* format, uint32_t* size, uint32_t used_components) { EXIT_IF(format == nullptr); EXIT_IF(size == nullptr); @@ -98,244 +98,244 @@ static void GetInputFormat(const ShaderBufferResource& res, VkFormat* format, ui static bool logged_113 = false; if (!logged_113) { LOGF("InputFormat: temporary: accepting invalid PS5 buffer format 113 as " - "VK_FORMAT_R32G32B32A32_SFLOAT\n"); + "vk::Format::eR32G32B32A32Sfloat\n"); logged_113 = true; } - *format = VK_FORMAT_R32G32B32A32_SFLOAT; + *format = vk::Format::eR32G32B32A32Sfloat; *size = 4; if (NarrowInputFormat(format, size, used_components)) { LOGF("InputFormat: narrowing fmt=%u to %s for used_components=%u\n", fmt, - string_VkFormat(*format), used_components); + VulkanToString(*format).c_str(), used_components); } return; } if (fmt == kTemporaryPs5BufferFormat121) { static bool logged_121 = false; if (!logged_121) { - LOGF("InputFormat: accepting PS5 buffer format 121 as VK_FORMAT_R16G16_SFLOAT\n"); + LOGF("InputFormat: accepting PS5 buffer format 121 as vk::Format::eR16G16Sfloat\n"); logged_121 = true; } - *format = VK_FORMAT_R16G16_SFLOAT; + *format = vk::Format::eR16G16Sfloat; *size = 2; if (NarrowInputFormat(format, size, used_components)) { LOGF("InputFormat: narrowing fmt=%u to %s for used_components=%u\n", fmt, - string_VkFormat(*format), used_components); + VulkanToString(*format).c_str(), used_components); } return; } switch (static_cast(fmt)) { case Prospero::BufferFormat::k32_32_32_32Float: - *format = VK_FORMAT_R32G32B32A32_SFLOAT; + *format = vk::Format::eR32G32B32A32Sfloat; *size = 4; break; case Prospero::BufferFormat::k32_32_32_32SInt: - *format = VK_FORMAT_R32G32B32A32_SINT; + *format = vk::Format::eR32G32B32A32Sint; *size = 4; break; case Prospero::BufferFormat::k32_32_32_32UInt: - *format = VK_FORMAT_R32G32B32A32_UINT; + *format = vk::Format::eR32G32B32A32Uint; *size = 4; break; case Prospero::BufferFormat::k32_32_32Float: - *format = VK_FORMAT_R32G32B32_SFLOAT; + *format = vk::Format::eR32G32B32Sfloat; *size = 3; break; case Prospero::BufferFormat::k32_32_32SInt: - *format = VK_FORMAT_R32G32B32_SINT; + *format = vk::Format::eR32G32B32Sint; *size = 3; break; case Prospero::BufferFormat::k32_32_32UInt: - *format = VK_FORMAT_R32G32B32_UINT; + *format = vk::Format::eR32G32B32Uint; *size = 3; break; case Prospero::BufferFormat::k16_16_16_16Float: - *format = VK_FORMAT_R16G16B16A16_SFLOAT; + *format = vk::Format::eR16G16B16A16Sfloat; *size = 4; break; case Prospero::BufferFormat::k16_16_16_16SInt: - *format = VK_FORMAT_R16G16B16A16_SINT; + *format = vk::Format::eR16G16B16A16Sint; *size = 4; break; case Prospero::BufferFormat::k16_16_16_16UInt: - *format = VK_FORMAT_R16G16B16A16_UINT; + *format = vk::Format::eR16G16B16A16Uint; *size = 4; break; case Prospero::BufferFormat::k16_16_16_16SScaled: - *format = VK_FORMAT_R16G16B16A16_SSCALED; + *format = vk::Format::eR16G16B16A16Sscaled; *size = 4; break; case Prospero::BufferFormat::k16_16_16_16UScaled: - *format = VK_FORMAT_R16G16B16A16_USCALED; + *format = vk::Format::eR16G16B16A16Uscaled; *size = 4; break; case Prospero::BufferFormat::k16_16_16_16SNorm: - *format = VK_FORMAT_R16G16B16A16_SNORM; + *format = vk::Format::eR16G16B16A16Snorm; *size = 4; break; case Prospero::BufferFormat::k16_16_16_16UNorm: - *format = VK_FORMAT_R16G16B16A16_UNORM; + *format = vk::Format::eR16G16B16A16Unorm; *size = 4; break; case Prospero::BufferFormat::k32_32Float: - *format = VK_FORMAT_R32G32_SFLOAT; + *format = vk::Format::eR32G32Sfloat; *size = 2; break; case Prospero::BufferFormat::k32_32SInt: - *format = VK_FORMAT_R32G32_SINT; + *format = vk::Format::eR32G32Sint; *size = 2; break; case Prospero::BufferFormat::k32_32UInt: - *format = VK_FORMAT_R32G32_UINT; + *format = vk::Format::eR32G32Uint; *size = 2; break; case Prospero::BufferFormat::k8_8_8_8UInt: - *format = VK_FORMAT_R8G8B8A8_UINT; + *format = vk::Format::eR8G8B8A8Uint; *size = 4; break; case Prospero::BufferFormat::k8_8_8_8SScaled: - *format = VK_FORMAT_R8G8B8A8_SSCALED; + *format = vk::Format::eR8G8B8A8Sscaled; *size = 4; break; case Prospero::BufferFormat::k8_8_8_8UScaled: - *format = VK_FORMAT_R8G8B8A8_USCALED; + *format = vk::Format::eR8G8B8A8Uscaled; *size = 4; break; case Prospero::BufferFormat::k8_8_8_8SNorm: - *format = VK_FORMAT_R8G8B8A8_SNORM; + *format = vk::Format::eR8G8B8A8Snorm; *size = 4; break; case Prospero::BufferFormat::k8_8_8_8UNorm: - *format = VK_FORMAT_R8G8B8A8_UNORM; + *format = vk::Format::eR8G8B8A8Unorm; *size = 4; break; case Prospero::BufferFormat::k10_10_10_2UNorm: - *format = VK_FORMAT_A2B10G10R10_UNORM_PACK32; + *format = vk::Format::eA2B10G10R10UnormPack32; *size = 4; break; case Prospero::BufferFormat::k10_10_10_2SNorm: - *format = VK_FORMAT_A2B10G10R10_SNORM_PACK32; + *format = vk::Format::eA2B10G10R10SnormPack32; *size = 4; break; case Prospero::BufferFormat::k16_16Float: - *format = VK_FORMAT_R16G16_SFLOAT; + *format = vk::Format::eR16G16Sfloat; *size = 2; break; case Prospero::BufferFormat::k16_16SInt: - *format = VK_FORMAT_R16G16_SINT; + *format = vk::Format::eR16G16Sint; *size = 2; break; case Prospero::BufferFormat::k16_16UInt: - *format = VK_FORMAT_R16G16_UINT; + *format = vk::Format::eR16G16Uint; *size = 2; break; case Prospero::BufferFormat::k16_16SScaled: - *format = VK_FORMAT_R16G16_SSCALED; + *format = vk::Format::eR16G16Sscaled; *size = 2; break; case Prospero::BufferFormat::k16_16UScaled: - *format = VK_FORMAT_R16G16_USCALED; + *format = vk::Format::eR16G16Uscaled; *size = 2; break; case Prospero::BufferFormat::k16_16SNorm: - *format = VK_FORMAT_R16G16_SNORM; + *format = vk::Format::eR16G16Snorm; *size = 2; break; case Prospero::BufferFormat::k16_16UNorm: - *format = VK_FORMAT_R16G16_UNORM; + *format = vk::Format::eR16G16Unorm; *size = 2; break; case Prospero::BufferFormat::k32Float: - *format = VK_FORMAT_R32_SFLOAT; + *format = vk::Format::eR32Sfloat; *size = 1; break; case Prospero::BufferFormat::k32SInt: - *format = VK_FORMAT_R32_SINT; + *format = vk::Format::eR32Sint; *size = 1; break; case Prospero::BufferFormat::k32UInt: - *format = VK_FORMAT_R32_UINT; + *format = vk::Format::eR32Uint; *size = 1; break; case Prospero::BufferFormat::k8_8SInt: - *format = VK_FORMAT_R8G8_SINT; + *format = vk::Format::eR8G8Sint; *size = 2; break; case Prospero::BufferFormat::k8_8UInt: - *format = VK_FORMAT_R8G8_UINT; + *format = vk::Format::eR8G8Uint; *size = 2; break; case Prospero::BufferFormat::k8_8SScaled: - *format = VK_FORMAT_R8G8_SSCALED; + *format = vk::Format::eR8G8Sscaled; *size = 2; break; case Prospero::BufferFormat::k8_8UScaled: - *format = VK_FORMAT_R8G8_USCALED; + *format = vk::Format::eR8G8Uscaled; *size = 2; break; case Prospero::BufferFormat::k8_8SNorm: - *format = VK_FORMAT_R8G8_SNORM; + *format = vk::Format::eR8G8Snorm; *size = 2; break; case Prospero::BufferFormat::k8_8UNorm: - *format = VK_FORMAT_R8G8_UNORM; + *format = vk::Format::eR8G8Unorm; *size = 2; break; case Prospero::BufferFormat::k16Float: - *format = VK_FORMAT_R16_SFLOAT; + *format = vk::Format::eR16Sfloat; *size = 1; break; case Prospero::BufferFormat::k16SInt: - *format = VK_FORMAT_R16_SINT; + *format = vk::Format::eR16Sint; *size = 1; break; case Prospero::BufferFormat::k16UInt: - *format = VK_FORMAT_R16_UINT; + *format = vk::Format::eR16Uint; *size = 1; break; case Prospero::BufferFormat::k16SScaled: - *format = VK_FORMAT_R16_SSCALED; + *format = vk::Format::eR16Sscaled; *size = 1; break; case Prospero::BufferFormat::k16UScaled: - *format = VK_FORMAT_R16_USCALED; + *format = vk::Format::eR16Uscaled; *size = 1; break; case Prospero::BufferFormat::k16SNorm: - *format = VK_FORMAT_R16_SNORM; + *format = vk::Format::eR16Snorm; *size = 1; break; case Prospero::BufferFormat::k16UNorm: - *format = VK_FORMAT_R16_UNORM; + *format = vk::Format::eR16Unorm; *size = 1; break; case Prospero::BufferFormat::k8SInt: - *format = VK_FORMAT_R8_SINT; + *format = vk::Format::eR8Sint; *size = 1; break; case Prospero::BufferFormat::k8UInt: - *format = VK_FORMAT_R8_UINT; + *format = vk::Format::eR8Uint; *size = 1; break; case Prospero::BufferFormat::k8SScaled: - *format = VK_FORMAT_R8_SSCALED; + *format = vk::Format::eR8Sscaled; *size = 1; break; case Prospero::BufferFormat::k8UScaled: - *format = VK_FORMAT_R8_USCALED; + *format = vk::Format::eR8Uscaled; *size = 1; break; case Prospero::BufferFormat::k8SNorm: - *format = VK_FORMAT_R8_SNORM; + *format = vk::Format::eR8Snorm; *size = 1; break; case Prospero::BufferFormat::k8UNorm: - *format = VK_FORMAT_R8_UNORM; + *format = vk::Format::eR8Unorm; *size = 1; break; default: EXIT("unknown format: fmt = %u\n", fmt); - *format = VK_FORMAT_UNDEFINED; + *format = vk::Format::eUndefined; *size = 4; break; } @@ -351,50 +351,51 @@ static void GetInputFormat(const ShaderBufferResource& res, VkFormat* format, ui } } -static VkBlendFactor GetBlendFactor(uint32_t factor) { +static vk::BlendFactor GetBlendFactor(uint32_t factor) { switch (static_cast(factor)) { - case Prospero::BlendFactor::kZero: return VK_BLEND_FACTOR_ZERO; - case Prospero::BlendFactor::kOne: return VK_BLEND_FACTOR_ONE; - case Prospero::BlendFactor::kSrcColor: return VK_BLEND_FACTOR_SRC_COLOR; - case Prospero::BlendFactor::kOneMinusSrcColor: return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR; - case Prospero::BlendFactor::kSrcAlpha: return VK_BLEND_FACTOR_SRC_ALPHA; - case Prospero::BlendFactor::kOneMinusSrcAlpha: return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - case Prospero::BlendFactor::kDstAlpha: return VK_BLEND_FACTOR_DST_ALPHA; - case Prospero::BlendFactor::kOneMinusDstAlpha: return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA; - case Prospero::BlendFactor::kDstColor: return VK_BLEND_FACTOR_DST_COLOR; - case Prospero::BlendFactor::kOneMinusDstColor: return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR; - case Prospero::BlendFactor::kSrcAlphaSaturate: return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE; - case Prospero::BlendFactor::kConstantColor: return VK_BLEND_FACTOR_CONSTANT_COLOR; + case Prospero::BlendFactor::kZero: return vk::BlendFactor::eZero; + case Prospero::BlendFactor::kOne: return vk::BlendFactor::eOne; + case Prospero::BlendFactor::kSrcColor: return vk::BlendFactor::eSrcColor; + case Prospero::BlendFactor::kOneMinusSrcColor: return vk::BlendFactor::eOneMinusSrcColor; + case Prospero::BlendFactor::kSrcAlpha: return vk::BlendFactor::eSrcAlpha; + case Prospero::BlendFactor::kOneMinusSrcAlpha: return vk::BlendFactor::eOneMinusSrcAlpha; + case Prospero::BlendFactor::kDstAlpha: return vk::BlendFactor::eDstAlpha; + case Prospero::BlendFactor::kOneMinusDstAlpha: return vk::BlendFactor::eOneMinusDstAlpha; + case Prospero::BlendFactor::kDstColor: return vk::BlendFactor::eDstColor; + case Prospero::BlendFactor::kOneMinusDstColor: return vk::BlendFactor::eOneMinusDstColor; + case Prospero::BlendFactor::kSrcAlphaSaturate: return vk::BlendFactor::eSrcAlphaSaturate; + case Prospero::BlendFactor::kConstantColor: return vk::BlendFactor::eConstantColor; case Prospero::BlendFactor::kOneMinusConstantColor: - return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR; - case Prospero::BlendFactor::kSrc1Color: return VK_BLEND_FACTOR_SRC1_COLOR; - case Prospero::BlendFactor::kOneMinusSrc1Color: return VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR; - case Prospero::BlendFactor::kSrc1Alpha: return VK_BLEND_FACTOR_SRC1_ALPHA; - case Prospero::BlendFactor::kOneMinusSrc1Alpha: return VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA; - case Prospero::BlendFactor::kConstantAlpha: return VK_BLEND_FACTOR_CONSTANT_ALPHA; + return vk::BlendFactor::eOneMinusConstantColor; + case Prospero::BlendFactor::kSrc1Color: return vk::BlendFactor::eSrc1Color; + case Prospero::BlendFactor::kOneMinusSrc1Color: return vk::BlendFactor::eOneMinusSrc1Color; + case Prospero::BlendFactor::kSrc1Alpha: return vk::BlendFactor::eSrc1Alpha; + case Prospero::BlendFactor::kOneMinusSrc1Alpha: return vk::BlendFactor::eOneMinusSrc1Alpha; + case Prospero::BlendFactor::kConstantAlpha: return vk::BlendFactor::eConstantAlpha; case Prospero::BlendFactor::kOneMinusConstantAlpha: - return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA; + return vk::BlendFactor::eOneMinusConstantAlpha; default: EXIT("unknown factor: %u\n", factor); } - return VK_BLEND_FACTOR_ZERO; + return vk::BlendFactor::eZero; } -static VkBlendOp GetBlendOp(uint32_t op) { +static vk::BlendOp GetBlendOp(uint32_t op) { switch (static_cast(op)) { - case Prospero::BlendOp::kAdd: return VK_BLEND_OP_ADD; - case Prospero::BlendOp::kSubtract: return VK_BLEND_OP_SUBTRACT; - case Prospero::BlendOp::kMin: return VK_BLEND_OP_MIN; - case Prospero::BlendOp::kMax: return VK_BLEND_OP_MAX; - case Prospero::BlendOp::kReverseSubtract: return VK_BLEND_OP_REVERSE_SUBTRACT; + case Prospero::BlendOp::kAdd: return vk::BlendOp::eAdd; + case Prospero::BlendOp::kSubtract: return vk::BlendOp::eSubtract; + case Prospero::BlendOp::kMin: return vk::BlendOp::eMin; + case Prospero::BlendOp::kMax: return vk::BlendOp::eMax; + case Prospero::BlendOp::kReverseSubtract: return vk::BlendOp::eReverseSubtract; default: EXIT("unknown op: %u\n", op); } - return VK_BLEND_OP_ADD; + return vk::BlendOp::eAdd; } -static void CreateLayout(VkDescriptorSetLayout* set_layouts, uint32_t* set_layouts_num, - VkPushConstantRange* push_constant_info, uint32_t* push_constant_info_num, - const ShaderRecompiler::IR::Program& program, VkShaderStageFlags vk_stage, - DescriptorCache::Stage stage) { +static void CreateLayout(vk::DescriptorSetLayout* set_layouts, uint32_t* set_layouts_num, + vk::PushConstantRange* push_constant_info, + uint32_t* push_constant_info_num, + const ShaderRecompiler::IR::Program& program, + vk::ShaderStageFlags vk_stage, DescriptorCache::Stage stage) { EXIT_IF(set_layouts == nullptr); EXIT_IF(set_layouts_num == nullptr); EXIT_IF(push_constant_info == nullptr); @@ -421,10 +422,10 @@ static void CreateLayout(VkDescriptorSetLayout* set_layouts, uint32_t* set_layou } } -static void ConfigureSubgroupSize(const GraphicContext* gctx, VkShaderStageFlagBits vk_stage, - const ShaderRecompiler::IR::Program& program, - VkPipelineShaderStageRequiredSubgroupSizeCreateInfo* required, - VkPipelineShaderStageCreateInfo* stage) { +static void ConfigureSubgroupSize(const GraphicContext* gctx, vk::ShaderStageFlagBits vk_stage, + const ShaderRecompiler::IR::Program& program, + vk::PipelineShaderStageRequiredSubgroupSizeCreateInfo* required, + vk::PipelineShaderStageCreateInfo* stage) { EXIT_IF(gctx == nullptr || required == nullptr || stage == nullptr); const auto config = ConfigureShaderSubgroup(*gctx, vk_stage, program); switch (config.mode) { @@ -454,16 +455,16 @@ static void ConfigureSubgroupSize(const GraphicContext* gctx, VkShaderStageFlagB "controlled_stages=0x%08x\n", program.wave_size, static_cast(vk_stage), gctx->subgroup_size, gctx->min_subgroup_size, gctx->max_subgroup_size, - gctx->required_subgroup_size_stages); + static_cast(gctx->required_subgroup_size_stages)); } - required->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO; + required->sType = vk::StructureType::ePipelineShaderStageRequiredSubgroupSizeCreateInfo; required->requiredSubgroupSize = config.required_size; stage->pNext = required; } // NOLINTNEXTLINE(readability-function-cognitive-complexity) -void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderPass render_pass, +void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, vk::RenderPass render_pass, const ShaderVertexInputInfo* vs_input_info, std::span vs_shader, const ShaderPixelInputInfo* ps_input_info, @@ -480,80 +481,81 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP EXIT_IF(gctx == nullptr); - VkShaderModule vert_shader_module = nullptr; - VkShaderModule frag_shader_module = nullptr; + vk::ShaderModule vert_shader_module = nullptr; + vk::ShaderModule frag_shader_module = nullptr; - VkShaderModuleCreateInfo create_info {}; + vk::ShaderModuleCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + create_info.sType = vk::StructureType::eShaderModuleCreateInfo; create_info.pNext = nullptr; - create_info.flags = 0; + create_info.flags = {}; create_info.codeSize = vs_shader.size() * 4; create_info.pCode = vs_shader.data(); - auto result = vkCreateShaderModule(gctx->device, &create_info, nullptr, &vert_shader_module); + auto result = gctx->device.createShaderModule(&create_info, nullptr, &vert_shader_module); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreateShaderModule VS done result=%s module=%p\n", - string_VkResult(result), static_cast(vert_shader_module)); + VulkanToString(result).c_str(), static_cast(vert_shader_module)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); if (ps_active) { create_info.codeSize = ps_shader.size() * 4; create_info.pCode = ps_shader.data(); - result = vkCreateShaderModule(gctx->device, &create_info, nullptr, &frag_shader_module); + result = gctx->device.createShaderModule(&create_info, nullptr, &frag_shader_module); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreateShaderModule PS done result=%s module=%p\n", - string_VkResult(result), static_cast(frag_shader_module)); + VulkanToString(result).c_str(), static_cast(frag_shader_module)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } EXIT_NOT_IMPLEMENTED(vert_shader_module == nullptr); EXIT_NOT_IMPLEMENTED(ps_active && frag_shader_module == nullptr); - VkPipelineShaderStageCreateInfo vert_shader_stage_info {}; - VkPipelineShaderStageRequiredSubgroupSizeCreateInfo vert_subgroup_size {}; + vk::PipelineShaderStageCreateInfo vert_shader_stage_info {}; + vk::PipelineShaderStageRequiredSubgroupSizeCreateInfo vert_subgroup_size {}; - vert_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - vert_shader_stage_info.pNext = nullptr; - vert_shader_stage_info.flags = 0; - vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT; - vert_shader_stage_info.module = vert_shader_module; - vert_shader_stage_info.pName = "main"; + vert_shader_stage_info.sType = vk::StructureType::ePipelineShaderStageCreateInfo; + vert_shader_stage_info.pNext = nullptr; + vert_shader_stage_info.flags = {}; + vert_shader_stage_info.stage = vk::ShaderStageFlagBits::eVertex; + vert_shader_stage_info.module = vert_shader_module; + vert_shader_stage_info.pName = "main"; vert_shader_stage_info.pSpecializationInfo = nullptr; EXIT_IF(!vs_input_info->stage); - ConfigureSubgroupSize(gctx, VK_SHADER_STAGE_VERTEX_BIT, *vs_input_info->stage.program, + ConfigureSubgroupSize(gctx, vk::ShaderStageFlagBits::eVertex, *vs_input_info->stage.program, &vert_subgroup_size, &vert_shader_stage_info); - VkPipelineShaderStageCreateInfo frag_shader_stage_info {}; - VkPipelineShaderStageRequiredSubgroupSizeCreateInfo frag_subgroup_size {}; - frag_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - frag_shader_stage_info.pNext = nullptr; - frag_shader_stage_info.flags = 0; - frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - frag_shader_stage_info.module = frag_shader_module; - frag_shader_stage_info.pName = "main"; + vk::PipelineShaderStageCreateInfo frag_shader_stage_info {}; + vk::PipelineShaderStageRequiredSubgroupSizeCreateInfo frag_subgroup_size {}; + frag_shader_stage_info.sType = vk::StructureType::ePipelineShaderStageCreateInfo; + frag_shader_stage_info.pNext = nullptr; + frag_shader_stage_info.flags = {}; + frag_shader_stage_info.stage = vk::ShaderStageFlagBits::eFragment; + frag_shader_stage_info.module = frag_shader_module; + frag_shader_stage_info.pName = "main"; frag_shader_stage_info.pSpecializationInfo = nullptr; if (ps_active) { EXIT_IF(!ps_input_info->stage); - ConfigureSubgroupSize(gctx, VK_SHADER_STAGE_FRAGMENT_BIT, *ps_input_info->stage.program, - &frag_subgroup_size, &frag_shader_stage_info); + ConfigureSubgroupSize(gctx, vk::ShaderStageFlagBits::eFragment, + *ps_input_info->stage.program, &frag_subgroup_size, + &frag_shader_stage_info); } - VkPipelineShaderStageCreateInfo shader_stages[] = {vert_shader_stage_info, - frag_shader_stage_info}; - const uint32_t shader_stage_count = ps_active ? 2u : 1u; + vk::PipelineShaderStageCreateInfo shader_stages[] = {vert_shader_stage_info, + frag_shader_stage_info}; + const uint32_t shader_stage_count = ps_active ? 2u : 1u; - VkVertexInputAttributeDescription input_attr[ShaderVertexInputInfo::RES_MAX]; - VkVertexInputBindingDescription input_desc[ShaderVertexInputInfo::RES_MAX]; + vk::VertexInputAttributeDescription input_attr[ShaderVertexInputInfo::RES_MAX]; + vk::VertexInputBindingDescription input_desc[ShaderVertexInputInfo::RES_MAX]; for (int bi = 0; bi < vs_input_info->buffers_num; bi++) { const auto& b = vs_input_info->buffers[bi]; input_desc[bi].binding = bi; input_desc[bi].stride = b.stride; input_desc[bi].inputRate = - (b.fetch_index == 0 ? VK_VERTEX_INPUT_RATE_VERTEX : VK_VERTEX_INPUT_RATE_INSTANCE); + (b.fetch_index == 0 ? vk::VertexInputRate::eVertex : vk::VertexInputRate::eInstance); for (int ai = 0; ai < b.attr_num; ai++) { auto index = b.attr_indices[ai]; @@ -673,23 +675,23 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP } } - VkPipelineVertexInputStateCreateInfo vertex_input_info {}; - vertex_input_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vk::PipelineVertexInputStateCreateInfo vertex_input_info {}; + vertex_input_info.sType = vk::StructureType::ePipelineVertexInputStateCreateInfo; vertex_input_info.pNext = nullptr; - vertex_input_info.flags = 0; + vertex_input_info.flags = {}; vertex_input_info.vertexBindingDescriptionCount = vs_input_info->buffers_num; vertex_input_info.pVertexBindingDescriptions = input_desc; vertex_input_info.vertexAttributeDescriptionCount = vs_input_info->resources_num; vertex_input_info.pVertexAttributeDescriptions = input_attr; - VkPipelineInputAssemblyStateCreateInfo input_assembly {}; - input_assembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + vk::PipelineInputAssemblyStateCreateInfo input_assembly {}; + input_assembly.sType = vk::StructureType::ePipelineInputAssemblyStateCreateInfo; input_assembly.pNext = nullptr; - input_assembly.flags = 0; + input_assembly.flags = {}; input_assembly.topology = static_params.topology; input_assembly.primitiveRestartEnable = VK_FALSE; - VkViewport viewport {}; + vk::Viewport viewport {}; viewport.x = static_params.viewport_offset[0] - static_params.viewport_scale[0]; viewport.y = static_params.viewport_offset[1] - static_params.viewport_scale[1]; viewport.width = static_params.viewport_scale[0] * 2.0f; @@ -697,47 +699,50 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP viewport.minDepth = static_params.viewport_offset[2]; viewport.maxDepth = static_params.viewport_scale[2] + static_params.viewport_offset[2]; - VkRect2D scissor {}; + vk::Rect2D scissor {}; scissor.offset = {static_params.scissor_ltrb[0], static_params.scissor_ltrb[1]}; scissor.extent = { static_cast(static_params.scissor_ltrb[2] - static_params.scissor_ltrb[0]), static_cast(static_params.scissor_ltrb[3] - static_params.scissor_ltrb[1])}; - VkPipelineViewportDepthClipControlCreateInfoEXT depth_clip_control {}; - depth_clip_control.sType = - VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_DEPTH_CLIP_CONTROL_CREATE_INFO_EXT; - depth_clip_control.pNext = nullptr; + vk::PipelineViewportDepthClipControlCreateInfoEXT depth_clip_control {}; + depth_clip_control.sType = vk::StructureType::ePipelineViewportDepthClipControlCreateInfoEXT; + depth_clip_control.pNext = nullptr; depth_clip_control.negativeOneToOne = (static_params.negative_one_to_one ? VK_TRUE : VK_FALSE); - VkPipelineViewportStateCreateInfo viewport_state {}; - viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + vk::PipelineViewportStateCreateInfo viewport_state {}; + viewport_state.sType = vk::StructureType::ePipelineViewportStateCreateInfo; viewport_state.pNext = &depth_clip_control; - viewport_state.flags = 0; + viewport_state.flags = {}; viewport_state.viewportCount = 1; viewport_state.pViewports = &viewport; viewport_state.scissorCount = 1; viewport_state.pScissors = &scissor; - VkCullModeFlags cull_mode = VK_CULL_MODE_NONE; - cull_mode |= (static_params.cull_back ? VK_CULL_MODE_BACK_BIT : 0u); - cull_mode |= (static_params.cull_front ? VK_CULL_MODE_FRONT_BIT : 0u); + vk::CullModeFlags cull_mode = vk::CullModeFlagBits::eNone; + if (static_params.cull_back) { + cull_mode |= vk::CullModeFlagBits::eBack; + } + if (static_params.cull_front) { + cull_mode |= vk::CullModeFlagBits::eFront; + } - VkFrontFace front_face = - (static_params.face ? VK_FRONT_FACE_CLOCKWISE : VK_FRONT_FACE_COUNTER_CLOCKWISE); + vk::FrontFace front_face = + (static_params.face ? vk::FrontFace::eClockwise : vk::FrontFace::eCounterClockwise); - VkPipelineRasterizationDepthClipStateCreateInfoEXT clip_ext {}; - clip_ext.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT; - clip_ext.pNext = nullptr; - clip_ext.flags = 0; + vk::PipelineRasterizationDepthClipStateCreateInfoEXT clip_ext {}; + clip_ext.sType = vk::StructureType::ePipelineRasterizationDepthClipStateCreateInfoEXT; + clip_ext.pNext = nullptr; + clip_ext.flags = {}; clip_ext.depthClipEnable = VK_FALSE; - VkPipelineRasterizationStateCreateInfo rasterizer {}; - rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + vk::PipelineRasterizationStateCreateInfo rasterizer {}; + rasterizer.sType = vk::StructureType::ePipelineRasterizationStateCreateInfo; rasterizer.pNext = &clip_ext; - rasterizer.flags = 0; + rasterizer.flags = {}; rasterizer.depthClampEnable = VK_FALSE; rasterizer.rasterizerDiscardEnable = VK_FALSE; - rasterizer.polygonMode = VK_POLYGON_MODE_FILL; + rasterizer.polygonMode = vk::PolygonMode::eFill; rasterizer.cullMode = cull_mode; rasterizer.frontFace = front_face; rasterizer.depthBiasEnable = VK_FALSE; @@ -746,32 +751,36 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP rasterizer.depthBiasSlopeFactor = 0.0f; rasterizer.lineWidth = 1.0f; - VkPipelineMultisampleStateCreateInfo multisampling {}; - multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + vk::PipelineMultisampleStateCreateInfo multisampling {}; + multisampling.sType = vk::StructureType::ePipelineMultisampleStateCreateInfo; multisampling.pNext = nullptr; - multisampling.flags = 0; + multisampling.flags = {}; multisampling.sampleShadingEnable = VK_FALSE; - multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + multisampling.rasterizationSamples = vk::SampleCountFlagBits::e1; multisampling.minSampleShading = 1.0f; multisampling.pSampleMask = nullptr; multisampling.alphaToCoverageEnable = VK_FALSE; multisampling.alphaToOneEnable = VK_FALSE; - VkPipelineColorBlendAttachmentState color_blend_attachment[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::PipelineColorBlendAttachmentState color_blend_attachment[RENDER_COLOR_ATTACHMENTS_MAX] = {}; for (uint32_t i = 0; i < static_params.color_count; i++) { - VkColorComponentFlags color_write_mask = 0; + vk::ColorComponentFlags color_write_mask = {}; EXIT_NOT_IMPLEMENTED((static_params.color_mask[i] & ~0x0fu) != 0); if ((static_params.color_mask[i] & 0x1u) != 0) { - color_write_mask |= static_cast(VK_COLOR_COMPONENT_R_BIT); + color_write_mask |= + static_cast(vk::ColorComponentFlagBits::eR); } if ((static_params.color_mask[i] & 0x2u) != 0) { - color_write_mask |= static_cast(VK_COLOR_COMPONENT_G_BIT); + color_write_mask |= + static_cast(vk::ColorComponentFlagBits::eG); } if ((static_params.color_mask[i] & 0x4u) != 0) { - color_write_mask |= static_cast(VK_COLOR_COMPONENT_B_BIT); + color_write_mask |= + static_cast(vk::ColorComponentFlagBits::eB); } if ((static_params.color_mask[i] & 0x8u) != 0) { - color_write_mask |= static_cast(VK_COLOR_COMPONENT_A_BIT); + color_write_mask |= + static_cast(vk::ColorComponentFlagBits::eA); } color_blend_attachment[i].colorWriteMask = color_write_mask; @@ -794,23 +803,23 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP : color_blend_attachment[i].colorBlendOp); } - VkBool32 color_write_enable[RENDER_COLOR_ATTACHMENTS_MAX] = {}; + vk::Bool32 color_write_enable[RENDER_COLOR_ATTACHMENTS_MAX] = {}; for (uint32_t i = 0; i < static_params.color_count; i++) { color_write_enable[i] = VK_TRUE; } - VkPipelineColorWriteCreateInfoEXT color_write {}; - color_write.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_WRITE_CREATE_INFO_EXT; + vk::PipelineColorWriteCreateInfoEXT color_write {}; + color_write.sType = vk::StructureType::ePipelineColorWriteCreateInfoEXT; color_write.pNext = nullptr; color_write.attachmentCount = static_params.color_count; color_write.pColorWriteEnables = color_write_enable; - VkPipelineColorBlendStateCreateInfo color_blending {}; - color_blending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + vk::PipelineColorBlendStateCreateInfo color_blending {}; + color_blending.sType = vk::StructureType::ePipelineColorBlendStateCreateInfo; color_blending.pNext = &color_write; - color_blending.flags = 0; + color_blending.flags = {}; color_blending.logicOpEnable = VK_FALSE; - color_blending.logicOp = VK_LOGIC_OP_COPY; + color_blending.logicOp = vk::LogicOp::eCopy; color_blending.attachmentCount = static_params.color_count; color_blending.pAttachments = color_blend_attachment; color_blending.blendConstants[0] = static_params.blend_color_red; @@ -818,27 +827,27 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP color_blending.blendConstants[2] = static_params.blend_color_blue; color_blending.blendConstants[3] = static_params.blend_color_alpha; - VkDescriptorSetLayout set_layouts[2] = {}; - uint32_t set_layouts_num = 0; + vk::DescriptorSetLayout set_layouts[2] = {}; + uint32_t set_layouts_num = 0; - VkPushConstantRange push_constant_info[2]; - uint32_t push_constant_info_num = 0; + vk::PushConstantRange push_constant_info[2]; + uint32_t push_constant_info_num = 0; EXIT_IF(!vs_input_info->stage); CreateLayout(set_layouts, &set_layouts_num, push_constant_info, &push_constant_info_num, - *vs_input_info->stage.program, VK_SHADER_STAGE_VERTEX_BIT, + *vs_input_info->stage.program, vk::ShaderStageFlagBits::eVertex, DescriptorCache::Stage::Vertex); if (ps_active) { EXIT_IF(!ps_input_info->stage); CreateLayout(set_layouts, &set_layouts_num, push_constant_info, &push_constant_info_num, - *ps_input_info->stage.program, VK_SHADER_STAGE_FRAGMENT_BIT, + *ps_input_info->stage.program, vk::ShaderStageFlagBits::eFragment, DescriptorCache::Stage::Pixel); } - VkPipelineLayoutCreateInfo pipeline_layout_info {}; - pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + vk::PipelineLayoutCreateInfo pipeline_layout_info {}; + pipeline_layout_info.sType = vk::StructureType::ePipelineLayoutCreateInfo; pipeline_layout_info.pNext = nullptr; - pipeline_layout_info.flags = 0; + pipeline_layout_info.flags = {}; pipeline_layout_info.setLayoutCount = set_layouts_num; pipeline_layout_info.pSetLayouts = (set_layouts_num > 0 ? set_layouts : nullptr); pipeline_layout_info.pushConstantRangeCount = push_constant_info_num; @@ -853,21 +862,21 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP "\n", vs_hash0, vs_crc32, ps_hash0, ps_crc32, set_layouts_num, push_constant_info_num); } - result = vkCreatePipelineLayout(gctx->device, &pipeline_layout_info, nullptr, - &pipeline->pipeline_layout); + result = gctx->device.createPipelineLayout(&pipeline_layout_info, nullptr, + &pipeline->pipeline_layout); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreatePipelineLayout done result=%s layout=%p\n", - string_VkResult(result), static_cast(pipeline->pipeline_layout)); + VulkanToString(result).c_str(), static_cast(pipeline->pipeline_layout)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(pipeline->pipeline_layout == nullptr); - VkPipelineDepthStencilStateCreateInfo depth_stencil_info {}; - depth_stencil_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depth_stencil_info.pNext = nullptr; - depth_stencil_info.flags = 0; - depth_stencil_info.depthTestEnable = (static_params.depth_test_enable ? VK_TRUE : VK_FALSE); + vk::PipelineDepthStencilStateCreateInfo depth_stencil_info {}; + depth_stencil_info.sType = vk::StructureType::ePipelineDepthStencilStateCreateInfo; + depth_stencil_info.pNext = nullptr; + depth_stencil_info.flags = {}; + depth_stencil_info.depthTestEnable = (static_params.depth_test_enable ? VK_TRUE : VK_FALSE); depth_stencil_info.depthWriteEnable = (static_params.depth_write_enable ? VK_TRUE : VK_FALSE); depth_stencil_info.depthCompareOp = static_params.depth_compare_op; depth_stencil_info.depthBoundsTestEnable = @@ -884,29 +893,29 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP depth_stencil_info.minDepthBounds = static_params.depth_min_bounds; depth_stencil_info.maxDepthBounds = static_params.depth_max_bounds; - const VkDynamicState dynamic_states[] = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR, - VK_DYNAMIC_STATE_LINE_WIDTH, - VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK, - VK_DYNAMIC_STATE_STENCIL_REFERENCE, - VK_DYNAMIC_STATE_STENCIL_WRITE_MASK, - VK_DYNAMIC_STATE_COLOR_WRITE_ENABLE_EXT, + const vk::DynamicState dynamic_states[] = { + vk::DynamicState::eViewport, + vk::DynamicState::eScissor, + vk::DynamicState::eLineWidth, + vk::DynamicState::eStencilCompareMask, + vk::DynamicState::eStencilReference, + vk::DynamicState::eStencilWriteMask, + vk::DynamicState::eColorWriteEnableEXT, }; const auto dynamic_states_count = static_cast(sizeof(dynamic_states) / sizeof(dynamic_states[0])); - VkPipelineDynamicStateCreateInfo dynamic_state {}; - dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + vk::PipelineDynamicStateCreateInfo dynamic_state {}; + dynamic_state.sType = vk::StructureType::ePipelineDynamicStateCreateInfo; dynamic_state.pNext = nullptr; - dynamic_state.flags = 0; + dynamic_state.flags = {}; dynamic_state.dynamicStateCount = dynamic_states_count; dynamic_state.pDynamicStates = dynamic_states; - VkGraphicsPipelineCreateInfo pipeline_info {}; - pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + vk::GraphicsPipelineCreateInfo pipeline_info {}; + pipeline_info.sType = vk::StructureType::eGraphicsPipelineCreateInfo; pipeline_info.pNext = nullptr; - pipeline_info.flags = 0; + pipeline_info.flags = {}; pipeline_info.stageCount = shader_stage_count; pipeline_info.pStages = shader_stages; pipeline_info.pVertexInputState = &vertex_input_info; @@ -937,20 +946,20 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline* pipeline, VkRenderP viewport.y, viewport.width, viewport.height, scissor.offset.x, scissor.offset.y, scissor.extent.width, scissor.extent.height); } - result = vkCreateGraphicsPipelines(gctx->device, nullptr, 1, &pipeline_info, nullptr, - &pipeline->pipeline); + result = gctx->device.createGraphicsPipelines(nullptr, 1, &pipeline_info, nullptr, + &pipeline->pipeline); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreateGraphicsPipelines done result=%s pipeline=%p\n", - string_VkResult(result), static_cast(pipeline->pipeline)); + VulkanToString(result).c_str(), static_cast(pipeline->pipeline)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(pipeline->pipeline == nullptr); if (frag_shader_module != nullptr) { - vkDestroyShaderModule(gctx->device, frag_shader_module, nullptr); + gctx->device.destroyShaderModule(frag_shader_module, nullptr); } - vkDestroyShaderModule(gctx->device, vert_shader_module, nullptr); + gctx->device.destroyShaderModule(vert_shader_module, nullptr); } // NOLINTNEXTLINE(readability-function-cognitive-complexity) @@ -964,52 +973,52 @@ void CreatePipelineInternal(PipelineCache::ComputePipeline* pipeline, EXIT_IF(gctx == nullptr); - VkShaderModule comp_shader_module = nullptr; + vk::ShaderModule comp_shader_module = nullptr; - VkShaderModuleCreateInfo create_info {}; + vk::ShaderModuleCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + create_info.sType = vk::StructureType::eShaderModuleCreateInfo; create_info.pNext = nullptr; - create_info.flags = 0; + create_info.flags = {}; create_info.codeSize = cs_shader.size() * 4; create_info.pCode = cs_shader.data(); LOGF("PipelineTrace: vkCreateShaderModule CS begin words=%" PRIu64 "\n", static_cast(cs_shader.size())); - auto result = vkCreateShaderModule(gctx->device, &create_info, nullptr, &comp_shader_module); + auto result = gctx->device.createShaderModule(&create_info, nullptr, &comp_shader_module); LOGF("PipelineTrace: vkCreateShaderModule CS done result=%s module=%p\n", - string_VkResult(result), static_cast(comp_shader_module)); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + VulkanToString(result).c_str(), static_cast(comp_shader_module)); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(comp_shader_module == nullptr); - VkPipelineShaderStageCreateInfo comp_shader_stage_info {}; - VkPipelineShaderStageRequiredSubgroupSizeCreateInfo comp_subgroup_size {}; - comp_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - comp_shader_stage_info.pNext = nullptr; - comp_shader_stage_info.flags = 0; - comp_shader_stage_info.stage = VK_SHADER_STAGE_COMPUTE_BIT; - comp_shader_stage_info.module = comp_shader_module; - comp_shader_stage_info.pName = "main"; + vk::PipelineShaderStageCreateInfo comp_shader_stage_info {}; + vk::PipelineShaderStageRequiredSubgroupSizeCreateInfo comp_subgroup_size {}; + comp_shader_stage_info.sType = vk::StructureType::ePipelineShaderStageCreateInfo; + comp_shader_stage_info.pNext = nullptr; + comp_shader_stage_info.flags = {}; + comp_shader_stage_info.stage = vk::ShaderStageFlagBits::eCompute; + comp_shader_stage_info.module = comp_shader_module; + comp_shader_stage_info.pName = "main"; comp_shader_stage_info.pSpecializationInfo = nullptr; EXIT_IF(!input_info->stage); - ConfigureSubgroupSize(gctx, VK_SHADER_STAGE_COMPUTE_BIT, *input_info->stage.program, + ConfigureSubgroupSize(gctx, vk::ShaderStageFlagBits::eCompute, *input_info->stage.program, &comp_subgroup_size, &comp_shader_stage_info); - VkDescriptorSetLayout set_layouts[1] = {}; - uint32_t set_layouts_num = 0; + vk::DescriptorSetLayout set_layouts[1] = {}; + uint32_t set_layouts_num = 0; - VkPushConstantRange push_constant_info[1]; - uint32_t push_constant_info_num = 0; + vk::PushConstantRange push_constant_info[1]; + uint32_t push_constant_info_num = 0; EXIT_IF(!input_info->stage); CreateLayout(set_layouts, &set_layouts_num, push_constant_info, &push_constant_info_num, - *input_info->stage.program, VK_SHADER_STAGE_COMPUTE_BIT, + *input_info->stage.program, vk::ShaderStageFlagBits::eCompute, DescriptorCache::Stage::Compute); - VkPipelineLayoutCreateInfo pipeline_layout_info {}; - pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + vk::PipelineLayoutCreateInfo pipeline_layout_info {}; + pipeline_layout_info.sType = vk::StructureType::ePipelineLayoutCreateInfo; pipeline_layout_info.pNext = nullptr; - pipeline_layout_info.flags = 0; + pipeline_layout_info.flags = {}; pipeline_layout_info.setLayoutCount = set_layouts_num; pipeline_layout_info.pSetLayouts = (set_layouts_num > 0 ? set_layouts : nullptr); pipeline_layout_info.pushConstantRangeCount = push_constant_info_num; @@ -1020,18 +1029,18 @@ void CreatePipelineInternal(PipelineCache::ComputePipeline* pipeline, LOGF("PipelineTrace: vkCreatePipelineLayout CS begin set_layouts=%u push_constants=%u\n", set_layouts_num, push_constant_info_num); - result = vkCreatePipelineLayout(gctx->device, &pipeline_layout_info, nullptr, - &pipeline->pipeline_layout); + result = gctx->device.createPipelineLayout(&pipeline_layout_info, nullptr, + &pipeline->pipeline_layout); LOGF("PipelineTrace: vkCreatePipelineLayout CS done result=%s layout=%p\n", - string_VkResult(result), static_cast(pipeline->pipeline_layout)); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + VulkanToString(result).c_str(), static_cast(pipeline->pipeline_layout)); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(pipeline->pipeline_layout == nullptr); - VkComputePipelineCreateInfo info {}; - info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + vk::ComputePipelineCreateInfo info {}; + info.sType = vk::StructureType::eComputePipelineCreateInfo; info.pNext = nullptr; - info.flags = 0; + info.flags = {}; info.stage = comp_shader_stage_info; info.layout = pipeline->pipeline_layout; info.basePipelineHandle = nullptr; @@ -1041,15 +1050,14 @@ void CreatePipelineInternal(PipelineCache::ComputePipeline* pipeline, LOGF("PipelineTrace: vkCreateComputePipelines begin layout=%p\n", static_cast(pipeline->pipeline_layout)); - result = - vkCreateComputePipelines(gctx->device, nullptr, 1, &info, nullptr, &pipeline->pipeline); + result = gctx->device.createComputePipelines(nullptr, 1, &info, nullptr, &pipeline->pipeline); LOGF("PipelineTrace: vkCreateComputePipelines done result=%s pipeline=%p\n", - string_VkResult(result), static_cast(pipeline->pipeline)); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + VulkanToString(result).c_str(), static_cast(pipeline->pipeline)); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(pipeline->pipeline == nullptr); - vkDestroyShaderModule(gctx->device, comp_shader_module, nullptr); + gctx->device.destroyShaderModule(comp_shader_module, nullptr); } } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/renderer/streamBuffer.cpp b/src/graphics/host_gpu/renderer/streamBuffer.cpp index 4ad3b2736..39dadea95 100644 --- a/src/graphics/host_gpu/renderer/streamBuffer.cpp +++ b/src/graphics/host_gpu/renderer/streamBuffer.cpp @@ -32,12 +32,13 @@ void HostStreamBuffer::EnsureBuffer(GraphicContext* ctx) { KYTY_PROFILER_BLOCK("HostStreamBuffer::create"); m_ctx = ctx; m_buffer = std::make_unique(); - m_buffer->usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | - VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | - VK_BUFFER_USAGE_TRANSFER_DST_BIT; - m_buffer->memory.property = static_cast(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + m_buffer->usage = vk::BufferUsageFlagBits::eStorageBuffer | + vk::BufferUsageFlagBits::eVertexBuffer | + vk::BufferUsageFlagBits::eIndexBuffer | + vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst; + m_buffer->memory.property = vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent | + vk::MemoryPropertyFlagBits::eHostCached; VulkanCreateBuffer(ctx, CAPACITY, m_buffer.get()); VulkanMapMemory(ctx, &m_buffer->memory, &m_mapped); const auto count = g_stream_buffer_count.fetch_add(1, std::memory_order_relaxed) + 1; diff --git a/src/graphics/host_gpu/renderer/textureCache.cpp b/src/graphics/host_gpu/renderer/textureCache.cpp index fb149615d..20e5b1a02 100644 --- a/src/graphics/host_gpu/renderer/textureCache.cpp +++ b/src/graphics/host_gpu/renderer/textureCache.cpp @@ -251,7 +251,7 @@ VulkanImage* TextureCache::PublishImage(CommandBuffer* command, image != nullptr ? static_cast(image->image) : nullptr, image != nullptr && image->registered); } - auto* result = image->image; + auto result = image->image; command->RetainResourceUntilFence(image); m_images.push_back(std::move(image)); RegisterImageLocked(*m_images.back()); @@ -397,10 +397,10 @@ struct TextureCache::ReadbackWorker { size <= info.address + info.size - vaddr; const bool d16 = info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm) && - info.format == VK_FORMAT_D16_UNORM && info.bytes_per_element == 2; + info.format == vk::Format::eD16Unorm && info.bytes_per_element == 2; const bool d32 = info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) && - info.format == VK_FORMAT_D32_SFLOAT && info.bytes_per_element == 4; + info.format == vk::Format::eD32Sfloat && info.bytes_per_element == 4; TileSizeAlign expected_stencil {}; TileSizeAlign expected_htile {}; TileSizeAlign expected_depth {}; @@ -466,7 +466,7 @@ struct TextureCache::ReadbackWorker { std::fill(download.begin(), download.end(), 0); const auto regions = MakeLayeredImageBufferCopies(info.layers, slice_size, info.pitch, info.width, - info.height, VK_IMAGE_ASPECT_DEPTH_BIT); + info.height, vk::ImageAspectFlagBits::eDepth); UtilFillBuffer(cached.ctx, download.data(), info.size, regions, cached.image, cached.image->layout); guest.resize(info.size); @@ -820,7 +820,7 @@ bool Equal(const DepthTargetInfo& left, const DepthTargetInfo& right) { } void AppendLayerCopies(std::vector& regions, VulkanImage* source, - VkImageAspectFlags aspect) { + vk::ImageAspectFlags aspect) { for (uint32_t layer = 0; layer < source->layers; layer++) { for (uint32_t level = 0; level < source->mip_levels; level++) { ImageImageCopy region {}; @@ -1060,7 +1060,7 @@ void TextureCache::RetireStorageDepthAliasLocked(GraphicContext* ctx, const Imag cached.ctx == ctx && cached.gpu_modified && !cached.buffer_modified && depth.address == requested.address && depth.size == requested.size && depth.stencil_address == 0 && depth.stencil_size == 0 && depth.htile_address == 0 && - depth.htile_size == 0 && depth.layers == 1 && depth.format == VK_FORMAT_D32_SFLOAT && + depth.htile_size == 0 && depth.layers == 1 && depth.format == vk::Format::eD32Sfloat && depth.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) && depth.bytes_per_element == 4 && depth.width == requested.width && depth.height == requested.height && depth.pitch == requested.pitch && @@ -1265,7 +1265,7 @@ VulkanImage* TextureCache::FindTexture(CommandBuffer* command, GraphicContext* c cached->kind = CachedImage::Kind::Texture; cached->info = info; cached->ctx = ctx; - VkComponentMapping components {}; + vk::ComponentMapping components {}; cached->image = ImageOps::CreateTexture(ctx, info, false, &cached->memory, &components); m_memory_tracker.ForEachUploadRange( info.address, info.size, false, [](uint64_t, uint64_t) noexcept {}, @@ -1401,7 +1401,7 @@ StorageTextureVulkanImage* TextureCache::FindStorageTexture(CommandBuffer* com cached->kind = CachedImage::Kind::StorageTexture; cached->info = info; cached->ctx = ctx; - VkComponentMapping components {}; + vk::ComponentMapping components {}; cached->image = ImageOps::CreateTexture(ctx, info, true, &cached->memory, &components); m_memory_tracker.ForEachUploadRange( info.address, info.size, true, [](uint64_t, uint64_t) noexcept {}, @@ -1420,7 +1420,7 @@ RenderTextureVulkanImage* TextureCache::FindRenderTarget(CommandBuffer* const RenderTargetInfo& info) { const bool standard64 = IsSupportedStandard64RenderTarget(info); if (info.address == 0 || info.size == 0 || info.address >= TRACKER_ADDRESS_SIZE || - info.size > TRACKER_ADDRESS_SIZE - info.address || info.format == VK_FORMAT_UNDEFINED || + info.size > TRACKER_ADDRESS_SIZE - info.address || info.format == vk::Format::eUndefined || info.width == 0 || info.height == 0 || info.pitch < info.width || info.bytes_per_element == 0 || info.levels == 0 || info.levels > 16 || info.layers == 0 || info.size % info.layers != 0 || @@ -1635,9 +1635,8 @@ RenderTextureVulkanImage* TextureCache::FindRenderTarget(CommandBuffer* std::vector regions; regions.reserve(static_cast(native_image_source->image->layers) * native_image_source->image->mip_levels); - AppendLayerCopies(regions, native_image_source->image, VK_IMAGE_ASPECT_COLOR_BIT); - UtilImageToImage(command, regions, cached->image, - static_cast(RENDER_COLOR_IMAGE_LAYOUT)); + AppendLayerCopies(regions, native_image_source->image, vk::ImageAspectFlagBits::eColor); + UtilImageToImage(command, regions, cached->image, RENDER_COLOR_IMAGE_LAYOUT); } else { m_memory_tracker.ForEachUploadRange( info.address, info.size, false, [](uint64_t, uint64_t) noexcept {}, @@ -1935,12 +1934,13 @@ DepthStencilVulkanImage* TextureCache::FindDepthTarget(CommandBuffer* command, G } std::vector regions; regions.reserve(native_depth_source->image->layers * (has_stencil ? 2u : 1u)); - AppendLayerCopies(regions, native_depth_source->image, VK_IMAGE_ASPECT_DEPTH_BIT); + AppendLayerCopies(regions, native_depth_source->image, vk::ImageAspectFlagBits::eDepth); if (has_stencil) { - AppendLayerCopies(regions, native_depth_source->image, VK_IMAGE_ASPECT_STENCIL_BIT); + AppendLayerCopies(regions, native_depth_source->image, + vk::ImageAspectFlagBits::eStencil); } UtilImageToImage(command, regions, cached->image, - static_cast(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)); + vk::ImageLayout::eDepthStencilAttachmentOptimal); cached->gpu_modified = true; } else { if (sampled_depth_source != nullptr && @@ -1967,11 +1967,11 @@ DepthStencilVulkanImage* TextureCache::FindDepthTarget(CommandBuffer* command, G break; case DepthTransitionSource::Native: command->RetainResourceUntilFence(sampled_depth_source); - UtilCopyImageWithBuffer( - command, ctx, sampled_depth_source->image, VK_IMAGE_ASPECT_COLOR_BIT, - cached->image, VK_IMAGE_ASPECT_DEPTH_BIT, info.bytes_per_element, - static_cast( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)); + UtilCopyImageWithBuffer(command, ctx, sampled_depth_source->image, + vk::ImageAspectFlagBits::eColor, cached->image, + vk::ImageAspectFlagBits::eDepth, + info.bytes_per_element, + vk::ImageLayout::eDepthStencilAttachmentOptimal); break; } }); @@ -2269,18 +2269,17 @@ bool TextureCache::ClearImageFromBuffer(CommandBuffer* command, uint64_t vaddr, image_cpu_modified); } - auto* vk_buffer = command->GetPool()->buffers[command->GetIndex()]; + auto vk_buffer = command->GetPool()->buffers[command->GetIndex()]; if (aspect == ClearAspect::Color) { - VkClearColorValue clear {}; + vk::ClearColorValue clear {}; if (!DecodePackedColorClear(match->image->format, packed_clear, &clear)) { return false; } GraphicsRenderColorImageBarrier(vk_buffer, match->image, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - const VkImageSubresourceRange range {VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, - 0, match->image->layers}; - vkCmdClearColorImage(vk_buffer, match->image->image, match->image->layout, &clear, 1, - &range); + vk::ImageLayout::eTransferDstOptimal); + const vk::ImageSubresourceRange range {vk::ImageAspectFlagBits::eColor, 0, + VK_REMAINING_MIP_LEVELS, 0, match->image->layers}; + vk_buffer.clearColorImage(match->image->image, match->image->layout, &clear, 1, &range); GraphicsRenderColorImageBarrier(vk_buffer, match->image, RENDER_COLOR_IMAGE_LAYOUT); if (!match->gpu_modified) { m_memory_tracker.MarkRegionAsGpuModified(vaddr, size); @@ -2290,22 +2289,22 @@ bool TextureCache::ClearImageFromBuffer(CommandBuffer* command, uint64_t vaddr, return true; } - if (match->image->layout == VK_IMAGE_LAYOUT_UNDEFINED || - match->image->layout == VK_IMAGE_LAYOUT_PREINITIALIZED) { + if (match->image->layout == vk::ImageLayout::eUndefined || + match->image->layout == vk::ImageLayout::ePreinitialized) { EXIT("TextureCache: compute %s clear has invalid source layout %u\n", aspect == ClearAspect::Depth ? "depth" : "stencil", static_cast(match->image->layout)); } const auto old_layout = match->image->layout; GraphicsRenderDepthStencilImageBarrier(vk_buffer, match->image, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - const VkClearDepthStencilValue clear {depth_clear, stencil_clear}; - const auto clear_aspect = static_cast( - aspect == ClearAspect::Depth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_STENCIL_BIT); - const VkImageSubresourceRange range {clear_aspect, 0, VK_REMAINING_MIP_LEVELS, 0, - match->image->layers}; - vkCmdClearDepthStencilImage(vk_buffer, match->image->image, match->image->layout, &clear, 1, - &range); + vk::ImageLayout::eTransferDstOptimal); + const vk::ClearDepthStencilValue clear {depth_clear, stencil_clear}; + const auto clear_aspect = static_cast( + aspect == ClearAspect::Depth ? vk::ImageAspectFlagBits::eDepth + : vk::ImageAspectFlagBits::eStencil); + const vk::ImageSubresourceRange range {clear_aspect, 0, VK_REMAINING_MIP_LEVELS, 0, + match->image->layers}; + vk_buffer.clearDepthStencilImage(match->image->image, match->image->layout, &clear, 1, &range); GraphicsRenderDepthStencilImageBarrier(vk_buffer, match->image, old_layout); if (aspect == ClearAspect::Stencil) { match->stencil_initialized = true; @@ -2575,10 +2574,10 @@ void TextureCache::SynchronizeDepthImageToBufferLocked(CachedImage& cached, uint TileSizeAlign expected_depth {}; const bool d16 = info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm) && - info.format == VK_FORMAT_D16_UNORM && info.bytes_per_element == 2; + info.format == vk::Format::eD16Unorm && info.bytes_per_element == 2; const bool d32 = info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) && - info.format == VK_FORMAT_D32_SFLOAT && info.bytes_per_element == 4; + info.format == vk::Format::eD32Sfloat && info.bytes_per_element == 4; const bool layout = (d16 || d32) && TileGetDepthSize(info.width, info.height, 0, @@ -2604,7 +2603,7 @@ void TextureCache::SynchronizeDepthImageToBufferLocked(CachedImage& cached, uint m_buffer_transition_linear.resize(info.size); std::fill(m_buffer_transition_linear.begin(), m_buffer_transition_linear.end(), 0); const auto regions = MakeLayeredImageBufferCopies(1, info.size, info.pitch, info.width, - info.height, VK_IMAGE_ASPECT_DEPTH_BIT); + info.height, vk::ImageAspectFlagBits::eDepth); UtilFillBuffer(cached.ctx, m_buffer_transition_linear.data(), info.size, regions, cached.image, cached.image->layout); m_buffer_transition_guest.resize(info.size); diff --git a/src/graphics/host_gpu/renderer/textureCache.h b/src/graphics/host_gpu/renderer/textureCache.h index 803e00200..fc9e33c11 100644 --- a/src/graphics/host_gpu/renderer/textureCache.h +++ b/src/graphics/host_gpu/renderer/textureCache.h @@ -8,12 +8,12 @@ #include "graphics/host_gpu/renderer/imageInfo.h" #include "graphics/host_gpu/renderer/multiLevelPageTable.h" #include "graphics/host_gpu/renderer/tiler.h" +#include "graphics/host_gpu/vulkanCommon.h" #include #include #include #include -#include namespace Libs::Graphics { @@ -68,37 +68,35 @@ public: bool formatted_buffer_write = false); [[nodiscard]] RenderTextureVulkanImage* FindRenderTargetByRange(CommandBuffer* command, uint64_t vaddr, uint64_t size); - [[nodiscard]] VkImageView GetRenderTargetAttachmentView(GraphicContext* ctx, - RenderTextureVulkanImage* image, - VkFormat format, uint32_t level, - uint32_t base_layer, - uint32_t layer_count); - [[nodiscard]] VkImageView GetDepthTargetAttachmentView(GraphicContext* ctx, - DepthStencilVulkanImage* image, - uint32_t base_layer, - uint32_t layer_count); - [[nodiscard]] VkImageView GetDepthTargetSampledView(GraphicContext* ctx, - DepthStencilVulkanImage* image, - VkFormat view_format, uint32_t swizzle, - uint32_t base_level, uint32_t level_count, - VkImageViewType type, uint32_t base_layer, - uint32_t layer_count); - [[nodiscard]] VkImageView GetSampledColorView(GraphicContext* ctx, VulkanImage* image, - VkFormat view_format, uint32_t swizzle, - uint32_t base_level, uint32_t level_count, - VkImageViewType type, uint32_t base_layer, - uint32_t layer_count); - [[nodiscard]] VkImageView GetRenderTargetStorageView(GraphicContext* ctx, - RenderTextureVulkanImage* image, - VkFormat view_format, uint32_t base_level, - uint32_t level_count, VkImageViewType type, - uint32_t base_layer, uint32_t layer_count); - [[nodiscard]] VkImageView GetStorageTextureSampledView(GraphicContext* ctx, - StorageTextureVulkanImage* image, - const ImageInfo& info); - [[nodiscard]] VkImageView GetStorageTextureStorageView(GraphicContext* ctx, - StorageTextureVulkanImage* image, - uint32_t base_level); + [[nodiscard]] vk::ImageView GetRenderTargetAttachmentView(GraphicContext* ctx, + RenderTextureVulkanImage* image, + vk::Format format, uint32_t level, + uint32_t base_layer, + uint32_t layer_count); + [[nodiscard]] vk::ImageView GetDepthTargetAttachmentView(GraphicContext* ctx, + DepthStencilVulkanImage* image, + uint32_t base_layer, + uint32_t layer_count); + [[nodiscard]] vk::ImageView + GetDepthTargetSampledView(GraphicContext* ctx, DepthStencilVulkanImage* image, + vk::Format view_format, uint32_t swizzle, uint32_t base_level, + uint32_t level_count, vk::ImageViewType type, uint32_t base_layer, + uint32_t layer_count); + [[nodiscard]] vk::ImageView GetSampledColorView(GraphicContext* ctx, VulkanImage* image, + vk::Format view_format, uint32_t swizzle, + uint32_t base_level, uint32_t level_count, + vk::ImageViewType type, uint32_t base_layer, + uint32_t layer_count); + [[nodiscard]] vk::ImageView + GetRenderTargetStorageView(GraphicContext* ctx, RenderTextureVulkanImage* image, + vk::Format view_format, uint32_t base_level, uint32_t level_count, + vk::ImageViewType type, uint32_t base_layer, uint32_t layer_count); + [[nodiscard]] vk::ImageView GetStorageTextureSampledView(GraphicContext* ctx, + StorageTextureVulkanImage* image, + const ImageInfo& info); + [[nodiscard]] vk::ImageView GetStorageTextureStorageView(GraphicContext* ctx, + StorageTextureVulkanImage* image, + uint32_t base_level); [[nodiscard]] DepthStencilVulkanImage* FindDepthTargetByRange(CommandBuffer* command, uint64_t vaddr, uint64_t size, bool allow_containing_sampled = false); @@ -126,12 +124,12 @@ private: uint32_t clear_mask = 0; bool gpu_modified = false; }; - [[nodiscard]] VkImageView GetImageView(GraphicContext* ctx, VulkanImage* image, - const ImageViewInfo& info); - [[nodiscard]] bool HasMetaOverlapLocked(uint64_t vaddr, uint64_t size) const; - [[nodiscard]] CachedImage* FindGpuReadbackPageCandidateLocked(uint64_t vaddr, uint64_t size); - void RequireNoMetaOverlapLocked(uint64_t vaddr, uint64_t size) const; - void MarkSampledAliasesCpuDirtyLocked(uint64_t vaddr, uint64_t size); + [[nodiscard]] vk::ImageView GetImageView(GraphicContext* ctx, VulkanImage* image, + const ImageViewInfo& info); + [[nodiscard]] bool HasMetaOverlapLocked(uint64_t vaddr, uint64_t size) const; + [[nodiscard]] CachedImage* FindGpuReadbackPageCandidateLocked(uint64_t vaddr, uint64_t size); + void RequireNoMetaOverlapLocked(uint64_t vaddr, uint64_t size) const; + void MarkSampledAliasesCpuDirtyLocked(uint64_t vaddr, uint64_t size); void RetireSampledTargetAliases(GraphicContext* ctx, const ImageInfo& requested); void ResolveStorageImageOverlaps(GraphicContext* ctx, const ImageInfo& requested); void RetireStorageDepthAliasLocked(GraphicContext* ctx, const ImageInfo& requested); diff --git a/src/graphics/host_gpu/renderer/tiler.cpp b/src/graphics/host_gpu/renderer/tiler.cpp index 6bdeb1aaf..7afa38efd 100644 --- a/src/graphics/host_gpu/renderer/tiler.cpp +++ b/src/graphics/host_gpu/renderer/tiler.cpp @@ -45,11 +45,11 @@ static void UploadPromotedD16Depth(GraphicContext* ctx, DepthStencilVulkanImage* region.width = info.width; region.height = info.height; region.dst_layer = base_layer + layer; - region.aspect = VK_IMAGE_ASPECT_DEPTH_BIT; + region.aspect = vk::ImageAspectFlagBits::eDepth; regions.push_back(region); } UtilFillImage(ctx, image, host_linear.Data(), host_upload_size, regions, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + vk::ImageLayout::eDepthStencilAttachmentOptimal); } void Tiler::DetileImage(GraphicContext* ctx, GpuTextureVulkanImage* image, const ImageInfo& info, @@ -70,8 +70,7 @@ void Tiler::DetileImage(GraphicContext* ctx, GpuTextureVulkanImage* image, const ctx, image, reinterpret_cast(source.address), info.size, regions, layout, info.format, info.width, info.height, info.depth, info.levels, slice_layout, storage ? "StorageTextureCache" : "TextureCache", - static_cast(storage ? VK_IMAGE_LAYOUT_GENERAL - : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)); + storage ? vk::ImageLayout::eGeneral : vk::ImageLayout::eShaderReadOnlyOptimal); } void Tiler::DetileImage(GraphicContext* ctx, DepthStencilVulkanImage* image, @@ -82,10 +81,10 @@ void Tiler::DetileImage(GraphicContext* ctx, DepthStencilVulkanImage* image, } if (DepthAspectTransferBytes(info.format) != info.bytes_per_element) { switch (info.format) { - case VK_FORMAT_D24_UNORM_S8_UINT: + case vk::Format::eD24UnormS8Uint: UploadPromotedD16Depth(ctx, image, info, source, base_layer); return; - case VK_FORMAT_D32_SFLOAT_S8_UINT: + case vk::Format::eD32SfloatS8Uint: UploadPromotedD16Depth(ctx, image, info, source, base_layer); return; default: @@ -108,11 +107,11 @@ void Tiler::DetileImage(GraphicContext* ctx, DepthStencilVulkanImage* image, region.width = info.width; region.height = info.height; region.dst_layer = base_layer + layer; - region.aspect = VK_IMAGE_ASPECT_DEPTH_BIT; + region.aspect = vk::ImageAspectFlagBits::eDepth; regions.push_back(region); } UtilFillImage(ctx, image, linear.Data(), info.size, regions, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + vk::ImageLayout::eDepthStencilAttachmentOptimal); } void Tiler::DetileStencil(GraphicContext* ctx, DepthStencilVulkanImage* image, @@ -139,11 +138,11 @@ void Tiler::DetileStencil(GraphicContext* ctx, DepthStencilVulkanImage* image, region.width = info.width; region.height = info.height; region.dst_layer = base_layer + layer; - region.aspect = VK_IMAGE_ASPECT_STENCIL_BIT; + region.aspect = vk::ImageAspectFlagBits::eStencil; regions.push_back(region); } UtilFillImage(ctx, image, linear.Data(), info.stencil_size, regions, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + vk::ImageLayout::eDepthStencilAttachmentOptimal); } void Tiler::TileImage(void* dst, const void* src, const RenderTargetInfo& info) const { diff --git a/src/graphics/host_gpu/utils.cpp b/src/graphics/host_gpu/utils.cpp index c249f277c..7cc91c950 100644 --- a/src/graphics/host_gpu/utils.cpp +++ b/src/graphics/host_gpu/utils.cpp @@ -8,13 +8,13 @@ #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/vma.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/window.h" #include #include #include #include -#include namespace Libs::Graphics { @@ -24,8 +24,8 @@ static uint64_t g_scratch_buffer_capacity = 0; std::vector MakeLayeredImageBufferCopies(uint32_t layers, uint64_t slice_size, uint32_t pitch, uint32_t width, - uint32_t height, - VkImageAspectFlags aspect) { + uint32_t height, + vk::ImageAspectFlags aspect) { if (layers == 0 || slice_size == 0 || slice_size > UINT32_MAX / layers || pitch < width || width == 0 || height == 0) { EXIT("invalid layered image-buffer copy layout\n"); @@ -104,17 +104,17 @@ void VulkanDeviceWaitIdle(GraphicContext* ctx) { } } - auto result = vkDeviceWaitIdle(ctx->device); + auto result = ctx->device.waitIdle(); for (int i = locked_num - 1; i >= 0; i--) { locked[i]->Unlock(); } - if (result != VK_SUCCESS) { - LOGF("vkDeviceWaitIdle failed: %s (%d)\n", string_VkResult(result), + if (result != vk::Result::eSuccess) { + LOGF("vkDeviceWaitIdle failed: %s (%d)\n", VulkanToString(result).c_str(), static_cast(result)); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } void UtilResetImageViews(VulkanImage* image) { @@ -124,10 +124,10 @@ void UtilResetImageViews(VulkanImage* image) { } void UtilCreateImageView(GraphicContext* ctx, VulkanImage* image, int view_index, - VkImageViewType view_type, VkImageAspectFlags aspect_mask, - VkComponentMapping components, uint32_t base_array_layer, + vk::ImageViewType view_type, vk::ImageAspectFlags aspect_mask, + vk::ComponentMapping components, uint32_t base_array_layer, uint32_t base_mip_level, uint32_t layer_count, uint32_t level_count, - VkFormat view_format, VkImageUsageFlags view_usage) { + vk::Format view_format, vk::ImageUsageFlags view_usage) { if (view_index < 0 || view_index >= VulkanImage::VIEW_MAX || image->image == nullptr || image->image_view[view_index] != nullptr) { EXIT("invalid image-view creation target: image=%p index=%d current_view=%d\n", @@ -136,18 +136,18 @@ void UtilCreateImageView(GraphicContext* ctx, VulkanImage* image, int view_index image->image_view[view_index] != nullptr); } - VkImageViewUsageCreateInfo usage_info {}; - usage_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO; + vk::ImageViewUsageCreateInfo usage_info {}; + usage_info.sType = vk::StructureType::eImageViewUsageCreateInfo; usage_info.pNext = nullptr; usage_info.usage = view_usage; - VkImageViewCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - create_info.pNext = (view_usage != 0 ? &usage_info : nullptr); - create_info.flags = 0; + vk::ImageViewCreateInfo create_info {}; + create_info.sType = vk::StructureType::eImageViewCreateInfo; + create_info.pNext = (view_usage ? &usage_info : nullptr); + create_info.flags = {}; create_info.image = image->image; create_info.viewType = view_type; - create_info.format = (view_format != VK_FORMAT_UNDEFINED ? view_format : image->format); + create_info.format = (view_format != vk::Format::eUndefined ? view_format : image->format); create_info.components = components; create_info.subresourceRange.aspectMask = aspect_mask; create_info.subresourceRange.baseArrayLayer = base_array_layer; @@ -156,17 +156,17 @@ void UtilCreateImageView(GraphicContext* ctx, VulkanImage* image, int view_index create_info.subresourceRange.levelCount = level_count; const auto result = - vkCreateImageView(ctx->device, &create_info, nullptr, &image->image_view[view_index]); - if (result != VK_SUCCESS || image->image_view[view_index] == nullptr) { + ctx->device.createImageView(&create_info, nullptr, &image->image_view[view_index]); + if (result != vk::Result::eSuccess || image->image_view[view_index] == nullptr) { EXIT("failed to create image view: result=%d image_format=%d view_format=%d index=%d\n", static_cast(result), static_cast(image->format), static_cast(create_info.format), view_index); } } -static void SetImageLayout(VkCommandBuffer buffer, VulkanImage* dst_image, uint32_t base_level, - uint32_t levels, VkImageAspectFlags aspect_mask, - VkImageLayout old_image_layout, VkImageLayout new_image_layout); +static void SetImageLayout(vk::CommandBuffer buffer, VulkanImage* dst_image, uint32_t base_level, + uint32_t levels, vk::ImageAspectFlags aspect_mask, + vk::ImageLayout old_image_layout, vk::ImageLayout new_image_layout); template static void ExecuteImmediateUtilCommands(const Recorder& recorder) { @@ -180,16 +180,16 @@ static void ExecuteImmediateUtilCommands(const Recorder& recorder) { command.WaitForFence(); } -[[nodiscard]] static bool IsSingleImageAspect(VkImageAspectFlags aspect) { - return aspect == VK_IMAGE_ASPECT_COLOR_BIT || aspect == VK_IMAGE_ASPECT_DEPTH_BIT || - aspect == VK_IMAGE_ASPECT_STENCIL_BIT; +[[nodiscard]] static bool IsSingleImageAspect(vk::ImageAspectFlags aspect) { + return aspect == vk::ImageAspectFlagBits::eColor || aspect == vk::ImageAspectFlagBits::eDepth || + aspect == vk::ImageAspectFlagBits::eStencil; } -[[nodiscard]] static VkBufferImageCopy -MakeBufferImageCopy(VkDeviceSize buffer_offset, uint32_t buffer_pitch, VkImageAspectFlags aspect, - uint32_t mip_level, uint32_t array_layer, VkOffset3D image_offset, - VkExtent3D image_extent) { - VkBufferImageCopy copy {}; +[[nodiscard]] static vk::BufferImageCopy +MakeBufferImageCopy(vk::DeviceSize buffer_offset, uint32_t buffer_pitch, + vk::ImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer, + vk::Offset3D image_offset, vk::Extent3D image_extent) { + vk::BufferImageCopy copy {}; copy.bufferOffset = buffer_offset; copy.bufferRowLength = buffer_pitch != image_extent.width ? buffer_pitch : 0; copy.bufferImageHeight = 0; @@ -202,12 +202,13 @@ MakeBufferImageCopy(VkDeviceSize buffer_offset, uint32_t buffer_pitch, VkImageAs return copy; } -static void SetBufferMemoryBarrier(VkCommandBuffer command, VkBuffer buffer, VkDeviceSize offset, - VkDeviceSize size, VkAccessFlags src_access, - VkAccessFlags dst_access, VkPipelineStageFlags src_stage, - VkPipelineStageFlags dst_stage) { - VkBufferMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; +static void SetBufferMemoryBarrier(vk::CommandBuffer command, vk::Buffer buffer, + vk::DeviceSize offset, vk::DeviceSize size, + vk::AccessFlags src_access, vk::AccessFlags dst_access, + vk::PipelineStageFlags src_stage, + vk::PipelineStageFlags dst_stage) { + vk::BufferMemoryBarrier barrier {}; + barrier.sType = vk::StructureType::eBufferMemoryBarrier; barrier.srcAccessMask = src_access; barrier.dstAccessMask = dst_access; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; @@ -215,59 +216,64 @@ static void SetBufferMemoryBarrier(VkCommandBuffer command, VkBuffer buffer, VkD barrier.buffer = buffer; barrier.offset = offset; barrier.size = size; - vkCmdPipelineBarrier(command, src_stage, dst_stage, 0, 0, nullptr, 1, &barrier, 0, nullptr); + command.pipelineBarrier(src_stage, dst_stage, vk::DependencyFlags {}, 0, nullptr, 1, &barrier, + 0, nullptr); } -[[nodiscard]] static VkImageAspectFlags GetDepthStencilAspects(VkFormat format) { +[[nodiscard]] static vk::ImageAspectFlags GetDepthStencilAspects(vk::Format format) { switch (format) { - case VK_FORMAT_D16_UNORM: - case VK_FORMAT_D32_SFLOAT: return VK_IMAGE_ASPECT_DEPTH_BIT; - case VK_FORMAT_D16_UNORM_S8_UINT: - case VK_FORMAT_D24_UNORM_S8_UINT: - case VK_FORMAT_D32_SFLOAT_S8_UINT: - return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + case vk::Format::eD16Unorm: + case vk::Format::eD32Sfloat: return vk::ImageAspectFlagBits::eDepth; + case vk::Format::eD16UnormS8Uint: + case vk::Format::eD24UnormS8Uint: + case vk::Format::eD32SfloatS8Uint: + return vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil; default: EXIT("unsupported depth/stencil image format: %d\n", static_cast(format)); } } -[[nodiscard]] static VkImageAspectFlags GetTransferAspects(const VulkanImage& image, - VkImageAspectFlags copy_aspect) { - switch (copy_aspect) { - case VK_IMAGE_ASPECT_COLOR_BIT: return VK_IMAGE_ASPECT_COLOR_BIT; - case VK_IMAGE_ASPECT_DEPTH_BIT: - case VK_IMAGE_ASPECT_STENCIL_BIT: { - const auto aspects = GetDepthStencilAspects(image.format); - if ((copy_aspect & aspects) == 0) { - EXIT("image transfer aspect is unavailable: format=%d copy=0x%x available=0x%x\n", - static_cast(image.format), copy_aspect, aspects); - } - return aspects; - } - default: EXIT("unsupported image transfer aspect: 0x%x\n", copy_aspect); +[[nodiscard]] static vk::ImageAspectFlags GetTransferAspects(const VulkanImage& image, + vk::ImageAspectFlags copy_aspect) { + if (copy_aspect == vk::ImageAspectFlagBits::eColor) { + return vk::ImageAspectFlagBits::eColor; } + if (copy_aspect == vk::ImageAspectFlagBits::eDepth || + copy_aspect == vk::ImageAspectFlagBits::eStencil) { + const auto aspects = GetDepthStencilAspects(image.format); + if (!(copy_aspect & aspects)) { + EXIT("image transfer aspect is unavailable: format=%d copy=0x%x available=0x%x\n", + static_cast(image.format), + static_cast(copy_aspect), + static_cast(aspects)); + } + return aspects; + } + EXIT("unsupported image transfer aspect: 0x%x\n", + static_cast(copy_aspect)); } static void RecordBufferToImageCopy(CommandBuffer& command, VulkanBuffer& src_buffer, - VulkanImage& dst_image, - std::span regions, - VkImageAspectFlags transition_aspects, - VkImageLayout initial_layout, VkImageLayout final_layout) { - auto* vk_command = command.GetPool()->buffers[command.GetIndex()]; + VulkanImage& dst_image, + std::span regions, + vk::ImageAspectFlags transition_aspects, + vk::ImageLayout initial_layout, vk::ImageLayout final_layout) { + auto vk_command = command.GetPool()->buffers[command.GetIndex()]; SetBufferMemoryBarrier(vk_command, src_buffer.buffer, 0, VK_WHOLE_SIZE, - VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + vk::AccessFlagBits::eMemoryWrite, vk::AccessFlagBits::eTransferRead, + vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer); SetImageLayout(vk_command, &dst_image, 0, VK_REMAINING_MIP_LEVELS, transition_aspects, - initial_layout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - vkCmdCopyBufferToImage(vk_command, src_buffer.buffer, dst_image.image, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - static_cast(regions.size()), regions.data()); + initial_layout, vk::ImageLayout::eTransferDstOptimal); + vk_command.copyBufferToImage(src_buffer.buffer, dst_image.image, + vk::ImageLayout::eTransferDstOptimal, + static_cast(regions.size()), regions.data()); SetImageLayout(vk_command, &dst_image, 0, VK_REMAINING_MIP_LEVELS, transition_aspects, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, final_layout); + vk::ImageLayout::eTransferDstOptimal, final_layout); } -[[nodiscard]] static std::span +[[nodiscard]] static std::span ConvertBufferImageCopies(std::span regions) { - static thread_local std::vector vk_regions; + static thread_local std::vector vk_regions; vk_regions.resize(regions.size()); for (size_t i = 0; i < regions.size(); i++) { @@ -279,9 +285,9 @@ ConvertBufferImageCopies(std::span regions) { return vk_regions; } -[[nodiscard]] static std::span +[[nodiscard]] static std::span ConvertImageBufferCopies(std::span regions) { - static thread_local std::vector vk_regions; + static thread_local std::vector vk_regions; vk_regions.resize(regions.size()); for (size_t i = 0; i < regions.size(); i++) { const auto& r = regions[i]; @@ -294,30 +300,32 @@ ConvertImageBufferCopies(std::span regions) { static void RecordImageToBuffer(CommandBuffer& command, VulkanImage& src_image, VulkanBuffer& dst_buffer, std::span regions, - VkImageLayout final_layout) { - auto* vk_command = command.GetPool()->buffers[command.GetIndex()]; - VkImageAspectFlags aspects = 0; + vk::ImageLayout final_layout) { + auto vk_command = command.GetPool()->buffers[command.GetIndex()]; + vk::ImageAspectFlags aspects = {}; for (const auto& region: regions) { aspects |= GetTransferAspects(src_image, region.aspect); } SetImageLayout(vk_command, &src_image, 0, VK_REMAINING_MIP_LEVELS, aspects, src_image.layout, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + vk::ImageLayout::eTransferSrcOptimal); SetBufferMemoryBarrier(vk_command, dst_buffer.buffer, 0, VK_WHOLE_SIZE, - VK_ACCESS_MEMORY_READ_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + vk::AccessFlagBits::eMemoryRead, vk::AccessFlagBits::eTransferWrite, + vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer); const auto copies = ConvertImageBufferCopies(regions); - vkCmdCopyImageToBuffer(vk_command, src_image.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - dst_buffer.buffer, static_cast(copies.size()), copies.data()); + vk_command.copyImageToBuffer(src_image.image, vk::ImageLayout::eTransferSrcOptimal, + dst_buffer.buffer, static_cast(copies.size()), + copies.data()); SetBufferMemoryBarrier(vk_command, dst_buffer.buffer, 0, VK_WHOLE_SIZE, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT); + vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eHostRead, + vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eHost); SetImageLayout(vk_command, &src_image, 0, VK_REMAINING_MIP_LEVELS, aspects, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, final_layout); + vk::ImageLayout::eTransferSrcOptimal, final_layout); } static void RecordImageToBuffer(CommandBuffer& command, VulkanImage& src_image, VulkanBuffer& dst_buffer, uint32_t dst_pitch, - VkImageLayout final_layout, VkImageAspectFlags aspect) { + vk::ImageLayout final_layout, vk::ImageAspectFlags aspect) { const ImageBufferCopy region { 0, dst_pitch, 0, src_image.extent.width, src_image.extent.height, 0, 0, 0, 0, 0, aspect}; RecordImageToBuffer(command, src_image, dst_buffer, @@ -332,62 +340,67 @@ public: void UploadToBuffer(GraphicContext* ctx, VulkanBuffer* dst_buffer, const void* src_data, uint64_t size, uint64_t dst_offset) { - RecordUpload(ctx, src_data, size, [&](CommandBuffer*, VkCommandBuffer vk_command) { - SetBufferMemoryBarrier(vk_command, m_buffer.buffer, 0, size, VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT); - SetBufferMemoryBarrier(vk_command, dst_buffer->buffer, dst_offset, size, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT); - const VkBufferCopy copy_region {.srcOffset = 0, .dstOffset = dst_offset, .size = size}; - vkCmdCopyBuffer(vk_command, m_buffer.buffer, dst_buffer->buffer, 1, ©_region); + RecordUpload(ctx, src_data, size, [&](CommandBuffer*, vk::CommandBuffer vk_command) { SetBufferMemoryBarrier( - vk_command, dst_buffer->buffer, dst_offset, size, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_INDEX_READ_BIT | - VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | - VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + vk_command, m_buffer.buffer, 0, size, vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eTransferRead, vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer); + SetBufferMemoryBarrier( + vk_command, dst_buffer->buffer, dst_offset, size, + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eTransferWrite, vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer); + const vk::BufferCopy copy_region { + .srcOffset = 0, .dstOffset = dst_offset, .size = size}; + vk_command.copyBuffer(m_buffer.buffer, dst_buffer->buffer, 1, ©_region); + SetBufferMemoryBarrier( + vk_command, dst_buffer->buffer, dst_offset, size, + vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eVertexAttributeRead | vk::AccessFlagBits::eIndexRead | + vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eVertexInput | vk::PipelineStageFlagBits::eVertexShader | + vk::PipelineStageFlagBits::eFragmentShader | + vk::PipelineStageFlagBits::eComputeShader); }); } void UploadToImage(GraphicContext* ctx, VulkanImage* image, const void* src_data, uint64_t size, - uint32_t src_pitch, VkImageAspectFlags copy_aspect, - VkImageLayout initial_layout, VkImageLayout final_layout) { + uint32_t src_pitch, vk::ImageAspectFlags copy_aspect, + vk::ImageLayout initial_layout, vk::ImageLayout final_layout) { const auto transition_aspects = GetTransferAspects(*image, copy_aspect); - RecordUpload(ctx, src_data, size, [&](CommandBuffer* command, VkCommandBuffer) { + RecordUpload(ctx, src_data, size, [&](CommandBuffer* command, vk::CommandBuffer) { const auto region = MakeBufferImageCopy(0, src_pitch, copy_aspect, 0, 0, {0, 0, 0}, {image->extent.width, image->extent.height, 1}); RecordBufferToImageCopy(*command, m_buffer, *image, - std::span(®ion, 1), + std::span(®ion, 1), transition_aspects, initial_layout, final_layout); }); } void UploadToImage(GraphicContext* ctx, VulkanImage* dst_image, const void* src_data, uint64_t size, std::span regions, - uint64_t dst_layout) { - RecordUpload(ctx, src_data, size, [&](CommandBuffer* command, VkCommandBuffer) { - VkImageAspectFlags transition_aspects = 0; + vk::ImageLayout dst_layout) { + RecordUpload(ctx, src_data, size, [&](CommandBuffer* command, vk::CommandBuffer) { + vk::ImageAspectFlags transition_aspects = {}; for (const auto& region: regions) { transition_aspects |= GetTransferAspects(*dst_image, region.aspect); } RecordBufferToImageCopy(*command, m_buffer, *dst_image, ConvertBufferImageCopies(regions), transition_aspects, - dst_image->layout, static_cast(dst_layout)); + dst_image->layout, dst_layout); }); } void DownloadFromImage(GraphicContext* ctx, void* dst_data, uint64_t size, uint32_t dst_pitch, - VulkanImage* src_image, uint64_t src_layout, VkImageAspectFlags aspect) { + VulkanImage* src_image, vk::ImageLayout src_layout, + vk::ImageAspectFlags aspect) { Common::LockGuard lock(m_mutex); - EnsureBuffer(ctx, size, VK_BUFFER_USAGE_TRANSFER_DST_BIT); + EnsureBuffer(ctx, size, vk::BufferUsageFlagBits::eTransferDst); - ExecuteImmediateUtilCommands([&](CommandBuffer* command, VkCommandBuffer) { - RecordImageToBuffer(*command, *src_image, m_buffer, dst_pitch, - static_cast(src_layout), aspect); + ExecuteImmediateUtilCommands([&](CommandBuffer* command, vk::CommandBuffer) { + RecordImageToBuffer(*command, *src_image, m_buffer, dst_pitch, src_layout, aspect); }); std::memcpy(dst_data, m_mapped_data, size); @@ -395,12 +408,11 @@ public: void DownloadFromImage(GraphicContext* ctx, void* dst_data, uint64_t size, std::span regions, VulkanImage* src_image, - uint64_t src_layout) { + vk::ImageLayout src_layout) { Common::LockGuard lock(m_mutex); - EnsureBuffer(ctx, size, VK_BUFFER_USAGE_TRANSFER_DST_BIT); - ExecuteImmediateUtilCommands([&](CommandBuffer* command, VkCommandBuffer) { - RecordImageToBuffer(*command, *src_image, m_buffer, regions, - static_cast(src_layout)); + EnsureBuffer(ctx, size, vk::BufferUsageFlagBits::eTransferDst); + ExecuteImmediateUtilCommands([&](CommandBuffer* command, vk::CommandBuffer) { + RecordImageToBuffer(*command, *src_image, m_buffer, regions, src_layout); }); std::memcpy(dst_data, m_mapped_data, size); } @@ -421,7 +433,7 @@ private: void RecordUpload(GraphicContext* ctx, const void* src_data, uint64_t size, const Recorder& recorder) { Common::LockGuard lock(m_mutex); - CopyFromHost(ctx, src_data, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); + CopyFromHost(ctx, src_data, size, vk::BufferUsageFlagBits::eTransferSrc); if constexpr (WaitIdle) { VulkanDeviceWaitIdle(ctx); } @@ -429,13 +441,13 @@ private: } void CopyFromHost(GraphicContext* ctx, const void* src_data, uint64_t size, - VkBufferUsageFlags usage) { + vk::BufferUsageFlags usage) { EnsureBuffer(ctx, size, usage); std::memcpy(m_mapped_data, src_data, size); } - void EnsureBuffer(GraphicContext* ctx, uint64_t size, VkBufferUsageFlags usage) { + void EnsureBuffer(GraphicContext* ctx, uint64_t size, vk::BufferUsageFlags usage) { if (m_capacity < size || m_buffer.usage != usage) { if (m_buffer.buffer != nullptr) { VulkanUnmapMemory(ctx, &m_buffer.memory); @@ -443,9 +455,9 @@ private: VulkanDeleteBuffer(ctx, &m_buffer); } - m_buffer.usage = usage; - m_buffer.memory.property = - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + m_buffer.usage = usage; + m_buffer.memory.property = vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent; VulkanCreateBuffer(ctx, size, &m_buffer); m_capacity = size; @@ -467,45 +479,45 @@ static ReusableStagingBuffer g_readback_staging_buffer; static Common::Mutex g_compressed_image_copy_mutex; static VulkanBuffer g_compressed_image_copy_buffer; -bool UtilIsBcFormat(VkFormat format) { - return format == VK_FORMAT_BC1_RGB_UNORM_BLOCK || format == VK_FORMAT_BC1_RGB_SRGB_BLOCK || - format == VK_FORMAT_BC1_RGBA_UNORM_BLOCK || format == VK_FORMAT_BC1_RGBA_SRGB_BLOCK || - format == VK_FORMAT_BC2_UNORM_BLOCK || format == VK_FORMAT_BC2_SRGB_BLOCK || - format == VK_FORMAT_BC3_UNORM_BLOCK || format == VK_FORMAT_BC3_SRGB_BLOCK || - format == VK_FORMAT_BC4_UNORM_BLOCK || format == VK_FORMAT_BC4_SNORM_BLOCK || - format == VK_FORMAT_BC5_UNORM_BLOCK || format == VK_FORMAT_BC5_SNORM_BLOCK || - format == VK_FORMAT_BC6H_UFLOAT_BLOCK || format == VK_FORMAT_BC6H_SFLOAT_BLOCK || - format == VK_FORMAT_BC7_UNORM_BLOCK || format == VK_FORMAT_BC7_SRGB_BLOCK; +bool UtilIsBcFormat(vk::Format format) { + return format == vk::Format::eBc1RgbUnormBlock || format == vk::Format::eBc1RgbSrgbBlock || + format == vk::Format::eBc1RgbaUnormBlock || format == vk::Format::eBc1RgbaSrgbBlock || + format == vk::Format::eBc2UnormBlock || format == vk::Format::eBc2SrgbBlock || + format == vk::Format::eBc3UnormBlock || format == vk::Format::eBc3SrgbBlock || + format == vk::Format::eBc4UnormBlock || format == vk::Format::eBc4SnormBlock || + format == vk::Format::eBc5UnormBlock || format == vk::Format::eBc5SnormBlock || + format == vk::Format::eBc6HUfloatBlock || format == vk::Format::eBc6HSfloatBlock || + format == vk::Format::eBc7UnormBlock || format == vk::Format::eBc7SrgbBlock; } -uint32_t UtilGetBcBlockSize(VkFormat format) { +uint32_t UtilGetBcBlockSize(vk::Format format) { switch (format) { - case VK_FORMAT_BC1_RGB_UNORM_BLOCK: - case VK_FORMAT_BC1_RGB_SRGB_BLOCK: - case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: - case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: - case VK_FORMAT_BC4_UNORM_BLOCK: - case VK_FORMAT_BC4_SNORM_BLOCK: return 8; - case VK_FORMAT_BC2_UNORM_BLOCK: - case VK_FORMAT_BC2_SRGB_BLOCK: - case VK_FORMAT_BC3_UNORM_BLOCK: - case VK_FORMAT_BC3_SRGB_BLOCK: - case VK_FORMAT_BC5_UNORM_BLOCK: - case VK_FORMAT_BC5_SNORM_BLOCK: - case VK_FORMAT_BC6H_UFLOAT_BLOCK: - case VK_FORMAT_BC6H_SFLOAT_BLOCK: - case VK_FORMAT_BC7_UNORM_BLOCK: - case VK_FORMAT_BC7_SRGB_BLOCK: return 16; + case vk::Format::eBc1RgbUnormBlock: + case vk::Format::eBc1RgbSrgbBlock: + case vk::Format::eBc1RgbaUnormBlock: + case vk::Format::eBc1RgbaSrgbBlock: + case vk::Format::eBc4UnormBlock: + case vk::Format::eBc4SnormBlock: return 8; + case vk::Format::eBc2UnormBlock: + case vk::Format::eBc2SrgbBlock: + case vk::Format::eBc3UnormBlock: + case vk::Format::eBc3SrgbBlock: + case vk::Format::eBc5UnormBlock: + case vk::Format::eBc5SnormBlock: + case vk::Format::eBc6HUfloatBlock: + case vk::Format::eBc6HSfloatBlock: + case vk::Format::eBc7UnormBlock: + case vk::Format::eBc7SrgbBlock: return 16; default: return 0; } } -static uint32_t GetFormatTexelSize(VkFormat format) { +static uint32_t GetFormatTexelSize(vk::Format format) { switch (format) { - case VK_FORMAT_R32G32_SFLOAT: - case VK_FORMAT_R32G32_UINT: return 8; - case VK_FORMAT_R32G32B32A32_SFLOAT: - case VK_FORMAT_R32G32B32A32_UINT: return 16; + case vk::Format::eR32G32Sfloat: + case vk::Format::eR32G32Uint: return 8; + case vk::Format::eR32G32B32A32Sfloat: + case vk::Format::eR32G32B32A32Uint: return 16; default: return 0; } } @@ -520,8 +532,8 @@ static VulkanBuffer* GetCompressedImageCopyBuffer(GraphicContext* ctx, uint64_t if (g_compressed_image_copy_buffer.buffer == nullptr) { g_compressed_image_copy_buffer.usage = - VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; - g_compressed_image_copy_buffer.memory.property = 0; + vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst; + g_compressed_image_copy_buffer.memory.property = {}; VulkanCreateBuffer(ctx, buffer_size, &g_compressed_image_copy_buffer); } @@ -539,20 +551,20 @@ static ReusableStagingBuffer* GetStagingBuffer(StagingBufferType type) { return nullptr; } -static void SetImageLayout(VkCommandBuffer buffer, VulkanImage* dst_image, uint32_t base_level, - uint32_t levels, VkImageAspectFlags aspect_mask, - VkImageLayout old_image_layout, VkImageLayout new_image_layout) { - if ((old_image_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && - new_image_layout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) || - (old_image_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && - new_image_layout == VK_IMAGE_LAYOUT_GENERAL) || - (old_image_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && - new_image_layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)) { +static void SetImageLayout(vk::CommandBuffer buffer, VulkanImage* dst_image, uint32_t base_level, + uint32_t levels, vk::ImageAspectFlags aspect_mask, + vk::ImageLayout old_image_layout, vk::ImageLayout new_image_layout) { + if ((old_image_layout == vk::ImageLayout::eTransferDstOptimal && + new_image_layout == vk::ImageLayout::eTransferSrcOptimal) || + (old_image_layout == vk::ImageLayout::eTransferDstOptimal && + new_image_layout == vk::ImageLayout::eGeneral) || + (old_image_layout == vk::ImageLayout::eTransferDstOptimal && + new_image_layout == vk::ImageLayout::ePresentSrcKHR)) { static std::atomic log_count {0}; if (log_count.fetch_add(1, std::memory_order_relaxed) < 64) { LOGF("set_image_layout: image=%p type=%d tracked=%d requested=%d->%d base=%u " "levels=%u\n", - reinterpret_cast(dst_image->image), static_cast(dst_image->type), + VulkanHandleToPointer(dst_image->image), static_cast(dst_image->type), static_cast(dst_image->layout), static_cast(old_image_layout), static_cast(new_image_layout), base_level, levels); } @@ -563,11 +575,11 @@ static void SetImageLayout(VkCommandBuffer buffer, VulkanImage* dst_image, uint3 return; } - VkImageMemoryBarrier image_memory_barrier {}; - image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + vk::ImageMemoryBarrier image_memory_barrier {}; + image_memory_barrier.sType = vk::StructureType::eImageMemoryBarrier; image_memory_barrier.pNext = nullptr; - image_memory_barrier.srcAccessMask = 0; - image_memory_barrier.dstAccessMask = 0; + image_memory_barrier.srcAccessMask = {}; + image_memory_barrier.dstAccessMask = {}; image_memory_barrier.oldLayout = old_image_layout; image_memory_barrier.newLayout = new_image_layout; image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; @@ -580,78 +592,80 @@ static void SetImageLayout(VkCommandBuffer buffer, VulkanImage* dst_image, uint3 image_memory_barrier.subresourceRange.layerCount = dst_image->layers; switch (old_image_layout) { - case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: - image_memory_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + case vk::ImageLayout::eColorAttachmentOptimal: + image_memory_barrier.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite; break; - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: - image_memory_barrier.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + case vk::ImageLayout::eDepthStencilAttachmentOptimal: + image_memory_barrier.srcAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentRead | + vk::AccessFlagBits::eDepthStencilAttachmentWrite; break; - case VK_IMAGE_LAYOUT_GENERAL: + case vk::ImageLayout::eGeneral: image_memory_barrier.srcAccessMask = - VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT | - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | - VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; + vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite | + vk::AccessFlagBits::eColorAttachmentRead | + vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eTransferRead | + vk::AccessFlagBits::eTransferWrite; break; - case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: - image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + case vk::ImageLayout::eTransferDstOptimal: + image_memory_barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite; break; - case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + case vk::ImageLayout::eTransferSrcOptimal: + image_memory_barrier.srcAccessMask = vk::AccessFlagBits::eTransferRead; break; - case VK_IMAGE_LAYOUT_PREINITIALIZED: - image_memory_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; + case vk::ImageLayout::ePreinitialized: + image_memory_barrier.srcAccessMask = vk::AccessFlagBits::eHostWrite; break; default: break; } switch (new_image_layout) { - case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: - image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + case vk::ImageLayout::eTransferDstOptimal: + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eTransferWrite; break; - case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + case vk::ImageLayout::eTransferSrcOptimal: + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eTransferRead; break; - case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: + case vk::ImageLayout::eShaderReadOnlyOptimal: image_memory_barrier.srcAccessMask |= - VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT; - image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + vk::AccessFlagBits::eTransferWrite | vk::AccessFlagBits::eHostWrite; + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead; break; - case VK_IMAGE_LAYOUT_GENERAL: + case vk::ImageLayout::eGeneral: image_memory_barrier.dstAccessMask = - VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite; break; - case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: - image_memory_barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + case vk::ImageLayout::eColorAttachmentOptimal: + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite; break; - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: - image_memory_barrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + case vk::ImageLayout::eDepthStencilAttachmentOptimal: + image_memory_barrier.dstAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentRead | + vk::AccessFlagBits::eDepthStencilAttachmentWrite; break; default: break; } - auto src_stages = static_cast( - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT | - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | - VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | - VK_PIPELINE_STAGE_HOST_BIT); - auto dest_stages = static_cast( - VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | - VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | - VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT); + auto src_stages = static_cast( + vk::PipelineStageFlagBits::eTopOfPipe | vk::PipelineStageFlagBits::eTransfer | + vk::PipelineStageFlagBits::eColorAttachmentOutput | + vk::PipelineStageFlagBits::eComputeShader | vk::PipelineStageFlagBits::eEarlyFragmentTests | + vk::PipelineStageFlagBits::eLateFragmentTests | vk::PipelineStageFlagBits::eHost); + auto dest_stages = static_cast( + vk::PipelineStageFlagBits::eTransfer | vk::PipelineStageFlagBits::eVertexShader | + vk::PipelineStageFlagBits::eFragmentShader | vk::PipelineStageFlagBits::eComputeShader | + vk::PipelineStageFlagBits::eColorAttachmentOutput | + vk::PipelineStageFlagBits::eEarlyFragmentTests | + vk::PipelineStageFlagBits::eLateFragmentTests); - vkCmdPipelineBarrier(buffer, src_stages, dest_stages, 0, 0, nullptr, 0, nullptr, 1, - &image_memory_barrier); + buffer.pipelineBarrier(src_stages, dest_stages, vk::DependencyFlags {}, 0, nullptr, 0, nullptr, + 1, &image_memory_barrier); dst_image->layout = new_image_layout; } -static bool CopyBlockImageToCompressedImage(VkCommandBuffer vk_buffer, const ImageImageCopy& r, +static bool CopyBlockImageToCompressedImage(vk::CommandBuffer vk_buffer, const ImageImageCopy& r, VulkanImage* dst_image) { - if (r.src_aspect != VK_IMAGE_ASPECT_COLOR_BIT || r.dst_aspect != VK_IMAGE_ASPECT_COLOR_BIT || - !UtilIsBcFormat(dst_image->format)) { + if (r.src_aspect != vk::ImageAspectFlagBits::eColor || + r.dst_aspect != vk::ImageAspectFlagBits::eColor || !UtilIsBcFormat(dst_image->format)) { return false; } @@ -672,41 +686,43 @@ static bool CopyBlockImageToCompressedImage(VkCommandBuffer vk_buffer, const Ima block_height * dst_block_size); const auto src_region = - MakeBufferImageCopy(0, 0, VK_IMAGE_ASPECT_COLOR_BIT, r.src_level, r.src_layer, + MakeBufferImageCopy(0, 0, vk::ImageAspectFlagBits::eColor, r.src_level, r.src_layer, {r.src_x, r.src_y, 0}, {block_width, block_height, 1}); auto src_layout = r.src_image->layout; - SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, VK_IMAGE_ASPECT_COLOR_BIT, src_layout, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, vk::ImageAspectFlagBits::eColor, + src_layout, vk::ImageLayout::eTransferSrcOptimal); SetBufferMemoryBarrier(vk_buffer, copy_buffer->buffer, 0, VK_WHOLE_SIZE, - VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); - vkCmdCopyImageToBuffer(vk_buffer, r.src_image->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - copy_buffer->buffer, 1, &src_region); + vk::AccessFlagBits::eTransferRead, vk::AccessFlagBits::eTransferWrite, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eTransfer); + vk_buffer.copyImageToBuffer(r.src_image->image, vk::ImageLayout::eTransferSrcOptimal, + copy_buffer->buffer, 1, &src_region); SetBufferMemoryBarrier(vk_buffer, copy_buffer->buffer, 0, VK_WHOLE_SIZE, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eTransferRead, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eTransfer); const auto dst_region = - MakeBufferImageCopy(0, 0, VK_IMAGE_ASPECT_COLOR_BIT, r.dst_level, r.dst_layer, + MakeBufferImageCopy(0, 0, vk::ImageAspectFlagBits::eColor, r.dst_level, r.dst_layer, {r.dst_x, r.dst_y, 0}, {r.width, r.height, 1}); - vkCmdCopyBufferToImage(vk_buffer, copy_buffer->buffer, dst_image->image, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &dst_region); + vk_buffer.copyBufferToImage(copy_buffer->buffer, dst_image->image, + vk::ImageLayout::eTransferDstOptimal, 1, &dst_region); - SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, VK_IMAGE_ASPECT_COLOR_BIT, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, src_layout); + SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, vk::ImageAspectFlagBits::eColor, + vk::ImageLayout::eTransferSrcOptimal, src_layout); return true; } void UtilImageToImage(CommandBuffer* buffer, std::span regions, - VulkanImage* dst_image, uint64_t dst_layout) { - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + VulkanImage* dst_image, vk::ImageLayout dst_layout) { + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; - bool same_image_copy = false; - VkImageAspectFlags dst_transition_aspects = 0; + bool same_image_copy = false; + vk::ImageAspectFlags dst_transition_aspects = {}; for (const auto& r: regions) { dst_transition_aspects |= GetTransferAspects(*dst_image, r.dst_aspect); if (r.src_image == dst_image) { @@ -717,10 +733,10 @@ void UtilImageToImage(CommandBuffer* buffer, std::span reg if (same_image_copy) { SetImageLayout(vk_buffer, dst_image, 0, VK_REMAINING_MIP_LEVELS, dst_transition_aspects, - dst_image->layout, VK_IMAGE_LAYOUT_GENERAL); + dst_image->layout, vk::ImageLayout::eGeneral); for (const auto& r: regions) { - VkImageCopy region; + vk::ImageCopy region; region.srcSubresource.aspectMask = r.src_aspect; region.srcSubresource.mipLevel = r.src_level; @@ -734,41 +750,41 @@ void UtilImageToImage(CommandBuffer* buffer, std::span reg region.dstOffset = {r.dst_x, r.dst_y, r.dst_z}; region.extent = {r.width, r.height, 1}; - auto src_layout = VK_IMAGE_LAYOUT_GENERAL; - auto restore_layout = VK_IMAGE_LAYOUT_GENERAL; + auto src_layout = vk::ImageLayout::eGeneral; + auto restore_layout = vk::ImageLayout::eGeneral; if (r.src_image != dst_image) { restore_layout = r.src_image->layout; SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, GetTransferAspects(*r.src_image, r.src_aspect), restore_layout, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - src_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + vk::ImageLayout::eTransferSrcOptimal); + src_layout = vk::ImageLayout::eTransferSrcOptimal; } - vkCmdCopyImage(vk_buffer, r.src_image->image, src_layout, dst_image->image, - VK_IMAGE_LAYOUT_GENERAL, 1, ®ion); + vk_buffer.copyImage(r.src_image->image, src_layout, dst_image->image, + vk::ImageLayout::eGeneral, 1, ®ion); if (r.src_image != dst_image) { SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, GetTransferAspects(*r.src_image, r.src_aspect), - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, restore_layout); + vk::ImageLayout::eTransferSrcOptimal, restore_layout); } } SetImageLayout(vk_buffer, dst_image, 0, VK_REMAINING_MIP_LEVELS, dst_transition_aspects, - VK_IMAGE_LAYOUT_GENERAL, static_cast(dst_layout)); + vk::ImageLayout::eGeneral, dst_layout); return; } SetImageLayout(vk_buffer, dst_image, 0, VK_REMAINING_MIP_LEVELS, dst_transition_aspects, - dst_image->layout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + dst_image->layout, vk::ImageLayout::eTransferDstOptimal); for (const auto& r: regions) { - VkImageCopy region; + vk::ImageCopy region; auto src_layout = r.src_image->layout; - if (r.src_aspect == VK_IMAGE_ASPECT_COLOR_BIT && - r.dst_aspect == VK_IMAGE_ASPECT_COLOR_BIT && + if (r.src_aspect == vk::ImageAspectFlagBits::eColor && + r.dst_aspect == vk::ImageAspectFlagBits::eColor && CopyBlockImageToCompressedImage(vk_buffer, r, dst_image)) { continue; } @@ -787,24 +803,24 @@ void UtilImageToImage(CommandBuffer* buffer, std::span reg SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, GetTransferAspects(*r.src_image, r.src_aspect), src_layout, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + vk::ImageLayout::eTransferSrcOptimal); - vkCmdCopyImage(vk_buffer, r.src_image->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - dst_image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + vk_buffer.copyImage(r.src_image->image, vk::ImageLayout::eTransferSrcOptimal, + dst_image->image, vk::ImageLayout::eTransferDstOptimal, 1, ®ion); SetImageLayout(vk_buffer, r.src_image, r.src_level, 1, GetTransferAspects(*r.src_image, r.src_aspect), - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, src_layout); + vk::ImageLayout::eTransferSrcOptimal, src_layout); } SetImageLayout(vk_buffer, dst_image, 0, VK_REMAINING_MIP_LEVELS, dst_transition_aspects, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, static_cast(dst_layout)); + vk::ImageLayout::eTransferDstOptimal, dst_layout); } void UtilCopyImageWithBuffer(CommandBuffer* buffer, GraphicContext* ctx, VulkanImage* src_image, - VkImageAspectFlags src_aspect, VulkanImage* dst_image, - VkImageAspectFlags dst_aspect, uint32_t bytes_per_element, - uint64_t dst_layout) { + vk::ImageAspectFlags src_aspect, VulkanImage* dst_image, + vk::ImageAspectFlags dst_aspect, uint32_t bytes_per_element, + vk::ImageLayout dst_layout) { if (!IsSingleImageAspect(src_aspect) || !IsSingleImageAspect(dst_aspect) || (bytes_per_element != 2 && bytes_per_element != 4) || src_image->layers != 1 || dst_image->layers != 1 || src_image->mip_levels != 1 || dst_image->mip_levels != 1 || @@ -813,10 +829,11 @@ void UtilCopyImageWithBuffer(CommandBuffer* buffer, GraphicContext* ctx, VulkanI src_image->extent.height != dst_image->extent.height) { EXIT("unsupported image-buffer-image copy, src_aspect=0x%x dst_aspect=0x%x bpe=%u " "src=%ux%u/%u/%u dst=%ux%u/%u/%u\n", - src_aspect, dst_aspect, bytes_per_element, src_image->extent.width, - src_image->extent.height, src_image->layers, src_image->mip_levels, - dst_image->extent.width, dst_image->extent.height, dst_image->layers, - dst_image->mip_levels); + static_cast(src_aspect), + static_cast(dst_aspect), bytes_per_element, + src_image->extent.width, src_image->extent.height, src_image->layers, + src_image->mip_levels, dst_image->extent.width, dst_image->extent.height, + dst_image->layers, dst_image->mip_levels); } const uint64_t row_bytes = static_cast(src_image->extent.width) * bytes_per_element; @@ -833,51 +850,54 @@ void UtilCopyImageWithBuffer(CommandBuffer* buffer, GraphicContext* ctx, VulkanI // barriers below. The preservation policy stays isolated here so a future scheduler can replace // this synchronization without changing texture-cache ownership logic. VulkanDeviceWaitIdle(ctx); - auto* copy_buffer = new VulkanBuffer; - copy_buffer->usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; - copy_buffer->memory.property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + auto* copy_buffer = new VulkanBuffer; + copy_buffer->usage = + vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst; + copy_buffer->memory.property = vk::MemoryPropertyFlagBits::eDeviceLocal; VulkanCreateBuffer(ctx, copy_buffer_size, copy_buffer); buffer->DeleteAfterFence(copy_buffer); - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; const auto src_layout = src_image->layout; - const auto final_layout = static_cast(dst_layout); + const auto final_layout = dst_layout; SetImageLayout(vk_buffer, src_image, 0, 1, src_aspect, src_layout, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + vk::ImageLayout::eTransferSrcOptimal); SetImageLayout(vk_buffer, dst_image, 0, 1, dst_aspect, dst_image->layout, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + vk::ImageLayout::eTransferDstOptimal); for (uint32_t row = 0; row < src_image->extent.height; row += rows_per_chunk) { const auto rows = std::min(rows_per_chunk, src_image->extent.height - row); auto copy = MakeBufferImageCopy(0, 0, src_aspect, 0, 0, {0, static_cast(row), 0}, {src_image->extent.width, rows, 1}); - vkCmdCopyImageToBuffer(vk_buffer, src_image->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - copy_buffer->buffer, 1, ©); + vk_buffer.copyImageToBuffer(src_image->image, vk::ImageLayout::eTransferSrcOptimal, + copy_buffer->buffer, 1, ©); - SetBufferMemoryBarrier(vk_buffer, copy_buffer->buffer, 0, copy_buffer_size, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + SetBufferMemoryBarrier( + vk_buffer, copy_buffer->buffer, 0, copy_buffer_size, vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eTransferRead, vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eTransfer); copy.imageSubresource.aspectMask = dst_aspect; - vkCmdCopyBufferToImage(vk_buffer, copy_buffer->buffer, dst_image->image, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©); + vk_buffer.copyBufferToImage(copy_buffer->buffer, dst_image->image, + vk::ImageLayout::eTransferDstOptimal, 1, ©); if (row + rows < src_image->extent.height) { - SetBufferMemoryBarrier(vk_buffer, copy_buffer->buffer, 0, copy_buffer_size, - VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + SetBufferMemoryBarrier( + vk_buffer, copy_buffer->buffer, 0, copy_buffer_size, + vk::AccessFlagBits::eTransferRead, vk::AccessFlagBits::eTransferWrite, + vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer); } } - SetImageLayout(vk_buffer, src_image, 0, 1, src_aspect, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + SetImageLayout(vk_buffer, src_image, 0, 1, src_aspect, vk::ImageLayout::eTransferSrcOptimal, src_layout); - SetImageLayout(vk_buffer, dst_image, 0, 1, dst_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + SetImageLayout(vk_buffer, dst_image, 0, 1, dst_aspect, vk::ImageLayout::eTransferDstOptimal, final_layout); } void UtilBlitPreparedImage(CommandBuffer* buffer, VulkanImage* src_image, VulkanSwapchain* dst_swapchain) { - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; - if (src_image->layout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + if (src_image->layout != vk::ImageLayout::eTransferSrcOptimal) { EXIT("invalid prepared presentation image, image=%p vk_image=%p layout=%d\n", static_cast(src_image), src_image != nullptr ? static_cast(src_image->image) : nullptr, @@ -887,13 +907,13 @@ void UtilBlitPreparedImage(CommandBuffer* buffer, VulkanImage* src_image, VulkanImage swapchain_image(VulkanImageType::Unknown); swapchain_image.image = dst_swapchain->swapchain_images[dst_swapchain->current_index]; - swapchain_image.layout = VK_IMAGE_LAYOUT_UNDEFINED; + swapchain_image.layout = vk::ImageLayout::eUndefined; - SetImageLayout(vk_buffer, &swapchain_image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT, - VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + SetImageLayout(vk_buffer, &swapchain_image, 0, 1, vk::ImageAspectFlagBits::eColor, + vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal); - VkImageBlit region {}; - region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + vk::ImageBlit region {}; + region.srcSubresource.aspectMask = vk::ImageAspectFlagBits::eColor; region.srcSubresource.mipLevel = 0; region.srcSubresource.baseArrayLayer = 0; region.srcSubresource.layerCount = 1; @@ -903,7 +923,7 @@ void UtilBlitPreparedImage(CommandBuffer* buffer, VulkanImage* src_image, region.srcOffsets[1].x = static_cast(src_image->extent.width); region.srcOffsets[1].y = static_cast(src_image->extent.height); region.srcOffsets[1].z = 1; - region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + region.dstSubresource.aspectMask = vk::ImageAspectFlagBits::eColor; region.dstSubresource.mipLevel = 0; region.dstSubresource.baseArrayLayer = 0; region.dstSubresource.layerCount = 1; @@ -914,21 +934,21 @@ void UtilBlitPreparedImage(CommandBuffer* buffer, VulkanImage* src_image, region.dstOffsets[1].y = static_cast(dst_swapchain->swapchain_extent.height); region.dstOffsets[1].z = 1; - vkCmdBlitImage(vk_buffer, src_image->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - swapchain_image.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion, - VK_FILTER_LINEAR); + vk_buffer.blitImage(src_image->image, vk::ImageLayout::eTransferSrcOptimal, + swapchain_image.image, vk::ImageLayout::eTransferDstOptimal, 1, ®ion, + vk::Filter::eLinear); } void UtilClearColorImage(CommandBuffer* buffer, VulkanImage* image, - const VkClearColorValue& color) { - auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; - SetImageLayout(vk_buffer, image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT, image->layout, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - const VkImageSubresourceRange range {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; - vkCmdClearColorImage(vk_buffer, image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &color, 1, - &range); - SetImageLayout(vk_buffer, image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + const vk::ClearColorValue& color) { + auto vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()]; + SetImageLayout(vk_buffer, image, 0, 1, vk::ImageAspectFlagBits::eColor, image->layout, + vk::ImageLayout::eTransferDstOptimal); + const vk::ImageSubresourceRange range {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1}; + vk_buffer.clearColorImage(image->image, vk::ImageLayout::eTransferDstOptimal, &color, 1, + &range); + SetImageLayout(vk_buffer, image, 0, 1, vk::ImageAspectFlagBits::eColor, + vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eTransferSrcOptimal); } void VulkanCreateBuffer(GraphicContext* gctx, uint64_t size, VulkanBuffer* buffer) { @@ -936,24 +956,27 @@ void VulkanCreateBuffer(GraphicContext* gctx, uint64_t size, VulkanBuffer* buffe EXIT_IF(buffer->buffer != nullptr); - VkBufferCreateInfo buffer_info {}; - buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + vk::BufferCreateInfo buffer_info {}; + buffer_info.sType = vk::StructureType::eBufferCreateInfo; buffer_info.size = size; buffer_info.usage = buffer->usage; - buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + buffer_info.sharingMode = vk::SharingMode::eExclusive; VmaAllocationCreateInfo alloc_info {}; - alloc_info.requiredFlags = buffer->memory.property; + alloc_info.requiredFlags = + static_cast(buffer->memory.property); - const auto result = - vmaCreateBuffer(gctx->allocator, &buffer_info, &alloc_info, &buffer->buffer, - &buffer->memory.allocation, &buffer->memory.allocation_info); - if (result != VK_SUCCESS) { + vk::Buffer::CType native_buffer = VK_NULL_HANDLE; + const auto result = static_cast(vmaCreateBuffer( + gctx->allocator, static_cast(buffer_info), + &alloc_info, &native_buffer, &buffer->memory.allocation, &buffer->memory.allocation_info)); + buffer->buffer = native_buffer; + if (result != vk::Result::eSuccess) { VulkanLogMemoryBudget(gctx); } - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); - vkGetBufferMemoryRequirements(gctx->device, buffer->buffer, &buffer->memory.requirements); + gctx->device.getBufferMemoryRequirements(buffer->buffer, &buffer->memory.requirements); buffer->memory.type = buffer->memory.allocation_info.memoryType; buffer->memory.memory = buffer->memory.allocation_info.deviceMemory; @@ -978,7 +1001,7 @@ void VulkanDeleteBuffer(GraphicContext* gctx, VulkanBuffer* buffer) { buffer->memory.offset = 0; } -bool VulkanCreateImage(GraphicContext* gctx, const VkImageCreateInfo* image_info, +bool VulkanCreateImage(GraphicContext* gctx, const vk::ImageCreateInfo* image_info, VulkanImage* image, VulkanMemory* memory) { KYTY_PROFILER_FUNCTION(); @@ -986,17 +1009,20 @@ bool VulkanCreateImage(GraphicContext* gctx, const VkImageCreateInfo* image_info EXIT_IF(memory->allocation != nullptr); VmaAllocationCreateInfo alloc_info {}; - alloc_info.requiredFlags = memory->property; + alloc_info.requiredFlags = static_cast(memory->property); - const auto result = vmaCreateImage(gctx->allocator, image_info, &alloc_info, &image->image, - &memory->allocation, &memory->allocation_info); + vk::Image::CType native_image = VK_NULL_HANDLE; + const auto result = static_cast(vmaCreateImage( + gctx->allocator, static_cast(*image_info), + &alloc_info, &native_image, &memory->allocation, &memory->allocation_info)); + image->image = native_image; - if (result != VK_SUCCESS) { + if (result != vk::Result::eSuccess) { VulkanLogMemoryBudget(gctx); return false; } - vkGetImageMemoryRequirements(gctx->device, image->image, &memory->requirements); + gctx->device.getImageMemoryRequirements(image->image, &memory->requirements); memory->type = memory->allocation_info.memoryType; memory->memory = memory->allocation_info.deviceMemory; @@ -1023,18 +1049,19 @@ void VulkanDeleteImage(GraphicContext* gctx, VulkanImage* image, VulkanMemory* m } void UtilFillImage(GraphicContext* ctx, VulkanImage* dst_image, const void* src_data, uint64_t size, - uint32_t src_pitch, uint64_t dst_layout) { + uint32_t src_pitch, vk::ImageLayout dst_layout) { KYTY_PROFILER_FUNCTION(); EXIT_IF(size == 0); GetStagingBuffer(StagingBufferType::Texture) - ->UploadToImage(ctx, dst_image, src_data, size, src_pitch, VK_IMAGE_ASPECT_COLOR_BIT, - VK_IMAGE_LAYOUT_UNDEFINED, static_cast(dst_layout)); + ->UploadToImage(ctx, dst_image, src_data, size, src_pitch, vk::ImageAspectFlagBits::eColor, + vk::ImageLayout::eUndefined, dst_layout); } void UtilFillBuffer(GraphicContext* ctx, void* dst_data, uint64_t size, uint32_t dst_pitch, - VulkanImage* src_image, uint64_t src_layout, VkImageAspectFlags aspect) { + VulkanImage* src_image, vk::ImageLayout src_layout, + vk::ImageAspectFlags aspect) { KYTY_PROFILER_FUNCTION(); EXIT_IF(size == 0); @@ -1045,7 +1072,7 @@ void UtilFillBuffer(GraphicContext* ctx, void* dst_data, uint64_t size, uint32_t void UtilFillBuffer(GraphicContext* ctx, void* dst_data, uint64_t size, std::span regions, VulkanImage* src_image, - uint64_t src_layout) { + vk::ImageLayout src_layout) { KYTY_PROFILER_FUNCTION(); EXIT_IF(size == 0 || regions.empty()); GetStagingBuffer(StagingBufferType::ReadBack) @@ -1053,14 +1080,14 @@ void UtilFillBuffer(GraphicContext* ctx, void* dst_data, uint64_t size, } void UtilSetImageLayoutOptimal(VulkanImage* image) { - ExecuteImmediateUtilCommands([&](CommandBuffer*, VkCommandBuffer vk_command) { - SetImageLayout(vk_command, image, 0, VK_REMAINING_MIP_LEVELS, VK_IMAGE_ASPECT_COLOR_BIT, - image->layout, VK_IMAGE_LAYOUT_GENERAL); + ExecuteImmediateUtilCommands([&](CommandBuffer*, vk::CommandBuffer vk_command) { + SetImageLayout(vk_command, image, 0, VK_REMAINING_MIP_LEVELS, + vk::ImageAspectFlagBits::eColor, image->layout, vk::ImageLayout::eGeneral); }); } void UtilFillImage(GraphicContext* ctx, VulkanImage* image, const void* src_data, uint64_t size, - std::span regions, uint64_t dst_layout) { + std::span regions, vk::ImageLayout dst_layout) { EXIT_IF(size == 0 || regions.empty()); GetStagingBuffer(StagingBufferType::Texture) @@ -1068,18 +1095,18 @@ void UtilFillImage(GraphicContext* ctx, VulkanImage* image, const void* src_data } void UtilFillImage(GraphicContext* ctx, std::span regions, - VulkanImage* dst_image, uint64_t dst_layout) { - ExecuteImmediateUtilCommands([&](CommandBuffer* command, VkCommandBuffer) { + VulkanImage* dst_image, vk::ImageLayout dst_layout) { + ExecuteImmediateUtilCommands([&](CommandBuffer* command, vk::CommandBuffer) { UtilImageToImage(command, regions, dst_image, dst_layout); }); } void UtilFillImage(GraphicContext* ctx, DepthStencilVulkanImage* image, const void* src_data, - uint64_t size, uint32_t src_pitch, VkImageAspectFlags aspect) { + uint64_t size, uint32_t src_pitch, vk::ImageAspectFlags aspect) { EXIT_IF(size == 0); GetStagingBuffer(StagingBufferType::Texture) ->UploadToImage(ctx, image, src_data, size, src_pitch, aspect, image->layout, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + vk::ImageLayout::eDepthStencilAttachmentOptimal); } void UtilUploadBuffer(GraphicContext* ctx, StagingBufferType type, VulkanBuffer* dst_buffer, @@ -1103,20 +1130,22 @@ void UtilReleaseCachedResources(GraphicContext* ctx) { void UtilCopyBuffer(VulkanBuffer* src_buffer, VulkanBuffer* dst_buffer, uint64_t size) { EXIT_IF(size == 0 || size > src_buffer->buffer_size || size > dst_buffer->buffer_size); - ExecuteImmediateUtilCommands([&](CommandBuffer*, VkCommandBuffer vk_command) { - SetBufferMemoryBarrier(vk_command, src_buffer->buffer, 0, size, VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT); + ExecuteImmediateUtilCommands([&](CommandBuffer*, vk::CommandBuffer vk_command) { + SetBufferMemoryBarrier(vk_command, src_buffer->buffer, 0, size, + vk::AccessFlagBits::eMemoryWrite, vk::AccessFlagBits::eTransferRead, + vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer); SetBufferMemoryBarrier(vk_command, dst_buffer->buffer, 0, size, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT); - const VkBufferCopy copy_region {.srcOffset = 0, .dstOffset = 0, .size = size}; - vkCmdCopyBuffer(vk_command, src_buffer->buffer, dst_buffer->buffer, 1, ©_region); - SetBufferMemoryBarrier(vk_command, dst_buffer->buffer, 0, size, - VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eTransferWrite, + vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer); + const vk::BufferCopy copy_region {.srcOffset = 0, .dstOffset = 0, .size = size}; + vk_command.copyBuffer(src_buffer->buffer, dst_buffer->buffer, 1, ©_region); + SetBufferMemoryBarrier( + vk_command, dst_buffer->buffer, 0, size, vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, + vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eAllCommands); }); } @@ -1132,7 +1161,7 @@ void UtilDownloadBuffer(GraphicContext* ctx, VulkanBuffer* src_buffer, uint64_t } EXIT_IF(ctx->queues[GraphicContext::QUEUE_GFX].family != family); - if ((src_buffer->memory.property & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) { + if (src_buffer->memory.property & vk::MemoryPropertyFlagBits::eHostVisible) { void* mapped = nullptr; VulkanMapMemory(ctx, &src_buffer->memory, &mapped); std::memcpy(dst_data, static_cast(mapped) + src_offset, size); @@ -1141,21 +1170,23 @@ void UtilDownloadBuffer(GraphicContext* ctx, VulkanBuffer* src_buffer, uint64_t } VulkanBuffer readback {}; - readback.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; - readback.memory.property = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + readback.usage = vk::BufferUsageFlagBits::eTransferDst; + readback.memory.property = vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent | + vk::MemoryPropertyFlagBits::eHostCached; VulkanCreateBuffer(ctx, size, &readback); - ExecuteImmediateUtilCommands([&](CommandBuffer*, VkCommandBuffer vk_command) { + ExecuteImmediateUtilCommands([&](CommandBuffer*, vk::CommandBuffer vk_command) { SetBufferMemoryBarrier(vk_command, src_buffer->buffer, src_offset, size, - VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); - const VkBufferCopy copy {.srcOffset = src_offset, .dstOffset = 0, .size = size}; - vkCmdCopyBuffer(vk_command, src_buffer->buffer, readback.buffer, 1, ©); - SetBufferMemoryBarrier(vk_command, readback.buffer, 0, size, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_HOST_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_HOST_BIT); + vk::AccessFlagBits::eMemoryWrite, vk::AccessFlagBits::eTransferRead, + vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer); + const vk::BufferCopy copy {.srcOffset = src_offset, .dstOffset = 0, .size = size}; + vk_command.copyBuffer(src_buffer->buffer, readback.buffer, 1, ©); + SetBufferMemoryBarrier(vk_command, readback.buffer, 0, size, + vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eHostRead, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eHost); }); void* mapped = nullptr; diff --git a/src/graphics/host_gpu/utils.h b/src/graphics/host_gpu/utils.h index 6915250b5..859f3a6e6 100644 --- a/src/graphics/host_gpu/utils.h +++ b/src/graphics/host_gpu/utils.h @@ -3,11 +3,11 @@ #include "common/abi.h" #include "common/common.h" +#include "graphics/host_gpu/vulkanCommon.h" #include #include #include -#include namespace Libs::Graphics { @@ -20,55 +20,55 @@ struct DepthStencilVulkanImage; struct VulkanSwapchain; struct BufferImageCopy { - uint32_t offset; - uint32_t pitch; - uint32_t dst_level; - uint32_t width; - uint32_t height; - uint32_t copy_height = 0; - uint32_t dst_layer = 0; - int dst_x; - int dst_y; - int dst_z = 0; - VkImageAspectFlags aspect = VK_IMAGE_ASPECT_COLOR_BIT; + uint32_t offset; + uint32_t pitch; + uint32_t dst_level; + uint32_t width; + uint32_t height; + uint32_t copy_height = 0; + uint32_t dst_layer = 0; + int dst_x; + int dst_y; + int dst_z = 0; + vk::ImageAspectFlags aspect = vk::ImageAspectFlagBits::eColor; }; struct ImageBufferCopy { - uint32_t offset; - uint32_t pitch; - uint32_t src_level; - uint32_t width; - uint32_t height; - uint32_t copy_height = 0; - uint32_t src_layer = 0; - int src_x; - int src_y; - int src_z = 0; - VkImageAspectFlags aspect = VK_IMAGE_ASPECT_COLOR_BIT; + uint32_t offset; + uint32_t pitch; + uint32_t src_level; + uint32_t width; + uint32_t height; + uint32_t copy_height = 0; + uint32_t src_layer = 0; + int src_x; + int src_y; + int src_z = 0; + vk::ImageAspectFlags aspect = vk::ImageAspectFlagBits::eColor; }; struct ImageImageCopy { - VulkanImage* src_image; - uint32_t src_level; - uint32_t dst_level; - uint32_t width; - uint32_t height; - uint32_t src_layer = 0; - uint32_t dst_layer = 0; - VkImageAspectFlags src_aspect = VK_IMAGE_ASPECT_COLOR_BIT; - VkImageAspectFlags dst_aspect = VK_IMAGE_ASPECT_COLOR_BIT; - int src_x; - int src_y; - int src_z = 0; - int dst_x; - int dst_y; - int dst_z = 0; + VulkanImage* src_image; + uint32_t src_level; + uint32_t dst_level; + uint32_t width; + uint32_t height; + uint32_t src_layer = 0; + uint32_t dst_layer = 0; + vk::ImageAspectFlags src_aspect = vk::ImageAspectFlagBits::eColor; + vk::ImageAspectFlags dst_aspect = vk::ImageAspectFlagBits::eColor; + int src_x; + int src_y; + int src_z = 0; + int dst_x; + int dst_y; + int dst_z = 0; }; [[nodiscard]] std::vector MakeLayeredImageBufferCopies(uint32_t layers, uint64_t slice_size, uint32_t pitch, uint32_t width, - uint32_t height, - VkImageAspectFlags aspect = VK_IMAGE_ASPECT_COLOR_BIT); + uint32_t height, + vk::ImageAspectFlags aspect = vk::ImageAspectFlagBits::eColor); enum class StagingBufferType { Texture, Vertex, ReadBack }; @@ -85,28 +85,29 @@ private: }; void UtilImageToImage(CommandBuffer* buffer, std::span regions, - VulkanImage* dst_image, uint64_t dst_layout); + VulkanImage* dst_image, vk::ImageLayout dst_layout); void UtilCopyImageWithBuffer(CommandBuffer* buffer, GraphicContext* ctx, VulkanImage* src_image, - VkImageAspectFlags src_aspect, VulkanImage* dst_image, - VkImageAspectFlags dst_aspect, uint32_t bytes_per_element, - uint64_t dst_layout); + vk::ImageAspectFlags src_aspect, VulkanImage* dst_image, + vk::ImageAspectFlags dst_aspect, uint32_t bytes_per_element, + vk::ImageLayout dst_layout); void UtilBlitPreparedImage(CommandBuffer* buffer, VulkanImage* src_image, VulkanSwapchain* dst_swapchain); -void UtilClearColorImage(CommandBuffer* buffer, VulkanImage* image, const VkClearColorValue& color); +void UtilClearColorImage(CommandBuffer* buffer, VulkanImage* image, + const vk::ClearColorValue& color); void UtilFillImage(GraphicContext* ctx, VulkanImage* dst_image, const void* src_data, uint64_t size, - uint32_t src_pitch, uint64_t dst_layout); + uint32_t src_pitch, vk::ImageLayout dst_layout); void UtilFillImage(GraphicContext* ctx, DepthStencilVulkanImage* dst_image, const void* src_data, - uint64_t size, uint32_t src_pitch, VkImageAspectFlags aspect); + uint64_t size, uint32_t src_pitch, vk::ImageAspectFlags aspect); void UtilFillImage(GraphicContext* ctx, VulkanImage* dst_image, const void* src_data, uint64_t size, - std::span regions, uint64_t dst_layout); + std::span regions, vk::ImageLayout dst_layout); void UtilFillImage(GraphicContext* ctx, std::span regions, - VulkanImage* dst_image, uint64_t dst_layout); + VulkanImage* dst_image, vk::ImageLayout dst_layout); void UtilFillBuffer(GraphicContext* ctx, void* dst_data, uint64_t size, uint32_t dst_pitch, - VulkanImage* src_image, uint64_t src_layout, - VkImageAspectFlags aspect = VK_IMAGE_ASPECT_COLOR_BIT); + VulkanImage* src_image, vk::ImageLayout src_layout, + vk::ImageAspectFlags aspect = vk::ImageAspectFlagBits::eColor); void UtilFillBuffer(GraphicContext* ctx, void* dst_data, uint64_t size, std::span regions, VulkanImage* src_image, - uint64_t src_layout); + vk::ImageLayout src_layout); void UtilUploadBuffer(GraphicContext* ctx, StagingBufferType type, VulkanBuffer* dst_buffer, uint64_t dst_offset, const void* src_data, uint64_t size); void UtilReleaseCachedResources(GraphicContext* ctx); @@ -117,17 +118,17 @@ bool UtilBufferIsTiled(uint64_t vaddr, uint64_t size); void UtilSetImageLayoutOptimal(VulkanImage* image); void UtilResetImageViews(VulkanImage* image); void UtilCreateImageView(GraphicContext* ctx, VulkanImage* image, int view_index, - VkImageViewType view_type, VkImageAspectFlags aspect_mask, - VkComponentMapping components, uint32_t base_array_layer, + vk::ImageViewType view_type, vk::ImageAspectFlags aspect_mask, + vk::ComponentMapping components, uint32_t base_array_layer, uint32_t base_mip_level, uint32_t layer_count, uint32_t level_count, - VkFormat view_format = VK_FORMAT_UNDEFINED, - VkImageUsageFlags view_usage = 0); -bool UtilIsBcFormat(VkFormat format); -uint32_t UtilGetBcBlockSize(VkFormat format); + vk::Format view_format = vk::Format::eUndefined, + vk::ImageUsageFlags view_usage = {}); +bool UtilIsBcFormat(vk::Format format); +uint32_t UtilGetBcBlockSize(vk::Format format); void VulkanCreateBuffer(GraphicContext* gctx, uint64_t size, VulkanBuffer* buffer); void VulkanDeleteBuffer(GraphicContext* gctx, VulkanBuffer* buffer); -bool VulkanCreateImage(GraphicContext* gctx, const VkImageCreateInfo* image_info, +bool VulkanCreateImage(GraphicContext* gctx, const vk::ImageCreateInfo* image_info, VulkanImage* image, VulkanMemory* memory); void VulkanDeleteImage(GraphicContext* gctx, VulkanImage* image, VulkanMemory* memory); void VulkanDeviceWaitIdle(GraphicContext* ctx); diff --git a/src/graphics/host_gpu/vma.cpp b/src/graphics/host_gpu/vma.cpp index aab3d9e1b..cbedd2025 100644 --- a/src/graphics/host_gpu/vma.cpp +++ b/src/graphics/host_gpu/vma.cpp @@ -1,3 +1,5 @@ +#include "graphics/host_gpu/vulkanCommon.h" + #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" @@ -24,7 +26,6 @@ #include #include #include -#include namespace Libs::Graphics { @@ -66,16 +67,21 @@ bool VulkanCreateAllocator(GraphicContext* ctx) { EXIT_IF(ctx == nullptr || ctx->instance == nullptr || ctx->physical_device == nullptr || ctx->device == nullptr || ctx->allocator != nullptr); + VmaVulkanFunctions functions {}; + functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + VmaAllocatorCreateInfo info {}; info.instance = ctx->instance; info.physicalDevice = ctx->physical_device; info.device = ctx->device; + info.pVulkanFunctions = &functions; info.vulkanApiVersion = VULKAN_TARGET_API_VERSION; info.flags = ctx->memory_budget_ext_enabled ? VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT : 0; - const auto result = vmaCreateAllocator(&info, &ctx->allocator); - if (result != VK_SUCCESS) { - LOGF("vmaCreateAllocator failed: %s\n", string_VkResult(result)); + const auto result = static_cast(vmaCreateAllocator(&info, &ctx->allocator)); + if (result != vk::Result::eSuccess) { + LOGF("vmaCreateAllocator failed: %s\n", VulkanToString(result).c_str()); return false; } return true; @@ -127,11 +133,13 @@ bool VulkanAllocate(GraphicContext* ctx, VulkanMemory* memory) { } VmaAllocationCreateInfo info {}; - info.requiredFlags = memory->property; + info.requiredFlags = static_cast(memory->property); memory->unique_id = VulkanNextMemoryUniqueId(); - const auto result = vmaAllocateMemory(ctx->allocator, &memory->requirements, &info, - &memory->allocation, &memory->allocation_info); - if (result == VK_SUCCESS) { + const auto result = static_cast(vmaAllocateMemory( + ctx->allocator, + static_cast(memory->requirements), &info, + &memory->allocation, &memory->allocation_info)); + if (result == vk::Result::eSuccess) { memory->type = memory->allocation_info.memoryType; memory->memory = memory->allocation_info.deviceMemory; memory->offset = memory->allocation_info.offset; @@ -146,7 +154,7 @@ bool VulkanAllocate(GraphicContext* ctx, VulkanMemory* memory) { g_memory_stats.allocated[i].load())); } EXIT("size = %" PRIu64 ", index = %u, error: %s:%s\n", memory->requirements.size, index, - string_VkResult(result), Common::Concat(stats, '\n').c_str()); + VulkanToString(result).c_str(), Common::Concat(stats, '\n').c_str()); return false; } @@ -166,7 +174,8 @@ void VulkanMapMemory(GraphicContext* ctx, VulkanMemory* memory, void** data) { KYTY_PROFILER_FUNCTION(); EXIT_IF(ctx == nullptr || memory == nullptr || data == nullptr || ctx->allocator == nullptr || memory->allocation == nullptr); - EXIT_NOT_IMPLEMENTED(vmaMapMemory(ctx->allocator, memory->allocation, data) != VK_SUCCESS); + EXIT_NOT_IMPLEMENTED(static_cast(vmaMapMemory(ctx->allocator, memory->allocation, + data)) != vk::Result::eSuccess); } void VulkanUnmapMemory(GraphicContext* ctx, VulkanMemory* memory) { @@ -180,16 +189,18 @@ void VulkanBindImageMemory(GraphicContext* ctx, VulkanImage* image, VulkanMemory KYTY_PROFILER_FUNCTION(); EXIT_IF(ctx == nullptr || image == nullptr || memory == nullptr || ctx->allocator == nullptr || memory->allocation == nullptr); - EXIT_NOT_IMPLEMENTED(vmaBindImageMemory(ctx->allocator, memory->allocation, image->image) != - VK_SUCCESS); + EXIT_NOT_IMPLEMENTED( + static_cast(vmaBindImageMemory(ctx->allocator, memory->allocation, + image->image)) != vk::Result::eSuccess); } void VulkanBindBufferMemory(GraphicContext* ctx, VulkanBuffer* buffer, VulkanMemory* memory) { KYTY_PROFILER_FUNCTION(); EXIT_IF(ctx == nullptr || buffer == nullptr || memory == nullptr || ctx->allocator == nullptr || memory->allocation == nullptr); - EXIT_NOT_IMPLEMENTED(vmaBindBufferMemory(ctx->allocator, memory->allocation, buffer->buffer) != - VK_SUCCESS); + EXIT_NOT_IMPLEMENTED( + static_cast(vmaBindBufferMemory(ctx->allocator, memory->allocation, + buffer->buffer)) != vk::Result::eSuccess); } } // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/vulkanCommon.cpp b/src/graphics/host_gpu/vulkanCommon.cpp new file mode 100644 index 000000000..4a1cc7b68 --- /dev/null +++ b/src/graphics/host_gpu/vulkanCommon.cpp @@ -0,0 +1,23 @@ +#include "graphics/host_gpu/vulkanCommon.h" + +VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE + +namespace Libs::Graphics { + +std::string VulkanToString(vk::Result value) { + return vk::to_string(value); +} + +std::string VulkanToString(vk::Format value) { + return vk::to_string(value); +} + +std::string VulkanToString(vk::ImageLayout value) { + return vk::to_string(value); +} + +std::string VulkanToString(vk::QueueFlags value) { + return vk::to_string(value); +} + +} // namespace Libs::Graphics diff --git a/src/graphics/host_gpu/vulkanCommon.h b/src/graphics/host_gpu/vulkanCommon.h new file mode 100644 index 000000000..04ebd2e91 --- /dev/null +++ b/src/graphics/host_gpu/vulkanCommon.h @@ -0,0 +1,33 @@ +#ifndef EMULATOR_SRC_GRAPHICS_HOST_GPU_VULKANCOMMON_H_ +#define EMULATOR_SRC_GRAPHICS_HOST_GPU_VULKANCOMMON_H_ + +#define VK_NO_PROTOTYPES +#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 +#define VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL 1 +#define VULKAN_HPP_NO_CONSTRUCTORS +#define VULKAN_HPP_NO_EXCEPTIONS + +#define VMA_STATIC_VULKAN_FUNCTIONS 0 +#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 + +#include +#include +#include + +namespace Libs::Graphics { + +using VulkanMemoryBarrier = vk::MemoryBarrier; + +template +[[nodiscard]] void* VulkanHandleToPointer(Handle handle) { + return reinterpret_cast(static_cast(handle)); +} + +std::string VulkanToString(vk::Result value); +std::string VulkanToString(vk::Format value); +std::string VulkanToString(vk::ImageLayout value); +std::string VulkanToString(vk::QueueFlags value); + +} // namespace Libs::Graphics + +#endif // EMULATOR_SRC_GRAPHICS_HOST_GPU_VULKANCOMMON_H_ diff --git a/src/graphics/host_gpu/vulkanInstance.h b/src/graphics/host_gpu/vulkanInstance.h index 4a76ab52a..beb115d6e 100644 --- a/src/graphics/host_gpu/vulkanInstance.h +++ b/src/graphics/host_gpu/vulkanInstance.h @@ -4,12 +4,12 @@ #include "common/abi.h" #include "common/common.h" #include "common/threads.h" +#include "graphics/host_gpu/vulkanCommon.h" #include #include #include #include -#include namespace Libs::Graphics { @@ -19,7 +19,7 @@ struct VulkanQueueInfo { Common::Mutex* mutex = nullptr; uint32_t family = static_cast(-1); uint32_t index = static_cast(-1); - VkQueue vk_queue = nullptr; + vk::Queue vk_queue = nullptr; }; struct VulkanInstance { @@ -33,51 +33,53 @@ struct VulkanInstance { static constexpr int QUEUE_COMPUTE_START = 0; static constexpr int QUEUE_COMPUTE_NUM = 8; - VkInstance instance = nullptr; - VkDebugUtilsMessengerEXT debug_messenger = nullptr; - VkPhysicalDevice physical_device = nullptr; - VkPhysicalDeviceProperties physical_device_properties = {}; - VkPhysicalDeviceMemoryProperties physical_device_memory_properties = {}; - VkDevice device = nullptr; - VmaAllocator allocator = nullptr; - bool memory_budget_ext_enabled = false; - bool subgroup_size_control_enabled = false; - uint32_t subgroup_size = 0; - uint32_t min_subgroup_size = 0; - uint32_t max_subgroup_size = 0; - VkShaderStageFlags required_subgroup_size_stages = 0; - VulkanQueueInfo queues[QUEUES_NUM]; + vk::Instance instance = nullptr; + vk::DebugUtilsMessengerEXT debug_messenger = nullptr; + vk::PhysicalDevice physical_device = nullptr; + vk::PhysicalDeviceProperties physical_device_properties = {}; + vk::PhysicalDeviceMemoryProperties physical_device_memory_properties = {}; + vk::Device device = nullptr; + VmaAllocator allocator = nullptr; + bool memory_budget_ext_enabled = false; + bool rt_extensions_enabled = false; + bool subgroup_size_control_enabled = false; + uint32_t subgroup_size = 0; + uint32_t min_subgroup_size = 0; + uint32_t max_subgroup_size = 0; + vk::ShaderStageFlags required_subgroup_size_stages = {}; + VulkanQueueInfo queues[QUEUES_NUM]; - [[nodiscard]] const VkPhysicalDeviceProperties& GetPhysicalDeviceProperties() const { + [[nodiscard]] const vk::PhysicalDeviceProperties& GetPhysicalDeviceProperties() const { return physical_device_properties; } - [[nodiscard]] const VkPhysicalDeviceMemoryProperties& + [[nodiscard]] const vk::PhysicalDeviceMemoryProperties& GetPhysicalDeviceMemoryProperties() const { return physical_device_memory_properties; } - [[nodiscard]] VkFormatProperties GetFormatProperties(VkFormat format) const { + [[nodiscard]] vk::FormatProperties GetFormatProperties(vk::Format format) const { std::scoped_lock lock(m_format_properties_mutex); auto [it, inserted] = m_format_properties.try_emplace(format); if (inserted) { - vkGetPhysicalDeviceFormatProperties(physical_device, format, &it->second); + physical_device.getFormatProperties(format, &it->second); } return it->second; } - [[nodiscard]] VkResult GetImageFormatProperties(VkFormat format, VkImageType type, - VkImageTiling tiling, VkImageUsageFlags usage, - VkImageCreateFlags flags, - VkImageFormatProperties* properties) const { - using Key = - std::tuple; + [[nodiscard]] vk::Result GetImageFormatProperties(vk::Format format, vk::ImageType type, + vk::ImageTiling tiling, + vk::ImageUsageFlags usage, + vk::ImageCreateFlags flags, + vk::ImageFormatProperties* properties) const { + using Key = std::tuple; std::scoped_lock lock(m_image_format_properties_mutex); auto [it, inserted] = m_image_format_properties.try_emplace(Key {format, type, tiling, usage, flags}); if (inserted) { - it->second.first = vkGetPhysicalDeviceImageFormatProperties( - physical_device, format, type, tiling, usage, flags, &it->second.second); + it->second.first = physical_device.getImageFormatProperties(format, type, tiling, usage, + flags, &it->second.second); } if (properties != nullptr) { *properties = it->second.second; @@ -85,18 +87,18 @@ struct VulkanInstance { return it->second.first; } - [[nodiscard]] VkDeviceSize StorageMinAlignment() const { + [[nodiscard]] vk::DeviceSize StorageMinAlignment() const { const auto alignment = physical_device_properties.limits.minStorageBufferOffsetAlignment; return alignment != 0 ? alignment : 1; } private: - mutable std::mutex m_format_properties_mutex; - mutable std::map m_format_properties; - mutable std::mutex m_image_format_properties_mutex; - mutable std::map< - std::tuple, - std::pair> + mutable std::mutex m_format_properties_mutex; + mutable std::map m_format_properties; + mutable std::mutex m_image_format_properties_mutex; + mutable std::map, + std::pair> m_image_format_properties; }; diff --git a/src/graphics/presentation/renderDoc.cpp b/src/graphics/presentation/renderDoc.cpp index d89cd4cc0..c6a4371e8 100644 --- a/src/graphics/presentation/renderDoc.cpp +++ b/src/graphics/presentation/renderDoc.cpp @@ -99,12 +99,12 @@ static std::atomic g_state = RenderDocState::Idle; static std::atomic_bool g_init_done = false; static std::atomic_bool g_unavailable_log = false; -static RenderDocDevicePointer GetRenderDocDevicePointer(VkInstance instance) { +static RenderDocDevicePointer GetRenderDocDevicePointer(vk::Instance instance) { if (instance == nullptr) { return nullptr; } - return reinterpret_cast(instance); + return VulkanHandleToPointer(instance); } static bool BindRenderDocApi(HMODULE module) { @@ -191,7 +191,7 @@ bool RenderDocIsLoaded() { return g_api != nullptr; } -void RenderDocSetActiveWindow(VkInstance instance, SDL_Window* window) { +void RenderDocSetActiveWindow(vk::Instance instance, SDL_Window* window) { if (g_api == nullptr) { return; } @@ -284,7 +284,7 @@ void RenderDocInit() {} bool RenderDocIsLoaded() { return false; } -void RenderDocSetActiveWindow(VkInstance /*instance*/, SDL_Window* /*window*/) {} +void RenderDocSetActiveWindow(vk::Instance /*instance*/, SDL_Window* /*window*/) {} void RenderDocRequestCapture() {} void RenderDocOnPresent() {} diff --git a/src/graphics/presentation/renderDoc.h b/src/graphics/presentation/renderDoc.h index eed135091..c359cb3f0 100644 --- a/src/graphics/presentation/renderDoc.h +++ b/src/graphics/presentation/renderDoc.h @@ -2,8 +2,7 @@ #define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_RENDERDOC_H_ #include "common/common.h" - -#include +#include "graphics/host_gpu/vulkanCommon.h" struct SDL_Window; @@ -11,7 +10,7 @@ namespace Libs::Graphics { void RenderDocInit(); bool RenderDocIsLoaded(); -void RenderDocSetActiveWindow(VkInstance instance, SDL_Window* window); +void RenderDocSetActiveWindow(vk::Instance instance, SDL_Window* window); void RenderDocRequestCapture(); void RenderDocOnPresent(); diff --git a/src/graphics/presentation/window.h b/src/graphics/presentation/window.h index 96baa35c4..8001d4c91 100644 --- a/src/graphics/presentation/window.h +++ b/src/graphics/presentation/window.h @@ -3,8 +3,7 @@ #include "common/abi.h" #include "common/common.h" - -struct VkSurfaceCapabilitiesKHR; +#include "graphics/host_gpu/vulkanCommon.h" namespace Libs::Graphics { @@ -13,7 +12,7 @@ class CommandBuffer; struct VideoOutVulkanImage; struct PreparedFrame; -VkSurfaceCapabilitiesKHR* VulkanGetSurfaceCapabilities(); +vk::SurfaceCapabilitiesKHR* VulkanGetSurfaceCapabilities(); GraphicContext* WindowGetGraphicContext(); diff --git a/src/graphics/presentation/window/swapchain.cpp b/src/graphics/presentation/window/swapchain.cpp index 6ed616980..a568b87f7 100644 --- a/src/graphics/presentation/window/swapchain.cpp +++ b/src/graphics/presentation/window/swapchain.cpp @@ -31,6 +31,7 @@ #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/host_gpu/utils.h" #include "graphics/host_gpu/vma.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/renderDoc.h" #include "graphics/presentation/videoOut.h" #include "graphics/presentation/window.h" @@ -48,7 +49,6 @@ #include #include #include -#include #include // IWYU pragma: no_include @@ -66,8 +66,8 @@ struct PreparedFrame { class PreparedFramePool { public: - void EnsureCapacity(uint32_t count, VkFormat format) { - if (count == 0 || format == VK_FORMAT_UNDEFINED) { + void EnsureCapacity(uint32_t count, vk::Format format) { + if (count == 0 || format == vk::Format::eUndefined) { EXIT("prepared-frame pool requires at least one frame\n"); } Common::LockGuard lock(m_mutex); @@ -79,9 +79,9 @@ public: } } - VkFormat GetFormat() { + vk::Format GetFormat() { Common::LockGuard lock(m_mutex); - if (m_format == VK_FORMAT_UNDEFINED) { + if (m_format == vk::Format::eUndefined) { EXIT("prepared-frame pool has no presentation format\n"); } return m_format; @@ -130,7 +130,7 @@ private: Common::CondVar m_available; std::vector> m_frames; std::deque m_free; - VkFormat m_format = VK_FORMAT_UNDEFINED; + vk::Format m_format = vk::Format::eUndefined; }; static PreparedFramePool* GetPreparedFramePool() { @@ -138,10 +138,10 @@ static PreparedFramePool* GetPreparedFramePool() { return pool; } -static void ConfigurePreparedFrame(PreparedFrame* frame, VkExtent2D extent, VkFormat format) { +static void ConfigurePreparedFrame(PreparedFrame* frame, vk::Extent2D extent, vk::Format format) { EXIT_IF(frame == nullptr); EXIT_IF(g_window_ctx == nullptr); - if (extent.width == 0 || extent.height == 0 || format == VK_FORMAT_UNDEFINED) { + if (extent.width == 0 || extent.height == 0 || format == vk::Format::eUndefined) { EXIT("unsupported prepared frame, extent=%ux%u format=%d\n", extent.width, extent.height, static_cast(format)); } @@ -163,21 +163,21 @@ static void ConfigurePreparedFrame(PreparedFrame* frame, VkExtent2D extent, VkFo dst.format = format; dst.layers = 1; dst.mip_levels = 1; - dst.layout = VK_IMAGE_LAYOUT_UNDEFINED; - dst.memory.property = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + dst.layout = vk::ImageLayout::eUndefined; + dst.memory.property = vk::MemoryPropertyFlagBits::eDeviceLocal; - VkImageCreateInfo create {}; - create.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - create.imageType = VK_IMAGE_TYPE_2D; + vk::ImageCreateInfo create {}; + create.sType = vk::StructureType::eImageCreateInfo; + create.imageType = vk::ImageType::e2D; create.extent = {dst.extent.width, dst.extent.height, 1}; create.mipLevels = 1; create.arrayLayers = 1; create.format = dst.format; - create.tiling = VK_IMAGE_TILING_OPTIMAL; - create.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - create.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; - create.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - create.samples = VK_SAMPLE_COUNT_1_BIT; + create.tiling = vk::ImageTiling::eOptimal; + create.initialLayout = vk::ImageLayout::eUndefined; + create.usage = vk::ImageUsageFlagBits::eTransferSrc | vk::ImageUsageFlagBits::eTransferDst; + create.sharingMode = vk::SharingMode::eExclusive; + create.samples = vk::SampleCountFlagBits::e1; if (!VulkanCreateImage(ctx, &create, &dst, &dst.memory)) { EXIT("failed to allocate prepared presentation image, extent=%ux%u format=%d\n", dst.extent.width, dst.extent.height, static_cast(dst.format)); @@ -186,11 +186,11 @@ static void ConfigurePreparedFrame(PreparedFrame* frame, VkExtent2D extent, VkFo VulkanSwapchain::~VulkanSwapchain() = default; -[[maybe_unused]] static VkSwapchainKHR VulkanCreateSwapchainInternal( - VkDevice device, VkSurfaceKHR surface, uint32_t width, uint32_t height, uint32_t image_count, - SurfaceCapabilities* r, VkFormat* swapchain_format, VkExtent2D* swapchain_extent, - std::unique_ptr* swapchain_images, - std::unique_ptr* swapchain_image_views, uint32_t* swapchain_images_count) { +[[maybe_unused]] static vk::SwapchainKHR VulkanCreateSwapchainInternal( + vk::Device device, vk::SurfaceKHR surface, uint32_t width, uint32_t height, + uint32_t image_count, SurfaceCapabilities* r, vk::Format* swapchain_format, + vk::Extent2D* swapchain_extent, std::unique_ptr* swapchain_images, + std::unique_ptr* swapchain_image_views, uint32_t* swapchain_images_count) { EXIT_IF(device == nullptr); EXIT_IF(surface == nullptr); EXIT_IF(r == nullptr); @@ -202,7 +202,7 @@ VulkanSwapchain::~VulkanSwapchain() = default; EXIT_NOT_IMPLEMENTED(r->formats.empty()); - VkExtent2D extent {}; + vk::Extent2D extent {}; extent.width = std::clamp(width, r->capabilities.minImageExtent.width, r->capabilities.maxImageExtent.width); extent.height = std::clamp(height, r->capabilities.minImageExtent.height, @@ -211,19 +211,19 @@ VulkanSwapchain::~VulkanSwapchain() = default; image_count = std::clamp(image_count, r->capabilities.minImageCount, r->capabilities.maxImageCount); - VkSwapchainCreateInfoKHR create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + vk::SwapchainCreateInfoKHR create_info {}; + create_info.sType = vk::StructureType::eSwapchainCreateInfoKHR; create_info.pNext = nullptr; - create_info.flags = 0; + create_info.flags = {}; create_info.surface = surface; create_info.minImageCount = image_count; if (r->format_unorm_bgra32) { - create_info.imageFormat = VK_FORMAT_B8G8R8A8_UNORM; - create_info.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + create_info.imageFormat = vk::Format::eB8G8R8A8Unorm; + create_info.imageColorSpace = vk::ColorSpaceKHR::eSrgbNonlinear; } else if (r->format_srgb_bgra32) { - create_info.imageFormat = VK_FORMAT_B8G8R8A8_SRGB; - create_info.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + create_info.imageFormat = vk::Format::eB8G8R8A8Srgb; + create_info.imageColorSpace = vk::ColorSpaceKHR::eSrgbNonlinear; } else { const auto& format = r->formats[0]; create_info.imageFormat = format.format; @@ -232,49 +232,50 @@ VulkanSwapchain::~VulkanSwapchain() = default; create_info.imageExtent = extent; create_info.imageArrayLayers = 1; - create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; - create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + create_info.imageUsage = + vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferDst; + create_info.imageSharingMode = vk::SharingMode::eExclusive; create_info.queueFamilyIndexCount = 0; create_info.pQueueFamilyIndices = nullptr; create_info.preTransform = r->capabilities.currentTransform; - create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - create_info.presentMode = VK_PRESENT_MODE_FIFO_KHR; + create_info.compositeAlpha = vk::CompositeAlphaFlagBitsKHR::eOpaque; + create_info.presentMode = vk::PresentModeKHR::eFifo; create_info.clipped = VK_TRUE; create_info.oldSwapchain = nullptr; *swapchain_format = create_info.imageFormat; *swapchain_extent = extent; - VkSwapchainKHR swapchain = nullptr; + vk::SwapchainKHR swapchain = nullptr; - vkCreateSwapchainKHR(device, &create_info, nullptr, &swapchain); + device.createSwapchainKHR(&create_info, nullptr, &swapchain); - vkGetSwapchainImagesKHR(device, swapchain, swapchain_images_count, nullptr); + device.getSwapchainImagesKHR(swapchain, swapchain_images_count, nullptr); EXIT_NOT_IMPLEMENTED(*swapchain_images_count == 0); - *swapchain_images = std::make_unique(*swapchain_images_count); - vkGetSwapchainImagesKHR(device, swapchain, swapchain_images_count, swapchain_images->get()); + *swapchain_images = std::make_unique(*swapchain_images_count); + device.getSwapchainImagesKHR(swapchain, swapchain_images_count, swapchain_images->get()); - *swapchain_image_views = std::make_unique(*swapchain_images_count); + *swapchain_image_views = std::make_unique(*swapchain_images_count); for (uint32_t i = 0; i < *swapchain_images_count; i++) { - VkImageViewCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + vk::ImageViewCreateInfo create_info {}; + create_info.sType = vk::StructureType::eImageViewCreateInfo; create_info.pNext = nullptr; - create_info.flags = 0; + create_info.flags = {}; create_info.image = (*swapchain_images)[i]; - create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + create_info.viewType = vk::ImageViewType::e2D; create_info.format = *swapchain_format; - create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; - create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + create_info.components.r = vk::ComponentSwizzle::eIdentity; + create_info.components.g = vk::ComponentSwizzle::eIdentity; + create_info.components.b = vk::ComponentSwizzle::eIdentity; + create_info.components.a = vk::ComponentSwizzle::eIdentity; + create_info.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; create_info.subresourceRange.baseArrayLayer = 0; create_info.subresourceRange.baseMipLevel = 0; create_info.subresourceRange.layerCount = 1; create_info.subresourceRange.levelCount = 1; - vkCreateImageView(device, &create_info, nullptr, &((*swapchain_image_views)[i])); + device.createImageView(&create_info, nullptr, &((*swapchain_image_views)[i])); } return swapchain; @@ -302,21 +303,21 @@ VulkanSwapchain* VulkanCreateSwapchain(GraphicContext* ctx, uint32_t image_count s->current_index = static_cast(-1); s->present_frame = 0; - VkSemaphoreCreateInfo semaphore_info {}; - semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + vk::SemaphoreCreateInfo semaphore_info {}; + semaphore_info.sType = vk::StructureType::eSemaphoreCreateInfo; semaphore_info.pNext = nullptr; - semaphore_info.flags = 0; + semaphore_info.flags = {}; - s->image_acquired_semaphores = std::make_unique(s->swapchain_images_count); - s->render_complete_semaphores = std::make_unique(s->swapchain_images_count); + s->image_acquired_semaphores = std::make_unique(s->swapchain_images_count); + s->render_complete_semaphores = std::make_unique(s->swapchain_images_count); for (uint32_t i = 0; i < s->swapchain_images_count; i++) { - auto result = vkCreateSemaphore(ctx->device, &semaphore_info, nullptr, - &s->image_acquired_semaphores[i]); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + auto result = + ctx->device.createSemaphore(&semaphore_info, nullptr, &s->image_acquired_semaphores[i]); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); - result = vkCreateSemaphore(ctx->device, &semaphore_info, nullptr, - &s->render_complete_semaphores[i]); - EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS); + result = ctx->device.createSemaphore(&semaphore_info, nullptr, + &s->render_complete_semaphores[i]); + EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } GetPreparedFramePool()->EnsureCapacity(s->swapchain_images_count, s->swapchain_format); @@ -334,27 +335,27 @@ static void VulkanDeleteSwapchain(GraphicContext* ctx, VulkanSwapchain* s) { if (s->image_acquired_semaphores != nullptr) { for (uint32_t i = 0; i < s->swapchain_images_count; i++) { if (s->image_acquired_semaphores[i] != nullptr) { - vkDestroySemaphore(ctx->device, s->image_acquired_semaphores[i], nullptr); + ctx->device.destroySemaphore(s->image_acquired_semaphores[i], nullptr); } } } if (s->render_complete_semaphores != nullptr) { for (uint32_t i = 0; i < s->swapchain_images_count; i++) { if (s->render_complete_semaphores[i] != nullptr) { - vkDestroySemaphore(ctx->device, s->render_complete_semaphores[i], nullptr); + ctx->device.destroySemaphore(s->render_complete_semaphores[i], nullptr); } } } if (s->swapchain_image_views != nullptr) { for (uint32_t i = 0; i < s->swapchain_images_count; i++) { if (s->swapchain_image_views[i] != nullptr) { - vkDestroyImageView(ctx->device, s->swapchain_image_views[i], nullptr); + ctx->device.destroyImageView(s->swapchain_image_views[i], nullptr); } } } if (s->swapchain != nullptr) { - vkDestroySwapchainKHR(ctx->device, s->swapchain, nullptr); + ctx->device.destroySwapchainKHR(s->swapchain, nullptr); } } @@ -395,7 +396,7 @@ static void ValidatePreparedCommand(CommandBuffer* buffer) { PreparedFrame* WindowPrepareFrame(CommandBuffer* buffer, VideoOutVulkanImage* image) { KYTY_PROFILER_FUNCTION(); ValidatePreparedCommand(buffer); - if (image->format == VK_FORMAT_UNDEFINED) { + if (image->format == vk::Format::eUndefined) { EXIT("unsupported presentation source, image=%p\n", static_cast(image)); } @@ -405,8 +406,7 @@ PreparedFrame* WindowPrepareFrame(CommandBuffer* buffer, VideoOutVulkanImage* im ConfigurePreparedFrame(frame, image->extent, image->format); const std::array copies {ImageImageCopy { .src_image = image, .width = image->extent.width, .height = image->extent.height}}; - UtilImageToImage(buffer, copies, &frame->image, - static_cast(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL)); + UtilImageToImage(buffer, copies, &frame->image, vk::ImageLayout::eTransferSrcOptimal); return frame; } @@ -419,7 +419,8 @@ PreparedFrame* WindowPrepareBlankFrame(CommandBuffer* buffer, uint32_t width, ui auto* frame = pool->Acquire(); Common::LockGuard render_lock(g_render_ctx->GetMutex()); ConfigurePreparedFrame(frame, {width, height}, format); - const VkClearColorValue clear {{0.0f, 0.0f, 0.0f, opaque ? 1.0f : 0.0f}}; + vk::ClearColorValue clear {}; + clear.float32[3] = opaque ? 1.0f : 0.0f; UtilClearColorImage(buffer, &frame->image, clear); return frame; } @@ -452,18 +453,20 @@ void WindowPresentFrame(PreparedFrame* frame) { swapchain->current_index = static_cast(-1); - auto result = vkAcquireNextImageKHR( - g_window_ctx->graphic_ctx.device, swapchain->swapchain, UINT64_MAX, - swapchain->image_acquired_semaphores[present_frame], nullptr, &swapchain->current_index); + auto result = g_window_ctx->graphic_ctx.device.acquireNextImageKHR( + swapchain->swapchain, UINT64_MAX, swapchain->image_acquired_semaphores[present_frame], + nullptr, &swapchain->current_index); switch (result) { - case VK_SUCCESS: break; - case VK_SUBOPTIMAL_KHR: LOGF("vkAcquireNextImageKHR returned VK_SUBOPTIMAL_KHR\n"); break; - case VK_ERROR_OUT_OF_DATE_KHR: - LOGF("vkAcquireNextImageKHR returned VK_ERROR_OUT_OF_DATE_KHR\n"); + case vk::Result::eSuccess: break; + case vk::Result::eSuboptimalKHR: + LOGF("vkAcquireNextImageKHR returned vk::Result::eSuboptimalKHR\n"); + break; + case vk::Result::eErrorOutOfDateKHR: + LOGF("vkAcquireNextImageKHR returned vk::Result::eErrorOutOfDateKHR\n"); VulkanRecreateSwapchain(); return; - default: EXIT("vkAcquireNextImageKHR failed: %s\n", string_VkResult(result)); + default: EXIT("vkAcquireNextImageKHR failed: %s\n", VulkanToString(result).c_str()); } EXIT_NOT_IMPLEMENTED(swapchain->current_index == static_cast(-1)); if (frame->present_commands == nullptr) { @@ -472,41 +475,41 @@ void WindowPresentFrame(PreparedFrame* frame) { frame->present_commands->WaitForFenceAndReset(); auto& buffer = *frame->present_commands; - auto* vk_buffer = buffer.GetPool()->buffers[buffer.GetIndex()]; + auto vk_buffer = buffer.GetPool()->buffers[buffer.GetIndex()]; buffer.Begin(); UtilBlitPreparedImage(&buffer, &frame->image, swapchain); - VkImageMemoryBarrier pre_present_barrier {}; - pre_present_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + vk::ImageMemoryBarrier pre_present_barrier {}; + pre_present_barrier.sType = vk::StructureType::eImageMemoryBarrier; pre_present_barrier.pNext = nullptr; - pre_present_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - pre_present_barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; - pre_present_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - pre_present_barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + pre_present_barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite; + pre_present_barrier.dstAccessMask = vk::AccessFlagBits::eMemoryRead; + pre_present_barrier.oldLayout = vk::ImageLayout::eTransferDstOptimal; + pre_present_barrier.newLayout = vk::ImageLayout::ePresentSrcKHR; pre_present_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; pre_present_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - pre_present_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + pre_present_barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; pre_present_barrier.subresourceRange.baseMipLevel = 0; pre_present_barrier.subresourceRange.levelCount = 1; pre_present_barrier.subresourceRange.baseArrayLayer = 0; pre_present_barrier.subresourceRange.layerCount = 1; pre_present_barrier.image = swapchain->swapchain_images[swapchain->current_index]; - vkCmdPipelineBarrier(vk_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, - &pre_present_barrier); + vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eBottomOfPipe, vk::DependencyFlags {}, 0, + nullptr, 0, nullptr, 1, &pre_present_barrier); buffer.End(); auto render_complete_semaphore = swapchain->render_complete_semaphores[swapchain->current_index]; - const VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_TRANSFER_BIT; + const vk::PipelineStageFlags wait_stage = vk::PipelineStageFlagBits::eTransfer; buffer.ExecuteWithSemaphore(swapchain->image_acquired_semaphores[present_frame], wait_stage, render_complete_semaphore); - VkPresentInfoKHR present; - present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + vk::PresentInfoKHR present; + present.sType = vk::StructureType::ePresentInfoKHR; present.pNext = nullptr; present.swapchainCount = 1; present.pSwapchains = &swapchain->swapchain; @@ -520,18 +523,20 @@ void WindowPresentFrame(PreparedFrame* frame) { if (queue.mutex != nullptr) { queue.mutex->Lock(); } - result = vkQueuePresentKHR(queue.vk_queue, &present); + result = queue.vk_queue.presentKHR(&present); if (queue.mutex != nullptr) { queue.mutex->Unlock(); } switch (result) { - case VK_SUCCESS: break; - case VK_SUBOPTIMAL_KHR: LOGF("vkQueuePresentKHR returned VK_SUBOPTIMAL_KHR\n"); break; - case VK_ERROR_OUT_OF_DATE_KHR: - LOGF("vkQueuePresentKHR returned VK_ERROR_OUT_OF_DATE_KHR\n"); + case vk::Result::eSuccess: break; + case vk::Result::eSuboptimalKHR: + LOGF("vkQueuePresentKHR returned vk::Result::eSuboptimalKHR\n"); + break; + case vk::Result::eErrorOutOfDateKHR: + LOGF("vkQueuePresentKHR returned vk::Result::eErrorOutOfDateKHR\n"); VulkanRecreateSwapchain(); return; - default: EXIT("vkQueuePresentKHR failed: %s\n", string_VkResult(result)); + default: EXIT("vkQueuePresentKHR failed: %s\n", VulkanToString(result).c_str()); } swapchain->present_frame = (present_frame + 1u) % swapchain->swapchain_images_count; diff --git a/src/graphics/presentation/window/vulkanWindow.cpp b/src/graphics/presentation/window/vulkanWindow.cpp index ab96282b4..69a135dc8 100644 --- a/src/graphics/presentation/window/vulkanWindow.cpp +++ b/src/graphics/presentation/window/vulkanWindow.cpp @@ -30,6 +30,7 @@ #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/utils.h" #include "graphics/host_gpu/vma.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/renderDoc.h" #include "graphics/presentation/videoOut.h" #include "graphics/presentation/window.h" @@ -45,7 +46,6 @@ #include #include #include -#include #include // IWYU pragma: no_include @@ -58,13 +58,13 @@ namespace Libs::Graphics { struct VulkanExtensions { bool enable_validation_layers = false; - std::vector required_extensions; - std::vector available_extensions; - std::vector required_layers; - std::vector available_layers; + std::vector required_extensions; + std::vector available_extensions; + std::vector required_layers; + std::vector available_layers; }; -static bool HasExtension(const std::vector& extensions, const char* name) { +static bool HasExtension(const std::vector& extensions, const char* name) { return std::any_of(extensions.begin(), extensions.end(), [name](const auto& ext) { return strcmp(ext.extensionName, name) == 0; }); } @@ -74,54 +74,52 @@ static bool HasExtension(const std::vector& extensions, const char* [name](const char* ext) { return strcmp(ext, name) == 0; }); } -static bool HasLayer(const std::vector& layers, const char* name) { +static bool HasLayer(const std::vector& layers, const char* name) { return std::any_of(layers.begin(), layers.end(), [name](const auto& layer) { return strcmp(layer.layerName, name) == 0; }); } -void VulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, +void VulkanGetSurfaceCapabilities(vk::PhysicalDevice physical_device, vk::SurfaceKHR surface, SurfaceCapabilities* r) { - vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &r->capabilities); + physical_device.getSurfaceCapabilitiesKHR(surface, &r->capabilities); uint32_t formats_count = 0; - vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &formats_count, nullptr); + physical_device.getSurfaceFormatsKHR(surface, &formats_count, nullptr); EXIT_NOT_IMPLEMENTED(formats_count == 0); - r->formats = std::vector(formats_count); // @suppress("Ambiguous problem") - vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &formats_count, - r->formats.data()); + r->formats = std::vector(formats_count); // @suppress("Ambiguous problem") + physical_device.getSurfaceFormatsKHR(surface, &formats_count, r->formats.data()); uint32_t present_modes_count = 0; - vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &present_modes_count, - nullptr); + physical_device.getSurfacePresentModesKHR(surface, &present_modes_count, nullptr); EXIT_NOT_IMPLEMENTED(present_modes_count == 0); r->present_modes = - std::vector(present_modes_count); // @suppress("Ambiguous problem") - vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &present_modes_count, + std::vector(present_modes_count); // @suppress("Ambiguous problem") + physical_device.getSurfacePresentModesKHR(surface, &present_modes_count, r->present_modes.data()); r->format_srgb_bgra32 = false; for (const auto& f: r->formats) { - if (f.format == VK_FORMAT_B8G8R8A8_SRGB && - f.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) { + if (f.format == vk::Format::eB8G8R8A8Srgb && + f.colorSpace == vk::ColorSpaceKHR::eSrgbNonlinear) { r->format_srgb_bgra32 = true; break; } - if (f.format == VK_FORMAT_B8G8R8A8_UNORM && - f.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) { + if (f.format == vk::Format::eB8G8R8A8Unorm && + f.colorSpace == vk::ColorSpaceKHR::eSrgbNonlinear) { r->format_unorm_bgra32 = true; break; } } } -static bool CheckFormat(VkPhysicalDevice device, VkFormat format, bool tile, - VkFormatFeatureFlags features) { - VkFormatProperties format_props {}; - vkGetPhysicalDeviceFormatProperties(device, format, &format_props); +static bool CheckFormat(vk::PhysicalDevice device, vk::Format format, bool tile, + vk::FormatFeatureFlags features) { + vk::FormatProperties format_props {}; + device.getFormatProperties(format, &format_props); const auto supported_features = (tile ? format_props.optimalTilingFeatures : format_props.linearTilingFeatures); @@ -175,7 +173,7 @@ static void VulkanDumpQueues(const VulkanQueues& qs) { } } -static VulkanQueues VulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface, +static VulkanQueues VulkanFindQueues(vk::PhysicalDevice device, vk::SurfaceKHR surface, uint32_t graphics_num, uint32_t compute_num, uint32_t transfer_num, uint32_t present_num) { EXIT_IF(device == nullptr); @@ -184,28 +182,28 @@ static VulkanQueues VulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surfa VulkanQueues qs; uint32_t queue_family_count = 0; - vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, nullptr); - std::vector queue_families(queue_family_count); - vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, queue_families.data()); + device.getQueueFamilyProperties(&queue_family_count, nullptr); + std::vector queue_families(queue_family_count); + device.getQueueFamilyProperties(&queue_family_count, queue_families.data()); qs.family_count = queue_family_count; uint32_t family = 0; for (auto& f: queue_families) { - VkBool32 presentation_supported = VK_FALSE; - vkGetPhysicalDeviceSurfaceSupportKHR(device, family, surface, &presentation_supported); + vk::Bool32 presentation_supported = VK_FALSE; + device.getSurfaceSupportKHR(family, surface, &presentation_supported); LOGF("\tqueue family: %s [count = %u], [present = %s]\n", - string_VkQueueFlags(f.queueFlags).c_str(), f.queueCount, + VulkanToString(f.queueFlags).c_str(), f.queueCount, (presentation_supported == VK_TRUE ? "true" : "false")); for (uint32_t i = 0; i < f.queueCount; i++) { QueueInfo info; info.family = family; info.index = i; - info.graphics = (f.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0; - info.compute = (f.queueFlags & VK_QUEUE_COMPUTE_BIT) != 0; - info.transfer = (f.queueFlags & VK_QUEUE_TRANSFER_BIT) != 0; + info.graphics = static_cast(f.queueFlags & vk::QueueFlagBits::eGraphics); + info.compute = static_cast(f.queueFlags & vk::QueueFlagBits::eCompute); + info.transfer = static_cast(f.queueFlags & vk::QueueFlagBits::eTransfer); info.present = (presentation_supported == VK_TRUE); qs.available.push_back(info); @@ -253,10 +251,10 @@ static VulkanQueues VulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surfa } // NOLINTNEXTLINE(readability-function-cognitive-complexity) -static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, +static void VulkanFindPhysicalDevice(vk::Instance instance, vk::SurfaceKHR surface, const std::vector& device_extensions, SurfaceCapabilities* out_capabilities, - VkPhysicalDevice* out_device, VulkanQueues* out_queues) { + vk::PhysicalDevice* out_device, VulkanQueues* out_queues) { EXIT_IF(instance == nullptr); EXIT_IF(surface == nullptr); EXIT_IF(out_capabilities == nullptr); @@ -264,23 +262,23 @@ static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, EXIT_IF(out_queues == nullptr); uint32_t devices_count = 0; - vkEnumeratePhysicalDevices(instance, &devices_count, nullptr); + instance.enumeratePhysicalDevices(&devices_count, nullptr); EXIT_NOT_IMPLEMENTED(devices_count == 0); - std::vector devices(devices_count); - vkEnumeratePhysicalDevices(instance, &devices_count, devices.data()); + std::vector devices(devices_count); + instance.enumeratePhysicalDevices(&devices_count, devices.data()); - VkPhysicalDevice best_device = nullptr; - VulkanQueues best_queues; + vk::PhysicalDevice best_device = nullptr; + VulkanQueues best_queues; for (const auto& device: devices) { bool skip_device = false; - VkPhysicalDeviceProperties device_properties {}; - vkGetPhysicalDeviceProperties(device, &device_properties); + vk::PhysicalDeviceProperties device_properties {}; + device.getProperties(&device_properties); - LOGF("Vulkan device: %s\n", device_properties.deviceName); + LOGF("Vulkan device: %s\n", device_properties.deviceName.data()); if (device_properties.apiVersion < VULKAN_TARGET_API_VERSION) { LOGF("Vulkan %u.%u is required, but device supports only %u.%u.%u\n", VK_VERSION_MAJOR(VULKAN_TARGET_API_VERSION), @@ -291,30 +289,29 @@ static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, continue; } - VkPhysicalDeviceFeatures2 device_features2 {}; + vk::PhysicalDeviceFeatures2 device_features2 {}; - VkPhysicalDeviceVulkan13Features features13 {}; - features13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; + vk::PhysicalDeviceVulkan13Features features13 {}; + features13.sType = vk::StructureType::ePhysicalDeviceVulkan13Features; features13.pNext = nullptr; - VkPhysicalDeviceColorWriteEnableFeaturesEXT color_write_ext {}; - color_write_ext.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT; + vk::PhysicalDeviceColorWriteEnableFeaturesEXT color_write_ext {}; + color_write_ext.sType = vk::StructureType::ePhysicalDeviceColorWriteEnableFeaturesEXT; color_write_ext.pNext = nullptr; - VkPhysicalDeviceDepthClipControlFeaturesEXT depth_clip_control {}; - depth_clip_control.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT; + vk::PhysicalDeviceDepthClipControlFeaturesEXT depth_clip_control {}; + depth_clip_control.sType = vk::StructureType::ePhysicalDeviceDepthClipControlFeaturesEXT; depth_clip_control.pNext = &color_write_ext; - VkPhysicalDeviceVulkan12Features features12 {}; - features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; + vk::PhysicalDeviceVulkan12Features features12 {}; + features12.sType = vk::StructureType::ePhysicalDeviceVulkan12Features; features12.pNext = &depth_clip_control; features13.pNext = &features12; - device_features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + device_features2.sType = vk::StructureType::ePhysicalDeviceFeatures2; device_features2.pNext = &features13; - vkGetPhysicalDeviceFeatures2(device, &device_features2); + device.getFeatures2(&device_features2); auto qs = VulkanFindQueues( device, surface, GraphicContext::QUEUE_GFX_NUM, GraphicContext::QUEUE_COMPUTE_NUM, @@ -391,13 +388,13 @@ static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, if (!skip_device) { uint32_t extensions_count = 0; - vkEnumerateDeviceExtensionProperties(device, nullptr, &extensions_count, nullptr); + device.enumerateDeviceExtensionProperties(nullptr, &extensions_count, nullptr); EXIT_NOT_IMPLEMENTED(extensions_count == 0); - std::vector available_extensions(extensions_count); - vkEnumerateDeviceExtensionProperties(device, nullptr, &extensions_count, - available_extensions.data()); + std::vector available_extensions(extensions_count); + device.enumerateDeviceExtensionProperties(nullptr, &extensions_count, + available_extensions.data()); for (const char* ext: device_extensions) { if (!HasExtension(available_extensions, ext)) { @@ -408,7 +405,7 @@ static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, if (skip_device) { for (const auto& ext: available_extensions) { - LOGF("Vulkan available extension: %s, version = %u\n", ext.extensionName, + LOGF("Vulkan available extension: %s, version = %u\n", ext.extensionName.data(), ext.specVersion); } } @@ -417,87 +414,87 @@ static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, if (!skip_device) { VulkanGetSurfaceCapabilities(device, surface, out_capabilities); - if ((out_capabilities->capabilities.supportedUsageFlags & - VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) { + if (!(out_capabilities->capabilities.supportedUsageFlags & + vk::ImageUsageFlagBits::eTransferDst)) { LOGF("Surface cannot be destination of blit\n"); skip_device = true; } } - if (!skip_device && - !CheckFormat(device, VK_FORMAT_R8G8B8A8_SRGB, false, VK_FORMAT_FEATURE_BLIT_SRC_BIT)) { - LOGF("Format VK_FORMAT_R8G8B8A8_SRGB cannot be used as transfer source\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eR8G8B8A8Srgb, false, + vk::FormatFeatureFlagBits::eBlitSrc)) { + LOGF("Format vk::Format::eR8G8B8A8Srgb cannot be used as transfer source\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_D32_SFLOAT, true, - VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { - LOGF("Format VK_FORMAT_D32_SFLOAT cannot be used as depth buffer\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eD32Sfloat, true, + vk::FormatFeatureFlagBits::eDepthStencilAttachment)) { + LOGF("Format vk::Format::eD32Sfloat cannot be used as depth buffer\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_D32_SFLOAT_S8_UINT, true, - VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { - LOGF("Format VK_FORMAT_D32_SFLOAT_S8_UINT cannot be used as depth buffer\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eD32SfloatS8Uint, true, + vk::FormatFeatureFlagBits::eDepthStencilAttachment)) { + LOGF("Format vk::Format::eD32SfloatS8Uint cannot be used as depth buffer\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_D16_UNORM, true, - VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { - LOGF("Format VK_FORMAT_D16_UNORM cannot be used as depth buffer\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eD16Unorm, true, + vk::FormatFeatureFlagBits::eDepthStencilAttachment)) { + LOGF("Format vk::Format::eD16Unorm cannot be used as depth buffer\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_BC3_SRGB_BLOCK, true, - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_BC3_SRGB_BLOCK cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eBc3SrgbBlock, true, + vk::FormatFeatureFlagBits::eSampledImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eBc3SrgbBlock cannot be used as texture\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_R8G8B8A8_SRGB, true, - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_R8G8B8A8_SRGB cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eR8G8B8A8Srgb, true, + vk::FormatFeatureFlagBits::eSampledImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eR8G8B8A8Srgb cannot be used as texture\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_R8_UNORM, true, - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_R8_UNORM cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eR8Unorm, true, + vk::FormatFeatureFlagBits::eSampledImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eR8Unorm cannot be used as texture\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_R8G8_UNORM, true, - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_R8G8_UNORM cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eR8G8Unorm, true, + vk::FormatFeatureFlagBits::eSampledImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eR8G8Unorm cannot be used as texture\n"); skip_device = true; } - if (!skip_device && !CheckFormat(device, VK_FORMAT_R8G8B8A8_SRGB, true, - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_R8G8B8A8_SRGB cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eR8G8B8A8Srgb, true, + vk::FormatFeatureFlagBits::eStorageImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eR8G8B8A8Srgb cannot be used as texture\n"); - if (!skip_device && !CheckFormat(device, VK_FORMAT_R8G8B8A8_UNORM, true, - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_R8G8B8A8_UNORM cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eR8G8B8A8Unorm, true, + vk::FormatFeatureFlagBits::eStorageImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eR8G8B8A8Unorm cannot be used as texture\n"); skip_device = true; } } - if (!skip_device && !CheckFormat(device, VK_FORMAT_B8G8R8A8_SRGB, true, - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_B8G8R8A8_SRGB cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eB8G8R8A8Srgb, true, + vk::FormatFeatureFlagBits::eStorageImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eB8G8R8A8Srgb cannot be used as texture\n"); - if (!skip_device && !CheckFormat(device, VK_FORMAT_B8G8R8A8_UNORM, true, - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) { - LOGF("Format VK_FORMAT_B8G8R8A8_UNORM cannot be used as texture\n"); + if (!skip_device && !CheckFormat(device, vk::Format::eB8G8R8A8Unorm, true, + vk::FormatFeatureFlagBits::eStorageImage | + vk::FormatFeatureFlagBits::eTransferDst)) { + LOGF("Format vk::Format::eB8G8R8A8Unorm cannot be used as texture\n"); skip_device = true; } } @@ -512,7 +509,7 @@ static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, } if (best_device == nullptr || - device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { + device_properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) { best_device = device; best_queues = qs; } @@ -522,34 +519,33 @@ static void VulkanFindPhysicalDevice(VkInstance instance, VkSurfaceKHR surface, *out_queues = best_queues; } -static void VulkanInitSubgroupSizeControl(VkPhysicalDevice physical_device, GraphicContext* ctx) { +static void VulkanInitSubgroupSizeControl(vk::PhysicalDevice physical_device, GraphicContext* ctx) { EXIT_IF(physical_device == nullptr); EXIT_IF(ctx == nullptr); - VkPhysicalDeviceSubgroupSizeControlProperties subgroup_size_control {}; - subgroup_size_control.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES; + vk::PhysicalDeviceSubgroupSizeControlProperties subgroup_size_control {}; + subgroup_size_control.sType = vk::StructureType::ePhysicalDeviceSubgroupSizeControlProperties; subgroup_size_control.pNext = nullptr; - VkPhysicalDeviceVulkan11Properties properties11 {}; - properties11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES; + vk::PhysicalDeviceVulkan11Properties properties11 {}; + properties11.sType = vk::StructureType::ePhysicalDeviceVulkan11Properties; properties11.pNext = &subgroup_size_control; - VkPhysicalDeviceProperties2 properties2 {}; - properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; + vk::PhysicalDeviceProperties2 properties2 {}; + properties2.sType = vk::StructureType::ePhysicalDeviceProperties2; properties2.pNext = &properties11; - vkGetPhysicalDeviceProperties2(physical_device, &properties2); + physical_device.getProperties2(&properties2); - VkPhysicalDeviceVulkan13Features features13 {}; - features13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; + vk::PhysicalDeviceVulkan13Features features13 {}; + features13.sType = vk::StructureType::ePhysicalDeviceVulkan13Features; features13.pNext = nullptr; - VkPhysicalDeviceFeatures2 features2 {}; - features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + vk::PhysicalDeviceFeatures2 features2 {}; + features2.sType = vk::StructureType::ePhysicalDeviceFeatures2; features2.pNext = &features13; - vkGetPhysicalDeviceFeatures2(physical_device, &features2); + physical_device.getFeatures2(&features2); ctx->subgroup_size = properties11.subgroupSize; ctx->min_subgroup_size = subgroup_size_control.minSubgroupSize; @@ -561,21 +557,22 @@ static void VulkanInitSubgroupSizeControl(VkPhysicalDevice physical_device, Grap LOGF("Vulkan subgroup: default=%u min=%u max=%u stages=0x%08x size_control=%s\n", ctx->subgroup_size, ctx->min_subgroup_size, ctx->max_subgroup_size, - ctx->required_subgroup_size_stages, ctx->subgroup_size_control_enabled ? "true" : "false"); + static_cast(ctx->required_subgroup_size_stages), + ctx->subgroup_size_control_enabled ? "true" : "false"); } -static VkDevice VulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, - const VulkanExtensions* r, const VulkanQueues& queues, - const std::vector& device_extensions, - const GraphicContext* ctx) { +static vk::Device VulkanCreateDevice(vk::PhysicalDevice physical_device, vk::SurfaceKHR surface, + const VulkanExtensions* r, const VulkanQueues& queues, + const std::vector& device_extensions, + const GraphicContext* ctx) { EXIT_IF(physical_device == nullptr); EXIT_IF(r == nullptr); EXIT_IF(surface == nullptr); EXIT_IF(ctx == nullptr); - std::vector queue_create_info(queues.family_count); - std::vector> queue_priority(queues.family_count); - uint32_t queue_create_info_num = 0; + std::vector queue_create_info(queues.family_count); + std::vector> queue_priority(queues.family_count); + uint32_t queue_create_info_num = 0; for (uint32_t i = 0; i < queues.family_count; i++) { if (queues.family_used[i] != 0) { @@ -584,9 +581,9 @@ static VkDevice VulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKH } queue_create_info[queue_create_info_num].sType = - VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + vk::StructureType::eDeviceQueueCreateInfo; queue_create_info[queue_create_info_num].pNext = nullptr; - queue_create_info[queue_create_info_num].flags = 0; + queue_create_info[queue_create_info_num].flags = {}; queue_create_info[queue_create_info_num].queueFamilyIndex = i; queue_create_info[queue_create_info_num].queueCount = queues.family_used[i]; queue_create_info[queue_create_info_num].pQueuePriorities = @@ -596,45 +593,45 @@ static VkDevice VulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKH } } - VkPhysicalDeviceColorWriteEnableFeaturesEXT color_write_ext {}; - color_write_ext.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT; + vk::PhysicalDeviceColorWriteEnableFeaturesEXT color_write_ext {}; + color_write_ext.sType = vk::StructureType::ePhysicalDeviceColorWriteEnableFeaturesEXT; color_write_ext.pNext = nullptr; color_write_ext.colorWriteEnable = VK_TRUE; - VkPhysicalDeviceDepthClipControlFeaturesEXT depth_clip_control {}; - depth_clip_control.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT; + vk::PhysicalDeviceDepthClipControlFeaturesEXT depth_clip_control {}; + depth_clip_control.sType = vk::StructureType::ePhysicalDeviceDepthClipControlFeaturesEXT; depth_clip_control.pNext = &color_write_ext; depth_clip_control.depthClipControl = VK_TRUE; - VkPhysicalDeviceVulkan12Features features12 {}; - features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; + vk::PhysicalDeviceVulkan12Features features12 {}; + features12.sType = vk::StructureType::ePhysicalDeviceVulkan12Features; features12.pNext = &depth_clip_control; features12.samplerMirrorClampToEdge = VK_TRUE; - VkPhysicalDeviceSubgroupSizeControlFeatures subgroup_size_control {}; - subgroup_size_control.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES; + vk::PhysicalDeviceSubgroupSizeControlFeatures subgroup_size_control {}; + subgroup_size_control.sType = vk::StructureType::ePhysicalDeviceSubgroupSizeControlFeatures; subgroup_size_control.pNext = &features12; - VkPhysicalDeviceVulkan13Features supported_features13 {}; - supported_features13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; + vk::PhysicalDeviceVulkan13Features supported_features13 {}; + supported_features13.sType = vk::StructureType::ePhysicalDeviceVulkan13Features; supported_features13.pNext = nullptr; const auto robustness2_ext_enabled = HasExtension(device_extensions, VK_EXT_ROBUSTNESS_2_EXTENSION_NAME); - VkPhysicalDeviceRobustness2FeaturesEXT supported_robustness2 {}; - supported_robustness2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT; + vk::PhysicalDeviceRobustness2FeaturesEXT supported_robustness2 {}; + supported_robustness2.sType = vk::StructureType::ePhysicalDeviceRobustness2FeaturesEXT; supported_robustness2.pNext = nullptr; if (robustness2_ext_enabled) { supported_features13.pNext = &supported_robustness2; } - VkPhysicalDeviceFeatures2 supported_features2 {}; - supported_features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + vk::PhysicalDeviceFeatures2 supported_features2 {}; + supported_features2.sType = vk::StructureType::ePhysicalDeviceFeatures2; supported_features2.pNext = &supported_features13; - vkGetPhysicalDeviceFeatures2(physical_device, &supported_features2); + physical_device.getFeatures2(&supported_features2); - VkPhysicalDeviceFeatures device_features {}; + vk::PhysicalDeviceFeatures device_features {}; device_features.fragmentStoresAndAtomics = VK_TRUE; device_features.samplerAnisotropy = VK_TRUE; device_features.robustBufferAccess = VK_TRUE; @@ -655,8 +652,8 @@ static VkDevice VulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKH ? static_cast(&subgroup_size_control) : static_cast(&features12)); - VkPhysicalDeviceRobustness2FeaturesEXT robustness2 {}; - robustness2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT; + vk::PhysicalDeviceRobustness2FeaturesEXT robustness2 {}; + robustness2.sType = vk::StructureType::ePhysicalDeviceRobustness2FeaturesEXT; robustness2.pNext = const_cast(base_feature_chain); if (robustness2_ext_enabled) { robustness2.robustBufferAccess2 = supported_robustness2.robustBufferAccess2; @@ -664,8 +661,8 @@ static VkDevice VulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKH robustness2.nullDescriptor = supported_robustness2.nullDescriptor; } - VkPhysicalDeviceVulkan13Features features13 {}; - features13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; + vk::PhysicalDeviceVulkan13Features features13 {}; + features13.sType = vk::StructureType::ePhysicalDeviceVulkan13Features; features13.pNext = robustness2_ext_enabled ? &robustness2 : const_cast(base_feature_chain); features13.robustImageAccess = supported_features13.robustImageAccess; @@ -674,10 +671,10 @@ static VkDevice VulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKH features13.robustImageAccess == VK_TRUE ? "true" : "false", robustness2_ext_enabled && robustness2.robustImageAccess2 == VK_TRUE ? "true" : "false"); - VkDeviceCreateInfo create_info {}; - create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + vk::DeviceCreateInfo create_info {}; + create_info.sType = vk::StructureType::eDeviceCreateInfo; create_info.pNext = &features13; - create_info.flags = 0; + create_info.flags = {}; create_info.pQueueCreateInfos = queue_create_info.data(); create_info.queueCreateInfoCount = queue_create_info_num; create_info.enabledLayerCount = @@ -688,11 +685,11 @@ static VkDevice VulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKH create_info.ppEnabledExtensionNames = device_extensions.data(); create_info.pEnabledFeatures = &device_features; - VkDevice device = nullptr; + vk::Device device = nullptr; - auto result = vkCreateDevice(physical_device, &create_info, nullptr, &device); - if (result != VK_SUCCESS) { - LOGF("vkCreateDevice failed: %s\n", string_VkResult(result)); + auto result = physical_device.createDevice(&create_info, nullptr, &device); + if (result != vk::Result::eSuccess) { + LOGF("vkCreateDevice failed: %s\n", VulkanToString(result).c_str()); return nullptr; } @@ -724,15 +721,15 @@ static void VulkanGetExtensions(SDL_Window* window, VulkanExtensions* r) { EXIT_NOT_IMPLEMENTED(required_extensions_count == 0); EXIT_NOT_IMPLEMENTED(required_extensions_count != r->required_extensions.size()); - vkEnumerateInstanceExtensionProperties(nullptr, &available_extensions_count, nullptr); + vk::enumerateInstanceExtensionProperties(nullptr, &available_extensions_count, nullptr); - r->available_extensions = std::vector( + r->available_extensions = std::vector( available_extensions_count); // @suppress("Ambiguous problem") std::memset(r->available_extensions.data(), 0, - sizeof(VkExtensionProperties) * r->available_extensions.size()); + sizeof(vk::ExtensionProperties) * r->available_extensions.size()); - vkEnumerateInstanceExtensionProperties(nullptr, &available_extensions_count, - r->available_extensions.data()); + vk::enumerateInstanceExtensionProperties(nullptr, &available_extensions_count, + r->available_extensions.data()); EXIT_NOT_IMPLEMENTED(available_extensions_count != r->available_extensions.size()); @@ -749,22 +746,23 @@ static void VulkanGetExtensions(SDL_Window* window, VulkanExtensions* r) { } for (const auto& ext: r->available_extensions) { - LOGF("Vulkan available extension: %s, version = %u\n", ext.extensionName, ext.specVersion); + LOGF("Vulkan available extension: %s, version = %u\n", ext.extensionName.data(), + ext.specVersion); } - vkEnumerateInstanceLayerProperties(&available_layers_count, nullptr); + vk::enumerateInstanceLayerProperties(&available_layers_count, nullptr); r->available_layers = - std::vector(available_layers_count); // @suppress("Ambiguous problem") + std::vector(available_layers_count); // @suppress("Ambiguous problem") std::memset(r->available_layers.data(), 0, - sizeof(VkLayerProperties) * r->available_layers.size()); - vkEnumerateInstanceLayerProperties(&available_layers_count, r->available_layers.data()); + sizeof(vk::LayerProperties) * r->available_layers.size()); + vk::enumerateInstanceLayerProperties(&available_layers_count, r->available_layers.data()); EXIT_NOT_IMPLEMENTED(available_layers_count != r->available_layers.size()); for (const auto& l: r->available_layers) { - LOGF("Vulkan available layer: %s, specVersion = %u, implVersion = %u, %s\n", l.layerName, - l.specVersion, l.implementationVersion, l.description); + LOGF("Vulkan available layer: %s, specVersion = %u, implVersion = %u, %s\n", + l.layerName.data(), l.specVersion, l.implementationVersion, l.description.data()); } r->required_layers = {"VK_LAYER_KHRONOS_validation"}; @@ -780,18 +778,18 @@ static void VulkanGetExtensions(SDL_Window* window, VulkanExtensions* r) { } if (r->enable_validation_layers) { - vkEnumerateInstanceExtensionProperties("VK_LAYER_KHRONOS_validation", - &available_extensions_count, nullptr); + vk::enumerateInstanceExtensionProperties("VK_LAYER_KHRONOS_validation", + &available_extensions_count, nullptr); - std::vector available_extensions(available_extensions_count); + std::vector available_extensions(available_extensions_count); - vkEnumerateInstanceExtensionProperties("VK_LAYER_KHRONOS_validation", - &available_extensions_count, - available_extensions.data()); + vk::enumerateInstanceExtensionProperties("VK_LAYER_KHRONOS_validation", + &available_extensions_count, + available_extensions.data()); for (const auto& ext: available_extensions) { LOGF("VK_LAYER_KHRONOS_validation available extension: %s, version = %u\n", - ext.extensionName, ext.specVersion); + ext.extensionName.data(), ext.specVersion); } if (HasExtension(available_extensions, VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME)) { @@ -802,10 +800,10 @@ static void VulkanGetExtensions(SDL_Window* window, VulkanExtensions* r) { } } -static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugMessengerCallback( - VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, - VkDebugUtilsMessageTypeFlagsEXT message_types, - const VkDebugUtilsMessengerCallbackDataEXT* callback_data, void* /*user_data*/) { +static VKAPI_ATTR vk::Bool32 VKAPI_CALL VulkanDebugMessengerCallback( + vk::DebugUtilsMessageSeverityFlagBitsEXT message_severity, + vk::DebugUtilsMessageTypeFlagsEXT message_types, + const vk::DebugUtilsMessengerCallbackDataEXT* callback_data, void* /*user_data*/) { EXIT_IF(callback_data == nullptr); EXIT_IF(callback_data->pMessage == nullptr); @@ -815,13 +813,13 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugMessengerCallback( bool error = false; bool debug_printf = false; switch (message_severity) { - case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose: severity_str = "V"; severity_style = Log::Color::BrightWhite; skip = true; break; - case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: - if ((message_types & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) != 0 && + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo: + if ((message_types & vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation) && Config::SpirvDebugPrintfEnabled() && callback_data->pMessageIdName != nullptr && strcmp(callback_data->pMessageIdName, "UNASSIGNED-DEBUG-PRINTF") == 0) { debug_printf = true; @@ -833,16 +831,17 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugMessengerCallback( skip = true; } break; - case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning: severity_str = "W"; severity_style = Log::Color::Red; break; - case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: + case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError: severity_str = "E"; severity_style = Log::Color::BrightRed; // Only validation errors are fatal; GENERAL-type errors can come // from unrelated loader/layer issues (e.g. a broken overlay). - error = (message_types & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) != 0; + error = static_cast(message_types & + vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation); break; default: severity_str = "?"; } @@ -867,17 +866,15 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugMessengerCallback( return VK_FALSE; } -static VKAPI_ATTR VkResult VKAPI_CALL VulkanCreateDebugUtilsMessengerEXT( - VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* create_info, - const VkAllocationCallbacks* allocator, VkDebugUtilsMessengerEXT* messenger) { +static VKAPI_ATTR vk::Result VKAPI_CALL VulkanCreateDebugUtilsMessengerEXT( + vk::Instance instance, const vk::DebugUtilsMessengerCreateInfoEXT* create_info, + const vk::AllocationCallbacks* allocator, vk::DebugUtilsMessengerEXT* messenger) { EXIT_IF(instance == nullptr); - if (auto func = reinterpret_cast( - vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT")); - func != nullptr) { - return func(instance, create_info, allocator, messenger); + if (auto func = VULKAN_HPP_DEFAULT_DISPATCHER.vkCreateDebugUtilsMessengerEXT; func != nullptr) { + return instance.createDebugUtilsMessengerEXT(create_info, allocator, messenger); } - return VK_ERROR_EXTENSION_NOT_PRESENT; + return vk::Result::eErrorExtensionNotPresent; } static void VulkanCreateQueues(GraphicContext* ctx, const VulkanQueues& queues) { @@ -893,8 +890,8 @@ static void VulkanCreateQueues(GraphicContext* ctx, const VulkanQueues& queues) ctx->queues[id].family = info.family; ctx->queues[id].index = info.index; EXIT_IF(ctx->queues[id].vk_queue != nullptr); - vkGetDeviceQueue(ctx->device, ctx->queues[id].family, ctx->queues[id].index, - &ctx->queues[id].vk_queue); + ctx->device.getQueue(ctx->queues[id].family, ctx->queues[id].index, + &ctx->queues[id].vk_queue); EXIT_NOT_IMPLEMENTED(ctx->queues[id].vk_queue == nullptr); if (with_mutex) { ctx->queues[id].mutex = new Common::Mutex; @@ -947,12 +944,10 @@ static void VulkanCreateQueues(GraphicContext* ctx, const VulkanQueues& queues) static void VulkanCheckInstanceVersion() { uint32_t version = VK_API_VERSION_1_0; - auto enumerate_instance_version = reinterpret_cast( - vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion")); - if (enumerate_instance_version != nullptr) { - auto result = enumerate_instance_version(&version); - if (result != VK_SUCCESS) { - EXIT("Could not query Vulkan loader version: %s\n", string_VkResult(result)); + if (VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion != nullptr) { + auto result = vk::enumerateInstanceVersion(&version); + if (result != vk::Result::eSuccess) { + EXIT("Could not query Vulkan loader version: %s\n", VulkanToString(result).c_str()); } } @@ -973,12 +968,19 @@ void VulkanCreate(WindowContext* ctx) { EXIT_IF(ctx->graphic_ctx.device != nullptr); EXIT_IF(ctx->surface_capabilities != nullptr); + auto get_instance_proc_addr = + reinterpret_cast(SDL_Vulkan_GetVkGetInstanceProcAddr()); + if (get_instance_proc_addr == nullptr) { + EXIT("Could not load Vulkan: %s\n", SDL_GetError()); + } + VULKAN_HPP_DEFAULT_DISPATCHER.init(get_instance_proc_addr); + VulkanExtensions r; VulkanGetExtensions(ctx->window, &r); VulkanCheckInstanceVersion(); - VkApplicationInfo app_info {}; - app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + vk::ApplicationInfo app_info {}; + app_info.sType = vk::StructureType::eApplicationInfo; app_info.pNext = nullptr; app_info.pApplicationName = "Kyty"; app_info.applicationVersion = 1; @@ -986,17 +988,17 @@ void VulkanCreate(WindowContext* ctx) { app_info.engineVersion = 1; app_info.apiVersion = VULKAN_TARGET_API_VERSION; // NOLINT - VkValidationFeatureEnableEXT enabled_features[] = { + vk::ValidationFeatureEnableEXT enabled_features[] = { #ifdef KYTY_ENABLE_BEST_PRACTICES - VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT, + vk::ValidationFeatureEnableEXT::eBestPractices, #endif #ifdef KYTY_ENABLE_DEBUG_PRINTF - VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT, + vk::ValidationFeatureEnableEXT::eDebugPrintf, #endif }; uint32_t enabled_features_count = - sizeof(enabled_features) / sizeof(VkValidationFeatureEnableEXT); + sizeof(enabled_features) / sizeof(vk::ValidationFeatureEnableEXT); #ifdef KYTY_ENABLE_DEBUG_PRINTF if (!Config::SpirvDebugPrintfEnabled()) { @@ -1004,34 +1006,32 @@ void VulkanCreate(WindowContext* ctx) { } #endif - VkValidationFeaturesEXT validation_features {}; - validation_features.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT; + vk::ValidationFeaturesEXT validation_features {}; + validation_features.sType = vk::StructureType::eValidationFeaturesEXT; validation_features.pNext = nullptr; validation_features.enabledValidationFeatureCount = enabled_features_count; validation_features.pEnabledValidationFeatures = enabled_features; validation_features.disabledValidationFeatureCount = 0; validation_features.pDisabledValidationFeatures = nullptr; - VkDebugUtilsMessengerCreateInfoEXT dbg_create_info {}; - dbg_create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; - dbg_create_info.pNext = &validation_features; - dbg_create_info.flags = 0; - dbg_create_info.messageSeverity = - static_cast(VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) | - static_cast(VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) | - static_cast(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) | - static_cast(VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT); - dbg_create_info.messageType = - static_cast(VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) | - static_cast(VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) | - static_cast(VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT); + vk::DebugUtilsMessengerCreateInfoEXT dbg_create_info {}; + dbg_create_info.sType = vk::StructureType::eDebugUtilsMessengerCreateInfoEXT; + dbg_create_info.pNext = &validation_features; + dbg_create_info.flags = {}; + dbg_create_info.messageSeverity = vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose | + vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo | + vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | + vk::DebugUtilsMessageSeverityFlagBitsEXT::eError; + dbg_create_info.messageType = vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | + vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | + vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance; dbg_create_info.pfnUserCallback = VulkanDebugMessengerCallback; dbg_create_info.pUserData = nullptr; - VkInstanceCreateInfo inst_info {}; - inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + vk::InstanceCreateInfo inst_info {}; + inst_info.sType = vk::StructureType::eInstanceCreateInfo; inst_info.pNext = (r.enable_validation_layers ? &dbg_create_info : nullptr); - inst_info.flags = 0; + inst_info.flags = {}; inst_info.pApplicationInfo = &app_info; inst_info.enabledExtensionCount = static_cast(r.required_extensions.size()); inst_info.ppEnabledExtensionNames = r.required_extensions.data(); @@ -1040,25 +1040,31 @@ void VulkanCreate(WindowContext* ctx) { inst_info.ppEnabledLayerNames = (r.enable_validation_layers ? r.required_layers.data() : nullptr); - const VkResult result = vkCreateInstance(&inst_info, nullptr, &ctx->graphic_ctx.instance); + const vk::Result result = vk::createInstance(&inst_info, nullptr, &ctx->graphic_ctx.instance); switch (result) { - case VK_SUCCESS: break; - case VK_ERROR_INCOMPATIBLE_DRIVER: EXIT("Unable to find a compatible Vulkan Driver"); + case vk::Result::eSuccess: break; + case vk::Result::eErrorIncompatibleDriver: + EXIT("Unable to find a compatible Vulkan Driver"); default: EXIT("Could not create a Vulkan instance (for unknown reasons)"); } + VULKAN_HPP_DEFAULT_DISPATCHER.init(ctx->graphic_ctx.instance); if (r.enable_validation_layers) { dbg_create_info.pNext = nullptr; if (VulkanCreateDebugUtilsMessengerEXT(ctx->graphic_ctx.instance, &dbg_create_info, nullptr, - &ctx->graphic_ctx.debug_messenger) != VK_SUCCESS) { + &ctx->graphic_ctx.debug_messenger) != + vk::Result::eSuccess) { EXIT("Could not create debug messenger"); } } - if (SDL_Vulkan_CreateSurface(ctx->window, ctx->graphic_ctx.instance, &ctx->surface) == - SDL_FALSE) { + vk::SurfaceKHR::CType native_surface = VK_NULL_HANDLE; + if (SDL_Vulkan_CreateSurface(ctx->window, + static_cast(ctx->graphic_ctx.instance), + &native_surface) == SDL_FALSE) { EXIT("Could not create a Vulkan surface"); } + ctx->surface = native_surface; std::vector device_extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME, @@ -1082,22 +1088,21 @@ void VulkanCreate(WindowContext* ctx) { EXIT("Could not find suitable device"); } - vkGetPhysicalDeviceProperties(ctx->graphic_ctx.physical_device, - &ctx->graphic_ctx.physical_device_properties); - vkGetPhysicalDeviceMemoryProperties(ctx->graphic_ctx.physical_device, - &ctx->graphic_ctx.physical_device_memory_properties); + ctx->graphic_ctx.physical_device.getProperties(&ctx->graphic_ctx.physical_device_properties); + ctx->graphic_ctx.physical_device.getMemoryProperties( + &ctx->graphic_ctx.physical_device_memory_properties); const auto& device_properties = ctx->graphic_ctx.GetPhysicalDeviceProperties(); - LOGF("Select device: %s\n", device_properties.deviceName); + LOGF("Select device: %s\n", device_properties.deviceName.data()); { uint32_t extensions_count = 0; - vkEnumerateDeviceExtensionProperties(ctx->graphic_ctx.physical_device, nullptr, - &extensions_count, nullptr); + ctx->graphic_ctx.physical_device.enumerateDeviceExtensionProperties( + nullptr, &extensions_count, nullptr); - std::vector available_extensions(extensions_count); - vkEnumerateDeviceExtensionProperties(ctx->graphic_ctx.physical_device, nullptr, - &extensions_count, available_extensions.data()); + std::vector available_extensions(extensions_count); + ctx->graphic_ctx.physical_device.enumerateDeviceExtensionProperties( + nullptr, &extensions_count, available_extensions.data()); if (HasExtension(available_extensions, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) { device_extensions.push_back(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME); @@ -1119,6 +1124,7 @@ void VulkanCreate(WindowContext* ctx) { if (ctx->graphic_ctx.device == nullptr) { EXIT("Could not create device"); } + VULKAN_HPP_DEFAULT_DISPATCHER.init(ctx->graphic_ctx.device); if (!VulkanCreateAllocator(&ctx->graphic_ctx)) { EXIT("Could not create Vulkan memory allocator"); diff --git a/src/graphics/presentation/window/window.cpp b/src/graphics/presentation/window/window.cpp index ae5285990..58b8624ef 100644 --- a/src/graphics/presentation/window/window.cpp +++ b/src/graphics/presentation/window/window.cpp @@ -32,6 +32,7 @@ #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/utils.h" #include "graphics/host_gpu/vma.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/presentation/renderDoc.h" #include "graphics/presentation/videoOut.h" #include "graphics/presentation/window/windowInternal.h" @@ -45,7 +46,6 @@ #include #include #include -#include #include #define STB_IMAGE_IMPLEMENTATION @@ -1035,7 +1035,7 @@ void WindowRun() { std::_Exit(0); } -VkSurfaceCapabilitiesKHR* VulkanGetSurfaceCapabilities() { +vk::SurfaceCapabilitiesKHR* VulkanGetSurfaceCapabilities() { EXIT_IF(g_window_ctx == nullptr); Common::LockGuard lock(g_window_ctx->mutex); diff --git a/src/graphics/presentation/window/windowInternal.h b/src/graphics/presentation/window/windowInternal.h index 45f37b0ad..f2e0c78ee 100644 --- a/src/graphics/presentation/window/windowInternal.h +++ b/src/graphics/presentation/window/windowInternal.h @@ -4,21 +4,21 @@ #include "SDL_video.h" #include "common/threads.h" #include "graphics/host_gpu/graphicContext.h" +#include "graphics/host_gpu/vulkanCommon.h" #include #include -#include namespace Libs::Graphics { struct WindowGame; struct SurfaceCapabilities { - VkSurfaceCapabilitiesKHR capabilities {}; - std::vector formats; - std::vector present_modes; - bool format_srgb_bgra32 = false; - bool format_unorm_bgra32 = false; + vk::SurfaceCapabilitiesKHR capabilities {}; + std::vector formats; + std::vector present_modes; + bool format_srgb_bgra32 = false; + bool format_unorm_bgra32 = false; }; struct WindowContext { @@ -26,7 +26,7 @@ struct WindowContext { VulkanSwapchain* swapchain = nullptr; SDL_Window* window = nullptr; bool window_hidden = true; - VkSurfaceKHR surface = nullptr; + vk::SurfaceKHR surface = nullptr; SurfaceCapabilities* surface_capabilities = nullptr; WindowGame* game = nullptr; @@ -40,7 +40,7 @@ struct WindowContext { extern WindowContext* g_window_ctx; -void VulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, +void VulkanGetSurfaceCapabilities(vk::PhysicalDevice physical_device, vk::SurfaceKHR surface, SurfaceCapabilities* capabilities); VulkanSwapchain* VulkanCreateSwapchain(GraphicContext* ctx, uint32_t image_count); void VulkanCreate(WindowContext* ctx); diff --git a/src/graphics/rt/hardware.cpp b/src/graphics/rt/hardware.cpp index 80b00a71a..aa9cbee91 100644 --- a/src/graphics/rt/hardware.cpp +++ b/src/graphics/rt/hardware.cpp @@ -9,7 +9,7 @@ namespace Libs::Graphics::Rt { namespace { -bool ExtensionAvailable(const std::vector& available, const char* name) { +bool ExtensionAvailable(const std::vector& available, const char* name) { return std::ranges::any_of(available, [name](const auto& extension) { return std::strcmp(extension.extensionName, name) == 0; }); @@ -26,7 +26,7 @@ void AppendExtensionIfMissing(std::vector& extensions, const char* } // namespace void AppendHardwareRayTracingDeviceExtensions( - const std::vector& available_extensions, + const std::vector& available_extensions, std::vector* device_extensions, GraphicContext* ctx) { EXIT_IF(device_extensions == nullptr || ctx == nullptr); @@ -64,33 +64,13 @@ void LoadHardwareRayTracingFunctions(GraphicContext* ctx) { return; } - ctx->vkGetBufferDeviceAddressKHR = reinterpret_cast( - vkGetDeviceProcAddr(ctx->device, "vkGetBufferDeviceAddressKHR")); - if (ctx->vkGetBufferDeviceAddressKHR == nullptr) { - ctx->vkGetBufferDeviceAddressKHR = reinterpret_cast( - vkGetDeviceProcAddr(ctx->device, "vkGetBufferDeviceAddress")); - } - ctx->vkCreateAccelerationStructureKHR = reinterpret_cast( - vkGetDeviceProcAddr(ctx->device, "vkCreateAccelerationStructureKHR")); - ctx->vkDestroyAccelerationStructureKHR = - reinterpret_cast( - vkGetDeviceProcAddr(ctx->device, "vkDestroyAccelerationStructureKHR")); - ctx->vkGetAccelerationStructureBuildSizesKHR = - reinterpret_cast( - vkGetDeviceProcAddr(ctx->device, "vkGetAccelerationStructureBuildSizesKHR")); - ctx->vkCmdBuildAccelerationStructuresKHR = - reinterpret_cast( - vkGetDeviceProcAddr(ctx->device, "vkCmdBuildAccelerationStructuresKHR")); - ctx->vkGetAccelerationStructureDeviceAddressKHR = - reinterpret_cast( - vkGetDeviceProcAddr(ctx->device, "vkGetAccelerationStructureDeviceAddressKHR")); - - if (ctx->vkGetBufferDeviceAddressKHR == nullptr || - ctx->vkCreateAccelerationStructureKHR == nullptr || - ctx->vkDestroyAccelerationStructureKHR == nullptr || - ctx->vkGetAccelerationStructureBuildSizesKHR == nullptr || - ctx->vkCmdBuildAccelerationStructuresKHR == nullptr || - ctx->vkGetAccelerationStructureDeviceAddressKHR == nullptr) { + const auto& dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER; + if (dispatcher.vkGetBufferDeviceAddressKHR == nullptr || + dispatcher.vkCreateAccelerationStructureKHR == nullptr || + dispatcher.vkDestroyAccelerationStructureKHR == nullptr || + dispatcher.vkGetAccelerationStructureBuildSizesKHR == nullptr || + dispatcher.vkCmdBuildAccelerationStructuresKHR == nullptr || + dispatcher.vkGetAccelerationStructureDeviceAddressKHR == nullptr) { EXIT("Vulkan RT: failed to load required device functions\n"); } } diff --git a/src/graphics/rt/hardware.h b/src/graphics/rt/hardware.h index 936615f52..ced5652c9 100644 --- a/src/graphics/rt/hardware.h +++ b/src/graphics/rt/hardware.h @@ -10,7 +10,7 @@ namespace Libs::Graphics { namespace Rt { void AppendHardwareRayTracingDeviceExtensions( - const std::vector& available_extensions, + const std::vector& available_extensions, std::vector* device_extensions, GraphicContext* ctx); void LoadHardwareRayTracingFunctions(GraphicContext* ctx); diff --git a/tests/ShaderRecompilerComputeTests.cpp b/tests/ShaderRecompilerComputeTests.cpp index fc123372b..4af564f57 100644 --- a/tests/ShaderRecompilerComputeTests.cpp +++ b/tests/ShaderRecompilerComputeTests.cpp @@ -1,6 +1,8 @@ #include "common/threads.h" +#include "common/assert.h" #include "common/emulatorConfig.h" +#include "common/logging/log.h" #include "graphics/guest_gpu/gpu_defs.h" #include "graphics/guest_gpu/hardwareContext.h" #include "graphics/guest_gpu/tile.h" @@ -16,24 +18,22 @@ #include "graphics/host_gpu/renderer/imageView.h" #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/renderer/renderContext.h" -#include "graphics/host_gpu/renderer/sync.h" #include "graphics/host_gpu/renderer/renderDraw.h" #include "graphics/host_gpu/renderer/renderTarget.h" #include "graphics/host_gpu/renderer/renderVertex.h" #include "graphics/host_gpu/renderer/resourceMutex.h" -#include "graphics/host_gpu/renderer/tiler.h" +#include "graphics/host_gpu/renderer/sync.h" #include "graphics/host_gpu/renderer/textureCache.h" +#include "graphics/host_gpu/renderer/tiler.h" #include "graphics/host_gpu/utils.h" +#include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/recompiler/BindingLayout.h" #include "graphics/shader/recompiler/ShaderDecoder.h" #include "graphics/shader/recompiler/ShaderRecompiler.h" #include "graphics/shader/recompiler/SpirvBuilder.h" #include "graphics/shader/shader.h" -#include "common/assert.h" -#include "common/logging/log.h" #include "spirv-tools/libspirv.hpp" -#include "vulkan/vulkan.h" #include #include @@ -419,39 +419,8 @@ std::string Hex(u32 value) { return buffer; } -std::string VkResultName(VkResult result) { - switch (result) { - case VK_SUCCESS: - return "VK_SUCCESS"; - case VK_NOT_READY: - return "VK_NOT_READY"; - case VK_TIMEOUT: - return "VK_TIMEOUT"; - case VK_ERROR_OUT_OF_HOST_MEMORY: - return "VK_ERROR_OUT_OF_HOST_MEMORY"; - case VK_ERROR_OUT_OF_DEVICE_MEMORY: - return "VK_ERROR_OUT_OF_DEVICE_MEMORY"; - case VK_ERROR_INITIALIZATION_FAILED: - return "VK_ERROR_INITIALIZATION_FAILED"; - case VK_ERROR_DEVICE_LOST: - return "VK_ERROR_DEVICE_LOST"; - case VK_ERROR_MEMORY_MAP_FAILED: - return "VK_ERROR_MEMORY_MAP_FAILED"; - case VK_ERROR_LAYER_NOT_PRESENT: - return "VK_ERROR_LAYER_NOT_PRESENT"; - case VK_ERROR_EXTENSION_NOT_PRESENT: - return "VK_ERROR_EXTENSION_NOT_PRESENT"; - case VK_ERROR_FEATURE_NOT_PRESENT: - return "VK_ERROR_FEATURE_NOT_PRESENT"; - case VK_ERROR_INCOMPATIBLE_DRIVER: - return "VK_ERROR_INCOMPATIBLE_DRIVER"; - case VK_ERROR_TOO_MANY_OBJECTS: - return "VK_ERROR_TOO_MANY_OBJECTS"; - case VK_ERROR_FORMAT_NOT_SUPPORTED: - return "VK_ERROR_FORMAT_NOT_SUPPORTED"; - default: - return "VkResult(" + std::to_string(static_cast(result)) + ")"; - } +std::string VulkanResultName(vk::Result result) { + return VulkanToString(result); } [[noreturn]] void Fail(const char *shader_name, const char *stage, @@ -470,18 +439,18 @@ void EnsureConfigInitialized() { Common::ThreadsSubsystem::Instance()->Init(nullptr); Config::ConfigSubsystem::Instance()->Init(nullptr); Config::ConfigOptions options; - options.printf_direction = Config::OutputDirection::Silent; + options.printf_direction = Config::OutputDirection::Silent; Config::Load(options); Log::LogSubsystem::Instance()->Init(nullptr); config_initialized = true; } } -void RequireVk(const char *shader_name, const char *stage, VkResult result, +void RequireVk(const char *shader_name, const char *stage, vk::Result result, const char *action) { - if (result != VK_SUCCESS) { + if (result != vk::Result::eSuccess) { Fail(shader_name, stage, - std::string(action) + " returned " + VkResultName(result)); + std::string(action) + " returned " + VulkanResultName(result)); } } @@ -507,11 +476,11 @@ struct TestCase { u32 image_height = 4; std::vector sampled_image_rgba; std::vector> sampled_image_rgba_mips; - VkFormat sampled_image_format = VK_FORMAT_R32G32B32A32_SFLOAT; + vk::Format sampled_image_format = vk::Format::eR32G32B32A32Sfloat; u32 sampled_image_dwords_per_pixel = 4; std::vector storage_image_rgba; std::vector expected_storage_image_rgba; - VkFormat storage_image_format = VK_FORMAT_R32G32B32A32_SFLOAT; + vk::Format storage_image_format = vk::Format::eR32G32B32A32Sfloat; u32 storage_image_dwords_per_pixel = 4; std::vector storage_image_r32ui; std::vector expected_storage_image_r32ui; @@ -650,8 +619,7 @@ CompiledShader CompileCase(const TestCase &test) { ShaderRecompiler::CompileResult result; std::string error; - if (!ShaderRecompiler::TryRecompile(test.code, options, &result, - &error)) { + if (!ShaderRecompiler::TryRecompile(test.code, options, &result, &error)) { Fail(test.name, "decode/IR", error.c_str()); } Require(test.name, "SPIR-V emit", !result.spirv.empty(), @@ -717,8 +685,8 @@ CompiledShader CompileFragmentCase(const GraphicsCase &test) { ShaderRecompiler::CompileResult result; std::string error; - if (!ShaderRecompiler::TryRecompile(test.fragment_code, options, - &result, &error)) { + if (!ShaderRecompiler::TryRecompile(test.fragment_code, options, &result, + &error)) { Fail(test.name, "decode/IR", error.c_str()); } Require(test.name, "SPIR-V emit", !result.spirv.empty(), @@ -865,189 +833,193 @@ public: VulkanHarness &operator=(const VulkanHarness &) = delete; struct Buffer { - VkBuffer buffer = VK_NULL_HANDLE; - VkDeviceMemory memory = VK_NULL_HANDLE; - VkDeviceSize size = 0; + vk::Buffer buffer = nullptr; + vk::DeviceMemory memory = nullptr; + vk::DeviceSize size = 0; bool coherent = false; }; struct Image { - VkImage image = VK_NULL_HANDLE; - VkDeviceMemory memory = VK_NULL_HANDLE; - VkImageView view = VK_NULL_HANDLE; - VkFormat format = VK_FORMAT_UNDEFINED; - VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED; + vk::Image image = nullptr; + vk::DeviceMemory memory = nullptr; + vk::ImageView view = nullptr; + vk::Format format = vk::Format::eUndefined; + vk::ImageLayout layout = vk::ImageLayout::eUndefined; u32 width = 0; u32 height = 0; u32 mip_levels = 1; u32 dwords_per_pixel = 0; }; - [[nodiscard]] VkDevice Device() const { return m_device; } + [[nodiscard]] vk::Device Device() const { return m_device; } void CheckMutableStorageSrgbView() { constexpr const char *name = "StorageTextureMutableSrgbView"; - VkImageCreateInfo image_info{}; - image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - image_info.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; - image_info.imageType = VK_IMAGE_TYPE_2D; - image_info.format = VK_FORMAT_R8G8B8A8_SRGB; + vk::ImageCreateInfo image_info{}; + image_info.sType = vk::StructureType::eImageCreateInfo; + image_info.flags = vk::ImageCreateFlagBits::eMutableFormat; + image_info.imageType = vk::ImageType::e2D; + image_info.format = vk::Format::eR8G8B8A8Srgb; image_info.extent = {16, 16, 1}; image_info.mipLevels = 1; image_info.arrayLayers = 1; - image_info.samples = VK_SAMPLE_COUNT_1_BIT; - image_info.tiling = VK_IMAGE_TILING_OPTIMAL; - image_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | - VK_IMAGE_USAGE_TRANSFER_DST_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_STORAGE_BIT; - image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + image_info.samples = vk::SampleCountFlagBits::e1; + image_info.tiling = vk::ImageTiling::eOptimal; + image_info.usage = vk::ImageUsageFlagBits::eTransferSrc | + vk::ImageUsageFlagBits::eTransferDst | + vk::ImageUsageFlagBits::eSampled | + vk::ImageUsageFlagBits::eStorage; + image_info.sharingMode = vk::SharingMode::eExclusive; + image_info.initialLayout = vk::ImageLayout::eUndefined; - VkImageFormatProperties exact_properties{}; + vk::ImageFormatProperties exact_properties{}; const bool srgb_storage_supported = - vkGetPhysicalDeviceImageFormatProperties( - m_physical_device, image_info.format, image_info.imageType, - image_info.tiling, image_info.usage, image_info.flags, - &exact_properties) == VK_SUCCESS; + m_physical_device.getImageFormatProperties( + image_info.format, image_info.imageType, image_info.tiling, + image_info.usage, image_info.flags, + &exact_properties) == vk::Result::eSuccess; GraphicContext context{}; context.physical_device = m_physical_device; Require(name, "format fallback", TextureCheckFormat(&context, &image_info), "mutable sampled/storage RGBA8 image is unsupported"); Require(name, "format fallback", - image_info.format == VK_FORMAT_R8G8B8A8_UNORM || + image_info.format == vk::Format::eR8G8B8A8Unorm || (srgb_storage_supported && - image_info.format == VK_FORMAT_R8G8B8A8_SRGB), + image_info.format == vk::Format::eR8G8B8A8Srgb), "unsupported sRGB storage format did not fall back to UNORM"); - VkImage image = VK_NULL_HANDLE; - RequireVk(name, "backing", vkCreateImage(m_device, &image_info, nullptr, &image), + vk::Image image = nullptr; + RequireVk(name, "backing", + m_device.createImage(&image_info, nullptr, &image), "vkCreateImage"); - VkMemoryRequirements requirements{}; - vkGetImageMemoryRequirements(m_device, image, &requirements); + vk::MemoryRequirements requirements{}; + m_device.getImageMemoryRequirements(image, &requirements); u32 memory_type = 0; Require(name, "backing", FindMemoryType(requirements.memoryTypeBits, - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memory_type) || - FindMemoryType(requirements.memoryTypeBits, 0, &memory_type), + vk::MemoryPropertyFlagBits::eDeviceLocal, + &memory_type) || + FindMemoryType(requirements.memoryTypeBits, {}, &memory_type), "no memory type for mutable storage image"); - VkMemoryAllocateInfo allocation{}; - allocation.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + vk::MemoryAllocateInfo allocation{}; + allocation.sType = vk::StructureType::eMemoryAllocateInfo; allocation.allocationSize = requirements.size; allocation.memoryTypeIndex = memory_type; - VkDeviceMemory memory = VK_NULL_HANDLE; + vk::DeviceMemory memory = nullptr; RequireVk(name, "backing", - vkAllocateMemory(m_device, &allocation, nullptr, &memory), + m_device.allocateMemory(&allocation, nullptr, &memory), "vkAllocateMemory"); - RequireVk(name, "backing", vkBindImageMemory(m_device, image, memory, 0), + RequireVk(name, "backing", m_device.bindImageMemory(image, memory, 0), "vkBindImageMemory"); - VkImageViewUsageCreateInfo view_usage{}; - view_usage.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO; - view_usage.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; - VkImageViewCreateInfo view_info{}; - view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + vk::ImageViewUsageCreateInfo view_usage{}; + view_usage.sType = vk::StructureType::eImageViewUsageCreateInfo; + view_usage.usage = + vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eStorage; + vk::ImageViewCreateInfo view_info{}; + view_info.sType = vk::StructureType::eImageViewCreateInfo; view_info.pNext = &view_usage; view_info.image = image; - view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + view_info.viewType = vk::ImageViewType::e2D; view_info.format = image_info.format; - view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + view_info.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; view_info.subresourceRange.levelCount = 1; view_info.subresourceRange.layerCount = 1; - VkImageView default_view = VK_NULL_HANDLE; + vk::ImageView default_view = nullptr; RequireVk(name, "default view", - vkCreateImageView(m_device, &view_info, nullptr, &default_view), - "vkCreateImageView(default sampled/storage)"); + m_device.createImageView(&view_info, nullptr, &default_view), + "vk::Device::createImageView(default sampled/storage)"); - view_usage.usage = VK_IMAGE_USAGE_SAMPLED_BIT; - view_info.format = VK_FORMAT_R8G8B8A8_SRGB; - VkImageView srgb_view = VK_NULL_HANDLE; + view_usage.usage = vk::ImageUsageFlagBits::eSampled; + view_info.format = vk::Format::eR8G8B8A8Srgb; + vk::ImageView srgb_view = nullptr; RequireVk(name, "sRGB view", - vkCreateImageView(m_device, &view_info, nullptr, &srgb_view), - "vkCreateImageView(sRGB sampled)"); + m_device.createImageView(&view_info, nullptr, &srgb_view), + "vk::Device::createImageView(sRGB sampled)"); - vkDestroyImageView(m_device, srgb_view, nullptr); - vkDestroyImageView(m_device, default_view, nullptr); - vkDestroyImage(m_device, image, nullptr); - vkFreeMemory(m_device, memory, nullptr); + m_device.destroyImageView(srgb_view, nullptr); + m_device.destroyImageView(default_view, nullptr); + m_device.destroyImage(image, nullptr); + m_device.freeMemory(memory, nullptr); std::printf("[host] %-32s ok (backing=%d)\n", name, static_cast(image_info.format)); } void CheckMutableRenderTargetBgraStorageView() { constexpr const char *name = "RenderTargetMutableBgraStorage"; - VkImageCreateInfo image_info{}; - image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - image_info.flags = - VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT; - image_info.imageType = VK_IMAGE_TYPE_2D; - image_info.format = VK_FORMAT_B8G8R8A8_SRGB; + vk::ImageCreateInfo image_info{}; + image_info.sType = vk::StructureType::eImageCreateInfo; + image_info.flags = vk::ImageCreateFlagBits::eMutableFormat | + vk::ImageCreateFlagBits::eExtendedUsage; + image_info.imageType = vk::ImageType::e2D; + image_info.format = vk::Format::eB8G8R8A8Srgb; image_info.extent = {8, 8, 1}; image_info.mipLevels = 1; image_info.arrayLayers = 1; - image_info.samples = VK_SAMPLE_COUNT_1_BIT; - image_info.tiling = VK_IMAGE_TILING_OPTIMAL; - image_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | - VK_IMAGE_USAGE_TRANSFER_DST_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; - image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + image_info.samples = vk::SampleCountFlagBits::e1; + image_info.tiling = vk::ImageTiling::eOptimal; + image_info.usage = vk::ImageUsageFlagBits::eColorAttachment | + vk::ImageUsageFlagBits::eTransferSrc | + vk::ImageUsageFlagBits::eTransferDst | + vk::ImageUsageFlagBits::eSampled | + vk::ImageUsageFlagBits::eStorage; + image_info.sharingMode = vk::SharingMode::eExclusive; + image_info.initialLayout = vk::ImageLayout::eUndefined; - VkImageFormatProperties properties{}; + vk::ImageFormatProperties properties{}; RequireVk(name, "backing query", - vkGetPhysicalDeviceImageFormatProperties( - m_physical_device, image_info.format, image_info.imageType, - image_info.tiling, image_info.usage, image_info.flags, - &properties), + m_physical_device.getImageFormatProperties( + image_info.format, image_info.imageType, image_info.tiling, + image_info.usage, image_info.flags, &properties), "mutable extended-usage BGRA sRGB backing"); - VkImage image = VK_NULL_HANDLE; + vk::Image image = nullptr; RequireVk(name, "backing", - vkCreateImage(m_device, &image_info, nullptr, &image), + m_device.createImage(&image_info, nullptr, &image), "vkCreateImage"); - VkMemoryRequirements requirements{}; - vkGetImageMemoryRequirements(m_device, image, &requirements); + vk::MemoryRequirements requirements{}; + m_device.getImageMemoryRequirements(image, &requirements); u32 memory_type = 0; Require(name, "backing", FindMemoryType(requirements.memoryTypeBits, - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memory_type) || - FindMemoryType(requirements.memoryTypeBits, 0, &memory_type), + vk::MemoryPropertyFlagBits::eDeviceLocal, + &memory_type) || + FindMemoryType(requirements.memoryTypeBits, {}, &memory_type), "no memory type for mutable render target"); - VkMemoryAllocateInfo allocation{}; - allocation.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + vk::MemoryAllocateInfo allocation{}; + allocation.sType = vk::StructureType::eMemoryAllocateInfo; allocation.allocationSize = requirements.size; allocation.memoryTypeIndex = memory_type; - VkDeviceMemory memory = VK_NULL_HANDLE; + vk::DeviceMemory memory = nullptr; RequireVk(name, "backing", - vkAllocateMemory(m_device, &allocation, nullptr, &memory), + m_device.allocateMemory(&allocation, nullptr, &memory), "vkAllocateMemory"); - RequireVk(name, "backing", vkBindImageMemory(m_device, image, memory, 0), + RequireVk(name, "backing", m_device.bindImageMemory(image, memory, 0), "vkBindImageMemory"); - VkImageViewUsageCreateInfo view_usage{}; - view_usage.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO; - view_usage.usage = VK_IMAGE_USAGE_STORAGE_BIT; - VkImageViewCreateInfo view_info{}; - view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + vk::ImageViewUsageCreateInfo view_usage{}; + view_usage.sType = vk::StructureType::eImageViewUsageCreateInfo; + view_usage.usage = vk::ImageUsageFlagBits::eStorage; + vk::ImageViewCreateInfo view_info{}; + view_info.sType = vk::StructureType::eImageViewCreateInfo; view_info.pNext = &view_usage; view_info.image = image; - view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - view_info.format = VK_FORMAT_R8G8B8A8_UNORM; + view_info.viewType = vk::ImageViewType::e2D; + view_info.format = vk::Format::eR8G8B8A8Unorm; view_info.components = { - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, - VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}; - view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity}; + view_info.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; view_info.subresourceRange.levelCount = 1; view_info.subresourceRange.layerCount = 1; - VkImageView storage_view = VK_NULL_HANDLE; + vk::ImageView storage_view = nullptr; RequireVk(name, "storage view", - vkCreateImageView(m_device, &view_info, nullptr, &storage_view), - "vkCreateImageView(RGBA UNORM storage)"); + m_device.createImageView(&view_info, nullptr, &storage_view), + "vk::Device::createImageView(RGBA UNORM storage)"); - vkDestroyImageView(m_device, storage_view, nullptr); - vkDestroyImage(m_device, image, nullptr); - vkFreeMemory(m_device, memory, nullptr); + m_device.destroyImageView(storage_view, nullptr); + m_device.destroyImage(image, nullptr); + m_device.freeMemory(memory, nullptr); std::printf("[host] %-32s ok (backing=%d view=%d)\n", name, static_cast(image_info.format), static_cast(view_info.format)); @@ -1055,42 +1027,43 @@ public: void CheckRenderTargetViewCache() { constexpr const char *name = "RenderTargetViewCache"; - VkImageCreateInfo image_info{}; - image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - image_info.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; - image_info.imageType = VK_IMAGE_TYPE_2D; - image_info.format = VK_FORMAT_R8G8B8A8_UNORM; + vk::ImageCreateInfo image_info{}; + image_info.sType = vk::StructureType::eImageCreateInfo; + image_info.flags = vk::ImageCreateFlagBits::eMutableFormat; + image_info.imageType = vk::ImageType::e2D; + image_info.format = vk::Format::eR8G8B8A8Unorm; image_info.extent = {8, 8, 1}; image_info.mipLevels = 2; image_info.arrayLayers = 2; - image_info.samples = VK_SAMPLE_COUNT_1_BIT; - image_info.tiling = VK_IMAGE_TILING_OPTIMAL; - image_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; - image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_info.samples = vk::SampleCountFlagBits::e1; + image_info.tiling = vk::ImageTiling::eOptimal; + image_info.usage = vk::ImageUsageFlagBits::eColorAttachment | + vk::ImageUsageFlagBits::eSampled | + vk::ImageUsageFlagBits::eStorage; + image_info.sharingMode = vk::SharingMode::eExclusive; - VkImage image_handle = VK_NULL_HANDLE; + vk::Image image_handle = nullptr; RequireVk(name, "image", - vkCreateImage(m_device, &image_info, nullptr, &image_handle), + m_device.createImage(&image_info, nullptr, &image_handle), "vkCreateImage"); - VkMemoryRequirements requirements{}; - vkGetImageMemoryRequirements(m_device, image_handle, &requirements); + vk::MemoryRequirements requirements{}; + m_device.getImageMemoryRequirements(image_handle, &requirements); u32 memory_type = 0; Require(name, "memory", FindMemoryType(requirements.memoryTypeBits, - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memory_type) || - FindMemoryType(requirements.memoryTypeBits, 0, &memory_type), + vk::MemoryPropertyFlagBits::eDeviceLocal, + &memory_type) || + FindMemoryType(requirements.memoryTypeBits, {}, &memory_type), "no memory type for sampled render target"); - VkMemoryAllocateInfo allocation{}; - allocation.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + vk::MemoryAllocateInfo allocation{}; + allocation.sType = vk::StructureType::eMemoryAllocateInfo; allocation.allocationSize = requirements.size; allocation.memoryTypeIndex = memory_type; - VkDeviceMemory memory = VK_NULL_HANDLE; + vk::DeviceMemory memory = nullptr; RequireVk(name, "memory", - vkAllocateMemory(m_device, &allocation, nullptr, &memory), + m_device.allocateMemory(&allocation, nullptr, &memory), "vkAllocateMemory"); - RequireVk(name, "memory", - vkBindImageMemory(m_device, image_handle, memory, 0), + RequireVk(name, "memory", m_device.bindImageMemory(image_handle, memory, 0), "vkBindImageMemory"); GraphicContext context{}; @@ -1112,33 +1085,33 @@ public: constexpr auto second_swizzle = DstSel(7, 4, 0, 1); const auto first = texture_cache.GetSampledColorView( &context, &image, image.format, first_swizzle, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + vk::ImageViewType::e2D, 0, 1); const auto first_again = texture_cache.GetSampledColorView( &context, &image, image.format, first_swizzle, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + vk::ImageViewType::e2D, 0, 1); const auto second = texture_cache.GetSampledColorView( &context, &image, image.format, second_swizzle, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + vk::ImageViewType::e2D, 0, 1); const auto different_mip = texture_cache.GetSampledColorView( &context, &image, image.format, first_swizzle, 1, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + vk::ImageViewType::e2D, 0, 1); const auto different_layer = texture_cache.GetSampledColorView( &context, &image, image.format, first_swizzle, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 1, 1); + vk::ImageViewType::e2D, 1, 1); const auto array_view = texture_cache.GetSampledColorView( &context, &image, image.format, first_swizzle, 0, 1, - VK_IMAGE_VIEW_TYPE_2D_ARRAY, 0, 2); + vk::ImageViewType::e2DArray, 0, 2); constexpr auto identity = DstSel(4, 5, 6, 7); const auto native_format = texture_cache.GetSampledColorView( - &context, &image, image.format, identity, 0, 1, VK_IMAGE_VIEW_TYPE_2D, + &context, &image, image.format, identity, 0, 1, vk::ImageViewType::e2D, 0, 1); const auto reinterpreted_format = texture_cache.GetSampledColorView( - &context, &image, VK_FORMAT_R8G8B8A8_UINT, identity, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + &context, &image, vk::Format::eR8G8B8A8Uint, identity, 0, 1, + vk::ImageViewType::e2D, 0, 1); const auto storage = texture_cache.GetRenderTargetStorageView( - &context, &image, image.format, 0, 1, VK_IMAGE_VIEW_TYPE_2D, 0, 1); + &context, &image, image.format, 0, 1, vk::ImageViewType::e2D, 0, 1); const auto storage_again = texture_cache.GetRenderTargetStorageView( - &context, &image, image.format, 0, 1, VK_IMAGE_VIEW_TYPE_2D, 0, 1); + &context, &image, image.format, 0, 1, vk::ImageViewType::e2D, 0, 1); const auto attachment = texture_cache.GetRenderTargetAttachmentView( &context, &image, image.format, 0, 0, 1); const auto attachment_again = texture_cache.GetRenderTargetAttachmentView( @@ -1148,68 +1121,67 @@ public: const auto attachment_array = texture_cache.GetRenderTargetAttachmentView( &context, &image, image.format, 0, 0, 2); Require(name, "cache identity", - first != VK_NULL_HANDLE && first_again == first && - second != VK_NULL_HANDLE && second != first && - different_mip != VK_NULL_HANDLE && different_mip != first && - different_layer != VK_NULL_HANDLE && different_layer != first && - array_view != VK_NULL_HANDLE && array_view != first && - native_format != VK_NULL_HANDLE && - reinterpreted_format != VK_NULL_HANDLE && - reinterpreted_format != native_format && - storage != VK_NULL_HANDLE && storage != native_format && - storage_again == storage && attachment != VK_NULL_HANDLE && - attachment_again == attachment && attachment != native_format && - attachment != storage && attachment_mip != VK_NULL_HANDLE && - attachment_mip != attachment && attachment_array != VK_NULL_HANDLE && - attachment_array != attachment && image.view_cache.views.size() == 11, + first != nullptr && first_again == first && second != nullptr && + second != first && different_mip != nullptr && + different_mip != first && different_layer != nullptr && + different_layer != first && array_view != nullptr && + array_view != first && native_format != nullptr && + reinterpreted_format != nullptr && + reinterpreted_format != native_format && storage != nullptr && + storage != native_format && storage_again == storage && + attachment != nullptr && attachment_again == attachment && + attachment != native_format && attachment != storage && + attachment_mip != nullptr && attachment_mip != attachment && + attachment_array != nullptr && attachment_array != attachment && + image.view_cache.views.size() == 11, "view cache omitted attachment usage, swizzle, format, type, mip, " "or layer identity"); ImageViewOps::DestroyViews(&context, &image); Require(name, "view teardown", image.view_cache.views.empty(), "dynamic render-target views survived DestroyViews"); - vkDestroyImage(m_device, image_handle, nullptr); - vkFreeMemory(m_device, memory, nullptr); + m_device.destroyImage(image_handle, nullptr); + m_device.freeMemory(memory, nullptr); std::printf("[host] %-32s ok\n", name); } void CheckDepthTargetSampledViewCache() { constexpr const char *name = "DepthTargetSampledViewCache"; - VkImageCreateInfo image_info{}; - image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - image_info.imageType = VK_IMAGE_TYPE_2D; - image_info.format = VK_FORMAT_D32_SFLOAT; + vk::ImageCreateInfo image_info{}; + image_info.sType = vk::StructureType::eImageCreateInfo; + image_info.imageType = vk::ImageType::e2D; + image_info.format = vk::Format::eD32Sfloat; image_info.extent = {8, 8, 1}; image_info.mipLevels = 1; image_info.arrayLayers = 2; - image_info.samples = VK_SAMPLE_COUNT_1_BIT; - image_info.tiling = VK_IMAGE_TILING_OPTIMAL; - image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT; - image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + image_info.samples = vk::SampleCountFlagBits::e1; + image_info.tiling = vk::ImageTiling::eOptimal; + image_info.usage = vk::ImageUsageFlagBits::eDepthStencilAttachment | + vk::ImageUsageFlagBits::eSampled; + image_info.sharingMode = vk::SharingMode::eExclusive; - VkImage image_handle = VK_NULL_HANDLE; + vk::Image image_handle = nullptr; RequireVk(name, "image", - vkCreateImage(m_device, &image_info, nullptr, &image_handle), + m_device.createImage(&image_info, nullptr, &image_handle), "vkCreateImage"); - VkMemoryRequirements requirements{}; - vkGetImageMemoryRequirements(m_device, image_handle, &requirements); + vk::MemoryRequirements requirements{}; + m_device.getImageMemoryRequirements(image_handle, &requirements); u32 memory_type = 0; Require(name, "memory", FindMemoryType(requirements.memoryTypeBits, - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memory_type) || - FindMemoryType(requirements.memoryTypeBits, 0, &memory_type), + vk::MemoryPropertyFlagBits::eDeviceLocal, + &memory_type) || + FindMemoryType(requirements.memoryTypeBits, {}, &memory_type), "no memory type for sampled depth target"); - VkMemoryAllocateInfo allocation{}; - allocation.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + vk::MemoryAllocateInfo allocation{}; + allocation.sType = vk::StructureType::eMemoryAllocateInfo; allocation.allocationSize = requirements.size; allocation.memoryTypeIndex = memory_type; - VkDeviceMemory memory = VK_NULL_HANDLE; + vk::DeviceMemory memory = nullptr; RequireVk(name, "memory", - vkAllocateMemory(m_device, &allocation, nullptr, &memory), + m_device.allocateMemory(&allocation, nullptr, &memory), "vkAllocateMemory"); - RequireVk(name, "memory", - vkBindImageMemory(m_device, image_handle, memory, 0), + RequireVk(name, "memory", m_device.bindImageMemory(image_handle, memory, 0), "vkBindImageMemory"); GraphicContext context{}; @@ -1230,55 +1202,57 @@ public: constexpr auto replicated = DstSel(4, 4, 4, 4); constexpr auto r001 = DstSel(4, 0, 0, 1); const auto first = texture_cache.GetDepthTargetSampledView( - &context, &image, VK_FORMAT_R32_SFLOAT, replicated, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + &context, &image, vk::Format::eR32Sfloat, replicated, 0, 1, + vk::ImageViewType::e2D, 0, 1); const auto first_again = texture_cache.GetDepthTargetSampledView( - &context, &image, VK_FORMAT_R32_SFLOAT, replicated, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + &context, &image, vk::Format::eR32Sfloat, replicated, 0, 1, + vk::ImageViewType::e2D, 0, 1); const auto different_swizzle = texture_cache.GetDepthTargetSampledView( - &context, &image, VK_FORMAT_R32_SFLOAT, r001, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 0, 1); + &context, &image, vk::Format::eR32Sfloat, r001, 0, 1, + vk::ImageViewType::e2D, 0, 1); const auto different_layer = texture_cache.GetDepthTargetSampledView( - &context, &image, VK_FORMAT_R32_SFLOAT, replicated, 0, 1, - VK_IMAGE_VIEW_TYPE_2D, 1, 1); + &context, &image, vk::Format::eR32Sfloat, replicated, 0, 1, + vk::ImageViewType::e2D, 1, 1); const auto array_view = texture_cache.GetDepthTargetSampledView( - &context, &image, VK_FORMAT_R32_SFLOAT, replicated, 0, 1, - VK_IMAGE_VIEW_TYPE_2D_ARRAY, 0, 2); - const auto attachment = texture_cache.GetDepthTargetAttachmentView( - &context, &image, 0, 1); - const auto attachment_again = texture_cache.GetDepthTargetAttachmentView( - &context, &image, 0, 1); - const auto attachment_layer = texture_cache.GetDepthTargetAttachmentView( - &context, &image, 1, 1); - const auto attachment_array = texture_cache.GetDepthTargetAttachmentView( - &context, &image, 0, 2); - Require(name, "cache identity", - first != VK_NULL_HANDLE && first_again == first && - different_swizzle != VK_NULL_HANDLE && - different_swizzle != first && - different_layer != VK_NULL_HANDLE && different_layer != first && - array_view != VK_NULL_HANDLE && array_view != first && - attachment != VK_NULL_HANDLE && attachment_again == attachment && - attachment != first && attachment_layer != VK_NULL_HANDLE && - attachment_layer != attachment && attachment_array != VK_NULL_HANDLE && - attachment_array != attachment && image.view_cache.views.size() == 7, - "depth view cache omitted attachment usage, swizzle, type, or layer " - "identity"); + &context, &image, vk::Format::eR32Sfloat, replicated, 0, 1, + vk::ImageViewType::e2DArray, 0, 2); + const auto attachment = + texture_cache.GetDepthTargetAttachmentView(&context, &image, 0, 1); + const auto attachment_again = + texture_cache.GetDepthTargetAttachmentView(&context, &image, 0, 1); + const auto attachment_layer = + texture_cache.GetDepthTargetAttachmentView(&context, &image, 1, 1); + const auto attachment_array = + texture_cache.GetDepthTargetAttachmentView(&context, &image, 0, 2); + Require( + name, "cache identity", + first != nullptr && first_again == first && + different_swizzle != nullptr && different_swizzle != first && + different_layer != nullptr && different_layer != first && + array_view != nullptr && array_view != first && + attachment != nullptr && attachment_again == attachment && + attachment != first && attachment_layer != nullptr && + attachment_layer != attachment && attachment_array != nullptr && + attachment_array != attachment && + image.view_cache.views.size() == 7, + "depth view cache omitted attachment usage, swizzle, type, or layer " + "identity"); ImageViewOps::DestroyViews(&context, &image); Require(name, "view teardown", image.view_cache.views.empty(), "dynamic depth-target views survived DestroyViews"); - vkDestroyImage(m_device, image_handle, nullptr); - vkFreeMemory(m_device, memory, nullptr); + m_device.destroyImage(image_handle, nullptr); + m_device.freeMemory(memory, nullptr); std::printf("[host] %-32s ok\n", name); } void CheckVideoOutSampledViewCache() { constexpr const char *name = "VideoOutSampledViewCache"; - auto backing = CreateImage2D(name, 8, 8, VK_FORMAT_R8G8B8A8_UNORM, - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT, - {}, 1, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + auto backing = + CreateImage2D(name, 8, 8, vk::Format::eR8G8B8A8Unorm, + vk::ImageUsageFlagBits::eColorAttachment | + vk::ImageUsageFlagBits::eSampled, + {}, 1, vk::ImageLayout::eShaderReadOnlyOptimal); GraphicContext context{}; context.physical_device = m_physical_device; @@ -1300,20 +1274,20 @@ public: constexpr auto bgra = DstSel(6, 5, 4, 7); constexpr auto uncommon = DstSel(5, 1, 7, 0); const auto default_view = texture_cache.GetSampledColorView( - &context, &image, image.format, identity, 0, 1, VK_IMAGE_VIEW_TYPE_2D, + &context, &image, image.format, identity, 0, 1, vk::ImageViewType::e2D, 0, 1); - const auto bgra_view = texture_cache.GetSampledColorView( - &context, &image, image.format, bgra, 0, 1, VK_IMAGE_VIEW_TYPE_2D, 0, - 1); + const auto bgra_view = + texture_cache.GetSampledColorView(&context, &image, image.format, bgra, + 0, 1, vk::ImageViewType::e2D, 0, 1); const auto uncommon_view = texture_cache.GetSampledColorView( - &context, &image, image.format, uncommon, 0, 1, VK_IMAGE_VIEW_TYPE_2D, + &context, &image, image.format, uncommon, 0, 1, vk::ImageViewType::e2D, 0, 1); const auto uncommon_again = texture_cache.GetSampledColorView( - &context, &image, image.format, uncommon, 0, 1, VK_IMAGE_VIEW_TYPE_2D, + &context, &image, image.format, uncommon, 0, 1, vk::ImageViewType::e2D, 0, 1); Require(name, "cache identity", - default_view == backing.view && bgra_view != VK_NULL_HANDLE && - bgra_view != default_view && uncommon_view != VK_NULL_HANDLE && + default_view == backing.view && bgra_view != nullptr && + bgra_view != default_view && uncommon_view != nullptr && uncommon_view != bgra_view && uncommon_again == uncommon_view && image.view_cache.views.size() == 2, "video-out sampled views did not use identity fast path and lazy " @@ -1324,9 +1298,9 @@ public: image.view_cache.views.empty() && std::all_of(std::begin(image.image_view), std::end(image.image_view), - [](VkImageView view) { return view == VK_NULL_HANDLE; }), + [](vk::ImageView view) { return view == nullptr; }), "dynamic or fixed video-out views survived DestroyViews"); - backing.view = VK_NULL_HANDLE; + backing.view = nullptr; DestroyImage(&backing); std::printf("[host] %-32s ok\n", name); } @@ -1336,9 +1310,9 @@ public: constexpr const char *name = "QueryRegionImageClassification"; constexpr uintptr_t base = 0x0000000200100000ull; constexpr uint64_t allocation_size = 0x4000; - auto *memory = static_cast(VirtualAlloc( - reinterpret_cast(base), allocation_size, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto *memory = static_cast( + VirtualAlloc(reinterpret_cast(base), allocation_size, + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); Require(name, "allocation", memory == reinterpret_cast(base), "fixed VirtualAlloc failed"); std::memset(memory, 0, allocation_size); @@ -1353,14 +1327,14 @@ public: constexpr auto format = Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm); - constexpr auto linear = - Prospero::GpuEnumValue(Prospero::TileMode::kLinear); + constexpr auto linear = Prospero::GpuEnumValue(Prospero::TileMode::kLinear); ImageInfo sampled_info{}; sampled_info.address = base + 0x100; sampled_info.format = format; sampled_info.width = 4; sampled_info.height = 4; - sampled_info.pitch = TileGetTexturePitch(format, sampled_info.width, 1, linear); + sampled_info.pitch = + TileGetTexturePitch(format, sampled_info.width, 1, linear); sampled_info.tile = linear; sampled_info.type = Prospero::GpuEnumValue(Prospero::ImageType::kColor2D); TileSizeAlign sampled_size{}; @@ -1377,7 +1351,7 @@ public: RenderTargetInfo target_info{}; target_info.address = base + 0x1100; target_info.size = 0x100; - target_info.format = VK_FORMAT_R8G8B8A8_UNORM; + target_info.format = vk::Format::eR8G8B8A8Unorm; target_info.width = 4; target_info.height = 4; target_info.pitch = 4; @@ -1386,10 +1360,10 @@ public: { CommandBuffer command(GraphicContext::QUEUE_GFX); - auto *sampled = - texture_cache.FindTexture(&command, &m_runtime_context, sampled_info, false); - auto *target = - texture_cache.FindRenderTarget(&command, &m_runtime_context, target_info); + auto *sampled = texture_cache.FindTexture(&command, &m_runtime_context, + sampled_info, false); + auto *target = texture_cache.FindRenderTarget( + &command, &m_runtime_context, target_info); Require(name, "registration", sampled != nullptr && target != nullptr, "sampled or non-sampled image registration failed"); @@ -1399,8 +1373,9 @@ public: Require(name, "sampled classification", sampled_bytes.image_pages && sampled_bytes.image_bytes && !sampled_bytes.gpu_image_bytes && - !sampled_bytes.non_sampled_pages && sampled_page.image_pages && - !sampled_page.image_bytes && !sampled_page.gpu_image_bytes && + !sampled_bytes.non_sampled_pages && + sampled_page.image_pages && !sampled_page.image_bytes && + !sampled_page.gpu_image_bytes && !sampled_page.non_sampled_pages, "sampled image page and byte ownership were not separated"); @@ -1410,9 +1385,10 @@ public: texture_cache.QueryRegion(target_info.address + 0x400, 0x20); Require(name, "non-sampled classification", target_bytes.image_pages && target_bytes.image_bytes && - !target_bytes.gpu_image_bytes && target_bytes.non_sampled_pages && - target_page.image_pages && !target_page.image_bytes && - !target_page.gpu_image_bytes && target_page.non_sampled_pages, + !target_bytes.gpu_image_bytes && + target_bytes.non_sampled_pages && target_page.image_pages && + !target_page.image_bytes && !target_page.gpu_image_bytes && + target_page.non_sampled_pages, "non-sampled image page and byte ownership were not separated"); texture_cache.MarkGpuWritten(target); @@ -1440,41 +1416,42 @@ public: const std::vector &initial, size_t dword_count) { Buffer ret; - ret.size = static_cast(std::max(dword_count, 1u) * - sizeof(u32)); + ret.size = static_cast(std::max(dword_count, 1u) * + sizeof(u32)); - VkBufferCreateInfo buffer_info{}; - buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + vk::BufferCreateInfo buffer_info{}; + buffer_info.sType = vk::StructureType::eBufferCreateInfo; buffer_info.size = ret.size; - buffer_info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + buffer_info.usage = vk::BufferUsageFlagBits::eStorageBuffer; + buffer_info.sharingMode = vk::SharingMode::eExclusive; RequireVk(shader_name, "dispatch", - vkCreateBuffer(m_device, &buffer_info, nullptr, &ret.buffer), + m_device.createBuffer(&buffer_info, nullptr, &ret.buffer), "vkCreateBuffer"); - VkMemoryRequirements req{}; - vkGetBufferMemoryRequirements(m_device, ret.buffer, &req); + vk::MemoryRequirements req{}; + m_device.getBufferMemoryRequirements(ret.buffer, &req); u32 memory_type = 0; ret.coherent = FindMemoryType(req.memoryTypeBits, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent, &memory_type); if (!ret.coherent) { Require(shader_name, "dispatch", FindMemoryType(req.memoryTypeBits, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &memory_type), + vk::MemoryPropertyFlagBits::eHostVisible, + &memory_type), "no host-visible memory type for storage buffer"); } - VkMemoryAllocateInfo alloc{}; - alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + vk::MemoryAllocateInfo alloc{}; + alloc.sType = vk::StructureType::eMemoryAllocateInfo; alloc.allocationSize = req.size; alloc.memoryTypeIndex = memory_type; RequireVk(shader_name, "dispatch", - vkAllocateMemory(m_device, &alloc, nullptr, &ret.memory), + m_device.allocateMemory(&alloc, nullptr, &ret.memory), "vkAllocateMemory"); RequireVk(shader_name, "dispatch", - vkBindBufferMemory(m_device, ret.buffer, ret.memory, 0), + m_device.bindBufferMemory(ret.buffer, ret.memory, 0), "vkBindBufferMemory"); std::vector contents(dword_count, 0); @@ -1489,20 +1466,20 @@ public: if (buffer == nullptr) { return; } - if (buffer->buffer != VK_NULL_HANDLE) { - vkDestroyBuffer(m_device, buffer->buffer, nullptr); - buffer->buffer = VK_NULL_HANDLE; + if (buffer->buffer != nullptr) { + m_device.destroyBuffer(buffer->buffer, nullptr); + buffer->buffer = nullptr; } - if (buffer->memory != VK_NULL_HANDLE) { - vkFreeMemory(m_device, buffer->memory, nullptr); - buffer->memory = VK_NULL_HANDLE; + if (buffer->memory != nullptr) { + m_device.freeMemory(buffer->memory, nullptr); + buffer->memory = nullptr; } } Image CreateImage2D(const char *shader_name, u32 width, u32 height, - VkFormat format, VkImageUsageFlags usage, + vk::Format format, vk::ImageUsageFlags usage, const std::vector &initial, u32 dwords_per_pixel, - VkImageLayout final_layout) { + vk::ImageLayout final_layout) { std::vector> mips; if (!initial.empty()) { mips.push_back(initial); @@ -1525,9 +1502,9 @@ public: } Image CreateImage2DMips(const char *shader_name, u32 width, u32 height, - VkFormat format, VkImageUsageFlags usage, + vk::Format format, vk::ImageUsageFlags usage, const std::vector> &initial_mips, - u32 dwords_per_pixel, VkImageLayout final_layout) { + u32 dwords_per_pixel, vk::ImageLayout final_layout) { Image ret; ret.format = format; ret.width = width; @@ -1535,58 +1512,59 @@ public: ret.mip_levels = std::max(static_cast(initial_mips.size()), 1u); ret.dwords_per_pixel = dwords_per_pixel; - VkImageCreateInfo image_info{}; - image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - image_info.imageType = VK_IMAGE_TYPE_2D; + vk::ImageCreateInfo image_info{}; + image_info.sType = vk::StructureType::eImageCreateInfo; + image_info.imageType = vk::ImageType::e2D; image_info.format = format; image_info.extent.width = width; image_info.extent.height = height; image_info.extent.depth = 1; image_info.mipLevels = ret.mip_levels; image_info.arrayLayers = 1; - image_info.samples = VK_SAMPLE_COUNT_1_BIT; - image_info.tiling = VK_IMAGE_TILING_OPTIMAL; - image_info.usage = usage | VK_IMAGE_USAGE_TRANSFER_DST_BIT | - VK_IMAGE_USAGE_TRANSFER_SRC_BIT; - image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + image_info.samples = vk::SampleCountFlagBits::e1; + image_info.tiling = vk::ImageTiling::eOptimal; + image_info.usage = usage | vk::ImageUsageFlagBits::eTransferDst | + vk::ImageUsageFlagBits::eTransferSrc; + image_info.sharingMode = vk::SharingMode::eExclusive; + image_info.initialLayout = vk::ImageLayout::eUndefined; RequireVk(shader_name, "dispatch", - vkCreateImage(m_device, &image_info, nullptr, &ret.image), + m_device.createImage(&image_info, nullptr, &ret.image), "vkCreateImage"); - VkMemoryRequirements req{}; - vkGetImageMemoryRequirements(m_device, ret.image, &req); + vk::MemoryRequirements req{}; + m_device.getImageMemoryRequirements(ret.image, &req); u32 memory_type = 0; - if (!FindMemoryType(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + if (!FindMemoryType(req.memoryTypeBits, + vk::MemoryPropertyFlagBits::eDeviceLocal, &memory_type)) { Require(shader_name, "dispatch", - FindMemoryType(req.memoryTypeBits, 0, &memory_type), + FindMemoryType(req.memoryTypeBits, {}, &memory_type), "no memory type for image"); } - VkMemoryAllocateInfo alloc{}; - alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + vk::MemoryAllocateInfo alloc{}; + alloc.sType = vk::StructureType::eMemoryAllocateInfo; alloc.allocationSize = req.size; alloc.memoryTypeIndex = memory_type; RequireVk(shader_name, "dispatch", - vkAllocateMemory(m_device, &alloc, nullptr, &ret.memory), - "vkAllocateMemory(image)"); + m_device.allocateMemory(&alloc, nullptr, &ret.memory), + "vk::Device::allocateMemory(image)"); RequireVk(shader_name, "dispatch", - vkBindImageMemory(m_device, ret.image, ret.memory, 0), + m_device.bindImageMemory(ret.image, ret.memory, 0), "vkBindImageMemory"); - VkImageViewCreateInfo view_info{}; - view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + vk::ImageViewCreateInfo view_info{}; + view_info.sType = vk::StructureType::eImageViewCreateInfo; view_info.image = ret.image; - view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + view_info.viewType = vk::ImageViewType::e2D; view_info.format = format; - view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + view_info.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; view_info.subresourceRange.baseMipLevel = 0; view_info.subresourceRange.levelCount = ret.mip_levels; view_info.subresourceRange.baseArrayLayer = 0; view_info.subresourceRange.layerCount = 1; RequireVk(shader_name, "dispatch", - vkCreateImageView(m_device, &view_info, nullptr, &ret.view), + m_device.createImageView(&view_info, nullptr, &ret.view), "vkCreateImageView"); if (!initial_mips.empty()) { @@ -1608,13 +1586,13 @@ public: } auto staging = CreateHostBuffer(shader_name, contents.size() * sizeof(u32), - VK_BUFFER_USAGE_TRANSFER_SRC_BIT, contents); + vk::BufferUsageFlagBits::eTransferSrc, contents); UploadImageMips(shader_name, &ret, staging.buffer, final_layout); DestroyBuffer(&staging); } else { TransitionImage(shader_name, &ret, final_layout, - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, + vk::PipelineStageFlagBits::eTopOfPipe, + vk::PipelineStageFlagBits::eComputeShader, {}, AccessForLayout(final_layout)); } return ret; @@ -1624,17 +1602,17 @@ public: if (image == nullptr) { return; } - if (image->view != VK_NULL_HANDLE) { - vkDestroyImageView(m_device, image->view, nullptr); - image->view = VK_NULL_HANDLE; + if (image->view != nullptr) { + m_device.destroyImageView(image->view, nullptr); + image->view = nullptr; } - if (image->image != VK_NULL_HANDLE) { - vkDestroyImage(m_device, image->image, nullptr); - image->image = VK_NULL_HANDLE; + if (image->image != nullptr) { + m_device.destroyImage(image->image, nullptr); + image->image = nullptr; } - if (image->memory != VK_NULL_HANDLE) { - vkFreeMemory(m_device, image->memory, nullptr); - image->memory = VK_NULL_HANDLE; + if (image->memory != nullptr) { + m_device.freeMemory(image->memory, nullptr); + image->memory = nullptr; } } @@ -1643,48 +1621,48 @@ public: static_cast(image->height) * image->dwords_per_pixel; auto staging = CreateHostBuffer(shader_name, dword_count * sizeof(u32), - VK_BUFFER_USAGE_TRANSFER_DST_BIT, {}); + vk::BufferUsageFlagBits::eTransferDst, {}); - VkCommandBuffer cmd = BeginCommands(shader_name, "readback"); + vk::CommandBuffer cmd = BeginCommands(shader_name, "readback"); AddImageBarrier( - cmd, image->image, image->layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, - VK_ACCESS_TRANSFER_READ_BIT); - VkBufferImageCopy copy{}; + cmd, image->image, image->layout, vk::ImageLayout::eTransferSrcOptimal, + vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eTransfer, + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eTransferRead); + vk::BufferImageCopy copy{}; copy.bufferOffset = 0; - copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + copy.imageSubresource.aspectMask = vk::ImageAspectFlagBits::eColor; copy.imageSubresource.mipLevel = 0; copy.imageSubresource.baseArrayLayer = 0; copy.imageSubresource.layerCount = 1; copy.imageExtent.width = image->width; copy.imageExtent.height = image->height; copy.imageExtent.depth = 1; - vkCmdCopyImageToBuffer(cmd, image->image, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, staging.buffer, - 1, ©); + cmd.copyImageToBuffer(image->image, vk::ImageLayout::eTransferSrcOptimal, + staging.buffer, 1, ©); EndSubmitAndFree(shader_name, "readback", cmd); - image->layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + image->layout = vk::ImageLayout::eTransferSrcOptimal; auto ret = ReadBuffer(shader_name, staging, dword_count); DestroyBuffer(&staging); return ret; } - VkSampler CreateNearestSampler(const char *shader_name) { - VkSamplerCreateInfo sampler_info{}; - sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - sampler_info.magFilter = VK_FILTER_NEAREST; - sampler_info.minFilter = VK_FILTER_NEAREST; - sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; - sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + vk::Sampler CreateNearestSampler(const char *shader_name) { + vk::SamplerCreateInfo sampler_info{}; + sampler_info.sType = vk::StructureType::eSamplerCreateInfo; + sampler_info.magFilter = vk::Filter::eNearest; + sampler_info.minFilter = vk::Filter::eNearest; + sampler_info.mipmapMode = vk::SamplerMipmapMode::eNearest; + sampler_info.addressModeU = vk::SamplerAddressMode::eClampToEdge; + sampler_info.addressModeV = vk::SamplerAddressMode::eClampToEdge; + sampler_info.addressModeW = vk::SamplerAddressMode::eClampToEdge; sampler_info.minLod = 0.0f; sampler_info.maxLod = 0.0f; - VkSampler sampler = VK_NULL_HANDLE; + vk::Sampler sampler = nullptr; RequireVk(shader_name, "dispatch", - vkCreateSampler(m_device, &sampler_info, nullptr, &sampler), + m_device.createSampler(&sampler_info, nullptr, &sampler), "vkCreateSampler"); return sampler; } @@ -1692,23 +1670,23 @@ public: std::vector ReadBuffer(const char *shader_name, const Buffer &buffer, size_t dword_count) { if (!buffer.coherent) { - VkMappedMemoryRange range{}; - range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; + vk::MappedMemoryRange range{}; + range.sType = vk::StructureType::eMappedMemoryRange; range.memory = buffer.memory; range.offset = 0; range.size = VK_WHOLE_SIZE; RequireVk(shader_name, "readback", - vkInvalidateMappedMemoryRanges(m_device, 1, &range), + m_device.invalidateMappedMemoryRanges(1, &range), "vkInvalidateMappedMemoryRanges"); } void *data = nullptr; RequireVk(shader_name, "readback", - vkMapMemory(m_device, buffer.memory, 0, buffer.size, 0, &data), + m_device.mapMemory(buffer.memory, 0, buffer.size, {}, &data), "vkMapMemory"); std::vector ret(dword_count, 0); std::memcpy(ret.data(), data, dword_count * sizeof(u32)); - vkUnmapMemory(m_device, buffer.memory); + m_device.unmapMemory(buffer.memory); return ret; } @@ -1717,7 +1695,7 @@ public: const Image *sampled_image = nullptr, const Image *storage_image = nullptr, const Image *storage_image_uint = nullptr, - VkSampler sampler = VK_NULL_HANDLE) { + vk::Sampler sampler = nullptr) { using Kind = ShaderRecompiler::IR::DescriptorBindingKind; const auto &layout = compiled.program.bindings; auto Binding = [&](Kind kind) { @@ -1740,30 +1718,30 @@ public: "array/3D image cases must provide matching Vulkan test views " "before dispatch"); - VkShaderModuleCreateInfo module_info{}; - module_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + vk::ShaderModuleCreateInfo module_info{}; + module_info.sType = vk::StructureType::eShaderModuleCreateInfo; module_info.codeSize = compiled.spirv.size() * sizeof(u32); module_info.pCode = compiled.spirv.data(); - VkShaderModule module = VK_NULL_HANDLE; + vk::ShaderModule module = nullptr; RequireVk(test.name, "SPIR-V module", - vkCreateShaderModule(m_device, &module_info, nullptr, &module), + m_device.createShaderModule(&module_info, nullptr, &module), "vkCreateShaderModule"); - std::vector layout_bindings; + std::vector layout_bindings; auto add_layout_binding = - [&layout_bindings](u32 binding, VkDescriptorType type, u32 count) { + [&layout_bindings](u32 binding, vk::DescriptorType type, u32 count) { if (count == 0) { return; } - VkDescriptorSetLayoutBinding item{}; + vk::DescriptorSetLayoutBinding item{}; item.binding = binding; item.descriptorType = type; item.descriptorCount = count; - item.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + item.stageFlags = vk::ShaderStageFlagBits::eCompute; layout_bindings.push_back(item); }; for (const auto &binding : layout.descriptors) { - VkDescriptorType type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + vk::DescriptorType type = vk::DescriptorType::eStorageBuffer; u32 count = static_cast(binding.resources.size()); switch (binding.kind) { case Kind::Sampled2D: @@ -1772,7 +1750,7 @@ public: case Kind::SampledUint2D: case Kind::SampledUint2DArray: case Kind::SampledUint3D: - type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + type = vk::DescriptorType::eSampledImage; break; case Kind::Storage2D: case Kind::Storage2DArray: @@ -1780,10 +1758,10 @@ public: case Kind::StorageUint2D: case Kind::StorageUint2DArray: case Kind::StorageUint3D: - type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + type = vk::DescriptorType::eStorageImage; break; case Kind::Samplers: - type = VK_DESCRIPTOR_TYPE_SAMPLER; + type = vk::DescriptorType::eSampler; break; case Kind::Gds: case Kind::FlattenedSrt: @@ -1796,53 +1774,53 @@ public: add_layout_binding(binding.binding, type, count); } - VkDescriptorSetLayoutCreateInfo layout_info{}; - layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + vk::DescriptorSetLayoutCreateInfo layout_info{}; + layout_info.sType = vk::StructureType::eDescriptorSetLayoutCreateInfo; layout_info.bindingCount = static_cast(layout_bindings.size()); layout_info.pBindings = layout_bindings.empty() ? nullptr : layout_bindings.data(); - VkDescriptorSetLayout descriptor_layout = VK_NULL_HANDLE; + vk::DescriptorSetLayout descriptor_layout = nullptr; RequireVk(test.name, "dispatch", - vkCreateDescriptorSetLayout(m_device, &layout_info, nullptr, - &descriptor_layout), + m_device.createDescriptorSetLayout(&layout_info, nullptr, + &descriptor_layout), "vkCreateDescriptorSetLayout"); - VkPipelineLayoutCreateInfo pipeline_layout_info{}; - pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + vk::PipelineLayoutCreateInfo pipeline_layout_info{}; + pipeline_layout_info.sType = vk::StructureType::ePipelineLayoutCreateInfo; pipeline_layout_info.setLayoutCount = 1; pipeline_layout_info.pSetLayouts = &descriptor_layout; - VkPushConstantRange push_range{}; + vk::PushConstantRange push_range{}; if (layout.push_constant_size != 0) { - push_range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + push_range.stageFlags = vk::ShaderStageFlagBits::eCompute; push_range.offset = layout.push_constant_offset; push_range.size = layout.push_constant_size; pipeline_layout_info.pushConstantRangeCount = 1; pipeline_layout_info.pPushConstantRanges = &push_range; } - VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; + vk::PipelineLayout pipeline_layout = nullptr; RequireVk(test.name, "dispatch", - vkCreatePipelineLayout(m_device, &pipeline_layout_info, nullptr, - &pipeline_layout), + m_device.createPipelineLayout(&pipeline_layout_info, nullptr, + &pipeline_layout), "vkCreatePipelineLayout"); - VkPipelineShaderStageCreateInfo stage{}; - stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; + vk::PipelineShaderStageCreateInfo stage{}; + stage.sType = vk::StructureType::ePipelineShaderStageCreateInfo; + stage.stage = vk::ShaderStageFlagBits::eCompute; stage.module = module; stage.pName = "main"; - VkComputePipelineCreateInfo pipeline_info{}; - pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + vk::ComputePipelineCreateInfo pipeline_info{}; + pipeline_info.sType = vk::StructureType::eComputePipelineCreateInfo; pipeline_info.stage = stage; pipeline_info.layout = pipeline_layout; - VkPipeline pipeline = VK_NULL_HANDLE; + vk::Pipeline pipeline = nullptr; RequireVk(test.name, "dispatch", - vkCreateComputePipelines(m_device, VK_NULL_HANDLE, 1, - &pipeline_info, nullptr, &pipeline), + m_device.createComputePipelines(nullptr, 1, &pipeline_info, + nullptr, &pipeline), "vkCreateComputePipelines"); - std::vector pool_sizes; - auto add_pool_size = [&pool_sizes](VkDescriptorType type, u32 count) { + std::vector pool_sizes; + auto add_pool_size = [&pool_sizes](vk::DescriptorType type, u32 count) { if (count == 0) { return; } @@ -1854,55 +1832,55 @@ public: } pool_sizes.push_back({type, count}); }; - add_pool_size(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + add_pool_size(vk::DescriptorType::eStorageBuffer, Count(Kind::Buffers) + Count(Kind::AddressMemory) + Count(Kind::Gds) + (Binding(Kind::FlattenedSrt) != nullptr ? 1u : 0u) + (Binding(Kind::UserData) != nullptr ? 1u : 0u)); - add_pool_size(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, + add_pool_size(vk::DescriptorType::eSampledImage, Count(Kind::Sampled2D) + Count(Kind::Sampled2DArray) + Count(Kind::Sampled3D) + Count(Kind::SampledUint2D) + Count(Kind::SampledUint2DArray) + Count(Kind::SampledUint3D)); - add_pool_size(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + add_pool_size(vk::DescriptorType::eStorageImage, Count(Kind::Storage2D) + Count(Kind::Storage2DArray) + Count(Kind::Storage3D) + Count(Kind::StorageUint2D) + Count(Kind::StorageUint2DArray) + Count(Kind::StorageUint3D)); - add_pool_size(VK_DESCRIPTOR_TYPE_SAMPLER, Count(Kind::Samplers)); - VkDescriptorPoolCreateInfo pool_info{}; - pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + add_pool_size(vk::DescriptorType::eSampler, Count(Kind::Samplers)); + vk::DescriptorPoolCreateInfo pool_info{}; + pool_info.sType = vk::StructureType::eDescriptorPoolCreateInfo; pool_info.maxSets = 1; pool_info.poolSizeCount = static_cast(pool_sizes.size()); pool_info.pPoolSizes = pool_sizes.empty() ? nullptr : pool_sizes.data(); - VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; + vk::DescriptorPool descriptor_pool = nullptr; RequireVk( test.name, "dispatch", - vkCreateDescriptorPool(m_device, &pool_info, nullptr, &descriptor_pool), + m_device.createDescriptorPool(&pool_info, nullptr, &descriptor_pool), "vkCreateDescriptorPool"); - VkDescriptorSetAllocateInfo set_info{}; - set_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + vk::DescriptorSetAllocateInfo set_info{}; + set_info.sType = vk::StructureType::eDescriptorSetAllocateInfo; set_info.descriptorPool = descriptor_pool; set_info.descriptorSetCount = 1; set_info.pSetLayouts = &descriptor_layout; - VkDescriptorSet descriptor_set = VK_NULL_HANDLE; + vk::DescriptorSet descriptor_set = nullptr; RequireVk(test.name, "dispatch", - vkAllocateDescriptorSets(m_device, &set_info, &descriptor_set), + m_device.allocateDescriptorSets(&set_info, &descriptor_set), "vkAllocateDescriptorSets"); - std::vector writes; - std::vector buffer_infos; - std::vector address_memory_infos; - std::vector sampled_infos; - std::vector storage_infos; - std::vector storage_uint_infos; - std::vector sampler_infos; + std::vector writes; + std::vector buffer_infos; + std::vector address_memory_infos; + std::vector sampled_infos; + std::vector storage_infos; + std::vector storage_uint_infos; + std::vector sampler_infos; Buffer flattened_buffer; Buffer user_data_buffer; - VkDescriptorBufferInfo flattened_info{}; - VkDescriptorBufferInfo user_data_info{}; - VkDescriptorBufferInfo gds_info{}; + vk::DescriptorBufferInfo flattened_info{}; + vk::DescriptorBufferInfo user_data_info{}; + vk::DescriptorBufferInfo gds_info{}; const auto *buffers = Binding(Kind::Buffers); if (buffers != nullptr) { @@ -1912,18 +1890,18 @@ public: info.offset = 0; info.range = buffer.size; if (test.storage_buffer_range_dwords != 0) { - info.range = static_cast( + info.range = static_cast( test.storage_buffer_range_dwords * sizeof(u32)); Require(test.name, "dispatch", info.range <= buffer.size, "storage buffer descriptor range exceeds backing buffer"); } } - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = buffers->binding; write.descriptorCount = static_cast(buffer_infos.size()); - write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + write.descriptorType = vk::DescriptorType::eStorageBuffer; write.pBufferInfo = buffer_infos.data(); writes.push_back(write); } @@ -1933,12 +1911,12 @@ public: for (auto &info : address_memory_infos) { info = {buffer.buffer, 0, buffer.size}; } - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = address->binding; write.descriptorCount = static_cast(address_memory_infos.size()); - write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + write.descriptorType = vk::DescriptorType::eStorageBuffer; write.pBufferInfo = address_memory_infos.data(); writes.push_back(write); } @@ -1947,12 +1925,12 @@ public: flattened_buffer = CreateStorageBuffer(test.name, compiled.flattened_srt, compiled.flattened_srt.size()); flattened_info = {flattened_buffer.buffer, 0, flattened_buffer.size}; - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = flattened->binding; write.descriptorCount = 1; - write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + write.descriptorType = vk::DescriptorType::eStorageBuffer; write.pBufferInfo = &flattened_info; writes.push_back(write); } @@ -1961,12 +1939,12 @@ public: CreateStorageBuffer(test.name, compiled.packed_user_data, compiled.packed_user_data.size()); user_data_info = {user_data_buffer.buffer, 0, user_data_buffer.size}; - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = user->binding; write.descriptorCount = 1; - write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + write.descriptorType = vk::DescriptorType::eStorageBuffer; write.pBufferInfo = &user_data_info; writes.push_back(write); } @@ -1974,12 +1952,12 @@ public: Require(test.name, "dispatch", gds_buffer != nullptr, "GDS descriptor requested but no GDS buffer was provided"); gds_info = {gds_buffer->buffer, 0, gds_buffer->size}; - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = gds->binding; write.descriptorCount = 1; - write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + write.descriptorType = vk::DescriptorType::eStorageBuffer; write.pBufferInfo = &gds_info; writes.push_back(write); } @@ -2000,12 +1978,12 @@ public: info.imageView = sampled_image->view; info.imageLayout = sampled_image->layout; } - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = sampled->binding; write.descriptorCount = static_cast(sampled_infos.size()); - write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + write.descriptorType = vk::DescriptorType::eSampledImage; write.pImageInfo = sampled_infos.data(); writes.push_back(write); } @@ -2030,105 +2008,105 @@ public: info.imageLayout = storage_image_uint->layout; } if (storage != nullptr) { - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = storage->binding; write.descriptorCount = static_cast(storage_infos.size()); - write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + write.descriptorType = vk::DescriptorType::eStorageImage; write.pImageInfo = storage_infos.data(); writes.push_back(write); } if (storage_uint != nullptr) { - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = storage_uint->binding; write.descriptorCount = static_cast(storage_uint_infos.size()); - write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + write.descriptorType = vk::DescriptorType::eStorageImage; write.pImageInfo = storage_uint_infos.data(); writes.push_back(write); } } const auto *samplers = Binding(Kind::Samplers); if (samplers != nullptr) { - Require(test.name, "dispatch", sampler != VK_NULL_HANDLE, + Require(test.name, "dispatch", sampler != nullptr, "sampler descriptor requested but no sampler was provided"); sampler_infos.resize(samplers->resources.size()); for (auto &info : sampler_infos) { info.sampler = sampler; } - VkWriteDescriptorSet write{}; - write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + vk::WriteDescriptorSet write{}; + write.sType = vk::StructureType::eWriteDescriptorSet; write.dstSet = descriptor_set; write.dstBinding = samplers->binding; write.descriptorCount = static_cast(sampler_infos.size()); - write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; + write.descriptorType = vk::DescriptorType::eSampler; write.pImageInfo = sampler_infos.data(); writes.push_back(write); } if (!writes.empty()) { - vkUpdateDescriptorSets(m_device, static_cast(writes.size()), - writes.data(), 0, nullptr); + m_device.updateDescriptorSets(static_cast(writes.size()), + writes.data(), 0, nullptr); } - VkCommandBuffer cmd = BeginCommands(test.name, "dispatch"); - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); - vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, - pipeline_layout, 0, 1, &descriptor_set, 0, nullptr); + vk::CommandBuffer cmd = BeginCommands(test.name, "dispatch"); + cmd.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline); + cmd.bindDescriptorSets(vk::PipelineBindPoint::eCompute, pipeline_layout, 0, + 1, &descriptor_set, 0, nullptr); if (layout.push_constant_size != 0) { Require(test.name, "dispatch", compiled.packed_user_data.size() * sizeof(u32) == layout.push_constant_size, "native user-data size does not match push-constant range"); - vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, - layout.push_constant_offset, layout.push_constant_size, - compiled.packed_user_data.data()); + cmd.pushConstants(pipeline_layout, vk::ShaderStageFlagBits::eCompute, + layout.push_constant_offset, layout.push_constant_size, + compiled.packed_user_data.data()); } - vkCmdDispatch(cmd, test.dispatch_x, test.dispatch_y, test.dispatch_z); + cmd.dispatch(test.dispatch_x, test.dispatch_y, test.dispatch_z); if (buffers != nullptr) { - VkBufferMemoryBarrier barrier{}; - barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; + vk::BufferMemoryBarrier barrier{}; + barrier.sType = vk::StructureType::eBufferMemoryBarrier; barrier.srcAccessMask = - VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT; + vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite; + barrier.dstAccessMask = vk::AccessFlagBits::eHostRead; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.buffer = buffer.buffer; barrier.offset = 0; barrier.size = buffer.size; - vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 1, - &barrier, 0, nullptr); + cmd.pipelineBarrier(vk::PipelineStageFlagBits::eComputeShader, + vk::PipelineStageFlagBits::eHost, {}, 0, nullptr, 1, + &barrier, 0, nullptr); } if (gds_buffer != nullptr) { - VkBufferMemoryBarrier barrier{}; - barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; + vk::BufferMemoryBarrier barrier{}; + barrier.sType = vk::StructureType::eBufferMemoryBarrier; barrier.srcAccessMask = - VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT; + vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite; + barrier.dstAccessMask = vk::AccessFlagBits::eHostRead; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.buffer = gds_buffer->buffer; barrier.offset = 0; barrier.size = gds_buffer->size; - vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 1, - &barrier, 0, nullptr); + cmd.pipelineBarrier(vk::PipelineStageFlagBits::eComputeShader, + vk::PipelineStageFlagBits::eHost, {}, 0, nullptr, 1, + &barrier, 0, nullptr); } EndSubmitAndFree(test.name, "dispatch", cmd); - if (flattened_buffer.buffer != VK_NULL_HANDLE) { + if (flattened_buffer.buffer != nullptr) { DestroyBuffer(&flattened_buffer); } - if (user_data_buffer.buffer != VK_NULL_HANDLE) { + if (user_data_buffer.buffer != nullptr) { DestroyBuffer(&user_data_buffer); } - vkDestroyDescriptorPool(m_device, descriptor_pool, nullptr); - vkDestroyPipeline(m_device, pipeline, nullptr); - vkDestroyPipelineLayout(m_device, pipeline_layout, nullptr); - vkDestroyDescriptorSetLayout(m_device, descriptor_layout, nullptr); - vkDestroyShaderModule(m_device, module, nullptr); + m_device.destroyDescriptorPool(descriptor_pool, nullptr); + m_device.destroyPipeline(pipeline, nullptr); + m_device.destroyPipelineLayout(pipeline_layout, nullptr); + m_device.destroyDescriptorSetLayout(descriptor_layout, nullptr); + m_device.destroyShaderModule(module, nullptr); } std::vector RenderFragment(const GraphicsCase &test, @@ -2136,9 +2114,10 @@ public: const auto vertex_spirv = TestSpv::MakePassthroughVertexSpirv(); ValidateSpirv(test.name, vertex_spirv); - Image target = CreateImage2D(test.name, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, {}, 4, - VK_IMAGE_LAYOUT_GENERAL); + Image target = + CreateImage2D(test.name, 1, 1, vk::Format::eR32G32B32A32Sfloat, + vk::ImageUsageFlagBits::eColorAttachment, {}, 4, + vk::ImageLayout::eGeneral); const std::vector default_vertices = { 0xbf800000u, 0xbf800000u, 0x3e800000u, 0x3f000000u, 0x3f400000u, 0x3f800000u, 0x40400000u, 0xbf800000u, 0x3e800000u, 0x3f000000u, @@ -2151,169 +2130,165 @@ public: "graphics vertex buffer must contain three pos2/color4 vertices"); auto vertex_buffer = CreateHostBuffer(test.name, vertices.size() * sizeof(u32), - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, vertices); + vk::BufferUsageFlagBits::eVertexBuffer, vertices); auto make_module = [&](const std::vector &spirv) { - VkShaderModuleCreateInfo module_info{}; - module_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + vk::ShaderModuleCreateInfo module_info{}; + module_info.sType = vk::StructureType::eShaderModuleCreateInfo; module_info.codeSize = spirv.size() * sizeof(u32); module_info.pCode = spirv.data(); - VkShaderModule module = VK_NULL_HANDLE; + vk::ShaderModule module = nullptr; RequireVk(test.name, "graphics", - vkCreateShaderModule(m_device, &module_info, nullptr, &module), + m_device.createShaderModule(&module_info, nullptr, &module), "vkCreateShaderModule"); return module; }; - VkShaderModule vertex_module = make_module(vertex_spirv); - VkShaderModule fragment_module = make_module(fragment.spirv); + vk::ShaderModule vertex_module = make_module(vertex_spirv); + vk::ShaderModule fragment_module = make_module(fragment.spirv); - VkAttachmentDescription attachment{}; - attachment.format = VK_FORMAT_R32G32B32A32_SFLOAT; - attachment.samples = VK_SAMPLE_COUNT_1_BIT; - attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; - attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; - attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachment.initialLayout = VK_IMAGE_LAYOUT_GENERAL; - attachment.finalLayout = VK_IMAGE_LAYOUT_GENERAL; + vk::AttachmentDescription attachment{}; + attachment.format = vk::Format::eR32G32B32A32Sfloat; + attachment.samples = vk::SampleCountFlagBits::e1; + attachment.loadOp = vk::AttachmentLoadOp::eClear; + attachment.storeOp = vk::AttachmentStoreOp::eStore; + attachment.stencilLoadOp = vk::AttachmentLoadOp::eDontCare; + attachment.stencilStoreOp = vk::AttachmentStoreOp::eDontCare; + attachment.initialLayout = vk::ImageLayout::eGeneral; + attachment.finalLayout = vk::ImageLayout::eGeneral; - VkAttachmentReference color_ref{}; + vk::AttachmentReference color_ref{}; color_ref.attachment = 0; - color_ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + color_ref.layout = vk::ImageLayout::eColorAttachmentOptimal; - VkSubpassDescription subpass{}; - subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + vk::SubpassDescription subpass{}; + subpass.pipelineBindPoint = vk::PipelineBindPoint::eGraphics; subpass.colorAttachmentCount = 1; subpass.pColorAttachments = &color_ref; - VkRenderPassCreateInfo render_pass_info{}; - render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + vk::RenderPassCreateInfo render_pass_info{}; + render_pass_info.sType = vk::StructureType::eRenderPassCreateInfo; render_pass_info.attachmentCount = 1; render_pass_info.pAttachments = &attachment; render_pass_info.subpassCount = 1; render_pass_info.pSubpasses = &subpass; - VkRenderPass render_pass = VK_NULL_HANDLE; + vk::RenderPass render_pass = nullptr; RequireVk( test.name, "graphics", - vkCreateRenderPass(m_device, &render_pass_info, nullptr, &render_pass), + m_device.createRenderPass(&render_pass_info, nullptr, &render_pass), "vkCreateRenderPass"); - VkFramebufferCreateInfo framebuffer_info{}; - framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + vk::FramebufferCreateInfo framebuffer_info{}; + framebuffer_info.sType = vk::StructureType::eFramebufferCreateInfo; framebuffer_info.renderPass = render_pass; framebuffer_info.attachmentCount = 1; framebuffer_info.pAttachments = &target.view; framebuffer_info.width = 1; framebuffer_info.height = 1; framebuffer_info.layers = 1; - VkFramebuffer framebuffer = VK_NULL_HANDLE; + vk::Framebuffer framebuffer = nullptr; RequireVk( test.name, "graphics", - vkCreateFramebuffer(m_device, &framebuffer_info, nullptr, &framebuffer), + m_device.createFramebuffer(&framebuffer_info, nullptr, &framebuffer), "vkCreateFramebuffer"); const auto &fragment_bind = fragment.program.bindings; - VkPushConstantRange push_constant_range{}; + vk::PushConstantRange push_constant_range{}; if (fragment_bind.push_constant_size > 0) { Require(test.name, "graphics", test.push_constants.size() * sizeof(u32) == fragment_bind.push_constant_size, "fragment push constant data size does not match reflection"); - push_constant_range.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + push_constant_range.stageFlags = vk::ShaderStageFlagBits::eFragment; push_constant_range.offset = fragment_bind.push_constant_offset; push_constant_range.size = fragment_bind.push_constant_size; } - VkPipelineLayoutCreateInfo pipeline_layout_info{}; - pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + vk::PipelineLayoutCreateInfo pipeline_layout_info{}; + pipeline_layout_info.sType = vk::StructureType::ePipelineLayoutCreateInfo; pipeline_layout_info.pushConstantRangeCount = push_constant_range.size != 0 ? 1u : 0u; pipeline_layout_info.pPushConstantRanges = push_constant_range.size != 0 ? &push_constant_range : nullptr; - VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; + vk::PipelineLayout pipeline_layout = nullptr; RequireVk(test.name, "graphics", - vkCreatePipelineLayout(m_device, &pipeline_layout_info, nullptr, - &pipeline_layout), + m_device.createPipelineLayout(&pipeline_layout_info, nullptr, + &pipeline_layout), "vkCreatePipelineLayout"); - VkPipelineShaderStageCreateInfo stages[2] = {}; - stages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; + vk::PipelineShaderStageCreateInfo stages[2] = {}; + stages[0].sType = vk::StructureType::ePipelineShaderStageCreateInfo; + stages[0].stage = vk::ShaderStageFlagBits::eVertex; stages[0].module = vertex_module; stages[0].pName = "main"; - stages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + stages[1].sType = vk::StructureType::ePipelineShaderStageCreateInfo; + stages[1].stage = vk::ShaderStageFlagBits::eFragment; stages[1].module = fragment_module; stages[1].pName = "main"; - VkVertexInputBindingDescription vertex_binding{}; + vk::VertexInputBindingDescription vertex_binding{}; vertex_binding.binding = 0; vertex_binding.stride = 6u * sizeof(float); - vertex_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; - VkVertexInputAttributeDescription attributes[2] = {}; + vertex_binding.inputRate = vk::VertexInputRate::eVertex; + vk::VertexInputAttributeDescription attributes[2] = {}; attributes[0].location = 0; attributes[0].binding = 0; - attributes[0].format = VK_FORMAT_R32G32_SFLOAT; + attributes[0].format = vk::Format::eR32G32Sfloat; attributes[0].offset = 0; attributes[1].location = 1; attributes[1].binding = 0; - attributes[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; + attributes[1].format = vk::Format::eR32G32B32A32Sfloat; attributes[1].offset = 2u * sizeof(float); - VkPipelineVertexInputStateCreateInfo vertex_input{}; - vertex_input.sType = - VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vk::PipelineVertexInputStateCreateInfo vertex_input{}; + vertex_input.sType = vk::StructureType::ePipelineVertexInputStateCreateInfo; vertex_input.vertexBindingDescriptionCount = 1; vertex_input.pVertexBindingDescriptions = &vertex_binding; vertex_input.vertexAttributeDescriptionCount = 2; vertex_input.pVertexAttributeDescriptions = attributes; - VkPipelineInputAssemblyStateCreateInfo input_assembly{}; + vk::PipelineInputAssemblyStateCreateInfo input_assembly{}; input_assembly.sType = - VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + vk::StructureType::ePipelineInputAssemblyStateCreateInfo; + input_assembly.topology = vk::PrimitiveTopology::eTriangleList; - VkViewport viewport{}; + vk::Viewport viewport{}; viewport.x = 0.0f; viewport.y = 0.0f; viewport.width = 1.0f; viewport.height = 1.0f; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; - VkRect2D scissor{}; + vk::Rect2D scissor{}; scissor.extent.width = 1; scissor.extent.height = 1; - VkPipelineViewportStateCreateInfo viewport_state{}; - viewport_state.sType = - VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + vk::PipelineViewportStateCreateInfo viewport_state{}; + viewport_state.sType = vk::StructureType::ePipelineViewportStateCreateInfo; viewport_state.viewportCount = 1; viewport_state.pViewports = &viewport; viewport_state.scissorCount = 1; viewport_state.pScissors = &scissor; - VkPipelineRasterizationStateCreateInfo raster{}; - raster.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - raster.polygonMode = VK_POLYGON_MODE_FILL; - raster.cullMode = VK_CULL_MODE_NONE; - raster.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + vk::PipelineRasterizationStateCreateInfo raster{}; + raster.sType = vk::StructureType::ePipelineRasterizationStateCreateInfo; + raster.polygonMode = vk::PolygonMode::eFill; + raster.cullMode = vk::CullModeFlagBits::eNone; + raster.frontFace = vk::FrontFace::eCounterClockwise; raster.lineWidth = 1.0f; - VkPipelineMultisampleStateCreateInfo multisample{}; - multisample.sType = - VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisample.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + vk::PipelineMultisampleStateCreateInfo multisample{}; + multisample.sType = vk::StructureType::ePipelineMultisampleStateCreateInfo; + multisample.rasterizationSamples = vk::SampleCountFlagBits::e1; - VkPipelineColorBlendAttachmentState color_attachment{}; + vk::PipelineColorBlendAttachmentState color_attachment{}; color_attachment.colorWriteMask = - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - VkPipelineColorBlendStateCreateInfo color_blend{}; - color_blend.sType = - VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | + vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA; + vk::PipelineColorBlendStateCreateInfo color_blend{}; + color_blend.sType = vk::StructureType::ePipelineColorBlendStateCreateInfo; color_blend.attachmentCount = 1; color_blend.pAttachments = &color_attachment; - VkGraphicsPipelineCreateInfo pipeline_info{}; - pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + vk::GraphicsPipelineCreateInfo pipeline_info{}; + pipeline_info.sType = vk::StructureType::eGraphicsPipelineCreateInfo; pipeline_info.stageCount = 2; pipeline_info.pStages = stages; pipeline_info.pVertexInputState = &vertex_input; @@ -2324,46 +2299,46 @@ public: pipeline_info.pColorBlendState = &color_blend; pipeline_info.layout = pipeline_layout; pipeline_info.renderPass = render_pass; - VkPipeline pipeline = VK_NULL_HANDLE; + vk::Pipeline pipeline = nullptr; RequireVk(test.name, "graphics", - vkCreateGraphicsPipelines(m_device, VK_NULL_HANDLE, 1, - &pipeline_info, nullptr, &pipeline), + m_device.createGraphicsPipelines(nullptr, 1, &pipeline_info, + nullptr, &pipeline), "vkCreateGraphicsPipelines"); - VkCommandBuffer cmd = BeginCommands(test.name, "graphics"); - VkClearValue clear{}; - VkRenderPassBeginInfo begin{}; - begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + vk::CommandBuffer cmd = BeginCommands(test.name, "graphics"); + vk::ClearValue clear{}; + vk::RenderPassBeginInfo begin{}; + begin.sType = vk::StructureType::eRenderPassBeginInfo; begin.renderPass = render_pass; begin.framebuffer = framebuffer; begin.renderArea.extent.width = 1; begin.renderArea.extent.height = 1; begin.clearValueCount = 1; begin.pClearValues = &clear; - vkCmdBeginRenderPass(cmd, &begin, VK_SUBPASS_CONTENTS_INLINE); - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); + cmd.beginRenderPass(&begin, vk::SubpassContents::eInline); + cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline); if (push_constant_range.size != 0) { - vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, - fragment_bind.push_constant_offset, - fragment_bind.push_constant_size, - test.push_constants.data()); + cmd.pushConstants(pipeline_layout, vk::ShaderStageFlagBits::eFragment, + fragment_bind.push_constant_offset, + fragment_bind.push_constant_size, + test.push_constants.data()); } - VkDeviceSize offset = 0; - vkCmdBindVertexBuffers(cmd, 0, 1, &vertex_buffer.buffer, &offset); - vkCmdDraw(cmd, 3, 1, 0, 0); - vkCmdEndRenderPass(cmd); + vk::DeviceSize offset = 0; + cmd.bindVertexBuffers(0, 1, &vertex_buffer.buffer, &offset); + cmd.draw(3, 1, 0, 0); + cmd.endRenderPass(); EndSubmitAndFree(test.name, "graphics", cmd); - target.layout = VK_IMAGE_LAYOUT_GENERAL; + target.layout = vk::ImageLayout::eGeneral; auto pixel = ReadImage(test.name, &target); pixel.resize(4); - vkDestroyPipeline(m_device, pipeline, nullptr); - vkDestroyPipelineLayout(m_device, pipeline_layout, nullptr); - vkDestroyFramebuffer(m_device, framebuffer, nullptr); - vkDestroyRenderPass(m_device, render_pass, nullptr); - vkDestroyShaderModule(m_device, fragment_module, nullptr); - vkDestroyShaderModule(m_device, vertex_module, nullptr); + m_device.destroyPipeline(pipeline, nullptr); + m_device.destroyPipelineLayout(pipeline_layout, nullptr); + m_device.destroyFramebuffer(framebuffer, nullptr); + m_device.destroyRenderPass(render_pass, nullptr); + m_device.destroyShaderModule(fragment_module, nullptr); + m_device.destroyShaderModule(vertex_module, nullptr); DestroyBuffer(&vertex_buffer); DestroyImage(&target); return pixel; @@ -2371,14 +2346,14 @@ public: private: void EnsureRuntimeContext() { - if (m_runtime_context.allocator != VK_NULL_HANDLE) { + if (m_runtime_context.allocator != nullptr) { return; } m_runtime_context.instance = m_instance; m_runtime_context.physical_device = m_physical_device; m_runtime_context.device = m_device; - vkGetPhysicalDeviceProperties(m_physical_device, - &m_runtime_context.physical_device_properties); + m_physical_device.getProperties( + &m_runtime_context.physical_device_properties); m_runtime_context.physical_device_memory_properties = m_memory_properties; for (auto &queue : m_runtime_context.queues) { queue.mutex = &m_runtime_queue_mutex; @@ -2387,13 +2362,21 @@ private: queue.vk_queue = m_queue; } + VmaVulkanFunctions functions{}; + functions.vkGetInstanceProcAddr = + VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = + VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + VmaAllocatorCreateInfo allocator_info{}; allocator_info.instance = m_instance; allocator_info.physicalDevice = m_physical_device; allocator_info.device = m_device; + allocator_info.pVulkanFunctions = &functions; allocator_info.vulkanApiVersion = VK_API_VERSION_1_2; RequireVk("VulkanHarness", "runtime context", - vmaCreateAllocator(&allocator_info, &m_runtime_context.allocator), + static_cast(vmaCreateAllocator( + &allocator_info, &m_runtime_context.allocator)), "vmaCreateAllocator"); if (g_render_ctx == nullptr) { GraphicsRenderInit(); @@ -2402,114 +2385,120 @@ private: } void Init() { - VkApplicationInfo app{}; - app.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + static vk::detail::DynamicLoader loader; + const auto get_instance_proc_addr = + loader.getProcAddress( + "vkGetInstanceProcAddr"); + Require("VulkanHarness", "dispatch", get_instance_proc_addr != nullptr, + "could not load the Vulkan loader"); + VULKAN_HPP_DEFAULT_DISPATCHER.init(get_instance_proc_addr); + + vk::ApplicationInfo app{}; + app.sType = vk::StructureType::eApplicationInfo; app.pApplicationName = "ShaderRecompilerComputeTests"; app.apiVersion = VK_API_VERSION_1_2; - VkInstanceCreateInfo instance_info{}; - instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + vk::InstanceCreateInfo instance_info{}; + instance_info.sType = vk::StructureType::eInstanceCreateInfo; instance_info.pApplicationInfo = &app; RequireVk("VulkanHarness", "dispatch", - vkCreateInstance(&instance_info, nullptr, &m_instance), + vk::createInstance(&instance_info, nullptr, &m_instance), "vkCreateInstance"); + VULKAN_HPP_DEFAULT_DISPATCHER.init(m_instance); u32 physical_count = 0; RequireVk("VulkanHarness", "dispatch", - vkEnumeratePhysicalDevices(m_instance, &physical_count, nullptr), + m_instance.enumeratePhysicalDevices(&physical_count, nullptr), "vkEnumeratePhysicalDevices"); Require("VulkanHarness", "dispatch", physical_count != 0, "no Vulkan physical devices"); - std::vector physical_devices(physical_count); + std::vector physical_devices(physical_count); RequireVk("VulkanHarness", "dispatch", - vkEnumeratePhysicalDevices(m_instance, &physical_count, - physical_devices.data()), + m_instance.enumeratePhysicalDevices(&physical_count, + physical_devices.data()), "vkEnumeratePhysicalDevices"); for (auto physical : physical_devices) { u32 queue_count = 0; - vkGetPhysicalDeviceQueueFamilyProperties(physical, &queue_count, nullptr); - std::vector queues(queue_count); - vkGetPhysicalDeviceQueueFamilyProperties(physical, &queue_count, - queues.data()); + physical.getQueueFamilyProperties(&queue_count, nullptr); + std::vector queues(queue_count); + physical.getQueueFamilyProperties(&queue_count, queues.data()); for (u32 i = 0; i < queue_count; i++) { if ((queues[i].queueFlags & - (VK_QUEUE_COMPUTE_BIT | VK_QUEUE_GRAPHICS_BIT)) == - (VK_QUEUE_COMPUTE_BIT | VK_QUEUE_GRAPHICS_BIT)) { + (vk::QueueFlagBits::eCompute | vk::QueueFlagBits::eGraphics)) == + (vk::QueueFlagBits::eCompute | vk::QueueFlagBits::eGraphics)) { m_physical_device = physical; m_queue_family = i; break; } } - if (m_physical_device != VK_NULL_HANDLE) { + if (m_physical_device != nullptr) { break; } } - Require("VulkanHarness", "dispatch", m_physical_device != VK_NULL_HANDLE, + Require("VulkanHarness", "dispatch", m_physical_device != nullptr, "no Vulkan graphics+compute queue family"); - vkGetPhysicalDeviceMemoryProperties(m_physical_device, - &m_memory_properties); + m_physical_device.getMemoryProperties(&m_memory_properties); - VkPhysicalDeviceFeatures available_features{}; - vkGetPhysicalDeviceFeatures(m_physical_device, &available_features); + vk::PhysicalDeviceFeatures available_features{}; + m_physical_device.getFeatures(&available_features); Require("VulkanHarness", "dispatch", - available_features.shaderStorageImageWriteWithoutFormat == VK_TRUE, + available_features.shaderStorageImageWriteWithoutFormat == true, "shaderStorageImageWriteWithoutFormat is not supported"); Require("VulkanHarness", "dispatch", - available_features.shaderStorageImageReadWithoutFormat == VK_TRUE, + available_features.shaderStorageImageReadWithoutFormat == true, "shaderStorageImageReadWithoutFormat is not supported"); float priority = 1.0f; - VkDeviceQueueCreateInfo queue_info{}; - queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + vk::DeviceQueueCreateInfo queue_info{}; + queue_info.sType = vk::StructureType::eDeviceQueueCreateInfo; queue_info.queueFamilyIndex = m_queue_family; queue_info.queueCount = 1; queue_info.pQueuePriorities = &priority; - VkDeviceCreateInfo device_info{}; - device_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + vk::DeviceCreateInfo device_info{}; + device_info.sType = vk::StructureType::eDeviceCreateInfo; device_info.queueCreateInfoCount = 1; device_info.pQueueCreateInfos = &queue_info; - VkPhysicalDeviceFeatures device_features{}; - device_features.shaderStorageImageWriteWithoutFormat = VK_TRUE; - device_features.shaderStorageImageReadWithoutFormat = VK_TRUE; + vk::PhysicalDeviceFeatures device_features{}; + device_features.shaderStorageImageWriteWithoutFormat = true; + device_features.shaderStorageImageReadWithoutFormat = true; device_info.pEnabledFeatures = &device_features; - RequireVk( - "VulkanHarness", "dispatch", - vkCreateDevice(m_physical_device, &device_info, nullptr, &m_device), - "vkCreateDevice"); - vkGetDeviceQueue(m_device, m_queue_family, 0, &m_queue); + RequireVk("VulkanHarness", "dispatch", + m_physical_device.createDevice(&device_info, nullptr, &m_device), + "vkCreateDevice"); + VULKAN_HPP_DEFAULT_DISPATCHER.init(m_device); + m_device.getQueue(m_queue_family, 0, &m_queue); - VkCommandPoolCreateInfo pool_info{}; - pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + vk::CommandPoolCreateInfo pool_info{}; + pool_info.sType = vk::StructureType::eCommandPoolCreateInfo; pool_info.queueFamilyIndex = m_queue_family; - pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - RequireVk( - "VulkanHarness", "dispatch", - vkCreateCommandPool(m_device, &pool_info, nullptr, &m_command_pool), - "vkCreateCommandPool"); + pool_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; + RequireVk("VulkanHarness", "dispatch", + m_device.createCommandPool(&pool_info, nullptr, &m_command_pool), + "vkCreateCommandPool"); } void Destroy() { - if (m_device != VK_NULL_HANDLE) { - vkDeviceWaitIdle(m_device); - if (m_runtime_context.allocator != VK_NULL_HANDLE) { + if (m_device != nullptr) { + m_device.waitIdle(); + if (m_runtime_context.allocator != nullptr) { GraphicsRenderReleaseThreadCommandPools(); UtilReleaseCachedResources(&m_runtime_context); vmaDestroyAllocator(m_runtime_context.allocator); - m_runtime_context.allocator = VK_NULL_HANDLE; + m_runtime_context.allocator = nullptr; } - if (m_command_pool != VK_NULL_HANDLE) { - vkDestroyCommandPool(m_device, m_command_pool, nullptr); + if (m_command_pool != nullptr) { + m_device.destroyCommandPool(m_command_pool, nullptr); } - vkDestroyDevice(m_device, nullptr); + m_device.destroy(nullptr); } - if (m_instance != VK_NULL_HANDLE) { - vkDestroyInstance(m_instance, nullptr); + if (m_instance != nullptr) { + m_instance.destroy(nullptr); } } - bool FindMemoryType(u32 type_bits, VkMemoryPropertyFlags required, + bool FindMemoryType(u32 type_bits, vk::MemoryPropertyFlags required, u32 *index) const { for (u32 i = 0; i < m_memory_properties.memoryTypeCount; i++) { if ((type_bits & (1u << i)) == 0) { @@ -2524,73 +2513,72 @@ private: return false; } - static VkAccessFlags AccessForLayout(VkImageLayout layout) { + static vk::AccessFlags AccessForLayout(vk::ImageLayout layout) { switch (layout) { - case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: - return VK_ACCESS_TRANSFER_WRITE_BIT; - case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - return VK_ACCESS_TRANSFER_READ_BIT; - case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: - return VK_ACCESS_SHADER_READ_BIT; - case VK_IMAGE_LAYOUT_GENERAL: - return VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; + case vk::ImageLayout::eTransferDstOptimal: + return vk::AccessFlagBits::eTransferWrite; + case vk::ImageLayout::eTransferSrcOptimal: + return vk::AccessFlagBits::eTransferRead; + case vk::ImageLayout::eShaderReadOnlyOptimal: + return vk::AccessFlagBits::eShaderRead; + case vk::ImageLayout::eGeneral: + return vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite; default: - return 0; + return {}; } } - VkCommandBuffer BeginCommands(const char *shader_name, const char *stage) { - VkCommandBufferAllocateInfo cmd_alloc{}; - cmd_alloc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + vk::CommandBuffer BeginCommands(const char *shader_name, const char *stage) { + vk::CommandBufferAllocateInfo cmd_alloc{}; + cmd_alloc.sType = vk::StructureType::eCommandBufferAllocateInfo; cmd_alloc.commandPool = m_command_pool; - cmd_alloc.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + cmd_alloc.level = vk::CommandBufferLevel::ePrimary; cmd_alloc.commandBufferCount = 1; - VkCommandBuffer cmd = VK_NULL_HANDLE; + vk::CommandBuffer cmd = nullptr; RequireVk(shader_name, stage, - vkAllocateCommandBuffers(m_device, &cmd_alloc, &cmd), + m_device.allocateCommandBuffers(&cmd_alloc, &cmd), "vkAllocateCommandBuffers"); - VkCommandBufferBeginInfo begin{}; - begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - RequireVk(shader_name, stage, vkBeginCommandBuffer(cmd, &begin), - "vkBeginCommandBuffer"); + vk::CommandBufferBeginInfo begin{}; + begin.sType = vk::StructureType::eCommandBufferBeginInfo; + begin.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit; + RequireVk(shader_name, stage, cmd.begin(&begin), "vkBeginCommandBuffer"); return cmd; } void EndSubmitAndFree(const char *shader_name, const char *stage, - VkCommandBuffer cmd) { - RequireVk(shader_name, stage, vkEndCommandBuffer(cmd), - "vkEndCommandBuffer"); + vk::CommandBuffer cmd) { + RequireVk(shader_name, stage, cmd.end(), "vkEndCommandBuffer"); - VkFenceCreateInfo fence_info{}; - fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; - VkFence fence = VK_NULL_HANDLE; + vk::FenceCreateInfo fence_info{}; + fence_info.sType = vk::StructureType::eFenceCreateInfo; + vk::Fence fence = nullptr; RequireVk(shader_name, stage, - vkCreateFence(m_device, &fence_info, nullptr, &fence), + m_device.createFence(&fence_info, nullptr, &fence), "vkCreateFence"); - VkSubmitInfo submit{}; - submit.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + vk::SubmitInfo submit{}; + submit.sType = vk::StructureType::eSubmitInfo; submit.commandBufferCount = 1; submit.pCommandBuffers = &cmd; - RequireVk(shader_name, stage, vkQueueSubmit(m_queue, 1, &submit, fence), + RequireVk(shader_name, stage, m_queue.submit(1, &submit, fence), "vkQueueSubmit"); RequireVk(shader_name, stage, - vkWaitForFences(m_device, 1, &fence, VK_TRUE, UINT64_MAX), + m_device.waitForFences(1, &fence, true, UINT64_MAX), "vkWaitForFences"); - vkDestroyFence(m_device, fence, nullptr); - vkFreeCommandBuffers(m_device, m_command_pool, 1, &cmd); + m_device.destroyFence(fence, nullptr); + m_device.freeCommandBuffers(m_command_pool, 1, &cmd); } - void AddImageBarrier(VkCommandBuffer cmd, VkImage image, - VkImageLayout old_layout, VkImageLayout new_layout, - VkPipelineStageFlags src_stage, - VkPipelineStageFlags dst_stage, VkAccessFlags src_access, - VkAccessFlags dst_access, u32 mip_levels = 1) { - VkImageMemoryBarrier barrier{}; - barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + void AddImageBarrier(vk::CommandBuffer cmd, vk::Image image, + vk::ImageLayout old_layout, vk::ImageLayout new_layout, + vk::PipelineStageFlags src_stage, + vk::PipelineStageFlags dst_stage, + vk::AccessFlags src_access, vk::AccessFlags dst_access, + u32 mip_levels = 1) { + vk::ImageMemoryBarrier barrier{}; + barrier.sType = vk::StructureType::eImageMemoryBarrier; barrier.srcAccessMask = src_access; barrier.dstAccessMask = dst_access; barrier.oldLayout = old_layout; @@ -2598,46 +2586,47 @@ private: barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.image = image; - barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; barrier.subresourceRange.baseMipLevel = 0; barrier.subresourceRange.levelCount = mip_levels; barrier.subresourceRange.baseArrayLayer = 0; barrier.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(cmd, src_stage, dst_stage, 0, 0, nullptr, 0, nullptr, - 1, &barrier); + cmd.pipelineBarrier(src_stage, dst_stage, {}, 0, nullptr, 0, nullptr, 1, + &barrier); } void TransitionImage(const char *shader_name, Image *image, - VkImageLayout new_layout, VkPipelineStageFlags src_stage, - VkPipelineStageFlags dst_stage, VkAccessFlags src_access, - VkAccessFlags dst_access) { - VkCommandBuffer cmd = BeginCommands(shader_name, "dispatch"); + vk::ImageLayout new_layout, + vk::PipelineStageFlags src_stage, + vk::PipelineStageFlags dst_stage, + vk::AccessFlags src_access, vk::AccessFlags dst_access) { + vk::CommandBuffer cmd = BeginCommands(shader_name, "dispatch"); AddImageBarrier(cmd, image->image, image->layout, new_layout, src_stage, dst_stage, src_access, dst_access, image->mip_levels); EndSubmitAndFree(shader_name, "dispatch", cmd); image->layout = new_layout; } - void UploadImage(const char *shader_name, Image *image, VkBuffer staging, - VkImageLayout final_layout) { + void UploadImage(const char *shader_name, Image *image, vk::Buffer staging, + vk::ImageLayout final_layout) { UploadImageMips(shader_name, image, staging, final_layout); } - void UploadImageMips(const char *shader_name, Image *image, VkBuffer staging, - VkImageLayout final_layout) { - VkCommandBuffer cmd = BeginCommands(shader_name, "dispatch"); - AddImageBarrier(cmd, image->image, VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, 0, - VK_ACCESS_TRANSFER_WRITE_BIT, image->mip_levels); - std::vector copies; + void UploadImageMips(const char *shader_name, Image *image, + vk::Buffer staging, vk::ImageLayout final_layout) { + vk::CommandBuffer cmd = BeginCommands(shader_name, "dispatch"); + AddImageBarrier(cmd, image->image, vk::ImageLayout::eUndefined, + vk::ImageLayout::eTransferDstOptimal, + vk::PipelineStageFlagBits::eTopOfPipe, + vk::PipelineStageFlagBits::eTransfer, {}, + vk::AccessFlagBits::eTransferWrite, image->mip_levels); + std::vector copies; copies.reserve(image->mip_levels); - VkDeviceSize offset = 0; + vk::DeviceSize offset = 0; for (u32 level = 0; level < image->mip_levels; level++) { - VkBufferImageCopy copy{}; + vk::BufferImageCopy copy{}; copy.bufferOffset = offset; - copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + copy.imageSubresource.aspectMask = vk::ImageAspectFlagBits::eColor; copy.imageSubresource.mipLevel = level; copy.imageSubresource.baseArrayLayer = 0; copy.imageSubresource.layerCount = 1; @@ -2645,61 +2634,62 @@ private: copy.imageExtent.height = MipExtent(image->height, level); copy.imageExtent.depth = 1; copies.push_back(copy); - offset += static_cast( + offset += static_cast( ImageMipDwordCount(image->width, image->height, image->dwords_per_pixel, level) * sizeof(u32)); } - vkCmdCopyBufferToImage(cmd, staging, image->image, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - static_cast(copies.size()), copies.data()); - AddImageBarrier(cmd, image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - final_layout, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT, AccessForLayout(final_layout), - image->mip_levels); + cmd.copyBufferToImage(staging, image->image, + vk::ImageLayout::eTransferDstOptimal, + static_cast(copies.size()), copies.data()); + AddImageBarrier(cmd, image->image, vk::ImageLayout::eTransferDstOptimal, + final_layout, vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eComputeShader, + vk::AccessFlagBits::eTransferWrite, + AccessForLayout(final_layout), image->mip_levels); EndSubmitAndFree(shader_name, "dispatch", cmd); image->layout = final_layout; } - Buffer CreateHostBuffer(const char *shader_name, VkDeviceSize size, - VkBufferUsageFlags usage, + Buffer CreateHostBuffer(const char *shader_name, vk::DeviceSize size, + vk::BufferUsageFlags usage, const std::vector &contents) { Buffer ret; - ret.size = std::max(size, sizeof(u32)); + ret.size = std::max(size, sizeof(u32)); - VkBufferCreateInfo buffer_info{}; - buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + vk::BufferCreateInfo buffer_info{}; + buffer_info.sType = vk::StructureType::eBufferCreateInfo; buffer_info.size = ret.size; buffer_info.usage = usage; - buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + buffer_info.sharingMode = vk::SharingMode::eExclusive; RequireVk(shader_name, "dispatch", - vkCreateBuffer(m_device, &buffer_info, nullptr, &ret.buffer), + m_device.createBuffer(&buffer_info, nullptr, &ret.buffer), "vkCreateBuffer"); - VkMemoryRequirements req{}; - vkGetBufferMemoryRequirements(m_device, ret.buffer, &req); + vk::MemoryRequirements req{}; + m_device.getBufferMemoryRequirements(ret.buffer, &req); u32 memory_type = 0; ret.coherent = FindMemoryType(req.memoryTypeBits, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + vk::MemoryPropertyFlagBits::eHostVisible | + vk::MemoryPropertyFlagBits::eHostCoherent, &memory_type); if (!ret.coherent) { Require(shader_name, "dispatch", FindMemoryType(req.memoryTypeBits, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &memory_type), + vk::MemoryPropertyFlagBits::eHostVisible, + &memory_type), "no host-visible memory type for staging buffer"); } - VkMemoryAllocateInfo alloc{}; - alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + vk::MemoryAllocateInfo alloc{}; + alloc.sType = vk::StructureType::eMemoryAllocateInfo; alloc.allocationSize = req.size; alloc.memoryTypeIndex = memory_type; RequireVk(shader_name, "dispatch", - vkAllocateMemory(m_device, &alloc, nullptr, &ret.memory), + m_device.allocateMemory(&alloc, nullptr, &ret.memory), "vkAllocateMemory"); RequireVk(shader_name, "dispatch", - vkBindBufferMemory(m_device, ret.buffer, ret.memory, 0), + m_device.bindBufferMemory(ret.buffer, ret.memory, 0), "vkBindBufferMemory"); if (!contents.empty()) { WriteBuffer(shader_name, ret, contents); @@ -2711,29 +2701,29 @@ private: const std::vector &contents) { void *data = nullptr; RequireVk(shader_name, "dispatch", - vkMapMemory(m_device, buffer.memory, 0, buffer.size, 0, &data), + m_device.mapMemory(buffer.memory, 0, buffer.size, {}, &data), "vkMapMemory"); std::memcpy(data, contents.data(), contents.size() * sizeof(u32)); if (!buffer.coherent) { - VkMappedMemoryRange range{}; - range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; + vk::MappedMemoryRange range{}; + range.sType = vk::StructureType::eMappedMemoryRange; range.memory = buffer.memory; range.offset = 0; range.size = VK_WHOLE_SIZE; RequireVk(shader_name, "dispatch", - vkFlushMappedMemoryRanges(m_device, 1, &range), + m_device.flushMappedMemoryRanges(1, &range), "vkFlushMappedMemoryRanges"); } - vkUnmapMemory(m_device, buffer.memory); + m_device.unmapMemory(buffer.memory); } - VkInstance m_instance = VK_NULL_HANDLE; - VkPhysicalDevice m_physical_device = VK_NULL_HANDLE; - VkDevice m_device = VK_NULL_HANDLE; - VkQueue m_queue = VK_NULL_HANDLE; - VkCommandPool m_command_pool = VK_NULL_HANDLE; + vk::Instance m_instance = nullptr; + vk::PhysicalDevice m_physical_device = nullptr; + vk::Device m_device = nullptr; + vk::Queue m_queue = nullptr; + vk::CommandPool m_command_pool = nullptr; u32 m_queue_family = 0; - VkPhysicalDeviceMemoryProperties m_memory_properties{}; + vk::PhysicalDeviceMemoryProperties m_memory_properties{}; Common::Mutex m_runtime_queue_mutex; GraphicContext m_runtime_context{}; }; @@ -2782,7 +2772,8 @@ void RunCase(VulkanHarness *vulkan, const TestCase &test) { !compiled.program.info.images.empty() && compiled.program.info.images[0].storage_swizzle == test.image_descriptor_swizzle, - "storage image descriptor swizzle did not reach the specialized program"); + "storage image descriptor swizzle did not reach the specialized " + "program"); } if (test.compile_only) { std::printf("[compute] %-32s ok\n", test.name); @@ -2801,7 +2792,7 @@ void RunCase(VulkanHarness *vulkan, const TestCase &test) { VulkanHarness::Image storage_image; VulkanHarness::Image storage_image_uint; VulkanHarness::Buffer gds_buffer; - VkSampler sampler = VK_NULL_HANDLE; + vk::Sampler sampler = nullptr; const bool needs_sampled_image = Has(Kind::Sampled2D) || Has(Kind::Sampled2DArray) || Has(Kind::Sampled3D) || Has(Kind::SampledUint2D) || @@ -2822,27 +2813,27 @@ void RunCase(VulkanHarness *vulkan, const TestCase &test) { if (!test.sampled_image_rgba_mips.empty()) { sampled_image = vulkan->CreateImage2DMips( test.name, test.image_width, test.image_height, - VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_USAGE_SAMPLED_BIT, + vk::Format::eR32G32B32A32Sfloat, vk::ImageUsageFlagBits::eSampled, test.sampled_image_rgba_mips, 4, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + vk::ImageLayout::eShaderReadOnlyOptimal); } else { sampled_image = vulkan->CreateImage2D( test.name, test.image_width, test.image_height, - test.sampled_image_format, VK_IMAGE_USAGE_SAMPLED_BIT, + test.sampled_image_format, vk::ImageUsageFlagBits::eSampled, test.sampled_image_rgba, test.sampled_image_dwords_per_pixel, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + vk::ImageLayout::eShaderReadOnlyOptimal); } } if (needs_storage_image) { storage_image = vulkan->CreateImage2D( test.name, test.image_width, test.image_height, - test.storage_image_format, VK_IMAGE_USAGE_STORAGE_BIT, + test.storage_image_format, vk::ImageUsageFlagBits::eStorage, test.storage_image_rgba, test.storage_image_dwords_per_pixel, - VK_IMAGE_LAYOUT_GENERAL); + vk::ImageLayout::eGeneral); storage_image_uint = vulkan->CreateImage2D( - test.name, test.image_width, test.image_height, VK_FORMAT_R32_UINT, - VK_IMAGE_USAGE_STORAGE_BIT, test.storage_image_r32ui, 1, - VK_IMAGE_LAYOUT_GENERAL); + test.name, test.image_width, test.image_height, vk::Format::eR32Uint, + vk::ImageUsageFlagBits::eStorage, test.storage_image_r32ui, 1, + vk::ImageLayout::eGeneral); } if (needs_sampler) { sampler = vulkan->CreateNearestSampler(test.name); @@ -2871,8 +2862,8 @@ void RunCase(VulkanHarness *vulkan, const TestCase &test) { CompareWords(test, "uint storage image readback", test.expected_storage_image_r32ui, image_actual); } - if (sampler != VK_NULL_HANDLE) { - vkDestroySampler(vulkan->Device(), sampler, nullptr); + if (sampler != nullptr) { + vulkan->Device().destroySampler(sampler, nullptr); } vulkan->DestroyImage(&sampled_image); vulkan->DestroyImage(&storage_image); @@ -6695,7 +6686,8 @@ TestCase TBufferLoadFormatX16FloatConvertsToFloat() { std::vector code; AppendVMovU32(&code, 20, 0); - AppendTBufferLoadFormatOpcode(&code, 0x00, 0, 20, Prospero::BufferFormat::k16Float); + AppendTBufferLoadFormatOpcode(&code, 0x00, 0, 20, + Prospero::BufferFormat::k16Float); AppendStoreVgpr(&code, 0, 0); AppendEnd(&code); @@ -6884,7 +6876,8 @@ TestCase TBufferLoadFormatXy88SnormConvertsToFloat() { std::vector code; AppendVMovU32(&code, 20, 0); - AppendTBufferLoadFormatOpcode(&code, 0x01, 0, 20, Prospero::BufferFormat::k8_8SNorm); + AppendTBufferLoadFormatOpcode(&code, 0x01, 0, 20, + Prospero::BufferFormat::k8_8SNorm); AppendStoreVgpr(&code, 0, 0); AppendStoreVgpr(&code, 1, 1); AppendEnd(&code); @@ -7115,10 +7108,8 @@ TestCase BranchVccnzUsesCarryProducedWholeMask() { using O = ShaderOpcode; std::vector code = { - EncodeVop1(0x01, 1, 0), - EncodeVop2(0x1a, 1, InlineU32(2), 1), - EncodeVop2(0x25, 1, Vgpr(0), 1), - EncodeVop2(0x1a, 3, InlineU32(2), 1), + EncodeVop1(0x01, 1, 0), EncodeVop2(0x1a, 1, InlineU32(2), 1), + EncodeVop2(0x25, 1, Vgpr(0), 1), EncodeVop2(0x1a, 3, InlineU32(2), 1), EncodeVopc(0xc0, Vgpr(0), 0), }; AppendVMovLiteral(&code, 2, 0xffffffffu); @@ -7827,7 +7818,7 @@ TestCase ImageLoadR32UintUsesIntegerSampledImage() { test.opcodes = {O::VMovB32, O::ImageLoad, O::BufferStoreDword, O::SEndpgm}; test.sampled_image_rgba.resize(16); test.sampled_image_rgba[6] = 0xdeadbeefu; - test.sampled_image_format = VK_FORMAT_R32_UINT; + test.sampled_image_format = vk::Format::eR32Uint; test.sampled_image_dwords_per_pixel = 1; test.user_data = MakeSampledTextureData(Prospero::BufferFormat::k32UInt); test.has_user_data = true; @@ -8228,7 +8219,7 @@ TestCase ImageStoreRgbOneUsesInverseSwizzle() { test.user_data[1] = Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm) << 20u; test.image_descriptor_swizzle = DstSel(4, 5, 6, 1); - test.storage_image_format = VK_FORMAT_R8G8B8A8_UNORM; + test.storage_image_format = vk::Format::eR8G8B8A8Unorm; test.storage_image_dwords_per_pixel = 1; test.storage_image_rgba = std::vector(16, 0); test.expected_storage_image_rgba = std::vector(16, 0); @@ -8260,7 +8251,7 @@ TestCase ImageStoreBgraUsesInverseSwizzle() { test.user_data[1] = Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm) << 20u; test.image_descriptor_swizzle = DstSel(6, 5, 4, 7); - test.storage_image_format = VK_FORMAT_R8G8B8A8_UNORM; + test.storage_image_format = vk::Format::eR8G8B8A8Unorm; test.storage_image_dwords_per_pixel = 1; test.storage_image_rgba = std::vector(16, 0); test.expected_storage_image_rgba = std::vector(16, 0); @@ -8287,7 +8278,8 @@ TestCase ImageStoreYzwxUsesInverseSwizzle() { test.name = "ImageStoreYzwxUsesInverseSwizzle"; test.code = code; test.opcodes = {O::VMovB32, O::ImageStore, O::SEndpgm}; - test.user_data = MakeStorageTextureData(Prospero::BufferFormat::k32_32_32_32Float); + test.user_data = + MakeStorageTextureData(Prospero::BufferFormat::k32_32_32_32Float); test.has_user_data = true; test.image_descriptor_swizzle = DstSel(5, 6, 7, 4); test.storage_image_rgba = MakeRgbaImage(4, 4); @@ -8316,7 +8308,7 @@ TestCase ImageStoreR32FloatUsesFormatlessStorageImage() { test.name = "ImageStoreR32FloatUsesFormatlessStorageImage"; test.code = code; test.opcodes = {O::VMovB32, O::ImageStore, O::SEndpgm}; - test.storage_image_format = VK_FORMAT_R32_SFLOAT; + test.storage_image_format = vk::Format::eR32Sfloat; test.storage_image_dwords_per_pixel = 1; test.storage_image_rgba = std::vector(16, 0); test.expected_storage_image_rgba = expected_image; @@ -8942,8 +8934,10 @@ void CheckPs5GameExampleImageClearRuntimeShape() { user_data[0] = 0x00010000u; user_data[1] = 16u << 16u; user_data[2] = 64; - user_data[3] = (Prospero::GpuEnumValue(Prospero::BufferFormat::k32_32_32_32UInt) << 12u) | - 4u | (5u << 3u) | (6u << 6u) | (7u << 9u); + user_data[3] = + (Prospero::GpuEnumValue(Prospero::BufferFormat::k32_32_32_32UInt) + << 12u) | + 4u | (5u << 3u) | (6u << 6u) | (7u << 9u); std::fill(user_data.begin() + 4, user_data.end(), 0xff000000u); ShaderComputeInputInfo compute{}; compute.threads_num[0] = 64; @@ -8982,7 +8976,8 @@ void CheckPs5GameExampleImageClearRuntimeShape() { compute.stage.program = std::make_shared(positive.program); compute.stage.resources = - std::make_shared(positive.resources); + std::make_shared( + positive.resources); ShaderBufferResource descriptor{}; u32 packed_clear = 0; uint64_t size = 0; @@ -8996,13 +8991,15 @@ void CheckPs5GameExampleImageClearRuntimeShape() { auto non_repeated = positive.resources; non_repeated.user_data[7] ^= 1u; compute.stage.resources = - std::make_shared(non_repeated); + std::make_shared( + non_repeated); Require("Ps5GameExampleImageClear", "non-repeated clear", !ResolveComputeImageClear(compute, 64, 1, 1, 0x61u, &descriptor, &packed_clear, &size), "non-uniform uint4 data was replaced with a color clear"); compute.stage.resources = - std::make_shared(positive.resources); + std::make_shared( + positive.resources); compute.dispatch_threads_num[0] = 32; Require("Ps5GameExampleImageClear", "partial dispatch", !ResolveComputeImageClear(compute, 32, 1, 1, 0x61u, &descriptor, @@ -9025,8 +9022,7 @@ void CheckEmbeddedFetchVertexOffset() { code.push_back(EncodeMubuf0(0x03u, 0, true)); code.push_back(EncodeMubuf1(9, 5, 0)); if (late_add.has_value()) { - AppendVop3B(&code, 0x30fu, 0, 0, late_add->first, - Vgpr(late_add->second)); + AppendVop3B(&code, 0x30fu, 0, 0, late_add->first, Vgpr(late_add->second)); } AppendEnd(&code); return code; @@ -9068,31 +9064,34 @@ void CheckEmbeddedFetchVertexOffset() { vertex.stage.program = std::make_shared(result.program); vertex.stage.resources = - std::make_shared(result.resources); + std::make_shared( + result.resources); return ResolveVertexOffset(index_offset, vertex); }; - const auto valid = Compile("EmbeddedFetchVertexOffset", - MakeFetch({{18, 0}}), 7); - Require("EmbeddedFetchVertexOffset", "parse", - valid.program.info.vertex_offset_sgpr == 18 && - Resolve(valid, 0) == 7 && Resolve(valid, 5) == 5, - "canonical fetch offset or register index-offset precedence is wrong"); + const auto valid = + Compile("EmbeddedFetchVertexOffset", MakeFetch({{18, 0}}), 7); + Require( + "EmbeddedFetchVertexOffset", "parse", + valid.program.info.vertex_offset_sgpr == 18 && Resolve(valid, 0) == 7 && + Resolve(valid, 5) == 5, + "canonical fetch offset or register index-offset precedence is wrong"); const auto pointer = 0x5b7c5100u; const auto late = Compile("EmbeddedFetchLateOffset", MakeFetch({}, std::pair{18, 0}), pointer); const auto conflict = Compile("EmbeddedFetchConflictingOffset", MakeFetch({{17, 0}, {18, 0}}), pointer); - const auto malformed = Compile("EmbeddedFetchMalformedOffset", - MakeFetch({{18, 1}}), pointer); - const auto outside = Compile("EmbeddedFetchOutsideOffset", - MakeFetch({{19, 0}}), pointer); + const auto malformed = + Compile("EmbeddedFetchMalformedOffset", MakeFetch({{18, 1}}), pointer); + const auto outside = + Compile("EmbeddedFetchOutsideOffset", MakeFetch({{19, 0}}), pointer); for (const auto *result : {&late, &conflict, &malformed, &outside}) { Require("EmbeddedFetchVertexOffset", "fail closed", result->program.info.vertex_offset_sgpr == -1 && Resolve(*result, 0) == 0, - "non-prolog, conflicting, malformed, or out-of-window add was classified"); + "non-prolog, conflicting, malformed, or out-of-window add was " + "classified"); } std::printf("[host] %-32s ok\n", "EmbeddedFetchVertexOffset"); } @@ -9117,7 +9116,7 @@ bool CacheFault(void *opaque, PageFaultAccess access, uint64_t vaddr, void CheckReverseRenderTargetFormatContract() { const auto format = TextureGetRenderTargetFormat(12u, 7u, 2u); Require("ReverseRenderTarget", "exact format", - format.format == VK_FORMAT_R16G16B16A16_SFLOAT && + format.format == vk::Format::eR16G16B16A16Sfloat && format.bytes_per_element == 8u && format.export_mapping == Prospero::ColorMappingAbgr, "exact reverse RGBA16F render-target tuple was rejected"); @@ -9139,8 +9138,9 @@ void CheckReverseRenderTargetFormatContract() { STARTUPINFOA startup{sizeof(startup)}; PROCESS_INFORMATION process{}; Require("ReverseRenderTarget", "host", - CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, FALSE, - CREATE_NO_WINDOW, nullptr, nullptr, &startup, &process) != 0, + CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, + FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &startup, + &process) != 0, "CreateProcess failed"); Require("ReverseRenderTarget", "host", WaitForSingleObject(process.hProcess, 10000) == WAIT_OBJECT_0, @@ -9149,66 +9149,70 @@ void CheckReverseRenderTargetFormatContract() { const bool exited = GetExitCodeProcess(process.hProcess, &exit_code) != 0; CloseHandle(process.hThread); CloseHandle(process.hProcess); - Require("ReverseRenderTarget", "hard failure", exited && exit_code == 321, - "adjacent unproven render-target tuple did not retain the fatal guard"); + Require( + "ReverseRenderTarget", "hard failure", exited && exit_code == 321, + "adjacent unproven render-target tuple did not retain the fatal guard"); std::printf("[host] %-32s ok\n", "ReverseRenderTargetFormat"); } [[noreturn]] void RunImageViewDeathCase(const char *kind) { if (std::strcmp(kind, "sampled") == 0) { - (void)SelectSampledColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, + (void)SelectSampledColorView(vk::Format::eR8G8B8A8Unorm, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 2)); } else if (std::strcmp(kind, "sampled-compatible-swizzle") == 0) { - (void)SelectSampledColorView(VK_FORMAT_B8G8R8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, + (void)SelectSampledColorView(vk::Format::eB8G8R8A8Unorm, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "sampled-compatible-reverse") == 0) { - (void)SelectSampledColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_B8G8R8A8_UNORM, + (void)SelectSampledColorView(vk::Format::eR8G8B8A8Unorm, + vk::Format::eB8G8R8A8Unorm, DstSel(6, 5, 4, 7)); } else if (std::strcmp(kind, "sampled-compatible-class") == 0) { - (void)SelectSampledColorView(VK_FORMAT_R8G8B8A8_UINT, - VK_FORMAT_R8G8B8A8_UNORM, + (void)SelectSampledColorView(vk::Format::eR8G8B8A8Uint, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "sampled-compatible-colorspace") == 0) { - (void)SelectSampledColorView(VK_FORMAT_B8G8R8A8_SRGB, - VK_FORMAT_R8G8B8A8_UNORM, + (void)SelectSampledColorView(vk::Format::eB8G8R8A8Srgb, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "sampled-compatible-snorm") == 0) { - (void)SelectSampledColorView(VK_FORMAT_R8G8B8A8_SNORM, - VK_FORMAT_R8G8B8A8_UNORM, + (void)SelectSampledColorView(vk::Format::eR8G8B8A8Snorm, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "sampled-rgb10-swizzle") == 0) { - (void)SelectSampledColorView(VK_FORMAT_A2R10G10B10_UNORM_PACK32, - VK_FORMAT_A2B10G10R10_UNORM_PACK32, + (void)SelectSampledColorView(vk::Format::eA2R10G10B10UnormPack32, + vk::Format::eA2B10G10R10UnormPack32, DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "sampled-rgb10-reverse") == 0) { - (void)SelectSampledColorView(VK_FORMAT_A2B10G10R10_UNORM_PACK32, - VK_FORMAT_A2R10G10B10_UNORM_PACK32, + (void)SelectSampledColorView(vk::Format::eA2B10G10R10UnormPack32, + vk::Format::eA2R10G10B10UnormPack32, DstSel(6, 5, 4, 7)); } else if (std::strcmp(kind, "sampled-invalid-high") == 0) { - (void)SelectSampledColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, + (void)SelectSampledColorView(vk::Format::eR8G8B8A8Unorm, + vk::Format::eR8G8B8A8Unorm, DstSel(7, 6, 5, 3)); } else if (std::strcmp(kind, "sampled-depth-format") == 0) { - (void)SelectSampledDepthView(VK_FORMAT_D24_UNORM_S8_UINT, - VK_FORMAT_R32_SFLOAT, DstSel(4, 4, 4, 4)); + (void)SelectSampledDepthView(vk::Format::eD24UnormS8Uint, + vk::Format::eR32Sfloat, DstSel(4, 4, 4, 4)); } else if (std::strcmp(kind, "sampled-depth-swizzle") == 0) { - (void)SelectSampledDepthView(VK_FORMAT_D32_SFLOAT_S8_UINT, - VK_FORMAT_R32_SFLOAT, DstSel(4, 5, 6, 7)); + (void)SelectSampledDepthView(vk::Format::eD32SfloatS8Uint, + vk::Format::eR32Sfloat, DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "storage") == 0) { - (void)SelectStorageColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, DstSel(4, 5, 6, 0)); + (void)SelectStorageColorView(vk::Format::eR8G8B8A8Unorm, + vk::Format::eR8G8B8A8Unorm, + DstSel(4, 5, 6, 0)); } else if (std::strcmp(kind, "storage-format") == 0) { - (void)SelectStorageColorView(VK_FORMAT_B8G8R8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, DstSel(4, 5, 6, 7)); + (void)SelectStorageColorView(vk::Format::eB8G8R8A8Unorm, + vk::Format::eR8G8B8A8Unorm, + DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "storage-compatible-swizzle") == 0) { - (void)SelectStorageColorView(VK_FORMAT_B8G8R8A8_SRGB, - VK_FORMAT_R8G8B8A8_UNORM, DstSel(4, 5, 6, 7)); + (void)SelectStorageColorView(vk::Format::eB8G8R8A8Srgb, + vk::Format::eR8G8B8A8Unorm, + DstSel(4, 5, 6, 7)); } else if (std::strcmp(kind, "storage-abgr") == 0) { - (void)SelectStorageColorView(VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_SFLOAT, + (void)SelectStorageColorView(vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Sfloat, DstSel(7, 6, 5, 4)); } else { ShaderRecompiler::IR::ImageResource resource{}; @@ -9237,8 +9241,8 @@ void CheckReverseRenderTargetFormatContract() { void CheckSampledColorViews() { Require("SampledColorViews", "identity", - SelectSampledColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, + SelectSampledColorView(vk::Format::eR8G8B8A8Unorm, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 7)) == DstSel(4, 5, 6, 7), "RGBA did not select the identity view"); uint32_t valid_swizzles = 0; @@ -9252,7 +9256,7 @@ void CheckSampledColorViews() { } const bool valid = IsValidSampledColorSwizzle(swizzle); const bool supported = IsSupportedSampledColorView( - VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, swizzle); + vk::Format::eR8G8B8A8Unorm, vk::Format::eR8G8B8A8Unorm, swizzle); Require("SampledColorViews", "exhaustive read swizzle domain", valid == expected && supported == expected, "sampled swizzle validator disagreed with the PS5 selector domain"); @@ -9268,156 +9272,168 @@ void CheckSampledColorViews() { const auto arbitrary = DstSel(5, 1, 7, 0); const auto components = TextureGetComponentMapping(arbitrary); Require("SampledColorViews", "generic Vulkan component mapping", - SelectSampledColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, + SelectSampledColorView(vk::Format::eR8G8B8A8Unorm, + vk::Format::eR8G8B8A8Unorm, arbitrary) == arbitrary && - components.r == VK_COMPONENT_SWIZZLE_G && - components.g == VK_COMPONENT_SWIZZLE_ONE && - components.b == VK_COMPONENT_SWIZZLE_A && - components.a == VK_COMPONENT_SWIZZLE_ZERO, + components.r == vk::ComponentSwizzle::eG && + components.g == vk::ComponentSwizzle::eOne && + components.b == vk::ComponentSwizzle::eA && + components.a == vk::ComponentSwizzle::eZero, "arbitrary valid sampled mapping did not use the generic view path"); Require("SampledColorViews", "R8 R001", - SelectSampledColorView(VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, + SelectSampledColorView(vk::Format::eR8Unorm, vk::Format::eR8Unorm, DstSel(4, 0, 0, 1)) == DstSel(4, 0, 0, 1), "R8 did not select its R001 view"); Require("SampledColorViews", "R8 000R", - SelectSampledColorView(VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, + SelectSampledColorView(vk::Format::eR8Unorm, vk::Format::eR8Unorm, DstSel(0, 0, 0, 4)) == DstSel(0, 0, 0, 4), "R8 did not select its 000R component-mapped view"); Require("SampledColorViews", "R16G16 RG01", - SelectSampledColorView(VK_FORMAT_R16G16_SFLOAT, - VK_FORMAT_R16G16_SFLOAT, + SelectSampledColorView(vk::Format::eR16G16Sfloat, + vk::Format::eR16G16Sfloat, DstSel(4, 5, 0, 1)) == DstSel(4, 5, 0, 1), "R16G16 did not select its RG01 view"); Require("SampledColorViews", "alpha one", - SelectSampledColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, + SelectSampledColorView(vk::Format::eR8G8B8A8Unorm, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 1)) == DstSel(4, 5, 6, 1), "RGB1 did not select the alpha-one view"); Require("SampledColorViews", "mutable BGRA target", - SelectSampledColorView(VK_FORMAT_B8G8R8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, + SelectSampledColorView(vk::Format::eB8G8R8A8Unorm, + vk::Format::eR8G8B8A8Unorm, DstSel(6, 5, 4, 7)) == DstSel(6, 5, 4, 7), "BGRA target did not select the exact RGBA/BGRA mutable view"); Require( "SampledColorViews", "mutable sRGB view of UNORM BGRA target", - SelectSampledColorView(VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_SRGB, + SelectSampledColorView(vk::Format::eB8G8R8A8Unorm, + vk::Format::eR8G8B8A8Srgb, DstSel(6, 5, 4, 7)) == DstSel(6, 5, 4, 7), "UNORM BGRA target did not select its compatible sRGB RGBA sampled view"); Require("SampledColorViews", "mutable sRGB BGRA target", - BgraToRgbaSampledViewFormat(VK_FORMAT_B8G8R8A8_SRGB) == - VK_FORMAT_R8G8B8A8_SRGB && - SelectSampledColorView(VK_FORMAT_B8G8R8A8_SRGB, - VK_FORMAT_R8G8B8A8_SRGB, + BgraToRgbaSampledViewFormat(vk::Format::eB8G8R8A8Srgb) == + vk::Format::eR8G8B8A8Srgb && + SelectSampledColorView(vk::Format::eB8G8R8A8Srgb, + vk::Format::eR8G8B8A8Srgb, DstSel(6, 5, 4, 7)) == DstSel(6, 5, 4, 7), "sRGB BGRA target did not select its matching mutable RGBA view"); constexpr auto colorspace_swizzle = DstSel(5, 1, 7, 0); Require("SampledColorViews", "mutable sRGB/UNORM views", - SelectSampledColorView(VK_FORMAT_R8G8B8A8_SRGB, - VK_FORMAT_R8G8B8A8_UNORM, + SelectSampledColorView(vk::Format::eR8G8B8A8Srgb, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 7)) == DstSel(4, 5, 6, 7) && - SelectSampledColorView(VK_FORMAT_B8G8R8A8_UNORM, - VK_FORMAT_B8G8R8A8_SRGB, + SelectSampledColorView(vk::Format::eB8G8R8A8Unorm, + vk::Format::eB8G8R8A8Srgb, colorspace_swizzle) == colorspace_swizzle, "same-order mutable sRGB/UNORM sampled views were rejected"); Require("SampledColorViews", "mutable packed RGB10 view", - BgraToRgbaSampledViewFormat(VK_FORMAT_A2R10G10B10_UNORM_PACK32) == - VK_FORMAT_A2B10G10R10_UNORM_PACK32 && - SelectSampledColorView(VK_FORMAT_A2R10G10B10_UNORM_PACK32, - VK_FORMAT_A2B10G10R10_UNORM_PACK32, + BgraToRgbaSampledViewFormat(vk::Format::eA2R10G10B10UnormPack32) == + vk::Format::eA2B10G10R10UnormPack32 && + SelectSampledColorView(vk::Format::eA2R10G10B10UnormPack32, + vk::Format::eA2B10G10R10UnormPack32, DstSel(6, 5, 4, 7)) == DstSel(6, 5, 4, 7), - "packed RGB10 target did not select its matching mutable channel-order view"); - Require("SampledColorViews", "reverse RGBA16F sampled view", - SelectSampledColorView(VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_SFLOAT, - DstSel(7, 6, 5, 4)) == DstSel(7, 6, 5, 4), - "reverse RGBA16F target did not select its reciprocal ABGR sampled view"); + "packed RGB10 target did not select its matching mutable " + "channel-order view"); + Require( + "SampledColorViews", "reverse RGBA16F sampled view", + SelectSampledColorView(vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Sfloat, + DstSel(7, 6, 5, 4)) == DstSel(7, 6, 5, 4), + "reverse RGBA16F target did not select its reciprocal ABGR sampled view"); Require("SampledColorViews", "mutable integer-class views", - SelectSampledColorView(VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_UINT, + SelectSampledColorView(vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Uint, DstSel(4, 5, 6, 7)) == DstSel(4, 5, 6, 7) && - SelectSampledColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UINT, - DstSel(4, 5, 6, 7)) == DstSel(4, 5, 6, 7) && - SelectSampledColorView(VK_FORMAT_R8G8B8A8_UINT, - VK_FORMAT_R8G8B8A8_UNORM, + SelectSampledColorView( + vk::Format::eR8G8B8A8Unorm, vk::Format::eR8G8B8A8Uint, + DstSel(4, 5, 6, 7)) == DstSel(4, 5, 6, 7) && + SelectSampledColorView(vk::Format::eR8G8B8A8Uint, + vk::Format::eR8G8B8A8Unorm, DstSel(4, 5, 6, 7)) == DstSel(4, 5, 6, 7), "compatible integer render-target sampled view was rejected"); Require("SampledColorViews", "D32 depth target", - SelectSampledDepthView(VK_FORMAT_D32_SFLOAT_S8_UINT, - VK_FORMAT_R32_SFLOAT, + SelectSampledDepthView(vk::Format::eD32SfloatS8Uint, + vk::Format::eR32Sfloat, DstSel(4, 4, 4, 4)) == DstSel(4, 4, 4, 4), "D32 depth target did not select its depth-aspect view"); Require("SampledColorViews", "D16 R000 depth target", - SelectSampledDepthView(VK_FORMAT_D16_UNORM, VK_FORMAT_R16_UNORM, + SelectSampledDepthView(vk::Format::eD16Unorm, vk::Format::eR16Unorm, DstSel(4, 0, 0, 0)) == DstSel(4, 0, 0, 0), "D16 depth target did not select its R000 depth-aspect view"); Require("SampledColorViews", "D16S8 R001 depth target", - SelectSampledDepthView(VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_R16_UNORM, + SelectSampledDepthView(vk::Format::eD16UnormS8Uint, + vk::Format::eR16Unorm, DstSel(4, 0, 0, 1)) == DstSel(4, 0, 0, 1), "D16S8 depth target did not select its R001 depth-aspect view"); Require("SampledColorViews", "promoted D24S8 R001 depth target", - SelectSampledDepthView(VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_R16_UNORM, + SelectSampledDepthView(vk::Format::eD24UnormS8Uint, + vk::Format::eR16Unorm, DstSel(4, 0, 0, 1)) == DstSel(4, 0, 0, 1), "D24S8 host fallback did not preserve the guest R16 depth view"); Require("SampledColorViews", "promoted D32S8 R001 depth target", - SelectSampledDepthView(VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_R16_UNORM, + SelectSampledDepthView(vk::Format::eD32SfloatS8Uint, + vk::Format::eR16Unorm, DstSel(4, 0, 0, 1)) == DstSel(4, 0, 0, 1), "D32S8 host fallback did not preserve the guest R16 depth view"); Require("SampledColorViews", "D32S8 R001 depth target", - SelectSampledDepthView(VK_FORMAT_D32_SFLOAT_S8_UINT, - VK_FORMAT_R32_SFLOAT, + SelectSampledDepthView(vk::Format::eD32SfloatS8Uint, + vk::Format::eR32Sfloat, DstSel(4, 0, 0, 1)) == DstSel(4, 0, 0, 1), "D32S8 depth target did not select its R001 depth-aspect view"); Require("SampledColorViews", "storage identity", - SelectStorageColorView(VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, - DstSel(4, 5, 6, 7)) == VulkanImage::VIEW_STORAGE, + SelectStorageColorView( + vk::Format::eR8G8B8A8Unorm, vk::Format::eR8G8B8A8Unorm, + DstSel(4, 5, 6, 7)) == VulkanImage::VIEW_STORAGE, "RGBA storage did not select the identity storage view"); - Require( - "SampledColorViews", "storage RGB1 write mapping", - SelectStorageColorView(VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, - DstSel(4, 5, 6, 1)) == VulkanImage::VIEW_STORAGE, - "RGBA8 RGB1 storage did not select the identity storage view"); - Require( - "SampledColorViews", "storage BGRA write mapping", - SelectStorageColorView(VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, - DstSel(6, 5, 4, 7)) == VulkanImage::VIEW_STORAGE, - "RGBA8 BGRA storage did not select the identity storage view"); + Require("SampledColorViews", "storage RGB1 write mapping", + SelectStorageColorView( + vk::Format::eR8G8B8A8Unorm, vk::Format::eR8G8B8A8Unorm, + DstSel(4, 5, 6, 1)) == VulkanImage::VIEW_STORAGE, + "RGBA8 RGB1 storage did not select the identity storage view"); + Require("SampledColorViews", "storage BGRA write mapping", + SelectStorageColorView( + vk::Format::eR8G8B8A8Unorm, vk::Format::eR8G8B8A8Unorm, + DstSel(6, 5, 4, 7)) == VulkanImage::VIEW_STORAGE, + "RGBA8 BGRA storage did not select the identity storage view"); Require("SampledColorViews", "storage uint BGRA write mapping", - SelectStorageColorView(VK_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_UINT, - DstSel(6, 5, 4, 7)) == VulkanImage::VIEW_STORAGE, + SelectStorageColorView( + vk::Format::eR8G8B8A8Uint, vk::Format::eR8G8B8A8Uint, + DstSel(6, 5, 4, 7)) == VulkanImage::VIEW_STORAGE, "RGBA8_UINT BGRA storage did not select the identity storage view"); Require( "SampledColorViews", "mutable BGRA sRGB storage view", - SelectStorageColorView(VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_R8G8B8A8_UNORM, + SelectStorageColorView(vk::Format::eB8G8R8A8Srgb, + vk::Format::eR8G8B8A8Unorm, DstSel(6, 5, 4, 7)) == VulkanImage::VIEW_STORAGE, "BGRA sRGB target did not select its RGBA UNORM identity storage view"); Require("SampledColorViews", "storage YZWX write mapping", SelectStorageColorView( - VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, + vk::Format::eR32G32B32A32Sfloat, vk::Format::eR32G32B32A32Sfloat, DstSel(5, 6, 7, 4)) == VulkanImage::VIEW_STORAGE, "RGBA32F YZWX storage did not select the identity storage view"); Require("SampledColorViews", "storage R32 uint R001 write mapping", - SelectStorageColorView(VK_FORMAT_R32_UINT, VK_FORMAT_R32_UINT, + SelectStorageColorView(vk::Format::eR32Uint, vk::Format::eR32Uint, DstSel(4, 0, 0, 1)) == VulkanImage::VIEW_STORAGE, "R32_UINT R001 storage did not select the identity storage view"); Require("SampledColorViews", "storage R16 uint R000 write mapping", - SelectStorageColorView(VK_FORMAT_R16_UINT, VK_FORMAT_R16_UINT, - DstSel(4, 0, 0, 0)) == VulkanImage::VIEW_STORAGE, + SelectStorageColorView(vk::Format::eR16Uint, vk::Format::eR16Uint, + DstSel(4, 0, 0, 0)) == + VulkanImage::VIEW_STORAGE, "R16_UINT R000 storage did not select the identity storage view"); Require("SampledColorViews", "storage R16 float R001 write mapping", - SelectStorageColorView(VK_FORMAT_R16_SFLOAT, VK_FORMAT_R16_SFLOAT, - DstSel(4, 0, 0, 1)) == VulkanImage::VIEW_STORAGE, + SelectStorageColorView(vk::Format::eR16Sfloat, vk::Format::eR16Sfloat, + DstSel(4, 0, 0, 1)) == + VulkanImage::VIEW_STORAGE, "R16_SFLOAT R001 storage did not select the identity storage view"); Require("SampledColorViews", "storage R32 float R001 write mapping", - SelectStorageColorView(VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, - DstSel(4, 0, 0, 1)) == VulkanImage::VIEW_STORAGE, + SelectStorageColorView(vk::Format::eR32Sfloat, vk::Format::eR32Sfloat, + DstSel(4, 0, 0, 1)) == + VulkanImage::VIEW_STORAGE, "R32_SFLOAT R001 storage did not select the identity storage view"); Require("SampledColorViews", "storage R8 unorm R001 write mapping", - SelectStorageColorView(VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, - DstSel(4, 0, 0, 1)) == VulkanImage::VIEW_STORAGE, + SelectStorageColorView(vk::Format::eR8Unorm, vk::Format::eR8Unorm, + DstSel(4, 0, 0, 1)) == + VulkanImage::VIEW_STORAGE, "R8_UNORM R001 storage did not select the identity storage view"); ShaderRecompiler::IR::ImageResource storage_resource{}; storage_resource.kind = ShaderRecompiler::IR::ResourceKind::StorageImage; @@ -9431,7 +9447,8 @@ void CheckSampledColorViews() { Require("SampledColorViews", "read-write 3D storage resource", IsSupportedStorageImageResource(storage_resource), "basic read-write 3D storage resource was rejected"); - storage_resource.dimension = ShaderRecompiler::Decoder::ImageDimension::Dim2DArray; + storage_resource.dimension = + ShaderRecompiler::Decoder::ImageDimension::Dim2DArray; storage_resource.read = false; Require("SampledColorViews", "write-only 2D-array storage resource", IsSupportedStorageImageResource(storage_resource), @@ -9445,15 +9462,26 @@ void CheckSampledColorViews() { Require("SampledColorViews", "host", GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, "GetModuleFileName failed"); - for (const char *kind : - {"sampled", "sampled-compatible-swizzle", "sampled-compatible-reverse", - "sampled-compatible-colorspace", - "sampled-compatible-snorm", "sampled-rgb10-swizzle", - "sampled-rgb10-reverse", "sampled-invalid-high", "sampled-depth-format", - "sampled-depth-swizzle", "storage", "storage-format", - "storage-compatible-swizzle", "storage-abgr", "storage-kind", "storage-no-write", - "storage-atomic", "storage-compare", "storage-mip", - "storage-dimension"}) { + for (const char *kind : {"sampled", + "sampled-compatible-swizzle", + "sampled-compatible-reverse", + "sampled-compatible-colorspace", + "sampled-compatible-snorm", + "sampled-rgb10-swizzle", + "sampled-rgb10-reverse", + "sampled-invalid-high", + "sampled-depth-format", + "sampled-depth-swizzle", + "storage", + "storage-format", + "storage-compatible-swizzle", + "storage-abgr", + "storage-kind", + "storage-no-write", + "storage-atomic", + "storage-compare", + "storage-mip", + "storage-dimension"}) { std::string command = std::string("\"") + path + "\" --image-view-death " + kind; std::vector mutable_command(command.begin(), command.end()); @@ -9473,7 +9501,8 @@ void CheckSampledColorViews() { CloseHandle(process.hThread); CloseHandle(process.hProcess); Require("SampledColorViews", "host", exited && exit_code == 321, - std::string(kind) + " component mapping did not report a fatal error"); + std::string(kind) + + " component mapping did not report a fatal error"); } std::printf("[host] %-32s ok\n", "SampledColorRenderTargetViews"); } @@ -9521,14 +9550,16 @@ void CheckSampledDepthResource() { const auto singleton_array_view = ResolveTargetTextureView( resource, Prospero::ImageType::kColor2DArray, 0, 1); Require("SampledDepthResource", "singleton array view", - singleton_array_view.type == VK_IMAGE_VIEW_TYPE_2D_ARRAY && + singleton_array_view.type == vk::ImageViewType::e2DArray && singleton_array_view.base_layer == 0 && singleton_array_view.layer_count == 1, "singleton depth array did not preserve the shader array view type"); - Require("SampledDepthResource", "array type mismatch rejected", - ResolveTargetTextureView(resource, Prospero::ImageType::kColor2D, 0, 1) - .type == VK_IMAGE_VIEW_TYPE_MAX_ENUM, - "array shader resource accepted a non-array descriptor view"); + Require( + "SampledDepthResource", "array type mismatch rejected", + ResolveTargetTextureView(resource, Prospero::ImageType::kColor2D, 0, 1) + .type == + static_cast(VK_IMAGE_VIEW_TYPE_MAX_ENUM), + "array shader resource accepted a non-array descriptor view"); resource = basic; resource.kind = ShaderRecompiler::IR::ResourceKind::ImageUint; Require("SampledDepthResource", "integer rejected", @@ -9539,11 +9570,13 @@ void CheckSampledDepthResource() { "read-only uint depth reinterpretation resource was rejected"); Require("SampledDepthResource", "D32 to R32_UINT", IsDepthUintTextureReinterpretation( - VK_FORMAT_D32_SFLOAT, - Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt), VK_FORMAT_R32_UINT) && + vk::Format::eD32Sfloat, + Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt), + vk::Format::eR32Uint) && !IsDepthUintTextureReinterpretation( - VK_FORMAT_D16_UNORM, - Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt), VK_FORMAT_R32_UINT), + vk::Format::eD16Unorm, + Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt), + vk::Format::eR32Uint), "depth uint reinterpretation format boundary changed"); std::printf("[host] %-32s ok\n", "SampledDepthResource"); } @@ -9600,9 +9633,10 @@ void CheckSampledDepthDescriptor() { image.extent = {1344, 756}; image.guest_pitch = 1408; image.layers = 1; - image.format = VK_FORMAT_D32_SFLOAT_S8_UINT; + image.format = vk::Format::eD32SfloatS8Uint; Require("SampledDepthDescriptor", "PPSA04319 padded pitch", - descriptor.Width5() + 1u == 1344 && descriptor.Height5() + 1u == 756 && + descriptor.Width5() + 1u == 1344 && + descriptor.Height5() + 1u == 756 && TileGetTexturePitch(descriptor.Format(), 1344, 1, descriptor.TileMode()) == 1408 && IsSupportedDepthTargetDescriptor(descriptor, image), @@ -9642,8 +9676,9 @@ void CheckSampledDepthDescriptor() { target.pitch = 512; target.layers = 1; target.bytes_per_element = 4; - target.guest_format = Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float); - target.format = VK_FORMAT_D32_SFLOAT; + target.guest_format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float); + target.format = vk::Format::eD32Sfloat; target.tile_mode = Prospero::GpuEnumValue(Prospero::TileMode::kDepth); ImageInfo expanded{}; expanded.address = target.address; @@ -9662,23 +9697,28 @@ void CheckSampledDepthDescriptor() { "exact D32 per-layer expansion was rejected"); auto invalid_expansion = expanded; invalid_expansion.pitch *= 2; - const bool rejects_pitch = !IsSampledDepthExpansion(invalid_expansion, target); + const bool rejects_pitch = + !IsSampledDepthExpansion(invalid_expansion, target); invalid_expansion = expanded; invalid_expansion.address++; - const bool rejects_address = !IsSampledDepthExpansion(invalid_expansion, target); + const bool rejects_address = + !IsSampledDepthExpansion(invalid_expansion, target); invalid_expansion = expanded; invalid_expansion.levels = 2; const bool rejects_mips = !IsSampledDepthExpansion(invalid_expansion, target); invalid_expansion = expanded; - invalid_expansion.type = Prospero::GpuEnumValue(Prospero::ImageType::kColor2D); - const bool rejects_topology = !IsSampledDepthExpansion(invalid_expansion, target); + invalid_expansion.type = + Prospero::GpuEnumValue(Prospero::ImageType::kColor2D); + const bool rejects_topology = + !IsSampledDepthExpansion(invalid_expansion, target); auto metadata_target = target; metadata_target.htile_address = 0x4a9c00000; metadata_target.htile_size = 0x10000; - const bool rejects_metadata = !IsSampledDepthExpansion(expanded, metadata_target); + const bool rejects_metadata = + !IsSampledDepthExpansion(expanded, metadata_target); Require("SampledDepthDescriptor", "expansion boundaries", - rejects_pitch && rejects_address && rejects_mips && rejects_topology && - rejects_metadata, + rejects_pitch && rejects_address && rejects_mips && + rejects_topology && rejects_metadata, "unsupported depth expansion topology was accepted"); std::printf("[host] %-32s ok\n", "SampledDepthDescriptor"); } @@ -9704,9 +9744,8 @@ void CheckBufferCacheRangeMerge() { Require("BufferCacheRangeMerge", "queue ownership", CanMergeBufferCacheQueueMask(0, 3) && CanMergeBufferCacheQueueMask(uint64_t{1} << 3u, 3) && - !CanMergeBufferCacheQueueMask((uint64_t{1} << 2u) | - (uint64_t{1} << 3u), - 3) && + !CanMergeBufferCacheQueueMask( + (uint64_t{1} << 2u) | (uint64_t{1} << 3u), 3) && !CanMergeBufferCacheQueueMask(0, 64), "cross-queue or invalid queue ownership was accepted"); std::printf("[host] %-32s ok\n", "BufferCacheRangeMerge"); @@ -9722,8 +9761,8 @@ ShaderRecompiler::IR::ImageResource BasicStorageTextureResource() { } ShaderTextureResource BasicStorageTextureDescriptor() { - return {{0x00785d00u, 0x04700000u, 0x00080008u, 0xa1b00facu, - 0x00000020u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x00785d00u, 0x04700000u, 0x00080008u, 0xa1b00facu, 0x00000020u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderRecompiler::IR::ImageResource BasicLinearStorageTextureResource() { @@ -9734,8 +9773,8 @@ ShaderRecompiler::IR::ImageResource BasicLinearStorageTextureResource() { } ShaderTextureResource BasicLinearStorageTextureDescriptor() { - return {{0x04bcc401u, 0xc3800000u, 0x021bc3bfu, 0x900003acu, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x04bcc401u, 0xc3800000u, 0x021bc3bfu, 0x900003acu, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderRecompiler::IR::ImageResource BasicBgraStorageTextureResource() { @@ -9746,13 +9785,13 @@ ShaderRecompiler::IR::ImageResource BasicBgraStorageTextureResource() { } ShaderTextureResource BasicBgraStorageTextureDescriptor() { - return {{0x007c6500u, 0xc3800000u, 0x010dc1dfu, 0x91b00f2eu, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x007c6500u, 0xc3800000u, 0x010dc1dfu, 0x91b00f2eu, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderTextureResource Ppsa01530MaxMipStorageTextureDescriptor() { - return {{0x04a42900u, 0xc3e00000u, 0x000fc00fu, 0x91b0022cu, - 0x00000000u, 0x00700050u, 0x00000000u, 0x00000000u}}; + return {{0x04a42900u, 0xc3e00000u, 0x000fc00fu, 0x91b0022cu, 0x00000000u, + 0x00700050u, 0x00000000u, 0x00000000u}}; } ShaderRecompiler::IR::ImageResource Ppsa01530MaxMipStorageTextureResource() { @@ -9762,23 +9801,23 @@ ShaderRecompiler::IR::ImageResource Ppsa01530MaxMipStorageTextureResource() { } ShaderTextureResource Ppsa02527R16FloatStorageTextureDescriptor() { - return {{0x00ce3500u, 0xc0d00000u, 0x010dc1dfu, 0x91b00204u, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x00ce3500u, 0xc0d00000u, 0x010dc1dfu, 0x91b00204u, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderTextureResource Ppsa02527R32FloatStorageTextureDescriptor() { - return {{0x00cea900u, 0xc1600000u, 0x0086c0efu, 0x91b00204u, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x00cea900u, 0xc1600000u, 0x0086c0efu, 0x91b00204u, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderTextureResource Ppsa02527R8UnormStorageTextureDescriptor() { - return {{0x00c7d500u, 0xc0100000u, 0x0086c0efu, 0x91b00204u, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x00c7d500u, 0xc0100000u, 0x0086c0efu, 0x91b00204u, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderTextureResource BasicYzwxStorageTextureDescriptor() { - return {{0x00627801u, 0xc4d00000u, 0x0001c001u, 0x900009f5u, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x00627801u, 0xc4d00000u, 0x0001c001u, 0x900009f5u, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderRecompiler::IR::ImageResource BasicArrayStorageTextureResource() { @@ -9788,8 +9827,8 @@ ShaderRecompiler::IR::ImageResource BasicArrayStorageTextureResource() { } ShaderTextureResource BasicArrayStorageTextureDescriptor() { - return {{0x20179000u, 0x03800000u, 0x00000000u, 0xd1b00f2eu, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x20179000u, 0x03800000u, 0x00000000u, 0xd1b00f2eu, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderRecompiler::IR::ImageResource BasicUintArrayStorageTextureResource() { @@ -9799,8 +9838,8 @@ ShaderRecompiler::IR::ImageResource BasicUintArrayStorageTextureResource() { } ShaderTextureResource BasicUintArrayStorageTextureDescriptor() { - return {{0x20179200u, 0x01400000u, 0x00000000u, 0xd1b00204u, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x20179200u, 0x01400000u, 0x00000000u, 0xd1b00204u, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderRecompiler::IR::ImageResource Ppsa14053DepthTileStorageTextureResource() { @@ -9808,8 +9847,8 @@ ShaderRecompiler::IR::ImageResource Ppsa14053DepthTileStorageTextureResource() { } ShaderTextureResource Ppsa14053DepthTileStorageTextureDescriptor() { - return {{0x20144c00u, 0x00500000u, 0x00000000u, 0xd1800204u, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x20144c00u, 0x00500000u, 0x00000000u, 0xd1800204u, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } ShaderRecompiler::IR::ImageResource BasicUintVolumeStorageTextureResource() { @@ -9820,8 +9859,8 @@ ShaderRecompiler::IR::ImageResource BasicUintVolumeStorageTextureResource() { } ShaderTextureResource BasicUintVolumeStorageTextureDescriptor() { - return {{0x20180600u, 0xc0b00000u, 0x0003c003u, 0xa0000004u, - 0x0000000fu, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x20180600u, 0xc0b00000u, 0x0003c003u, 0xa0000004u, 0x0000000fu, + 0x00700000u, 0x00000000u, 0x00000000u}}; } [[noreturn]] void RunStorageTextureDescriptorDeathCase(const char *kind) { @@ -9852,7 +9891,8 @@ ShaderTextureResource BasicUintVolumeStorageTextureDescriptor() { descriptor = BasicYzwxStorageTextureDescriptor(); descriptor.fields[1] = (descriptor.fields[1] & ~0x1ff00000u) | - (Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float) << 20u); + (Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float) + << 20u); } else if (std::strcmp(kind, "resource") == 0) { resource.written = false; } else if (std::strcmp(kind, "type") == 0) { @@ -9895,7 +9935,7 @@ ShaderTextureResource BasicUintVolumeStorageTextureDescriptor() { } else if (std::strcmp(kind, "depth-tile-extent") == 0) { resource = Ppsa14053DepthTileStorageTextureResource(); descriptor = Ppsa14053DepthTileStorageTextureDescriptor(); - descriptor.fields[4] |= 1u; + descriptor.fields[4] |= 1u; } else { std::_Exit(0x7e); } @@ -9906,7 +9946,8 @@ ShaderTextureResource BasicUintVolumeStorageTextureDescriptor() { void CheckBasicStorageTextureDescriptor() { const auto descriptor = BasicStorageTextureDescriptor(); Require("BasicStorageTexture", "descriptor", - descriptor.Base40() == 0x785d0000ull && descriptor.Width5() + 1u == 33 && + descriptor.Base40() == 0x785d0000ull && + descriptor.Width5() + 1u == 33 && descriptor.Height5() + 1u == 33 && descriptor.Depth() + 1u == 33, "basic 3D storage descriptor fixture is malformed"); ValidateStorageTexture(BasicStorageTextureResource(), descriptor, 0x10000); @@ -9915,17 +9956,22 @@ void CheckBasicStorageTextureDescriptor() { Require("BasicStorageTexture", "linear descriptor", linear.Base40() == 0x4bcc40100ull && linear.Width5() + 1u == 3840 && linear.Height5() + 1u == 2160 && linear.Depth() + 1u == 1 && - linear.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm) && - linear.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kLinear), + linear.Format() == Prospero::GpuEnumValue( + Prospero::BufferFormat::k8_8_8_8UNorm) && + linear.TileMode() == + Prospero::GpuEnumValue(Prospero::TileMode::kLinear), "PPSA07429 linear 2D storage descriptor fixture is malformed"); - ValidateStorageTexture(BasicLinearStorageTextureResource(), linear, 0x1fa4000); + ValidateStorageTexture(BasicLinearStorageTextureResource(), linear, + 0x1fa4000); const auto bgra = BasicBgraStorageTextureDescriptor(); Require("BasicStorageTexture", "BGRA descriptor", bgra.Base40() == 0x7c650000ull && bgra.Width5() + 1u == 1920 && bgra.Height5() + 1u == 1080 && bgra.Depth() + 1u == 1 && - bgra.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm) && - bgra.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && + bgra.Format() == Prospero::GpuEnumValue( + Prospero::BufferFormat::k8_8_8_8UNorm) && + bgra.TileMode() == + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && bgra.DstSelXYZW() == DstSel(6, 5, 4, 7), "PPSA02604 BGRA 2D storage descriptor fixture is malformed"); ValidateStorageTexture(BasicBgraStorageTextureResource(), bgra, 0x870000); @@ -9942,17 +9988,21 @@ void CheckBasicStorageTextureDescriptor() { Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && max_mip.DstSelXYZW() == DstSel(4, 5, 0, 1), "PPSA01530 max-mip storage descriptor fixture is malformed"); - ValidateStorageTexture(Ppsa01530MaxMipStorageTextureResource(), max_mip, 0x20000); + ValidateStorageTexture(Ppsa01530MaxMipStorageTextureResource(), max_mip, + 0x20000); auto mip_one = max_mip; mip_one.fields[3] |= (1u << 12u) | (1u << 16u); Require("BasicStorageTexture", "PPSA01530 mip-one descriptor", - mip_one.BaseLevel() == 1 && mip_one.LastLevel() == 1 && mip_one.MaxMip() == 5, + mip_one.BaseLevel() == 1 && mip_one.LastLevel() == 1 && + mip_one.MaxMip() == 5, "PPSA01530 mip-one storage descriptor fixture is malformed"); - ValidateStorageTexture(Ppsa01530MaxMipStorageTextureResource(), mip_one, 0x20000); + ValidateStorageTexture(Ppsa01530MaxMipStorageTextureResource(), mip_one, + 0x20000); const auto r16_float = Ppsa02527R16FloatStorageTextureDescriptor(); Require("BasicStorageTexture", "PPSA02527 R16F descriptor", - r16_float.Base40() == 0xce350000ull && r16_float.Width5() + 1u == 1920 && + r16_float.Base40() == 0xce350000ull && + r16_float.Width5() + 1u == 1920 && r16_float.Height5() + 1u == 1080 && r16_float.Depth() + 1u == 1 && r16_float.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k16Float) && @@ -9960,11 +10010,13 @@ void CheckBasicStorageTextureDescriptor() { Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && r16_float.DstSelXYZW() == DstSel(4, 0, 0, 1), "PPSA02527 R16F 2D storage descriptor fixture is malformed"); - ValidateStorageTexture(BasicBgraStorageTextureResource(), r16_float, 0x480000); + ValidateStorageTexture(BasicBgraStorageTextureResource(), r16_float, + 0x480000); const auto r32_float = Ppsa02527R32FloatStorageTextureDescriptor(); Require("BasicStorageTexture", "PPSA02527 R32F descriptor", - r32_float.Base40() == 0xcea90000ull && r32_float.Width5() + 1u == 960 && + r32_float.Base40() == 0xcea90000ull && + r32_float.Width5() + 1u == 960 && r32_float.Height5() + 1u == 540 && r32_float.Depth() + 1u == 1 && r32_float.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) && @@ -9972,7 +10024,8 @@ void CheckBasicStorageTextureDescriptor() { Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && r32_float.DstSelXYZW() == DstSel(4, 0, 0, 1), "PPSA02527 R32F 2D storage descriptor fixture is malformed"); - ValidateStorageTexture(BasicBgraStorageTextureResource(), r32_float, 0x280000); + ValidateStorageTexture(BasicBgraStorageTextureResource(), r32_float, + 0x280000); const auto r8_unorm = Ppsa02527R8UnormStorageTextureDescriptor(); Require("BasicStorageTexture", "PPSA02527 R8 UNORM descriptor", @@ -9990,8 +10043,10 @@ void CheckBasicStorageTextureDescriptor() { Require("BasicStorageTexture", "YZWX descriptor", yzwx.Base40() == 0x62780100ull && yzwx.Width5() + 1u == 8 && yzwx.Height5() + 1u == 8 && yzwx.Depth() + 1u == 1 && - yzwx.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k32_32_32_32Float) && - yzwx.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kLinear) && + yzwx.Format() == Prospero::GpuEnumValue( + Prospero::BufferFormat::k32_32_32_32Float) && + yzwx.TileMode() == + Prospero::GpuEnumValue(Prospero::TileMode::kLinear) && yzwx.DstSelXYZW() == DstSel(5, 6, 7, 4), "PPSA04181 linear YZWX storage descriptor fixture is malformed"); ValidateStorageTexture(BasicLinearStorageTextureResource(), yzwx, 0x800); @@ -10001,42 +10056,54 @@ void CheckBasicStorageTextureDescriptor() { array.Base40() == 0x2017900000ull && array.Width5() + 1u == 1 && array.Height5() + 1u == 1 && array.Depth() + 1u == 1 && array.BaseArray5() == 0 && - array.Type() == Prospero::GpuEnumValue(Prospero::ImageType::kColor2DArray) && - array.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm) && - array.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && + array.Type() == + Prospero::GpuEnumValue(Prospero::ImageType::kColor2DArray) && + array.Format() == Prospero::GpuEnumValue( + Prospero::BufferFormat::k8_8_8_8UNorm) && + array.TileMode() == + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && array.DstSelXYZW() == DstSel(6, 5, 4, 7), "PPSA21268 2D-array storage descriptor fixture is malformed"); ValidateStorageTexture(BasicArrayStorageTextureResource(), array, 0x10000); const auto uint_array = BasicUintArrayStorageTextureDescriptor(); Require("BasicStorageTexture", "uint 2D-array descriptor", - uint_array.Base40() == 0x2017920000ull && uint_array.Width5() + 1u == 1 && - uint_array.Height5() + 1u == 1 && uint_array.Depth() + 1u == 1 && - uint_array.BaseArray5() == 0 && - uint_array.Type() == Prospero::GpuEnumValue(Prospero::ImageType::kColor2DArray) && - uint_array.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt) && - uint_array.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && + uint_array.Base40() == 0x2017920000ull && + uint_array.Width5() + 1u == 1 && uint_array.Height5() + 1u == 1 && + uint_array.Depth() + 1u == 1 && uint_array.BaseArray5() == 0 && + uint_array.Type() == + Prospero::GpuEnumValue(Prospero::ImageType::kColor2DArray) && + uint_array.Format() == + Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt) && + uint_array.TileMode() == + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) && uint_array.DstSelXYZW() == DstSel(4, 0, 0, 1), "PPSA21268 uint 2D-array storage descriptor fixture is malformed"); - ValidateStorageTexture(BasicUintArrayStorageTextureResource(), uint_array, 0x10000); + ValidateStorageTexture(BasicUintArrayStorageTextureResource(), uint_array, + 0x10000); const auto uint_volume = BasicUintVolumeStorageTextureDescriptor(); Require("BasicStorageTexture", "uint 3D descriptor", - uint_volume.Base40() == 0x2018060000ull && uint_volume.Width5() + 1u == 16 && - uint_volume.Height5() + 1u == 16 && uint_volume.Depth() + 1u == 16 && - uint_volume.BaseArray5() == 0 && - uint_volume.Type() == Prospero::GpuEnumValue(Prospero::ImageType::kColor3D) && - uint_volume.Format() == Prospero::GpuEnumValue(Prospero::BufferFormat::k16UInt) && - uint_volume.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kLinear) && + uint_volume.Base40() == 0x2018060000ull && + uint_volume.Width5() + 1u == 16 && + uint_volume.Height5() + 1u == 16 && + uint_volume.Depth() + 1u == 16 && uint_volume.BaseArray5() == 0 && + uint_volume.Type() == + Prospero::GpuEnumValue(Prospero::ImageType::kColor3D) && + uint_volume.Format() == + Prospero::GpuEnumValue(Prospero::BufferFormat::k16UInt) && + uint_volume.TileMode() == + Prospero::GpuEnumValue(Prospero::TileMode::kLinear) && uint_volume.DstSelXYZW() == DstSel(4, 0, 0, 0), "PPSA21268 uint 3D storage descriptor fixture is malformed"); - ValidateStorageTexture(BasicUintVolumeStorageTextureResource(), uint_volume, 0x10000); + ValidateStorageTexture(BasicUintVolumeStorageTextureResource(), uint_volume, + 0x10000); const auto depth_tile = Ppsa14053DepthTileStorageTextureDescriptor(); Require("BasicStorageTexture", "PPSA14053 depth-tile descriptor", - depth_tile.Base40() == 0x20144c0000ull && depth_tile.Width5() + 1u == 1 && - depth_tile.Height5() + 1u == 1 && depth_tile.Depth() + 1u == 1 && - depth_tile.BaseArray5() == 0 && + depth_tile.Base40() == 0x20144c0000ull && + depth_tile.Width5() + 1u == 1 && depth_tile.Height5() + 1u == 1 && + depth_tile.Depth() + 1u == 1 && depth_tile.BaseArray5() == 0 && depth_tile.Type() == Prospero::GpuEnumValue(Prospero::ImageType::kColor2DArray) && depth_tile.Format() == @@ -10044,8 +10111,10 @@ void CheckBasicStorageTextureDescriptor() { depth_tile.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kDepth) && depth_tile.DstSelXYZW() == DstSel(4, 0, 0, 1), - "PPSA14053 write-only depth-tile storage descriptor fixture is malformed"); - ValidateStorageTexture(Ppsa14053DepthTileStorageTextureResource(), depth_tile, 0x10000); + "PPSA14053 write-only depth-tile storage descriptor fixture is " + "malformed"); + ValidateStorageTexture(Ppsa14053DepthTileStorageTextureResource(), depth_tile, + 0x10000); Require("BasicStorageTexture", "D32-compatible R32_UINT depth tile", IsSupportedStorageDepthTile( Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt), @@ -10061,12 +10130,12 @@ void CheckBasicStorageTextureDescriptor() { Require("BasicStorageTexture", "host", GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, "GetModuleFileName failed"); - for (const char *kind : {"resource", "type", "tile", "mip", "swizzle", - "linear-rgb1-read", "bgra-read", "r16-float-read", "r8-unorm-read", - "yzwx-read", "yzwx-format", - "array-base-view", "array-mip-view", "reserved", "metadata", "uint-format", - "uint-resource-float-format", "depth-tile-read", - "depth-tile-extent"}) { + for (const char *kind : + {"resource", "type", "tile", "mip", "swizzle", "linear-rgb1-read", + "bgra-read", "r16-float-read", "r8-unorm-read", "yzwx-read", + "yzwx-format", "array-base-view", "array-mip-view", "reserved", + "metadata", "uint-format", "uint-resource-float-format", + "depth-tile-read", "depth-tile-extent"}) { std::string command = std::string("\"") + path + "\" --storage-texture-descriptor-death " + kind; std::vector mutable_command(command.begin(), command.end()); @@ -10074,8 +10143,9 @@ void CheckBasicStorageTextureDescriptor() { STARTUPINFOA startup{sizeof(startup)}; PROCESS_INFORMATION process{}; Require("BasicStorageTexture", "host", - CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, FALSE, - CREATE_NO_WINDOW, nullptr, nullptr, &startup, &process) != 0, + CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, + FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &startup, + &process) != 0, "CreateProcess failed"); Require("BasicStorageTexture", "host", WaitForSingleObject(process.hProcess, 10000) == WAIT_OBJECT_0, @@ -10085,13 +10155,15 @@ void CheckBasicStorageTextureDescriptor() { CloseHandle(process.hThread); CloseHandle(process.hProcess); Require("BasicStorageTexture", "host", exited && exit_code == 321, - std::string(kind) + " storage descriptor did not report a fatal error"); + std::string(kind) + + " storage descriptor did not report a fatal error"); } std::printf("[host] %-32s ok\n", "BasicStorageTextureDescriptor"); } void CheckStorageTextureLinearUploadLayout() { - constexpr uint32_t format = Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm); + constexpr uint32_t format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm); constexpr uint32_t width = 3840; constexpr uint32_t height = 2160; constexpr uint32_t depth = 1; @@ -10104,8 +10176,8 @@ void CheckStorageTextureLinearUploadLayout() { format, width, height, 1, depth, pitch, tile, total.size, true, false, false, "StorageTextureLinearTest"); const auto regions = TextureBuildUploadRegions( - layout, VK_FORMAT_R8G8B8A8_UNORM, width, height, depth, 1, false, - false, TextureUploadDestination::MipLevels, + layout, vk::Format::eR8G8B8A8Unorm, width, height, depth, 1, false, false, + TextureUploadDestination::MipLevels, TextureUploadSliceLayout::MipChainPerSlice); Require("StorageTextureLinearUpload", "layout", pitch == width && total.size == 0x1fa4000 && total.align == 256 && @@ -10113,15 +10185,16 @@ void CheckStorageTextureLinearUploadLayout() { layout.slice_stride == total.size && regions.size() == 1 && regions[0].offset == 0 && regions[0].width == width && regions[0].height == height && regions[0].pitch == width && - TextureCalcUploadSize(layout, regions, 1, depth, - TextureUploadSliceLayout::MipChainPerSlice) == - total.size, + TextureCalcUploadSize( + layout, regions, 1, depth, + TextureUploadSliceLayout::MipChainPerSlice) == total.size, "linear RGBA8 storage upload lost Prospero pitch or allocation size"); std::printf("[host] %-32s ok\n", "StorageTextureLinearUpload"); } void CheckStorageTextureDepthTileUploadLayout() { - constexpr uint32_t format = Prospero::GpuEnumValue(Prospero::BufferFormat::k8UInt); + constexpr uint32_t format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k8UInt); constexpr uint32_t width = 1; constexpr uint32_t height = 1; constexpr uint32_t depth = 1; @@ -10139,7 +10212,7 @@ void CheckStorageTextureDepthTileUploadLayout() { format, width, height, 1, depth, pitch, tile, total.size, true, false, false, "StorageTextureDepthTileTest"); const auto regions = TextureBuildUploadRegions( - layout, VK_FORMAT_R8_UINT, width, height, depth, 1, true, false, + layout, vk::Format::eR8Uint, width, height, depth, 1, true, false, TextureUploadDestination::MipLevels, TextureUploadSliceLayout::MipChainPerSlice); Require("StorageTextureDepthTileUpload", "PPSA14053 layout", @@ -10152,9 +10225,9 @@ void CheckStorageTextureDepthTileUploadLayout() { layout.slice_stride == total.size && regions.size() == 1 && regions[0].offset == 0 && regions[0].width == width && regions[0].height == height && regions[0].pitch == pitch && - TextureCalcUploadSize(layout, regions, 1, depth, - TextureUploadSliceLayout::MipChainPerSlice) == - total.size, + TextureCalcUploadSize( + layout, regions, 1, depth, + TextureUploadSliceLayout::MipChainPerSlice) == total.size, "1x1 R8_UINT depth tile lost its PS5 64 KiB block footprint"); std::printf("[host] %-32s ok\n", "StorageTextureDepthTileUpload"); } @@ -10173,14 +10246,14 @@ void CheckStorageTextureLinearReadbackLayout() { info.depth = 1; info.type = Prospero::GpuEnumValue(Prospero::ImageType::kColor2D); const auto transfer = - MakeColorImageTransferInfo(info, VK_FORMAT_R8G8B8A8_UNORM, 4); + MakeColorImageTransferInfo(info, vk::Format::eR8G8B8A8Unorm, 4); const auto linear_size = ((static_cast(transfer.height) - 1) * transfer.pitch + transfer.width) * transfer.bytes_per_element; Require("StorageTextureLinearReadback", "layout", transfer.address == info.address && transfer.size == info.size && - transfer.format == VK_FORMAT_R8G8B8A8_UNORM && + transfer.format == vk::Format::eR8G8B8A8Unorm && transfer.width == info.width && transfer.height == info.height && transfer.pitch == info.pitch && transfer.bytes_per_element == 4 && transfer.tile_mode == info.tile && linear_size == info.size, @@ -10215,40 +10288,45 @@ void CheckStorageImageSwizzleSpecializationId() { const auto identity_id = ShaderGetIdCS(®s, &identity_info, true); const auto rgb1_id = ShaderGetIdCS(®s, &rgb1_info, true); Require("StorageImageSwizzleSpecializationId", "pipeline cache key", - identity_id != rgb1_id && identity_id.ids.size() == rgb1_id.ids.size(), + identity_id != rgb1_id && + identity_id.ids.size() == rgb1_id.ids.size(), "storage swizzle-specialized SPIR-V variants share a pipeline ID"); std::printf("[host] %-32s ok\n", "StorageImageSwizzlePipelineId"); } void CheckStorageTextureVolumeUploadLayout() { - constexpr uint32_t format = Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float); + constexpr uint32_t format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float); constexpr uint32_t width = 33; constexpr uint32_t height = 33; constexpr uint32_t depth = 33; constexpr uint32_t bytes_per_element = 8; const auto pitch = TileGetTexturePitch( - format, width, 1, Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget)); + format, width, 1, + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget)); TileSizeAlign total{}; - TileGetTextureTotalSize(format, width, height, depth, pitch, 1, - Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget), true, &total); + TileGetTextureTotalSize( + format, width, height, depth, pitch, 1, + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget), true, &total); const auto layout = TextureCalcUploadLayout( format, width, height, 1, depth, pitch, - Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget), total.size, true, false, true, - "StorageTextureVolumeTest"); + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget), total.size, + true, false, true, "StorageTextureVolumeTest"); const auto regions = TextureBuildUploadRegions( - layout, VK_FORMAT_R16G16B16A16_SFLOAT, width, height, depth, 1, false, true, - TextureUploadDestination::MipLevels, + layout, vk::Format::eR16G16B16A16Sfloat, width, height, depth, 1, false, + true, TextureUploadDestination::MipLevels, TextureUploadSliceLayout::MipChainPerSlice); - Require("StorageTextureVolumeUpload", "layout", - pitch == 128 && total.size == 0x210000 && - layout.slice_stride == 0x8400 && - layout.source_slice_stride == 0x10000 && - layout.level_sizes[0].size == 0x8400 && - layout.level_sizes[0].src_size == 0x10000 && - TextureCalcUploadSize(layout, regions, 1, depth, - TextureUploadSliceLayout::MipChainPerSlice) == - total.size, - "3D render-target upload did not preserve distinct linear and guest strides"); + Require( + "StorageTextureVolumeUpload", "layout", + pitch == 128 && total.size == 0x210000 && layout.slice_stride == 0x8400 && + layout.source_slice_stride == 0x10000 && + layout.level_sizes[0].size == 0x8400 && + layout.level_sizes[0].src_size == 0x10000 && + TextureCalcUploadSize(layout, regions, 1, depth, + TextureUploadSliceLayout::MipChainPerSlice) == + total.size, + "3D render-target upload did not preserve distinct linear and guest " + "strides"); std::vector source(total.size); for (uint32_t z = 0; z < depth; z++) { @@ -10263,14 +10341,15 @@ void CheckStorageTextureVolumeUploadLayout() { src_offset == static_cast(z) * 0x10000, "volume slice selected a compact linear source offset"); TileConvertTiledToLinearRenderTarget( - linear.data() + regions[z].offset, source.data() + src_offset, width, height, - regions[z].pitch, bytes_per_element, layout.level_sizes[0].size, + linear.data() + regions[z].offset, source.data() + src_offset, width, + height, regions[z].pitch, bytes_per_element, layout.level_sizes[0].size, layout.level_sizes[0].src_size, layout.level_sizes[0].x, layout.level_sizes[0].y); const auto value = static_cast(z + 1); for (uint32_t y = 0; y < height; y++) { - const auto row = regions[z].offset + - static_cast(y) * regions[z].pitch * bytes_per_element; + const auto row = regions[z].offset + static_cast(y) * + regions[z].pitch * + bytes_per_element; Require("StorageTextureVolumeUpload", "contents", std::all_of(linear.begin() + row, linear.begin() + row + width * bytes_per_element, @@ -10290,9 +10369,10 @@ void CheckColorResolveLayers() { dst.base_array_layer = 3; src.vulkan_buffer = reinterpret_cast(uintptr_t{1}); - Require("ColorResolveLayers", "identity", - !IsSameColorResolveSubresource(src, dst), - "different array layers were treated as the same resolve subresource"); + Require( + "ColorResolveLayers", "identity", + !IsSameColorResolveSubresource(src, dst), + "different array layers were treated as the same resolve subresource"); const auto copy = MakeColorResolveCopy(src, dst, 128, 64); Require("ColorResolveLayers", "region", copy.src_image == src.vulkan_buffer && copy.src_level == 2 && @@ -10310,13 +10390,12 @@ void CheckColorResolveLayers() { RenderTargetInfo info{}; info.address = 0x10000; info.size = 0x10000; - info.format = VK_FORMAT_R16G16B16A16_SFLOAT; + info.format = vk::Format::eR16G16B16A16Sfloat; info.width = 128; info.height = 64; info.pitch = 128; info.bytes_per_element = 8; - info.tile_mode = - Prospero::GpuEnumValue(Prospero::TileMode::kStandard64KB); + info.tile_mode = Prospero::GpuEnumValue(Prospero::TileMode::kStandard64KB); std::vector linear(info.size, 0); std::vector tiled(info.size, 0); Tiler tiler; @@ -10335,8 +10414,8 @@ void CheckStandard64RenderTargetTileRoundTrip() { const auto observed_pitch = TileGetTexturePitch(format, observed_width, 1, tile); TileSizeAlign observed{}; - TileGetTextureSize(format, observed_width, observed_height, observed_pitch, - 1, tile, &observed, nullptr, nullptr); + TileGetTextureSize(format, observed_width, observed_height, observed_pitch, 1, + tile, &observed, nullptr, nullptr); Require("Standard64RenderTarget", "observed layout", observed_pitch == 3840 && observed.size == 0x1fe0000 && observed.align == 0x10000, @@ -10346,32 +10425,29 @@ void CheckStandard64RenderTargetTileRoundTrip() { constexpr uint32_t height = 131; const auto pitch = TileGetTexturePitch(format, width, 1, tile); TileSizeAlign storage{}; - TileGetTextureSize(format, width, height, pitch, 1, tile, &storage, - nullptr, nullptr); + TileGetTextureSize(format, width, height, pitch, 1, tile, &storage, nullptr, + nullptr); Require("Standard64RenderTarget", "partial layout", - pitch == 384 && storage.size == 0x60000 && - storage.align == 0x10000, + pitch == 384 && storage.size == 0x60000 && storage.align == 0x10000, "partial Standard64KB footprint was not padded in 128x128 blocks"); RenderTargetInfo info{}; info.address = 0x10000; info.size = storage.size; - info.format = VK_FORMAT_R8G8B8A8_UNORM; + info.format = vk::Format::eR8G8B8A8Unorm; info.width = width; info.height = height; info.pitch = pitch; info.bytes_per_element = 4; info.tile_mode = tile; Require("Standard64RenderTarget", "support boundary", - IsSupportedStandard64RenderTarget(info) && - IsTiledRenderTarget(info), + IsSupportedStandard64RenderTarget(info) && IsTiledRenderTarget(info), "exact Standard64KB render target was not classified as tiled"); - Require( - "Standard64RenderTarget", "display tile boundary", - IsSupportedDisplayRenderTargetTileMode( - Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget)) && - !IsSupportedDisplayRenderTargetTileMode(tile), - "Standard64KB render target could alias a mode-27 display image"); + Require("Standard64RenderTarget", "display tile boundary", + IsSupportedDisplayRenderTargetTileMode( + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget)) && + !IsSupportedDisplayRenderTargetTileMode(tile), + "Standard64KB render target could alias a mode-27 display image"); auto unsupported = info; unsupported.address += 4; Require("Standard64RenderTarget", "address guard", @@ -10414,8 +10490,8 @@ void CheckStandard64RenderTargetTileRoundTrip() { std::vector restored(linear.size(), 0xa5a5a5a5u); Tiler tiler; tiler.TileImage(tiled.data(), linear.data(), info); - TileConvertTiledToLinearStandard64KB32( - restored.data(), tiled.data(), width, height, pitch, storage.size); + TileConvertTiledToLinearStandard64KB32(restored.data(), tiled.data(), width, + height, pitch, storage.size); for (uint32_t y = 0; y < height; y++) { const auto row = static_cast(y) * pitch; Require("Standard64RenderTarget", "round trip", @@ -10423,8 +10499,7 @@ void CheckStandard64RenderTargetTileRoundTrip() { width * sizeof(uint32_t)) == 0, "Standard64KB render-target conversion did not round-trip"); } - Require("Standard64RenderTarget", "padding", - tiled.back() == 0, + Require("Standard64RenderTarget", "padding", tiled.back() == 0, "Standard64KB render-target conversion retained stale padding"); constexpr uint32_t block_width = 128; @@ -10436,14 +10511,13 @@ void CheckStandard64RenderTargetTileRoundTrip() { } std::vector standard(known.size(), 0); std::vector render_target(known.size(), 0); - TileConvertLinearToTiledStandard64KB32( - standard.data(), known.data(), block_width, block_height, block_width, - block_size); + TileConvertLinearToTiledStandard64KB32(standard.data(), known.data(), + block_width, block_height, block_width, + block_size); Require("Standard64RenderTarget", "SDK byte mapping", standard[0] == 0 && standard[1] == 1 && standard[2] == 2 && - standard[4] == 128 && standard[8] == 256 && - standard[16] == 512 && standard[32] == 4 && - standard[16383] == 16383, + standard[4] == 128 && standard[8] == 256 && standard[16] == 512 && + standard[32] == 4 && standard[16383] == 16383, "Standard64KB reciprocal mapping disagreed with the PS5 SDK"); constexpr uint32_t block_width_16 = 256; @@ -10453,31 +10527,30 @@ void CheckStandard64RenderTargetTileRoundTrip() { tiled_16[i] = static_cast(i); } std::vector linear_16(tiled_16.size(), 0xffffu); - TileConvertTiledToLinearStandard64KB16( - linear_16.data(), tiled_16.data(), block_width_16, block_height_16, - block_width_16, block_size); + TileConvertTiledToLinearStandard64KB16(linear_16.data(), tiled_16.data(), + block_width_16, block_height_16, + block_width_16, block_size); const auto sample_16 = [&](uint32_t x, uint32_t y) { return linear_16[static_cast(y) * block_width_16 + x]; }; - Require("Standard64RenderTarget", "16-bit SDK byte mapping", - sample_16(0, 0) == 0 && sample_16(1, 0) == 1 && - sample_16(2, 0) == 2 && sample_16(4, 0) == 4 && - sample_16(8, 0) == 64 && sample_16(0, 1) == 8 && - sample_16(0, 2) == 16 && sample_16(0, 4) == 32, - "Standard64KB 16-bit mapping interleaved X/Y address bits incorrectly"); - TileConvertLinearToTiledRenderTarget( - render_target.data(), known.data(), block_width, block_height, - block_width, sizeof(uint32_t), block_size); - Require("Standard64RenderTarget", "mode identity", - standard != render_target, + Require( + "Standard64RenderTarget", "16-bit SDK byte mapping", + sample_16(0, 0) == 0 && sample_16(1, 0) == 1 && sample_16(2, 0) == 2 && + sample_16(4, 0) == 4 && sample_16(8, 0) == 64 && + sample_16(0, 1) == 8 && sample_16(0, 2) == 16 && + sample_16(0, 4) == 32, + "Standard64KB 16-bit mapping interleaved X/Y address bits incorrectly"); + TileConvertLinearToTiledRenderTarget(render_target.data(), known.data(), + block_width, block_height, block_width, + sizeof(uint32_t), block_size); + Require("Standard64RenderTarget", "mode identity", standard != render_target, "Standard64KB was accidentally treated as RenderTarget/XOR tiling"); char path[MAX_PATH]{}; Require("Standard64RenderTarget", "host", GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, "GetModuleFileName failed"); - std::string command = - std::string("\"") + path + "\" --standard64-rt-death"; + std::string command = std::string("\"") + path + "\" --standard64-rt-death"; std::vector mutable_command(command.begin(), command.end()); mutable_command.push_back('\0'); STARTUPINFOA startup{sizeof(startup)}; @@ -10494,8 +10567,7 @@ void CheckStandard64RenderTargetTileRoundTrip() { const bool exited = GetExitCodeProcess(process.hProcess, &exit_code) != 0; CloseHandle(process.hThread); CloseHandle(process.hProcess); - Require("Standard64RenderTarget", "hard failure", - exited && exit_code == 321, + Require("Standard64RenderTarget", "hard failure", exited && exit_code == 321, "unsupported Standard64KB render-target shape lost its fatal guard"); std::printf("[host] %-32s ok\n", "Standard64RenderTarget"); } @@ -10506,8 +10578,8 @@ void CheckRenderTargetTileRoundTrip() { uint32_t height; uint32_t bytes_per_element; }; - constexpr std::array cases{ - Case{129, 65, 1}, Case{257, 131, 2}, Case{3840, 2160, 4}, Case{65, 67, 8}}; + constexpr std::array cases{Case{129, 65, 1}, Case{257, 131, 2}, + Case{3840, 2160, 4}, Case{65, 67, 8}}; for (const auto test : cases) { const auto pitch = TileGetRenderTargetPitch(test.width, test.bytes_per_element); @@ -10521,23 +10593,23 @@ void CheckRenderTargetTileRoundTrip() { std::vector linear(storage.size, 0); for (uint32_t y = 0; y < test.height; y++) { for (uint32_t x = 0; x < test.width * test.bytes_per_element; x++) { - const auto offset = static_cast(y) * pitch * - test.bytes_per_element + - x; + const auto offset = + static_cast(y) * pitch * test.bytes_per_element + x; linear[offset] = static_cast( (x * 37u + y * 101u + test.bytes_per_element * 13u) & 0xffu); } } std::vector tiled(storage.size, 0xcd); std::vector restored(storage.size, 0xa5); - TileConvertLinearToTiledRenderTarget( - tiled.data(), linear.data(), test.width, test.height, pitch, - test.bytes_per_element, storage.size); - TileConvertTiledToLinearRenderTarget( - restored.data(), tiled.data(), test.width, test.height, pitch, - test.bytes_per_element, storage.size); + TileConvertLinearToTiledRenderTarget(tiled.data(), linear.data(), + test.width, test.height, pitch, + test.bytes_per_element, storage.size); + TileConvertTiledToLinearRenderTarget(restored.data(), tiled.data(), + test.width, test.height, pitch, + test.bytes_per_element, storage.size); for (uint32_t y = 0; y < test.height; y++) { - const auto row = static_cast(y) * pitch * test.bytes_per_element; + const auto row = + static_cast(y) * pitch * test.bytes_per_element; Require("RenderTargetTileRoundTrip", "contents", std::memcmp(linear.data() + row, restored.data() + row, test.width * test.bytes_per_element) == 0, @@ -10558,7 +10630,7 @@ void CheckRenderTargetTileRoundTrip() { RenderTargetInfo info{}; info.address = 1; info.size = storage.size * layers; - info.format = VK_FORMAT_R8G8B8A8_UNORM; + info.format = vk::Format::eR8G8B8A8Unorm; info.width = width; info.height = height; info.pitch = pitch; @@ -10579,10 +10651,10 @@ void CheckRenderTargetTileRoundTrip() { Tiler tiler; tiler.TileImage(tiled.data(), linear.data(), info); for (uint32_t layer = 0; layer < layers; layer++) { - TileConvertTiledToLinearRenderTarget( - restored.data() + storage.size * layer, - tiled.data() + storage.size * layer, width, height, pitch, - bytes_per_element, storage.size); + TileConvertTiledToLinearRenderTarget(restored.data() + storage.size * layer, + tiled.data() + storage.size * layer, + width, height, pitch, + bytes_per_element, storage.size); for (uint32_t y = 0; y < height; y++) { const auto row = storage.size * layer + static_cast(y) * pitch * bytes_per_element; @@ -10592,8 +10664,8 @@ void CheckRenderTargetTileRoundTrip() { "layered render-target conversion crossed array slices"); } } - const auto regions = MakeLayeredImageBufferCopies( - layers, storage.size, pitch, width, height); + const auto regions = + MakeLayeredImageBufferCopies(layers, storage.size, pitch, width, height); Require("RenderTargetTileRoundTrip", "layered regions", regions.size() == layers && regions[0].offset == 0 && regions[1].offset == storage.size && @@ -10629,14 +10701,15 @@ void CheckStorageTextureMipTailRoundTrip() { info.size = total.size; Require("StorageTextureMipTail", "layout", info.pitch == 128 && info.size == 0x20000 && - levels[0].src_offset == 0x10000 && levels[0].src_size == 0x10000 && - levels[1].src_offset == 0 && levels[1].src_size == 0x10000, + levels[0].src_offset == 0x10000 && + levels[0].src_size == 0x10000 && levels[1].src_offset == 0 && + levels[1].src_size == 0x10000, "PPSA01530 mip-tail fixture disagrees with the PS5 layout"); auto layout = TextureCalcUploadLayout( format, info.width, info.height, info.levels, info.depth, info.pitch, info.tile, info.size, true, false, false, "StorageTextureMipTailTest"); auto regions = TextureBuildUploadRegions( - layout, VK_FORMAT_R32G32_UINT, info.width, info.height, info.depth, + layout, vk::Format::eR32G32Uint, info.width, info.height, info.depth, info.levels, false, false, TextureUploadDestination::MipLevels, TextureUploadSliceLayout::MipChainPerSlice); std::vector linear(info.size, 0); @@ -10657,18 +10730,20 @@ void CheckStorageTextureMipTailRoundTrip() { for (uint32_t level = 0; level < info.levels; level++) { const auto ®ion = regions[level]; const auto &level_size = layout.level_sizes[level]; - const auto guest_offset = level_size.src_size != 0 ? level_size.src_offset - : level_size.offset; + const auto guest_offset = + level_size.src_size != 0 ? level_size.src_offset : level_size.offset; TileConvertTiledToLinearRenderTarget( restored.data() + region.offset, guest.data() + guest_offset, region.width, region.height, region.pitch, 8u, level_size.size, level_size.src_size, level_size.x, level_size.y); for (uint32_t y = 0; y < region.height; y++) { - const auto row = region.offset + static_cast(y) * region.pitch * 8u; + const auto row = + region.offset + static_cast(y) * region.pitch * 8u; Require("StorageTextureMipTail", "contents", std::memcmp(linear.data() + row, restored.data() + row, region.width * 8u) == 0, - "multi-mip storage texture did not round-trip through its packed tail"); + "multi-mip storage texture did not round-trip through its packed " + "tail"); } } std::printf("[host] %-32s ok\n", "StorageTextureMipTail"); @@ -10692,36 +10767,40 @@ void CheckDepthTargetTileRoundTrip() { Case{640, 360, Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), 4}}; for (const auto test : cases) { - const auto pitch = TileGetTexturePitch( - test.guest_format, test.width, 1, Prospero::GpuEnumValue(Prospero::TileMode::kDepth)); + const auto pitch = + TileGetTexturePitch(test.guest_format, test.width, 1, + Prospero::GpuEnumValue(Prospero::TileMode::kDepth)); TileSizeAlign stencil{}; TileSizeAlign htile{}; TileSizeAlign depth{}; Require("DepthTargetTileRoundTrip", "layout", pitch >= test.width && - TileGetDepthSize(test.width, test.height, 0, test.depth_format, - Prospero::GpuEnumValue(Prospero::StencilFormat::kInvalid), false, - &stencil, &htile, &depth) && + TileGetDepthSize( + test.width, test.height, 0, test.depth_format, + Prospero::GpuEnumValue(Prospero::StencilFormat::kInvalid), + false, &stencil, &htile, &depth) && depth.size != 0 && depth.align == 0x10000, "Prospero depth layout was rejected"); std::vector linear(depth.size, 0); for (uint32_t y = 0; y < test.height; y++) { for (uint32_t x = 0; x < test.width * test.bytes_per_element; x++) { - const auto offset = static_cast(y) * pitch * - test.bytes_per_element + - x; + const auto offset = + static_cast(y) * pitch * test.bytes_per_element + x; linear[offset] = static_cast( (x * 29u + y * 83u + test.bytes_per_element * 17u) & 0xffu); } } std::vector tiled(depth.size, 0xcd); std::vector restored(depth.size, 0xa5); - TileConvertLinearToTiledDepth(tiled.data(), linear.data(), test.guest_format, - test.width, test.height, pitch, depth.size); - TileConvertTiledToLinearDepth(restored.data(), tiled.data(), test.guest_format, - test.width, test.height, pitch, depth.size); + TileConvertLinearToTiledDepth(tiled.data(), linear.data(), + test.guest_format, test.width, test.height, + pitch, depth.size); + TileConvertTiledToLinearDepth(restored.data(), tiled.data(), + test.guest_format, test.width, test.height, + pitch, depth.size); for (uint32_t y = 0; y < test.height; y++) { - const auto row = static_cast(y) * pitch * test.bytes_per_element; + const auto row = + static_cast(y) * pitch * test.bytes_per_element; Require("DepthTargetTileRoundTrip", "contents", std::memcmp(linear.data() + row, restored.data() + row, test.width * test.bytes_per_element) == 0, @@ -10772,7 +10851,8 @@ void CheckStencilTargetTileRoundTrip() { uint32_t height; }; constexpr std::array cases{Case{8, 8}, Case{257, 259}, Case{1920, 1080}}; - constexpr auto format = Prospero::GpuEnumValue(Prospero::BufferFormat::k8UInt); + constexpr auto format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k8UInt); constexpr auto tile = Prospero::GpuEnumValue(Prospero::TileMode::kDepth); for (const auto test : cases) { const auto pitch = TileGetTexturePitch(format, test.width, 1, tile); @@ -10781,10 +10861,11 @@ void CheckStencilTargetTileRoundTrip() { TileSizeAlign depth{}; Require("StencilTargetTileRoundTrip", "layout", pitch >= test.width && pitch % 256 == 0 && - TileGetDepthSize(test.width, test.height, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), false, - &stencil, &htile, &depth) && + TileGetDepthSize( + test.width, test.height, 0, + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), + false, &stencil, &htile, &depth) && stencil.size != 0 && stencil.align == 0x10000, "Prospero stencil layout was rejected"); std::vector linear(stencil.size, 0); @@ -10796,14 +10877,15 @@ void CheckStencilTargetTileRoundTrip() { } std::vector tiled(stencil.size, 0xcd); std::vector restored(stencil.size, 0xa5); - TileConvertLinearToTiledDepth(tiled.data(), linear.data(), format, test.width, - test.height, pitch, stencil.size); - TileConvertTiledToLinearDepth(restored.data(), tiled.data(), format, test.width, - test.height, pitch, stencil.size); + TileConvertLinearToTiledDepth(tiled.data(), linear.data(), format, + test.width, test.height, pitch, stencil.size); + TileConvertTiledToLinearDepth(restored.data(), tiled.data(), format, + test.width, test.height, pitch, stencil.size); for (uint32_t y = 0; y < test.height; y++) { const auto row = static_cast(y) * pitch; Require("StencilTargetTileRoundTrip", "contents", - std::memcmp(linear.data() + row, restored.data() + row, test.width) == 0, + std::memcmp(linear.data() + row, restored.data() + row, + test.width) == 0, "linear-to-tiled PS5 stencil conversion did not round-trip"); } if (test.width == 8 && test.height == 8) { @@ -10815,7 +10897,8 @@ void CheckStencilTargetTileRoundTrip() { } if (test.width == 257 && test.height == 259) { Require("StencilTargetTileRoundTrip", "Prospero S8 block order", - tiled[0x10000] == linear[256] && tiled[0x20000] == linear[256 * pitch], + tiled[0x10000] == linear[256] && + tiled[0x20000] == linear[256 * pitch], "Prospero S8 stencil block order changed"); } if (test.width == 1920 && test.height == 1080) { @@ -10830,62 +10913,72 @@ void CheckStencilTargetTileRoundTrip() { void CheckStorageTextureGpuOwnedRebindState() { constexpr uintptr_t base = 0x0000000200200000ull; constexpr uint64_t size = 0x10000; - auto *memory = static_cast(VirtualAlloc( - reinterpret_cast(base), size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto *memory = static_cast( + VirtualAlloc(reinterpret_cast(base), size, + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); Require("StorageTextureGpuOwnedRebind", "allocation", - memory == reinterpret_cast(base), "fixed VirtualAlloc failed"); + memory == reinterpret_cast(base), + "fixed VirtualAlloc failed"); PageManager page_manager(CacheFault, nullptr); MemoryTracker tracker(page_manager); page_manager.OnGpuMap(base, size); - tracker.ForEachUploadRange(base, size, true, - [](uint64_t, uint64_t) noexcept {}, []() noexcept {}); + tracker.ForEachUploadRange( + base, size, true, [](uint64_t, uint64_t) noexcept {}, []() noexcept {}); uint64_t readable = 0; uint64_t mapped = 0; MEMORY_BASIC_INFORMATION protection{}; - Require("StorageTextureGpuOwnedRebind", "owned", - tracker.IsRegionGpuModified(base, size) && page_manager.IsMapped(base, size) && - (!HostMemoryQueryReadable(base, size, &readable) || readable < size) && - HostMemoryQueryRange(base, size, HostMemoryAccess::Mapped, &mapped) && - mapped == size && - VirtualQuery(memory, &protection, sizeof(protection)) != 0 && - protection.Protect == PAGE_NOACCESS, - "GPU-owned storage pages remained host-readable or lost tracker identity"); + Require( + "StorageTextureGpuOwnedRebind", "owned", + tracker.IsRegionGpuModified(base, size) && + page_manager.IsMapped(base, size) && + (!HostMemoryQueryReadable(base, size, &readable) || + readable < size) && + HostMemoryQueryRange(base, size, HostMemoryAccess::Mapped, &mapped) && + mapped == size && + VirtualQuery(memory, &protection, sizeof(protection)) != 0 && + protection.Protect == PAGE_NOACCESS, + "GPU-owned storage pages remained host-readable or lost tracker " + "identity"); tracker.UnmarkRegionAsGpuModified(base, size); readable = 0; Require("StorageTextureGpuOwnedRebind", "clean readback", !tracker.IsRegionGpuModified(base, size) && !tracker.IsRegionCpuModified(base, size) && - HostMemoryQueryReadable(base, size, &readable) && readable == size, + HostMemoryQueryReadable(base, size, &readable) && + readable == size, "clean storage readback did not publish readable coherent backing"); tracker.MarkRegionAsGpuModified(base, size); readable = 0; - Require("StorageTextureGpuOwnedRebind", "clean reclaim", - tracker.IsRegionGpuModified(base, size) && - !tracker.IsRegionCpuModified(base, size) && - (!HostMemoryQueryReadable(base, size, &readable) || readable < size), - "clean storage rebind did not reclaim GPU ownership without an upload"); + Require( + "StorageTextureGpuOwnedRebind", "clean reclaim", + tracker.IsRegionGpuModified(base, size) && + !tracker.IsRegionCpuModified(base, size) && + (!HostMemoryQueryReadable(base, size, &readable) || readable < size), + "clean storage rebind did not reclaim GPU ownership without an upload"); tracker.UnmarkRegionAsGpuModified(base, size); tracker.MarkRegionAsCpuModified(base, size); uint32_t dirty_ranges = 0; bool upload_called = false; tracker.ForEachUploadRange( - base, size, true, - [&](uint64_t, uint64_t) noexcept { dirty_ranges++; }, + base, size, true, [&](uint64_t, uint64_t) noexcept { dirty_ranges++; }, [&]() noexcept { upload_called = true; }); readable = 0; - Require("StorageTextureGpuOwnedRebind", "dirty refresh", - dirty_ranges == 1 && upload_called && tracker.IsRegionGpuModified(base, size) && - !tracker.IsRegionCpuModified(base, size) && - (!HostMemoryQueryReadable(base, size, &readable) || readable < size), - "CPU-dirty storage rebind did not refresh once and reclaim GPU ownership"); + Require( + "StorageTextureGpuOwnedRebind", "dirty refresh", + dirty_ranges == 1 && upload_called && + tracker.IsRegionGpuModified(base, size) && + !tracker.IsRegionCpuModified(base, size) && + (!HostMemoryQueryReadable(base, size, &readable) || readable < size), + "CPU-dirty storage rebind did not refresh once and reclaim GPU " + "ownership"); tracker.UnmarkRegionAsGpuModified(base, size); tracker.UntrackMemory(base, size); page_manager.OnGpuUnmap(base, size); - Require("StorageTextureGpuOwnedRebind", "free", VirtualFree(memory, 0, MEM_RELEASE) != 0, - "VirtualFree failed"); + Require("StorageTextureGpuOwnedRebind", "free", + VirtualFree(memory, 0, MEM_RELEASE) != 0, "VirtualFree failed"); std::printf("[host] %-32s ok\n", "StorageTextureGpuOwnedRebind"); } @@ -10894,24 +10987,26 @@ void CheckStorageTextureSampledReuse() { const auto image_2d_array = Prospero::GpuEnumValue(Prospero::ImageType::kColor2DArray); const auto image_3d = Prospero::GpuEnumValue(Prospero::ImageType::kColor3D); - Require("StorageTextureSampledReuse", "view shapes", - SelectStorageSampledViewShape(image_2d, 1, 1) == - StorageSampledViewShape::Image2D && - SelectStorageSampledViewShape(image_2d_array, 16, 16) == - StorageSampledViewShape::Image2DArray && - SelectStorageSampledViewShape(image_3d, 16, 1) == - StorageSampledViewShape::Image3D && - SelectStorageSampledViewShape(image_2d, 16, 1) == - StorageSampledViewShape::Unsupported && - SelectStorageSampledViewShape(image_2d_array, 16, 1) == - StorageSampledViewShape::Unsupported && - SelectStorageSampledViewShape(image_3d, 16, 16) == - StorageSampledViewShape::Unsupported, - "sampled storage view shape or backing-layer validation is incorrect"); + Require( + "StorageTextureSampledReuse", "view shapes", + SelectStorageSampledViewShape(image_2d, 1, 1) == + StorageSampledViewShape::Image2D && + SelectStorageSampledViewShape(image_2d_array, 16, 16) == + StorageSampledViewShape::Image2DArray && + SelectStorageSampledViewShape(image_3d, 16, 1) == + StorageSampledViewShape::Image3D && + SelectStorageSampledViewShape(image_2d, 16, 1) == + StorageSampledViewShape::Unsupported && + SelectStorageSampledViewShape(image_2d_array, 16, 1) == + StorageSampledViewShape::Unsupported && + SelectStorageSampledViewShape(image_3d, 16, 16) == + StorageSampledViewShape::Unsupported, + "sampled storage view shape or backing-layer validation is incorrect"); ImageInfo storage{}; storage.address = 0x78650000; storage.size = 0x210000; - storage.format = Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float); + storage.format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float); storage.width = 33; storage.height = 33; storage.pitch = 128; @@ -10922,76 +11017,78 @@ void CheckStorageTextureSampledReuse() { storage.type = Prospero::GpuEnumValue(Prospero::ImageType::kColor3D); Require("StorageTextureSampledReuse", "exact", - ClassifyStorageSampledOverlap(storage, storage, - VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_SFLOAT, - true, false, true) == - StorageSampledOverlap::ExactImage, + ClassifyStorageSampledOverlap( + storage, storage, vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Sfloat, true, false, + true) == StorageSampledOverlap::ExactImage, "exact GPU-owned storage image was not reusable for sampling"); auto incompatible = storage; - incompatible.format = Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16UNorm); + incompatible.format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16UNorm); Require("StorageTextureSampledReuse", "incompatible", - ClassifyStorageSampledOverlap(incompatible, storage, - VK_FORMAT_R16G16B16A16_UNORM, - VK_FORMAT_R16G16B16A16_SFLOAT, - true, false, true) == - StorageSampledOverlap::Unsupported && - ClassifyStorageSampledOverlap(storage, storage, - VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_SFLOAT, - false, false, true) == - StorageSampledOverlap::Unsupported && - ClassifyStorageSampledOverlap(storage, storage, - VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_SFLOAT, - true, true, true) == - StorageSampledOverlap::Unsupported && - ClassifyStorageSampledOverlap(storage, storage, - VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_SFLOAT, - true, false, false) == - StorageSampledOverlap::Unsupported, + ClassifyStorageSampledOverlap( + incompatible, storage, vk::Format::eR16G16B16A16Unorm, + vk::Format::eR16G16B16A16Sfloat, true, false, + true) == StorageSampledOverlap::Unsupported && + ClassifyStorageSampledOverlap( + storage, storage, vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Sfloat, false, false, + true) == StorageSampledOverlap::Unsupported && + ClassifyStorageSampledOverlap( + storage, storage, vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Sfloat, true, true, + true) == StorageSampledOverlap::Unsupported && + ClassifyStorageSampledOverlap( + storage, storage, vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Sfloat, true, false, + false) == StorageSampledOverlap::Unsupported, "incompatible storage-image state was accepted for sampling"); auto separate = storage; separate.address += 0x400000; Require("StorageTextureSampledReuse", "separate", - ClassifyStorageSampledOverlap(separate, storage, - VK_FORMAT_R16G16B16A16_SFLOAT, - VK_FORMAT_R16G16B16A16_SFLOAT, - true, false, true) == - StorageSampledOverlap::None, + ClassifyStorageSampledOverlap( + separate, storage, vk::Format::eR16G16B16A16Sfloat, + vk::Format::eR16G16B16A16Sfloat, true, false, + true) == StorageSampledOverlap::None, "disjoint storage image was classified as an alias"); ImageInfo ppsa02604_storage{}; ppsa02604_storage.address = 0x7c690000; ppsa02604_storage.size = 0x870000; - ppsa02604_storage.format = Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm); + ppsa02604_storage.format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm); ppsa02604_storage.width = 1920; ppsa02604_storage.height = 1080; ppsa02604_storage.pitch = 1920; - ppsa02604_storage.tile = Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget); + ppsa02604_storage.tile = + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget); ppsa02604_storage.swizzle = DstSel(6, 5, 4, 7); - ppsa02604_storage.type = Prospero::GpuEnumValue(Prospero::ImageType::kColor2D); + ppsa02604_storage.type = + Prospero::GpuEnumValue(Prospero::ImageType::kColor2D); auto ppsa02604_sampled = ppsa02604_storage; - ppsa02604_sampled.format = Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb); + ppsa02604_sampled.format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb); Require("StorageTextureSampledReuse", "PPSA02604 sRGB view", ClassifyStorageSampledOverlap( - ppsa02604_sampled, ppsa02604_storage, VK_FORMAT_R8G8B8A8_SRGB, - VK_FORMAT_R8G8B8A8_UNORM, true, false, true) == - StorageSampledOverlap::ExactImage, - "PPSA02604 GPU-owned UNORM storage image did not accept its exact sRGB view"); + ppsa02604_sampled, ppsa02604_storage, vk::Format::eR8G8B8A8Srgb, + vk::Format::eR8G8B8A8Unorm, true, false, + true) == StorageSampledOverlap::ExactImage, + "PPSA02604 GPU-owned UNORM storage image did not accept its exact " + "sRGB view"); auto alternate_swizzle = ppsa02604_storage; alternate_swizzle.swizzle = DstSel(4, 5, 6, 7); - Require("StorageTextureSampledReuse", "descriptor swizzle view", - ClassifyStorageSampledOverlap( - alternate_swizzle, ppsa02604_storage, VK_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, true, false, true) == - StorageSampledOverlap::ExactImage, - "exact storage backing rejected a distinct sampled descriptor swizzle"); + Require( + "StorageTextureSampledReuse", "descriptor swizzle view", + ClassifyStorageSampledOverlap(alternate_swizzle, ppsa02604_storage, + vk::Format::eR8G8B8A8Unorm, + vk::Format::eR8G8B8A8Unorm, true, false, + true) == StorageSampledOverlap::ExactImage, + "exact storage backing rejected a distinct sampled descriptor swizzle"); ImageInfo depth_uint_storage{}; depth_uint_storage.address = 0x4a5c90000; depth_uint_storage.size = 0x10000; - depth_uint_storage.format = Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt); + depth_uint_storage.format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k32UInt); depth_uint_storage.width = 64; depth_uint_storage.height = 64; depth_uint_storage.pitch = 128; @@ -11002,23 +11099,28 @@ void CheckStorageTextureSampledReuse() { depth_uint_storage.swizzle = DstSel(4, 4, 4, 4); depth_uint_storage.type = image_2d; auto depth_float_sampled = depth_uint_storage; - depth_float_sampled.format = Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float); + depth_float_sampled.format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float); depth_float_sampled.swizzle = DstSel(4, 0, 0, 1); Require("StorageTextureSampledReuse", "PPSA01530 R32 view", - ClassifyStorageSampledOverlap(depth_float_sampled, depth_uint_storage, - VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_UINT, - true, false, true) == - StorageSampledOverlap::ExactImage, - "PPSA01530 GPU-owned R32_UINT storage image did not accept its exact R32_SFLOAT view"); + ClassifyStorageSampledOverlap( + depth_float_sampled, depth_uint_storage, vk::Format::eR32Sfloat, + vk::Format::eR32Uint, true, false, + true) == StorageSampledOverlap::ExactImage, + "PPSA01530 GPU-owned R32_UINT storage image did not accept its exact " + "R32_SFLOAT view"); const auto usage = TextureFormatUsage::Sampled | TextureFormatUsage::Storage; - Require("StorageTextureSampledReuse", "usage", - (TextureGetUsage(usage) & - (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT)) == - (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT) && - (TextureGetViewUsage(usage) & - (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT)) == - (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), - "shared storage image or view is missing sampled/storage usage"); + Require( + "StorageTextureSampledReuse", "usage", + (TextureGetUsage(usage) & + (vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eStorage)) == + (vk::ImageUsageFlagBits::eSampled | + vk::ImageUsageFlagBits::eStorage) && + (TextureGetViewUsage(usage) & (vk::ImageUsageFlagBits::eSampled | + vk::ImageUsageFlagBits::eStorage)) == + (vk::ImageUsageFlagBits::eSampled | + vk::ImageUsageFlagBits::eStorage), + "shared storage image or view is missing sampled/storage usage"); std::printf("[host] %-32s ok\n", "StorageTextureSampledReuse"); } @@ -11032,16 +11134,19 @@ void CheckStorageTextureDepthAlias() { depth.stencil_address = storage.address; depth.stencil_size = storage.size; Require("StorageTextureDepthAlias", "inactive stencil", - ClassifyStorageDepthOverlap(storage, depth) == DepthOverlap::RetireStorage, + ClassifyStorageDepthOverlap(storage, depth) == + DepthOverlap::RetireStorage, "inactive stencil storage ownership was not retired"); depth.stencil_access = true; Require("StorageTextureDepthAlias", "active stencil", - ClassifyStorageDepthOverlap(storage, depth) == DepthOverlap::Unsupported, + ClassifyStorageDepthOverlap(storage, depth) == + DepthOverlap::Unsupported, "active stencil storage contents were discarded"); depth.stencil_access = false; storage.address = depth.address; Require("StorageTextureDepthAlias", "depth aspect", - ClassifyStorageDepthOverlap(storage, depth) == DepthOverlap::Unsupported, + ClassifyStorageDepthOverlap(storage, depth) == + DepthOverlap::Unsupported, "depth-aspect storage contents were discarded"); storage.address = 0x2000000000ull; Require("StorageTextureDepthAlias", "disjoint", @@ -11078,7 +11183,8 @@ void CheckStorageTextureAccessPermissions() { constexpr uint64_t size = 0x10000; auto *memory = VirtualAlloc(reinterpret_cast(base), size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - Require("StorageTextureAccess", "allocation", memory == reinterpret_cast(base), + Require("StorageTextureAccess", "allocation", + memory == reinterpret_cast(base), "fixed VirtualAlloc failed"); ResourceMutex resource_mutex; PageManager page_manager(CacheFault, nullptr); @@ -11086,23 +11192,24 @@ void CheckStorageTextureAccessPermissions() { page_manager.OnGpuMap(base, size, GpuAccess::ReadWrite); buffer_cache.ValidateGpuAccess(base, size, true, true); page_manager.OnGpuUnmap(base, size, GpuAccess::ReadWrite); - Require("StorageTextureAccess", "free", VirtualFree(memory, 0, MEM_RELEASE) != 0, - "VirtualFree failed"); + Require("StorageTextureAccess", "free", + VirtualFree(memory, 0, MEM_RELEASE) != 0, "VirtualFree failed"); char path[MAX_PATH]{}; Require("StorageTextureAccess", "host", GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, "GetModuleFileName failed"); for (const char *kind : {"read", "write"}) { - std::string command = std::string("\"") + path + - "\" --storage-texture-access-death " + kind; + std::string command = + std::string("\"") + path + "\" --storage-texture-access-death " + kind; std::vector mutable_command(command.begin(), command.end()); mutable_command.push_back('\0'); STARTUPINFOA startup{sizeof(startup)}; PROCESS_INFORMATION process{}; Require("StorageTextureAccess", "host", - CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, FALSE, - CREATE_NO_WINDOW, nullptr, nullptr, &startup, &process) != 0, + CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, + FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &startup, + &process) != 0, "CreateProcess failed"); Require("StorageTextureAccess", "host", WaitForSingleObject(process.hProcess, 10000) == WAIT_OBJECT_0, @@ -11120,9 +11227,9 @@ void CheckStorageTextureAccessPermissions() { [[noreturn]] void RunMetaOverlapDeathCase(const char *kind) { constexpr uint64_t address = 0x0000000200010000ull; constexpr uint64_t allocation_size = 0x10000; - auto *memory = static_cast(VirtualAlloc( - reinterpret_cast(address), allocation_size, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto *memory = static_cast( + VirtualAlloc(reinterpret_cast(address), allocation_size, + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); if (memory != reinterpret_cast(address)) { EXIT("metadata-overlap child could not reserve its fixed test address\n"); } @@ -11143,31 +11250,34 @@ void CheckStorageTextureAccessPermissions() { info.size = 0x1000; info.width = 1; info.height = 1; - (void)texture_cache.FindTexture(reinterpret_cast(1), ctx, info, false); + (void)texture_cache.FindTexture(reinterpret_cast(1), ctx, + info, false); } else if (std::strcmp(kind, "render-target") == 0) { RenderTargetInfo info{}; info.address = address; info.size = 0x1000; - info.format = VK_FORMAT_R8G8B8A8_UNORM; + info.format = vk::Format::eR8G8B8A8Unorm; info.width = 1; info.height = 1; info.pitch = 1; info.bytes_per_element = 4; info.tile_mode = Prospero::GpuEnumValue(Prospero::TileMode::kLinear); - (void)texture_cache.FindRenderTarget(reinterpret_cast(1), ctx, info); + (void)texture_cache.FindRenderTarget(reinterpret_cast(1), + ctx, info); } else if (std::strcmp(kind, "depth-target") == 0) { DepthTargetInfo info{}; info.address = address; info.size = 0x1000; - info.format = VK_FORMAT_D16_UNORM; - info.guest_format = Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm); + info.format = vk::Format::eD16Unorm; + info.guest_format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm); info.width = 1; info.height = 1; info.pitch = 1; info.bytes_per_element = 2; info.tile_mode = Prospero::GpuEnumValue(Prospero::TileMode::kDepth); - (void)texture_cache.FindDepthTarget(reinterpret_cast(1), ctx, - info); + (void)texture_cache.FindDepthTarget(reinterpret_cast(1), + ctx, info); } else if (std::strcmp(kind, "copy-stale") == 0) { if (!texture_cache.ClearMeta(address)) { std::_Exit(0x7f); @@ -11188,8 +11298,8 @@ ShaderRecompiler::IR::ImageResource BasicMetadataReuseResource() { } ShaderTextureResource BasicMetadataReuseDescriptor() { - return {{0x0062b100u, 0xcad00000u, 0x003fc03fu, 0x90500facu, - 0x00000000u, 0x00700000u, 0x00000000u, 0x00000000u}}; + return {{0x0062b100u, 0xcad00000u, 0x003fc03fu, 0x90500facu, 0x00000000u, + 0x00700000u, 0x00000000u, 0x00000000u}}; } [[noreturn]] void RunMetadataDescriptorDeathCase(const char *kind) { @@ -11218,19 +11328,21 @@ ShaderTextureResource BasicMetadataReuseDescriptor() { void CheckMetaOverlapDeaths() { char path[MAX_PATH]{}; - Require("MetaOverlap", "host", GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, + Require("MetaOverlap", "host", + GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, "GetModuleFileName failed"); - for (const char *kind : {"metadata-size", "texture", "render-target", "depth-target", - "copy-stale"}) { - std::string command = std::string("\"") + path + - "\" --meta-overlap-death " + kind; + for (const char *kind : {"metadata-size", "texture", "render-target", + "depth-target", "copy-stale"}) { + std::string command = + std::string("\"") + path + "\" --meta-overlap-death " + kind; std::vector mutable_command(command.begin(), command.end()); mutable_command.push_back('\0'); STARTUPINFOA startup{sizeof(startup)}; PROCESS_INFORMATION process{}; Require("MetaOverlap", "host", - CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, FALSE, - CREATE_NO_WINDOW, nullptr, nullptr, &startup, &process) != 0, + CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, + FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &startup, + &process) != 0, "CreateProcess failed"); Require("MetaOverlap", "host", WaitForSingleObject(process.hProcess, 10000) == WAIT_OBJECT_0, @@ -11250,11 +11362,12 @@ void CheckOverlappingMetadataViews() { constexpr uint64_t allocation_size = 0x60000; constexpr uint64_t metadata_size = 0x30000; constexpr uint64_t second = base + 0x18000; - auto *memory = static_cast(VirtualAlloc( - reinterpret_cast(base), allocation_size, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto *memory = static_cast( + VirtualAlloc(reinterpret_cast(base), allocation_size, + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); Require("OverlappingMetadataViews", "allocation", - memory == reinterpret_cast(base), "fixed VirtualAlloc failed"); + memory == reinterpret_cast(base), + "fixed VirtualAlloc failed"); ResourceMutex resource_mutex; CacheFaultContext fault_context; @@ -11297,11 +11410,12 @@ void CheckQueryRegionAggregation() { constexpr uintptr_t base = 0x0000000200010000ull; constexpr uint64_t allocation_size = 0x10000; constexpr uint64_t metadata_size = 0x180; - auto *memory = static_cast(VirtualAlloc( - reinterpret_cast(base), allocation_size, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto *memory = static_cast( + VirtualAlloc(reinterpret_cast(base), allocation_size, + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); Require("QueryRegionAggregation", "allocation", - memory == reinterpret_cast(base), "fixed VirtualAlloc failed"); + memory == reinterpret_cast(base), + "fixed VirtualAlloc failed"); ResourceMutex resource_mutex; CacheFaultContext fault_context; @@ -11323,14 +11437,15 @@ void CheckQueryRegionAggregation() { const auto bytes = texture_cache.QueryRegion(base + 0x20, 0x40); const auto page_only = texture_cache.QueryRegion(base + 0x400, 0x40); const auto disjoint = texture_cache.QueryRegion(base + 0x1000, 0x40); - Require("QueryRegionAggregation", "page and byte overlap", - bytes.metadata_pages && bytes.metadata_bytes && - !bytes.gpu_metadata_bytes && page_only.metadata_pages && - !page_only.metadata_bytes && !page_only.gpu_metadata_bytes && - !disjoint.metadata_pages && !disjoint.metadata_bytes && - !bytes.image_pages && !bytes.image_bytes && - !bytes.gpu_image_bytes && !bytes.non_sampled_pages, - "metadata page candidates were not separated from exact byte overlap"); + Require( + "QueryRegionAggregation", "page and byte overlap", + bytes.metadata_pages && bytes.metadata_bytes && + !bytes.gpu_metadata_bytes && page_only.metadata_pages && + !page_only.metadata_bytes && !page_only.gpu_metadata_bytes && + !disjoint.metadata_pages && !disjoint.metadata_bytes && + !bytes.image_pages && !bytes.image_bytes && !bytes.gpu_image_bytes && + !bytes.non_sampled_pages, + "metadata page candidates were not separated from exact byte overlap"); Require("QueryRegionAggregation", "clear", texture_cache.ClearMeta(base), "metadata clear setup failed"); @@ -11339,13 +11454,14 @@ void CheckQueryRegionAggregation() { Require("QueryRegionAggregation", "GPU ownership", gpu_bytes.metadata_pages && gpu_bytes.metadata_bytes && gpu_bytes.gpu_metadata_bytes && gpu_page_only.metadata_pages && - !gpu_page_only.metadata_bytes && !gpu_page_only.gpu_metadata_bytes, + !gpu_page_only.metadata_bytes && + !gpu_page_only.gpu_metadata_bytes, "GPU metadata ownership escaped its exact registered byte range"); texture_cache.UnmapMemory(base, allocation_size); page_manager.OnGpuUnmap(base, allocation_size); - Require("QueryRegionAggregation", "free", VirtualFree(memory, 0, MEM_RELEASE) != 0, - "VirtualFree failed"); + Require("QueryRegionAggregation", "free", + VirtualFree(memory, 0, MEM_RELEASE) != 0, "VirtualFree failed"); std::printf("[host] %-32s ok\n", "QueryRegionAggregation"); } @@ -11354,9 +11470,9 @@ void CheckGpuMetadataReuse() { constexpr uint64_t allocation_size = 0x20000; constexpr uint64_t metadata_size = 0x18000; constexpr uint32_t layers = 3; - auto *memory = static_cast(VirtualAlloc( - reinterpret_cast(base), allocation_size, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto *memory = static_cast( + VirtualAlloc(reinterpret_cast(base), allocation_size, + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); Require("GpuMetadataReuse", "allocation", memory == reinterpret_cast(base), "fixed VirtualAlloc failed"); @@ -11378,7 +11494,8 @@ void CheckGpuMetadataReuse() { Require("GpuMetadataReuse", "discard", !full_image_transition && !texture_cache.IsMeta(base) && !texture_cache.QueryRegion(base, allocation_size).metadata_bytes, - "metadata-only overwrite retained identity or claimed an image transition"); + "metadata-only overwrite retained identity or claimed an image " + "transition"); texture_cache.RegisterMeta(base, metadata_size, layers); Require("GpuMetadataReuse", "re-register", texture_cache.IsMetaRange(base, metadata_size) && @@ -11397,7 +11514,8 @@ void CheckGpuMetadataReuse() { texture_cache.InvalidateMemoryFromGPU(base + 0x1000, 0x1000); Require("GpuMetadataReuse", "partial discard", !partial_image_transition && !texture_cache.IsMeta(base), - "partial metadata overwrite retained identity or claimed an image transition"); + "partial metadata overwrite retained identity or claimed an image " + "transition"); texture_cache.UnmapMemory(base, allocation_size); page_manager.OnGpuUnmap(base, allocation_size); @@ -11413,17 +11531,19 @@ void CheckMetadataReuseDescriptors() { Require("MetadataReuseDescriptor", "host", GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, "GetModuleFileName failed"); - for (const char *kind : {"field1-reserved", "field2-low-reserved", - "field2-high-reserved", "unsupported-format", "uint-format"}) { - std::string command = std::string("\"") + path + - "\" --metadata-descriptor-death " + kind; + for (const char *kind : + {"field1-reserved", "field2-low-reserved", "field2-high-reserved", + "unsupported-format", "uint-format"}) { + std::string command = + std::string("\"") + path + "\" --metadata-descriptor-death " + kind; std::vector mutable_command(command.begin(), command.end()); mutable_command.push_back('\0'); STARTUPINFOA startup{sizeof(startup)}; PROCESS_INFORMATION process{}; Require("MetadataReuseDescriptor", "host", - CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, FALSE, - CREATE_NO_WINDOW, nullptr, nullptr, &startup, &process) != 0, + CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, + FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &startup, + &process) != 0, "CreateProcess failed"); Require("MetadataReuseDescriptor", "host", WaitForSingleObject(process.hProcess, 10000) == WAIT_OBJECT_0, @@ -11462,8 +11582,9 @@ void CheckBufferImageWrites() { Case{"sampled exact", sampled, sampled_size, sampled, sampled_size, BufferImageBinding::Texture, false, false, BufferImageWrite::InvalidateTexture}, - Case{"sampled contained prefix", sampled, sampled_size - TRACKER_PAGE_SIZE, - sampled, sampled_size, BufferImageBinding::Texture, false, false, + Case{"sampled contained prefix", sampled, + sampled_size - TRACKER_PAGE_SIZE, sampled, sampled_size, + BufferImageBinding::Texture, false, false, BufferImageWrite::InvalidateTexture}, Case{"sampled contained raw", sampled + 0x23030, 0xfa0, sampled, sampled_size, BufferImageBinding::Texture, false, false, @@ -11474,11 +11595,11 @@ void CheckBufferImageWrites() { Case{"sampled suffix crossing", sampled + sampled_size - 0x10, 0x20, sampled, sampled_size, BufferImageBinding::Texture, false, false, BufferImageWrite::Unsupported}, - Case{"sampled contained GPU-owned", sampled + 0x23030, 0xfa0, - sampled, sampled_size, BufferImageBinding::Texture, true, false, + Case{"sampled contained GPU-owned", sampled + 0x23030, 0xfa0, sampled, + sampled_size, BufferImageBinding::Texture, true, false, BufferImageWrite::Unsupported}, - Case{"sampled contained unsupported", sampled + 0x23030, 0xfa0, - sampled, sampled_size, BufferImageBinding::Unsupported, false, false, + Case{"sampled contained unsupported", sampled + 0x23030, 0xfa0, sampled, + sampled_size, BufferImageBinding::Unsupported, false, false, BufferImageWrite::Unsupported}, Case{"sampled unaligned", sampled + 1, sampled_size, sampled + 1, sampled_size, BufferImageBinding::Texture, false, false, @@ -11530,22 +11651,24 @@ void CheckBufferImageWrites() { Case{"target unaligned", target + 0x100, target_size, target + 0x100, target_size, BufferImageBinding::RenderTarget, true, true, BufferImageWrite::Unsupported}, - Case{"storage mip page", storage_address + 0x10000, 0x10000, storage_address, storage_size, - BufferImageBinding::StorageTexture, true, true, - BufferImageWrite::SynchronizeStorageTexture}, - Case{"storage unformatted", storage_address + 0x10000, 0x10000, storage_address, storage_size, - BufferImageBinding::StorageTexture, true, false, - BufferImageWrite::Unsupported}, - Case{"storage unaligned", storage_address + 0x100, 0x10000, storage_address, storage_size, - BufferImageBinding::StorageTexture, true, true, - BufferImageWrite::Unsupported}, + Case{"storage mip page", storage_address + 0x10000, 0x10000, + storage_address, storage_size, BufferImageBinding::StorageTexture, + true, true, BufferImageWrite::SynchronizeStorageTexture}, + Case{"storage unformatted", storage_address + 0x10000, 0x10000, + storage_address, storage_size, BufferImageBinding::StorageTexture, + true, false, BufferImageWrite::Unsupported}, + Case{"storage unaligned", storage_address + 0x100, 0x10000, + storage_address, storage_size, BufferImageBinding::StorageTexture, + true, true, BufferImageWrite::Unsupported}, Case{"depth exact", 0x4a5c80000ull, 0x10000, 0x4a5c80000ull, 0x10000, BufferImageBinding::DepthTarget, true, true, BufferImageWrite::SynchronizeDepthTarget}, Case{"depth partial", 0x4a5c80000ull, 0x8000, 0x4a5c80000ull, 0x10000, - BufferImageBinding::DepthTarget, true, true, BufferImageWrite::Unsupported}, - Case{"depth unformatted", 0x4a5c80000ull, 0x10000, 0x4a5c80000ull, 0x10000, - BufferImageBinding::DepthTarget, true, false, BufferImageWrite::Unsupported}, + BufferImageBinding::DepthTarget, true, true, + BufferImageWrite::Unsupported}, + Case{"depth unformatted", 0x4a5c80000ull, 0x10000, 0x4a5c80000ull, + 0x10000, BufferImageBinding::DepthTarget, true, false, + BufferImageWrite::Unsupported}, }; for (const auto &test : cases) { const auto actual = ClassifyBufferImageWrite( @@ -11555,27 +11678,32 @@ void CheckBufferImageWrites() { "buffer/image write classification mismatch"); } Require("BufferImageWrite", "storage containing overwrite", - ClassifyBufferImageWrite(storage_address - 0x80000, 0x100000, storage_address, - storage_size, BufferImageBinding::StorageTexture, false, true, - true) == BufferImageWrite::InvalidateStorageTexture, - "formatted containing overwrite did not retain refreshable storage ownership"); + ClassifyBufferImageWrite( + storage_address - 0x80000, 0x100000, storage_address, + storage_size, BufferImageBinding::StorageTexture, false, true, + true) == BufferImageWrite::InvalidateStorageTexture, + "formatted containing overwrite did not retain refreshable storage " + "ownership"); Require("BufferImageWrite", "storage containing overwrite GPU-owned", - ClassifyBufferImageWrite(storage_address - 0x80000, 0x100000, storage_address, - storage_size, BufferImageBinding::StorageTexture, true, true, - false) == BufferImageWrite::Unsupported, + ClassifyBufferImageWrite( + storage_address - 0x80000, 0x100000, storage_address, + storage_size, BufferImageBinding::StorageTexture, true, true, + false) == BufferImageWrite::Unsupported, "containing overwrite bypassed GPU-owned storage synchronization"); Require("BufferImageWrite", "depth repeated buffer overwrite", - ClassifyBufferImageWrite(0x4a5cd0000ull, 0x10000, 0x4a5cd0000ull, 0x10000, - BufferImageBinding::DepthTarget, false, true, true) == + ClassifyBufferImageWrite(0x4a5cd0000ull, 0x10000, 0x4a5cd0000ull, + 0x10000, BufferImageBinding::DepthTarget, + false, true, true) == BufferImageWrite::InvalidateDepthTarget, "buffer-owned exact depth overwrite was rejected"); - // PPSA01530's packed mip0 page is first synchronized out of a GPU-owned storage image, - // written through a persistent formatted buffer, and then rebound as the same storage image. - const auto partial_refresh = ClassifyStorageBufferRebind( - true, false, true, false, false, true); - const auto refreshed_reuse = ClassifyStorageBufferRebind( - true, true, false, true, false, true); + // PPSA01530's packed mip0 page is first synchronized out of a GPU-owned + // storage image, written through a persistent formatted buffer, and then + // rebound as the same storage image. + const auto partial_refresh = + ClassifyStorageBufferRebind(true, false, true, false, false, true); + const auto refreshed_reuse = + ClassifyStorageBufferRebind(true, true, false, true, false, true); Require("BufferImageWrite", "storage partial lifecycle", partial_refresh == StorageBufferRebind::RefreshFromBacking && refreshed_reuse == StorageBufferRebind::Reuse, @@ -11588,10 +11716,11 @@ void CheckBufferImageWrites() { ClassifyStorageBufferRebind(true, false, true, true, false, true) == StorageBufferRebind::Unsupported, "contradictory storage tracker ownership was admitted"); - Require("BufferImageWrite", "storage mip-one cache miss", - SelectImageBackingBaseLevel(true, 1) == 0 && - SelectImageBackingBaseLevel(false, 1) == 1, - "storage backing creation remained dependent on first-bound view mip"); + Require( + "BufferImageWrite", "storage mip-one cache miss", + SelectImageBackingBaseLevel(true, 1) == 0 && + SelectImageBackingBaseLevel(false, 1) == 1, + "storage backing creation remained dependent on first-bound view mip"); Require("BufferImageWrite", "dynamic one-layer array view", !NeedsStaticSampledArrayView(true, true) && NeedsStaticSampledArrayView(true, false) && @@ -11606,28 +11735,32 @@ void CheckBufferImageWrites() { DepthTargetInfo cleared_depth = old_depth; cleared_depth.width = cleared_depth.height = 64; cleared_depth.depth_load_clear = true; - Require("BufferImageWrite", "cleared depth reinterpretation", - ClassifyDepthTargetOverlap(old_depth, true, false, true, cleared_depth) == - DepthOverlap::DiscardTarget, - "exact cleared depth allocation could not discard its old native shape"); + Require( + "BufferImageWrite", "cleared depth reinterpretation", + ClassifyDepthTargetOverlap(old_depth, true, false, true, cleared_depth) == + DepthOverlap::DiscardTarget, + "exact cleared depth allocation could not discard its old native shape"); cleared_depth.depth_load_clear = false; - Require("BufferImageWrite", "loaded depth reinterpretation", - ClassifyDepthTargetOverlap(old_depth, true, false, true, cleared_depth) == - DepthOverlap::Unsupported, - "loaded depth reinterpretation discarded live native contents"); + Require( + "BufferImageWrite", "loaded depth reinterpretation", + ClassifyDepthTargetOverlap(old_depth, true, false, true, cleared_depth) == + DepthOverlap::Unsupported, + "loaded depth reinterpretation discarded live native contents"); RenderTargetInfo color_alias{}; color_alias.address = old_depth.address; color_alias.size = old_depth.size; - Require("BufferImageWrite", "buffer-owned depth to color", - CanRetireBufferOwnedDepthForRenderTarget(old_depth, false, true, true, true, - color_alias) && - !CanRetireBufferOwnedDepthForRenderTarget(old_depth, true, false, true, true, - color_alias), - "depth-to-color recreation did not require coherent buffer ownership"); - Require("BufferImageWrite", "page-neighbor depth to color", - !CanRetireBufferOwnedDepthForRenderTarget(old_depth, false, true, true, false, - color_alias), - "same-page byte-disjoint buffer authorized depth-to-color recreation"); + Require( + "BufferImageWrite", "buffer-owned depth to color", + CanRetireBufferOwnedDepthForRenderTarget(old_depth, false, true, true, + true, color_alias) && + !CanRetireBufferOwnedDepthForRenderTarget(old_depth, true, false, + true, true, color_alias), + "depth-to-color recreation did not require coherent buffer ownership"); + Require( + "BufferImageWrite", "page-neighbor depth to color", + !CanRetireBufferOwnedDepthForRenderTarget(old_depth, false, true, true, + false, color_alias), + "same-page byte-disjoint buffer authorized depth-to-color recreation"); TileSizeAlign storage{}; Require("BufferImageWrite", "target layout", @@ -11649,15 +11782,15 @@ void CheckImageOverlapResolution() { Require( "ImageOverlapResolution", "existing video-out formats", DecodeVideoOutPixelFormat(0x8000000022000000ull, &video_format) && - video_format.format == VK_FORMAT_R8G8B8A8_SRGB && + video_format.format == vk::Format::eR8G8B8A8Srgb && video_format.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb) && DecodeVideoOutPixelFormat(0x8000000000000000ull, &video_format) && - video_format.format == VK_FORMAT_B8G8R8A8_SRGB && + video_format.format == vk::Format::eB8G8R8A8Srgb && video_format.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8Srgb) && DecodeVideoOutPixelFormat(0x8100000022000000ull, &video_format) && - video_format.format == VK_FORMAT_A2B10G10R10_UNORM_PACK32 && + video_format.format == vk::Format::eA2B10G10R10UnormPack32 && video_format.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k10_10_10_2UNorm), "pre-existing PS5 video-out format mappings changed during decoder " @@ -11665,7 +11798,7 @@ void CheckImageOverlapResolution() { Require( "ImageOverlapResolution", "B10G10R10A2 video-out format", DecodeVideoOutPixelFormat(0x8100000000000000ull, &video_format) && - video_format.format == VK_FORMAT_A2R10G10B10_UNORM_PACK32 && + video_format.format == vk::Format::eA2R10G10B10UnormPack32 && video_format.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k10_10_10_2UNorm), "PS5 B10G10R10A2 sRGB video-out format did not preserve alternate " @@ -11673,7 +11806,7 @@ void CheckImageOverlapResolution() { Require( "ImageOverlapResolution", "RGBA16 float video-out formats", DecodeVideoOutPixelFormat(0xc001000622000000ull, &video_format) && - video_format.format == VK_FORMAT_R16G16B16A16_SFLOAT && + video_format.format == vk::Format::eR16G16B16A16Sfloat && video_format.guest_format == Prospero::GpuEnumValue( Prospero::BufferFormat::k16_16_16_16Float) && @@ -11739,35 +11872,30 @@ void CheckImageOverlapResolution() { TileSizeOffset mip_levels[16]{}; TilePaddedSize mip_padded[16]{}; - Require("ImageOverlapResolution", "PPSA09076 mip-chain layout", - TileGetRenderTargetMipLayout(960, 540, 1024, 8, 10, - &render_target_layout, mip_levels, - mip_padded) && - render_target_layout.size == 0x650000 && - render_target_layout.align == 0x10000 && - mip_levels[0].offset == 0x1d0000 && - mip_levels[0].size == 0x480000 && - mip_levels[1].offset == 0x90000 && - mip_levels[1].size == 0x140000 && - mip_padded[1].width == 512 && mip_padded[1].height == 320, - "native render-target mip allocation or subresource geometry regressed"); - Require("ImageOverlapResolution", "render-target mip-chain rejection", - !TileGetRenderTargetMipLayout(960, 540, 960, 8, 10, - &render_target_layout, nullptr, nullptr) && - !TileGetRenderTargetMipLayout(960, 540, 1024, 3, 10, - &render_target_layout, nullptr, - nullptr) && - !TileGetRenderTargetMipLayout(960, 540, 1024, 8, 0, - &render_target_layout, nullptr, - nullptr) && - !TileGetRenderTargetMipLayout(960, 540, 1024, 8, 17, - &render_target_layout, nullptr, - nullptr) && - !TileGetRenderTargetMipLayout( - 4, 4, TileGetRenderTargetPitch(4, 4), 4, 4, - &render_target_layout, nullptr, - nullptr), - "invalid render-target mip topology was admitted"); + Require( + "ImageOverlapResolution", "PPSA09076 mip-chain layout", + TileGetRenderTargetMipLayout(960, 540, 1024, 8, 10, &render_target_layout, + mip_levels, mip_padded) && + render_target_layout.size == 0x650000 && + render_target_layout.align == 0x10000 && + mip_levels[0].offset == 0x1d0000 && mip_levels[0].size == 0x480000 && + mip_levels[1].offset == 0x90000 && mip_levels[1].size == 0x140000 && + mip_padded[1].width == 512 && mip_padded[1].height == 320, + "native render-target mip allocation or subresource geometry regressed"); + Require( + "ImageOverlapResolution", "render-target mip-chain rejection", + !TileGetRenderTargetMipLayout(960, 540, 960, 8, 10, &render_target_layout, + nullptr, nullptr) && + !TileGetRenderTargetMipLayout( + 960, 540, 1024, 3, 10, &render_target_layout, nullptr, nullptr) && + !TileGetRenderTargetMipLayout( + 960, 540, 1024, 8, 0, &render_target_layout, nullptr, nullptr) && + !TileGetRenderTargetMipLayout( + 960, 540, 1024, 8, 17, &render_target_layout, nullptr, nullptr) && + !TileGetRenderTargetMipLayout(4, 4, TileGetRenderTargetPitch(4, 4), 4, + 4, &render_target_layout, nullptr, + nullptr), + "invalid render-target mip topology was admitted"); ImageInfo sampled{}; sampled.address = 0x200000; @@ -11792,17 +11920,18 @@ void CheckImageOverlapResolution() { Image dirty_image; dirty_image = dirty_info; dirty_image.InvalidateCpuWrite(0x500300, 0x10); - Require("ImageOverlapResolution", "sampled edge-page maybe dirty", - dirty_image.IsCpuDirty() && dirty_image.IsMaybeCpuDirty() && - !dirty_image.IsDefinitelyCpuDirty(), - "byte-disjoint write sharing a tracker page was not kept maybe-dirty"); + Require( + "ImageOverlapResolution", "sampled edge-page maybe dirty", + dirty_image.IsCpuDirty() && dirty_image.IsMaybeCpuDirty() && + !dirty_image.IsDefinitelyCpuDirty(), + "byte-disjoint write sharing a tracker page was not kept maybe-dirty"); Require("ImageOverlapResolution", "sampled edge hash required", dirty_image.NeedsMaybeCpuHash(), "collapsed edge tracking did not request a baseline hash"); dirty_image.SetMaybeCpuHash(0x1234); Require("ImageOverlapResolution", "sampled unchanged edge hash", - !dirty_image.ResolveMaybeCpuHash(0x1234) && !dirty_image.IsCpuDirty() && - dirty_image.IsCpuTrackingComplete(), + !dirty_image.ResolveMaybeCpuHash(0x1234) && + !dirty_image.IsCpuDirty() && dirty_image.IsCpuTrackingComplete(), "unchanged edge bytes forced an image upload"); dirty_image.InvalidateCpuWrite(0x500300, 0x10); dirty_image.SetMaybeCpuHash(0x1234); @@ -11827,7 +11956,8 @@ void CheckImageOverlapResolution() { "a single disjoint edge fault prematurely dirtied a two-page image"); two_page_image.InvalidateCpuWrite(0x601a00, 1); Require("ImageOverlapResolution", "sampled head-tail collapse", - two_page_image.IsMaybeCpuDirty() && two_page_image.NeedsMaybeCpuHash(), + two_page_image.IsMaybeCpuDirty() && + two_page_image.NeedsMaybeCpuHash(), "both disjoint edge faults did not collapse logical tracking"); constexpr uint64_t storage_subrange = 0x649b0100; constexpr uint64_t storage_subrange_size = 0x800; @@ -11842,19 +11972,20 @@ void CheckImageOverlapResolution() { Require("ImageOverlapResolution", "storage preserves dirty sampled backing", ClassifyStorageImageOverlap(storage_subrange, storage_subrange_size, sampled_backing, sampled_backing_size, - true, true, true, false, true) == - StorageImageOverlap::Unsupported, + true, true, true, false, + true) == StorageImageOverlap::Unsupported, "GPU-owned sampled subrange was admitted as storage backing"); ImageInfo page_left = sampled; page_left.size = TRACKER_PAGE_SIZE / 2; ImageInfo same_page = page_left; same_page.address += page_left.size; - Require("ImageOverlapResolution", "sampled shared page", - !ImageRangeOverlaps(same_page.address, same_page.size, - page_left.address, page_left.size) && - ClassifySampledOverlap(same_page, page_left, false, true) == - SampledOverlap::ReadOnlyAlias, - "byte-disjoint sampled images sharing a tracker page were not aliased"); + Require( + "ImageOverlapResolution", "sampled shared page", + !ImageRangeOverlaps(same_page.address, same_page.size, page_left.address, + page_left.size) && + ClassifySampledOverlap(same_page, page_left, false, true) == + SampledOverlap::ReadOnlyAlias, + "byte-disjoint sampled images sharing a tracker page were not aliased"); ImageInfo separate_page = same_page; separate_page.address = page_left.address + TRACKER_PAGE_SIZE; Require("ImageOverlapResolution", "sampled separate page", @@ -11863,13 +11994,15 @@ void CheckImageOverlapResolution() { "sampled images on separate pages were aliased"); constexpr uint64_t edge_target_address = 0x108ad00100ull; constexpr uint64_t edge_target_size = 0x1fa400; - constexpr uint64_t edge_fault_address = edge_target_address + edge_target_size + 0x1b8; - Require("ImageOverlapResolution", "GPU target shared edge page", - !ImageRangeOverlaps(edge_fault_address, 1, edge_target_address, - edge_target_size) && - ImagePageRangesOverlap(edge_fault_address, 1, - edge_target_address, edge_target_size), - "byte-disjoint CPU access lost the GPU owner of its shared tracker page"); + constexpr uint64_t edge_fault_address = + edge_target_address + edge_target_size + 0x1b8; + Require( + "ImageOverlapResolution", "GPU target shared edge page", + !ImageRangeOverlaps(edge_fault_address, 1, edge_target_address, + edge_target_size) && + ImagePageRangesOverlap(edge_fault_address, 1, edge_target_address, + edge_target_size), + "byte-disjoint CPU access lost the GPU owner of its shared tracker page"); Image sampled_image{}; sampled_image = page_left; Image same_page_image{}; @@ -11890,37 +12023,38 @@ void CheckImageOverlapResolution() { constexpr uint64_t texture_size = 0x4000; Require("ImageOverlapResolution", "host fill sampled image", ClassifyHostWriteOverlap(fill_address, fill_size, texture_address, - texture_size, true, false, false) == - HostWriteOverlap::InvalidateImage, + texture_size, true, false, + false) == HostWriteOverlap::InvalidateImage, "host-backed fill did not invalidate its CPU-current sampled image"); Require("ImageOverlapResolution", "host fill GPU owner", ClassifyHostWriteOverlap(fill_address, fill_size, texture_address, - texture_size, true, true, false) == - HostWriteOverlap::Unsupported, + texture_size, true, true, + false) == HostWriteOverlap::Unsupported, "host-backed fill was admitted over a GPU-owned sampled image"); Require("ImageOverlapResolution", "host fill clean render target", ClassifyHostWriteOverlap(fill_address, fill_size, texture_address, - texture_size, true, false, false) == - HostWriteOverlap::InvalidateImage, + texture_size, true, false, + false) == HostWriteOverlap::InvalidateImage, "host-backed fill did not invalidate its clean render target"); Require("ImageOverlapResolution", "host fill non-refreshable image", ClassifyHostWriteOverlap(fill_address, fill_size, texture_address, - texture_size, false, false, false) == - HostWriteOverlap::Unsupported, + texture_size, false, false, + false) == HostWriteOverlap::Unsupported, "host-backed fill was admitted over a non-refreshable image"); constexpr uint64_t dma_address = 0x10f562000ull; constexpr uint64_t dma_size = 0x40000; constexpr uint64_t target_address = 0x10f570000ull; constexpr uint64_t target_size = 0x20000; - Require("ImageOverlapResolution", "host copy clean render target", - ClassifyHostWriteOverlap(dma_address, dma_size, target_address, - target_size, true, false, false) == - HostWriteOverlap::InvalidateImage, - "host-backed copy did not invalidate the covered clean render target"); + Require( + "ImageOverlapResolution", "host copy clean render target", + ClassifyHostWriteOverlap(dma_address, dma_size, target_address, + target_size, true, false, + false) == HostWriteOverlap::InvalidateImage, + "host-backed copy did not invalidate the covered clean render target"); Require("ImageOverlapResolution", "host copy GPU render target", ClassifyHostWriteOverlap(dma_address, dma_size, target_address, - target_size, true, true, false) == - HostWriteOverlap::Unsupported, + target_size, true, true, + false) == HostWriteOverlap::Unsupported, "host-backed copy was admitted over a GPU-owned render target"); Require("ImageOverlapResolution", "host copy partial clean render target", ClassifyHostWriteOverlap(target_address + 0x1000, 0x1000, @@ -11931,17 +12065,17 @@ void CheckImageOverlapResolution() { ClassifyHostWriteOverlap(target_address + target_size - 1, 1, target_address, target_size - 1, true, false, false) == HostWriteOverlap::InvalidateImage, - "shared-page host copy did not conservatively invalidate the clean target"); + "shared-page host copy did not conservatively invalidate the clean " + "target"); Require("ImageOverlapResolution", "host fill metadata", ClassifyHostWriteOverlap(fill_address, fill_size, texture_address, - texture_size, true, false, true) == - HostWriteOverlap::Unsupported, + texture_size, true, false, + true) == HostWriteOverlap::Unsupported, "host-backed sampled-image fill was admitted over metadata pages"); Require("ImageOverlapResolution", "host fill disjoint page", ClassifyHostWriteOverlap(texture_address + texture_size, fill_size, texture_address, texture_size, true, false, - true) == - HostWriteOverlap::None, + true) == HostWriteOverlap::None, "host-backed fill aliased a sampled image on another page"); constexpr uint64_t video_metadata = 0x1020c10000ull; @@ -11953,71 +12087,74 @@ void CheckImageOverlapResolution() { ClassifyVideoOutCompression(true, video_metadata, 0x208u, 0) == VideoOutCompression::Dcc256_64_64, "Prospero video-out DCC 256/64/64 mode was rejected"); - Require("ImageOverlapResolution", "video-out compression guards", - ClassifyVideoOutCompression(false, 0, 0, 0) == - VideoOutCompression::Uncompressed && - ClassifyVideoOutCompression(true, 0, 0x208u, 0) == - VideoOutCompression::Unsupported && - ClassifyVideoOutCompression(true, video_metadata + 1, 0x208u, 0) == - VideoOutCompression::Unsupported && - ClassifyVideoOutCompression(true, video_metadata, 0x204u, 0) == - VideoOutCompression::Unsupported && - ClassifyVideoOutCompression(true, video_metadata, 0x208u, 1) == - VideoOutCompression::Unsupported && - ClassifyVideoOutCompression(false, video_metadata, 0, 0) == - VideoOutCompression::Unsupported, - "unsupported video-out compression state was admitted"); - Require("ImageOverlapResolution", "compressed video-out native ownership", - CanUseVideoOutNativeWithoutUpload( - VideoOutCompression::Dcc256_64_64, true, false, false) && - CanUseVideoOutNativeWithoutUpload( - VideoOutCompression::Dcc256_64_64, false, true, false) && - !CanUseVideoOutNativeWithoutUpload( - VideoOutCompression::Dcc256_64_64, false, false, false) && - CanUseVideoOutNativeWithoutUpload( - VideoOutCompression::Dcc256_256_0, true, false, false) && - !CanUseVideoOutNativeWithoutUpload( - VideoOutCompression::Dcc256_256_0, false, false, true) && - !CanUseVideoOutNativeWithoutUpload( - VideoOutCompression::Dcc256_64_64, true, false, true) && - !CanUseVideoOutNativeWithoutUpload( - VideoOutCompression::Uncompressed, true, true, false), - "compressed video-out upload/read ownership boundary regressed"); + Require( + "ImageOverlapResolution", "video-out compression guards", + ClassifyVideoOutCompression(false, 0, 0, 0) == + VideoOutCompression::Uncompressed && + ClassifyVideoOutCompression(true, 0, 0x208u, 0) == + VideoOutCompression::Unsupported && + ClassifyVideoOutCompression(true, video_metadata + 1, 0x208u, 0) == + VideoOutCompression::Unsupported && + ClassifyVideoOutCompression(true, video_metadata, 0x204u, 0) == + VideoOutCompression::Unsupported && + ClassifyVideoOutCompression(true, video_metadata, 0x208u, 1) == + VideoOutCompression::Unsupported && + ClassifyVideoOutCompression(false, video_metadata, 0, 0) == + VideoOutCompression::Unsupported, + "unsupported video-out compression state was admitted"); + Require( + "ImageOverlapResolution", "compressed video-out native ownership", + CanUseVideoOutNativeWithoutUpload(VideoOutCompression::Dcc256_64_64, true, + false, false) && + CanUseVideoOutNativeWithoutUpload(VideoOutCompression::Dcc256_64_64, + false, true, false) && + !CanUseVideoOutNativeWithoutUpload(VideoOutCompression::Dcc256_64_64, + false, false, false) && + CanUseVideoOutNativeWithoutUpload(VideoOutCompression::Dcc256_256_0, + true, false, false) && + !CanUseVideoOutNativeWithoutUpload(VideoOutCompression::Dcc256_256_0, + false, false, true) && + !CanUseVideoOutNativeWithoutUpload(VideoOutCompression::Dcc256_64_64, + true, false, true) && + !CanUseVideoOutNativeWithoutUpload(VideoOutCompression::Uncompressed, + true, true, false), + "compressed video-out upload/read ownership boundary regressed"); - VkClearColorValue clear{}; - Require("ImageOverlapResolution", "RGBA8 compute clear decode", - DecodePackedColorClear(VK_FORMAT_R8G8B8A8_UNORM, 0x80402010u, - &clear) && - std::abs(clear.float32[0] - 16.0f / 255.0f) < 0.000001f && - std::abs(clear.float32[1] - 32.0f / 255.0f) < 0.000001f && - std::abs(clear.float32[2] - 64.0f / 255.0f) < 0.000001f && - std::abs(clear.float32[3] - 128.0f / 255.0f) < 0.000001f, - "packed RGBA8 clear did not preserve component values"); - Require("ImageOverlapResolution", "BGRA8 compute clear decode", - DecodePackedColorClear(VK_FORMAT_B8G8R8A8_UNORM, 0x80402010u, - &clear) && - std::abs(clear.float32[0] - 64.0f / 255.0f) < 0.000001f && - std::abs(clear.float32[1] - 32.0f / 255.0f) < 0.000001f && - std::abs(clear.float32[2] - 16.0f / 255.0f) < 0.000001f, - "packed BGRA8 clear did not account for memory channel order"); - const uint32_t rgb10_clear = 1023u | (512u << 10u) | (1u << 20u) | (3u << 30u); + vk::ClearColorValue clear{}; + Require( + "ImageOverlapResolution", "RGBA8 compute clear decode", + DecodePackedColorClear(vk::Format::eR8G8B8A8Unorm, 0x80402010u, &clear) && + std::abs(clear.float32[0] - 16.0f / 255.0f) < 0.000001f && + std::abs(clear.float32[1] - 32.0f / 255.0f) < 0.000001f && + std::abs(clear.float32[2] - 64.0f / 255.0f) < 0.000001f && + std::abs(clear.float32[3] - 128.0f / 255.0f) < 0.000001f, + "packed RGBA8 clear did not preserve component values"); + Require( + "ImageOverlapResolution", "BGRA8 compute clear decode", + DecodePackedColorClear(vk::Format::eB8G8R8A8Unorm, 0x80402010u, &clear) && + std::abs(clear.float32[0] - 64.0f / 255.0f) < 0.000001f && + std::abs(clear.float32[1] - 32.0f / 255.0f) < 0.000001f && + std::abs(clear.float32[2] - 16.0f / 255.0f) < 0.000001f, + "packed BGRA8 clear did not account for memory channel order"); + const uint32_t rgb10_clear = + 1023u | (512u << 10u) | (1u << 20u) | (3u << 30u); Require("ImageOverlapResolution", "RGB10 compute clear decode", - DecodePackedColorClear(VK_FORMAT_A2B10G10R10_UNORM_PACK32, + DecodePackedColorClear(vk::Format::eA2B10G10R10UnormPack32, rgb10_clear, &clear) && clear.float32[0] == 1.0f && std::abs(clear.float32[1] - 512.0f / 1023.0f) < 0.000001f && std::abs(clear.float32[2] - 1.0f / 1023.0f) < 0.000001f && clear.float32[3] == 1.0f, "packed RGB10 clear did not preserve component values"); - Require("ImageOverlapResolution", "sRGB compute clear decode", - DecodePackedColorClear(VK_FORMAT_R8G8B8A8_SRGB, 0xff808080u, - &clear) && - std::abs(clear.float32[0] - 0.215861f) < 0.00001f && - std::abs(clear.float32[1] - 0.215861f) < 0.00001f && - std::abs(clear.float32[2] - 0.215861f) < 0.00001f && - clear.float32[3] == 1.0f && - !DecodePackedColorClear(VK_FORMAT_R16G16_UNORM, 0, &clear), - "sRGB clear decode or unsupported-format guard regressed"); + Require( + "ImageOverlapResolution", "sRGB compute clear decode", + DecodePackedColorClear(vk::Format::eR8G8B8A8Srgb, 0xff808080u, &clear) && + std::abs(clear.float32[0] - 0.215861f) < 0.00001f && + std::abs(clear.float32[1] - 0.215861f) < 0.00001f && + std::abs(clear.float32[2] - 0.215861f) < 0.00001f && + clear.float32[3] == 1.0f && + !DecodePackedColorClear(vk::Format::eR16G16Unorm, 0, &clear), + "sRGB clear decode or unsupported-format guard regressed"); uint8_t stencil_clear = 0; Require("ImageOverlapResolution", "stencil compute clear decode", DecodePackedStencilClear(0x7f7f7f7fu, &stencil_clear) && @@ -12028,28 +12165,31 @@ void CheckImageOverlapResolution() { !DecodePackedStencilClear(0, nullptr), "packed stencil clear admitted non-uniform byte values"); float depth_clear = -1.0f; - Require("ImageOverlapResolution", "D32 compute clear decode", - DecodePackedDepthClear(VK_FORMAT_D32_SFLOAT, 0u, &depth_clear) && - depth_clear == 0.0f && - DecodePackedDepthClear(VK_FORMAT_D32_SFLOAT_S8_UINT, - 0x3f800000u, &depth_clear) && - depth_clear == 1.0f && - !DecodePackedDepthClear(VK_FORMAT_D16_UNORM, 0u, &depth_clear) && - !DecodePackedDepthClear(VK_FORMAT_D32_SFLOAT, 0xbf800000u, - &depth_clear) && - !DecodePackedDepthClear(VK_FORMAT_D32_SFLOAT, 0x40000000u, - &depth_clear) && - !DecodePackedDepthClear(VK_FORMAT_D32_SFLOAT, 0x7f800000u, - &depth_clear) && - !DecodePackedDepthClear(VK_FORMAT_D32_SFLOAT, 0u, nullptr), - "D32 compute clear decode admitted an unsupported format or value"); + Require( + "ImageOverlapResolution", "D32 compute clear decode", + DecodePackedDepthClear(vk::Format::eD32Sfloat, 0u, &depth_clear) && + depth_clear == 0.0f && + DecodePackedDepthClear(vk::Format::eD32SfloatS8Uint, 0x3f800000u, + &depth_clear) && + depth_clear == 1.0f && + !DecodePackedDepthClear(vk::Format::eD16Unorm, 0u, &depth_clear) && + !DecodePackedDepthClear(vk::Format::eD32Sfloat, 0xbf800000u, + &depth_clear) && + !DecodePackedDepthClear(vk::Format::eD32Sfloat, 0x40000000u, + &depth_clear) && + !DecodePackedDepthClear(vk::Format::eD32Sfloat, 0x7f800000u, + &depth_clear) && + !DecodePackedDepthClear(vk::Format::eD32Sfloat, 0u, nullptr), + "D32 compute clear decode admitted an unsupported format or value"); DepthTargetInfo native_clear_target{}; native_clear_target.address = 0x1158d80000ull; native_clear_target.size = 0x870000ull; - native_clear_target.format = VK_FORMAT_D32_SFLOAT; - native_clear_target.guest_format = Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float); + native_clear_target.format = vk::Format::eD32Sfloat; + native_clear_target.guest_format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float); native_clear_target.bytes_per_element = 4; - native_clear_target.tile_mode = Prospero::GpuEnumValue(Prospero::TileMode::kDepth); + native_clear_target.tile_mode = + Prospero::GpuEnumValue(Prospero::TileMode::kDepth); Require("ImageOverlapResolution", "native D32 buffer clear target", CanNativeClearDepthFromBuffer(native_clear_target, native_clear_target.address, @@ -12059,8 +12199,9 @@ void CheckImageOverlapResolution() { compressed_depth.htile_address = 0x1161480000ull; compressed_depth.htile_size = 0x10000ull; auto d16_depth = native_clear_target; - d16_depth.format = VK_FORMAT_D16_UNORM; - d16_depth.guest_format = Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm); + d16_depth.format = vk::Format::eD16Unorm; + d16_depth.guest_format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm); d16_depth.bytes_per_element = 2; Require("ImageOverlapResolution", "native depth buffer clear guards", !CanNativeClearDepthFromBuffer(native_clear_target, @@ -12079,10 +12220,11 @@ void CheckImageOverlapResolution() { RenderTargetInfo target{}; target.address = sampled.address; target.size = sampled.size; - Require("ImageOverlapResolution", "render target reuse", - ClassifyRenderTargetOverlap(sampled, false, true, target) == - RenderTargetOverlap::RetireSampled, - "exact CPU-owned sampled allocation was not retired for a render target"); + Require( + "ImageOverlapResolution", "render target reuse", + ClassifyRenderTargetOverlap(sampled, false, true, target) == + RenderTargetOverlap::RetireSampled, + "exact CPU-owned sampled allocation was not retired for a render target"); Require("ImageOverlapResolution", "render target GPU owner", ClassifyRenderTargetOverlap(sampled, true, true, target) == RenderTargetOverlap::Unsupported, @@ -12110,7 +12252,8 @@ void CheckImageOverlapResolution() { ImageInfo storage{}; storage.address = 0x112cd0000ull; storage.size = 0xff0000; - storage.format = Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float); + storage.format = + Prospero::GpuEnumValue(Prospero::BufferFormat::k16_16_16_16Float); storage.width = 1920; storage.height = 1080; storage.pitch = 1920; @@ -12119,37 +12262,39 @@ void CheckImageOverlapResolution() { RenderTargetInfo storage_target{}; storage_target.address = storage.address; storage_target.size = storage.size; - storage_target.format = VK_FORMAT_R16G16B16A16_SFLOAT; + storage_target.format = vk::Format::eR16G16B16A16Sfloat; storage_target.width = storage.width; storage_target.height = storage.height; storage_target.pitch = storage.pitch; storage_target.bytes_per_element = 8; storage_target.tile_mode = storage.tile; Require("ImageOverlapResolution", "storage render-target native transition", - ClassifyStorageRenderTargetOverlap(storage, storage_target.format, true, false, false, - true, storage_target) == - RenderTargetOverlap::PreserveStorage, - "exact GPU-owned RGBA16F storage image was not preserved for a render target"); + ClassifyStorageRenderTargetOverlap( + storage, storage_target.format, true, false, false, true, + storage_target) == RenderTargetOverlap::PreserveStorage, + "exact GPU-owned RGBA16F storage image was not preserved for a " + "render target"); auto mismatched_storage_target = storage_target; mismatched_storage_target.width--; Require("ImageOverlapResolution", "storage render-target guards", - ClassifyStorageRenderTargetOverlap(storage, storage_target.format, false, false, false, - true, storage_target) == - RenderTargetOverlap::Unsupported && - ClassifyStorageRenderTargetOverlap(storage, storage_target.format, true, true, false, - true, storage_target) == - RenderTargetOverlap::Unsupported && - ClassifyStorageRenderTargetOverlap(storage, storage_target.format, true, false, true, - true, storage_target) == - RenderTargetOverlap::Unsupported && - ClassifyStorageRenderTargetOverlap(storage, storage_target.format, true, false, false, - false, storage_target) == - RenderTargetOverlap::Unsupported && - ClassifyStorageRenderTargetOverlap(storage, VK_FORMAT_R32G32B32A32_SFLOAT, true, - false, false, true, storage_target) == - RenderTargetOverlap::Unsupported && - ClassifyStorageRenderTargetOverlap(storage, storage_target.format, true, false, false, - true, mismatched_storage_target) == + ClassifyStorageRenderTargetOverlap( + storage, storage_target.format, false, false, false, true, + storage_target) == RenderTargetOverlap::Unsupported && + ClassifyStorageRenderTargetOverlap( + storage, storage_target.format, true, true, false, true, + storage_target) == RenderTargetOverlap::Unsupported && + ClassifyStorageRenderTargetOverlap( + storage, storage_target.format, true, false, true, true, + storage_target) == RenderTargetOverlap::Unsupported && + ClassifyStorageRenderTargetOverlap( + storage, storage_target.format, true, false, false, false, + storage_target) == RenderTargetOverlap::Unsupported && + ClassifyStorageRenderTargetOverlap( + storage, vk::Format::eR32G32B32A32Sfloat, true, false, false, + true, storage_target) == RenderTargetOverlap::Unsupported && + ClassifyStorageRenderTargetOverlap(storage, storage_target.format, + true, false, false, true, + mismatched_storage_target) == RenderTargetOverlap::Unsupported, "unsupported storage-to-render-target transition was admitted"); Require("ImageOverlapResolution", "render target context", @@ -12161,13 +12306,15 @@ void CheckImageOverlapResolution() { Require("ImageOverlapResolution", "render target pool reuse", ClassifyRenderTargetOverlap(sampled, false, true, target) == RenderTargetOverlap::RetireSampled, - "page-contained CPU-owned sampled pool was not retired for a render target"); + "page-contained CPU-owned sampled pool was not retired for a render " + "target"); target.address = sampled.address + 0x6000; target.size = 0x4000; - Require("ImageOverlapResolution", "render target chance overlap", - ClassifyRenderTargetOverlap(sampled, false, true, target) == - RenderTargetOverlap::RetireSampled, - "page-isolated sampled pool overlap was not retired for a render target"); + Require( + "ImageOverlapResolution", "render target chance overlap", + ClassifyRenderTargetOverlap(sampled, false, true, target) == + RenderTargetOverlap::RetireSampled, + "page-isolated sampled pool overlap was not retired for a render target"); target.address++; Require("ImageOverlapResolution", "render target partial page", ClassifyRenderTargetOverlap(sampled, false, true, target) == @@ -12184,30 +12331,34 @@ void CheckImageOverlapResolution() { Require("ImageOverlapResolution", "render target shared page", ClassifyRenderTargetOverlap(page_left, false, true, target) == RenderTargetOverlap::None, - "byte-disjoint allocation sharing a tracker page was treated as an alias"); + "byte-disjoint allocation sharing a tracker page was treated as an " + "alias"); Require("ImageOverlapResolution", "sampled render-target shared page", ClassifySampledRenderTargetOverlap(page_left, target, false, true) == RenderTargetOverlap::None, - "reverse byte-disjoint tracker-page relationship was treated as an alias"); + "reverse byte-disjoint tracker-page relationship was treated as an " + "alias"); target.address = sampled.address + sampled.size; target.size = sampled.size; - Require("ImageOverlapResolution", "render target adjacent", - ClassifyRenderTargetOverlap(sampled, false, true, target) == - RenderTargetOverlap::None, - "adjacent sampled and render-target allocations were treated as aliases"); + Require( + "ImageOverlapResolution", "render target adjacent", + ClassifyRenderTargetOverlap(sampled, false, true, target) == + RenderTargetOverlap::None, + "adjacent sampled and render-target allocations were treated as aliases"); RenderTargetInfo old_target{}; old_target.address = 0x108d80000ull; old_target.size = 0x10000; - old_target.format = VK_FORMAT_R8G8B8A8_UNORM; + old_target.format = vk::Format::eR8G8B8A8Unorm; old_target.width = 48; old_target.height = 48; old_target.pitch = 128; old_target.bytes_per_element = 4; - old_target.tile_mode = Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget); + old_target.tile_mode = + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget); RenderTargetInfo replacement_target = old_target; replacement_target.size = 0x20000; - replacement_target.format = VK_FORMAT_R16G16B16A16_SFLOAT; + replacement_target.format = vk::Format::eR16G16B16A16Sfloat; replacement_target.width = 128; replacement_target.height = 128; replacement_target.bytes_per_element = 8; @@ -12221,7 +12372,8 @@ void CheckImageOverlapResolution() { replacement_target) == RenderTargetOverlap::Unsupported, "GPU-owned render-target pool allocation was retired"); - Require("ImageOverlapResolution", "render target allocation-pool buffer owner", + Require("ImageOverlapResolution", + "render target allocation-pool buffer owner", ClassifyRenderTargetOverlap(old_target, false, true, true, replacement_target) == RenderTargetOverlap::Unsupported, @@ -12234,29 +12386,36 @@ void CheckImageOverlapResolution() { auto offset_target = replacement_target; offset_target.address += TRACKER_PAGE_SIZE; Require("ImageOverlapResolution", "render target allocation-pool offset", - ClassifyRenderTargetOverlap(old_target, false, false, true, offset_target) == + ClassifyRenderTargetOverlap(old_target, false, false, true, + offset_target) == RenderTargetOverlap::Unsupported, - "offset render-target overlap was treated as allocation-pool replacement"); + "offset render-target overlap was treated as allocation-pool " + "replacement"); auto partial_page_target = replacement_target; partial_page_target.address++; - Require("ImageOverlapResolution", "render target allocation-pool partial page", + Require("ImageOverlapResolution", + "render target allocation-pool partial page", ClassifyRenderTargetOverlap(old_target, false, false, true, partial_page_target) == RenderTargetOverlap::Unsupported, - "partially shared tracker page was treated as allocation-pool replacement"); + "partially shared tracker page was treated as allocation-pool " + "replacement"); auto same_shape_target = old_target; - same_shape_target.format = VK_FORMAT_R8G8B8A8_SRGB; + same_shape_target.format = vk::Format::eR8G8B8A8Srgb; Require("ImageOverlapResolution", "render target RGBA8 sRGB reinterpretation", IsCompatibleRenderTargetView(old_target, same_shape_target), - "exact RGBA8 UNORM-to-sRGB target was not recognized as a compatible view"); + "exact RGBA8 UNORM-to-sRGB target was not recognized as a compatible " + "view"); Require("ImageOverlapResolution", "render target sRGB no retirement", - ClassifyRenderTargetOverlap(old_target, false, false, true, same_shape_target) == + ClassifyRenderTargetOverlap(old_target, false, false, true, + same_shape_target) == RenderTargetOverlap::Unsupported, "compatible render-target view fell through to target retirement"); auto incompatible_same_shape_target = same_shape_target; - incompatible_same_shape_target.format = VK_FORMAT_R8G8B8A8_UINT; + incompatible_same_shape_target.format = vk::Format::eR8G8B8A8Uint; Require("ImageOverlapResolution", "render target incompatible same shape", - !IsCompatibleRenderTargetView(old_target, incompatible_same_shape_target) && + !IsCompatibleRenderTargetView(old_target, + incompatible_same_shape_target) && ClassifyRenderTargetOverlap(old_target, false, false, true, incompatible_same_shape_target) == RenderTargetOverlap::Unsupported, @@ -12265,23 +12424,27 @@ void CheckImageOverlapResolution() { RenderTargetInfo ppsa02604_unorm_target{}; ppsa02604_unorm_target.address = 0x79c50000ull; ppsa02604_unorm_target.size = 0x870000; - ppsa02604_unorm_target.format = VK_FORMAT_B8G8R8A8_UNORM; + ppsa02604_unorm_target.format = vk::Format::eB8G8R8A8Unorm; ppsa02604_unorm_target.width = 1920; ppsa02604_unorm_target.height = 1080; ppsa02604_unorm_target.pitch = 1920; ppsa02604_unorm_target.bytes_per_element = 4; - ppsa02604_unorm_target.tile_mode = Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget); + ppsa02604_unorm_target.tile_mode = + Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget); auto ppsa02604_srgb_target = ppsa02604_unorm_target; - ppsa02604_srgb_target.format = VK_FORMAT_B8G8R8A8_SRGB; + ppsa02604_srgb_target.format = vk::Format::eB8G8R8A8Srgb; Require("ImageOverlapResolution", "PPSA02604 BGRA8 sRGB reinterpretation", - IsCompatibleRenderTargetView(ppsa02604_unorm_target, ppsa02604_srgb_target), - "PPSA02604 exact BGRA8 UNORM-to-sRGB target was not recognized as a view"); + IsCompatibleRenderTargetView(ppsa02604_unorm_target, + ppsa02604_srgb_target), + "PPSA02604 exact BGRA8 UNORM-to-sRGB target was not recognized as a " + "view"); auto adjacent_target = replacement_target; adjacent_target.address = old_target.address + old_target.size; - Require("ImageOverlapResolution", "render target allocation-pool adjacent", - ClassifyRenderTargetOverlap(old_target, false, false, true, adjacent_target) == - RenderTargetOverlap::None, - "adjacent render targets were treated as allocation-pool replacement"); + Require( + "ImageOverlapResolution", "render target allocation-pool adjacent", + ClassifyRenderTargetOverlap(old_target, false, false, true, + adjacent_target) == RenderTargetOverlap::None, + "adjacent render targets were treated as allocation-pool replacement"); Require("ImageOverlapResolution", "metadata retains sampled image", ClassifyMetaImageOverlap(true, false, false, false) == @@ -12296,7 +12459,8 @@ void CheckImageOverlapResolution() { MetaImageOverlap::Unsupported && ClassifyMetaImageOverlap(false, true, false, true) == MetaImageOverlap::Unsupported, - "unordered or buffer-dirty render target was admitted for metadata reuse"); + "unordered or buffer-dirty render target was admitted for metadata " + "reuse"); Require("ImageOverlapResolution", "metadata rejects unsupported image", ClassifyMetaImageOverlap(false, false, false, false) == MetaImageOverlap::Unsupported, @@ -12323,10 +12487,11 @@ void CheckImageOverlapResolution() { depth.address = sampled.address; depth.size = 0x6000; depth.depth_load_clear = true; - Require("ImageOverlapResolution", "clear depth reuse", - ClassifyDepthOverlap(sampled, false, depth) == - DepthOverlap::RetireSampled, - "equal-base CPU-owned sampled image was not classified as pool reuse"); + Require( + "ImageOverlapResolution", "clear depth reuse", + ClassifyDepthOverlap(sampled, false, depth) == + DepthOverlap::RetireSampled, + "equal-base CPU-owned sampled image was not classified as pool reuse"); Require("ImageOverlapResolution", "gpu owner", ClassifyDepthOverlap(sampled, true, depth) == DepthOverlap::Unsupported, @@ -12352,7 +12517,7 @@ void CheckImageOverlapResolution() { DepthTargetInfo ppsa01880_depth{}; ppsa01880_depth.address = ppsa01880_sampled_depth.address; ppsa01880_depth.size = ppsa01880_sampled_depth.size; - ppsa01880_depth.format = VK_FORMAT_D32_SFLOAT; + ppsa01880_depth.format = vk::Format::eD32Sfloat; ppsa01880_depth.guest_format = ppsa01880_sampled_depth.format; ppsa01880_depth.width = ppsa01880_sampled_depth.width; ppsa01880_depth.height = ppsa01880_sampled_depth.height; @@ -12361,8 +12526,7 @@ void CheckImageOverlapResolution() { ppsa01880_depth.tile_mode = ppsa01880_sampled_depth.tile; Require("ImageOverlapResolution", "PPSA01880 exact depth load", ClassifyDepthOverlap(ppsa01880_sampled_depth, false, - ppsa01880_depth) == - DepthOverlap::RetireSampled, + ppsa01880_depth) == DepthOverlap::RetireSampled, "captured CPU-owned R32F/D32F depth layout was not retired"); ImageInfo ppsa09477_sampled_depth{}; @@ -12382,7 +12546,7 @@ void CheckImageOverlapResolution() { ppsa09477_depth.size = ppsa09477_sampled_depth.size; ppsa09477_depth.stencil_address = 0x10aec00000ull; ppsa09477_depth.stencil_size = 0x220000; - ppsa09477_depth.format = VK_FORMAT_D32_SFLOAT_S8_UINT; + ppsa09477_depth.format = vk::Format::eD32SfloatS8Uint; ppsa09477_depth.guest_format = ppsa09477_sampled_depth.format; ppsa09477_depth.width = ppsa09477_sampled_depth.width; ppsa09477_depth.height = ppsa09477_sampled_depth.height; @@ -12392,9 +12556,9 @@ void CheckImageOverlapResolution() { ppsa09477_depth.stencil_access = true; Require("ImageOverlapResolution", "PPSA09477 disjoint stencil depth load", ClassifyDepthOverlap(ppsa09477_sampled_depth, false, - ppsa09477_depth) == - DepthOverlap::RetireSampled, - "captured sampled depth was not preserved beside its disjoint stencil plane"); + ppsa09477_depth) == DepthOverlap::RetireSampled, + "captured sampled depth was not preserved beside its disjoint " + "stencil plane"); auto ppsa09477_overlapping_stencil = ppsa09477_depth; ppsa09477_overlapping_stencil.stencil_address = ppsa09477_sampled_depth.address + 0x800000; @@ -12408,44 +12572,42 @@ void CheckImageOverlapResolution() { Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm); auto promoted_d16_depth = ppsa09477_depth; promoted_d16_depth.guest_format = promoted_d16_sampled.format; - promoted_d16_depth.format = VK_FORMAT_D24_UNORM_S8_UINT; + promoted_d16_depth.format = vk::Format::eD24UnormS8Uint; promoted_d16_depth.bytes_per_element = 2; - Require("ImageOverlapResolution", "promoted D16 native-copy guard", - ClassifyDepthOverlap(promoted_d16_sampled, false, - promoted_d16_depth) == - DepthOverlap::Unsupported, - "sampled D16 depth was admitted without a native transfer-width match"); + Require( + "ImageOverlapResolution", "promoted D16 native-copy guard", + ClassifyDepthOverlap(promoted_d16_sampled, false, promoted_d16_depth) == + DepthOverlap::Unsupported, + "sampled D16 depth was admitted without a native transfer-width match"); Require("ImageOverlapResolution", "PPSA01880 GPU depth load", ClassifyDepthOverlap(ppsa01880_sampled_depth, true, - ppsa01880_depth) == - DepthOverlap::Unsupported, + ppsa01880_depth) == DepthOverlap::Unsupported, "captured GPU-owned sampled depth was admitted for retirement"); auto mismatched_sampled_depth = ppsa01880_sampled_depth; mismatched_sampled_depth.pitch++; auto mismatched_depth = ppsa01880_depth; - mismatched_depth.stencil_address = ppsa01880_depth.address + ppsa01880_depth.size; + mismatched_depth.stencil_address = + ppsa01880_depth.address + ppsa01880_depth.size; mismatched_depth.stencil_size = 0x4000000; - Require("ImageOverlapResolution", "PPSA01880 depth layout guards", - ClassifyDepthOverlap(mismatched_sampled_depth, false, - ppsa01880_depth) == - DepthOverlap::Unsupported && - ClassifyDepthOverlap(ppsa01880_sampled_depth, false, - mismatched_depth) == - DepthOverlap::Unsupported, - "pitch-mismatched or stencil-bearing depth load was admitted"); + Require( + "ImageOverlapResolution", "PPSA01880 depth layout guards", + ClassifyDepthOverlap(mismatched_sampled_depth, false, ppsa01880_depth) == + DepthOverlap::Unsupported && + ClassifyDepthOverlap(ppsa01880_sampled_depth, false, + mismatched_depth) == DepthOverlap::Unsupported, + "pitch-mismatched or stencil-bearing depth load was admitted"); mismatched_sampled_depth = ppsa01880_sampled_depth; mismatched_sampled_depth.levels = 2; mismatched_sampled_depth.view_levels = 2; mismatched_depth = ppsa01880_depth; - mismatched_depth.format = VK_FORMAT_D16_UNORM; - Require("ImageOverlapResolution", "PPSA01880 depth topology guards", - ClassifyDepthOverlap(mismatched_sampled_depth, false, - ppsa01880_depth) == - DepthOverlap::Unsupported && - ClassifyDepthOverlap(ppsa01880_sampled_depth, false, - mismatched_depth) == - DepthOverlap::Unsupported, - "mipmapped or format-mismatched depth load was admitted"); + mismatched_depth.format = vk::Format::eD16Unorm; + Require( + "ImageOverlapResolution", "PPSA01880 depth topology guards", + ClassifyDepthOverlap(mismatched_sampled_depth, false, ppsa01880_depth) == + DepthOverlap::Unsupported && + ClassifyDepthOverlap(ppsa01880_sampled_depth, false, + mismatched_depth) == DepthOverlap::Unsupported, + "mipmapped or format-mismatched depth load was admitted"); struct DepthTransitionCase { const char *name; bool clear; @@ -12529,14 +12691,17 @@ void CheckImageOverlapResolution() { Require("ImageOverlapResolution", "oversized depth view", !IsDepthTargetRangeCompatible(depth, depth.address, depth.size + 1), "oversized depth range was silently admitted"); - Require("ImageOverlapResolution", "offset depth view", - !IsDepthTargetRangeCompatible(depth, depth.address + 1, depth.size - 1), - "offset depth range was silently admitted"); + Require( + "ImageOverlapResolution", "offset depth view", + !IsDepthTargetRangeCompatible(depth, depth.address + 1, depth.size - 1), + "offset depth range was silently admitted"); Require("ImageOverlapResolution", "complete stencil view", - IsDepthTargetRangeCompatible(depth, depth.stencil_address, depth.stencil_size), + IsDepthTargetRangeCompatible(depth, depth.stencil_address, + depth.stencil_size), "complete stencil range was rejected"); Require("ImageOverlapResolution", "partial stencil view", - !IsDepthTargetRangeCompatible(depth, depth.stencil_address, depth.stencil_size - 1), + !IsDepthTargetRangeCompatible(depth, depth.stencil_address, + depth.stencil_size - 1), "partial stencil range was silently admitted"); depth.address = sampled.address + 0x1000; Require("ImageOverlapResolution", "offset alias", @@ -12598,18 +12763,19 @@ void CheckDepthHtileStencilCompatibility() { } void CheckStencilAttachmentAccess() { - PipelineStencilStaticState state{VK_STENCIL_OP_KEEP, VK_STENCIL_OP_KEEP, - VK_STENCIL_OP_KEEP, VK_COMPARE_OP_ALWAYS}; + PipelineStencilStaticState state{vk::StencilOp::eKeep, vk::StencilOp::eKeep, + vk::StencilOp::eKeep, + vk::CompareOp::eAlways}; PipelineStencilDynamicState dynamic{0xff, 0xff, 0}; Require("StencilAttachmentAccess", "always keep", !stencil_face_accesses_attachment(state, dynamic), "ALWAYS/KEEP state was classified as stencil access"); - state.compareOp = VK_COMPARE_OP_EQUAL; + state.compareOp = vk::CompareOp::eEqual; Require("StencilAttachmentAccess", "compare reads", stencil_face_accesses_attachment(state, dynamic), "real stencil comparison was classified as no access"); - state.compareOp = VK_COMPARE_OP_ALWAYS; - state.passOp = VK_STENCIL_OP_ZERO; + state.compareOp = vk::CompareOp::eAlways; + state.passOp = vk::StencilOp::eZero; Require("StencilAttachmentAccess", "write operation", stencil_face_accesses_attachment(state, dynamic), "write-capable stencil operation was classified as no access"); @@ -12628,26 +12794,26 @@ void CheckDepthTargetFootprints() { const char *name; uint32_t depth_format; uint32_t stencil_format; - VkFormat expected; + vk::Format expected; }; constexpr AttachmentFormatCase attachment_cases[] = { {"Z16", Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16), Prospero::GpuEnumValue(Prospero::StencilFormat::kInvalid), - VK_FORMAT_D16_UNORM}, + vk::Format::eD16Unorm}, {"Z16S8", Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16), Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), - VK_FORMAT_D16_UNORM_S8_UINT}, + vk::Format::eD16UnormS8Uint}, {"Z32", Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), Prospero::GpuEnumValue(Prospero::StencilFormat::kInvalid), - VK_FORMAT_D32_SFLOAT}, + vk::Format::eD32Sfloat}, {"Z32S8", Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), - VK_FORMAT_D32_SFLOAT_S8_UINT}, + vk::Format::eD32SfloatS8Uint}, {"invalid depth", 2, Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), - VK_FORMAT_UNDEFINED}, + vk::Format::eUndefined}, {"invalid stencil", Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16), - 2, VK_FORMAT_UNDEFINED}, + 2, vk::Format::eUndefined}, }; for (const auto &test : attachment_cases) { Require("DepthTargetFootprints", test.name, @@ -12655,43 +12821,51 @@ void CheckDepthTargetFootprints() { test.expected, "PS5 depth/stencil attachment mapping changed"); } - Require("DepthTargetFootprints", "1920x1080 Z16S8 without HTile", - TileGetDepthSize(1920, 1080, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), false, - &stencil, &htile, &depth) && - depth.size == 0x480000 && depth.align == 0x10000 && - stencil.size == 0x280000 && stencil.align == 0x10000 && htile.size == 0, - "captured Z16S8 footprint disagrees with Prospero block rules"); + Require( + "DepthTargetFootprints", "1920x1080 Z16S8 without HTile", + TileGetDepthSize(1920, 1080, 0, + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), + false, &stencil, &htile, &depth) && + depth.size == 0x480000 && depth.align == 0x10000 && + stencil.size == 0x280000 && stencil.align == 0x10000 && + htile.size == 0, + "captured Z16S8 footprint disagrees with Prospero block rules"); struct TargetFormatCase { const char *name; - VkFormat host_format; + vk::Format host_format; uint32_t guest_format; uint32_t bytes_per_element; bool stencil; bool supported; }; constexpr TargetFormatCase target_cases[] = { - {"D16", VK_FORMAT_D16_UNORM, - Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, false, true}, - {"D16S8", VK_FORMAT_D16_UNORM_S8_UINT, + {"D16", vk::Format::eD16Unorm, + Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, false, + true}, + {"D16S8", vk::Format::eD16UnormS8Uint, Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, true, true}, - {"D16 via D24S8", VK_FORMAT_D24_UNORM_S8_UINT, + {"D16 via D24S8", vk::Format::eD24UnormS8Uint, Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, true, true}, - {"D16 via D32S8", VK_FORMAT_D32_SFLOAT_S8_UINT, + {"D16 via D32S8", vk::Format::eD32SfloatS8Uint, Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, true, true}, - {"D32", VK_FORMAT_D32_SFLOAT, - Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 4, false, true}, - {"D32S8", VK_FORMAT_D32_SFLOAT_S8_UINT, + {"D32", vk::Format::eD32Sfloat, + Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 4, false, + true}, + {"D32S8", vk::Format::eD32SfloatS8Uint, Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 4, true, true}, - {"D16 plus stencil mismatch", VK_FORMAT_D16_UNORM, - Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, true, false}, - {"fallback without stencil", VK_FORMAT_D24_UNORM_S8_UINT, - Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, false, false}, - {"D32 guest via D24", VK_FORMAT_D24_UNORM_S8_UINT, - Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 4, true, false}, - {"D16 byte mismatch", VK_FORMAT_D16_UNORM, - Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 4, false, false}, + {"D16 plus stencil mismatch", vk::Format::eD16Unorm, + Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, true, + false}, + {"fallback without stencil", vk::Format::eD24UnormS8Uint, + Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 2, false, + false}, + {"D32 guest via D24", vk::Format::eD24UnormS8Uint, + Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 4, true, + false}, + {"D16 byte mismatch", vk::Format::eD16Unorm, + Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm), 4, false, + false}, }; for (const auto &test : target_cases) { DepthTargetInfo target{}; @@ -12706,16 +12880,17 @@ void CheckDepthTargetFootprints() { } struct TransferPlaneCase { const char *name; - VkFormat attachment; - VkFormat transfer; + vk::Format attachment; + vk::Format transfer; uint32_t bytes; }; constexpr TransferPlaneCase transfer_cases[] = { - {"D16S8 transfer", VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D16_UNORM, 2}, - {"D24S8 transfer", VK_FORMAT_D24_UNORM_S8_UINT, - VK_FORMAT_X8_D24_UNORM_PACK32, 4}, - {"D32S8 transfer", VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT, 4}, - {"invalid transfer", VK_FORMAT_R16_UNORM, VK_FORMAT_UNDEFINED, 0}, + {"D16S8 transfer", vk::Format::eD16UnormS8Uint, vk::Format::eD16Unorm, 2}, + {"D24S8 transfer", vk::Format::eD24UnormS8Uint, + vk::Format::eX8D24UnormPack32, 4}, + {"D32S8 transfer", vk::Format::eD32SfloatS8Uint, vk::Format::eD32Sfloat, + 4}, + {"invalid transfer", vk::Format::eR16Unorm, vk::Format::eUndefined, 0}, }; for (const auto &test : transfer_cases) { Require("DepthTargetFootprints", test.name, @@ -12741,74 +12916,82 @@ void CheckDepthTargetFootprints() { "D16 host promotion changed the represented depth value"); } Require("DepthTargetFootprints", "640x360 Z32S8 without HTile", - TileGetDepthSize(640, 360, 0, Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), false, - &stencil, &htile, &depth), + TileGetDepthSize( + 640, 360, 0, Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), false, + &stencil, &htile, &depth), "valid non-HTile depth/stencil footprint was rejected"); - Require("DepthTargetFootprints", "640x360 Prospero block sizes", - depth.size == 0xf0000 && depth.align == 0x10000 && - stencil.size == 0x60000 && stencil.align == 0x10000 && - htile.size == 0 && htile.align == 0, - "non-HTile depth/stencil footprint disagrees with Prospero block rules"); + Require( + "DepthTargetFootprints", "640x360 Prospero block sizes", + depth.size == 0xf0000 && depth.align == 0x10000 && + stencil.size == 0x60000 && stencil.align == 0x10000 && + htile.size == 0 && htile.align == 0, + "non-HTile depth/stencil footprint disagrees with Prospero block rules"); const auto depth_pitch = TileGetTexturePitch( Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 640, 1, Prospero::GpuEnumValue(Prospero::TileMode::kDepth)); TileSizeAlign texture_depth{}; - TileGetTextureTotalSize(Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 640, 360, - 1, depth_pitch, 1, - Prospero::GpuEnumValue(Prospero::TileMode::kDepth), false, - &texture_depth); + TileGetTextureTotalSize( + Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), 640, 360, 1, + depth_pitch, 1, Prospero::GpuEnumValue(Prospero::TileMode::kDepth), false, + &texture_depth); Require("DepthTargetFootprints", "640x360 generic depth tile", depth_pitch == 640 && texture_depth.size == 0xf0000 && texture_depth.align == 0x10000, "generic depth texture sizing bypassed 64 KiB block padding"); - Require("DepthTargetFootprints", "960x540 Z32S8 with HTile", - TileGetDepthSize(960, 540, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, - &stencil, &htile, &depth) && - depth.size == 0x280000 && depth.align == 0x10000 && - stencil.size == 0xc0000 && stencil.align == 0x10000 && - htile.size == 0x10000 && htile.align == 0x8000, - "generic Prospero HTile block calculation rejected the title footprint"); - Require("DepthTargetFootprints", "known HTile extent", - TileGetDepthSize(1280, 720, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, - &stencil, &htile, &depth) && - depth.size == 0x3c0000 && stencil.size == 0xf0000 && - htile.size == 0x20000, - "validated 1280x720 HTile footprint regressed"); - Require("DepthTargetFootprints", "PPSA06228 3840x2160 Z32S8 with HTile", - TileGetDepthSize(3840, 2160, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, - &stencil, &htile, &depth) && - depth.size == 0x1fe0000 && depth.align == 0x10000 && - stencil.size == 0x870000 && stencil.align == 0x10000 && - htile.size == 0xa0000 && htile.align == 0x8000, - "captured 3840x2160 depth/stencil/HTile footprint disagrees with Prospero rules"); - Require("DepthTargetFootprints", "invalid depth format", - !TileGetDepthSize(960, 540, 0, 2, - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, - &stencil, &htile, &depth), - "unsupported depth format was silently admitted"); + Require( + "DepthTargetFootprints", "960x540 Z32S8 with HTile", + TileGetDepthSize(960, 540, 0, + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), + true, &stencil, &htile, &depth) && + depth.size == 0x280000 && depth.align == 0x10000 && + stencil.size == 0xc0000 && stencil.align == 0x10000 && + htile.size == 0x10000 && htile.align == 0x8000, + "generic Prospero HTile block calculation rejected the title footprint"); + Require( + "DepthTargetFootprints", "known HTile extent", + TileGetDepthSize(1280, 720, 0, + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), + true, &stencil, &htile, &depth) && + depth.size == 0x3c0000 && stencil.size == 0xf0000 && + htile.size == 0x20000, + "validated 1280x720 HTile footprint regressed"); + Require( + "DepthTargetFootprints", "PPSA06228 3840x2160 Z32S8 with HTile", + TileGetDepthSize(3840, 2160, 0, + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), + true, &stencil, &htile, &depth) && + depth.size == 0x1fe0000 && depth.align == 0x10000 && + stencil.size == 0x870000 && stencil.align == 0x10000 && + htile.size == 0xa0000 && htile.align == 0x8000, + "captured 3840x2160 depth/stencil/HTile footprint disagrees with " + "Prospero rules"); + Require( + "DepthTargetFootprints", "invalid depth format", + !TileGetDepthSize(960, 540, 0, 2, + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), + true, &stencil, &htile, &depth), + "unsupported depth format was silently admitted"); Require("DepthTargetFootprints", "invalid stencil format", - !TileGetDepthSize(960, 540, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), 2, true, - &stencil, &htile, &depth), + !TileGetDepthSize( + 960, 540, 0, Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + 2, true, &stencil, &htile, &depth), "unsupported stencil format was silently admitted"); Require("DepthTargetFootprints", "invalid extent", - !TileGetDepthSize(0, 540, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, - &stencil, &htile, &depth) && - !TileGetDepthSize(16385, 540, 0, - Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), - Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, - &stencil, &htile, &depth), + !TileGetDepthSize( + 0, 540, 0, Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, + &stencil, &htile, &depth) && + !TileGetDepthSize( + 16385, 540, 0, + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F), + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt), true, + &stencil, &htile, &depth), "invalid HTile extent was silently admitted"); std::printf("[host] %-32s ok\n", "DepthTargetFootprints"); } @@ -12817,13 +13000,15 @@ void CheckHtileClearTargetResolution() { HW::DepthDepthSizeXY one_pixel{}; one_pixel.valid = true; Require("HtileClearTargetResolution", "1x1 encoded depth extent", - one_pixel.valid && one_pixel.x_max + 1u == 1u && one_pixel.y_max + 1u == 1u, + one_pixel.valid && one_pixel.x_max + 1u == 1u && + one_pixel.y_max + 1u == 1u, "zero DB_DEPTH_SIZE_XY fields were mistaken for an absent register"); HW::DepthDepthSizeXY absent{}; Require("HtileClearTargetResolution", "absent depth extent", !absent.valid, "an unwritten DB_DEPTH_SIZE_XY register was admitted"); HW::DepthRenderTarget descriptor_backed{}; - descriptor_backed.z_info.format = Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16); + descriptor_backed.z_info.format = + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16); descriptor_backed.z_info.tile_surface_enable = true; descriptor_backed.z_info.zrange_precision = 1; descriptor_backed.stencil_info.tile_stencil_disable = true; @@ -12832,7 +13017,8 @@ void CheckHtileClearTargetResolution() { descriptor_backed.htile_data_base_addr = 0xc1a98000; HtileClearTarget resolved{}; - Require("HtileClearTargetResolution", "PPSA09076 descriptor-backed Z16 target", + Require("HtileClearTargetResolution", + "PPSA09076 descriptor-backed Z16 target", ResolveHtileClearTarget(descriptor_backed, 0x8000, &resolved) && resolved.address == 0xc1a98000 && resolved.size == 0x8000, "valid descriptor-proven Z16 HTile clear target was rejected"); @@ -12840,21 +13026,24 @@ void CheckHtileClearTargetResolution() { auto partial_extent = descriptor_backed; partial_extent.size.x_max = 1; auto missing_stencil = descriptor_backed; - missing_stencil.stencil_info.format = Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt); + missing_stencil.stencil_info.format = + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt); auto mismatched_write = descriptor_backed; mismatched_write.z_write_base_addr += 0x10000; - Require("HtileClearTargetResolution", "descriptor-backed rejection boundaries", - !ResolveHtileClearTarget(descriptor_backed, 0x4000, &resolved) && - !ResolveHtileClearTarget(partial_extent, 0x8000, &resolved) && - !ResolveHtileClearTarget(missing_stencil, 0x8000, &resolved) && - !ResolveHtileClearTarget(mismatched_write, 0x8000, &resolved), - "ambiguous or inconsistent descriptor-backed HTile target was admitted"); + Require( + "HtileClearTargetResolution", "descriptor-backed rejection boundaries", + !ResolveHtileClearTarget(descriptor_backed, 0x4000, &resolved) && + !ResolveHtileClearTarget(partial_extent, 0x8000, &resolved) && + !ResolveHtileClearTarget(missing_stencil, 0x8000, &resolved) && + !ResolveHtileClearTarget(mismatched_write, 0x8000, &resolved), + "ambiguous or inconsistent descriptor-backed HTile target was admitted"); HW::DepthRenderTarget derived{}; derived.z_info.format = Prospero::GpuEnumValue(Prospero::DepthFormat::kZ32F); derived.z_info.tile_surface_enable = true; derived.z_info.zrange_precision = 1; - derived.stencil_info.format = Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt); + derived.stencil_info.format = + Prospero::GpuEnumValue(Prospero::StencilFormat::k8UInt); derived.stencil_info.tile_stencil_disable = true; derived.z_read_base_addr = 0x100000; derived.z_write_base_addr = derived.z_read_base_addr; @@ -12867,42 +13056,49 @@ void CheckHtileClearTargetResolution() { TileSizeAlign depth_size{}; TileSizeAlign stencil_size{}; TileSizeAlign htile_size{}; - Require("HtileClearTargetResolution", "derived Z32S8 target", - TileGetDepthSize(960, 540, 0, derived.z_info.format, - derived.stencil_info.format, true, &stencil_size, - &htile_size, &depth_size) && - ResolveHtileClearTarget(derived, htile_size.size, &resolved) && - resolved.address == derived.htile_data_base_addr && - resolved.size == htile_size.size && - !ResolveHtileClearTarget(derived, htile_size.size + 0x8000, &resolved), - "extent-derived HTile validation or descriptor cross-check regressed"); + Require( + "HtileClearTargetResolution", "derived Z32S8 target", + TileGetDepthSize(960, 540, 0, derived.z_info.format, + derived.stencil_info.format, true, &stencil_size, + &htile_size, &depth_size) && + ResolveHtileClearTarget(derived, htile_size.size, &resolved) && + resolved.address == derived.htile_data_base_addr && + resolved.size == htile_size.size && + !ResolveHtileClearTarget(derived, htile_size.size + 0x8000, + &resolved), + "extent-derived HTile validation or descriptor cross-check regressed"); auto derived_z16 = derived; - derived_z16.z_info.format = Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16); - derived_z16.stencil_info.format = Prospero::GpuEnumValue(Prospero::StencilFormat::kInvalid); + derived_z16.z_info.format = + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16); + derived_z16.stencil_info.format = + Prospero::GpuEnumValue(Prospero::StencilFormat::kInvalid); derived_z16.stencil_read_base_addr = 0; derived_z16.stencil_write_base_addr = 0; - Require("HtileClearTargetResolution", "derived Z16 depth-only target", - TileGetDepthSize(960, 540, 0, derived_z16.z_info.format, - derived_z16.stencil_info.format, true, &stencil_size, - &htile_size, &depth_size) && - stencil_size.align == 0 && stencil_size.size == 0 && - ResolveHtileClearTarget(derived_z16, htile_size.size, &resolved) && - resolved.address == derived_z16.htile_data_base_addr && - resolved.size == htile_size.size, - "extent-derived Z16 depth-only HTile target was rejected"); + Require( + "HtileClearTargetResolution", "derived Z16 depth-only target", + TileGetDepthSize(960, 540, 0, derived_z16.z_info.format, + derived_z16.stencil_info.format, true, &stencil_size, + &htile_size, &depth_size) && + stencil_size.align == 0 && stencil_size.size == 0 && + ResolveHtileClearTarget(derived_z16, htile_size.size, &resolved) && + resolved.address == derived_z16.htile_data_base_addr && + resolved.size == htile_size.size, + "extent-derived Z16 depth-only HTile target was rejected"); auto derived_z16s8 = derived; - derived_z16s8.z_info.format = Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16); - Require("HtileClearTargetResolution", "derived Z16S8 target", - TileGetDepthSize(960, 540, 0, derived_z16s8.z_info.format, - derived_z16s8.stencil_info.format, true, &stencil_size, - &htile_size, &depth_size) && - stencil_size.size != 0 && stencil_size.align == 0x10000 && - ResolveHtileClearTarget(derived_z16s8, htile_size.size, &resolved) && - resolved.address == derived_z16s8.htile_data_base_addr && - resolved.size == htile_size.size, - "extent-derived Z16S8 HTile target was rejected"); + derived_z16s8.z_info.format = + Prospero::GpuEnumValue(Prospero::DepthFormat::kZ16); + Require( + "HtileClearTargetResolution", "derived Z16S8 target", + TileGetDepthSize(960, 540, 0, derived_z16s8.z_info.format, + derived_z16s8.stencil_info.format, true, &stencil_size, + &htile_size, &depth_size) && + stencil_size.size != 0 && stencil_size.align == 0x10000 && + ResolveHtileClearTarget(derived_z16s8, htile_size.size, &resolved) && + resolved.address == derived_z16s8.htile_data_base_addr && + resolved.size == htile_size.size, + "extent-derived Z16S8 HTile target was rejected"); std::printf("[host] %-32s ok\n", "HtileClearTargetResolution"); } @@ -12926,12 +13122,12 @@ void CheckCrossQueueImageLifetime() { compute.Retain(image); graphics.Retain(image); image.reset(); - Require("CrossQueueImageLifetime", "retained", !destroyed && !graphics.Empty() && - !compute.Empty(), + Require("CrossQueueImageLifetime", "retained", + !destroyed && !graphics.Empty() && !compute.Empty(), "cache removal destroyed an image retained by command buffers"); graphics.ReleaseAfterFence(); - Require("CrossQueueImageLifetime", "first fence", !destroyed && graphics.Empty() && - !compute.Empty(), + Require("CrossQueueImageLifetime", "first fence", + !destroyed && graphics.Empty() && !compute.Empty(), "first command-buffer fence destroyed another queue's image"); compute.ReleaseAfterFence(); Require("CrossQueueImageLifetime", "last fence", destroyed && compute.Empty(), @@ -12943,11 +13139,12 @@ void CheckHostDmaMetadataReuse() { constexpr uintptr_t base = 0x0000000200010000ull; constexpr uint64_t allocation_size = 0x10000; constexpr uint64_t metadata_size = 0x8000; - auto *memory = static_cast(VirtualAlloc( - reinterpret_cast(base), allocation_size, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto *memory = static_cast( + VirtualAlloc(reinterpret_cast(base), allocation_size, + MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); Require("HostDmaMetadataReuse", "allocation", - memory == reinterpret_cast(base), "fixed VirtualAlloc failed"); + memory == reinterpret_cast(base), + "fixed VirtualAlloc failed"); std::memset(memory + metadata_size, 0x5a, 0x1000); ResourceMutex resource_mutex; @@ -13005,7 +13202,8 @@ void CheckEmbeddedFetchLaneSpill() { code.push_back(EncodeSmem1(0)); // s_load_dwordx4 s[20:23], s[8:9] AppendVop3(&code, 0x361u, 6, 20, InlineU32(0)); // v_writelane_b32 v6, s20, 0 code.push_back(EncodeSMovB32(20, InlineU32(0))); - AppendVop3(&code, 0x360u, 20, Vgpr(6), InlineU32(0)); // v_readlane_b32 s20, v6, 0 + AppendVop3(&code, 0x360u, 20, Vgpr(6), + InlineU32(0)); // v_readlane_b32 s20, v6, 0 code.push_back(EncodeVop2(0x01u, 0, Vgpr(8), 5)); code.push_back(EncodeMubuf0(0x03u, 0, true)); code.push_back(EncodeMubuf1(9, 5, 0)); @@ -13029,7 +13227,8 @@ void CheckEmbeddedFetchLaneSpill() { ShaderRecompiler::CompileResult result; std::string error; Require("EmbeddedFetchLaneSpill", "compile", - ShaderRecompiler::TryRecompile(code, options, &result, &error), error); + ShaderRecompiler::TryRecompile(code, options, &result, &error), + error); Require("EmbeddedFetchLaneSpill", "fetch rewrite", vertex.resource_fetch_components[0] == 4, "lane-spilled fetch descriptor was not recognized and rewritten"); diff --git a/tests/shaderCfgTests.cpp b/tests/shaderCfgTests.cpp index 3ac27dd84..b49f86d89 100644 --- a/tests/shaderCfgTests.cpp +++ b/tests/shaderCfgTests.cpp @@ -411,14 +411,16 @@ constexpr uint32_t EncodeSopp(uint32_t opcode, uint32_t simm = 0) { void TestNativeShaderResourceDependencies() { const auto stages = ShaderPipelineStages( - VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT); - Check(stages == (VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT), + vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | + vk::ShaderStageFlagBits::eCompute); + Check(stages == (vk::PipelineStageFlagBits::eVertexShader | + vk::PipelineStageFlagBits::eFragmentShader | + vk::PipelineStageFlagBits::eComputeShader), "shader-stage dependency mapping was not exact"); const auto shader_barrier = MakeShaderWriteDependency(); - Check(shader_barrier.srcAccessMask == VK_ACCESS_SHADER_WRITE_BIT && - (shader_barrier.dstAccessMask & VK_ACCESS_SHADER_READ_BIT) != 0 && - (shader_barrier.dstAccessMask & VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT) != 0, + Check(shader_barrier.srcAccessMask == vk::AccessFlagBits::eShaderWrite && + (shader_barrier.dstAccessMask & vk::AccessFlagBits::eShaderRead) && + (shader_barrier.dstAccessMask & vk::AccessFlagBits::eVertexAttributeRead), "shader-write dependency does not expose draw/dispatch buffer writes"); ShaderRecompiler::IR::Program program; @@ -445,27 +447,27 @@ void TestNativeShaderResourceDependencies() { "graphics/compute write collector lost or invented a storage-buffer range"); VulkanImage image {VulkanImageType::StorageTexture}; - image.image = reinterpret_cast(uintptr_t {1}); - image.layout = VK_IMAGE_LAYOUT_GENERAL; + image.image = reinterpret_cast(uintptr_t {1}); + image.layout = vk::ImageLayout::eGeneral; image.layers = 3; const auto image_barrier = MakeStorageImageDependency(image, true, true); - Check(image_barrier.oldLayout == VK_IMAGE_LAYOUT_GENERAL && - image_barrier.newLayout == VK_IMAGE_LAYOUT_GENERAL && - (image_barrier.srcAccessMask & VK_ACCESS_MEMORY_WRITE_BIT) != 0 && - (image_barrier.dstAccessMask & VK_ACCESS_SHADER_READ_BIT) != 0 && - (image_barrier.dstAccessMask & VK_ACCESS_SHADER_WRITE_BIT) != 0 && + Check(image_barrier.oldLayout == vk::ImageLayout::eGeneral && + image_barrier.newLayout == vk::ImageLayout::eGeneral && + (image_barrier.srcAccessMask & vk::AccessFlagBits::eMemoryWrite) && + (image_barrier.dstAccessMask & vk::AccessFlagBits::eShaderRead) && + (image_barrier.dstAccessMask & vk::AccessFlagBits::eShaderWrite) && image_barrier.subresourceRange.levelCount == VK_REMAINING_MIP_LEVELS && image_barrier.subresourceRange.layerCount == image.layers, "GENERAL storage-image dependency lacks a complete memory barrier"); VulkanBuffer buffer; - buffer.buffer = reinterpret_cast(uintptr_t {1}); + buffer.buffer = reinterpret_cast(uintptr_t {1}); const auto gds_barrier = MakeGdsDependency(buffer); - Check((gds_barrier.srcAccessMask & VK_ACCESS_HOST_WRITE_BIT) != 0 && - (gds_barrier.srcAccessMask & VK_ACCESS_TRANSFER_WRITE_BIT) != 0 && - (gds_barrier.srcAccessMask & VK_ACCESS_SHADER_WRITE_BIT) != 0 && + Check((gds_barrier.srcAccessMask & vk::AccessFlagBits::eHostWrite) && + (gds_barrier.srcAccessMask & vk::AccessFlagBits::eTransferWrite) && + (gds_barrier.srcAccessMask & vk::AccessFlagBits::eShaderWrite) && gds_barrier.dstAccessMask == - (VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT) && + (vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite) && gds_barrier.size == VK_WHOLE_SIZE, "GDS dependency does not order host/transfer/shader writes"); } @@ -476,21 +478,21 @@ void TestNativeSubgroupPolicy() { context.min_subgroup_size = 32; context.max_subgroup_size = 32; context.subgroup_size_control_enabled = true; - context.required_subgroup_size_stages = VK_SHADER_STAGE_ALL; + context.required_subgroup_size_stages = vk::ShaderStageFlagBits::eAll; ShaderRecompiler::IR::Program safe; safe.wave_size = 32; safe.lane_mask_mode = ShaderLaneMaskMode::NativeWave; - Check(ConfigureShaderSubgroup(context, VK_SHADER_STAGE_VERTEX_BIT, safe).mode == + Check(ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eVertex, safe).mode == ShaderSubgroupMode::Natural, "native wave32 policy changed"); safe.wave_size = 64; Check(SelectGraphicsLaneMaskMode(context, safe.wave_size) == ShaderLaneMaskMode::PerInvocation && - ConfigureShaderSubgroup(context, VK_SHADER_STAGE_VERTEX_BIT, safe).mode == + ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eVertex, safe).mode == ShaderSubgroupMode::Unsupported, "wave64 graphics mismatch accepted native-wave mask lowering"); safe.lane_mask_mode = ShaderLaneMaskMode::PerInvocation; - Check(ConfigureShaderSubgroup(context, VK_SHADER_STAGE_VERTEX_BIT, safe).mode == + Check(ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eVertex, safe).mode == ShaderSubgroupMode::PerInvocationGraphics, "wave64 graphics mismatch did not select per-invocation masks"); @@ -498,12 +500,12 @@ void TestNativeSubgroupPolicy() { cross_lane.blocks.emplace_back().instructions.emplace_back().op = ShaderRecompiler::IR::Opcode::ReadLaneU32; Check(ShaderRecompiler::Spirv::ProgramRequiresExactSubgroupSize(cross_lane) && - ConfigureShaderSubgroup(context, VK_SHADER_STAGE_VERTEX_BIT, cross_lane).mode == + ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eVertex, cross_lane).mode == ShaderSubgroupMode::PerInvocationGraphics, "graphics mismatch did not select per-invocation masks"); auto cross_lane_compute = cross_lane; cross_lane_compute.lane_mask_mode = ShaderLaneMaskMode::NativeWave; - Check(ConfigureShaderSubgroup(context, VK_SHADER_STAGE_COMPUTE_BIT, cross_lane_compute).mode == + Check(ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eCompute, cross_lane_compute).mode == ShaderSubgroupMode::Unsupported, "cross-lane compute mismatch bypassed the exact subgroup requirement"); @@ -519,7 +521,7 @@ void TestNativeSubgroupPolicy() { zero_bfm.src_count = 2; zero_bfm.scalar_sources[0] = 2; Check(!ShaderRecompiler::Spirv::ProgramRequiresExactSubgroupSize(zero_exec) && - ConfigureShaderSubgroup(context, VK_SHADER_STAGE_COMPUTE_BIT, zero_exec).mode == + ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eCompute, zero_exec).mode == ShaderSubgroupMode::FlattenedMasks, "compile-time uniform-zero EXEC write did not stay on the mask-free path"); @@ -550,23 +552,23 @@ void TestNativeSubgroupPolicy() { ds_partial.lane_mask_mode = ShaderLaneMaskMode::NativeWave; ds_partial.blocks.emplace_back().instructions.emplace_back().op = ShaderRecompiler::IR::Opcode::DsAppend; - Check(ConfigureShaderSubgroup(context, VK_SHADER_STAGE_COMPUTE_BIT, ds_partial).mode == + Check(ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eCompute, ds_partial).mode == ShaderSubgroupMode::Unsupported, "partial wave64 DS append bypassed the exact subgroup requirement"); context.max_subgroup_size = 64; const auto controlled = - ConfigureShaderSubgroup(context, VK_SHADER_STAGE_COMPUTE_BIT, cross_lane_compute); + ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eCompute, cross_lane_compute); Check(controlled.mode == ShaderSubgroupMode::Controlled && controlled.required_size == 64, "supported controlled wave64 was not preferred over splitting"); context.subgroup_size = 64; context.subgroup_size_control_enabled = false; cross_lane.wave_size = 32; cross_lane.lane_mask_mode = ShaderLaneMaskMode::PerInvocation; - Check(ConfigureShaderSubgroup(context, VK_SHADER_STAGE_FRAGMENT_BIT, cross_lane).mode == + Check(ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eFragment, cross_lane).mode == ShaderSubgroupMode::Unsupported, "inverse graphics mismatch was accepted as one guest wave"); cross_lane_compute.wave_size = 32; - Check(ConfigureShaderSubgroup(context, VK_SHADER_STAGE_COMPUTE_BIT, cross_lane_compute).mode == + Check(ConfigureShaderSubgroup(context, vk::ShaderStageFlagBits::eCompute, cross_lane_compute).mode == ShaderSubgroupMode::Unsupported, "inverse cross-lane compute mismatch was accepted"); } @@ -5720,7 +5722,7 @@ void TestRenderTargetReverseFloat16ExportMapping() { TextureGetRenderTargetFormat(Prospero::GpuEnumValue(Prospero::ChannelLayout::k16_16_16_16), Prospero::GpuEnumValue(Prospero::ChannelType::kFloat), Prospero::GpuEnumValue(Prospero::ChannelOrder::kReversed)); - Check(format.format == VK_FORMAT_R16G16B16A16_SFLOAT && format.bytes_per_element == 8u, + Check(format.format == vk::Format::eR16G16B16A16Sfloat && format.bytes_per_element == 8u, "reverse RGBA16F render target did not retain its native host format " "and size"); Check(format.export_mapping == Prospero::ColorMappingAbgr && @@ -5735,7 +5737,7 @@ void TestRenderTargetReverseFloat16ExportMapping() { Prospero::GpuEnumValue(Prospero::ChannelLayout::k8_8_8_8), Prospero::GpuEnumValue(Prospero::ChannelType::kUNorm), Prospero::GpuEnumValue(Prospero::ChannelOrder::kAlt)); - Check(legacy_alt.format == VK_FORMAT_B8G8R8A8_UNORM && legacy_alt.export_mapping.IsIdentity(), + Check(legacy_alt.format == vk::Format::eB8G8R8A8Unorm && legacy_alt.export_mapping.IsIdentity(), "legacy BGRA render target acquired a duplicate shader export mapping"); const uint32_t shader[] = {