Skip to content

Commit

Permalink
Native: More work on GPU implementation (both D3D12 and Vulkan)
Browse files Browse the repository at this point in the history
Managed: Working on native engine integration and usage for Image loading.
  • Loading branch information
amerkoleci committed Dec 5, 2024
1 parent 14b9d3f commit e3e30c6
Show file tree
Hide file tree
Showing 36 changed files with 1,911 additions and 811 deletions.
1 change: 1 addition & 0 deletions Alimer.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<When Condition="($([MSBuild]::IsOsPlatform('windows')) and '$(RuntimeIdentifier)'=='') or '$(RuntimeIdentifier)'=='win-x64'">
<ItemGroup>
<None Include="$(AlimerNativeDirectory)win-x64/alimer_native.dll" Link="alimer_native.dll" Visible="False" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(AlimerNativeDirectory)win-x64/openal.dll" Link="openal.dll" Visible="False" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</When>
<When Condition="($([MSBuild]::IsOsPlatform('windows')) and '$(RuntimeIdentifier)'=='') or '$(RuntimeIdentifier)'=='win-arm64'">
Expand Down
6 changes: 6 additions & 0 deletions Alimer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Alimer.ImGui", "src\Alimer.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Alimer.ShaderCompiler", "src\assets\Alimer.ShaderCompiler\Alimer.ShaderCompiler.csproj", "{40A434AE-8653-4F40-B096-3B620DD092A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alimer.Native", "src\Alimer.Native\Alimer.Native.csproj", "{B9A73BF6-EBAB-4585-AD73-B3B6A496C3BC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -152,6 +154,10 @@ Global
{40A434AE-8653-4F40-B096-3B620DD092A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40A434AE-8653-4F40-B096-3B620DD092A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40A434AE-8653-4F40-B096-3B620DD092A7}.Release|Any CPU.Build.0 = Release|Any CPU
{B9A73BF6-EBAB-4585-AD73-B3B6A496C3BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9A73BF6-EBAB-4585-AD73-B3B6A496C3BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9A73BF6-EBAB-4585-AD73-B3B6A496C3BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9A73BF6-EBAB-4585-AD73-B3B6A496C3BC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 0 additions & 7 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
</AssemblyAttribute>
</ItemGroup>

<!-- Assembly attributes to include for every project -->
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatformAttribute">
<_Parameter1>windows10.0.19043.0</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<!-- platform version number information -->
<PropertyGroup Condition=" '$(_AlimerTargetPlatformIsWinUI)' == 'True' ">
<SupportedOSPlatformVersion>10.0.19043.0</SupportedOSPlatformVersion>
Expand Down
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<PackageVersion Include="Vortice.Win32.Graphics.Direct3D12" Version="$(VorticeWin32Version)" />
<PackageVersion Include="XenoAtom.Collections" Version="1.2.0" />
<PackageVersion Include="Alimer.Bindings.SDL" Version="3.9.4" />
<PackageVersion Include="StbImageSharp" Version="2.30.15" />

<!-- Graphics -->
<PackageVersion Include="Alimer.Bindings.WebGPU" Version="1.5.0" />
Expand Down
Binary file modified native/linux-x64/libopenal.so
Binary file not shown.
Binary file removed native/osx-arm64/libopenal.dylib
Binary file not shown.
Binary file removed native/osx-x64/libopenal.dylib
Binary file not shown.
File renamed without changes.
Binary file added native/osx/libopenal.dylib
Binary file not shown.
Binary file removed native/win-x64/OpenAL32.dll
Binary file not shown.
Binary file modified native/win-x64/alimer_native.dll
Binary file not shown.
Binary file added native/win-x64/openal.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions samples/Alimer.Samples/SampleBrowserApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ protected override void Initialize()
//_runningSample = new DrawIndexedQuadSample(Services, MainWindow);
//_runningSample = new DrawCubeSample(Services, MainWindow);
//_runningSample = new DrawTexturedCubeSample(Services, MainWindow);
//_runningSample = new DrawTexturedFromFileCubeSample(GraphicsDevice, MainWindow);
_runningSample = new DrawTexturedFromFileCubeSample(Services, MainWindow);
//_runningSample = new DrawMeshSample(Services, MainWindow);

// Engine samples (scene)
_runningSample = new SceneCubeSample(Services);
//_runningSample = new SceneCubeSample(Services);

MainWindow.Title = $"{_runningSample.Name} - {GraphicsDevice.Backend}";
}
Expand Down
40 changes: 0 additions & 40 deletions src/Alimer.Bindings.OpenAL/Alimer.Bindings.OpenAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,4 @@
<CopyContentFiles>True</CopyContentFiles>
</PropertyGroup>

<ItemGroup Condition="'$(CopyContentFiles)' == 'True'">
<Content Include="$(AlimerNativeDirectory)win-x64\OpenAL32.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes\win-x64\native\%(RecursiveDir)%(Filename)%(Extension)</Link>
<PackagePath>runtimes/win-x64/native</PackagePath>
<Pack>true</Pack>
</Content>
<Content Include="$(AlimerNativeDirectory)win-arm64\OpenAL32.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes\win-arm64\native\%(RecursiveDir)%(Filename)%(Extension)</Link>
<PackagePath>runtimes/win-arm64/native</PackagePath>
<Pack>true</Pack>
</Content>
<Content Include="$(AlimerNativeDirectory)linux-x64\libopenal.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes\linux-x64\native\%(RecursiveDir)%(Filename)%(Extension)</Link>
<PackagePath>runtimes/linux-x64/native</PackagePath>
<Pack>true</Pack>
</Content>
<Content Include="$(AlimerNativeDirectory)linux-arm64\libopenal.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes\linux-arm64\native\%(RecursiveDir)%(Filename)%(Extension)</Link>
<PackagePath>runtimes/linux-arm64/native</PackagePath>
<Pack>true</Pack>
</Content>
<!-- TODO: Add osx-universal -->
<Content Include="$(AlimerNativeDirectory)osx-x64\libopenal.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes\osx-x64\native\%(RecursiveDir)%(Filename)%(Extension)</Link>
<PackagePath>runtimes/osx-x64/native</PackagePath>
<Pack>true</Pack>
</Content>
<Content Include="$(AlimerNativeDirectory)osx-arm64\libopenal.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes\osx-arm64\native\%(RecursiveDir)%(Filename)%(Extension)</Link>
<PackagePath>runtimes/osx-arm64/native</PackagePath>
<Pack>true</Pack>
</Content>
</ItemGroup>

</Project>
50 changes: 25 additions & 25 deletions src/Alimer.Bindings.OpenAL/OpenAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Alimer.Bindings.OpenAL;

public static partial class OpenAL
{
private const string LibName = "OpenAL32";
private const string LibraryName = "openal";

/** Context attribute: <int> Hz. */
public const int ALC_FREQUENCY = 0x1007;
Expand All @@ -21,7 +21,7 @@ static OpenAL()

private static nint OnDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
if (libraryName.Equals(LibName) && TryResolveOpenAL(assembly, searchPath, out nint nativeLibrary))
if (libraryName.Equals(LibraryName) && TryResolveOpenAL(assembly, searchPath, out nint nativeLibrary))
{
return nativeLibrary;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ private static bool TryResolveOpenAL(Assembly assembly, DllImportSearchPath? sea
}

#region Alc
[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
private static unsafe partial ALCdevice alcOpenDevice(byte* deviceName);

public static unsafe ALCdevice alcOpenDevice(string? deviceName)
Expand All @@ -76,13 +76,13 @@ public static unsafe ALCdevice alcOpenDevice(string? deviceName)
}
}

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial Bool8 alcCloseDevice(ALCdevice device);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial AlcError alcGetError(ALCdevice device);

[LibraryImport(LibName, EntryPoint = nameof(alcGetString))]
[LibraryImport(LibraryName, EntryPoint = nameof(alcGetString))]
private static unsafe partial byte* alcGetStringPrivate(ALCdevice device, int param);

public static unsafe string alcGetString(ALCdevice device, int param)
Expand All @@ -95,7 +95,7 @@ public static unsafe string alcGetString(ALCdevice device, int param)
public static string alcGetString(ALCdevice device, AlcGetString param) => alcGetString(device, (int)param);
public static string alcGetString(AlcGetString param) => alcGetString(ALCdevice.Null, (int)param);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static unsafe partial void alcGetIntegerv(ALCdevice device, AlcGetInteger param, int size, int* values);

public static unsafe int alcGetInteger(ALCdevice device, AlcGetInteger param)
Expand All @@ -105,7 +105,7 @@ public static unsafe int alcGetInteger(ALCdevice device, AlcGetInteger param)
return value;
}

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static unsafe partial Bool8 alcIsExtensionPresent(ALCdevice device, byte* extName);

public static unsafe bool alcIsExtensionPresent(string? extName)
Expand All @@ -124,7 +124,7 @@ public static unsafe bool alcIsExtensionPresent(ALCdevice device, string? extNam
}
}

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static unsafe partial ALCcontext alcCreateContext(ALCdevice device, int* attrlist);

public static unsafe ALCcontext alcCreateContext(ALCdevice device, Span<int> attributes)
Expand All @@ -139,39 +139,39 @@ public static unsafe ALCcontext alcCreateContext(ALCdevice device, int[] attribu
return alcCreateContext(device, attrlist);
}

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial Bool8 alcMakeContextCurrent(ALCcontext context);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alcProcessContext(ALCcontext context);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alcSuspendContext(ALCcontext context);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alcDestroyContext(ALCcontext context);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial ALCdevice alcGetContextsDevice(ALCcontext context);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial ALCcontext alcGetCurrentContext();
#endregion

#region AL
[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alEnable(int capability);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alDisable(int capability);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial Bool8 alIsEnabled(int capability);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial int alGetError();

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static unsafe partial Bool8 alIsExtensionPresent(byte* extName);

public static unsafe bool alIsExtensionPresent(string? extName)
Expand All @@ -182,19 +182,19 @@ public static unsafe bool alIsExtensionPresent(string? extName)
}
}

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alDopplerFactor(float value);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alDopplerVelocity(float value);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alSpeedOfSound(float value);

