Add config entry to enable OpenGL debug context and callbacks

This commit is contained in:
ReinUsesLisp 2018-08-17 23:36:26 -03:00
parent 056c2840b1
commit 90159e6cf1
8 changed files with 90 additions and 2 deletions

View file

@ -4,6 +4,8 @@ namespace Ryujinx.Graphics.Gal
{
public interface IGalRenderer
{
void Initialize();
void QueueAction(Action ActionMthd);
void RunActions();

View file

@ -6,8 +6,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
private static bool Initialized = false;
private static bool Debug;
private static bool EnhancedLayouts;
public static bool HasDebug()
{
EnsureInitialized();
return Debug;
}
public static bool HasEnhancedLayouts()
{
EnsureInitialized();
@ -22,6 +30,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
return;
}
Debug = HasExtension("GL_KHR_debug");
EnhancedLayouts = HasExtension("GL_ARB_enhanced_layouts");
}

View file

@ -1,5 +1,8 @@
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System;
using System.Collections.Concurrent;
using System.Text;
namespace Ryujinx.Graphics.Gal.OpenGL
{
@ -19,6 +22,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
private ConcurrentQueue<Action> ActionsQueue;
private DebugProc DebugProcDelegate;
public OGLRenderer()
{
Buffer = new OGLConstBuffer();
@ -36,6 +41,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
ActionsQueue = new ConcurrentQueue<Action>();
}
public void Initialize()
{
if (GraphicsConfig.DebugMode && OGLExtension.HasDebug())
{
DebugProcDelegate = DebugCallback;
GL.DebugMessageCallback(DebugProcDelegate, IntPtr.Zero);
}
}
public void QueueAction(Action ActionMthd)
{
ActionsQueue.Enqueue(ActionMthd);
@ -50,5 +65,35 @@ namespace Ryujinx.Graphics.Gal.OpenGL
RenderAction();
}
}
private static unsafe void DebugCallback(
DebugSource Source,
DebugType Type,
int Id,
DebugSeverity Severity,
int Length,
IntPtr Message,
IntPtr UserParam)
{
bool IsError = Type == DebugType.DebugTypeError || Type == DebugType.DebugTypeDeprecatedBehavior;
if (!IsError && !GraphicsConfig.DebugEnableInfo)
{
return;
}
string MessageLog = Encoding.UTF8.GetString((byte*)Message, Length);
Console.ForegroundColor = IsError ? ConsoleColor.Red : ConsoleColor.Cyan;
Console.WriteLine(MessageLog);
Console.ResetColor();
if (IsError && GraphicsConfig.DebugFatalErrors)
{
throw new OpenGLException(MessageLog);
}
}
}
}

View file

@ -0,0 +1,11 @@
using System;
namespace Ryujinx.Graphics.Gal.OpenGL
{
class OpenGLException : Exception
{
public OpenGLException() : base() { }
public OpenGLException(string Message) : base(Message) { }
}
}

View file

@ -1,4 +1,10 @@
public static class GraphicsConfig
{
public static bool DebugMode;
public static bool DebugFatalErrors;
public static bool DebugEnableInfo;
public static string ShadersDumpPath;
}

View file

@ -23,7 +23,10 @@ namespace Ryujinx
IniParser Parser = new IniParser(IniPath);
GraphicsConfig.ShadersDumpPath = Parser.Value("Graphics_Shaders_Dump_Path");
GraphicsConfig.DebugMode = Convert.ToBoolean(Parser.Value("Graphics_Enable_Debug"));
GraphicsConfig.DebugFatalErrors = Convert.ToBoolean(Parser.Value("Graphics_Debug_Fatal_Errors"));
GraphicsConfig.DebugEnableInfo = Convert.ToBoolean(Parser.Value("Graphics_Debug_Enable_Info"));
GraphicsConfig.ShadersDumpPath = Parser.Value("Graphics_Shaders_Dump_Path");
Device.Log.SetEnable(LogLevel.Debug, Convert.ToBoolean(Parser.Value("Logging_Enable_Debug")));
Device.Log.SetEnable(LogLevel.Stub, Convert.ToBoolean(Parser.Value("Logging_Enable_Stub")));

View file

@ -1,6 +1,15 @@
#Enable cpu memory checks (slow)
Enable_Memory_Checks = false
#Enable graphics API debug functionality
Graphics_Enable_Debug = false
#Graphics errors are fatal
Graphics_Debug_Fatal_Errors = true
#Show graphics info messages
Graphics_Debug_Enable_Info = false
#Dump shaders in local directory (e.g. `C:\ShaderDumps`)
Graphics_Shaders_Dump_Path =

View file

@ -38,7 +38,8 @@ namespace Ryujinx
: base(1280, 720,
new GraphicsMode(), "Ryujinx", 0,
DisplayDevice.Default, 3, 3,
GraphicsContextFlags.ForwardCompatible)
GraphicsContextFlags.ForwardCompatible |
(GraphicsConfig.DebugMode ? GraphicsContextFlags.Debug : 0))
{
this.Device = Device;
this.Renderer = Renderer;
@ -96,6 +97,8 @@ namespace Ryujinx
Visible = true;
Renderer.Initialize();
Renderer.FrameBuffer.SetWindowSize(Width, Height);
Context.MakeCurrent(null);