From 5bff682cd532ef3da394c759b2e4ded82378a99c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 9 Oct 2023 16:31:47 +0200 Subject: [PATCH] Optimize InputTypes memory manager for downlevel TFMs --- ...PixelShaderDescriptorGenerator.InputTypes.Syntax.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.Syntax.cs index 5c0255fba..f38586d1c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.Syntax.cs @@ -76,8 +76,8 @@ static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer) // RVA field writer.WriteLine(); - writer.WriteLine("/// The RVA data with the input type info."); - writer.WriteLine("private static global::System.ReadOnlySpan Data => new[]"); + writer.WriteLine("/// The data with the input type info."); + writer.WriteLine("private static D2D1PixelShaderInputType[] Data = new[]"); writer.WriteLine("{"); writer.IncreaseIndent(); @@ -98,7 +98,7 @@ static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer) /// public override unsafe Span GetSpan() { - return new(Unsafe.AsPointer(ref MemoryMarshal.GetReference(Data)), Data.Length); + return Data; } /// @@ -111,7 +111,9 @@ public override Memory Memory /// public override unsafe MemoryHandle Pin(int elementIndex) { - return new(Unsafe.AsPointer(ref Unsafe.AsRef(in Data[elementIndex])), pinnable: this); + GCHandle handle = GCHandle.Alloc(Data, GCHandleType.Pinned); + + return new(Unsafe.AsPointer(ref Data[elementIndex]), handle); } ///