From 64395f818c716f39c6745d083736b78b3bf4b377 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 4 Oct 2023 00:16:55 +0200 Subject: [PATCH] Move API calls outside of lock in D2D1EffectXmlFactory --- .../Interop/Helpers/D2D1EffectXmlFactory.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs index a879b4d9..1e322f48 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs @@ -25,6 +25,14 @@ internal static unsafe class D2D1EffectXmlFactory public static EffectXml GetXmlBuffer() where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { + // Compute all necessary values first, outside of the lock + string? displayName = D2D1PixelShaderEffect.GetEffectDisplayName(); + string? description = D2D1PixelShaderEffect.GetEffectDescription(); + string? category = D2D1PixelShaderEffect.GetEffectCategory(); + string? author = D2D1PixelShaderEffect.GetEffectAuthor(); + int inputCount = D2D1PixelShader.GetInputCount(); + int resourceTextureCount = D2D1PixelShader.GetResourceTextureCount(); + StringBuilder builder = XmlBuilder; // We use a simple caching schema here with a single StringBuilder instance shared across all threads. @@ -39,15 +47,15 @@ internal static unsafe class D2D1EffectXmlFactory _ = builder.Append($""" - - - - + + + + """); // Add the input nodes, if any - for (int i = 0; i < D2D1PixelShader.GetInputCount(); i++) + for (int i = 0; i < inputCount; i++) { _ = builder.Append('\n'); _ = builder.Append($" "); @@ -66,7 +74,7 @@ internal static unsafe class D2D1EffectXmlFactory """); // Add the resource texture manager nodes, if any - for (int i = 0; i < D2D1PixelShader.GetResourceTextureCount(); i++) + for (int i = 0; i < resourceTextureCount; i++) { _ = builder.Append('\n'); _ = builder.Append($"""