Skip to content

Commit

Permalink
Occlusion query API added.
Browse files Browse the repository at this point in the history
Added DesktopVK to MG platforms.
  • Loading branch information
tomspilman committed Sep 13, 2024
1 parent 4f54da2 commit 06f8e9c
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 9 deletions.
21 changes: 21 additions & 0 deletions MonoGame.Framework/Platform/Native/Graphics.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ [MGHandle] internal readonly struct MGG_Texture { }
[MGHandle] internal readonly struct MGG_SamplerState { }
[MGHandle] internal readonly struct MGG_Shader { }
[MGHandle] internal readonly struct MGG_InputLayout { }
[MGHandle] internal readonly struct MGG_OcclusionQuery { }


[StructLayout(LayoutKind.Sequential)]
Expand Down Expand Up @@ -407,4 +408,24 @@ public static partial void Texture_GetData(
public static partial void Shader_Destroy(MGG_GraphicsDevice* device, MGG_Shader* shader);

#endregion

#region Occlusion Query

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGG_OcclusionQuery_Create", StringMarshalling = StringMarshalling.Utf8)]
public static partial MGG_OcclusionQuery* OcclusionQuery_Create(MGG_GraphicsDevice* device);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGG_OcclusionQuery_Destroy", StringMarshalling = StringMarshalling.Utf8)]
public static partial void OcclusionQuery_Destroy(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGG_OcclusionQuery_Begin", StringMarshalling = StringMarshalling.Utf8)]
public static partial void OcclusionQuery_Begin(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGG_OcclusionQuery_End", StringMarshalling = StringMarshalling.Utf8)]
public static partial void OcclusionQuery_End(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGG_OcclusionQuery_GetResult", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
public static partial bool OcclusionQuery_GetResult(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query, out int pixelCount);

#endregion
}
32 changes: 26 additions & 6 deletions MonoGame.Framework/Platform/Native/OcclusionQuery.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,45 @@
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

using MonoGame.Interop;

namespace Microsoft.Xna.Framework.Graphics;

partial class OcclusionQuery
{
private void PlatformConstruct()
internal unsafe MGG_OcclusionQuery* Handle;

private unsafe void PlatformConstruct()
{
Handle = MGG.OcclusionQuery_Create(GraphicsDevice.Handle);
}

private unsafe void PlatformBegin()
{
MGG.OcclusionQuery_Begin(GraphicsDevice.Handle, Handle);
}

private void PlatformBegin()
private unsafe void PlatformEnd()
{
MGG.OcclusionQuery_End(GraphicsDevice.Handle, Handle);
}

private void PlatformEnd()
private unsafe bool PlatformGetResult(out int pixelCount)
{
return MGG.OcclusionQuery_GetResult(GraphicsDevice.Handle, Handle, out pixelCount);
}

private bool PlatformGetResult(out int pixelCount)
protected unsafe override void Dispose(bool disposing)
{
pixelCount = 0;
return false;
if (!IsDisposed)
{
if (disposing)
{
MGG.OcclusionQuery_Destroy(GraphicsDevice.Handle, Handle);
Handle = null;
}
}

base.Dispose(disposing);
}
}
7 changes: 6 additions & 1 deletion MonoGame.Framework/Utilities/MonoGamePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public enum MonoGamePlatform
/// <summary>
/// MonoGame Nintendo Switch platform.
/// </summary>
NintendoSwitch
NintendoSwitch,

/// <summary>
/// All desktop versions using Vulkan.
/// </summary>
DesktopVK,
}
}
6 changes: 6 additions & 0 deletions native/monogame/include/api_MGG.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct MGG_Texture;
struct MGG_SamplerState;
struct MGG_Shader;
struct MGG_InputLayout;
struct MGG_OcclusionQuery;

MG_EXPORT void MGG_EffectResource_GetBytecode(const char* name, mgbyte*& bytecode, mgint& size);
MG_EXPORT MGG_GraphicsSystem* MGG_GraphicsSystem_Create();
Expand Down Expand Up @@ -74,3 +75,8 @@ MG_EXPORT MGG_InputLayout* MGG_InputLayout_Create(MGG_GraphicsDevice* device, MG
MG_EXPORT void MGG_InputLayout_Destroy(MGG_GraphicsDevice* device, MGG_InputLayout* layout);
MG_EXPORT MGG_Shader* MGG_Shader_Create(MGG_GraphicsDevice* device, MGShaderStage stage, mgbyte* bytecode, mgint sizeInBytes);
MG_EXPORT void MGG_Shader_Destroy(MGG_GraphicsDevice* device, MGG_Shader* shader);
MG_EXPORT MGG_OcclusionQuery* MGG_OcclusionQuery_Create(MGG_GraphicsDevice* device);
MG_EXPORT void MGG_OcclusionQuery_Destroy(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query);
MG_EXPORT void MGG_OcclusionQuery_Begin(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query);
MG_EXPORT void MGG_OcclusionQuery_End(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query);
MG_EXPORT mgbool MGG_OcclusionQuery_GetResult(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query, mgint& pixelCount);
1 change: 1 addition & 0 deletions native/monogame/include/api_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ enum class MGMonoGamePlatform : mgint
PlayStation4 = 7,
PlayStation5 = 8,
NintendoSwitch = 9,
DesktopVK = 10,
};

enum class MGGraphicsBackend : mgint
Expand Down
4 changes: 2 additions & 2 deletions native/monogame/sdl/MGP_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ void MGP_Platform_BeforeInitialize(MGP_Platform* platform)

MGMonoGamePlatform MGP_Platform_GetPlatform()
{
#if _WIN32
return MGMonoGamePlatform::Windows;
#if MG_VULKAN
return MGMonoGamePlatform::DesktopVK;
#else
assert(false);
return (MGMonoGamePlatform)-1;
Expand Down
55 changes: 55 additions & 0 deletions native/monogame/vulkan/MGG_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ struct MGG_SamplerState
MGG_SamplerState_Info info;
};

struct MGG_OcclusionQuery
{
// TODO!
};

struct MGG_GraphicsSystem
{
Expand Down Expand Up @@ -3955,3 +3959,54 @@ void MGG_Shader_Destroy(MGG_GraphicsDevice* device, MGG_Shader* shader)
mg_remove(device->all_shaders, shader);
delete shader;
}

MGG_OcclusionQuery* MGG_OcclusionQuery_Create(MGG_GraphicsDevice* device)
{
assert(device != nullptr);

auto query = new MGG_OcclusionQuery();

// TODO: Implement!

return query;
}

void MGG_OcclusionQuery_Destroy(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query)
{
assert(device != nullptr);
assert(query != nullptr);

if (!query)
return;

// TODO: Implement!

delete query;
}

void MGG_OcclusionQuery_Begin(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query)
{
assert(device != nullptr);
assert(query != nullptr);

// TODO: Implement!
}

void MGG_OcclusionQuery_End(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query)
{
assert(device != nullptr);
assert(query != nullptr);

// TODO: Implement!
}

mgbool MGG_OcclusionQuery_GetResult(MGG_GraphicsDevice* device, MGG_OcclusionQuery* query, mgint& pixelCount)
{
assert(device != nullptr);
assert(query != nullptr);

// TODO: Implement!

pixelCount = 0;
return true;
}

0 comments on commit 06f8e9c

Please sign in to comment.