Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] OpenGL Codegen #2020

Merged
merged 21 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 18 additions & 6 deletions generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,24 @@
"AddApiProfiles": {
"Profiles": [
{
"Name": "gl",
"Profile": "gl",
"SourceSubdirectory": "glcompat",
"BakedOutputSubdirectory": "gl"
},
{
"Name": "glcore",
"Profile": "glcore",
"SourceSubdirectory": "glcore",
"BakedOutputSubdirectory": "gl",
"MinVersion": "3.2"
},
{
"Name": "gles1",
"Profile": "gles1",
"SourceSubdirectory": "gles1",
"BakedOutputSubdirectory": "gl",
"MaxVersion": "2.0"
},
{
"Name": "gles2",
"Profile": "gles2",
"SourceSubdirectory": "gles2",
"BakedOutputSubdirectory": "gl",
"MinVersion": "2.0"
Expand All @@ -106,7 +106,13 @@
},
"MixKhronosData": {
"UseDataTypeTrimmings": true,
"SpecPath": "eng/submodules/opengl/xml/gl.xml"
"SpecPath": "eng/submodules/opengl/xml/gl.xml",
"TypeMap": {
"TraceMaskMESA": "uint",
"PathRenderingTokenNV": "byte",
"PathCoordType": "byte"
},
"Namespace": "Silk.NET.OpenGL"
},
"AddVTables": {
"VTables": [
Expand All @@ -124,7 +130,13 @@
]
},
"PrettifyNames": {
"LongAcronymThreshold": 4
"LongAcronymThreshold": 4,
"GlobalPrefixHint": "gl"
},
"TransformFunctions": {
"BoolTypes": {
"GLboolean": null
}
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions sources/Core/Abstractions/IBoolScheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Numerics;
using System.Runtime.CompilerServices;

namespace Silk.NET.Core;

/// <summary>
/// Represents a boolean marshalling scheme for the given underlying type.
/// </summary>
public interface IBoolScheme
{
/// <summary>
/// The <c>true</c> value.
/// </summary>
static abstract T True<T>()
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>;

/// <summary>
/// The <c>false</c> value.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
static virtual T False<T>()
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T> =>
default!;

/// <summary>
/// Determines whether the given value represents a true value.
/// </summary>
/// <param name="value">The underlying value.</param>
/// <typeparam name="T">The type of the underlying value.</typeparam>
/// <returns>True or false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
static virtual bool IsTrue<T>(T value)
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T> =>
!value.Equals(default);
}
10 changes: 6 additions & 4 deletions sources/Core/Annotations/SupportedApiProfileAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Silk.NET.Core;
using System.Text.Json.Serialization;

Perksey marked this conversation as resolved.
Show resolved Hide resolved
namespace Silk.NET.Core;

/// <summary>
/// Indicates that the annotated API is supported using a specific API profile.
Expand All @@ -20,12 +22,12 @@
AllowMultiple = true,
Inherited = false
)]
public class SupportedApiProfileAttribute(string profile, string[] apiSets) : Attribute
public class SupportedApiProfileAttribute(string profile, string[]? apiSets = null) : Attribute
{
/// <summary>
/// The API profile supported e.g. gl, glcore, gles2, vulkan, vulkansc, etc.
/// </summary>
public string Profile { get; } = profile;
public string Profile { get; init; } = profile;

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

/// <summary>
/// The minimum (inclusive) version number (for illustration purposes only) wherein the API is supported by default.
Expand Down
25 changes: 25 additions & 0 deletions sources/Core/DSL/Default.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Numerics;
using System.Runtime.CompilerServices;

namespace Silk.NET.Core;

/// <summary>
/// The "default" option for variance of DSL types using type parameters. For example, use this in place of a
/// <see cref="IBoolScheme"/> type parameter to use the default boolean scheme (as implemented by
/// <see cref="MaybeBool{T}"/>)
/// </summary>
public class Default : IBoolScheme
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T True<T>()
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>
{
var ret = default(T);
ret++;
return ret;
}
}
57 changes: 57 additions & 0 deletions sources/Core/DSL/MaybeBool`1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Numerics;
using System.Runtime.CompilerServices;

namespace Silk.NET.Core;

/// <summary>
/// A boolean represented as an underlying value.
/// </summary>
/// <param name="Value">The underlying value/</param>
/// <typeparam name="T">The underlying type.</typeparam>
public readonly record struct MaybeBool<T>(T Value)
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>
{
/// <summary>
/// Creates a <see cref="MaybeBool{T}"/> from a <typeparamref name="T"/>.
/// </summary>
/// <param name="Value">The underlying value.</param>
/// <returns>The wrapped value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MaybeBool<T>(T Value) => new(Value);

/// <summary>
/// Gets the underlying value.
/// </summary>
/// <param name="value">The wrapped value.</param>
/// <returns>The underlying value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator T(MaybeBool<T> value) => value.Value;

/// <summary>
/// Creates a boolean wrapper of the specified type representing the given value.
/// </summary>
/// <param name="value">The boolean value.</param>
/// <returns>The wrapped underlying value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MaybeBool<T>(bool value)
{
var val = default(T);
if (value)
{
val++;
}

return val;
}

/// <summary>
/// Gets the boolean value of this wrapped value.
/// </summary>
/// <param name="value">The wrapped underlying value.</param>
/// <returns>The boolean value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator bool(MaybeBool<T> value) => !value.Value.Equals(default);
}
52 changes: 52 additions & 0 deletions sources/Core/DSL/MaybeBool`2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Numerics;
using System.Runtime.CompilerServices;

namespace Silk.NET.Core;

/// <summary>
/// A boolean represented as an underlying value expressed using a specific scheme.
/// </summary>
/// <param name="Value">The underlying value/</param>
/// <typeparam name="T">The underlying type.</typeparam>
/// <typeparam name="TScheme">The scheme used to determine the underlying value.</typeparam>
public readonly record struct MaybeBool<T, TScheme>(T Value)
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>
where TScheme : IBoolScheme
{
/// <summary>
/// Creates a <see cref="MaybeBool{T,TScheme}"/> from a <typeparamref name="T"/>.
/// </summary>
/// <param name="Value">The underlying value.</param>
/// <returns>The wrapped value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MaybeBool<T, TScheme>(T Value) => new(Value);

/// <summary>
/// Gets the underlying value.
/// </summary>
/// <param name="value">The wrapped value.</param>
/// <returns>The underlying value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator T(MaybeBool<T, TScheme> value) => value.Value;

/// <summary>
/// Creates a boolean wrapper of the specified type representing the given value.
/// </summary>
/// <param name="value">The boolean value.</param>
/// <returns>The wrapped underlying value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator MaybeBool<T, TScheme>(bool value) =>
value ? TScheme.True<T>() : TScheme.False<T>();

/// <summary>
/// Gets the boolean value of this wrapped value.
/// </summary>
/// <param name="value">The wrapped underlying value.</param>
/// <returns>The boolean value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator bool(MaybeBool<T, TScheme> value) =>
!value.Value.Equals(TScheme.False<T>());
Perksey marked this conversation as resolved.
Show resolved Hide resolved
}
31 changes: 31 additions & 0 deletions sources/Core/DSL/VariantBool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Numerics;

namespace Silk.NET.Core;

/// <summary>
/// The bool scheme for the Win32 <c>VARIANT_BOOL</c> type.
/// </summary>
public class VariantBool : IBoolScheme
{
/// <inheritdoc />
public static T True<T>()
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T>
{
// True is -1/all bits set
var ret = default(T);
unchecked
{
ret--;
}

return ret;
}

/// <inheritdoc />
public static bool IsTrue<T>(T value)
where T : unmanaged, IEquatable<T>, IIncrementOperators<T>, IDecrementOperators<T> =>
value.Equals(True<T>());
}
7 changes: 7 additions & 0 deletions sources/Core/Pointers/Ptr2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,12 @@ public T[][] ToArray<T>(int length, int[] lengths)
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public override int GetHashCode() => base.GetHashCode();

/// <summary>
/// Creates a <see cref="Ptr2D"/> from a <see cref="Ptr"/> pointer.
/// </summary>
/// <param name="ptr">The pointer.</param>
/// <returns>The wrapped pointer.</returns>
public static implicit operator Ptr2D(Ptr* ptr) => (byte*)ptr;
}
}
7 changes: 7 additions & 0 deletions sources/Core/Pointers/Ptr2D.generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,5 +586,12 @@ public Ptr2D(T** ptr)
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public override int GetHashCode() => base.GetHashCode();