[LibraryImport(LibName)]
[LibraryImport(LibraryName)]
public static partial void alDistanceModel(AlDistanceModel distanceModel);

[LibraryImport(LibName, EntryPoint = nameof(alGetString))]
[LibraryImport(LibraryName, EntryPoint = nameof(alGetString))]
private static unsafe partial byte* alGetStringPrivate(int param);

public static unsafe string alGetString(int param)
Expand Down
2 changes: 1 addition & 1 deletion src/Alimer.Graphics/GraphicsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static ulong ComputeTextureMemorySizeInBytes(in TextureDescriptor descrip
uint pixelsPerBlock = descriptor.Format.GetFormatHeightCompressionRatio();
uint numBlocksX = descriptor.Width / pixelsPerBlock;
uint numBlocksY = descriptor.Height / pixelsPerBlock;
uint mipLevelCount = descriptor.MipLevelCount == 0 ? (uint)ImageDescription.GetMipLevelCount((int)descriptor.Width, (int)descriptor.Height, (int)descriptor.DepthOrArrayLayers) : descriptor.MipLevelCount;
uint mipLevelCount = descriptor.MipLevelCount == 0 ? ImageDescription.GetMipLevelCount(descriptor.Width, descriptor.Height, descriptor.DepthOrArrayLayers) : descriptor.MipLevelCount;
for (uint arrayLayer = 0; arrayLayer < descriptor.DepthOrArrayLayers; ++arrayLayer)
{
for (int mipLevel = 0; mipLevel < mipLevelCount; ++mipLevel)
Expand Down
2 changes: 1 addition & 1 deletion src/Alimer.Graphics/TextureDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public TextureDescriptor(
Width = width;
Height = height;
DepthOrArrayLayers = depthOrArrayLayers;
MipLevelCount = mipLevelCount == 0 ? (uint)ImageDescription.GetMipLevelCount((int)width, (int)height, dimension == TextureDimension.Texture3D ? (int)depthOrArrayLayers : 1) : mipLevelCount;
MipLevelCount = mipLevelCount == 0 ? ImageDescription.GetMipLevelCount(width, height, dimension == TextureDimension.Texture3D ? depthOrArrayLayers : 1u) : mipLevelCount;
SampleCount = sampleCount;
Usage = usage;
CpuAccess = access;
Expand Down
62 changes: 62 additions & 0 deletions src/Alimer.Native/Alimer.Native.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;net8.0;net9.0</TargetFrameworks>
<Description>Alimer native libraries</Description>
<PackageVersion>1.0.0</PackageVersion>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="$(AlimerRootDirectory)/README.md" Pack="true" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<Content Include="build\**" PackagePath="build/%(RecursiveDir)%(Filename)%(Extension)" />
<Content Include="$(MSBuildThisFileDirectory)_._" PackagePath="lib/netstandard2.0" />
<Content Include="$(MSBuildThisFileDirectory)_._" PackagePath="lib/net461" />
<Content Include="$(MSBuildThisFileDirectory)_._" PackagePath="lib/net8.0" />
<Content Include="$(MSBuildThisFileDirectory)_._" PackagePath="lib/net9.0" />
</ItemGroup>

<ItemGroup>
<None Include="$(AlimerNativeDirectory)win-x64\alimer_native.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<Pack>True</Pack>
<Visible>False</Visible>
</None>
<None Include="$(AlimerNativeDirectory)win-x64\openal.dll">
<PackagePath>runtimes\win-x64\native</PackagePath>
<Pack>True</Pack>
<Visible>False</Visible>
</None>
<None Include="$(AlimerNativeDirectory)win-arm64\alimer_native.dll">
<PackagePath>runtimes\win-arm64\native</PackagePath>
<Pack>True</Pack>
<Visible>False</Visible>
</None>
<None Include="$(AlimerNativeDirectory)linux-x64\libalimer_native.so">
<PackagePath>runtimes\linux-x64\native</PackagePath>
<Pack>True</Pack>
<Visible>False</Visible>
</None>
<None Include="$(AlimerNativeDirectory)linux-x64\libopenal.so">
<PackagePath>runtimes\linux-x64\native</PackagePath>
<Pack>True</Pack>
<Visible>False</Visible>
</None>
<None Include="$(AlimerNativeDirectory)osx\libalimer_native.dylib">
<PackagePath>runtimes\osx\native</PackagePath>
<Pack>True</Pack>
<Visible>False</Visible>
</None>
<None Include="$(AlimerNativeDirectory)osx\libopenal.dylib">
<PackagePath>runtimes\osx\native</PackagePath>
<Pack>True</Pack>
<Visible>False</Visible>
</None>
</ItemGroup>

</Project>
Empty file added src/Alimer.Native/_._
Empty file.
36 changes: 36 additions & 0 deletions src/Alimer.Native/build/net461/Alimer.Native.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AlimerTargetSystem Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">win</AlimerTargetSystem>
<AlimerTargetSystem Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">osx</AlimerTargetSystem>
<AlimerTargetSystem Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</AlimerTargetSystem>
</PropertyGroup>

<PropertyGroup>
<!-- handle PlatformTarget specifically -->
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == '' and '$(PlatformTarget)' == 'ARM'">arm</AlimerTargetPlatform>
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == '' and '$(PlatformTarget)' == 'ARM64'">arm64</AlimerTargetPlatform>
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == '' and '$(PlatformTarget)' == 'x86'">x86</AlimerTargetPlatform>
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == '' and '$(PlatformTarget)' == 'x64'">x64</AlimerTargetPlatform>
<!-- handle Any CPU, considering Prefer32Bit -->
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == '' and '$(Prefer32Bit)' == 'False'">x64</AlimerTargetPlatform>
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == '' and '$(Prefer32Bit)' == 'True'">x86</AlimerTargetPlatform>
<!-- fall back to x64 on 64-bit machines -->
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == '' and $([System.Environment]::Is64BitOperatingSystem)">x64</AlimerTargetPlatform>
<!-- fall back to x86 -->
<AlimerTargetPlatform Condition="'$(AlimerTargetPlatform)' == ''">x86</AlimerTargetPlatform>
</PropertyGroup>

<PropertyGroup>
<AlimerNativeLibrary Condition="'$(AlimerTargetSystem)' == 'win'">$(MSBuildThisFileDirectory)..\..\runtimes\$(AlimerTargetSystem)-$(AlimerTargetPlatform)\native\alimer_native.dll</AlimerNativeLibrary>
<AlimerNativeLibrary Condition="'$(AlimerTargetSystem)' == 'osx'">$(MSBuildThisFileDirectory)..\..\runtimes\$(AlimerTargetSystem)-$(AlimerTargetPlatform)\native\libalimer_native.dylib</AlimerNativeLibrary>
<AlimerNativeLibrary Condition="'$(AlimerTargetSystem)' == 'linux'">$(MSBuildThisFileDirectory)..\..\runtimes\$(AlimerTargetSystem)-$(AlimerTargetPlatform)\native\libalimer_native.so</AlimerNativeLibrary>
</PropertyGroup>

<ItemGroup>
<None Include="$(AlimerNativeLibrary)" Condition="Exists('$(AlimerNativeLibrary)')">
<Link>$([System.IO.Path]::GetFilename('$(AlimerNativeLibrary)'))</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Loading

0 comments on commit e3e30c6

Please sign in to comment.