forked from Misaki/GhostEngine
Added DescriptorAllocator.cs to manage descriptor allocations for Direct3D 12. Added Texture2D.cs to handle 2D textures and GPU resource creation. Added DescriptorAllocatorExample.cs to demonstrate the new descriptor allocator interface. Changed project files to reference Misaki.HighPerformance.LowLevel instead of Misaki.HighPerformance.Unsafe. Changed _renderView type from IRenderer? to Renderer? in ScenePage.xaml.cs. Changed EngineCore.cs to remove explicit graphics API specification during initialization. Changed Logger.cs to enhance the Assert method with a DoesNotReturnIf attribute. Changed resource types in Mesh.cs from IResource to GraphicsResource. Removed multiple interfaces including ICommandBuffer, IDebugLayer, IGraphicsDevice, IPipelineResource, IRenderPass, IRenderer, IResource, and IResourceAllocator to simplify the graphics architecture. Removed D3D12DebugLayer class from DebugLayer.cs to streamline the debug layer implementation. Updated CommandList.cs and D3D12CommandBuffer.cs to implement a new command list structure for Direct3D 12. Updated Material.cs to improve handling of constant buffers and textures. Updated Shader.cs to include new structures for texture and property information. Updated GraphicsPipeline.cs to support the new graphics device and resource management system. Updated UnitTestAppWindow.xaml.cs to reflect changes in the renderer type and ensure proper resource management. Updated BindlessMeshRenderPass.cs and MeshRenderPass.cs to implement modern rendering techniques, including bindless textures and improved shader management. Updated CBufferCache.cs to align with the new resource management system and improve memory handling.
106 lines
2.7 KiB
C#
106 lines
2.7 KiB
C#
using Ghost.Engine.Models;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace Ghost.Engine.Services;
|
|
|
|
internal enum LogChangeType
|
|
{
|
|
LogAdded,
|
|
LogRemoved,
|
|
LogsCleared
|
|
}
|
|
|
|
internal readonly struct LogChangeContext(LogChangeType type, int index)
|
|
{
|
|
public readonly LogChangeType changeType = type;
|
|
public readonly int index = index;
|
|
}
|
|
|
|
public static class Logger
|
|
{
|
|
|
|
private const int _MAX_LOGS = 4096;
|
|
|
|
private static readonly List<LogMessage> _logs = new();
|
|
internal static IReadOnlyList<LogMessage> Logs => _logs;
|
|
|
|
internal static event Action<LogChangeContext>? OnLogsUpdate;
|
|
|
|
internal static bool HasStackTrace
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
private static StackTrace? CaptureStackTrace()
|
|
{
|
|
return HasStackTrace ? new StackTrace(1, true) : null;
|
|
}
|
|
|
|
private static void LogInternal(LogLevel level, object? message, StackTrace? stackTrace)
|
|
{
|
|
if (_logs.Count >= _MAX_LOGS)
|
|
{
|
|
_logs.RemoveAt(0);
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogRemoved, 0));
|
|
}
|
|
|
|
var logMessage = new LogMessage(level, message?.ToString(), stackTrace?.ToString());
|
|
_logs.Add(logMessage);
|
|
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogAdded, _logs.Count - 1));
|
|
}
|
|
|
|
private static void LogExceptionInternal(Exception ex)
|
|
{
|
|
if (_logs.Count >= _MAX_LOGS)
|
|
{
|
|
_logs.RemoveAt(0);
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogRemoved, 0));
|
|
}
|
|
|
|
var logMessage = new LogMessage(LogLevel.Error, ex.Message, ex.StackTrace);
|
|
_logs.Add(logMessage);
|
|
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogAdded, _logs.Count - 1));
|
|
}
|
|
|
|
public static void Log(LogLevel level, object? message)
|
|
{
|
|
LogInternal(level, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogInfo(object? message)
|
|
{
|
|
LogInternal(LogLevel.Info, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogWarning(object? message)
|
|
{
|
|
LogInternal(LogLevel.Warning, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogError(object? message)
|
|
{
|
|
LogInternal(LogLevel.Error, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogError(Exception ex)
|
|
{
|
|
LogExceptionInternal(ex);
|
|
}
|
|
|
|
public static void Assert([DoesNotReturnIf(false)] bool condition, object? message = null)
|
|
{
|
|
if (!condition)
|
|
{
|
|
LogInternal(LogLevel.Error, message ?? "Assertion failed", CaptureStackTrace());
|
|
}
|
|
}
|
|
|
|
internal static void Clear()
|
|
{
|
|
_logs.Clear();
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogsCleared, -1));
|
|
}
|
|
} |