Refactor and enhance graphics and audio systems
Updated target frameworks to .NET 10.0 across multiple projects for compatibility with the latest features. Refactored namespaces and introduced new classes for shader descriptors, FMOD integration, and DirectX 12 utilities using TerraFX. Replaced `Win32` bindings with TerraFX equivalents for DirectX 12. Added a C# wrapper for FMOD Studio API, including DSP and error handling. Enhanced entity queries, component storage, and query filters for better performance and type safety. Introduced new test projects and updated the solution structure. Added `meshoptimizer` bindings and integrated `meshoptimizer_native.dll`. Improved code readability, maintainability, and performance.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using Ghost.Core;
|
||||
using Ghost.Graphics.Data;
|
||||
using Win32.Graphics.Direct3D12;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace Ghost.Graphics.RHI;
|
||||
|
||||
@@ -178,20 +178,20 @@ public enum ResourceState
|
||||
|
||||
internal static class ResourceStateExtensions
|
||||
{
|
||||
public static ResourceStates ToD3D12States(this ResourceState state)
|
||||
public static D3D12_RESOURCE_STATES ToD3D12States(this ResourceState state)
|
||||
{
|
||||
return state switch
|
||||
{
|
||||
ResourceState.Common or ResourceState.Present => ResourceStates.Common,
|
||||
ResourceState.VertexAndConstantBuffer => ResourceStates.VertexAndConstantBuffer,
|
||||
ResourceState.IndexBuffer => ResourceStates.IndexBuffer,
|
||||
ResourceState.RenderTarget => ResourceStates.RenderTarget,
|
||||
ResourceState.UnorderedAccess => ResourceStates.UnorderedAccess,
|
||||
ResourceState.DepthWrite => ResourceStates.DepthWrite,
|
||||
ResourceState.DepthRead => ResourceStates.DepthRead,
|
||||
ResourceState.PixelShaderResource => ResourceStates.PixelShaderResource,
|
||||
ResourceState.CopyDest => ResourceStates.CopyDest,
|
||||
ResourceState.CopySource => ResourceStates.CopySource,
|
||||
ResourceState.Common or ResourceState.Present => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON,
|
||||
ResourceState.VertexAndConstantBuffer => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER,
|
||||
ResourceState.IndexBuffer => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_INDEX_BUFFER,
|
||||
ResourceState.RenderTarget => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_RENDER_TARGET,
|
||||
ResourceState.UnorderedAccess => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
ResourceState.DepthWrite => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_DEPTH_WRITE,
|
||||
ResourceState.DepthRead => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_DEPTH_READ,
|
||||
ResourceState.PixelShaderResource => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
|
||||
ResourceState.CopyDest => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
ResourceState.CopySource => D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE,
|
||||
_ => throw new ArgumentException($"Unknown resource state: {state}")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Win32.Graphics.Direct3D12;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace Ghost.Graphics.RHI;
|
||||
|
||||
@@ -52,16 +52,15 @@ public struct ResourceDesc
|
||||
};
|
||||
}
|
||||
|
||||
internal static ResourceDesc FromD3D12(ResourceDescription desc)
|
||||
internal static ResourceDesc FromD3D12(D3D12_RESOURCE_DESC desc)
|
||||
{
|
||||
if (desc.Dimension == ResourceDimension.Buffer)
|
||||
if (desc.Dimension == D3D12_RESOURCE_DIMENSION.D3D12_RESOURCE_DIMENSION_BUFFER)
|
||||
{
|
||||
return Buffer(new BufferDesc
|
||||
{
|
||||
Size = desc.Width,
|
||||
Size = (uint)desc.Width,
|
||||
Stride = 0,
|
||||
Usage = BufferUsage.None,
|
||||
CreationFlags = BufferCreationFlags.None,
|
||||
MemoryType = MemoryType.Default
|
||||
});
|
||||
}
|
||||
@@ -76,7 +75,6 @@ public struct ResourceDesc
|
||||
Dimension = desc.Dimension.ToTextureDimension(),
|
||||
MipLevels = desc.MipLevels,
|
||||
Usage = TextureUsage.None,
|
||||
CreationFlags = TextureCreationFlags.None
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -174,7 +172,7 @@ public struct RenderTargetDesc
|
||||
/// </summary>
|
||||
public static RenderTargetDesc Color(uint width, uint height, uint slice = 1,
|
||||
TextureFormat format = TextureFormat.R8G8B8A8_UNorm, TextureDimension dimension = TextureDimension.Texture2D,
|
||||
RenderTargetCreationFlags creationFlags = RenderTargetCreationFlags.AllowUAV | RenderTargetCreationFlags.DynamicallyScalable | RenderTargetCreationFlags.GenerateMips,
|
||||
RenderTargetCreationFlags creationFlags = RenderTargetCreationFlags.AllowUAV | RenderTargetCreationFlags.DynamicallyResolution | RenderTargetCreationFlags.GenerateMips,
|
||||
uint mipLevels = 0u, uint sampleCount = 1)
|
||||
{
|
||||
return new RenderTargetDesc
|
||||
@@ -196,7 +194,7 @@ public struct RenderTargetDesc
|
||||
/// </summary>
|
||||
public static RenderTargetDesc Depth(uint width, uint height, uint slice = 1,
|
||||
TextureFormat format = TextureFormat.D24_UNorm_S8_UInt, TextureDimension dimension = TextureDimension.Texture2D,
|
||||
RenderTargetCreationFlags creationFlags = RenderTargetCreationFlags.AllowUAV | RenderTargetCreationFlags.DynamicallyScalable,
|
||||
RenderTargetCreationFlags creationFlags = RenderTargetCreationFlags.AllowUAV | RenderTargetCreationFlags.DynamicallyResolution,
|
||||
uint mipLevels = 0u, uint sampleCount = 1)
|
||||
{
|
||||
return new RenderTargetDesc
|
||||
@@ -231,7 +229,6 @@ public struct RenderTargetDesc
|
||||
Dimension = desc.Dimension,
|
||||
MipLevels = desc.MipLevels,
|
||||
Usage = usage,
|
||||
CreationFlags = TextureCreationFlags.Bindless
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -303,15 +300,6 @@ public struct TextureDesc
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Texture creation flags
|
||||
/// </summary>
|
||||
public TextureCreationFlags CreationFlags
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -322,7 +310,7 @@ public struct BufferDesc
|
||||
/// <summary>
|
||||
/// Size of the buffer in bytes
|
||||
/// </summary>
|
||||
public ulong Size
|
||||
public uint Size
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@@ -343,12 +331,6 @@ public struct BufferDesc
|
||||
set;
|
||||
}
|
||||
|
||||
public BufferCreationFlags CreationFlags
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Memory type for the buffer
|
||||
/// </summary>
|
||||
@@ -388,13 +370,13 @@ public enum TextureDimension
|
||||
|
||||
public static class TextureDimensionExtension
|
||||
{
|
||||
public static TextureDimension ToTextureDimension(this ResourceDimension dimension)
|
||||
public static TextureDimension ToTextureDimension(this D3D12_RESOURCE_DIMENSION dimension)
|
||||
{
|
||||
return dimension switch
|
||||
{
|
||||
ResourceDimension.Texture1D => TextureDimension.Texture2D,
|
||||
ResourceDimension.Texture2D => TextureDimension.Texture2D,
|
||||
ResourceDimension.Texture3D => TextureDimension.Texture3D,
|
||||
D3D12_RESOURCE_DIMENSION.D3D12_RESOURCE_DIMENSION_TEXTURE1D => TextureDimension.Texture2D,
|
||||
D3D12_RESOURCE_DIMENSION.D3D12_RESOURCE_DIMENSION_TEXTURE2D => TextureDimension.Texture2D,
|
||||
D3D12_RESOURCE_DIMENSION.D3D12_RESOURCE_DIMENSION_TEXTURE3D => TextureDimension.Texture3D,
|
||||
_ => TextureDimension.Unknown,
|
||||
};
|
||||
}
|
||||
@@ -409,7 +391,7 @@ public enum RenderTargetCreationFlags
|
||||
None = 0,
|
||||
AllowUAV = 1 << 0,
|
||||
AllowMSAA = 1 << 1,
|
||||
DynamicallyScalable = 1 << 2,
|
||||
DynamicallyResolution = 1 << 2,
|
||||
GenerateMips = 1 << 3
|
||||
}
|
||||
|
||||
@@ -421,11 +403,4 @@ public enum MemoryType
|
||||
Default, // GPU memory
|
||||
Upload, // CPU-to-GPU memory
|
||||
Readback // GPU-to-CPU memory
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum TextureCreationFlags
|
||||
{
|
||||
None = 0,
|
||||
Bindless = 1 << 0
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Win32.Graphics.Dxgi.Common;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace Ghost.Graphics.RHI;
|
||||
|
||||
@@ -46,13 +46,6 @@ public enum BufferUsage
|
||||
ShaderResource = Vertex | Index | Constant
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum BufferCreationFlags
|
||||
{
|
||||
None = 0,
|
||||
Bindless = 1 << 0
|
||||
}
|
||||
|
||||
public enum IndexType
|
||||
{
|
||||
UInt16,
|
||||
@@ -61,30 +54,30 @@ public enum IndexType
|
||||
|
||||
internal static class TextureFormatExtensions
|
||||
{
|
||||
public static Format ToD3D12Format(this TextureFormat format)
|
||||
public static DXGI_FORMAT ToD3D12Format(this TextureFormat format)
|
||||
{
|
||||
return format switch
|
||||
{
|
||||
TextureFormat.R8G8B8A8_UNorm => Format.R8G8B8A8Unorm,
|
||||
TextureFormat.B8G8R8A8_UNorm => Format.B8G8R8A8Unorm,
|
||||
TextureFormat.R16G16B16A16_Float => Format.R16G16B16A16Float,
|
||||
TextureFormat.R32G32B32A32_Float => Format.R32G32B32A32Float,
|
||||
TextureFormat.D24_UNorm_S8_UInt => Format.D24UnormS8Uint,
|
||||
TextureFormat.D32_Float => Format.D32Float,
|
||||
TextureFormat.R8G8B8A8_UNorm => DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
TextureFormat.B8G8R8A8_UNorm => DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
TextureFormat.R16G16B16A16_Float => DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT,
|
||||
TextureFormat.R32G32B32A32_Float => DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT,
|
||||
TextureFormat.D24_UNorm_S8_UInt => DXGI_FORMAT.DXGI_FORMAT_D24_UNORM_S8_UINT,
|
||||
TextureFormat.D32_Float => DXGI_FORMAT.DXGI_FORMAT_D32_FLOAT,
|
||||
_ => throw new NotSupportedException($"Texture format {format} is not supported."),
|
||||
};
|
||||
}
|
||||
|
||||
public static TextureFormat ToTextureFormat(this Format format)
|
||||
public static TextureFormat ToTextureFormat(this DXGI_FORMAT format)
|
||||
{
|
||||
return format switch
|
||||
{
|
||||
Format.R8G8B8A8Unorm => TextureFormat.R8G8B8A8_UNorm,
|
||||
Format.B8G8R8A8Unorm => TextureFormat.B8G8R8A8_UNorm,
|
||||
Format.R16G16B16A16Float => TextureFormat.R16G16B16A16_Float,
|
||||
Format.R32G32B32A32Float => TextureFormat.R32G32B32A32_Float,
|
||||
Format.D24UnormS8Uint => TextureFormat.D24_UNorm_S8_UInt,
|
||||
Format.D32Float => TextureFormat.D32_Float,
|
||||
DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM => TextureFormat.R8G8B8A8_UNorm,
|
||||
DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM => TextureFormat.B8G8R8A8_UNorm,
|
||||
DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT => TextureFormat.R16G16B16A16_Float,
|
||||
DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT => TextureFormat.R32G32B32A32_Float,
|
||||
DXGI_FORMAT.DXGI_FORMAT_D24_UNORM_S8_UINT => TextureFormat.D24_UNorm_S8_UInt,
|
||||
DXGI_FORMAT.DXGI_FORMAT_D32_FLOAT => TextureFormat.D32_Float,
|
||||
_ => TextureFormat.Unknown,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user