/// <summary>
/// Creates a <see cref="Ptr2D{T}"/> from a <see cref="Ptr{T}"/> pointer.
/// </summary>
/// <param name="ptr">The pointer.</param>
/// <returns>The wrapped pointer.</returns>
public static implicit operator Ptr2D<T>(Ptr<T>* ptr) => (T**)ptr;
}
}
7 changes: 7 additions & 0 deletions sources/Core/Pointers/Ptr3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,12 @@ public T[][][] ToArray<T>(int length, int[] lengths0, int[][] lengths1)
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public override int GetHashCode() => base.GetHashCode();

/// <summary>
/// Creates a <see cref="Ptr3D"/> from a <see cref="Ptr2D"/> pointer.
/// </summary>
/// <param name="ptr">The pointer.</param>
/// <returns>The wrapped pointer.</returns>
public static implicit operator Ptr3D(Ptr2D* ptr) => (byte***)ptr;
}
}
7 changes: 7 additions & 0 deletions sources/Core/Pointers/Ptr3D.generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,12 @@ public Ptr3D(T*** ptr)
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public override int GetHashCode() => base.GetHashCode();

/// <summary>
/// Creates a <see cref="Ptr3D{T}"/> from a <see cref="Ptr2D{T}"/> pointer.
/// </summary>
/// <param name="ptr">The pointer.</param>
/// <returns>The wrapped pointer.</returns>
public static implicit operator Ptr3D<T>(Ptr2D<T>* ptr) => (T***)ptr;
}
}
2 changes: 1 addition & 1 deletion sources/GLFW/Glfw.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// Ported from glfw3.h and corresponding dependencies of GLFW3
// Original source is Copyright © 2002-2006 Marcus Geelnard, 2006-2019 Camilla Löwy. Licensed under the zlib license.
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Silk.NET.Core.Loader;
using System.Reflection;

namespace Silk.NET.GLFW;

Expand Down
Loading
Loading