Skip to content

Commit ca92db9

Browse files
authored
[3.0] OpenGL Codegen (#2020)
* Initial group codegen * Fix some trimming oddities * Fix HintTargetPGI and others similarly situated * Base typing and namespacing * Cast enum members, fix stray semicolons, Silk.NET.OpenGL builds again * Group and bool transformations * Fix erroneous cast order * Add Delete(singular) overloads (ArrayParameterOverloader) * Add SAL object model & Khronos length metadata parsing * ArrayParameterTransformer w/ tests * Integrate ArrayParameterTransformer * Support SupportedApiProfileAttribute generation with metadata * PrettifyNames conflict resolution now actually works * Fix casting transformation ambiguity bugs * Fix metadata retrieval for reserved identifiers * Fix unit tests * Fixup for all caps names * Fix naive trimming bug * More self-review comments
1 parent 6b67ce5 commit ca92db9

File tree

366 files changed

+518108
-117125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

366 files changed

+518108
-117125
lines changed

generator.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,24 @@
7575
"AddApiProfiles": {
7676
"Profiles": [
7777
{
78-
"Name": "gl",
78+
"Profile": "gl",
7979
"SourceSubdirectory": "glcompat",
8080
"BakedOutputSubdirectory": "gl"
8181
},
8282
{
83-
"Name": "glcore",
83+
"Profile": "glcore",
8484
"SourceSubdirectory": "glcore",
8585
"BakedOutputSubdirectory": "gl",
8686
"MinVersion": "3.2"
8787
},
8888
{
89-
"Name": "gles1",
89+
"Profile": "gles1",
9090
"SourceSubdirectory": "gles1",
9191
"BakedOutputSubdirectory": "gl",
9292
"MaxVersion": "2.0"
9393
},
9494
{
95-
"Name": "gles2",
95+
"Profile": "gles2",
9696
"SourceSubdirectory": "gles2",
9797
"BakedOutputSubdirectory": "gl",
9898
"MinVersion": "2.0"
@@ -106,7 +106,13 @@
106106
},
107107
"MixKhronosData": {
108108
"UseDataTypeTrimmings": true,
109-
"SpecPath": "eng/submodules/opengl/xml/gl.xml"
109+
"SpecPath": "eng/submodules/opengl/xml/gl.xml",
110+
"TypeMap": {
111+
"TraceMaskMESA": "uint",
112+
"PathRenderingTokenNV": "byte",
113+
"PathCoordType": "byte"
114+
},
115+
"Namespace": "Silk.NET.OpenGL"
110116
},
111117
"AddVTables": {
112118
"VTables": [
@@ -124,7 +130,13 @@
124130
]
125131
},
126132
"PrettifyNames": {
127-
"LongAcronymThreshold": 4
133+
"LongAcronymThreshold": 4,
134+
"GlobalPrefixHint": "gl"
135+
},
136+
"TransformFunctions": {
137+
"BoolTypes": {
138+
"GLboolean": null
139+
}
128140
}
129141
}
130142
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
7+
namespace Silk.NET.Core;
8+
9+
/// <summary>
10+
/// Represents a boolean marshalling scheme for the given underlying type.
11+
/// </summary>
12+
public interface IBoolScheme
13+
{
14+
/// <summary>
15+
/// The <c>true</c> value.
16+
/// </summary>
17+
static abstract T True<T>()
18+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>;
19+
20+
/// <summary>
21+
/// The <c>false</c> value.
22+
/// </summary>
23+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
24+
static virtual T False<T>()
25+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T> =>
26+
default!;
27+
28+
/// <summary>
29+
/// Determines whether the given value represents a true value.
30+
/// </summary>
31+
/// <param name="value">The underlying value.</param>
32+
/// <typeparam name="T">The type of the underlying value.</typeparam>
33+
/// <returns>True or false.</returns>
34+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
35+
static virtual bool IsTrue<T>(T value)
36+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T> =>
37+
!value.Equals(default);
38+
}

sources/Core/Annotations/SupportedApiProfileAttribute.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace Silk.NET.Core;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.Core;
25

36
/// <summary>
47
/// Indicates that the annotated API is supported using a specific API profile.
@@ -20,12 +23,12 @@
2023
AllowMultiple = true,
2124
Inherited = false
2225
)]
23-
public class SupportedApiProfileAttribute(string profile, string[] apiSets) : Attribute
26+
public class SupportedApiProfileAttribute(string profile, string[]? apiSets = null) : Attribute
2427
{
2528
/// <summary>
2629
/// The API profile supported e.g. gl, glcore, gles2, vulkan, vulkansc, etc.
2730
/// </summary>
28-
public string Profile { get; } = profile;
31+
public string Profile { get; init; } = profile;
2932

3033
/// <summary>
3134
/// A list of API sets (i.e. feature or extension names) in which the API is supported. If any of the elements
@@ -37,7 +40,7 @@ public class SupportedApiProfileAttribute(string profile, string[] apiSets) : At
3740
/// By default, the API is deemed supported if any of the sets in this array are supported. However, this can be
3841
/// changed using <see cref="RequireAll"/>.
3942
/// </remarks>
40-
public string[]? ApiSets { get; } = apiSets;
43+
public string[]? ApiSets { get; init; } = apiSets;
4144

4245
/// <summary>
4346
/// The minimum (inclusive) version number (for illustration purposes only) wherein the API is supported by default.

sources/Core/DSL/Default.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
7+
namespace Silk.NET.Core;
8+
9+
/// <summary>
10+
/// The "default" option for variance of DSL types using type parameters. For example, use this in place of a
11+
/// <see cref="IBoolScheme"/> type parameter to use the default boolean scheme (as implemented by
12+
/// <see cref="MaybeBool{T}"/>)
13+
/// </summary>
14+
public class Default : IBoolScheme
15+
{
16+
/// <inheritdoc />
17+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
18+
public static T True<T>()
19+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>
20+
{
21+
var ret = default(T);
22+
ret++;
23+
return ret;
24+
}
25+
}

sources/Core/DSL/MaybeBool`1.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
7+
namespace Silk.NET.Core;
8+
9+
/// <summary>
10+
/// A boolean represented as an underlying value.
11+
/// </summary>
12+
/// <param name="Value">The underlying value/</param>
13+
/// <typeparam name="T">The underlying type.</typeparam>
14+
public readonly record struct MaybeBool<T>(T Value)
15+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>
16+
{
17+
/// <summary>
18+
/// Creates a <see cref="MaybeBool{T}"/> from a <typeparamref name="T"/>.
19+
/// </summary>
20+
/// <param name="Value">The underlying value.</param>
21+
/// <returns>The wrapped value.</returns>
22+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
23+
public static implicit operator MaybeBool<T>(T Value) => new(Value);
24+
25+
/// <summary>
26+
/// Gets the underlying value.
27+
/// </summary>
28+
/// <param name="value">The wrapped value.</param>
29+
/// <returns>The underlying value.</returns>
30+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
31+
public static implicit operator T(MaybeBool<T> value) => value.Value;
32+
33+
/// <summary>
34+
/// Creates a boolean wrapper of the specified type representing the given value.
35+
/// </summary>
36+
/// <param name="value">The boolean value.</param>
37+
/// <returns>The wrapped underlying value.</returns>
38+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
39+
public static implicit operator MaybeBool<T>(bool value)
40+
{
41+
var val = default(T);
42+
if (value)
43+
{
44+
val++;
45+
}
46+
47+
return val;
48+
}
49+
50+
/// <summary>
51+
/// Gets the boolean value of this wrapped value.
52+
/// </summary>
53+
/// <param name="value">The wrapped underlying value.</param>
54+
/// <returns>The boolean value.</returns>
55+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
56+
public static implicit operator bool(MaybeBool<T> value) => !value.Value.Equals(default);
57+
}

sources/Core/DSL/MaybeBool`2.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
7+
namespace Silk.NET.Core;
8+
9+
/// <summary>
10+
/// A boolean represented as an underlying value expressed using a specific scheme.
11+
/// </summary>
12+
/// <param name="Value">The underlying value/</param>
13+
/// <typeparam name="T">The underlying type.</typeparam>
14+
/// <typeparam name="TScheme">The scheme used to determine the underlying value.</typeparam>
15+
public readonly record struct MaybeBool<T, TScheme>(T Value)
16+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>
17+
where TScheme : IBoolScheme
18+
{
19+
/// <summary>
20+
/// Creates a <see cref="MaybeBool{T,TScheme}"/> from a <typeparamref name="T"/>.
21+
/// </summary>
22+
/// <param name="Value">The underlying value.</param>
23+
/// <returns>The wrapped value.</returns>
24+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
25+
public static implicit operator MaybeBool<T, TScheme>(T Value) => new(Value);
26+
27+
/// <summary>
28+
/// Gets the underlying value.
29+
/// </summary>
30+
/// <param name="value">The wrapped value.</param>
31+
/// <returns>The underlying value.</returns>
32+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
33+
public static implicit operator T(MaybeBool<T, TScheme> value) => value.Value;
34+
35+
/// <summary>
36+
/// Creates a boolean wrapper of the specified type representing the given value.
37+
/// </summary>
38+
/// <param name="value">The boolean value.</param>
39+
/// <returns>The wrapped underlying value.</returns>
40+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
41+
public static implicit operator MaybeBool<T, TScheme>(bool value) =>
42+
value ? TScheme.True<T>() : TScheme.False<T>();
43+
44+
/// <summary>
45+
/// Gets the boolean value of this wrapped value.
46+
/// </summary>
47+
/// <param name="value">The wrapped underlying value.</param>
48+
/// <returns>The boolean value.</returns>
49+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
50+
public static implicit operator bool(MaybeBool<T, TScheme> value) =>
51+
TScheme.IsTrue(value.Value);
52+
}

sources/Core/DSL/VariantBool.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Numerics;
5+
6+
namespace Silk.NET.Core;
7+
8+
/// <summary>
9+
/// The bool scheme for the Win32 <c>VARIANT_BOOL</c> type.
10+
/// </summary>
11+
public class VariantBool : IBoolScheme
12+
{
13+
/// <inheritdoc />
14+
public static T True<T>()
15+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>
16+
{
17+
// True is -1/all bits set
18+
var ret = default(T);
19+
unchecked
20+
{
21+
ret--;
22+
}
23+
24+
return ret;
25+
}
26+
27+
/// <inheritdoc />
28+
public static bool IsTrue<T>(T value)
29+
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T> =>
30+
value.Equals(True<T>());
31+
}

sources/Core/Pointers/Ptr2D.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,5 +397,12 @@ public T[][] ToArray<T>(int length, int[] lengths)
397397
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
398398
)]
399399
public override int GetHashCode() => base.GetHashCode();
400+
401+
/// <summary>
402+
/// Creates a <see cref="Ptr2D"/> from a <see cref="Ptr"/> pointer.
403+
/// </summary>
404+
/// <param name="ptr">The pointer.</param>
405+
/// <returns>The wrapped pointer.</returns>
406+
public static implicit operator Ptr2D(Ptr* ptr) => (byte*)ptr;
400407
}
401408
}

