2019-02-12 22:28:05 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
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-09-13 06:55:28 +02:00
|
|
|
#include <string_view>
|
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"
|
2019-12-19 06:09:05 +01:00
|
|
|
#include "core/settings.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 {
|
|
|
|
|
2019-09-13 06:55:28 +02:00
|
|
|
namespace {
|
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
namespace Alternatives {
|
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
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{},
|
|
|
|
};
|
2019-12-09 05:04:48 +01:00
|
|
|
|
|
|
|
} // namespace Alternatives
|
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
constexpr std::array REQUIRED_EXTENSIONS{
|
2020-03-27 05:33:21 +01:00
|
|
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
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,
|
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,
|
|
|
|
VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME,
|
|
|
|
};
|
|
|
|
|
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) {
|
2020-03-27 05:33:21 +01:00
|
|
|
case VK_FORMAT_D24_UNORM_S8_UINT:
|
|
|
|
return Alternatives::Depth24UnormS8_UINT.data();
|
|
|
|
case VK_FORMAT_D16_UNORM_S8_UINT:
|
|
|
|
return Alternatives::Depth16UnormS8_UINT.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 {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 02:17:08 +02:00
|
|
|
[[nodiscard]] bool IsRDNA(std::string_view device_name, VkDriverIdKHR driver_id) {
|
|
|
|
static constexpr std::array RDNA_DEVICES{
|
|
|
|
"5700",
|
|
|
|
"5600",
|
|
|
|
"5500",
|
|
|
|
"5300",
|
|
|
|
};
|
|
|
|
if (driver_id != VK_DRIVER_ID_AMD_PROPRIETARY_KHR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return std::any_of(RDNA_DEVICES.begin(), RDNA_DEVICES.end(), [device_name](const char* name) {
|
|
|
|
return device_name.find(name) != std::string_view::npos;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties(
|
|
|
|
vk::PhysicalDevice physical, const vk::InstanceDispatch& dld) {
|
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,
|
|
|
|
VK_FORMAT_B5G6R5_UNORM_PACK16,
|
|
|
|
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,
|
2020-12-30 06:25:23 +01:00
|
|
|
VK_FORMAT_R16G16_SINT,
|
2020-06-02 07:11:32 +02:00
|
|
|
VK_FORMAT_R16_UNORM,
|
|
|
|
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,
|
|
|
|
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,
|
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;
|
|
|
|
}
|
|
|
|
|
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()},
|
2020-12-30 08:58:38 +01:00
|
|
|
format_properties{GetFormatProperties(physical, dld)} {
|
2020-12-26 05:50:25 +01:00
|
|
|
CheckSuitability();
|
2020-04-02 07:32:58 +02:00
|
|
|
SetupFamilies(surface);
|
|
|
|
SetupFeatures();
|
2019-02-12 22:28:05 +01:00
|
|
|
|
2019-05-26 06:33:57 +02:00
|
|
|
const auto queue_cis = GetDeviceQueueCreateInfos();
|
2020-04-02 07:32:58 +02:00
|
|
|
const std::vector extensions = LoadExtensions();
|
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,
|
|
|
|
};
|
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-07-13 23:27:05 +02:00
|
|
|
features2.features = {
|
|
|
|
.robustBufferAccess = false,
|
|
|
|
.fullDrawIndexUint32 = false,
|
2020-12-30 06:25:23 +01:00
|
|
|
.imageCubeArray = true,
|
2020-07-13 23:27:05 +02:00
|
|
|
.independentBlend = true,
|
|
|
|
.geometryShader = true,
|
|
|
|
.tessellationShader = true,
|
|
|
|
.sampleRateShading = false,
|
|
|
|
.dualSrcBlend = false,
|
|
|
|
.logicOp = false,
|
|
|
|
.multiDrawIndirect = false,
|
|
|
|
.drawIndirectFirstInstance = false,
|
|
|
|
.depthClamp = true,
|
|
|
|
.depthBiasClamp = true,
|
|
|
|
.fillModeNonSolid = false,
|
|
|
|
.depthBounds = false,
|
|
|
|
.wideLines = false,
|
|
|
|
.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,
|
2020-12-30 06:25:23 +01:00
|
|
|
.shaderStorageImageMultisample = true,
|
2020-07-13 23:27:05 +02:00
|
|
|
.shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported,
|
|
|
|
.shaderStorageImageWriteWithoutFormat = true,
|
|
|
|
.shaderUniformBufferArrayDynamicIndexing = false,
|
|
|
|
.shaderSampledImageArrayDynamicIndexing = false,
|
|
|
|
.shaderStorageBufferArrayDynamicIndexing = false,
|
|
|
|
.shaderStorageImageArrayDynamicIndexing = false,
|
|
|
|
.shaderClipDistance = false,
|
|
|
|
.shaderCullDistance = false,
|
|
|
|
.shaderFloat64 = false,
|
|
|
|
.shaderInt64 = false,
|
|
|
|
.shaderInt16 = false,
|
|
|
|
.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-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,
|
|
|
|
.storageBuffer16BitAccess = false,
|
|
|
|
.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
|
|
|
|
2020-07-13 23:27:05 +02:00
|
|
|
VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT,
|
|
|
|
.hostQueryReset = true,
|
|
|
|
};
|
2020-02-11 22:59:44 +01:00
|
|
|
SetNext(next, host_query_reset);
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
|
2019-09-13 06:55:28 +02:00
|
|
|
if (is_float16_supported) {
|
2020-07-13 23:27:05 +02:00
|
|
|
float16_int8 = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.shaderFloat16 = true,
|
|
|
|
.shaderInt8 = false,
|
|
|
|
};
|
2019-09-13 06:55:28 +02:00
|
|
|
SetNext(next, float16_int8);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
|
|
|
|
}
|
|
|
|
|
2020-05-04 23:31:17 +02:00
|
|
|
if (!nv_viewport_swizzle) {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support viewport swizzles");
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
VkPhysicalDeviceRobustness2FeaturesEXT robustness2;
|
|
|
|
if (ext_robustness2) {
|
|
|
|
robustness2 = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT,
|
|
|
|
.pNext = nullptr,
|
|
|
|
.robustBufferAccess2 = false,
|
|
|
|
.robustImageAccess2 = true,
|
|
|
|
.nullDescriptor = true,
|
|
|
|
};
|
|
|
|
SetNext(next, robustness2);
|
|
|
|
} else {
|
|
|
|
LOG_INFO(Render_Vulkan, "Device doesn't support robustness2");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (nv_device_diagnostics_config) {
|
|
|
|
nsight_aftermath_tracker.Initialize();
|
|
|
|
|
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
|
|
|
|
2019-12-09 05:04:48 +01:00
|
|
|
CollectTelemetryParameters();
|
2020-12-30 06:25:23 +01:00
|
|
|
CollectToolingInfo();
|
2019-09-13 06:55:28 +02:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
if (ext_extended_dynamic_state && driver_id == VK_DRIVER_ID_MESA_RADV) {
|
|
|
|
LOG_WARNING(
|
|
|
|
Render_Vulkan,
|
|
|
|
"Blacklisting RADV for VK_EXT_extended_dynamic state, likely due to a bug in yuzu");
|
|
|
|
ext_extended_dynamic_state = false;
|
|
|
|
}
|
2020-10-09 02:17:08 +02:00
|
|
|
if (ext_extended_dynamic_state && IsRDNA(properties.deviceName, driver_id)) {
|
|
|
|
// AMD's proprietary driver supports VK_EXT_extended_dynamic_state but on RDNA devices it
|
|
|
|
// seems to cause stability issues
|
|
|
|
LOG_WARNING(
|
|
|
|
Render_Vulkan,
|
|
|
|
"Blacklisting AMD proprietary on RDNA devices from VK_EXT_extended_dynamic_state");
|
|
|
|
ext_extended_dynamic_state = false;
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
graphics_queue = logical.GetQueue(graphics_family);
|
|
|
|
present_queue = logical.GetQueue(present_family);
|
2020-07-28 06:08:02 +02:00
|
|
|
|
|
|
|
use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue();
|
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 {
|
|
|
|
LOG_CRITICAL(Render_Vulkan, "Device loss occured!");
|
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
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
void Device::SaveShader(const std::vector<u32>& spirv) const {
|
2020-03-30 10:21:59 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
void Device::CheckSuitability() const {
|
2020-03-27 05:33:21 +01:00
|
|
|
std::bitset<REQUIRED_EXTENSIONS.size()> available_extensions;
|
2020-12-26 05:50:25 +01:00
|
|
|
for (const VkExtensionProperties& property : physical.EnumerateDeviceExtensionProperties()) {
|
2020-03-27 05:33:21 +01:00
|
|
|
for (std::size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
|
2019-09-13 06:55:28 +02:00
|
|
|
if (available_extensions[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-26 05:50:25 +01:00
|
|
|
const std::string_view name{property.extensionName};
|
2020-03-27 05:33:21 +01:00
|
|
|
available_extensions[i] = name == REQUIRED_EXTENSIONS[i];
|
2019-09-13 06:55:28 +02:00
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
}
|
2020-12-26 05:50:25 +01:00
|
|
|
const VkPhysicalDeviceFeatures features{physical.GetFeatures()};
|
|
|
|
const std::array feature_report{
|
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"),
|
|
|
|
std::make_pair(features.geometryShader, "geometryShader"),
|
|
|
|
std::make_pair(features.tessellationShader, "tessellationShader"),
|
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"),
|
2020-12-30 06:25:23 +01:00
|
|
|
std::make_pair(features.shaderStorageImageMultisample, "shaderStorageImageMultisample"),
|
2019-12-09 05:04:48 +01:00
|
|
|
std::make_pair(features.shaderStorageImageWriteWithoutFormat,
|
|
|
|
"shaderStorageImageWriteWithoutFormat"),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
std::vector<const char*> Device::LoadExtensions() {
|
2019-05-26 06:33:57 +02:00
|
|
|
std::vector<const char*> extensions;
|
2020-03-27 05:33:21 +01:00
|
|
|
extensions.reserve(7 + REQUIRED_EXTENSIONS.size());
|
|
|
|
extensions.insert(extensions.begin(), REQUIRED_EXTENSIONS.begin(), REQUIRED_EXTENSIONS.end());
|
|
|
|
|
2020-03-06 09:09:06 +01:00
|
|
|
bool has_khr_shader_float16_int8{};
|
|
|
|
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{};
|
2020-12-30 06:25:23 +01:00
|
|
|
bool has_ext_robustness2{};
|
2020-06-29 07:48:29 +02:00
|
|
|
for (const VkExtensionProperties& extension : physical.EnumerateDeviceExtensionProperties()) {
|
|
|
|
const auto test = [&](std::optional<std::reference_wrapper<bool>> status, const char* name,
|
|
|
|
bool push) {
|
|
|
|
if (extension.extensionName != std::string_view(name)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (push) {
|
|
|
|
extensions.push_back(name);
|
|
|
|
}
|
|
|
|
if (status) {
|
|
|
|
status->get() = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
test(nv_viewport_swizzle, VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME, true);
|
|
|
|
test(khr_uniform_buffer_standard_layout,
|
2019-09-13 06:55:28 +02:00
|
|
|
VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_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);
|
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);
|
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 06:25:23 +01:00
|
|
|
test(has_ext_robustness2, VK_EXT_ROBUSTNESS_2_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);
|
2020-01-21 20:37:41 +01:00
|
|
|
if (Settings::values.renderer_debug) {
|
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
|
|
|
}
|
2019-09-13 06:55:28 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkPhysicalDeviceFeatures2KHR features;
|
|
|
|
features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
|
|
|
|
|
2020-12-05 10:51:14 +01:00
|
|
|
VkPhysicalDeviceProperties2KHR physical_properties;
|
|
|
|
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;
|
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;
|
2019-12-09 05:04:48 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
is_warp_potentially_bigger = 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) {
|
2020-06-21 22:20:30 +02:00
|
|
|
VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
|
|
|
|
dynamic_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
|
|
|
|
dynamic_state.pNext = nullptr;
|
|
|
|
features.pNext = &dynamic_state;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
|
|
|
|
if (dynamic_state.extendedDynamicState) {
|
|
|
|
extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
|
|
|
|
ext_extended_dynamic_state = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
if (has_ext_robustness2) {
|
|
|
|
VkPhysicalDeviceRobustness2FeaturesEXT robustness2;
|
|
|
|
robustness2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
|
|
|
|
robustness2.pNext = nullptr;
|
|
|
|
features.pNext = &robustness2;
|
|
|
|
physical.GetFeatures2KHR(features);
|
|
|
|
if (robustness2.nullDescriptor && robustness2.robustImageAccess2) {
|
|
|
|
extensions.push_back(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME);
|
|
|
|
ext_robustness2 = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (graphics && present) {
|
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:50:25 +01:00
|
|
|
if (physical.GetSurfaceSupportKHR(index, surface)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (!present) {
|
|
|
|
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() {
|
2020-03-27 05:33:21 +01:00
|
|
|
const auto supported_features{physical.GetFeatures()};
|
2020-03-06 09:06:02 +01:00
|
|
|
is_formatless_image_load_supported = supported_features.shaderStorageImageReadWithoutFormat;
|
2020-12-30 06:25:23 +01:00
|
|
|
is_blit_depth_stencil_supported = TestDepthStencilBlits();
|
2020-04-02 07:32:58 +02:00
|
|
|
is_optimal_astc_supported = IsOptimalAstcSupported(supported_features);
|
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;
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
|
2019-12-09 05:04:48 +01:00
|
|
|
reported_extensions.reserve(std::size(extensions));
|
|
|
|
for (const auto& extension : extensions) {
|
2020-07-13 23:27:05 +02:00
|
|
|
reported_extensions.emplace_back(extension.extensionName);
|
2019-12-09 05:04:48 +01: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
|