Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize InputTypes memory manager for downlevel TFMs #600

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)

// RVA field
writer.WriteLine();
writer.WriteLine("/// <summary>The RVA data with the input type info.</summary>");
writer.WriteLine("private static global::System.ReadOnlySpan<D2D1PixelShaderInputType> Data => new[]");
writer.WriteLine("/// <summary>The data with the input type info.</summary>");
writer.WriteLine("private static D2D1PixelShaderInputType[] Data = new[]");
writer.WriteLine("{");
writer.IncreaseIndent();

Expand All @@ -98,7 +98,7 @@ static void Callback(D2D1ShaderInfo info, IndentedTextWriter writer)
/// <inheritdoc/>
public override unsafe Span<D2D1PixelShaderInputType> GetSpan()
{
return new(Unsafe.AsPointer(ref MemoryMarshal.GetReference(Data)), Data.Length);
return Data;
}

/// <inheritdoc/>
Expand All @@ -111,7 +111,9 @@ public override Memory<D2D1PixelShaderInputType> Memory
/// <inheritdoc/>
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);
}

/// <inheritdoc/>
Expand Down