mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-24 15:26:50 +00:00
[Bind] Do not generate slots for OpenGL <= v1.1
We can use DllImports for OpenGL functions <= v1.1 on all platforms, including Windows. This allows us to reduce the number of required GetProcAddress calls by 474, reducing startup time and memory consumption. This setting can be turned off through Settings.Legacy.UseDllImports and UseWindowsCompatibleGL.
This commit is contained in:
parent
6994a13770
commit
774ebd1df7
|
@ -173,7 +173,7 @@ namespace Bind
|
||||||
sw.Indent();
|
sw.Indent();
|
||||||
foreach (var d in delegates.Values.Select(d => d.First()))
|
foreach (var d in delegates.Values.Select(d => d.First()))
|
||||||
{
|
{
|
||||||
if (!Settings.IsEnabled(Settings.Legacy.UseDllImports) || d.Extension != "Core")
|
if (d.RequiresSlot(Settings))
|
||||||
{
|
{
|
||||||
sw.WriteLine("\"{0}{1}\",", Settings.FunctionPrefix, d.Name);
|
sw.WriteLine("\"{0}{1}\",", Settings.FunctionPrefix, d.Name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,10 +154,20 @@ namespace Bind
|
||||||
|
|
||||||
void GenerateAddressTable(DelegateCollection delegates)
|
void GenerateAddressTable(DelegateCollection delegates)
|
||||||
{
|
{
|
||||||
|
// We allocate one slot per entry point. Rules:
|
||||||
|
// - All extensions get a slot
|
||||||
|
// - Core functions get a slot, unless UseDllImports is enabled
|
||||||
|
// - On Windows, core functions with version > 1.1 must be treated as extensions.
|
||||||
|
// This is controlled via the UseWindowsCompatibleGL setting.
|
||||||
|
// Entry points without a slot are assigned the magic slot index -1.
|
||||||
|
// Generator.Rewrite detects this and generates a static DllImport call
|
||||||
|
// instead of a calli instruction for these functions.
|
||||||
|
|
||||||
int slot = -1;
|
int slot = -1;
|
||||||
foreach (var list in delegates.Values)
|
foreach (var list in delegates.Values)
|
||||||
{
|
{
|
||||||
if (!Settings.IsEnabled(Settings.Legacy.UseDllImports) || list.First().Extension != "Core")
|
var func = list.First();
|
||||||
|
if (func.RequiresSlot(Settings))
|
||||||
{
|
{
|
||||||
slot++;
|
slot++;
|
||||||
foreach (var d in list)
|
foreach (var d in list)
|
||||||
|
|
|
@ -55,6 +55,9 @@ namespace Bind.GL2
|
||||||
Settings.DefaultWrappersFile = "GL.cs";
|
Settings.DefaultWrappersFile = "GL.cs";
|
||||||
Settings.DefaultDocPath = Path.Combine(
|
Settings.DefaultDocPath = Path.Combine(
|
||||||
Settings.DefaultDocPath, "GL");
|
Settings.DefaultDocPath, "GL");
|
||||||
|
|
||||||
|
Settings.DefaultCompatibility |=
|
||||||
|
Settings.Legacy.UseDllImports | Settings.Legacy.UseWindowsCompatibleGL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,9 @@ namespace Bind.GL2
|
||||||
Settings.DefaultDocPath, "GL");
|
Settings.DefaultDocPath, "GL");
|
||||||
|
|
||||||
Profile = "glcore";
|
Profile = "glcore";
|
||||||
|
|
||||||
|
Settings.DefaultCompatibility |=
|
||||||
|
Settings.Legacy.UseDllImports | Settings.Legacy.UseWindowsCompatibleGL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,13 @@ namespace Bind
|
||||||
AddDeprecationWarnings = 0x2000,
|
AddDeprecationWarnings = 0x2000,
|
||||||
/// <summary>Use DllImport declaration for core functions (do not generate entry point slots)</summary>
|
/// <summary>Use DllImport declaration for core functions (do not generate entry point slots)</summary>
|
||||||
UseDllImports = 0x4000,
|
UseDllImports = 0x4000,
|
||||||
|
/// <summary>
|
||||||
|
/// Use in conjuction with UseDllImports, to create
|
||||||
|
/// bindings that are compatible with opengl32.dll on Windows.
|
||||||
|
/// This uses DllImports up to GL 1.1 and function pointers
|
||||||
|
/// for higher versions.
|
||||||
|
/// </summary>
|
||||||
|
UseWindowsCompatibleGL = 0x8000,
|
||||||
Tao = ConstIntEnums |
|
Tao = ConstIntEnums |
|
||||||
NoAdvancedEnumProcessing |
|
NoAdvancedEnumProcessing |
|
||||||
NoPublicUnsafeFunctions |
|
NoPublicUnsafeFunctions |
|
||||||
|
|
|
@ -302,5 +302,19 @@ namespace Bind
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public static bool RequiresSlot(this Delegate d, Settings settings)
|
||||||
|
{
|
||||||
|
double version;
|
||||||
|
Double.TryParse(
|
||||||
|
d.Version,
|
||||||
|
System.Globalization.NumberStyles.Float,
|
||||||
|
System.Globalization.CultureInfo.InvariantCulture,
|
||||||
|
out version);
|
||||||
|
return
|
||||||
|
!settings.IsEnabled(Settings.Legacy.UseDllImports) ||
|
||||||
|
(settings.IsEnabled(Settings.Legacy.UseWindowsCompatibleGL) && version > 1.1) ||
|
||||||
|
d.Extension != "Core";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue