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

Fix a regression with some OpenGL Span overloads (v2.17.1) (fixes #1394) #1397

Merged
merged 1 commit into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 2 additions & 44 deletions build/props/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,14 @@
<LangVersion>10</LangVersion>
<Authors>.NET Foundation and Contributors</Authors>
<PackageReleaseNotes>
Silk.NET Spring 2023 Update 1

- Added zero-cost extension methods for ComPtrs, making our DirectX bindings easier to use and higher quality than ever before.
- Added WebGPU bindings for Dawn and WGPU.
- Added Direct2D bindings. (massive thank you to @curin)
- Added DirectComposition bindings. (again, massive preesh to @curin)
- Added DirectWrite bindings.
- Added d3d11on12 bindings.
- Added WGL bindings.
- Added support for Android 12.
- Added support for OpenAL disconnect extension. (thanks @okaniku)
- Added GLFW API constants for ANGLE. (thanks @cyraid)
- Added extension functions for OpenAL BufferData to make use of AL_EXT_float32 enums.
- Added ReopenDevices extension for OpenAL Soft. (thanks @LeNitrous)
- Added BufferCallback extension for OpenAL Soft.
- Added Vulkan structure chain polymorphism. (thanks @Khitiara for the proposal)
- Added SDL/GLFW native libraries for Windows on ARM64.
- Added IsScancodePressed function in Silk.NET Input.
- Added TopMost in Silk.NET Windowing (thanks @MarioGK)
- Added EGL display and surface to INativeWindow.
- Added an explicit check against calling Reset on a window while within the render loop of said window.
- Added support for multiple native binary candidate paths for a single binding.
- Improved support for WASM and AOT in the Silk.NET loader.
- Improved support for Windows on ARM64.
- Improved Silk.NET.Maths generic specialization codegen.
- Improved support for DXVK, including a new DXHandle property in INativeWindow for getting Linux HWND equivalents.
- Improved support for Silk.NET.Windowing under reflection-free NativeAOT
- Updated to SDL 2.24.
- Updated to Vulkan 1.3.246.
- Updated to DirectStorage 1.1.1.
- Updated to OpenXR 1.0.27.
- Updated to Assimp 5.2.5.
- Updated to latest OpenCL specifications.
- Updated to latest OpenGL specifications.
- Updated to latest ImGui.
- Fixed XInput GetApi not being implemented. (thanks @skyebird189)
- Fixed TransparentBuffer not being applied correctly without specifying a PreferredBitDepth. (thanks @MarioGK)
- Fixed wide string marshalling.
- Fixed string array marshalling on systems where the max DBCS character size is insufficient for UTF8.
- Fixed Span overloads not calculating the correct length value for ommitted (implicit) length parameters.
- Fixed copying of native libraries under .NET Framework 4.6.1. (thanks @paralaxsd)
- Fixed SDL crashing on Android when the screen rotates in some cases.
- Fixed a memory leak when using GlobalMemory to marshal string arrays instead of StringArrayToPtr. (thanks @Khitiara)
Fix a minor regression with some OpenGL Span overloads. Read more about the 2.17 update here: https://dotnet.github.io/Silk.NET/blog/apr-2023/silk2170.html
</PackageReleaseNotes>
<PackageTags Condition="'$(PackageTags)' == ''">OpenCL;OpenGL;OpenAL;OpenGLES;GLES;Vulkan;Assimp;DirectX;GLFW;SDL;Windowing;Input;Gamepad;Joystick;Keyboard;Mouse;SilkTouch;Source;Generator;C#;F#;.NET;DotNet;Mono;Vector;Math;Maths;Numerics;Game;Graphics;Compute;Audio;Sound;Engine;Silk;Silk.NET;Slim.NET;ElgarTK;GPU;Sharp;Science;Scientific;Visualization;Visual;Audiovisual;Windows;macOS;Linux;Android;Bindings;OSX;Wrapper;Native</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageOutputPath>$(MSBuildThisFileDirectory)/../output_packages</PackageOutputPath>
<RepositoryUrl>https://github.com/dotnet/Silk.NET</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<VersionPrefix>2.17</VersionPrefix>
<VersionPrefix>2.17.1</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
<Description Condition="'$(Description)' == ''">
Silk.NET is a high-speed, advanced library, providing bindings to popular low-level APIs such as OpenGL, OpenCL, OpenAL, OpenXR, GLFW, SDL, Vulkan, Assimp, and DirectX.
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Silk.NET.BuildTools/Bind/ClassWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void WriteNameContainer(this Project project, Profile profile, str
/// <param name="project">The current project.</param>
/// <param name="profile">The profile to write mixed-mode classes for.</param>
/// <param name="folder">The folder to store the generated classes in.</param>
public static void WriteMixedModeClasses(this Project project, Profile profile, string folder, BindState task)
public static void WriteMixedModeClasses(this Project project, Profile profile, string folder, string manualFolder, BindState task)
{
// public abstract class MixedModeClass : IMixedModeClass
// {
Expand Down Expand Up @@ -245,9 +245,9 @@ static string GetSignature(Function func)
FinishOverloadsFile(swOverloads);
sw.Flush();
sw.Dispose();
if (!File.Exists(Path.Combine(folder, $"{@class.ClassName}.cs")) && allFunctions.Any())
if (!File.Exists(Path.Combine(manualFolder, $"{@class.ClassName}.cs")) && allFunctions.Any())
{
sw = new StreamWriter(Path.Combine(folder, $"{@class.ClassName}.cs")) {NewLine = "\n"};
sw = new StreamWriter(Path.Combine(manualFolder, $"{@class.ClassName}.cs")) {NewLine = "\n"};
sw.WriteCoreUsings();
sw.WriteLine("using static Silk.NET.Core.Attributes.ExtensionAttribute;");
sw.WriteLine();
Expand Down Expand Up @@ -296,7 +296,7 @@ static string GetSignature(Function func)
if (!(task.Task.NameContainer is null))
{
project.WriteNameContainer
(profile, Path.Combine(folder, $"{task.Task.NameContainer.ClassName}.cs"), task);
(profile, Path.Combine(manualFolder, $"{task.Task.NameContainer.ClassName}.cs"), task);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Silk.NET.BuildTools/Bind/ProfileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static void Flush(this Profile profile, BindTask originalTask, Config con
Directory.CreateDirectory(folder);
}

proj.Value.WriteGeneratedCode(tmpFolder, profile, task);
proj.Value.WriteGeneratedCode(tmpFolder, folder, profile, task);
if (doCheck)
{
var filesBefore = Directory.GetFiles(folder, "*", SearchOption.AllDirectories)
Expand Down
12 changes: 9 additions & 3 deletions src/Core/Silk.NET.BuildTools/Bind/ProjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ private static string GetFileName(string name, string ext, params string[] direc
/// Writes this project in the given folder, with the given settings and parent subsystem.
/// </summary>
/// <param name="project">The project to write.</param>
/// <param name="folder">The folder to write this project to.</param>
/// <param name="folder">The folder to write this project's .gen.cs files to.</param>
/// <param name="manualFolder">The folder to write this project's .cs (i.e. non-.gen.cs) files to.</param>
/// <param name="profile">The parent subsystem.</param>
public static void WriteGeneratedCode(this Project project, string folder, Profile profile, BindState task)
public static void WriteGeneratedCode(this Project project, string folder, string manualFolder, Profile profile, BindState task)
{
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}

if (!Directory.Exists(manualFolder))
{
Directory.CreateDirectory(manualFolder);
}

if (!Directory.Exists(Path.Combine(folder, ProfileWriter.EnumsSubfolder)))
{
Expand Down Expand Up @@ -92,7 +98,7 @@ public static void WriteGeneratedCode(this Project project, string folder, Profi
);
});

project.WriteMixedModeClasses(profile, folder, task);
project.WriteMixedModeClasses(profile, folder, manualFolder, task);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public bool TryGetFunctionVariant(Function original, out ImplementedFunction var
$"$VAR${original.Parameters[spanParamIndex].Count?.Expression}"
).Replace("$VAR$", $"{original.Parameters[spanParamIndex].Name}.Length");
var lengthParam = $"({original.Parameters[countParamIndex].Type}) " + (
original.Parameters[spanParamIndex].Type.IsSinglePointerTo("void")
original.Parameters[spanParamIndex].Type.IsGenericTypeParameterReference
? $"(({lengthExpr}) * Unsafe.SizeOf<{original.Parameters[spanParamIndex].Type.Name}>())"
: lengthExpr);
parameters[countParamIndex] = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,49 +77,49 @@ public unsafe partial class ArbBaseInstance : NativeExtension<GL>
public unsafe void DrawElementsInstancedBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, baseinstance);
DrawElementsInstancedBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, baseinstance);
}

public unsafe void DrawElementsInstancedBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] DrawElementsType type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, baseinstance);
DrawElementsInstancedBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, baseinstance);
}

