Skip to content

Commit

Permalink
[PAID BOUNTY] A shared base for public and console repos (MonoGame#8309)
Browse files Browse the repository at this point in the history
This is a shared native base for future platform work in MonoGame.

See MonoGame#8242

The implementation is now finished and we're looking for final feedback
before we merge things.

- ~~C# to C++ wrapper generator.~~
- ~~C# native wrapper.~~
- ~~Windows VK setup.~~
- ~~C++ native wrapper.~~
- ~~SDL native backend.~~
- ~~Vulkan rendering backend.~~
- ~~Input native backend.~~
- ~~WindowsVK unit tests.~~
- ~~Sound API stubs~~

---------

Co-authored-by: harry.cpp <[email protected]>
  • Loading branch information
tomspilman and harry-cpp authored Sep 25, 2024
1 parent d44ed76 commit c42673d
Show file tree
Hide file tree
Showing 186 changed files with 24,235 additions and 2,203 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,27 @@ jobs:
with:
dotnet-version: '8.0.x'

- name: Add msbuild to PATH
if: runner.os == 'Windows'
uses: microsoft/[email protected]

- name: Setup Premake5
uses: abel0b/[email protected]
with:
version: "5.0.0-beta2"

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '17'

- name: Install Vulkan SDK
uses: humbletim/[email protected]
with:
version: 1.3.283.0
cache: true

- name: Disable annotations
run: echo "::remove-matcher owner=csc::"

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,9 @@ IDE/MonoDevelop/MonoDevelop.MonoGame/templates/Common/MonoGame.Framework.dll.con
# CAKE
.cake/**

# Xmake
.xmake
vsxmake2022

# docfx
_*
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@
[submodule "ThirdParty/StbImageWriteSharp"]
path = ThirdParty/StbImageWriteSharp
url = https://github.com/StbSharp/StbImageWriteSharp.git
[submodule "src/monogame/external/sdl2"]
path = native/monogame/external/sdl2
url = https://github.com/MonoGame/MonoGame.Library.SDL.git
[submodule "src/monogame/external/vulkan-headers"]
path = native/monogame/external/vulkan-headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
[submodule "src/monogame/external/volk"]
path = native/monogame/external/volk
url = https://github.com/zeux/volk.git
[submodule "src/monogame/external/vma"]
path = native/monogame/external/vma
url = https://github.com/LunarG/VulkanMemoryAllocator.git
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Generator: CTypes",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "generator-ctypes",
"program": "${workspaceFolder}/Tools/MonoGame.Generator.CTypes/bin/Debug/net8.0/MonoGame.Generator.CTypes",
"args": [],
"cwd": "${workspaceFolder}/Tools/MonoGame.Generator.CTypes/bin/Debug/net8.0",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "MGCB Editor (Mac)",
"type": "coreclr",
Expand Down
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "generator-ctypes",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Tools/MonoGame.Generator.CTypes/MonoGame.Generator.CTypes.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public override bool Supports(TargetPlatform platform)
{
return platform == TargetPlatform.Android ||
platform == TargetPlatform.DesktopGL ||
platform == TargetPlatform.DesktopVK ||
platform == TargetPlatform.MacOSX ||
platform == TargetPlatform.NativeClient ||
platform == TargetPlatform.RaspberryPi ||
Expand Down Expand Up @@ -64,6 +65,7 @@ private static TextureProcessorOutputFormat GetTextureFormatForPlatform(TextureP
}
else if (platform == TargetPlatform.Windows ||
platform == TargetPlatform.DesktopGL ||
platform == TargetPlatform.DesktopVK ||
platform == TargetPlatform.MacOSX ||
platform == TargetPlatform.NativeClient ||
platform == TargetPlatform.Web)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ private string GetProfileForPlatform(TargetPlatform platform)
case TargetPlatform.RaspberryPi:
case TargetPlatform.Web:
return "OpenGL";
case TargetPlatform.DesktopVK:
return "Vulkan";
}

return platform.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public sealed class ContentWriter : BinaryWriter
'O', // XboxOne
'S', // Nintendo Switch
'b', // WebAssembly and Bridge.NET
'V', // DesktopVK (Vulkan)
};

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion MonoGame.Framework.Content.Pipeline/TargetPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ public enum TargetPlatform
/// <summary>
/// WebAssembly and Bridge.NET
/// </summary>
Web
Web,

/// <summary>
/// All desktop versions using Vulkan.
/// </summary>
DesktopVK,
}


Expand Down
88 changes: 84 additions & 4 deletions MonoGame.Framework.Native.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,100 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Native", "MonoGame.Framework\MonoGame.Framework.Native.csproj", "{56BA741D-6AF1-489B-AB00-338DE11B1D32}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGame.Framework.Native", "MonoGame.Framework\MonoGame.Framework.Native.csproj", "{56BA741D-6AF1-489B-AB00-338DE11B1D32}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{65B3DC17-24BA-4C39-810F-E371AC48199A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGame.Generator.CTypes", "Tools\MonoGame.Generator.CTypes\MonoGame.Generator.CTypes.csproj", "{74F12E34-D96B-4EC1-A218-BAFC83DC6220}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGame.Tests.WindowsVK", "Tests\MonoGame.Tests.WindowsVK.csproj", "{C670BF60-56F7-493F-B5DD-50F97DB80A04}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "desktopvk", "native\monogame\desktopvk.vcxproj", "{60D6243F-CC40-D9B5-157F-8A5B8128B70A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_VK|Any CPU = Debug_VK|Any CPU
Debug_VK|x64 = Debug_VK|x64
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release_VK|Any CPU = Release_VK|Any CPU
Release_VK|x64 = Release_VK|x64
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug_VK|Any CPU.ActiveCfg = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug_VK|Any CPU.Build.0 = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug_VK|x64.ActiveCfg = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug_VK|x64.Build.0 = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|x64.ActiveCfg = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|x64.Build.0 = Debug|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release_VK|Any CPU.ActiveCfg = Release|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release_VK|Any CPU.Build.0 = Release|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release_VK|x64.ActiveCfg = Release|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release_VK|x64.Build.0 = Release|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|Any CPU.Build.0 = Release|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|x64.ActiveCfg = Release|Any CPU
{56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|x64.Build.0 = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug_VK|Any CPU.ActiveCfg = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug_VK|Any CPU.Build.0 = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug_VK|x64.ActiveCfg = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug_VK|x64.Build.0 = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|x64.ActiveCfg = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|x64.Build.0 = Debug|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release_VK|Any CPU.ActiveCfg = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release_VK|Any CPU.Build.0 = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release_VK|x64.ActiveCfg = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release_VK|x64.Build.0 = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|Any CPU.Build.0 = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|x64.ActiveCfg = Release|Any CPU
{74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|x64.Build.0 = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug_VK|Any CPU.ActiveCfg = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug_VK|Any CPU.Build.0 = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug_VK|x64.ActiveCfg = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug_VK|x64.Build.0 = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug|x64.ActiveCfg = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Debug|x64.Build.0 = Debug|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release_VK|Any CPU.ActiveCfg = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release_VK|Any CPU.Build.0 = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release_VK|x64.ActiveCfg = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release_VK|x64.Build.0 = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release|Any CPU.Build.0 = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release|x64.ActiveCfg = Release|Any CPU
{C670BF60-56F7-493F-B5DD-50F97DB80A04}.Release|x64.Build.0 = Release|Any CPU
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug_VK|Any CPU.ActiveCfg = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug_VK|Any CPU.Build.0 = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug_VK|x64.ActiveCfg = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug_VK|x64.Build.0 = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug|Any CPU.ActiveCfg = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug|Any CPU.Build.0 = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug|x64.ActiveCfg = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Debug|x64.Build.0 = Debug|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release_VK|Any CPU.ActiveCfg = Release|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release_VK|Any CPU.Build.0 = Release|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release_VK|x64.ActiveCfg = Release|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release_VK|x64.Build.0 = Release|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release|Any CPU.ActiveCfg = Release|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release|Any CPU.Build.0 = Release|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release|x64.ActiveCfg = Release|x64
{60D6243F-CC40-D9B5-157F-8A5B8128B70A}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{74F12E34-D96B-4EC1-A218-BAFC83DC6220} = {65B3DC17-24BA-4C39-810F-E371AC48199A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CDA9FB22-5A50-47C6-B732-CE09AC673DCA}
EndGlobalSection
EndGlobal
26 changes: 12 additions & 14 deletions MonoGame.Framework/Audio/SoundEffectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ public partial class SoundEffectInstance : IDisposable
internal SoundEffect _effect;
private float _pan;
private float _volume;
private float _pitch;
private float _pitch;
private bool _isLooped;

/// <summary>Enables or Disables whether the SoundEffectInstance should repeat after playback.</summary>
/// <remarks>This value has no effect on an already playing sound.</remarks>
public virtual bool IsLooped
{
get { return PlatformGetIsLooped(); }
set { PlatformSetIsLooped(value); }
{
get { return _isLooped; }
set { _isLooped = value; }
}

/// <summary>Gets or sets the pan, or speaker balance..</summary>
Expand Down Expand Up @@ -94,13 +95,8 @@ internal SoundEffectInstance()
{
_pan = 0.0f;
_volume = 1.0f;
_pitch = 0.0f;
}

internal SoundEffectInstance(byte[] buffer, int sampleRate, int channels)
: this()
{
PlatformInitialize(buffer, sampleRate, channels);
_pitch = 0.0f;
_isLooped = false;
}

/// <summary>
Expand Down Expand Up @@ -142,19 +138,21 @@ public virtual void Play()
{
if (_isDisposed)
throw new ObjectDisposedException("SoundEffectInstance");

var state = State;

if (State == SoundState.Playing)
if (state == SoundState.Playing)
return;

if (State == SoundState.Paused)
if (state == SoundState.Paused)
{
Resume();
return;
}

// We don't need to check if we're at the instance play limit
// if we're resuming from a paused state.
if (State != SoundState.Paused)
if (state != SoundState.Paused)
{
if (!SoundEffectInstancePool.SoundsAvailable)
throw new InstancePlayLimitException();
Expand Down
1 change: 1 addition & 0 deletions MonoGame.Framework/Content/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public partial class ContentManager : IDisposable
'O', // XboxOne
'S', // Nintendo Switch
'b', // WebAssembly and Bridge.NET
'V', // DesktopVK

// NOTE: There are additional identifiers for consoles that
// are not defined in this repository. Be sure to ask the
Expand Down
4 changes: 2 additions & 2 deletions MonoGame.Framework/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ protected virtual void UnloadContent() { }
protected virtual void Initialize()
{
// TODO: This should be removed once all platforms use the new GraphicsDeviceManager
#if !(WINDOWS && DIRECTX)
#if !(WINDOWS && DIRECTX) && !NATIVE
applyChanges(graphicsDeviceManager);
#endif

Expand Down Expand Up @@ -791,7 +791,7 @@ private void Platform_AsyncRunLoopEnded(object sender, EventArgs e)
// break entirely the possibility that additional platforms could
// be added by third parties without changing MonoGame itself.

#if !(WINDOWS && DIRECTX)
#if !(WINDOWS && DIRECTX) && !NATIVE
internal void applyChanges(GraphicsDeviceManager manager)
{
Platform.BeginScreenDeviceChange(GraphicsDevice.PresentationParameters.IsFullScreen);
Expand Down
9 changes: 5 additions & 4 deletions MonoGame.Framework/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public abstract class GameWindow
/// </summary>
public virtual bool AllowAltF4 { get { return _allowAltF4; } set { _allowAltF4 = value; } }

#if WINDOWS || DESKTOPGL
/// <summary>
/// The location of this window on the desktop, eg: global coordinate space
/// which stretches across all screens.
///
/// May be zero on platforms where it is not supported.
/// </summary>
public abstract Point Position { get; set; }
#endif

/// <summary>
/// The display orientation on a mobile device.
Expand Down Expand Up @@ -123,7 +123,7 @@ protected GameWindow()
/// </summary>
public event EventHandler<EventArgs> ScreenDeviceNameChanged;

#if WINDOWS || DESKTOPGL|| ANGLE
#if WINDOWS || DESKTOPGL|| ANGLE || NATIVE

/// <summary>
/// Use this event to user text input.
Expand Down Expand Up @@ -228,7 +228,8 @@ protected void OnScreenDeviceNameChanged ()
EventHelpers.Raise(this, ScreenDeviceNameChanged, EventArgs.Empty);
}

#if WINDOWS || DESKTOPGL || ANGLE
#if WINDOWS || DESKTOPGL || ANGLE || NATIVE

/// <summary>
/// Called when the window receives text input. Raises the <see cref="TextInput"/> event.
/// </summary>
Expand Down
Loading

0 comments on commit c42673d

Please sign in to comment.