Skip to content

Commit

Permalink
This is the October 2023 Update (v2.18.0) (#1680)
Browse files Browse the repository at this point in the history
* Update SdlWindowing.cs

* Update GlfwWindowing.cs

* Finish AOT robustness

* Add a hack for #1691

* Fix #1677

* Fix public API

* snap
  • Loading branch information
Perksey committed Oct 21, 2023
1 parent eeedf77 commit 521e18a
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 15 deletions.
44 changes: 42 additions & 2 deletions build/props/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,54 @@
<LangVersion>10</LangVersion>
<Authors>.NET Foundation and Contributors</Authors>
<PackageReleaseNotes>
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
Silk.NET October 2023 Update

- Added SPIR-V Reflect bindings
- Added SPIR-V Cross bindings
- Added Shaderc bindings
- Added WIC/WindowsCodecs bindings (thanks @hez2010)
- Added multi-channel formats support for OpenAL (thanks @aleksrutins)
- Added EffectTarget support for OpenAL Soft (thanks @okaniku, @doobah)
- Added MoltenVK support for iOS (massive thank you to @zvasya for contributing and testing)
- Added macOS support for the CreateWebGPUSurface helper function (thanks @AsgardXIV)
- Added the ability to load MoltenVK directly as a fallback should the Vulkan Loader be unavailable on macOS
- Added trimming support with an option to enable/disable static-linking support at link time
- Added WinRT interoperability support for Direct3D 11.
- Added the ability to query extensions from specific Vulkan layers using the Silk.NET helpers
- Added extension methods on IGamepad to return Thumbstick state instead of requiring use of the indexers (thanks @jvyden)
- Added ref properties for Vulkan chain constituents (thanks @khitiara)
- Added Apple Silicon binaries for Assimp (thanks @jschieck)
- Added compatibility with Linux distributions using as early as glibc 2.16
- Added equality operators and IEquatable to Bool32 (thanks @Syncaidius)
- Added ToSystem/ToGeneric as extension methods (rather than plain static functions) to convert to/from Silk.NET.Maths types (thanks @Wafer-EX)
- Added discriminant values to PinObjectMarshaller to tie pinned handles to state to which the pin pertains
- Updated to Vulkan 1.3.266
- Updated to OpenXR 1.0.30
- Updated to SDL 2.28.1
- Updated to MoltenVK 1.2.5
- Updated to latest WebGPU headers
- Updated to latest OpenCL specifications
- Updated to latest OpenGL specifications
- Improved allocations in the Silk.NET Loader (thanks @Youssef1313)
- Improved robustness of HLU on AOT compilations
- Fixed WGPU not loading with the correct filename on Windows
- Fixed COM V-Table indices not matching the Clang-reported V-Table index in some cases (DirectWrite/D2D1/DComp)
- Fixed OpenAL throwing when loading an extension prefixed with ALC_ instead AL_
- Fixed WGL.GetApi throwing a NotImplementedException
- Fixed library loading failing on platforms that do not have a libdl.so symlink (we are now using libdl.so.2, thanks @CasualPokePlayer)
- Fixed a StackOverflowException when using SetWindowIcon in some cases with Silk.NET.Windowing
- Fixed GLFW crashing in some cases where multiple windows are used
- Fixed WebGPU using the incorrect size for booleans
- Fixed a memory leak with some string marshalling functions

If you are using Silk.NET with an iOS or Android application, please enable trimming and set TrimMode to full.
</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.1</VersionPrefix>
<VersionPrefix>2.18.0</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
2 changes: 1 addition & 1 deletion src/Input/Silk.NET.Input.Common/InputWindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Silk.NET.Input
/// </summary>
public static class InputWindowExtensions
{
private static List<IInputPlatform> _platforms = new List<IInputPlatform>();
internal static List<IInputPlatform> _platforms = new List<IInputPlatform>();

/// <summary>
/// Gets the input platforms currently registered with the input system.
Expand Down
9 changes: 6 additions & 3 deletions src/Input/Silk.NET.Input.Glfw/GlfwInput.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Silk.NET.Windowing;
using System.Linq;
using Silk.NET.Windowing.Glfw;

namespace Silk.NET.Input.Glfw
Expand All @@ -10,8 +10,11 @@ public static class GlfwInput
{
public static void RegisterPlatform()
{
Window.Add(new GlfwPlatform());
InputWindowExtensions.Add(new GlfwInputPlatform());
GlfwWindowing.RegisterPlatform(); // just in case it's not already
if (!InputWindowExtensions._platforms.OfType<GlfwInputPlatform>().Any())
{
InputWindowExtensions.Add(new GlfwInputPlatform());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
static Silk.NET.Input.Sdl.SdlInput.Use() -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
static Silk.NET.Input.Sdl.SdlInput.Use() -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
static Silk.NET.Input.Sdl.SdlInput.Use() -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
static Silk.NET.Input.Sdl.SdlInput.Use() -> void
15 changes: 12 additions & 3 deletions src/Input/Silk.NET.Input.Sdl/SdlInput.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Silk.NET.Windowing;
using System.Linq;
using Silk.NET.Windowing.Sdl;

namespace Silk.NET.Input.Sdl
Expand All @@ -10,8 +10,17 @@ public static class SdlInput
{
public static void RegisterPlatform()
{
Window.Add(new SdlPlatform());
InputWindowExtensions.Add(new SdlInputPlatform());
SdlWindowing.RegisterPlatform(); // just in case it's not already
if (!InputWindowExtensions._platforms.OfType<SdlInputPlatform>().Any())
{
InputWindowExtensions.Add(new SdlInputPlatform());
}
}

public static void Use() // for consistency with windowing
{
InputWindowExtensions.ShouldLoadFirstPartyPlatforms(false);
RegisterPlatform();
}
}
}
2 changes: 1 addition & 1 deletion src/Lab/Experiments/BlankWindow/BlankWindow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
21 changes: 20 additions & 1 deletion src/OpenAL/Silk.NET.OpenAL/AL/AL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ public AL(INativeContext ctx)
}

/// <inheritdoc />
public override partial bool IsExtensionPresent(string name);
public override unsafe bool IsExtensionPresent(string name)
{
if (name.StartsWith("ALC_"))
{
// extreme hack for ALC_EXT_EFX which does not have a standard AL variant
var maxName = SilkMarshal.GetMaxSizeOf(name, NativeStringEncoding.UTF8);
var nameNative = name.Length > 256 ? new byte[maxName] : stackalloc byte[maxName];
SilkMarshal.StringIntoSpan(name, nameNative, NativeStringEncoding.UTF8);
fixed (byte* namePtr = nameNative)
{
return ((delegate* unmanaged[Cdecl]<byte*, char>) Context.GetProcAddress("alcIsExtensionPresent"))
(namePtr) == 1;
}
}

return CoreIsExtensionPresent(name);
}

[NativeApi(EntryPoint = nameof(IsExtensionPresent))]
private partial bool CoreIsExtensionPresent(string name);

/// <inheritdoc />
public SearchPathContainer SearchPaths => _searchPaths ??= new OpenALLibraryNameContainer(_soft);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Silk.NET.Windowing.VideoMode.AspectRatioEstimate.get -> Silk.NET.Maths.Vector2D<
Silk.NET.Windowing.WindowOptions.TopMost.get -> bool
Silk.NET.Windowing.WindowOptions.TopMost.set -> void
Silk.NET.Windowing.WindowOptions.WindowOptions(bool isVisible, Silk.NET.Maths.Vector2D<int> position, Silk.NET.Maths.Vector2D<int> size, double framesPerSecond, double updatesPerSecond, Silk.NET.Windowing.GraphicsAPI api, string! title, Silk.NET.Windowing.WindowState windowState, Silk.NET.Windowing.WindowBorder windowBorder, bool isVSync, bool shouldSwapAutomatically, Silk.NET.Windowing.VideoMode videoMode, int? preferredDepthBufferBits = null, int? preferredStencilBufferBits = null, Silk.NET.Maths.Vector4D<int>? preferredBitDepth = null, bool transparentFramebuffer = false, bool topMost = false, bool isEventDriven = false, Silk.NET.Core.Contexts.IGLContext? sharedContext = null, int? samples = null, string? windowClass = null, bool isContextControlDisabled = false) -> void
static Silk.NET.Windowing.Window.PrioritizeOrAdd<T>(System.Func<T>! factory, bool isFirstParty = false) -> T
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Silk.NET.Windowing.VideoMode.AspectRatioEstimate.get -> Silk.NET.Maths.Vector2D<
Silk.NET.Windowing.WindowOptions.TopMost.get -> bool
Silk.NET.Windowing.WindowOptions.TopMost.set -> void
Silk.NET.Windowing.WindowOptions.WindowOptions(bool isVisible, Silk.NET.Maths.Vector2D<int> position, Silk.NET.Maths.Vector2D<int> size, double framesPerSecond, double updatesPerSecond, Silk.NET.Windowing.GraphicsAPI api, string! title, Silk.NET.Windowing.WindowState windowState, Silk.NET.Windowing.WindowBorder windowBorder, bool isVSync, bool shouldSwapAutomatically, Silk.NET.Windowing.VideoMode videoMode, int? preferredDepthBufferBits = null, int? preferredStencilBufferBits = null, Silk.NET.Maths.Vector4D<int>? preferredBitDepth = null, bool transparentFramebuffer = false, bool topMost = false, bool isEventDriven = false, Silk.NET.Core.Contexts.IGLContext? sharedContext = null, int? samples = null, string? windowClass = null, bool isContextControlDisabled = false) -> void
static Silk.NET.Windowing.Window.PrioritizeOrAdd<T>(System.Func<T>! factory, bool isFirstParty = false) -> T
28 changes: 28 additions & 0 deletions src/Windowing/Silk.NET.Windowing.Common/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,34 @@ public static void PrioritizeSdl()
Prioritize(platform);
}

/// <summary>
/// <see cref="Prioritize"/>s the platform of type <typeparamref name="T"/> if it's already been added,
/// otherwise it uses <paramref name="factory"/> to create an instance to <see cref="Add"/> the platform. The
/// instance used is returned.
/// </summary>
/// <param name="factory">The factory to use if the platform has not been registered.</param>
/// <param name="isFirstParty">If true, first-party reflection-based loading will be disabled.</param>
/// <typeparam name="T">The platform type.</typeparam>
/// <returns>The platform instance.</returns>
public static T PrioritizeOrAdd<T>(Func<T> factory, bool isFirstParty = false) where T: IWindowPlatform
{
if (isFirstParty)
{
_initializedFirstPartyPlatforms = true;
}

var platform = (T?)_platformsValues.FirstOrDefault(x => x is T);
if (platform is null)
{
var inst = factory();
Add(inst);
return inst;
}

Prioritize(platform);
return platform;
}

/// <summary>
/// Adds this window platform to the platform list. Shouldn't be used unless writing your own windowing backend.
/// </summary>
Expand Down
33 changes: 32 additions & 1 deletion src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,45 @@ public override void SetWindowIcon(ReadOnlySpan<RawImage> icons)
throw new InvalidOperationException("Window should be initialized.");
}

var budget = 1024;
if (icons == null)
{
_glfw.SetWindowIcon(_glfwWindow, 0, null);
}
else
{
var images = stackalloc Image[icons.Length];
nint harr = 0;
var harrLen = 0;
var harrOff = 0;
for (var i = 0; i < icons.Length; i++)
{
var icon = icons[i];
// ReSharper disable once StackAllocInsideLoop
Span<byte> iconMemory = stackalloc byte[icon.Pixels.Length];
var iconMemory = budget >= icon.Pixels.Length
? stackalloc byte[icon.Pixels.Length]
: harr == 0
? null
: new Span<byte>((void*)(harr + harrOff), icon.Pixels.Length);
if (iconMemory == null)
{
for (var j = i; j < icons.Length; j++)
{
harrLen += icons[j].Pixels.Length;
}

harr = SilkMarshal.Allocate(harrLen);
iconMemory = new Span<byte>((void*) harr, icon.Pixels.Length);
harrOff = icon.Pixels.Length;
}
else if (budget >= icon.Pixels.Length)
{
budget -= icon.Pixels.Length;
}
else
{
harrOff += icon.Pixels.Length;
}
images[i] = new()
{
Width = icon.Width, Height = icon.Height,
Expand All @@ -446,6 +473,10 @@ public override void SetWindowIcon(ReadOnlySpan<RawImage> icons)
}

_glfw.SetWindowIcon(_glfwWindow, icons.Length, images);
if (harr != 0)
{
SilkMarshal.Free(harr);
}
GLFW.Glfw.ThrowExceptions();
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindowing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ public static class GlfwWindowing
{
public static void RegisterPlatform()
{
Window.Add(new GlfwPlatform());
if (Window.GetOrDefault<GlfwPlatform>() is null)
{
Window.Add(new GlfwPlatform());
}
}

/// <summary>
/// Prioritizes the GLFW windowing platform over others.
/// </summary>
public static void Use() => Window.PrioritizeGlfw();
public static void Use() => Window.PrioritizeOrAdd(() => new GlfwPlatform(), true);

/// <summary>
/// Gets a value indicating whether the given view is a GLFW view.
Expand Down
2 changes: 1 addition & 1 deletion src/Windowing/Silk.NET.Windowing.Sdl/SdlWindowing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static unsafe IView CreateFrom(void* handle, IGLContext? ctx = null)
/// <summary>
/// Prioritizes the SDL windowing platform over others.
/// </summary>
public static void Use() => Window.PrioritizeSdl();
public static void Use() => Window.PrioritizeOrAdd(() => new SdlPlatform(), true);

/// <summary>
/// Gets a value indicating whether the given view is an SDL view.
Expand Down

0 comments on commit 521e18a

Please sign in to comment.