2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2021-07-03 09:07:50 +02:00
|
|
|
#include <algorithm>
|
2019-09-13 06:55:28 +02:00
|
|
|
#include <bitset>
|
2019-12-19 06:09:05 +01:00
|
|
|
#include <chrono>
|
2019-02-12 22:28:05 +01:00
|
|
|
#include <optional>
|
2019-12-19 06:09:05 +01:00
|
|
|
#include <thread>
|
2020-03-27 05:33:21 +01:00
|
|
|
#include <unordered_set>
|
2020-03-30 10:21:59 +02:00
|
|
|
#include <utility>
|
2019-02-12 22:28:05 +01:00
|
|
|
#include <vector>
|
2020-04-02 07:32:58 +02:00
|
|
|
|
2019-02-12 22:28:05 +01:00
|
|
|
#include "common/assert.h"
|
2022-01-16 04:43:06 +01:00
|
|
|
#include "common/literals.h"
|
2021-04-15 01:07:40 +02:00
|
|
|
#include "common/settings.h"
|
2020-12-26 05:26:52 +01:00
|
|
|
#include "video_core/vulkan_common/nsight_aftermath_tracker.h"
|
2020-12-26 05:19:46 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_device.h"
|
2020-12-25 01:30:11 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
2019-02-12 22:28:05 +01:00
|
|
|
|
|
|
|
namespace Vulkan {
|
2022-01-16 04:43:06 +01:00
|
|
|
using namespace Common::Literals;
|
2019-09-13 06:55:28 +02:00
|
|
|
namespace {
|
2019-12-09 05:04:48 +01:00
|
|
|
namespace Alternatives {
|
2021-11-17 21:08:08 +01:00
|
|
|
constexpr std::array STENCIL8_UINT{
|
|
|
|
VK_FORMAT_D16_UNORM_S8_UINT,
|
|
|
|
VK_FORMAT_D24_UNORM_S8_UINT,
|
|
|
|
VK_FORMAT_D32_SFLOAT_S8_UINT,
|
|
|
|
VK_FORMAT_UNDEFINED,
|
|
|
|
};
|
|
|
|
|
2021-01-17 00:30:33 +01:00
|
|
|
constexpr std::array DEPTH24_UNORM_STENCIL8_UINT{
|
2020-07-13 23:27:05 +02:00
|
|
|
VK_FORMAT_D32_SFLOAT_S8_UINT,
|
|
|
|
VK_FORMAT_D16_UNORM_S8_UINT,
|
2021-01-17 00:30:33 +01:00
|
|
|
VK_FORMAT_UNDEFINED,
|
2020-07-13 23:27:05 +02:00
|
|
|
};
|
|
|
|
|
2021-01-17 00:30:33 +01:00
|
|
|
constexpr std::array DEPTH16_UNORM_STENCIL8_UINT{
|
2020-07-13 23:27:05 +02:00
|
|
|
VK_FORMAT_D24_UNORM_S8_UINT,
|
|
|
|
VK_FORMAT_D32_SFLOAT_S8_UINT,
|
2021-01-17 00:30:33 +01:00
|
|
|
VK_FORMAT_UNDEFINED,
|
2020-07-13 23:27:05 +02:00
|
|
|
};
|
2022-02-18 09:44:34 +01:00
|
|
|
|
|
|
|
constexpr std::array B5G6R5_UNORM_PACK16{
|
|
|
|
VK_FORMAT_R5G6B5_UNORM_PACK16,
|
|
|
|
VK_FORMAT_UNDEFINED,
|
|
|
|
};
|
2022-04-13 17:01:57 +02:00
|
|
|
|
|
|
|
constexpr std::array R4G4_UNORM_PACK8{
|
|
|
|
VK_FORMAT_R8_UNORM,
|
|
|
|
VK_FORMAT_UNDEFINED,
|
|
|
|
};
|
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
} // namespace Alternatives
|
|
|
|
|
2021-07-21 02:51:10 +02:00
|
|
|
enum class NvidiaArchitecture {
|
|
|
|
AmpereOrNewer,
|
|
|
|
Turing,
|
|
|
|
VoltaOrOlder,
|
|
|
|
};
|
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
constexpr std::array REQUIRED_EXTENSIONS{
|
2020-06-29 07:48:29 +02:00
|
|
|
VK_KHR_MAINTENANCE1_EXTENSION_NAME,
|
|
|
|
VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME,
|
|
|
|
VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME,
|
2020-03-27 05:33:21 +01:00
|
|
|
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,
|
2020-09-10 08:43:30 +02:00
|
|
|
VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME,
|
2020-12-30 06:25:23 +01:00
|
|
|
VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME,
|
2021-02-20 07:30:13 +01:00
|
|
|
VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME,
|
2021-04-13 10:32:21 +02:00
|
|
|
VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME,
|
2020-03-27 05:33:21 +01:00
|
|
|
VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME,
|
|
|
|
VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME,
|
|
|
|
VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME,
|
2021-02-13 07:31:50 +01:00
|
|
|
VK_EXT_ROBUSTNESS_2_EXTENSION_NAME,
|
2020-03-27 05:33:21 +01:00
|
|
|
VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME,
|
2021-03-19 23:28:31 +01:00
|
|
|
VK_EXT_SHADER_DEMOTE_TO_HELPER_INVOCATION_EXTENSION_NAME,
|
2021-01-17 00:40:39 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME,
|
|
|
|
#endif
|
2021-03-29 00:58:48 +02:00
|
|
|
#ifdef __unix__
|
2021-01-17 00:40:39 +01:00
|
|
|
VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,
|
|
|
|
#endif
|
2020-03-27 05:33:21 +01:00
|
|
|
};
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
template <typename T>
|
|
|
|
void SetNext(void**& next, T& data) {
|
|
|
|
*next = &data;
|
|
|
|
next = &data.pNext;
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
constexpr const VkFormat* GetFormatAlternatives(VkFormat format) {
|
2019-02-12 22:28:05 +01:00
|
|
|
switch (format) {
|
2021-11-17 21:08:08 +01:00
|
|
|
case VK_FORMAT_S8_UINT:
|
|
|
|
return Alternatives::STENCIL8_UINT.data();
|
2020-03-27 05:33:21 +01:00
|
|
|
case VK_FORMAT_D24_UNORM_S8_UINT:
|
2021-01-17 00:30:33 +01:00
|
|
|
return Alternatives::DEPTH24_UNORM_STENCIL8_UINT.data();
|
2020-03-27 05:33:21 +01:00
|
|
|
case VK_FORMAT_D16_UNORM_S8_UINT:
|
2021-01-17 00:30:33 +01:00
|
|
|
return Alternatives::DEPTH16_UNORM_STENCIL8_UINT.data();
|
2022-02-18 09:44:34 +01:00
|
|
|
case VK_FORMAT_B5G6R5_UNORM_PACK16:
|
|
|
|
return Alternatives::B5G6R5_UNORM_PACK16.data();
|
2022-04-13 17:01:57 +02:00
|
|
|
case VK_FORMAT_R4G4_UNORM_PACK8:
|
|
|
|
return Alternatives::R4G4_UNORM_PACK8.data();
|
2019-02-12 22:28:05 +01:00
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkFormatFeatureFlags GetFormatFeatures(VkFormatProperties properties, FormatType format_type) {
|
2019-02-12 22:28:05 +01:00
|
|
|
switch (format_type) {
|
|
|
|
case FormatType::Linear:
|
|
|
|
return properties.linearTilingFeatures;
|
|
|
|
case FormatType::Optimal:
|
|
|
|
return properties.optimalTilingFeatures;
|
|
|
|
case FormatType::Buffer:
|
|
|
|
return properties.bufferFeatures;
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 06:55:08 +01:00
|
|
|
std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties(vk::PhysicalDevice physical) {
|
2020-06-02 07:11:32 +02:00
|
|
|
static constexpr std::array formats{
|
|
|
|
VK_FORMAT_A8B8G8R8_UNORM_PACK32,
|
|
|
|
VK_FORMAT_A8B8G8R8_UINT_PACK32,
|
|
|
|
VK_FORMAT_A8B8G8R8_SNORM_PACK32,
|
2020-06-30 09:31:48 +02:00
|
|
|
VK_FORMAT_A8B8G8R8_SINT_PACK32,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_A8B8G8R8_SRGB_PACK32,
|
2021-11-05 15:31:40 +01:00
|
|
|
VK_FORMAT_R5G6B5_UNORM_PACK16,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_B5G6R5_UNORM_PACK16,
|
2022-04-13 17:01:57 +02:00
|
|
|
VK_FORMAT_R5G5B5A1_UNORM_PACK16,
|
|
|
|
VK_FORMAT_B5G5R5A1_UNORM_PACK16,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_A2B10G10R10_UNORM_PACK32,
|
2020-06-30 09:53:48 +02:00
|
|
|
VK_FORMAT_A2B10G10R10_UINT_PACK32,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_A1R5G5B5_UNORM_PACK16,
|
|
|
|
VK_FORMAT_R32G32B32A32_SFLOAT,
|
2020-06-30 09:46:07 +02:00
|
|
|
VK_FORMAT_R32G32B32A32_SINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R32G32B32A32_UINT,
|
|
|
|
VK_FORMAT_R32G32_SFLOAT,
|
2020-06-30 09:23:03 +02:00
|
|
|
VK_FORMAT_R32G32_SINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R32G32_UINT,
|
2020-06-30 09:38:29 +02:00
|
|
|
VK_FORMAT_R16G16B16A16_SINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R16G16B16A16_UINT,
|
|
|
|
VK_FORMAT_R16G16B16A16_SNORM,
|
|
|
|
VK_FORMAT_R16G16B16A16_UNORM,
|
|
|
|
VK_FORMAT_R16G16_UNORM,
|
|
|
|
VK_FORMAT_R16G16_SNORM,
|
|
|
|
VK_FORMAT_R16G16_SFLOAT,
|
2021-12-08 16:55:11 +01:00
|
|
|
VK_FORMAT_R16G16_UINT,
|
2020-12-30 06:25:23 +01:00
|
|
|
VK_FORMAT_R16G16_SINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R16_UNORM,
|
2021-07-07 05:18:30 +02:00
|
|
|
VK_FORMAT_R16_SNORM,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R16_UINT,
|
|
|
|
VK_FORMAT_R8G8B8A8_SRGB,
|
|
|
|
VK_FORMAT_R8G8_UNORM,
|
|
|
|
VK_FORMAT_R8G8_SNORM,
|
2020-06-30 09:13:46 +02:00
|
|
|
VK_FORMAT_R8G8_SINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R8G8_UINT,
|
|
|
|
VK_FORMAT_R8_UNORM,
|
2020-06-30 08:51:42 +02:00
|
|
|
VK_FORMAT_R8_SNORM,
|
2020-06-30 09:00:23 +02:00
|
|
|
VK_FORMAT_R8_SINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
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_B8G8R8A8_SRGB,
|
2022-04-13 17:01:57 +02:00
|
|
|
VK_FORMAT_R4G4_UNORM_PACK8,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R4G4B4A4_UNORM_PACK16,
|
2022-04-13 17:01:57 +02:00
|
|
|
VK_FORMAT_B4G4R4A4_UNORM_PACK16,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_D32_SFLOAT,
|
|
|
|
VK_FORMAT_D16_UNORM,
|
2021-11-17 21:08:08 +01:00
|
|
|
VK_FORMAT_S8_UINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
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,
|
2020-07-01 06:18:43 +02:00
|
|
|
VK_FORMAT_BC4_SNORM_BLOCK,
|
2020-06-02 07:11:32 +02:00
|
|
|
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,
|
2020-12-30 06:25:23 +01:00
|
|
|
VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
|
2020-12-30 06:25:23 +01:00
|
|
|
VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
|
|
|
|
VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
|
|
|
|
VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
|
2020-12-30 06:25:23 +01:00
|
|
|
VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
|
|
|
|
VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
|
|
|
|
VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
|
2020-12-30 06:25:23 +01:00
|
|
|
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,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
|
|
|
|
VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
|
2020-12-30 06:25:23 +01:00
|
|
|
VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
|
|
|
|
VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
|
2020-06-02 07:11:32 +02:00
|
|
|
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,
|
|
|
|
};
|
2020-03-27 05:33:21 +01:00
|
|
|
std::unordered_map<VkFormat, VkFormatProperties> format_properties;
|
|
|
|
for (const auto format : formats) {
|
|
|
|
format_properties.emplace(format, physical.GetFormatProperties(format));
|
|
|
|
}
|
|
|
|
return format_properties;
|
|
|
|
}
|
|
|
|
|
2021-07-03 07:49:59 +02:00
|
|
|
std::vector<std::string> GetSupportedExtensions(vk::PhysicalDevice physical) {
|
|
|
|
const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
|
2021-07-21 02:51:10 +02:00
|
|
|
std::vector<std::string> supported_extensions;
|
|
|
|
supported_extensions.reserve(extensions.size());
|
2021-07-03 07:49:59 +02:00
|
|
|
for (const auto& extension : extensions) {
|
|
|
|
supported_extensions.emplace_back(extension.extensionName);
|
|
|
|
}
|
|
|
|
return supported_extensions;
|
|
|
|
}
|
|
|
|
|
2022-02-25 22:30:13 +01:00
|
|
|
bool IsExtensionSupported(std::span<const std::string> supported_extensions,
|
|
|
|
std::string_view extension) {
|
|
|
|
return std::ranges::find(supported_extensions, extension) != supported_extensions.end();
|
|
|
|
}
|
|
|
|
|
2021-07-21 02:51:10 +02:00
|
|
|
NvidiaArchitecture GetNvidiaArchitecture(vk::PhysicalDevice physical,
|
|
|
|
std::span<const std::string> exts) {
|
2022-02-25 22:30:13 +01:00
|
|
|
if (IsExtensionSupported(exts, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME)) {
|
2021-07-21 02:51:10 +02:00
|
|
|
VkPhysicalDeviceFragmentShadingRatePropertiesKHR shading_rate_props{};
|
|
|
|
shading_rate_props.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_PROPERTIES_KHR;
|
|
|
|
VkPhysicalDeviceProperties2KHR physical_properties{};
|
|
|
|
physical_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
|
|
|
|
physical_properties.pNext = &shading_rate_props;
|
|
|
|
physical.GetProperties2KHR(physical_properties);
|
|
|
|
if (shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports) {
|
|
|
|
// Only Ampere and newer support this feature
|
|
|
|
return NvidiaArchitecture::AmpereOrNewer;
|
|
|
|
}
|
|
|
|
}
|
2022-02-25 22:30:13 +01:00
|
|
|
if (IsExtensionSupported(exts, VK_NV_SHADING_RATE_IMAGE_EXTENSION_NAME)) {
|
2021-07-21 02:51:10 +02:00
|
|
|
return NvidiaArchitecture::Turing;
|
|
|
|
}
|
|
|
|
return NvidiaArchitecture::VoltaOrOlder;
|
|
|
|
}
|
2019-12-09 05:04:48 +01:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR surface,
|
|
|
|
const vk::InstanceDispatch& dld_)
|
2020-12-30 06:25:23 +01:00
|
|
|
: instance{instance_}, dld{dld_}, physical{physical_}, properties{physical.GetProperties()},
|
2021-07-03 07:49:59 +02:00
|
|
|
supported_extensions{GetSupportedExtensions(physical)},
|
|
|
|
format_properties(GetFormatProperties(physical)) {
|
2021-01-17 00:38:20 +01:00
|
|
|
CheckSuitability(surface != nullptr);
|
2020-04-02 07:32:58 +02:00
|
|
|
SetupFamilies(surface);
|
|
|
|
SetupFeatures();
|
2021-02-20 07:30:13 +01:00
|
|
|
SetupProperties();
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
const auto queue_cis = GetDeviceQueueCreateInfos();
|
2021-01-17 00:38:20 +01:00
|
|
|
const std::vector extensions = LoadExtensions(surface != nullptr);
|
2019-09-13 06:55:28 +02:00
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
VkPhysicalDeviceFeatures2 features2{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
|
|
|
.pNext = nullptr,
|
2021-01-17 00:38:20 +01:00
|
|
|
.features{
|
2021-01-17 07:12:42 +01:00
|
|
|
.robustBufferAccess = true,
|
2021-01-17 00:38:20 +01:00
|
|
|
.fullDrawIndexUint32 = false,
|
|
|
|
.imageCubeArray = true,
|
|
|
|
.independentBlend = true,
|
|
|
|
.geometryShader = true,
|
|
|
|
.tessellationShader = true,
|
2021-04-16 22:22:59 +02:00
|
|
|
.sampleRateShading = true,
|
2021-04-22 21:19:14 +02:00
|
|
|
.dualSrcBlend = true,
|
2021-12-18 06:52:28 +01:00
|
|
|
.logicOp = true,
|
2021-01-17 00:38:20 +01:00
|
|
|
.multiDrawIndirect = false,
|
|
|
|
.drawIndirectFirstInstance = false,
|
|
|
|
.depthClamp = true,
|
|
|
|
.depthBiasClamp = true,
|
2021-04-16 03:46:11 +02:00
|
|
|
.fillModeNonSolid = true,
|
2021-05-31 01:43:47 +02:00
|
|
|
.depthBounds = is_depth_bounds_supported,
|
2021-06-25 10:21:51 +02:00
|
|
|
.wideLines = true,
|
2021-01-17 00:38:20 +01:00
|
|
|
.largePoints = true,
|
|
|
|
.alphaToOne = false,
|
|
|
|
.multiViewport = true,
|
|
|
|
.samplerAnisotropy = true,
|
|
|
|
.textureCompressionETC2 = false,
|
|
|
|
.textureCompressionASTC_LDR = is_optimal_astc_supported,
|
|
|
|
.textureCompressionBC = false,
|
|
|
|
.occlusionQueryPrecise = true,
|
|
|
|
.pipelineStatisticsQuery = false,
|
|
|
|
.vertexPipelineStoresAndAtomics = true,
|
|
|
|
.fragmentStoresAndAtomics = true,
|
|
|
|
.shaderTessellationAndGeometryPointSize = false,
|
|
|
|
.shaderImageGatherExtended = true,
|
|
|
|
.shaderStorageImageExtendedFormats = false,
|
|
|
|
.shaderStorageImageMultisample = is_shader_storage_image_multisample,
|
|
|
|
.shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported,
|
|
|
|
.shaderStorageImageWriteWithoutFormat = true,
|
|
|
|
.shaderUniformBufferArrayDynamicIndexing = false,
|
|
|
|
.shaderSampledImageArrayDynamicIndexing = false,
|
|
|
|
.shaderStorageBufferArrayDynamicIndexing = false,
|
|
|
|
.shaderStorageImageArrayDynamicIndexing = false,
|
2021-04-23 12:39:00 +02:00
|
|
|
.shaderClipDistance = true,
|
|
|
|
.shaderCullDistance = true,
|
2021-05-29 07:53:39 +02:00
|
|
|
.shaderFloat64 = is_shader_float64_supported,
|
|
|
|
.shaderInt64 = is_shader_int64_supported,
|
2021-05-31 01:44:28 +02:00
|
|
|
.shaderInt16 = is_shader_int16_supported,
|
2021-01-17 00:38:20 +01:00
|
|
|
.shaderResourceResidency = false,
|
|
|
|
.shaderResourceMinLod = false,
|
|
|
|
.sparseBinding = false,
|
|
|
|
.sparseResidencyBuffer = false,
|
|
|
|
.sparseResidencyImage2D = false,
|
|
|
|
.sparseResidencyImage3D = false,
|
|
|
|
.sparseResidency2Samples = false,
|
|
|
|
.sparseResidency4Samples = false,
|
|
|
|
.sparseResidency8Samples = false,
|
|
|
|
.sparseResidency16Samples = false,
|
|
|
|
.sparseResidencyAliased = false,
|
|
|
|
.variableMultisampleRate = false,
|
|
|
|
.inheritedQueries = false,
|
|
|
|
},
|
2020-07-13 23:27:05 +02:00
|
|
|
};
|
2020-03-30 10:21:59 +02:00
|
|
|
const void* first_next = &features2;
|
2019-09-13 06:55:28 +02:00
|
|
|
void** next = &features2.pNext;
|
2020-03-27 05:33:21 +01:00
|
|
|
|
2020-09-10 08:43:30 +02:00
|
|
|
VkPhysicalDeviceTimelineSemaphoreFeaturesKHR timeline_semaphore{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.timelineSemaphore = true,
|
|
|
|
};
|
|
|
|
SetNext(next, timeline_semaphore);
|
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
2021-05-23 09:28:34 +02:00
|
|
|
.storageBuffer16BitAccess = true,
|
2020-07-13 23:27:05 +02:00
|
|
|
.uniformAndStorageBuffer16BitAccess = true,
|
|
|
|
.storagePushConstant16 = false,
|
|
|
|
.storageInputOutput16 = false,
|
|
|
|
};
|
2019-12-09 05:04:48 +01:00
|
|
|
SetNext(next, bit16_storage);
|
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.storageBuffer8BitAccess = false,
|
|
|
|
.uniformAndStorageBuffer8BitAccess = true,
|
|
|
|
.storagePushConstant8 = false,
|
|
|
|
};
|
2019-12-09 05:04:48 +01:00
|
|
|
SetNext(next, bit8_storage);
|
2019-09-13 06:55:28 +02:00
|
|
|
|
2021-04-11 10:47:23 +02:00
|
|
|
VkPhysicalDeviceRobustness2FeaturesEXT robustness2{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.robustBufferAccess2 = true,
|
|
|
|
.robustImageAccess2 = true,
|
|
|
|
.nullDescriptor = true,
|
|
|
|
};
|
|
|
|
SetNext(next, robustness2);
|
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT,
|
2021-01-15 06:55:08 +01:00
|
|
|
.pNext = nullptr,
|
2020-07-13 23:27:05 +02:00
|
|
|
.hostQueryReset = true,
|
|
|
|
};
|
2020-02-11 22:59:44 +01:00
|
|
|
SetNext(next, host_query_reset);
|
|
|
|
|
2021-04-13 10:32:21 +02:00
|
|
|
VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointers{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.variablePointersStorageBuffer = VK_TRUE,
|
|
|
|
.variablePointers = VK_TRUE,
|
|
|
|
};
|
|
|
|
SetNext(next, variable_pointers);
|
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT demote{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.shaderDemoteToHelperInvocation = true,
|
|
|
|
};
|
|
|
|
SetNext(next, demote);
|
|
|
|
|
2021-09-16 06:54:24 +02:00
|
|
|
VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
|
2021-08-25 03:22:41 +02:00
|
|
|
if (is_int8_supported || is_float16_supported) {
|
2021-09-16 06:54:24 +02:00
|
|
|
float16_int8 = {
|
2020-07-13 23:27:05 +02:00
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
2021-08-25 03:22:41 +02:00
|
|
|
.shaderFloat16 = is_float16_supported,
|
|
|
|
.shaderInt8 = is_int8_supported,
|
2020-07-13 23:27:05 +02:00
|
|
|
};
|
2019-09-13 06:55:28 +02:00
|
|
|
SetNext(next, float16_int8);
|
2021-08-25 03:22:41 +02:00
|
|
|
}
|
|
|
|
if (!is_float16_supported) {
|
2019-09-13 06:55:28 +02:00
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
|
|
|
|
}
|
2021-08-25 03:22:41 +02:00
|
|
|
if (!is_int8_supported) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support int8 natively");
|
|
|
|
}
|
2019-09-13 06:55:28 +02:00
|
|
|
|
2020-05-04 23:31:17 +02:00
|
|
|
if (!nv_viewport_swizzle) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support viewport swizzles");
|
|
|
|
}
|
|
|
|
|
2021-04-16 21:31:15 +02:00
|
|
|
if (!nv_viewport_array2) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support viewport masks");
|
|
|
|
}
|
|
|
|
|
2021-06-24 07:41:09 +02:00
|
|
|
if (!nv_geometry_shader_passthrough) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support passthrough geometry shaders");
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
|
2019-09-13 06:55:28 +02:00
|
|
|
if (khr_uniform_buffer_standard_layout) {
|
2020-07-13 23:27:05 +02:00
|
|
|
std430_layout = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.uniformBufferStandardLayout = true,
|
|
|
|
};
|
2019-09-13 06:55:28 +02:00
|
|
|
SetNext(next, std430_layout);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs");
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
|
2019-09-13 06:55:28 +02:00
|
|
|
if (ext_index_type_uint8) {
|
2020-07-13 23:27:05 +02:00
|
|
|
index_type_uint8 = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.indexTypeUint8 = true,
|
|
|
|
};
|
2019-09-13 06:55:28 +02:00
|
|
|
SetNext(next, index_type_uint8);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes");
|
|
|
|
}
|
|
|
|
|
2021-12-18 05:47:48 +01:00
|
|
|
VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT primitive_topology_list_restart;
|
|
|
|
if (is_topology_list_restart_supported || is_patch_list_restart_supported) {
|
|
|
|
primitive_topology_list_restart = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.primitiveTopologyListRestart = is_topology_list_restart_supported,
|
|
|
|
.primitiveTopologyPatchListRestart = is_patch_list_restart_supported,
|
|
|
|
};
|
|
|
|
SetNext(next, primitive_topology_list_restart);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support list topology primitive restart");
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback;
|
2020-03-06 09:09:06 +01:00
|
|
|
if (ext_transform_feedback) {
|
2020-07-13 23:27:05 +02:00
|
|
|
transform_feedback = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.transformFeedback = true,
|
|
|
|
.geometryStreams = true,
|
|
|
|
};
|
2020-03-06 09:09:06 +01:00
|
|
|
SetNext(next, transform_feedback);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support transform feedbacks");
|
|
|
|
}
|
|
|
|
|
2020-05-04 21:41:19 +02:00
|
|
|
VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border;
|
|
|
|
if (ext_custom_border_color) {
|
2020-07-13 23:27:05 +02:00
|
|
|
custom_border = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.customBorderColors = VK_TRUE,
|
|
|
|
.customBorderColorWithoutFormat = VK_TRUE,
|
|
|
|
};
|
2020-05-04 21:41:19 +02:00
|
|
|
SetNext(next, custom_border);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support custom border colors");
|
|
|
|
}
|
|
|
|
|
2020-06-21 22:20:30 +02:00
|
|
|
VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
|
|
|
|
if (ext_extended_dynamic_state) {
|
2020-07-13 23:27:05 +02:00
|
|
|
dynamic_state = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.extendedDynamicState = VK_TRUE,
|
|
|
|
};
|
2020-06-21 22:20:30 +02:00
|
|
|
SetNext(next, dynamic_state);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state");
|
|
|
|
}
|
|
|
|
|
2021-06-25 10:25:19 +02:00
|
|
|
VkPhysicalDeviceLineRasterizationFeaturesEXT line_raster;
|
|
|
|
if (ext_line_rasterization) {
|
|
|
|
line_raster = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.rectangularLines = VK_TRUE,
|
|
|
|
.bresenhamLines = VK_FALSE,
|
|
|
|
.smoothLines = VK_TRUE,
|
|
|
|
.stippledRectangularLines = VK_FALSE,
|
|
|
|
.stippledBresenhamLines = VK_FALSE,
|
|
|
|
.stippledSmoothLines = VK_FALSE,
|
|
|
|
};
|
|
|
|
SetNext(next, line_raster);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support smooth lines");
|
|
|
|
}
|
|
|
|
|
2021-06-23 08:32:41 +02:00
|
|
|
if (!ext_conservative_rasterization) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support conservative rasterization");
|
|
|
|
}
|
|
|
|
|
2021-06-12 02:52:04 +02:00
|
|
|
VkPhysicalDeviceProvokingVertexFeaturesEXT provoking_vertex;
|
|
|
|
if (ext_provoking_vertex) {
|
|
|
|
provoking_vertex = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.provokingVertexLast = VK_TRUE,
|
|
|
|
.transformFeedbackPreservesProvokingVertex = VK_TRUE,
|
|
|
|
};
|
|
|
|
SetNext(next, provoking_vertex);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support provoking vertex last");
|
|
|
|
}
|
|
|
|
|
2021-06-13 04:25:40 +02:00
|
|
|
VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT vertex_input_dynamic;
|
|
|
|
if (ext_vertex_input_dynamic_state) {
|
|
|
|
vertex_input_dynamic = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.vertexInputDynamicState = VK_TRUE,
|
|
|
|
};
|
|
|
|
SetNext(next, vertex_input_dynamic);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support vertex input dynamic state");
|
|
|
|
}
|
|
|
|
|
2021-04-13 10:32:21 +02:00
|
|
|
VkPhysicalDeviceShaderAtomicInt64FeaturesKHR atomic_int64;
|
|
|
|
if (ext_shader_atomic_int64) {
|
|
|
|
atomic_int64 = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.shaderBufferInt64Atomics = VK_TRUE,
|
|
|
|
.shaderSharedInt64Atomics = VK_TRUE,
|
|
|
|
};
|
|
|
|
SetNext(next, atomic_int64);
|
|
|
|
}
|
|
|
|
|
2021-03-29 00:53:34 +02:00
|
|
|
VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR workgroup_layout;
|
2022-05-20 02:05:37 +02:00
|
|
|
if (khr_workgroup_memory_explicit_layout && is_shader_int16_supported) {
|
2021-03-29 00:53:34 +02:00
|
|
|
workgroup_layout = {
|
|
|
|
.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.workgroupMemoryExplicitLayout = VK_TRUE,
|
|
|
|
.workgroupMemoryExplicitLayoutScalarBlockLayout = VK_TRUE,
|
|
|
|
.workgroupMemoryExplicitLayout8BitAccess = VK_TRUE,
|
|
|
|
.workgroupMemoryExplicitLayout16BitAccess = VK_TRUE,
|
|
|
|
};
|
|
|
|
SetNext(next, workgroup_layout);
|
2022-05-20 02:05:37 +02:00
|
|
|
} else if (khr_workgroup_memory_explicit_layout) {
|
|
|
|
// TODO(lat9nq): Find a proper fix for this
|
|
|
|
LOG_WARNING(Render_Vulkan, "Disabling VK_KHR_workgroup_memory_explicit_layout due to a "
|
|
|
|
"yuzu bug when host driver does not support 16-bit integers");
|
|
|
|
khr_workgroup_memory_explicit_layout = false;
|
2021-03-29 00:53:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 00:15:32 +02:00
|
|
|
VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR executable_properties;
|
|
|
|
if (khr_pipeline_executable_properties) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Enabling shader feedback, expect slower shader build times");
|
|
|
|
executable_properties = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.pipelineExecutableInfo = VK_TRUE,
|
|
|
|
};
|
|
|
|
SetNext(next, executable_properties);
|
|
|
|
}
|
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
if (!ext_depth_range_unrestricted) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support depth range unrestricted");
|
|
|
|
}
|
|
|
|
|
2020-03-30 10:21:59 +02:00
|
|
|
VkDeviceDiagnosticsConfigCreateInfoNV diagnostics_nv;
|
2021-07-08 23:22:31 +02:00
|
|
|
if (Settings::values.enable_nsight_aftermath && nv_device_diagnostics_config) {
|
2020-12-26 05:26:52 +01:00
|
|
|
nsight_aftermath_tracker = std::make_unique<NsightAftermathTracker>();
|
2020-03-30 10:21:59 +02:00
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
diagnostics_nv = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV,
|
|
|
|
.pNext = &features2,
|
|
|
|
.flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV |
|
|
|
|
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
|
|
|
|
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV,
|
|
|
|
};
|
2020-03-30 10:21:59 +02:00
|
|
|
first_next = &diagnostics_nv;
|
|
|
|
}
|
|
|
|
logical = vk::Device::Create(physical, queue_cis, extensions, first_next, dld);
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2022-01-18 18:05:44 +01:00
|
|
|
is_integrated = properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
|
|
|
|
is_virtual = properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
|
|
|
|
is_non_gpu = properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_OTHER ||
|
|
|
|
properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU;
|
2022-01-16 04:43:06 +01:00
|
|
|
|
2021-06-17 00:29:48 +02:00
|
|
|
CollectPhysicalMemoryInfo();
|
2021-09-16 06:51:22 +02:00
|
|
|
CollectTelemetryParameters();
|
2020-12-30 06:25:23 +01:00
|
|
|
CollectToolingInfo();
|
2019-09-13 06:55:28 +02:00
|
|
|
|
2021-07-21 02:51:10 +02:00
|
|
|
if (driver_id == VK_DRIVER_ID_NVIDIA_PROPRIETARY_KHR) {
|
|
|
|
const auto arch = GetNvidiaArchitecture(physical, supported_extensions);
|
|
|
|
switch (arch) {
|
|
|
|
case NvidiaArchitecture::AmpereOrNewer:
|
2021-07-03 07:49:59 +02:00
|
|
|
LOG_WARNING(Render_Vulkan, "Blacklisting Ampere devices from float16 math");
|
|
|
|
is_float16_supported = false;
|
2021-07-21 02:51:10 +02:00
|
|
|
break;
|
|
|
|
case NvidiaArchitecture::Turing:
|
|
|
|
break;
|
|
|
|
case NvidiaArchitecture::VoltaOrOlder:
|
|
|
|
LOG_WARNING(Render_Vulkan, "Blacklisting Volta and older from VK_KHR_push_descriptor");
|
|
|
|
khr_push_descriptor = false;
|
|
|
|
break;
|
2021-07-03 07:49:59 +02:00
|
|
|
}
|
2022-03-24 04:30:17 +01:00
|
|
|
const u32 nv_major_version = (properties.driverVersion >> 22) & 0x3ff;
|
|
|
|
if (nv_major_version >= 510) {
|
|
|
|
LOG_WARNING(Render_Vulkan, "NVIDIA Drivers >= 510 do not support MSAA image blits");
|
|
|
|
cant_blit_msaa = true;
|
|
|
|
}
|
2021-07-03 07:49:59 +02:00
|
|
|
}
|
2022-02-25 22:30:13 +01:00
|
|
|
const bool is_radv = driver_id == VK_DRIVER_ID_MESA_RADV;
|
|
|
|
if (ext_extended_dynamic_state && is_radv) {
|
2021-06-29 23:58:32 +02:00
|
|
|
// Mask driver version variant
|
|
|
|
const u32 version = (properties.driverVersion << 3) >> 3;
|
|
|
|
if (version < VK_MAKE_API_VERSION(0, 21, 2, 0)) {
|
|
|
|
LOG_WARNING(Render_Vulkan,
|
|
|
|
"RADV versions older than 21.2 have broken VK_EXT_extended_dynamic_state");
|
|
|
|
ext_extended_dynamic_state = false;
|
|
|
|
}
|
2020-10-09 02:17:08 +02:00
|
|
|
}
|
2022-02-25 22:30:13 +01:00
|
|
|
if (ext_vertex_input_dynamic_state && is_radv) {
|
|
|
|
// TODO(ameerj): Blacklist only offending driver versions
|
|
|
|
// TODO(ameerj): Confirm if RDNA1 is affected
|
|
|
|
const bool is_rdna2 =
|
|
|
|
IsExtensionSupported(supported_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
|
|
|
|
if (is_rdna2) {
|
|
|
|
LOG_WARNING(Render_Vulkan,
|
|
|
|
"RADV has broken VK_EXT_vertex_input_dynamic_state on RDNA2 hardware");
|
|
|
|
ext_vertex_input_dynamic_state = false;
|
|
|
|
}
|
|
|
|
}
|
2021-08-29 21:56:36 +02:00
|
|
|
sets_per_pool = 64;
|
2021-09-24 00:11:18 +02:00
|
|
|
|
|
|
|
const bool is_amd =
|
|
|
|
driver_id == VK_DRIVER_ID_AMD_PROPRIETARY || driver_id == VK_DRIVER_ID_AMD_OPEN_SOURCE;
|
|
|
|
if (is_amd) {
|
2022-05-25 07:01:14 +02:00
|
|
|
// TODO(lat9nq): Add an upper bound when AMD fixes their VK_KHR_push_descriptor
|
|
|
|
const bool has_broken_push_descriptor = VK_VERSION_MAJOR(properties.driverVersion) == 2 &&
|
|
|
|
VK_VERSION_MINOR(properties.driverVersion) == 0 &&
|
|
|
|
VK_VERSION_PATCH(properties.driverVersion) >= 226;
|
|
|
|
if (khr_push_descriptor && has_broken_push_descriptor) {
|
|
|
|
LOG_WARNING(
|
|
|
|
Render_Vulkan,
|
|
|
|
"Disabling AMD driver 2.0.226 and later from broken VK_KHR_push_descriptor");
|
|
|
|
khr_push_descriptor = false;
|
|
|
|
}
|
|
|
|
|
2021-08-29 21:56:36 +02:00
|
|
|
// AMD drivers need a higher amount of Sets per Pool in certain circunstances like in XC2.
|
|
|
|
sets_per_pool = 96;
|
2021-09-24 00:11:18 +02:00
|
|
|
// Disable VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT on AMD GCN4 and lower as it is broken.
|
2021-08-29 21:56:36 +02:00
|
|
|
if (!is_float16_supported) {
|
|
|
|
LOG_WARNING(
|
|
|
|
Render_Vulkan,
|
2021-09-24 00:11:18 +02:00
|
|
|
"AMD GCN4 and earlier do not properly support VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT");
|
|
|
|
has_broken_cube_compatibility = true;
|
|
|
|
}
|
|
|
|
}
|
2022-02-25 22:30:13 +01:00
|
|
|
const bool is_amd_or_radv = is_amd || is_radv;
|
2021-09-24 00:11:18 +02:00
|
|
|
if (ext_sampler_filter_minmax && is_amd_or_radv) {
|
|
|
|
// Disable ext_sampler_filter_minmax on AMD GCN4 and lower as it is broken.
|
|
|
|
if (!is_float16_supported) {
|
|
|
|
LOG_WARNING(Render_Vulkan,
|
|
|
|
"Blacklisting AMD GCN4 and earlier for VK_EXT_sampler_filter_minmax");
|
2021-08-29 21:56:36 +02:00
|
|
|
ext_sampler_filter_minmax = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 04:30:10 +01:00
|
|
|
const bool is_intel_windows = driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS;
|
2022-02-18 09:44:34 +01:00
|
|
|
const bool is_intel_anv = driver_id == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA;
|
2021-12-24 04:30:10 +01:00
|
|
|
if (ext_vertex_input_dynamic_state && is_intel_windows) {
|
2021-06-16 03:48:55 +02:00
|
|
|
LOG_WARNING(Render_Vulkan, "Blacklisting Intel for VK_EXT_vertex_input_dynamic_state");
|
|
|
|
ext_vertex_input_dynamic_state = false;
|
|
|
|
}
|
2021-12-24 04:30:10 +01:00
|
|
|
if (is_float16_supported && is_intel_windows) {
|
2021-01-27 22:31:32 +01:00
|
|
|
// Intel's compiler crashes when using fp16 on Astral Chain, disable it for the time being.
|
2021-06-16 08:03:08 +02:00
|
|
|
LOG_WARNING(Render_Vulkan, "Blacklisting Intel proprietary from float16 math");
|
|
|
|
is_float16_supported = false;
|
2021-01-27 22:31:32 +01:00
|
|
|
}
|
2021-12-24 04:30:10 +01:00
|
|
|
if (is_intel_windows) {
|
|
|
|
LOG_WARNING(Render_Vulkan, "Intel proprietary drivers do not support MSAA image blits");
|
|
|
|
cant_blit_msaa = true;
|
|
|
|
}
|
2022-02-18 09:44:34 +01:00
|
|
|
if (is_intel_anv) {
|
|
|
|
LOG_WARNING(Render_Vulkan, "ANV driver does not support native BGR format");
|
|
|
|
must_emulate_bgr565 = true;
|
|
|
|
}
|
2020-10-09 02:17:08 +02:00
|
|
|
|
2021-09-23 03:14:10 +02:00
|
|
|
supports_d24_depth =
|
|
|
|
IsFormatSupported(VK_FORMAT_D24_UNORM_S8_UINT,
|
|
|
|
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT, FormatType::Optimal);
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
graphics_queue = logical.GetQueue(graphics_family);
|
|
|
|
present_queue = logical.GetQueue(present_family);
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
Device::~Device() = default;
|
2020-12-25 06:42:03 +01:00
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
VkFormat Device::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
|
|
|
|
FormatType format_type) const {
|
2019-02-12 22:28:05 +01:00
|
|
|
if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
|
|
|
|
return wanted_format;
|
|
|
|
}
|
|
|
|
// The wanted format is not supported by hardware, search for alternatives
|
2020-03-27 05:33:21 +01:00
|
|
|
const VkFormat* alternatives = GetFormatAlternatives(wanted_format);
|
2019-02-12 22:28:05 +01:00
|
|
|
if (alternatives == nullptr) {
|
2019-09-13 06:55:28 +02:00
|
|
|
UNREACHABLE_MSG("Format={} with usage={} and type={} has no defined alternatives and host "
|
|
|
|
"hardware does not support it",
|
2020-03-27 05:33:21 +01:00
|
|
|
wanted_format, wanted_usage, format_type);
|
2019-02-12 22:28:05 +01:00
|
|
|
return wanted_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t i = 0;
|
2020-03-27 05:33:21 +01:00
|
|
|
for (VkFormat alternative = *alternatives; alternative; alternative = alternatives[++i]) {
|
2019-09-13 06:55:28 +02:00
|
|
|
if (!IsFormatSupported(alternative, wanted_usage, format_type)) {
|
2019-02-12 22:28:05 +01:00
|
|
|
continue;
|
2019-09-13 06:55:28 +02:00
|
|
|
}
|
2019-02-12 22:28:05 +01:00
|
|
|
LOG_WARNING(Render_Vulkan,
|
|
|
|
"Emulating format={} with alternative format={} with usage={} and type={}",
|
2020-03-27 05:33:21 +01:00
|
|
|
wanted_format, alternative, wanted_usage, format_type);
|
2019-02-12 22:28:05 +01:00
|
|
|
return alternative;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No alternatives found, panic
|
2019-09-13 06:55:28 +02:00
|
|
|
UNREACHABLE_MSG("Format={} with usage={} and type={} is not supported by the host hardware and "
|
|
|
|
"doesn't support any of the alternatives",
|
2020-03-27 05:33:21 +01:00
|
|
|
wanted_format, wanted_usage, format_type);
|
2019-02-12 22:28:05 +01:00
|
|
|
return wanted_format;
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
void Device::ReportLoss() const {
|
2022-04-02 16:34:07 +02:00
|
|
|
LOG_CRITICAL(Render_Vulkan, "Device loss occurred!");
|
2019-12-19 06:09:05 +01:00
|
|
|
|
2020-03-30 10:21:59 +02:00
|
|
|
// Wait for the log to flush and for Nsight Aftermath to dump the results
|
2020-12-30 06:25:23 +01:00
|
|
|
std::this_thread::sleep_for(std::chrono::seconds{15});
|
2020-03-30 10:21:59 +02:00
|
|
|
}
|
2019-12-19 06:09:05 +01:00
|
|
|
|
2021-04-11 07:50:30 +02:00
|
|
|
void Device::SaveShader(std::span<const u32> spirv) const {
|
2020-12-26 05:26:52 +01:00
|
|
|
if (nsight_aftermath_tracker) {
|
|
|
|
nsight_aftermath_tracker->SaveShader(spirv);
|
|
|
|
}
|
2019-12-19 06:09:05 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
bool Device::IsOptimalAstcSupported(const VkPhysicalDeviceFeatures& features) const {
|
2020-04-02 07:32:58 +02:00
|
|
|
// Disable for now to avoid converting ASTC twice.
|
2019-12-09 05:04:48 +01:00
|
|
|
static constexpr std::array astc_formats = {
|
2020-03-27 05:33:21 +01:00
|
|
|
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,
|
|
|
|
};
|
2019-05-26 06:33:57 +02:00
|
|
|
if (!features.textureCompressionASTC_LDR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto format_feature_usage{
|
2020-03-27 05:33:21 +01:00
|
|
|
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};
|
2019-05-26 06:33:57 +02:00
|
|
|
for (const auto format : astc_formats) {
|
2020-12-05 10:51:14 +01:00
|
|
|
const auto physical_format_properties{physical.GetFormatProperties(format)};
|
|
|
|
if ((physical_format_properties.optimalTilingFeatures & format_feature_usage) == 0) {
|
2019-05-26 06:33:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
bool Device::TestDepthStencilBlits() const {
|
2020-12-30 06:25:23 +01:00
|
|
|
static constexpr VkFormatFeatureFlags required_features =
|
|
|
|
VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
|
|
|
const auto test_features = [](VkFormatProperties props) {
|
|
|
|
return (props.optimalTilingFeatures & required_features) == required_features;
|
|
|
|
};
|
|
|
|
return test_features(format_properties.at(VK_FORMAT_D32_SFLOAT_S8_UINT)) &&
|
|
|
|
test_features(format_properties.at(VK_FORMAT_D24_UNORM_S8_UINT));
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
bool Device::IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
|
|
|
|
FormatType format_type) const {
|
2019-02-12 22:28:05 +01:00
|
|
|
const auto it = format_properties.find(wanted_format);
|
|
|
|
if (it == format_properties.end()) {
|
2020-03-27 05:33:21 +01:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented format query={}", wanted_format);
|
2019-02-12 22:28:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
2019-09-13 06:55:28 +02:00
|
|
|
const auto supported_usage = GetFormatFeatures(it->second, format_type);
|
2019-02-12 22:28:05 +01:00
|
|
|
return (supported_usage & wanted_usage) == wanted_usage;
|
|
|
|
}
|
|
|
|
|
2021-06-20 23:26:55 +02:00
|
|
|
std::string Device::GetDriverName() const {
|
|
|
|
switch (driver_id) {
|
|
|
|
case VK_DRIVER_ID_AMD_PROPRIETARY:
|
|
|
|
return "AMD";
|
|
|
|
case VK_DRIVER_ID_AMD_OPEN_SOURCE:
|
|
|
|
return "AMDVLK";
|
|
|
|
case VK_DRIVER_ID_MESA_RADV:
|
|
|
|
return "RADV";
|
|
|
|
case VK_DRIVER_ID_NVIDIA_PROPRIETARY:
|
|
|
|
return "NVIDIA";
|
|
|
|
case VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS:
|
|
|
|
return "INTEL";
|
|
|
|
case VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA:
|
|
|
|
return "ANV";
|
|
|
|
case VK_DRIVER_ID_MESA_LLVMPIPE:
|
|
|
|
return "LAVAPIPE";
|
|
|
|
default:
|
|
|
|
return vendor_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-17 00:42:02 +01:00
|
|
|
void Device::CheckSuitability(bool requires_swapchain) const {
|
2020-03-27 05:33:21 +01:00
|
|
|
std::bitset<REQUIRED_EXTENSIONS.size()> available_extensions;
|
2021-01-17 00:42:02 +01:00
|
|
|
bool has_swapchain = false;
|
2020-12-26 05:50:25 +01:00
|
|
|
for (const VkExtensionProperties& property : physical.EnumerateDeviceExtensionProperties()) {
|
2021-01-17 00:42:02 +01:00
|
|
|
const std::string_view name{property.extensionName};
|
|
|
|
for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
|
2019-09-13 06:55:28 +02:00
|
|
|
if (available_extensions[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-03-27 05:33:21 +01:00
|
|
|
available_extensions[i] = name == REQUIRED_EXTENSIONS[i];
|
2019-09-13 06:55:28 +02:00
|
|
|
}
|
2021-01-17 00:42:02 +01:00
|
|
|
has_swapchain = has_swapchain || name == VK_KHR_SWAPCHAIN_EXTENSION_NAME;
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
2020-12-26 05:50:25 +01:00
|
|
|
for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
|
|
|
|
if (available_extensions[i]) {
|
2019-02-12 22:28:05 +01:00
|
|
|
continue;
|
2019-09-13 06:55:28 +02:00
|
|
|
}
|
2020-12-26 05:50:25 +01:00
|
|
|
LOG_ERROR(Render_Vulkan, "Missing required extension: {}", REQUIRED_EXTENSIONS[i]);
|
|
|
|
throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
2021-01-17 00:42:02 +01:00
|
|
|
if (requires_swapchain && !has_swapchain) {
|
|
|
|
LOG_ERROR(Render_Vulkan, "Missing required extension: VK_KHR_swapchain");
|
|
|
|
throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
|
|
|
|
}
|
|
|
|
|
2020-12-26 06:09:55 +01:00
|
|
|
struct LimitTuple {
|
|
|
|
u32 minimum;
|
|
|
|
u32 value;
|
|
|
|
const char* name;
|
|
|
|
};
|
2020-12-26 05:50:25 +01:00
|
|
|
const VkPhysicalDeviceLimits& limits{properties.limits};
|
2020-12-26 06:09:55 +01:00
|
|
|
const std::array limits_report{
|
|
|
|
LimitTuple{65536, limits.maxUniformBufferRange, "maxUniformBufferRange"},
|
|
|
|
LimitTuple{16, limits.maxViewports, "maxViewports"},
|
|
|
|
LimitTuple{8, limits.maxColorAttachments, "maxColorAttachments"},
|
|
|
|
LimitTuple{8, limits.maxClipDistances, "maxClipDistances"},
|
|
|
|
};
|
|
|
|
for (const auto& tuple : limits_report) {
|
|
|
|
if (tuple.value < tuple.minimum) {
|
|
|
|
LOG_ERROR(Render_Vulkan, "{} has to be {} or greater but it is {}", tuple.name,
|
|
|
|
tuple.minimum, tuple.value);
|
|
|
|
throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
|
|
|
|
}
|
2019-05-26 06:33:57 +02:00
|
|
|
}
|
2021-03-19 23:28:31 +01:00
|
|
|
VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT demote{};
|
|
|
|
demote.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT;
|
|
|
|
demote.pNext = nullptr;
|
|
|
|
|
2021-04-13 10:32:21 +02:00
|
|
|
VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointers{};
|
|
|
|
variable_pointers.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES_KHR;
|
|
|
|
variable_pointers.pNext = &demote;
|
|
|
|
|
2021-02-13 07:31:50 +01:00
|
|
|
VkPhysicalDeviceRobustness2FeaturesEXT robustness2{};
|
|
|
|
robustness2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
|
2021-04-13 10:32:21 +02:00
|
|
|
robustness2.pNext = &variable_pointers;
|
2021-02-13 07:31:50 +01:00
|
|
|
|
2021-02-20 07:30:13 +01:00
|
|
|
VkPhysicalDeviceFeatures2KHR features2{};
|
2021-02-13 07:31:50 +01:00
|
|
|
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
|
|
|
features2.pNext = &robustness2;
|
|
|
|
|
|
|
|
physical.GetFeatures2KHR(features2);
|
|
|
|
|
|
|
|
const VkPhysicalDeviceFeatures& features{features2.features};
|
2020-12-26 05:50:25 +01:00
|
|
|
const std::array feature_report{
|
2021-01-17 07:12:42 +01:00
|
|
|
std::make_pair(features.robustBufferAccess, "robustBufferAccess"),
|
2019-09-13 06:55:28 +02:00
|
|
|
std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"),
|
2020-12-30 06:25:23 +01:00
|
|
|
std::make_pair(features.imageCubeArray, "imageCubeArray"),
|
2019-09-13 06:55:28 +02:00
|
|
|
std::make_pair(features.independentBlend, "independentBlend"),
|
|
|
|
std::make_pair(features.depthClamp, "depthClamp"),
|
|
|
|
std::make_pair(features.samplerAnisotropy, "samplerAnisotropy"),
|
|
|
|
std::make_pair(features.largePoints, "largePoints"),
|
2019-12-09 05:04:48 +01:00
|
|
|
std::make_pair(features.multiViewport, "multiViewport"),
|
|
|
|
std::make_pair(features.depthBiasClamp, "depthBiasClamp"),
|
2021-04-16 03:46:11 +02:00
|
|
|
std::make_pair(features.fillModeNonSolid, "fillModeNonSolid"),
|
2021-06-25 10:21:51 +02:00
|
|
|
std::make_pair(features.wideLines, "wideLines"),
|
2019-12-09 05:04:48 +01:00
|
|
|
std::make_pair(features.geometryShader, "geometryShader"),
|
|
|
|
std::make_pair(features.tessellationShader, "tessellationShader"),
|
2021-04-16 22:22:59 +02:00
|
|
|
std::make_pair(features.sampleRateShading, "sampleRateShading"),
|
2021-04-22 21:19:14 +02:00
|
|
|
std::make_pair(features.dualSrcBlend, "dualSrcBlend"),
|
2020-02-11 22:59:44 +01:00
|
|
|
std::make_pair(features.occlusionQueryPrecise, "occlusionQueryPrecise"),
|
2019-12-09 05:04:48 +01:00
|
|
|
std::make_pair(features.fragmentStoresAndAtomics, "fragmentStoresAndAtomics"),
|
|
|
|
std::make_pair(features.shaderImageGatherExtended, "shaderImageGatherExtended"),
|
|
|
|
std::make_pair(features.shaderStorageImageWriteWithoutFormat,
|
|
|
|
"shaderStorageImageWriteWithoutFormat"),
|
2021-04-23 12:39:00 +02:00
|
|
|
std::make_pair(features.shaderClipDistance, "shaderClipDistance"),
|
|
|
|
std::make_pair(features.shaderCullDistance, "shaderCullDistance"),
|
2021-03-19 23:28:31 +01:00
|
|
|
std::make_pair(demote.shaderDemoteToHelperInvocation, "shaderDemoteToHelperInvocation"),
|
2021-04-13 10:32:21 +02:00
|
|
|
std::make_pair(variable_pointers.variablePointers, "variablePointers"),
|
|
|
|
std::make_pair(variable_pointers.variablePointersStorageBuffer,
|
|
|
|
"variablePointersStorageBuffer"),
|
2021-02-13 07:31:50 +01:00
|
|
|
std::make_pair(robustness2.robustBufferAccess2, "robustBufferAccess2"),
|
|
|
|
std::make_pair(robustness2.robustImageAccess2, "robustImageAccess2"),
|
|
|
|
std::make_pair(robustness2.nullDescriptor, "nullDescriptor"),
|
2019-09-13 06:55:28 +02:00
|
|
|
};
|
2020-12-26 05:50:25 +01:00
|
|
|
for (const auto& [is_supported, name] : feature_report) {
|
|
|
|
if (is_supported) {
|
2019-09-13 06:55:28 +02:00
|
|
|
continue;
|
|
|
|
}
|
2019-12-09 05:04:48 +01:00
|
|
|
LOG_ERROR(Render_Vulkan, "Missing required feature: {}", name);
|
2020-12-26 05:50:25 +01:00
|
|
|
throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-17 00:42:02 +01:00
|
|
|
std::vector<const char*> Device::LoadExtensions(bool requires_surface) {
|
2019-05-26 06:33:57 +02:00
|
|
|
std::vector<const char*> extensions;
|
2021-01-17 00:42:02 +01:00
|
|
|
extensions.reserve(8 + REQUIRED_EXTENSIONS.size());
|
2020-03-27 05:33:21 +01:00
|
|
|
extensions.insert(extensions.begin(), REQUIRED_EXTENSIONS.begin(), REQUIRED_EXTENSIONS.end());
|
2021-01-17 00:42:02 +01:00
|
|
|
if (requires_surface) {
|
|
|
|
extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
|
|
|
}
|
2020-03-27 05:33:21 +01:00
|
|
|
|
2020-03-06 09:09:06 +01:00
|
|
|
bool has_khr_shader_float16_int8{};
|
2021-03-29 00:53:34 +02:00
|
|
|
bool has_khr_workgroup_memory_explicit_layout{};
|
2021-07-28 00:15:32 +02:00
|
|
|
bool has_khr_pipeline_executable_properties{};
|
2021-08-29 07:52:09 +02:00
|
|
|
bool has_khr_image_format_list{};
|
|
|
|
bool has_khr_swapchain_mutable_format{};
|
2020-03-06 09:09:06 +01:00
|
|
|
bool has_ext_subgroup_size_control{};
|
|
|
|
bool has_ext_transform_feedback{};
|
2020-05-04 21:41:19 +02:00
|
|
|
bool has_ext_custom_border_color{};
|
2020-06-21 22:20:30 +02:00
|
|
|
bool has_ext_extended_dynamic_state{};
|
2021-04-11 08:07:02 +02:00
|
|
|
bool has_ext_shader_atomic_int64{};
|
2021-06-12 02:52:04 +02:00
|
|
|
bool has_ext_provoking_vertex{};
|
2021-06-13 04:25:40 +02:00
|
|
|
bool has_ext_vertex_input_dynamic_state{};
|
2021-06-25 10:25:19 +02:00
|
|
|
bool has_ext_line_rasterization{};
|
2021-12-18 05:47:48 +01:00
|
|
|
bool has_ext_primitive_topology_list_restart{};
|
2021-07-03 07:49:59 +02:00
|
|
|
for (const std::string& extension : supported_extensions) {
|
2020-06-29 07:48:29 +02:00
|
|
|
const auto test = [&](std::optional<std::reference_wrapper<bool>> status, const char* name,
|
|
|
|
bool push) {
|
2021-07-03 07:49:59 +02:00
|
|
|
if (extension != name) {
|
2020-06-29 07:48:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (push) {
|
|
|
|
extensions.push_back(name);
|
|
|
|
}
|
|
|
|
if (status) {
|
|
|
|
status->get() = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
test(nv_viewport_swizzle, VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME, true);
|
2021-04-16 21:31:15 +02:00
|
|
|
test(nv_viewport_array2, VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME, true);
|
2021-06-24 07:41:09 +02:00
|
|
|
test(nv_geometry_shader_passthrough, VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME,
|
|
|
|
true);
|
2020-06-29 07:48:29 +02:00
|
|
|
test(khr_uniform_buffer_standard_layout,
|
2019-09-13 06:55:28 +02:00
|
|
|
VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true);
|
2021-03-29 00:53:34 +02:00
|
|
|
test(khr_spirv_1_4, VK_KHR_SPIRV_1_4_EXTENSION_NAME, true);
|
2021-06-17 02:14:57 +02:00
|
|
|
test(khr_push_descriptor, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, true);
|
2020-06-29 07:48:29 +02:00
|
|
|
test(has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, false);
|
|
|
|
test(ext_depth_range_unrestricted, VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME, true);
|
|
|
|
test(ext_index_type_uint8, VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, true);
|
2021-12-18 05:47:48 +01:00
|
|
|
test(has_ext_primitive_topology_list_restart,
|
|
|
|
VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_EXTENSION_NAME, true);
|
2020-12-30 06:25:23 +01:00
|
|
|
test(ext_sampler_filter_minmax, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, true);
|
2020-06-29 07:48:29 +02:00
|
|
|
test(ext_shader_viewport_index_layer, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME,
|
|
|
|
true);
|
2020-12-30 06:25:23 +01:00
|
|
|
test(ext_tooling_info, VK_EXT_TOOLING_INFO_EXTENSION_NAME, true);
|
|
|
|
test(ext_shader_stencil_export, VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME, true);
|
2021-06-23 08:32:41 +02:00
|
|
|
test(ext_conservative_rasterization, VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME,
|
|
|
|
true);
|
2020-06-29 07:48:29 +02:00
|
|
|
test(has_ext_transform_feedback, VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME, false);
|
|
|
|
test(has_ext_custom_border_color, VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME, false);
|
|
|
|
test(has_ext_extended_dynamic_state, VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME, false);
|
2020-12-30 08:58:38 +01:00
|
|
|
test(has_ext_subgroup_size_control, VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false);
|
2021-06-12 02:52:04 +02:00
|
|
|
test(has_ext_provoking_vertex, VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME, false);
|
2021-06-13 04:25:40 +02:00
|
|
|
test(has_ext_vertex_input_dynamic_state, VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME,
|
|
|
|
false);
|
2021-04-11 08:07:02 +02:00
|
|
|
test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false);
|
2021-03-29 00:53:34 +02:00
|
|
|
test(has_khr_workgroup_memory_explicit_layout,
|
|
|
|
VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false);
|
2021-08-29 07:52:09 +02:00
|
|
|
test(has_khr_image_format_list, VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, false);
|
|
|
|
test(has_khr_swapchain_mutable_format, VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME,
|
|
|
|
false);
|
2021-06-25 10:25:19 +02:00
|
|
|
test(has_ext_line_rasterization, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, false);
|
2022-01-16 04:43:06 +01:00
|
|
|
test(ext_memory_budget, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME, true);
|
2021-07-08 23:22:31 +02:00
|
|
|
if (Settings::values.enable_nsight_aftermath) {
|
2020-06-29 07:48:29 +02:00
|
|
|
test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME,
|
|
|
|
true);
|
2020-01-21 20:37:41 +01:00
|
|
|
}
|
2021-07-28 00:15:32 +02:00
|
|
|
if (Settings::values.renderer_shader_feedback) {
|
|
|
|
test(has_khr_pipeline_executable_properties,
|
|
|
|
VK_KHR_PIPELINE_EXECUTABLE_PROPERTIES_EXTENSION_NAME, false);
|
|
|
|
}
|
2019-09-13 06:55:28 +02:00
|
|
|
}
|
2021-02-20 07:30:13 +01:00
|
|
|
VkPhysicalDeviceFeatures2KHR features{};
|
2020-03-27 05:33:21 +01:00
|
|
|
features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
|
|
|
|
|
2022-01-16 04:43:06 +01:00
|
|
|
VkPhysicalDeviceProperties2KHR physical_properties{};
|
2020-12-05 10:51:14 +01:00
|
|
|
physical_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
|
2020-03-27 05:33:21 +01:00
|
|
|
|
2020-03-06 09:09:06 +01:00
|
|
|
if (has_khr_shader_float16_int8) {
|
2020-03-27 05:33:21 +01:00
|
|
|
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;
|
2021-08-25 03:22:41 +02:00
|
|
|
is_int8_supported = float16_int8_features.shaderInt8;
|
2019-09-13 06:55:28 +02:00
|
|
|
extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME);
|
2019-05-26 06:33:57 +02:00
|
|
|
}
|
2020-03-06 09:09:06 +01:00
|
|
|
if (has_ext_subgroup_size_control) {
|
2020-03-27 05:33:21 +01:00
|
|
|
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;
|
2020-12-05 10:51:14 +01:00
|
|
|
physical_properties.pNext = &subgroup_properties;
|
|
|
|
physical.GetProperties2KHR(physical_properties);
|
2020-03-27 05:33:21 +01:00
|
|
|
|
|
|
|
is_warp_potentially_bigger = subgroup_properties.maxSubgroupSize > GuestWarpSize;
|
|
|
|
|
|
|
|
if (subgroup_features.subgroupSizeControl &&
|
|
|
|
subgroup_properties.minSubgroupSize <= GuestWarpSize &&
|
|
|
|
subgroup_properties.maxSubgroupSize >= GuestWarpSize) {
|
2019-12-09 05:04:48 +01:00
|
|
|
extensions.push_back(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);
|
2020-03-27 05:33:21 +01:00
|
|
|
guest_warp_stages = subgroup_properties.requiredSubgroupSizeStages;
|
2021-03-24 01:27:17 +01:00
|
|
|
ext_subgroup_size_control = true;
|
2019-12-09 05:04:48 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
is_warp_potentially_bigger = true;
|
|
|
|
}
|
2021-06-12 02:52:04 +02:00
|
|
|
if (has_ext_provoking_vertex) {
|
|
|
|
VkPhysicalDeviceProvokingVertexFeaturesEXT provoking_vertex;
|
|
|
|
provoking_vertex.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT;
|
|
|
|
provoking_vertex.pNext = nullptr;
|
|
|
|
features.pNext = &provoking_vertex;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
if (provoking_vertex.provokingVertexLast &&
|
|
|
|
provoking_vertex.transformFeedbackPreservesProvokingVertex) {
|
|
|
|
extensions.push_back(VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME);
|
|
|
|
ext_provoking_vertex = true;
|
|
|
|
}
|
|
|
|
}
|
2021-06-13 04:25:40 +02:00
|
|
|
if (has_ext_vertex_input_dynamic_state) {
|
|
|
|
VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT vertex_input;
|
|
|
|
vertex_input.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT;
|
|
|
|
vertex_input.pNext = nullptr;
|
|
|
|
features.pNext = &vertex_input;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
if (vertex_input.vertexInputDynamicState) {
|
|
|
|
extensions.push_back(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
|
|
|
|
ext_vertex_input_dynamic_state = true;
|
|
|
|
}
|
|
|
|
}
|
2021-04-11 08:07:02 +02:00
|
|
|
if (has_ext_shader_atomic_int64) {
|
|
|
|
VkPhysicalDeviceShaderAtomicInt64Features atomic_int64;
|
2022-01-19 19:48:39 +01:00
|
|
|
atomic_int64.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES;
|
2021-04-11 08:07:02 +02:00
|
|
|
atomic_int64.pNext = nullptr;
|
|
|
|
features.pNext = &atomic_int64;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
if (atomic_int64.shaderBufferInt64Atomics && atomic_int64.shaderSharedInt64Atomics) {
|
|
|
|
extensions.push_back(VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME);
|
|
|
|
ext_shader_atomic_int64 = true;
|
|
|
|
}
|
|
|
|
}
|
2020-03-06 09:09:06 +01:00
|
|
|
if (has_ext_transform_feedback) {
|
2020-03-27 05:33:21 +01:00
|
|
|
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;
|
2020-12-05 10:51:14 +01:00
|
|
|
physical_properties.pNext = &tfb_properties;
|
|
|
|
physical.GetProperties2KHR(physical_properties);
|
2020-03-27 05:33:21 +01:00
|
|
|
|
|
|
|
if (tfb_features.transformFeedback && tfb_features.geometryStreams &&
|
|
|
|
tfb_properties.maxTransformFeedbackStreams >= 4 &&
|
|
|
|
tfb_properties.maxTransformFeedbackBuffers && tfb_properties.transformFeedbackQueries &&
|
|
|
|
tfb_properties.transformFeedbackDraw) {
|
2020-03-06 09:09:06 +01:00
|
|
|
extensions.push_back(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
|
|
|
|
ext_transform_feedback = true;
|
|
|
|
}
|
|
|
|
}
|
2020-05-04 21:41:19 +02:00
|
|
|
if (has_ext_custom_border_color) {
|
|
|
|
VkPhysicalDeviceCustomBorderColorFeaturesEXT border_features;
|
|
|
|
border_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT;
|
|
|
|
border_features.pNext = nullptr;
|
|
|
|
features.pNext = &border_features;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
if (border_features.customBorderColors && border_features.customBorderColorWithoutFormat) {
|
|
|
|
extensions.push_back(VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
|
|
|
|
ext_custom_border_color = true;
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 01:22:48 +02:00
|
|
|
if (has_ext_extended_dynamic_state) {
|
2021-06-25 10:25:19 +02:00
|
|
|
VkPhysicalDeviceExtendedDynamicStateFeaturesEXT extended_dynamic_state;
|
|
|
|
extended_dynamic_state.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
|
|
|
|
extended_dynamic_state.pNext = nullptr;
|
|
|
|
features.pNext = &extended_dynamic_state;
|
2020-06-21 22:20:30 +02:00
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
2021-06-25 10:25:19 +02:00
|
|
|
if (extended_dynamic_state.extendedDynamicState) {
|
2020-06-21 22:20:30 +02:00
|
|
|
extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
|
|
|
|
ext_extended_dynamic_state = true;
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 10:25:19 +02:00
|
|
|
if (has_ext_line_rasterization) {
|
|
|
|
VkPhysicalDeviceLineRasterizationFeaturesEXT line_raster;
|
|
|
|
line_raster.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT;
|
|
|
|
line_raster.pNext = nullptr;
|
|
|
|
features.pNext = &line_raster;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
if (line_raster.rectangularLines && line_raster.smoothLines) {
|
|
|
|
extensions.push_back(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
|
|
|
|
ext_line_rasterization = true;
|
|
|
|
}
|
|
|
|
}
|
2021-03-29 00:53:34 +02:00
|
|
|
if (has_khr_workgroup_memory_explicit_layout) {
|
|
|
|
VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR layout;
|
|
|
|
layout.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR;
|
|
|
|
layout.pNext = nullptr;
|
|
|
|
features.pNext = &layout;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
if (layout.workgroupMemoryExplicitLayout &&
|
|
|
|
layout.workgroupMemoryExplicitLayout8BitAccess &&
|
|
|
|
layout.workgroupMemoryExplicitLayout16BitAccess &&
|
|
|
|
layout.workgroupMemoryExplicitLayoutScalarBlockLayout) {
|
|
|
|
extensions.push_back(VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME);
|
|
|
|
khr_workgroup_memory_explicit_layout = true;
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 00:15:32 +02:00
|
|
|
if (has_khr_pipeline_executable_properties) {
|
|
|
|
VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR executable_properties;
|
|
|
|
executable_properties.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR;
|
|
|
|
executable_properties.pNext = nullptr;
|
|
|
|
features.pNext = &executable_properties;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
if (executable_properties.pipelineExecutableInfo) {
|
|
|
|
extensions.push_back(VK_KHR_PIPELINE_EXECUTABLE_PROPERTIES_EXTENSION_NAME);
|
|
|
|
khr_pipeline_executable_properties = true;
|
|
|
|
}
|
|
|
|
}
|
2021-12-18 07:03:13 +01:00
|
|
|
if (has_ext_primitive_topology_list_restart) {
|
|
|
|
VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT primitive_topology_list_restart{};
|
|
|
|
primitive_topology_list_restart.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT;
|
|
|
|
primitive_topology_list_restart.pNext = nullptr;
|
|
|
|
features.pNext = &primitive_topology_list_restart;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
is_topology_list_restart_supported =
|
|
|
|
primitive_topology_list_restart.primitiveTopologyListRestart;
|
|
|
|
is_patch_list_restart_supported =
|
|
|
|
primitive_topology_list_restart.primitiveTopologyPatchListRestart;
|
|
|
|
}
|
2021-08-29 07:52:09 +02:00
|
|
|
if (has_khr_image_format_list && has_khr_swapchain_mutable_format) {
|
|
|
|
extensions.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
|
|
|
|
extensions.push_back(VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME);
|
|
|
|
khr_swapchain_mutable_format = true;
|
|
|
|
}
|
2021-06-17 02:14:57 +02:00
|
|
|
if (khr_push_descriptor) {
|
|
|
|
VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor;
|
|
|
|
push_descriptor.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR;
|
|
|
|
push_descriptor.pNext = nullptr;
|
|
|
|
|
|
|
|
physical_properties.pNext = &push_descriptor;
|
|
|
|
physical.GetProperties2KHR(physical_properties);
|
|
|
|
|
|
|
|
max_push_descriptors = push_descriptor.maxPushDescriptors;
|
|
|
|
}
|
2019-05-26 06:33:57 +02:00
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
void Device::SetupFamilies(VkSurfaceKHR surface) {
|
2020-03-27 05:33:21 +01:00
|
|
|
const std::vector queue_family_properties = physical.GetQueueFamilyProperties();
|
2020-12-26 05:50:25 +01:00
|
|
|
std::optional<u32> graphics;
|
|
|
|
std::optional<u32> present;
|
|
|
|
for (u32 index = 0; index < static_cast<u32>(queue_family_properties.size()); ++index) {
|
2020-12-26 05:32:46 +01:00
|
|
|
if (graphics && (present || !surface)) {
|
2019-02-12 22:28:05 +01:00
|
|
|
break;
|
2020-12-26 05:50:25 +01:00
|
|
|
}
|
|
|
|
const VkQueueFamilyProperties& queue_family = queue_family_properties[index];
|
|
|
|
if (queue_family.queueCount == 0) {
|
2019-02-12 22:28:05 +01:00
|
|
|
continue;
|
2020-12-26 05:50:25 +01:00
|
|
|
}
|
2020-03-27 05:33:21 +01:00
|
|
|
if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
|
2020-12-26 05:50:25 +01:00
|
|
|
graphics = index;
|
2020-04-02 07:32:58 +02:00
|
|
|
}
|
2020-12-26 05:32:46 +01:00
|
|
|
if (surface && physical.GetSurfaceSupportKHR(index, surface)) {
|
2020-12-26 05:50:25 +01:00
|
|
|
present = index;
|
2020-04-02 07:32:58 +02:00
|
|
|
}
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
2020-12-26 05:50:25 +01:00
|
|
|
if (!graphics) {
|
|
|
|
LOG_ERROR(Render_Vulkan, "Device lacks a graphics queue");
|
|
|
|
throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
|
|
|
|
}
|
2020-12-26 05:32:46 +01:00
|
|
|
if (surface && !present) {
|
2020-12-26 05:50:25 +01:00
|
|
|
LOG_ERROR(Render_Vulkan, "Device lacks a present queue");
|
|
|
|
throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
|
|
|
|
}
|
|
|
|
graphics_family = *graphics;
|
|
|
|
present_family = *present;
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
void Device::SetupFeatures() {
|
2021-02-20 07:30:13 +01:00
|
|
|
const VkPhysicalDeviceFeatures features{physical.GetFeatures()};
|
2021-05-31 01:43:47 +02:00
|
|
|
is_depth_bounds_supported = features.depthBounds;
|
2021-02-20 07:30:13 +01:00
|
|
|
is_formatless_image_load_supported = features.shaderStorageImageReadWithoutFormat;
|
2021-05-29 07:53:39 +02:00
|
|
|
is_shader_float64_supported = features.shaderFloat64;
|
|
|
|
is_shader_int64_supported = features.shaderInt64;
|
2021-05-31 01:44:28 +02:00
|
|
|
is_shader_int16_supported = features.shaderInt16;
|
2021-02-20 07:30:13 +01:00
|
|
|
is_shader_storage_image_multisample = features.shaderStorageImageMultisample;
|
2020-12-30 06:25:23 +01:00
|
|
|
is_blit_depth_stencil_supported = TestDepthStencilBlits();
|
2021-02-20 07:30:13 +01:00
|
|
|
is_optimal_astc_supported = IsOptimalAstcSupported(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::SetupProperties() {
|
|
|
|
float_controls.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR;
|
|
|
|
|
|
|
|
VkPhysicalDeviceProperties2KHR properties2{};
|
|
|
|
properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
|
|
|
|
properties2.pNext = &float_controls;
|
|
|
|
|
|
|
|
physical.GetProperties2KHR(properties2);
|
2019-02-12 22:28:05 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
void Device::CollectTelemetryParameters() {
|
2020-07-13 23:27:05 +02:00
|
|
|
VkPhysicalDeviceDriverPropertiesKHR driver{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR,
|
|
|
|
.pNext = nullptr,
|
2020-10-29 06:48:02 +01:00
|
|
|
.driverID = {},
|
|
|
|
.driverName = {},
|
|
|
|
.driverInfo = {},
|
|
|
|
.conformanceVersion = {},
|
2020-07-13 23:27:05 +02:00
|
|
|
};
|
2020-03-27 05:33:21 +01:00
|
|
|
|
2020-10-29 06:48:02 +01:00
|
|
|
VkPhysicalDeviceProperties2KHR device_properties{
|
2020-07-13 23:27:05 +02:00
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
|
|
|
|
.pNext = &driver,
|
2020-10-29 06:48:02 +01:00
|
|
|
.properties = {},
|
2020-07-13 23:27:05 +02:00
|
|
|
};
|
2020-10-29 06:48:02 +01:00
|
|
|
physical.GetProperties2KHR(device_properties);
|
2020-03-27 05:33:21 +01:00
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
driver_id = driver.driverID;
|
|
|
|
vendor_name = driver.driverName;
|
|
|
|
}
|
|
|
|
|
2022-01-16 04:43:06 +01:00
|
|
|
u64 Device::GetDeviceMemoryUsage() const {
|
|
|
|
VkPhysicalDeviceMemoryBudgetPropertiesEXT budget;
|
|
|
|
budget.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
|
|
|
|
budget.pNext = nullptr;
|
|
|
|
physical.GetMemoryProperties(&budget);
|
|
|
|
u64 result{};
|
|
|
|
for (const size_t heap : valid_heap_memory) {
|
|
|
|
result += budget.heapUsage[heap];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-06-17 00:29:48 +02:00
|
|
|
void Device::CollectPhysicalMemoryInfo() {
|
2022-01-16 04:43:06 +01:00
|
|
|
VkPhysicalDeviceMemoryBudgetPropertiesEXT budget{};
|
|
|
|
budget.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
|
|
|
|
const auto mem_info = physical.GetMemoryProperties(ext_memory_budget ? &budget : nullptr);
|
|
|
|
const auto& mem_properties = mem_info.memoryProperties;
|
2021-06-25 07:38:56 +02:00
|
|
|
const size_t num_properties = mem_properties.memoryHeapCount;
|
2021-06-17 00:29:48 +02:00
|
|
|
device_access_memory = 0;
|
2022-01-16 04:43:06 +01:00
|
|
|
u64 device_initial_usage = 0;
|
|
|
|
u64 local_memory = 0;
|
2021-06-25 07:38:56 +02:00
|
|
|
for (size_t element = 0; element < num_properties; ++element) {
|
2022-01-16 04:43:06 +01:00
|
|
|
const bool is_heap_local =
|
2022-01-18 18:05:44 +01:00
|
|
|
(mem_properties.memoryHeaps[element].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0;
|
2022-01-16 04:43:06 +01:00
|
|
|
if (!is_integrated && !is_heap_local) {
|
|
|
|
continue;
|
2021-06-17 00:29:48 +02:00
|
|
|
}
|
2022-01-16 04:43:06 +01:00
|
|
|
valid_heap_memory.push_back(element);
|
|
|
|
if (is_heap_local) {
|
|
|
|
local_memory += mem_properties.memoryHeaps[element].size;
|
|
|
|
}
|
|
|
|
if (ext_memory_budget) {
|
|
|
|
device_initial_usage += budget.heapUsage[element];
|
|
|
|
device_access_memory += budget.heapBudget[element];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
device_access_memory += mem_properties.memoryHeaps[element].size;
|
|
|
|
}
|
|
|
|
if (!is_integrated) {
|
|
|
|
return;
|
2021-06-17 00:29:48 +02:00
|
|
|
}
|
2022-01-16 04:43:06 +01:00
|
|
|
const s64 available_memory = static_cast<s64>(device_access_memory - device_initial_usage);
|
|
|
|
device_access_memory = static_cast<u64>(std::max<s64>(
|
|
|
|
std::min<s64>(available_memory - 8_GiB, 4_GiB), static_cast<s64>(local_memory)));
|
2021-06-17 00:29:48 +02:00
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
void Device::CollectToolingInfo() {
|
2020-12-30 06:25:23 +01:00
|
|
|
if (!ext_tooling_info) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto vkGetPhysicalDeviceToolPropertiesEXT =
|
|
|
|
reinterpret_cast<PFN_vkGetPhysicalDeviceToolPropertiesEXT>(
|
|
|
|
dld.vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceToolPropertiesEXT"));
|
|
|
|
if (!vkGetPhysicalDeviceToolPropertiesEXT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
u32 tool_count = 0;
|
|
|
|
if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, nullptr) != VK_SUCCESS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::vector<VkPhysicalDeviceToolPropertiesEXT> tools(tool_count);
|
|
|
|
if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, tools.data()) != VK_SUCCESS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const VkPhysicalDeviceToolPropertiesEXT& tool : tools) {
|
|
|
|
const std::string_view name = tool.name;
|
|
|
|
LOG_INFO(Render_Vulkan, "{}", name);
|
|
|
|
has_renderdoc = has_renderdoc || name == "RenderDoc";
|
|
|
|
has_nsight_graphics = has_nsight_graphics || name == "NVIDIA Nsight Graphics";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
std::vector<VkDeviceQueueCreateInfo> Device::GetDeviceQueueCreateInfos() const {
|
2020-03-27 05:33:21 +01:00
|
|
|
static constexpr float QUEUE_PRIORITY = 1.0f;
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
std::unordered_set<u32> unique_queue_families{graphics_family, present_family};
|
2020-03-27 05:33:21 +01:00
|
|
|
std::vector<VkDeviceQueueCreateInfo> queue_cis;
|
2020-07-13 23:27:05 +02:00
|
|
|
queue_cis.reserve(unique_queue_families.size());
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
for (const u32 queue_family : unique_queue_families) {
|
2020-07-18 01:27:53 +02:00
|
|
|
auto& ci = queue_cis.emplace_back(VkDeviceQueueCreateInfo{
|
2020-07-13 23:27:05 +02:00
|
|
|
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.flags = 0,
|
|
|
|
.queueFamilyIndex = queue_family,
|
2020-08-03 13:39:39 +02:00
|
|
|
.queueCount = 1,
|
|
|
|
.pQueuePriorities = nullptr,
|
2020-07-13 23:27:05 +02:00
|
|
|
});
|
2020-07-18 01:27:53 +02:00
|
|
|
ci.pQueuePriorities = &QUEUE_PRIORITY;
|
2020-03-27 05:33:21 +01:00
|
|
|
}
|
2019-02-12 22:28:05 +01:00
|
|
|
|
|
|
|
return queue_cis;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Vulkan
|