sources/Core/Pointers/Ptr2D.generic.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,5 +586,12 @@ public T[][] ToArray(int length, int[] lengths) =>
586586
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
587587
)]
588588
public override int GetHashCode() => base.GetHashCode();
589+
590+
/// <summary>
591+
/// Creates a <see cref="Ptr2D{T}"/> from a <see cref="Ptr{T}"/> pointer.
592+
/// </summary>
593+
/// <param name="ptr">The pointer.</param>
594+
/// <returns>The wrapped pointer.</returns>
595+
public static implicit operator Ptr2D<T>(Ptr<T>* ptr) => (T**)ptr;
589596
}
590597
}

sources/Core/Pointers/Ptr3D.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,12 @@ ptr.Native is not null && ptr.Native->Native is not null
429429
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
430430
)]
431431
public override int GetHashCode() => base.GetHashCode();
432+
433+
/// <summary>
434+
/// Creates a <see cref="Ptr3D"/> from a <see cref="Ptr2D"/> pointer.
435+
/// </summary>
436+
/// <param name="ptr">The pointer.</param>
437+
/// <returns>The wrapped pointer.</returns>
438+
public static implicit operator Ptr3D(Ptr2D* ptr) => (byte***)ptr;
432439
}
433440
}

sources/Core/Pointers/Ptr3D.generic.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,5 +612,12 @@ ptr.Native is not null && ptr.Native->Native is not null
612612
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
613613
)]
614614
public override int GetHashCode() => base.GetHashCode();
615+
616+
/// <summary>
617+
/// Creates a <see cref="Ptr3D{T}"/> from a <see cref="Ptr2D{T}"/> pointer.
618+
/// </summary>
619+
/// <param name="ptr">The pointer.</param>
620+
/// <returns>The wrapped pointer.</returns>
621+
public static implicit operator Ptr3D<T>(Ptr2D<T>* ptr) => (T***)ptr;
615622
}
616623
}

sources/GLFW/Glfw.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// Ported from glfw3.h and corresponding dependencies of GLFW3
44
// Original source is Copyright © 2002-2006 Marcus Geelnard, 2006-2019 Camilla Löwy. Licensed under the zlib license.
5+
using System.Reflection;
56
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
78
using Silk.NET.Core.Loader;
8-
using System.Reflection;
99

1010
namespace Silk.NET.GLFW;
1111

0 commit comments

Comments
 (0)