Skip to content

Commit 510de97

Browse files
HurricanKaiPerksey
andauthored
SilkTouch work for 2.4 (#454)
* Remove ConcurrentDictionaryVTable * Out with the trees! * Split files * Out with the threes part 2! * Remove slots & cleanup * Add fallback arm * Adjust exception message * Update src/Core/Silk.NET.Core/Native/NativeApiContainer.cs Co-authored-by: Dylan Perks <[email protected]> * Change how loading exceptions work * Update src/Core/Silk.NET.Core/Native/NativeApiContainer.cs Co-authored-by: Dylan Perks <[email protected]> * Try to filter usings * Cleanup Vk + XR * Remove redundant code * Fix some warnings * enable telemetry * Raise telemetry diagnostic to Warning * Fix telemetry option * Enable compact file format always Co-authored-by: Dylan Perks <[email protected]>
1 parent cbafa96 commit 510de97

File tree

13 files changed

+328
-1191
lines changed

13 files changed

+328
-1191
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ silk_touch_vtable_generate = true
6767
silk_touch_vtable_tree_emit_assert = true
6868
silk_touch_sealed_vtable_creation = true
6969
silk_touch_vtable_preload = false
70+
silk_touch_telemetry = false
71+
silk_touch_compact_file_format = true
7072

7173
[*.{appxmanifest,asax,ascx,aspx,build,config,cs,cshtml,csproj,dbml,discomap,dtd,fs,fsi,fsscript,fsx,htm,html,jsproj,lsproj,master,ml,mli,njsproj,nuspec,proj,props,razor,resw,resx,skin,StyleCop,targets,tasks,vb,vbproj,xaml,xamlx,xml,xoml,xsd}]
7274
indent_style = space

src/Core/Silk.NET.Core/Contexts/INativeContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Silk.NET.Core.Contexts
88
public interface INativeContext : IDisposable
99
{
1010
nint GetProcAddress(string proc, int? slot = default);
11+
1112
bool TryGetProcAddress(string proc, out nint addr, int? slot = default);
1213
}
1314
}

src/Core/Silk.NET.Core/Native/ConcurrentDictionaryVTable.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/Core/Silk.NET.Core/Native/IVTable.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ namespace Silk.NET.Core.Native
88
{
99
public interface IVTable : IDisposable
1010
{
11-
void Initialize(INativeContext ctx, int maxSlots);
11+
[Obsolete("Use method without slot - this method will be removed in 3.0")]
1212
nint Load(int slot, string entryPoint);
13+
nint Load(string entryPoint);
1314
void Purge();
1415
}
1516
}

src/Core/Silk.NET.Core/Native/NativeApiContainer.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#nullable enable
55
using System;
66
using System.Diagnostics;
77
using System.Threading;
88
using Silk.NET.Core.Contexts;
9+
using Silk.NET.Core.Loader;
910

1011
namespace Silk.NET.Core.Native
1112
{
1213
public abstract class NativeApiContainer : IDisposable
1314
{
14-
private readonly INativeContext _ctx;
15+
protected readonly INativeContext _ctx;
1516
private IVTable _vTable;
1617

1718
protected NativeApiContainer(INativeContext ctx)
@@ -21,16 +22,6 @@ protected NativeApiContainer(INativeContext ctx)
2122
// The only implementer of this function should be SilkTouch
2223
// ReSharper disable VirtualMemberCallInConstructor
2324
_vTable = CreateVTable();
24-
var slotCount = CoreGetSlotCount();
25-
if (slotCount == 0)
26-
{
27-
throw new InvalidOperationException
28-
(
29-
"The derived class does not implement CoreGetSlotCount, or does not have any slots." +
30-
"This could be because of a SilkTouch bug, or because you're not using SilkTouch at all."
31-
);
32-
}
33-
_vTable.Initialize(_ctx, slotCount);
3425
GcUtility = new GcUtility(1, CoreGcSlotCount());
3526
PostInit();
3627
// ReSharper restore VirtualMemberCallInConstructor
@@ -46,10 +37,10 @@ public void Dispose()
4637
CurrentVTable.Dispose();
4738
}
4839

49-
protected virtual int CoreGetSlotCount() => 0;
5040
protected virtual int CoreGcSlotCount() => 0;
51-
protected virtual IVTable CreateVTable() => new ConcurrentDictionaryVTable();
52-
protected IVTable SwapVTable() => Interlocked.Exchange(ref _vTable, CreateVTable());
41+
protected virtual IVTable CreateVTable()
42+
=> throw new NotImplementedException("Must be implemented by SilkTouch");
43+
protected IVTable SwapVTable() => SwapVTable(CreateVTable());
5344
protected IVTable SwapVTable(IVTable newVTable) => Interlocked.Exchange(ref _vTable, newVTable);
5445

5546
protected void Pin(object o, int slot = -1)
@@ -72,11 +63,24 @@ public void PurgeEntryPoints()
7263
CurrentVTable.Purge();
7364
}
7465

