Implemented direct binding loading

OpenTK normally uses reflection to load bindings, instead of generating
huge constructors. Although reflection is faster on first load (thanks
to reduced JIT overhead), it fails to work correctly with monolinker.
This branch explores the performance of a direct binding.
This commit is contained in:
Stefanos A 2013-11-22 17:32:17 +01:00
parent e2404d2cfc
commit 2ace001203
7 changed files with 9060 additions and 4499 deletions

View file

@ -123,6 +123,7 @@ namespace Bind
sw.Indent();
sw.WriteLine("using System;");
sw.WriteLine("using System.Security;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
@ -201,6 +202,29 @@ namespace Bind
sw.WriteLine("{");
sw.Indent();
// Write constructor to initialize entry points
sw.WriteLine("public {0}()", Settings.OutputClass);
sw.WriteLine("{");
sw.Indent();
sw.WriteLine("IGraphicsContextInternal context = GraphicsContext.CurrentContext as IGraphicsContextInternal;");
sw.WriteLine("if (context == null) throw new GraphicsContextMissingException();");
sw.WriteLine();
foreach (var overloads in delegates.Values)
{
var d = overloads.First();
sw.WriteLine("{0}{1}{2}{3} = ({0}{1}{3})GetExtensionDelegate(\"{2}{3}\", typeof({0}{1}{3}));",
Settings.DelegatesClass,
Settings.NamespaceSeparator,
Settings.FunctionPrefix,
d.Name);
}
sw.Unindent();
sw.WriteLine("}");
sw.WriteLine();
// Write internal class to hold entry points
sw.WriteLine("internal static partial class {0}", Settings.DelegatesClass);
sw.WriteLine("{");
sw.Indent();
@ -212,7 +236,7 @@ namespace Bind
// so ignore them.
var d = overloads.First();
sw.WriteLine("[System.Security.SuppressUnmanagedCodeSecurity()]");
sw.WriteLine("[SuppressUnmanagedCodeSecurity]");
sw.WriteLine("internal {0};", GetDeclarationString(d, true));
sw.WriteLine("internal {0}static {2} {1}{2};", // = null
d.Unsafe ? "unsafe " : "",

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -26,6 +26,7 @@
#endregion
using System;
using System.Diagnostics;
using OpenTK.Graphics;
namespace OpenTK.Platform
@ -35,12 +36,16 @@ namespace OpenTK.Platform
{
public override void LoadAll()
{
new OpenTK.Graphics.OpenGL.GL().LoadEntryPoints();
new OpenTK.Graphics.OpenGL4.GL().LoadEntryPoints();
new OpenTK.Graphics.ES10.GL().LoadEntryPoints();
new OpenTK.Graphics.ES11.GL().LoadEntryPoints();
new OpenTK.Graphics.ES20.GL().LoadEntryPoints();
new OpenTK.Graphics.ES30.GL().LoadEntryPoints();
Stopwatch time = Stopwatch.StartNew();
new OpenTK.Graphics.OpenGL.GL();
new OpenTK.Graphics.OpenGL4.GL();
new OpenTK.Graphics.ES10.GL();
new OpenTK.Graphics.ES11.GL();
new OpenTK.Graphics.ES20.GL();
new OpenTK.Graphics.ES30.GL();
Debug.Print("Bindings loaded in {0} ms.", time.Elapsed.TotalMilliseconds);
}
}
}