summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan/vk_device.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/renderer_vulkan/vk_device.cpp')
-rw-r--r--src/video_core/renderer_vulkan/vk_device.cpp570
1 files changed, 315 insertions, 255 deletions
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp
index 6f4ae9132..52d29e49d 100644
--- a/src/video_core/renderer_vulkan/vk_device.cpp
+++ b/src/video_core/renderer_vulkan/vk_device.cpp
@@ -6,15 +6,15 @@
#include <chrono>
#include <cstdlib>
#include <optional>
-#include <set>
#include <string_view>
#include <thread>
+#include <unordered_set>
#include <vector>
#include "common/assert.h"
#include "core/settings.h"
-#include "video_core/renderer_vulkan/declarations.h"
#include "video_core/renderer_vulkan/vk_device.h"
+#include "video_core/renderer_vulkan/wrapper.h"
namespace Vulkan {
@@ -22,49 +22,43 @@ namespace {
namespace Alternatives {
-constexpr std::array Depth24UnormS8Uint = {vk::Format::eD32SfloatS8Uint,
- vk::Format::eD16UnormS8Uint, vk::Format{}};
-constexpr std::array Depth16UnormS8Uint = {vk::Format::eD24UnormS8Uint,
- vk::Format::eD32SfloatS8Uint, vk::Format{}};
+constexpr std::array Depth24UnormS8_UINT = {VK_FORMAT_D32_SFLOAT_S8_UINT,
+ VK_FORMAT_D16_UNORM_S8_UINT, VkFormat{}};
+constexpr std::array Depth16UnormS8_UINT = {VK_FORMAT_D24_UNORM_S8_UINT,
+ VK_FORMAT_D32_SFLOAT_S8_UINT, VkFormat{}};
} // namespace Alternatives
+constexpr std::array REQUIRED_EXTENSIONS = {
+ VK_KHR_SWAPCHAIN_EXTENSION_NAME,
+ VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
+ VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
+ VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME,
+ VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME,
+ VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME,
+ VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME,
+ VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME,
+ VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME,
+};
+
template <typename T>
void SetNext(void**& next, T& data) {
*next = &data;
next = &data.pNext;
}
-template <typename T>
-T GetFeatures(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dld) {
- vk::PhysicalDeviceFeatures2 features;
- T extension_features;
- features.pNext = &extension_features;
- physical.getFeatures2(&features, dld);
- return extension_features;
-}
-
-template <typename T>
-T GetProperties(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dld) {
- vk::PhysicalDeviceProperties2 properties;
- T extension_properties;
- properties.pNext = &extension_properties;
- physical.getProperties2(&properties, dld);
- return extension_properties;
-}
-
-constexpr const vk::Format* GetFormatAlternatives(vk::Format format) {
+constexpr const VkFormat* GetFormatAlternatives(VkFormat format) {
switch (format) {
- case vk::Format::eD24UnormS8Uint:
- return Alternatives::Depth24UnormS8Uint.data();
- case vk::Format::eD16UnormS8Uint:
- return Alternatives::Depth16UnormS8Uint.data();
+ case VK_FORMAT_D24_UNORM_S8_UINT:
+ return Alternatives::Depth24UnormS8_UINT.data();
+ case VK_FORMAT_D16_UNORM_S8_UINT:
+ return Alternatives::Depth16UnormS8_UINT.data();
default:
return nullptr;
}
}
-vk::FormatFeatureFlags GetFormatFeatures(vk::FormatProperties properties, FormatType format_type) {
+VkFormatFeatureFlags GetFormatFeatures(VkFormatProperties properties, FormatType format_type) {
switch (format_type) {
case FormatType::Linear:
return properties.linearTilingFeatures;
@@ -77,79 +71,220 @@ vk::FormatFeatureFlags GetFormatFeatures(vk::FormatProperties properties, Format
}
}
+std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties(
+ vk::PhysicalDevice physical, const vk::InstanceDispatch& dld) {
+ static constexpr std::array formats{VK_FORMAT_A8B8G8R8_UNORM_PACK32,
+ VK_FORMAT_A8B8G8R8_UINT_PACK32,
+ VK_FORMAT_A8B8G8R8_SNORM_PACK32,
+ VK_FORMAT_A8B8G8R8_SRGB_PACK32,
+ VK_FORMAT_B5G6R5_UNORM_PACK16,
+ VK_FORMAT_A2B10G10R10_UNORM_PACK32,
+ VK_FORMAT_A1R5G5B5_UNORM_PACK16,
+ VK_FORMAT_R32G32B32A32_SFLOAT,
+ VK_FORMAT_R32G32B32A32_UINT,
+ VK_FORMAT_R32G32_SFLOAT,
+ VK_FORMAT_R32G32_UINT,
+ VK_FORMAT_R16G16B16A16_UINT,
+ VK_FORMAT_R16G16B16A16_SNORM,
+ VK_FORMAT_R16G16B16A16_UNORM,
+ VK_FORMAT_R16G16_UNORM,
+ VK_FORMAT_R16G16_SNORM,
+ VK_FORMAT_R16G16_SFLOAT,
+ VK_FORMAT_R16_UNORM,
+ VK_FORMAT_R8G8B8A8_SRGB,
+ VK_FORMAT_R8G8_UNORM,
+ VK_FORMAT_R8G8_SNORM,
+ VK_FORMAT_R8_UNORM,
+ VK_FORMAT_R8_UINT,
+ VK_FORMAT_B10G11R11_UFLOAT_PACK32,
+ VK_FORMAT_R32_SFLOAT,
+ VK_FORMAT_R32_UINT,
+ VK_FORMAT_R32_SINT,
+ VK_FORMAT_R16_SFLOAT,
+ VK_FORMAT_R16G16B16A16_SFLOAT,
+ VK_FORMAT_B8G8R8A8_UNORM,
+ VK_FORMAT_R4G4B4A4_UNORM_PACK16,
+ VK_FORMAT_D32_SFLOAT,
+ VK_FORMAT_D16_UNORM,
+ VK_FORMAT_D16_UNORM_S8_UINT,
+ VK_FORMAT_D24_UNORM_S8_UINT,
+ VK_FORMAT_D32_SFLOAT_S8_UINT,
+ VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
+ VK_FORMAT_BC2_UNORM_BLOCK,
+ VK_FORMAT_BC3_UNORM_BLOCK,
+ VK_FORMAT_BC4_UNORM_BLOCK,
+ VK_FORMAT_BC5_UNORM_BLOCK,
+ VK_FORMAT_BC5_SNORM_BLOCK,
+ VK_FORMAT_BC7_UNORM_BLOCK,
+ VK_FORMAT_BC6H_UFLOAT_BLOCK,
+ VK_FORMAT_BC6H_SFLOAT_BLOCK,
+ VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
+ VK_FORMAT_BC2_SRGB_BLOCK,
+ VK_FORMAT_BC3_SRGB_BLOCK,
+ VK_FORMAT_BC7_SRGB_BLOCK,
+ VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
+ VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
+ VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
+ VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
+ VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
+ VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
+ VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
+ VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
+ VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
+ VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
+ VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
+ VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
+ VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
+ VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
+ VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
+ VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
+ VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
+ VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
+ VK_FORMAT_E5B9G9R9_UFLOAT_PACK32};
+ std::unordered_map<VkFormat, VkFormatProperties> format_properties;
+ for (const auto format : formats) {
+ format_properties.emplace(format, physical.GetFormatProperties(format));
+ }
+ return format_properties;
+}
+
} // Anonymous namespace
-VKDevice::VKDevice(const vk::DispatchLoaderDynamic& dld, vk::PhysicalDevice physical,
- vk::SurfaceKHR surface)
- : dld{dld}, physical{physical}, properties{physical.getProperties(dld)},
- format_properties{GetFormatProperties(dld, physical)} {
+VKDevice::VKDevice(VkInstance instance, vk::PhysicalDevice physical, VkSurfaceKHR surface,
+ const vk::InstanceDispatch& dld)
+ : dld{dld}, physical{physical}, properties{physical.GetProperties()},
+ format_properties{GetFormatProperties(physical, dld)} {
SetupFamilies(surface);
SetupFeatures();
}
VKDevice::~VKDevice() = default;
-bool VKDevice::Create(vk::Instance instance) {
+bool VKDevice::Create() {
const auto queue_cis = GetDeviceQueueCreateInfos();
const std::vector extensions = LoadExtensions();
- vk::PhysicalDeviceFeatures2 features2;
+ VkPhysicalDeviceFeatures2 features2;
+ features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
+ features2.pNext = nullptr;
void** next = &features2.pNext;
+
auto& features = features2.features;
- features.vertexPipelineStoresAndAtomics = true;
+ features.robustBufferAccess = false;
+ features.fullDrawIndexUint32 = false;
+ features.imageCubeArray = false;
features.independentBlend = true;
+ features.geometryShader = true;
+ features.tessellationShader = true;
+ features.sampleRateShading = false;
+ features.dualSrcBlend = false;
+ features.logicOp = false;
+ features.multiDrawIndirect = false;
+ features.drawIndirectFirstInstance = false;
features.depthClamp = true;
- features.samplerAnisotropy = true;
+ features.depthBiasClamp = true;
+ features.fillModeNonSolid = false;
+ features.depthBounds = false;
+ features.wideLines = false;
features.largePoints = true;
+ features.alphaToOne = false;
features.multiViewport = true;
- features.depthBiasClamp = true;
- features.geometryShader = true;
- features.tessellationShader = true;
+ features.samplerAnisotropy = true;
+ features.textureCompressionETC2 = false;
+ features.textureCompressionASTC_LDR = is_optimal_astc_supported;
+ features.textureCompressionBC = false;
features.occlusionQueryPrecise = true;
+ features.pipelineStatisticsQuery = false;
+ features.vertexPipelineStoresAndAtomics = true;
features.fragmentStoresAndAtomics = true;
+ features.shaderTessellationAndGeometryPointSize = false;
features.shaderImageGatherExtended = true;
+ features.shaderStorageImageExtendedFormats = false;
+ features.shaderStorageImageMultisample = false;
features.shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported;
features.shaderStorageImageWriteWithoutFormat = true;
- features.textureCompressionASTC_LDR = is_optimal_astc_supported;
-
- vk::PhysicalDevice16BitStorageFeaturesKHR bit16_storage;
+ features.shaderUniformBufferArrayDynamicIndexing = false;
+ features.shaderSampledImageArrayDynamicIndexing = false;
+ features.shaderStorageBufferArrayDynamicIndexing = false;
+ features.shaderStorageImageArrayDynamicIndexing = false;
+ features.shaderClipDistance = false;
+ features.shaderCullDistance = false;
+ features.shaderFloat64 = false;
+ features.shaderInt64 = false;
+ features.shaderInt16 = false;
+ features.shaderResourceResidency = false;
+ features.shaderResourceMinLod = false;
+ features.sparseBinding = false;
+ features.sparseResidencyBuffer = false;
+ features.sparseResidencyImage2D = false;
+ features.sparseResidencyImage3D = false;
+ features.sparseResidency2Samples = false;
+ features.sparseResidency4Samples = false;
+ features.sparseResidency8Samples = false;
+ features.sparseResidency16Samples = false;
+ features.sparseResidencyAliased = false;
+ features.variableMultisampleRate = false;
+ features.inheritedQueries = false;
+
+ VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage;
+ bit16_storage.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR;
+ bit16_storage.pNext = nullptr;
+ bit16_storage.storageBuffer16BitAccess = false;
bit16_storage.uniformAndStorageBuffer16BitAccess = true;
+ bit16_storage.storagePushConstant16 = false;
+ bit16_storage.storageInputOutput16 = false;
SetNext(next, bit16_storage);
- vk::PhysicalDevice8BitStorageFeaturesKHR bit8_storage;
+ VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage;
+ bit8_storage.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR;
+ bit8_storage.pNext = nullptr;
+ bit8_storage.storageBuffer8BitAccess = false;
bit8_storage.uniformAndStorageBuffer8BitAccess = true;
+ bit8_storage.storagePushConstant8 = false;
SetNext(next, bit8_storage);
- vk::PhysicalDeviceHostQueryResetFeaturesEXT host_query_reset;
+ VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset;
+ host_query_reset.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT;
host_query_reset.hostQueryReset = true;
SetNext(next, host_query_reset);
- vk::PhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
+ VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
if (is_float16_supported) {
+ float16_int8.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR;
+ float16_int8.pNext = nullptr;
float16_int8.shaderFloat16 = true;
+ float16_int8.shaderInt8 = false;
SetNext(next, float16_int8);
} else {
LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
}
- vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
+ VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
if (khr_uniform_buffer_standard_layout) {
+ std430_layout.sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR;
+ std430_layout.pNext = nullptr;
std430_layout.uniformBufferStandardLayout = true;
SetNext(next, std430_layout);
} else {
LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs");
}
- vk::PhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
+ VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
if (ext_index_type_uint8) {
+ index_type_uint8.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT;
+ index_type_uint8.pNext = nullptr;
index_type_uint8.indexTypeUint8 = true;
SetNext(next, index_type_uint8);
} else {
LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes");
}
- vk::PhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback;
+ VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback;
if (ext_transform_feedback) {
+ transform_feedback.sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT;
+ transform_feedback.pNext = nullptr;
transform_feedback.transformFeedback = true;
transform_feedback.geometryStreams = true;
SetNext(next, transform_feedback);
@@ -161,60 +296,48 @@ bool VKDevice::Create(vk::Instance instance) {
LOG_INFO(Render_Vulkan, "Device doesn't support depth range unrestricted");
}
- vk::DeviceCreateInfo device_ci({}, static_cast<u32>(queue_cis.size()), queue_cis.data(), 0,
- nullptr, static_cast<u32>(extensions.size()), extensions.data(),
- nullptr);
- device_ci.pNext = &features2;
-
- vk::Device unsafe_logical;
- if (physical.createDevice(&device_ci, nullptr, &unsafe_logical, dld) != vk::Result::eSuccess) {
- LOG_CRITICAL(Render_Vulkan, "Logical device failed to be created!");
+ logical = vk::Device::Create(physical, queue_cis, extensions, features2, dld);
+ if (!logical) {
+ LOG_ERROR(Render_Vulkan, "Failed to create logical device");
return false;
}
- dld.init(instance, dld.vkGetInstanceProcAddr, unsafe_logical);
- logical = UniqueDevice(unsafe_logical, {nullptr, dld});
CollectTelemetryParameters();
- graphics_queue = logical->getQueue(graphics_family, 0, dld);
- present_queue = logical->getQueue(present_family, 0, dld);
+ graphics_queue = logical.GetQueue(graphics_family);
+ present_queue = logical.GetQueue(present_family);
return true;
}
-vk::Format VKDevice::GetSupportedFormat(vk::Format wanted_format,
- vk::FormatFeatureFlags wanted_usage,
- FormatType format_type) const {
+VkFormat VKDevice::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
+ FormatType format_type) const {
if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
return wanted_format;
}
// The wanted format is not supported by hardware, search for alternatives
- const vk::Format* alternatives = GetFormatAlternatives(wanted_format);
+ const VkFormat* alternatives = GetFormatAlternatives(wanted_format);
if (alternatives == nullptr) {
UNREACHABLE_MSG("Format={} with usage={} and type={} has no defined alternatives and host "
"hardware does not support it",
- vk::to_string(wanted_format), vk::to_string(wanted_usage),
- static_cast<u32>(format_type));
+ wanted_format, wanted_usage, format_type);
return wanted_format;
}
std::size_t i = 0;
- for (vk::Format alternative = alternatives[0]; alternative != vk::Format{};
- alternative = alternatives[++i]) {
+ for (VkFormat alternative = *alternatives; alternative; alternative = alternatives[++i]) {
if (!IsFormatSupported(alternative, wanted_usage, format_type)) {
continue;
}
LOG_WARNING(Render_Vulkan,
"Emulating format={} with alternative format={} with usage={} and type={}",
- static_cast<u32>(wanted_format), static_cast<u32>(alternative),
- static_cast<u32>(wanted_usage), static_cast<u32>(format_type));
+ wanted_format, alternative, wanted_usage, format_type);
return alternative;
}
// No alternatives found, panic
UNREACHABLE_MSG("Format={} with usage={} and type={} is not supported by the host hardware and "
"doesn't support any of the alternatives",
- static_cast<u32>(wanted_format), static_cast<u32>(wanted_usage),
- static_cast<u32>(format_type));
+ wanted_format, wanted_usage, format_type);
return wanted_format;
}
@@ -228,38 +351,39 @@ void VKDevice::ReportLoss() const {
return;
}
- [[maybe_unused]] const std::vector data = graphics_queue.getCheckpointDataNV(dld);
+ [[maybe_unused]] const std::vector data = graphics_queue.GetCheckpointDataNV(dld);
// Catch here in debug builds (or with optimizations disabled) the last graphics pipeline to be
// executed. It can be done on a debugger by evaluating the expression:
// *(VKGraphicsPipeline*)data[0]
}
-bool VKDevice::IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features) const {
+bool VKDevice::IsOptimalAstcSupported(const VkPhysicalDeviceFeatures& features) const {
// Disable for now to avoid converting ASTC twice.
static constexpr std::array astc_formats = {
- vk::Format::eAstc4x4UnormBlock, vk::Format::eAstc4x4SrgbBlock,
- vk::Format::eAstc5x4UnormBlock, vk::Format::eAstc5x4SrgbBlock,
- vk::Format::eAstc5x5UnormBlock, vk::Format::eAstc5x5SrgbBlock,
- vk::Format::eAstc6x5UnormBlock, vk::Format::eAstc6x5SrgbBlock,
- vk::Format::eAstc6x6UnormBlock, vk::Format::eAstc6x6SrgbBlock,
- vk::Format::eAstc8x5UnormBlock, vk::Format::eAstc8x5SrgbBlock,
- vk::Format::eAstc8x6UnormBlock, vk::Format::eAstc8x6SrgbBlock,
- vk::Format::eAstc8x8UnormBlock, vk::Format::eAstc8x8SrgbBlock,
- vk::Format::eAstc10x5UnormBlock, vk::Format::eAstc10x5SrgbBlock,
- vk::Format::eAstc10x6UnormBlock, vk::Format::eAstc10x6SrgbBlock,
- vk::Format::eAstc10x8UnormBlock, vk::Format::eAstc10x8SrgbBlock,
- vk::Format::eAstc10x10UnormBlock, vk::Format::eAstc10x10SrgbBlock,
- vk::Format::eAstc12x10UnormBlock, vk::Format::eAstc12x10SrgbBlock,
- vk::Format::eAstc12x12UnormBlock, vk::Format::eAstc12x12SrgbBlock};
+ VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
+ VK_FORMAT_ASTC_5x4_UNORM_BLOCK, VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
+ VK_FORMAT_ASTC_5x5_UNORM_BLOCK, VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
+ VK_FORMAT_ASTC_6x5_UNORM_BLOCK, VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
+ VK_FORMAT_ASTC_6x6_UNORM_BLOCK, VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
+ VK_FORMAT_ASTC_8x5_UNORM_BLOCK, VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
+ VK_FORMAT_ASTC_8x6_UNORM_BLOCK, VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
+ VK_FORMAT_ASTC_8x8_UNORM_BLOCK, VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
+ VK_FORMAT_ASTC_10x5_UNORM_BLOCK, VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
+ VK_FORMAT_ASTC_10x6_UNORM_BLOCK, VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
+ VK_FORMAT_ASTC_10x8_UNORM_BLOCK, VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
+ VK_FORMAT_ASTC_10x10_UNORM_BLOCK, VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
+ VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
+ VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
+ };
if (!features.textureCompressionASTC_LDR) {
return false;
}
const auto format_feature_usage{
- vk::FormatFeatureFlagBits::eSampledImage | vk::FormatFeatureFlagBits::eBlitSrc |
- vk::FormatFeatureFlagBits::eBlitDst | vk::FormatFeatureFlagBits::eTransferSrc |
- vk::FormatFeatureFlagBits::eTransferDst};
+ VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT |
+ VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
+ VK_FORMAT_FEATURE_TRANSFER_DST_BIT};
for (const auto format : astc_formats) {
- const auto format_properties{physical.getFormatProperties(format, dld)};
+ const auto format_properties{physical.GetFormatProperties(format)};
if (!(format_properties.optimalTilingFeatures & format_feature_usage)) {
return false;
}
@@ -267,61 +391,49 @@ bool VKDevice::IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features
return true;
}
-bool VKDevice::IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage,
+bool VKDevice::IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
FormatType format_type) const {
const auto it = format_properties.find(wanted_format);
if (it == format_properties.end()) {
- UNIMPLEMENTED_MSG("Unimplemented format query={}", vk::to_string(wanted_format));
+ UNIMPLEMENTED_MSG("Unimplemented format query={}", wanted_format);
return true;
}
const auto supported_usage = GetFormatFeatures(it->second, format_type);
return (supported_usage & wanted_usage) == wanted_usage;
}
-bool VKDevice::IsSuitable(vk::PhysicalDevice physical, vk::SurfaceKHR surface,
- const vk::DispatchLoaderDynamic& dld) {
- static constexpr std::array required_extensions = {
- VK_KHR_SWAPCHAIN_EXTENSION_NAME,
- VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
- VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
- VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME,
- VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME,
- VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME,
- VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME,
- VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME,
- };
+bool VKDevice::IsSuitable(vk::PhysicalDevice physical, VkSurfaceKHR surface) {
bool is_suitable = true;
- std::bitset<required_extensions.size()> available_extensions{};
+ std::bitset<REQUIRED_EXTENSIONS.size()> available_extensions;
- for (const auto& prop : physical.enumerateDeviceExtensionProperties(nullptr, dld)) {
- for (std::size_t i = 0; i < required_extensions.size(); ++i) {
+ for (const auto& prop : physical.EnumerateDeviceExtensionProperties()) {
+ for (std::size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
if (available_extensions[i]) {
continue;
}
- available_extensions[i] =
- required_extensions[i] == std::string_view{prop.extensionName};
+ const std::string_view name{prop.extensionName};
+ available_extensions[i] = name == REQUIRED_EXTENSIONS[i];
}
}
if (!available_extensions.all()) {
- for (std::size_t i = 0; i < required_extensions.size(); ++i) {
+ for (std::size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
if (available_extensions[i]) {
continue;
}
- LOG_ERROR(Render_Vulkan, "Missing required extension: {}", required_extensions[i]);
+ LOG_ERROR(Render_Vulkan, "Missing required extension: {}", REQUIRED_EXTENSIONS[i]);
is_suitable = false;
}
}
bool has_graphics{}, has_present{};
- const auto queue_family_properties = physical.getQueueFamilyProperties(dld);
+ const std::vector queue_family_properties = physical.GetQueueFamilyProperties();
for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) {
const auto& family = queue_family_properties[i];
if (family.queueCount == 0) {
continue;
}
- has_graphics |=
- (family.queueFlags & vk::QueueFlagBits::eGraphics) != static_cast<vk::QueueFlagBits>(0);
- has_present |= physical.getSurfaceSupportKHR(i, surface, dld) != 0;
+ has_graphics |= family.queueFlags & VK_QUEUE_GRAPHICS_BIT;
+ has_present |= physical.GetSurfaceSupportKHR(i, surface);
}
if (!has_graphics || !has_present) {
LOG_ERROR(Render_Vulkan, "Device lacks a graphics and present queue");
@@ -329,7 +441,7 @@ bool VKDevice::IsSuitable(vk::PhysicalDevice physical, vk::SurfaceKHR surface,
}
// TODO(Rodrigo): Check if the device matches all requeriments.
- const auto properties{physical.getProperties(dld)};
+ const auto properties{physical.GetProperties()};
const auto& limits{properties.limits};
constexpr u32 required_ubo_size = 65536;
@@ -346,7 +458,7 @@ bool VKDevice::IsSuitable(vk::PhysicalDevice physical, vk::SurfaceKHR surface,
is_suitable = false;
}
- const auto features{physical.getFeatures(dld)};
+ const auto features{physical.GetFeatures()};
const std::array feature_report = {
std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"),
std::make_pair(features.independentBlend, "independentBlend"),
@@ -380,7 +492,7 @@ bool VKDevice::IsSuitable(vk::PhysicalDevice physical, vk::SurfaceKHR surface,
std::vector<const char*> VKDevice::LoadExtensions() {
std::vector<const char*> extensions;
- const auto Test = [&](const vk::ExtensionProperties& extension,
+ const auto Test = [&](const VkExtensionProperties& extension,
std::optional<std::reference_wrapper<bool>> status, const char* name,
bool push) {
if (extension.extensionName != std::string_view(name)) {
@@ -394,22 +506,13 @@ std::vector<const char*> VKDevice::LoadExtensions() {
}
};
- extensions.reserve(15);
- extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
- extensions.push_back(VK_KHR_16BIT_STORAGE_EXTENSION_NAME);
- extensions.push_back(VK_KHR_8BIT_STORAGE_EXTENSION_NAME);
- extensions.push_back(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME);
- extensions.push_back(VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME);
- extensions.push_back(VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME);
- extensions.push_back(VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME);
- extensions.push_back(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME);
-
- [[maybe_unused]] const bool nsight =
- std::getenv("NVTX_INJECTION64_PATH") || std::getenv("NSIGHT_LAUNCHED");
+ extensions.reserve(7 + REQUIRED_EXTENSIONS.size());
+ extensions.insert(extensions.begin(), REQUIRED_EXTENSIONS.begin(), REQUIRED_EXTENSIONS.end());
+
bool has_khr_shader_float16_int8{};
bool has_ext_subgroup_size_control{};
bool has_ext_transform_feedback{};
- for (const auto& extension : physical.enumerateDeviceExtensionProperties(nullptr, dld)) {
+ for (const auto& extension : physical.EnumerateDeviceExtensionProperties()) {
Test(extension, khr_uniform_buffer_standard_layout,
VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true);
Test(extension, has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME,
@@ -429,38 +532,67 @@ std::vector<const char*> VKDevice::LoadExtensions() {
}
}
+ VkPhysicalDeviceFeatures2KHR features;
+ features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
+
+ VkPhysicalDeviceProperties2KHR properties;
+ properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
+
if (has_khr_shader_float16_int8) {
- is_float16_supported =
- GetFeatures<vk::PhysicalDeviceFloat16Int8FeaturesKHR>(physical, dld).shaderFloat16;
+ VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8_features;
+ float16_int8_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR;
+ float16_int8_features.pNext = nullptr;
+ features.pNext = &float16_int8_features;
+
+ physical.GetFeatures2KHR(features);
+ is_float16_supported = float16_int8_features.shaderFloat16;
extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME);
}
if (has_ext_subgroup_size_control) {
- const auto features =
- GetFeatures<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>(physical, dld);
- const auto properties =
- GetProperties<vk::PhysicalDeviceSubgroupSizeControlPropertiesEXT>(physical, dld);
-
- is_warp_potentially_bigger = properties.maxSubgroupSize > GuestWarpSize;
-
- if (features.subgroupSizeControl && properties.minSubgroupSize <= GuestWarpSize &&
- properties.maxSubgroupSize >= GuestWarpSize) {
+ VkPhysicalDeviceSubgroupSizeControlFeaturesEXT subgroup_features;
+ subgroup_features.sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT;
+ subgroup_features.pNext = nullptr;
+ features.pNext = &subgroup_features;
+ physical.GetFeatures2KHR(features);
+
+ VkPhysicalDeviceSubgroupSizeControlPropertiesEXT subgroup_properties;
+ subgroup_properties.sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT;
+ subgroup_properties.pNext = nullptr;
+ properties.pNext = &subgroup_properties;
+ physical.GetProperties2KHR(properties);
+
+ is_warp_potentially_bigger = subgroup_properties.maxSubgroupSize > GuestWarpSize;
+
+ if (subgroup_features.subgroupSizeControl &&
+ subgroup_properties.minSubgroupSize <= GuestWarpSize &&
+ subgroup_properties.maxSubgroupSize >= GuestWarpSize) {
extensions.push_back(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);
- guest_warp_stages = properties.requiredSubgroupSizeStages;
+ guest_warp_stages = subgroup_properties.requiredSubgroupSizeStages;
}
} else {
is_warp_potentially_bigger = true;
}
if (has_ext_transform_feedback) {
- const auto features =
- GetFeatures<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>(physical, dld);
- const auto properties =
- GetProperties<vk::PhysicalDeviceTransformFeedbackPropertiesEXT>(physical, dld);
-
- if (features.transformFeedback && features.geometryStreams &&
- properties.maxTransformFeedbackStreams >= 4 && properties.maxTransformFeedbackBuffers &&
- properties.transformFeedbackQueries && properties.transformFeedbackDraw) {
+ VkPhysicalDeviceTransformFeedbackFeaturesEXT tfb_features;
+ tfb_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT;
+ tfb_features.pNext = nullptr;
+ features.pNext = &tfb_features;
+ physical.GetFeatures2KHR(features);
+
+ VkPhysicalDeviceTransformFeedbackPropertiesEXT tfb_properties;
+ tfb_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT;
+ tfb_properties.pNext = nullptr;
+ properties.pNext = &tfb_properties;
+ physical.GetProperties2KHR(properties);
+
+ if (tfb_features.transformFeedback && tfb_features.geometryStreams &&
+ tfb_properties.maxTransformFeedbackStreams >= 4 &&
+ tfb_properties.maxTransformFeedbackBuffers && tfb_properties.transformFeedbackQueries &&
+ tfb_properties.transformFeedbackDraw) {
extensions.push_back(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
ext_transform_feedback = true;
}
@@ -469,10 +601,10 @@ std::vector<const char*> VKDevice::LoadExtensions() {
return extensions;
}
-void VKDevice::SetupFamilies(vk::SurfaceKHR surface) {
+void VKDevice::SetupFamilies(VkSurfaceKHR surface) {
std::optional<u32> graphics_family_, present_family_;
- const auto queue_family_properties = physical.getQueueFamilyProperties(dld);
+ const std::vector queue_family_properties = physical.GetQueueFamilyProperties();
for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) {
if (graphics_family_ && present_family_)
break;
@@ -481,10 +613,10 @@ void VKDevice::SetupFamilies(vk::SurfaceKHR surface) {
if (queue_family.queueCount == 0)
continue;
- if (queue_family.queueFlags & vk::QueueFlagBits::eGraphics) {
+ if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
graphics_family_ = i;
}
- if (physical.getSurfaceSupportKHR(i, surface, dld)) {
+ if (physical.GetSurfaceSupportKHR(i, surface)) {
present_family_ = i;
}
}
@@ -495,120 +627,48 @@ void VKDevice::SetupFamilies(vk::SurfaceKHR surface) {
}
void VKDevice::SetupFeatures() {
- const auto supported_features{physical.getFeatures(dld)};
+ const auto supported_features{physical.GetFeatures()};
is_formatless_image_load_supported = supported_features.shaderStorageImageReadWithoutFormat;
is_optimal_astc_supported = IsOptimalAstcSupported(supported_features);
}
void VKDevice::CollectTelemetryParameters() {
- const auto driver = GetProperties<vk::PhysicalDeviceDriverPropertiesKHR>(physical, dld);
+ VkPhysicalDeviceDriverPropertiesKHR driver;
+ driver.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
+ driver.pNext = nullptr;
+
+ VkPhysicalDeviceProperties2KHR properties;
+ properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
+ properties.pNext = &driver;
+ physical.GetProperties2KHR(properties);
+
driver_id = driver.driverID;
vendor_name = driver.driverName;
- const auto extensions = physical.enumerateDeviceExtensionProperties(nullptr, dld);
+ const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
reported_extensions.reserve(std::size(extensions));
for (const auto& extension : extensions) {
reported_extensions.push_back(extension.extensionName);
}
}
-std::vector<vk::DeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const {
- static const float QUEUE_PRIORITY = 1.0f;
+std::vector<VkDeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const {
+ static constexpr float QUEUE_PRIORITY = 1.0f;
- std::set<u32> unique_queue_families = {graphics_family, present_family};
- std::vector<vk::DeviceQueueCreateInfo> queue_cis;
+ std::unordered_set<u32> unique_queue_families = {graphics_family, present_family};
+ std::vector<VkDeviceQueueCreateInfo> queue_cis;
- for (u32 queue_family : unique_queue_families)
- queue_cis.push_back({{}, queue_family, 1, &QUEUE_PRIORITY});
+ for (const u32 queue_family : unique_queue_families) {
+ VkDeviceQueueCreateInfo& ci = queue_cis.emplace_back();
+ ci.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
+ ci.pNext = nullptr;
+ ci.flags = 0;
+ ci.queueFamilyIndex = queue_family;
+ ci.queueCount = 1;
+ ci.pQueuePriorities = &QUEUE_PRIORITY;
+ }
return queue_cis;
}
-std::unordered_map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperties(
- const vk::DispatchLoaderDynamic& dld, vk::PhysicalDevice physical) {
- static constexpr std::array formats{vk::Format::eA8B8G8R8UnormPack32,
- vk::Format::eA8B8G8R8UintPack32,
- vk::Format::eA8B8G8R8SnormPack32,
- vk::Format::eA8B8G8R8SrgbPack32,
- vk::Format::eB5G6R5UnormPack16,
- vk::Format::eA2B10G10R10UnormPack32,
- vk::Format::eA1R5G5B5UnormPack16,
- vk::Format::eR32G32B32A32Sfloat,
- vk::Format::eR32G32B32A32Uint,
- vk::Format::eR32G32Sfloat,
- vk::Format::eR32G32Uint,
- vk::Format::eR16G16B16A16Uint,
- vk::Format::eR16G16B16A16Snorm,
- vk::Format::eR16G16B16A16Unorm,
- vk::Format::eR16G16Unorm,
- vk::Format::eR16G16Snorm,
- vk::Format::eR16G16Sfloat,
- vk::Format::eR16Unorm,
- vk::Format::eR8G8B8A8Srgb,
- vk::Format::eR8G8Unorm,
- vk::Format::eR8G8Snorm,
- vk::Format::eR8Unorm,
- vk::Format::eR8Uint,
- vk::Format::eB10G11R11UfloatPack32,
- vk::Format::eR32Sfloat,
- vk::Format::eR32Uint,
- vk::Format::eR32Sint,
- vk::Format::eR16Sfloat,
- vk::Format::eR16G16B16A16Sfloat,
- vk::Format::eB8G8R8A8Unorm,
- vk::Format::eR4G4B4A4UnormPack16,
- vk::Format::eD32Sfloat,
- vk::Format::eD16Unorm,
- vk::Format::eD16UnormS8Uint,
- vk::Format::eD24UnormS8Uint,
- vk::Format::eD32SfloatS8Uint,
- vk::Format::eBc1RgbaUnormBlock,
- vk::Format::eBc2UnormBlock,
- vk::Format::eBc3UnormBlock,
- vk::Format::eBc4UnormBlock,
- vk::Format::eBc5UnormBlock,
- vk::Format::eBc5SnormBlock,
- vk::Format::eBc7UnormBlock,
- vk::Format::eBc6HUfloatBlock,
- vk::Format::eBc6HSfloatBlock,
- vk::Format::eBc1RgbaSrgbBlock,
- vk::Format::eBc2SrgbBlock,
- vk::Format::eBc3SrgbBlock,
- vk::Format::eBc7SrgbBlock,
- vk::Format::eAstc4x4UnormBlock,
- vk::Format::eAstc4x4SrgbBlock,
- vk::Format::eAstc5x4UnormBlock,
- vk::Format::eAstc5x4SrgbBlock,
- vk::Format::eAstc5x5UnormBlock,
- vk::Format::eAstc5x5SrgbBlock,
- vk::Format::eAstc6x5UnormBlock,
- vk::Format::eAstc6x5SrgbBlock,
- vk::Format::eAstc6x6UnormBlock,
- vk::Format::eAstc6x6SrgbBlock,
- vk::Format::eAstc8x5UnormBlock,
- vk::Format::eAstc8x5SrgbBlock,
- vk::Format::eAstc8x6UnormBlock,
- vk::Format::eAstc8x6SrgbBlock,
- vk::Format::eAstc8x8UnormBlock,
- vk::Format::eAstc8x8SrgbBlock,
- vk::Format::eAstc10x5UnormBlock,
- vk::Format::eAstc10x5SrgbBlock,
- vk::Format::eAstc10x6UnormBlock,
- vk::Format::eAstc10x6SrgbBlock,
- vk::Format::eAstc10x8UnormBlock,
- vk::Format::eAstc10x8SrgbBlock,
- vk::Format::eAstc10x10UnormBlock,
- vk::Format::eAstc10x10SrgbBlock,
- vk::Format::eAstc12x10UnormBlock,
- vk::Format::eAstc12x10SrgbBlock,
- vk::Format::eAstc12x12UnormBlock,
- vk::Format::eAstc12x12SrgbBlock,
- vk::Format::eE5B9G9R9UfloatPack32};
- std::unordered_map<vk::Format, vk::FormatProperties> format_properties;
- for (const auto format : formats) {
- format_properties.emplace(format, physical.getFormatProperties(format, dld));
- }
- return format_properties;
-}
-
} // namespace Vulkan