Refactoring Rendering backend

This commit is contained in:
2025-10-05 16:26:37 +09:00
parent a39f377533
commit 01a850ff94
99 changed files with 5056 additions and 5136 deletions

View File

@@ -1,6 +1,4 @@
using System;
namespace Ghost.UnitTest.Models;
namespace Ghost.UnitTest.Models;
public enum LogLevel
{
@@ -12,10 +10,22 @@ public enum LogLevel
internal struct LogItem
{
public LogLevel Level { get; init; }
public string Message { get; init; }
public DateTime Timestamp { get; init; }
public string? StackTrace { get; init; }
public LogLevel Level
{
get; init;
}
public string Message
{
get; init;
}
public DateTime Timestamp
{
get; init;
}
public string? StackTrace
{
get; init;
}
public LogItem(LogLevel level, string message, string? stackTrace = null)
{

View File

@@ -1,9 +1,5 @@
using Ghost.UnitTest.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading;
namespace Ghost.UnitTest.Services;
@@ -11,29 +7,31 @@ internal class LoggingService
{
private const int MAX_LOGS = 4096;
private static readonly Lazy<LoggingService> _instance = new(() => new LoggingService());
private readonly List<LogItem> _logs = [];
private readonly object _lockObject = new();
public static LoggingService Instance => _instance.Value;
public IReadOnlyList<LogItem> Logs
{
get
public IReadOnlyList<LogItem> Logs
{
get
{
lock (_lockObject)
{
return _logs.AsReadOnly();
}
}
}
}
public bool CaptureStackTrace { get; set; } = false;
public event Action<LogItem>? LogAdded;
public event Action? LogsCleared;
private LoggingService() { }
private LoggingService()
{
}
private void AddLog(LogItem logItem)
{
@@ -43,18 +41,19 @@ internal class LoggingService
{
_logs.RemoveAt(0);
}
_logs.Add(logItem);
}
// Invoke event outside of lock to prevent deadlock
LogAdded?.Invoke(logItem);
}
private string? CaptureCurrentStackTrace()
{
if (!CaptureStackTrace) return null;
if (!CaptureStackTrace)
return null;
var stackTrace = new StackTrace(skipFrames: 2, fNeedFileInfo: true);
return stackTrace.ToString();
}
@@ -98,7 +97,7 @@ internal class LoggingService
{
_logs.Clear();
}
LogsCleared?.Invoke();
}

View File

@@ -1,11 +1,8 @@
using Ghost.Graphics;
using Ghost.Graphics.Contracts;
using Ghost.Graphics.D3D12;
using Ghost.Graphics.RHI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Misaki.HighPerformance.LowLevel.Buffer;
using WinRT;
namespace Ghost.UnitTest.Windows;
@@ -31,7 +28,7 @@ public sealed partial class GraphicsTestWindow : Window
AllocationManager.EnableDebugLayer();
#endif
_renderSystem = new (GraphicsAPI.Direct3D12);
_renderSystem = new(GraphicsAPI.Direct3D12);
_renderer = _renderSystem.CreateRenderer();
_swapChain = _renderSystem.GraphicsEngine.CreateSwapChain(new SwapChainDesc((uint)AppWindow.Size.Width, (uint)AppWindow.Size.Height, SwapChainTarget.FromCompositionSurface(Panel)));