Skip to content

Commit

Permalink
AOT Support (#303)
Browse files Browse the repository at this point in the history
* AOT Support?

* Renames

* Register Windowing platforms with input platforms

* Remove the need to disable first-party loading

* Move WindowOptions defaults to static ctor

* Cleanup

* Style

* Rollback Version changes

* Multi-Target Silk.NET.Core to .Net Core 3.0

* Remove NET5_0 were unneeded

* SdlInput.RegisterWindow -> SdlInput.RegisterPlatform

* Refactor Window options to guarantee valid defaults

* netcoreapp3.0 -> netcoreapp3.1

* Add extra restore to SilkTouch

* Fix SilkTouch targetting issue

* Fix Typo

* Complete netcoreapp3.0 -> netcoreapp3.1

* ass -> asm

* Fix SilkTouch NuGet

* EnableSourceLink -> SilkEnableSourceLink
  • Loading branch information
HurricanKai committed Sep 25, 2020
1 parent 9d5bfc0 commit cde61b6
Show file tree
Hide file tree
Showing 51 changed files with 962 additions and 82 deletions.
4 changes: 2 additions & 2 deletions build/props/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
</Description>
</PropertyGroup>
<!-- SourceLink -->
<PropertyGroup>
<PropertyGroup Condition="'$(SilkEnableSourceLink)' == ''">
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<ItemGroup Condition="'$(SilkEnableSourceLink)' == ''">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tutorial</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Silk.NET.BuildTools/Silk.NET.BuildTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Silk.NET.BuildTools</RootNamespace>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
12 changes: 6 additions & 6 deletions src/Core/Silk.NET.Core/Loader/LibraryLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

#if NETCOREAPP3_0
#if NETCOREAPP3_1
using System.Reflection;
using NativeLibrary3 = System.Runtime.InteropServices.NativeLibrary;
#else
Expand Down Expand Up @@ -303,8 +303,8 @@ public void FreeNativeLibrary(IntPtr handle)
/// <returns>A LibraryLoader suitable for loading libraries.</returns>
public static LibraryLoader GetPlatformDefaultLoader()
{
#if NETCOREAPP3_0
return new NetCoreNativeLibraryLoader();
#if NETCOREAPP3_1
return new NetNextNativeLibraryLoader();
#else

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down Expand Up @@ -333,12 +333,12 @@ private static void PlatformNotSupported()
throw new PlatformNotSupportedException("This platform cannot load native libraries.");
}

#if NETCOREAPP3_0
private class NetCoreNativeLibraryLoader : LibraryLoader
#if NETCOREAPP3_1
private class NetNextNativeLibraryLoader : LibraryLoader
{
protected override IntPtr CoreLoadNativeLibrary(string name)
{
if (NativeLibrary3.TryLoad(name, Assembly.GetCallingAssembly(), null, out var lib))
if (NativeLibrary3.TryLoad(name, out var lib))
{
return lib;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Silk.NET.Core/Silk.NET.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
</PropertyGroup>
Expand Down
8 changes: 7 additions & 1 deletion src/Core/Silk.NET.SilkTouch/Silk.NET.SilkTouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<IncludeBuildOutput>false</IncludeBuildOutput>
<SilkEnableSourceLink>false</SilkEnableSourceLink>
</PropertyGroup>

<PropertyGroup>
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Silk.NET.Core\Native\NativeApiAttribute.cs" />
<Compile Include="..\Silk.NET.Core\Native\UnmanagedType.cs" />
Expand All @@ -19,4 +23,6 @@
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

<Import Project="..\..\..\build\props\common.props" />

</Project>
32 changes: 28 additions & 4 deletions src/Input/Silk.NET.Input.Common/InputWindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,36 @@ namespace Silk.NET.Input
/// </summary>
public static class InputWindowExtensions
{
private static List<IInputPlatform> _platforms = new List<IInputPlatform>();

/// <summary>
/// Gets the input platforms currently registered with the input system.
/// </summary>
public static IReadOnlyList<IInputPlatform> Platforms { get; } = new List<IInputPlatform>();
public static IReadOnlyList<IInputPlatform> Platforms
{
get
{
if (!_initializedFirstPartyPlatforms)
{
DoLoadFirstPartyPlatformsViaReflection();
_initializedFirstPartyPlatforms = true;
}

return _platforms;
}
}

private static bool _initializedFirstPartyPlatforms = false;

static InputWindowExtensions()
public static void ShouldLoadFirstPartyPlatforms(bool shouldLoad)
{
if (_initializedFirstPartyPlatforms)
throw new InvalidOperationException("Input Platforms already loaded, cannot change first party loading");

_initializedFirstPartyPlatforms = !shouldLoad;
}

private static void DoLoadFirstPartyPlatformsViaReflection()
{
TryAdd("Silk.NET.Input.Glfw");
TryAdd("Silk.NET.Input.Sdl");
Expand Down Expand Up @@ -52,13 +76,13 @@ public static IInputContext CreateInput(this IView view)
/// Adds this input platform to the platform list. Shouldn't be used unless writing your own input backend.
/// </summary>
/// <param name="platform">The platform to add.</param>
public static void Add(IInputPlatform platform) => ((List<IInputPlatform>) Platforms).Add(platform);
public static void Add(IInputPlatform platform) => _platforms.Add(platform);

/// <summary>
/// Removes this input platform from the platform list. Shouldn't be used unless writing your own input backend.
/// </summary>
/// <param name="platform">The platform to remove.</param>
public static void Remove(IInputPlatform platform) => ((List<IInputPlatform>) Platforms).Remove(platform);
public static void Remove(IInputPlatform platform) => _platforms.Remove(platform);

/// <summary>
/// Attempts to load the given assembly by name, checks for a <see cref="IInputPlatform"/>, if one is found it
Expand Down
19 changes: 19 additions & 0 deletions src/Input/Silk.NET.Input.Glfw/GlfwInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is part of Silk.NET.
//
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using Silk.NET.Windowing;
using Silk.NET.Windowing.Glfw;

namespace Silk.NET.Input.Glfw
{
public static class GlfwInput
{
public static void RegisterPlatform()
{
Window.Add(new GlfwPlatform());
InputWindowExtensions.Add(new GlfwInputPlatform());
}
}
}
19 changes: 19 additions & 0 deletions src/Input/Silk.NET.Input.Sdl/SdlInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is part of Silk.NET.
//
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using Silk.NET.Windowing;
using Silk.NET.Windowing.Sdl;

namespace Silk.NET.Input.Sdl
{
public static class SdlInput
{
public static void RegisterPlatform()
{
Window.Add(new SdlPlatform());
InputWindowExtensions.Add(new SdlInputPlatform());
}
}
}
2 changes: 1 addition & 1 deletion src/Lab/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</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
36 changes: 36 additions & 0 deletions src/Lab/CoreRTTest/BufferObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Silk.NET.OpenGL;
using System;

namespace Tutorial
{
public class BufferObject<TDataType> : IDisposable
where TDataType : unmanaged
{
private uint _handle;
private BufferTargetARB _bufferType;
private GL _gl;

public unsafe BufferObject(GL gl, Span<TDataType> data, BufferTargetARB bufferType)
{
_gl = gl;
_bufferType = bufferType;

_handle = _gl.GenBuffer();
Bind();
fixed (void* d = data)
{
_gl.BufferData(bufferType, (UIntPtr)(data.Length * sizeof(TDataType)), d, BufferUsageARB.StaticDraw);
}
}

public void Bind()
{
_gl.BindBuffer(_bufferType, _handle);
}

public void Dispose()
{
_gl.DeleteBuffer(_handle);
}
}
}
Loading

0 comments on commit cde61b6

Please sign in to comment.