public unsafe void DrawElementsInstancedBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] PrimitiveType mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, baseinstance);
DrawElementsInstancedBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, baseinstance);
}

public unsafe void DrawElementsInstancedBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] PrimitiveType mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] DrawElementsType type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, baseinstance);
DrawElementsInstancedBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, baseinstance);
}

public unsafe void DrawElementsInstancedBaseVertexBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] int basevertex, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
}

public unsafe void DrawElementsInstancedBaseVertexBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] DrawElementsType type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] int basevertex, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
}

public unsafe void DrawElementsInstancedBaseVertexBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] PrimitiveType mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] int basevertex, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
}

public unsafe void DrawElementsInstancedBaseVertexBaseInstance<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] PrimitiveType mode, [Flow(Silk.NET.Core.Native.FlowDirection.In)] DrawElementsType type, [Count(Parameter = "count"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> indices, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint instancecount, [Flow(Silk.NET.Core.Native.FlowDirection.In)] int basevertex, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint baseinstance) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) indices.Length, type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
DrawElementsInstancedBaseVertexBaseInstance(mode, (uint) ((indices.Length) * Unsafe.SizeOf<T0>()), type, in indices.GetPinnableReference(), instancecount, basevertex, baseinstance);
}

public ArbBaseInstance(INativeContext ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ public unsafe partial class ArbBufferStorage : NativeExtension<GL>
public unsafe void BufferStorage<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB target, [Count(Parameter = "size"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> data, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint flags) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
BufferStorage(target, (nuint) data.Length, in data.GetPinnableReference(), flags);
BufferStorage(target, (nuint) ((data.Length) * Unsafe.SizeOf<T0>()), in data.GetPinnableReference(), flags);
}

public unsafe void BufferStorage<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] ARB target, [Count(Parameter = "size"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> data, [Flow(Silk.NET.Core.Native.FlowDirection.In)] BufferStorageMask flags) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
BufferStorage(target, (nuint) data.Length, in data.GetPinnableReference(), flags);
BufferStorage(target, (nuint) ((data.Length) * Unsafe.SizeOf<T0>()), in data.GetPinnableReference(), flags);
}

public unsafe void BufferStorage<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] BufferStorageTarget target, [Count(Parameter = "size"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> data, [Flow(Silk.NET.Core.Native.FlowDirection.In)] uint flags) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
BufferStorage(target, (nuint) data.Length, in data.GetPinnableReference(), flags);
BufferStorage(target, (nuint) ((data.Length) * Unsafe.SizeOf<T0>()), in data.GetPinnableReference(), flags);
}

public unsafe void BufferStorage<T0>([Flow(Silk.NET.Core.Native.FlowDirection.In)] BufferStorageTarget target, [Count(Parameter = "size"), Flow(Silk.NET.Core.Native.FlowDirection.In)] ReadOnlySpan<T0> data, [Flow(Silk.NET.Core.Native.FlowDirection.In)] BufferStorageMask flags) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
BufferStorage(target, (nuint) data.Length, in data.GetPinnableReference(), flags);
BufferStorage(target, (nuint) ((data.Length) * Unsafe.SizeOf<T0>()), in data.GetPinnableReference(), flags);
}

public ArbBufferStorage(INativeContext ctx)
Expand Down
Loading