[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:
thefiddler 2014-04-02 13:19:41 +02:00
parent 6994a13770
commit 774ebd1df7
6 changed files with 39 additions and 2 deletions

View file

@ -173,7 +173,7 @@ namespace Bind
sw.Indent();
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);
}

View file

@ -154,10 +154,20 @@ namespace Bind
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;
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++;
foreach (var d in list)

View file

@ -55,6 +55,9 @@ namespace Bind.GL2
Settings.DefaultWrappersFile = "GL.cs";
Settings.DefaultDocPath = Path.Combine(
Settings.DefaultDocPath, "GL");
Settings.DefaultCompatibility |=
Settings.Legacy.UseDllImports | Settings.Legacy.UseWindowsCompatibleGL;
}
}
}

View file

@ -49,6 +49,9 @@ namespace Bind.GL2
Settings.DefaultDocPath, "GL");
Profile = "glcore";
Settings.DefaultCompatibility |=
Settings.Legacy.UseDllImports | Settings.Legacy.UseWindowsCompatibleGL;
}
}
}

View file

@ -156,6 +156,13 @@ namespace Bind
AddDeprecationWarnings = 0x2000,
/// <summary>Use DllImport declaration for core functions (do not generate entry point slots)</summary>
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 |
NoAdvancedEnumProcessing |
NoPublicUnsafeFunctions |

View file

@ -302,5 +302,19 @@ namespace Bind
}
#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";
}
}
}