66+
[Obsolete("Use method without slot - this method will be removed in 3.0")]
7567
protected nint Load(int slot, string entryPoint)
7668
{
77-
return CurrentVTable.Load(slot, entryPoint);
69+
return Load(entryPoint);
70+
}
71+
72+
protected nint Load(string entryPoint)
73+
{
74+
var result = CurrentVTable.Load(entryPoint);
75+
if (result == 0)
76+
{
77+
ThrowSymbolLoadingEx(entryPoint);
78+
}
79+
return result;
7880
}
7981

82+
private static void ThrowSymbolLoadingEx(string symbol) => throw new SymbolLoadingException(symbol);
83+
8084
protected virtual void PostInit()
8185
{
8286
// do nothing by default

src/Core/Silk.NET.SilkTouch/Diagnostics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ internal static class Diagnostics
5353
(
5454
id: "ST0004",
5555
title: "Build Info",
56-
messageFormat: "SlotCount: '{0}', GCSlotCount: '{1}', Time: '{2}'",
56+
messageFormat: "GCSlotCount: '{0}', Time: '{1}'",
5757
category: "SilkTouch.Internal",
58-
defaultSeverity: DiagnosticSeverity.Info,
58+
defaultSeverity: DiagnosticSeverity.Warning,
5959
isEnabledByDefault: true,
6060
description: null,
6161
helpLinkUri: null,

src/Core/Silk.NET.SilkTouch/EntryPoint.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ namespace Silk.NET.SilkTouch
1010
public readonly struct EntryPoint
1111
{
1212
public readonly string Name;
13-
public readonly int Slot;
1413
public readonly CallingConvention CallingConvention;
1514
public readonly TypeSyntax[] LoadTypes;
1615
public readonly IMethodSymbol SourceSymbol;
1716

18-
public EntryPoint(string name, int slot, CallingConvention callingConvention, TypeSyntax[] loadTypes, IMethodSymbol sourceSymbol)
17+
public EntryPoint(string name, CallingConvention callingConvention, TypeSyntax[] loadTypes, IMethodSymbol sourceSymbol)
1918
{
2019
Name = name;
21-
Slot = slot;
2220
CallingConvention = callingConvention;
2321
LoadTypes = loadTypes;
2422
SourceSymbol = sourceSymbol;

src/Core/Silk.NET.SilkTouch/MarshalContext.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public interface IMarshalContext
2222
/// </summary>
2323
Compilation Compilation { get; }
2424

25-
/// <summary>
26-
/// Indicates the method slot
27-
/// </summary>
28-
int Slot { get; }
29-
3025
/// <summary>
3126
/// All Load types in order, last is the return type
3227
/// </summary>
@@ -165,9 +160,6 @@ public class MarshalContext : IMarshalContext
165160
/// <inheritdoc />
166161
public Compilation Compilation { get; }
167162

168-
/// <inheritdoc />
169-
public int Slot { get; }
170-
171163
/// <inheritdoc />
172164
public ITypeSymbol[] LoadTypes { get; }
173165

@@ -498,11 +490,10 @@ public void TransitionTo(SilkTouchStage stage)
498490
CurrentStage = stage;
499491
}
500492

501-
public MarshalContext(Compilation compilation, IMethodSymbol methodSymbol, int slot)
493+
public MarshalContext(Compilation compilation, IMethodSymbol methodSymbol)
502494
{
503495
Compilation = compilation;
504496
MethodSymbol = methodSymbol;
505-
Slot = slot;
506497
ParameterVariables = new int[MethodSymbol.Parameters.Length];
507498

508499
LoadTypes = MethodSymbol.Parameters.Select

0 commit comments

Comments
 (0)