From 15b4d4c5e3c38e8550d3b5b78b3a9a2bb74e92b1 Mon Sep 17 00:00:00 2001 From: gr3ger Date: Sat, 16 Nov 2024 23:26:06 +0100 Subject: [PATCH] Refactor descriptor count validation This change retains the same functionality, but in a more performat way. I measured ticks for both the above for loop and the new one, and opted for moving this one down as well since it was slightly slower. --- src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs b/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs index 57c22282d..436914330 100644 --- a/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs +++ b/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs @@ -170,12 +170,6 @@ namespace Ryujinx.Graphics.Vulkan bool hasBinding3 = uniformUsage.Any(x => x.Binding == 3); int[] reserved = isCompute ? Array.Empty() : gd.GetPushDescriptorReservedBindings(hasBinding3); - //Prevent the sum of descriptors from exceeding MaxPushDescriptors - if (layout.Sets.First().Descriptors.Where(descriptor => !reserved.Contains(descriptor.Binding)).Sum(descriptor => descriptor.Count) > gd.Capabilities.MaxPushDescriptors) - { - return false; - } - // Can't use any of the reserved usages. for (int i = 0; i < uniformUsage.Count; i++) { @@ -188,6 +182,16 @@ namespace Ryujinx.Graphics.Vulkan return false; } } + + //Prevent the sum of descriptors from exceeding MaxPushDescriptors + int totalDescriptors = 0; + foreach (ResourceDescriptor desc in layout.Sets.First().Descriptors) + { + if (!reserved.Contains(desc.Binding)) + totalDescriptors += desc.Count; + } + if (totalDescriptors > gd.Capabilities.MaxPushDescriptors) + return false; return true; }