From 3d0eb4b5d71c6e051480408ab4274082c6b232e3 Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Wed, 8 Apr 2026 23:46:50 +0200 Subject: [vulkan] 1st Vulkan Global Maintenance (#3839) This pr aims to make a first step into giving Eden's Vulkan backend maintenance with better formatting, understanding and reduce the redundancy between some wrong implementations: -> ProvokingVertex: Has been reworked completely, now the wiring to ExtendedDynamicState3 (ProvokingVertexMode) it works safe, the gating of the extension no longer requires user enabling on UI, it will be enabled automatically based on what features of the extension are available on driver, depending if first or last mode are available and also will be properly set under TrasformFeedback operations; this way we're gonna ensure all drivers, including Android stock drivers on QCOM, Mali and other mobile vendors drivers access correctly to the extension, fixing some graphical issues (flickering textures or wrong sccisors on vertex that required first mode) generated by the missing first mode handling or the proper clearing on pipeline state. This change will increase/ decrease slightly the performance on some games that changes dynamically between first and last modes, but will also ensure a clear path to GPU to use resources smartly, reducing VRAM consumption in PC and MEM/GPU percentage of use on Android (marginal to 5 - 8% approx). -> Removal VK_EXT_multi_draw: It has passed some months since the first try to implement this feature, but wasn't completed so functionality was null to negative, taking space in source and using small CPU cicles for initialization during device creation that reduced CPU effectiveness by 2 - 5%, aside that, after reviewing the situation of formally introducing handling for multidraws to reduce the floods of constants draw calls into 1 per batch, seems to not pay the overhead when the multidraw capacity is less or equal to 1, aside that, for the time being batching multidraws will introduce indirections on each batch of command draws, that graphical issues will appear and reducing performance can happen, something it was gonna solve. For the time being it's discarded, but, may be analyzed the chance to introduce it properly in a later date. -> Removal VK_EXT_indexing_descriptor: Currently the implementation of this feature was partial, with not proper handling on layouts; just the initial checks on device creation and chained up to the pNext feature, currently this extension will require a buffer cache and texture cache rework to set layouts and reduce the amount of use of descriptor into making it a less expensive cost effective, aside that to generate a path for the Bindless Texture and Bindless Buffer, allowing to track state of textures in runtime and ensuring the state of some compiled shaders doesn't change if it's no needed, among other benefits, besides that, enabling this feature was only generating innecessary checks on GPU, so consumption would be higher than it should be. -> Removal of VK_EXT_swapchain_maintenance1: The use of this feature was really conditional to certain support on newer drivers and cards, which wasn't available for all platforms, I concluded that if the support for this instance wasn't really there, the cost effective between the try to initialize it and running it, won't be good as when it didn't exist on our Vulkan device, with also the constant factor of not being completely implemented, right now I'm aiming to reduce the complexity on Vulkan side to keep it as simple as it could for a future video_core rework, which may start somewhere these weeks. -> Refined the Maintenance features: Meawhile this features are usually inherent to Vulkan core functionality, sometimes drivers doesn't expose them well, which leads to Eden run Vulkan without really noticing the existence of maintenance features on driver to improve stability, so we're tied to declare them and load them when a device creation starts by asking if driver supports and which, currently 1 - 5 are core maintenance features, meanwhile the 7 - 9 are more experimental and not being available everywhere, so right now to help drivers give attention to this features we not only load them, but also calculate with features bits which features inside Maintenance5 are available to use, that was the initial purpose, but we weren't using the full potential of the extension; I made cleaned part of the unneeded log code for the initialization of this Maintenance5 and it's feature flags, but also making an operation to sanitize depth/ stencil when One is not available in swizzle operations, making it easier to draw it; it's also needed to mention that Maintenance9 was removed from source code until we can have better handling on Arrays2D, aside that, the use of the extension was really conditional to certain drivers being capable of use it, so I remove it. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3839 Co-authored-by: CamilleLaVey Co-committed-by: CamilleLaVey --- src/video_core/vulkan_common/vulkan_device.cpp | 100 ++----------------------- 1 file changed, 6 insertions(+), 94 deletions(-) (limited to 'src/video_core/vulkan_common/vulkan_device.cpp') diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index b51c57d380..5075a79bcd 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp @@ -465,18 +465,6 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR first_next = &diagnostics_nv; } - VkPhysicalDeviceDescriptorIndexingFeaturesEXT descriptor_indexing{ - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT, - .pNext = use_diagnostics_nv ? static_cast(&diagnostics_nv) : static_cast(&features2), - .shaderSampledImageArrayNonUniformIndexing = VK_TRUE, - .descriptorBindingPartiallyBound = VK_TRUE, - .descriptorBindingVariableDescriptorCount = VK_TRUE, - }; - - if (extensions.descriptor_indexing && Settings::values.descriptor_indexing.GetValue()) { - first_next = &descriptor_indexing; - } - is_blit_depth24_stencil8_supported = TestDepthStencilBlits(VK_FORMAT_D24_UNORM_S8_UINT); is_blit_depth32_stencil8_supported = TestDepthStencilBlits(VK_FORMAT_D32_SFLOAT_S8_UINT); is_optimal_astc_supported = ComputeIsOptimalAstcSupported(); @@ -1078,11 +1066,6 @@ bool Device::GetSuitability(bool requires_swapchain) { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_PROPERTIES_KHR; SetNext(next, properties.maintenance5); } - if (extensions.multi_draw) { - properties.multi_draw.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_PROPERTIES_EXT; - SetNext(next, properties.multi_draw); - } // Perform the property fetch. physical.GetProperties2(properties2); @@ -1196,7 +1179,7 @@ void Device::RemoveUnsuitableExtensions() { RemoveExtensionFeatureIfUnsuitable(extensions.depth_clip_control, features.depth_clip_control, VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME); - /* */ // VK_EXT_extended_dynamic_state + // VK_EXT_extended_dynamic_state extensions.extended_dynamic_state = features.extended_dynamic_state.extendedDynamicState; RemoveExtensionFeatureIfUnsuitable(extensions.extended_dynamic_state, features.extended_dynamic_state, @@ -1268,7 +1251,6 @@ void Device::RemoveUnsuitableExtensions() { VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME); // VK_EXT_robustness2 - // Enable if at least one robustness2 feature is available extensions.robustness_2 = features.robustness2.robustBufferAccess2 || features.robustness2.robustImageAccess2 || features.robustness2.nullDescriptor; @@ -1277,25 +1259,10 @@ void Device::RemoveUnsuitableExtensions() { VK_EXT_ROBUSTNESS_2_EXTENSION_NAME); // VK_EXT_image_robustness - // Enable if robustImageAccess is available extensions.image_robustness = features.image_robustness.robustImageAccess; RemoveExtensionFeatureIfUnsuitable(extensions.image_robustness, features.image_robustness, VK_EXT_IMAGE_ROBUSTNESS_EXTENSION_NAME); - // VK_EXT_provoking_vertex - if (Settings::values.provoking_vertex.GetValue()) { - extensions.provoking_vertex = features.provoking_vertex.provokingVertexLast - && features.provoking_vertex - .transformFeedbackPreservesProvokingVertex; - RemoveExtensionFeatureIfUnsuitable(extensions.provoking_vertex, - features.provoking_vertex, - VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME); - } else { - RemoveExtensionFeature(extensions.provoking_vertex, - features.provoking_vertex, - VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME); - } - // VK_KHR_shader_atomic_int64 extensions.shader_atomic_int64 = features.shader_atomic_int64.shaderBufferInt64Atomics && features.shader_atomic_int64.shaderSharedInt64Atomics; @@ -1319,21 +1286,12 @@ void Device::RemoveUnsuitableExtensions() { VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME); // VK_EXT_transform_feedback - // We only require the basic transformFeedback feature and at least - // one transform feedback buffer. We keep transformFeedbackQueries as it's used by - // the streaming byte count implementation. GeometryStreams and multiple streams - // are not strictly required since we currently support only stream 0. extensions.transform_feedback = features.transform_feedback.transformFeedback && properties.transform_feedback.maxTransformFeedbackBuffers > 0 && properties.transform_feedback.transformFeedbackQueries; RemoveExtensionFeatureIfUnsuitable(extensions.transform_feedback, features.transform_feedback, VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME); - if (extensions.transform_feedback) { - LOG_INFO(Render_Vulkan, "VK_EXT_transform_feedback enabled (buffers={}, queries={})", - properties.transform_feedback.maxTransformFeedbackBuffers, - properties.transform_feedback.transformFeedbackQueries); - } // VK_EXT_vertex_input_dynamic_state extensions.vertex_input_dynamic_state = @@ -1342,17 +1300,6 @@ void Device::RemoveUnsuitableExtensions() { features.vertex_input_dynamic_state, VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME); - // VK_EXT_multi_draw - extensions.multi_draw = features.multi_draw.multiDraw; - - if (extensions.multi_draw) { - LOG_INFO(Render_Vulkan, "VK_EXT_multi_draw: maxMultiDrawCount={}", - properties.multi_draw.maxMultiDrawCount); - } - - RemoveExtensionFeatureIfUnsuitable(extensions.multi_draw, features.multi_draw, - VK_EXT_MULTI_DRAW_EXTENSION_NAME); - // VK_KHR_pipeline_executable_properties if (Settings::values.renderer_shader_feedback.GetValue()) { extensions.pipeline_executable_properties = @@ -1377,35 +1324,15 @@ void Device::RemoveUnsuitableExtensions() { features.workgroup_memory_explicit_layout, VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME); - // VK_EXT_swapchain_maintenance1 (extension only, has features) - // Requires VK_EXT_surface_maintenance1 instance extension - extensions.swapchain_maintenance1 = features.swapchain_maintenance1.swapchainMaintenance1; - if (extensions.swapchain_maintenance1) { - // Check if VK_EXT_surface_maintenance1 instance extension is available - const auto instance_extensions = vk::EnumerateInstanceExtensionProperties(dld); - const bool has_surface_maintenance1 = instance_extensions && std::ranges::any_of(*instance_extensions, - [](const VkExtensionProperties& prop) { - return std::strcmp(prop.extensionName, VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME) == 0; - }); - if (!has_surface_maintenance1) { - LOG_WARNING(Render_Vulkan, - "VK_EXT_swapchain_maintenance1 requires VK_EXT_surface_maintenance1, disabling"); - extensions.swapchain_maintenance1 = false; - features.swapchain_maintenance1.swapchainMaintenance1 = false; - } - } - RemoveExtensionFeatureIfUnsuitable(extensions.swapchain_maintenance1, features.swapchain_maintenance1, - VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME); - - // VK_KHR_maintenance1 (core in Vulkan 1.1, no features) + // VK_KHR_maintenance1 extensions.maintenance1 = loaded_extensions.contains(VK_KHR_MAINTENANCE_1_EXTENSION_NAME); RemoveExtensionIfUnsuitable(extensions.maintenance1, VK_KHR_MAINTENANCE_1_EXTENSION_NAME); - // VK_KHR_maintenance2 (core in Vulkan 1.1, no features) + // VK_KHR_maintenance2 extensions.maintenance2 = loaded_extensions.contains(VK_KHR_MAINTENANCE_2_EXTENSION_NAME); RemoveExtensionIfUnsuitable(extensions.maintenance2, VK_KHR_MAINTENANCE_2_EXTENSION_NAME); - // VK_KHR_maintenance3 (core in Vulkan 1.1, no features) + // VK_KHR_maintenance3 extensions.maintenance3 = loaded_extensions.contains(VK_KHR_MAINTENANCE_3_EXTENSION_NAME); RemoveExtensionIfUnsuitable(extensions.maintenance3, VK_KHR_MAINTENANCE_3_EXTENSION_NAME); @@ -1416,17 +1343,6 @@ void Device::RemoveUnsuitableExtensions() { // VK_KHR_maintenance5 extensions.maintenance5 = features.maintenance5.maintenance5; - - if (extensions.maintenance5) { - LOG_INFO(Render_Vulkan, "VK_KHR_maintenance5 properties: polygonModePointSize={} " - "depthStencilSwizzleOne={} earlyFragmentTests={} nonStrictWideLines={}", - properties.maintenance5.polygonModePointSize, - properties.maintenance5.depthStencilSwizzleOneSupport, - properties.maintenance5.earlyFragmentMultisampleCoverageAfterSampleCounting && - properties.maintenance5.earlyFragmentSampleMaskTestBeforeSampleCounting, - properties.maintenance5.nonStrictWideLinesUseParallelogram); - } - RemoveExtensionFeatureIfUnsuitable(extensions.maintenance5, features.maintenance5, VK_KHR_MAINTENANCE_5_EXTENSION_NAME); @@ -1435,17 +1351,13 @@ void Device::RemoveUnsuitableExtensions() { RemoveExtensionFeatureIfUnsuitable(extensions.maintenance6, features.maintenance6, VK_KHR_MAINTENANCE_6_EXTENSION_NAME); - // VK_KHR_maintenance7 (proposed for Vulkan 1.4, no features) + // VK_KHR_maintenance7 extensions.maintenance7 = loaded_extensions.contains(VK_KHR_MAINTENANCE_7_EXTENSION_NAME); RemoveExtensionIfUnsuitable(extensions.maintenance7, VK_KHR_MAINTENANCE_7_EXTENSION_NAME); - // VK_KHR_maintenance8 (proposed for Vulkan 1.4, no features) + // VK_KHR_maintenance8 extensions.maintenance8 = loaded_extensions.contains(VK_KHR_MAINTENANCE_8_EXTENSION_NAME); RemoveExtensionIfUnsuitable(extensions.maintenance8, VK_KHR_MAINTENANCE_8_EXTENSION_NAME); - - // VK_KHR_maintenance9 (proposed for Vulkan 1.4, no features) - extensions.maintenance9 = loaded_extensions.contains(VK_KHR_MAINTENANCE_9_EXTENSION_NAME); - RemoveExtensionIfUnsuitable(extensions.maintenance9, VK_KHR_MAINTENANCE_9_EXTENSION_NAME); } void Device::SetupFamilies(VkSurfaceKHR surface) { -- cgit v1.2.3