Add config entry to enable OpenGL debug context and callbacks
This commit is contained in:
parent
056c2840b1
commit
90159e6cf1
8 changed files with 90 additions and 2 deletions
|
@ -4,6 +4,8 @@ namespace Ryujinx.Graphics.Gal
|
||||||
{
|
{
|
||||||
public interface IGalRenderer
|
public interface IGalRenderer
|
||||||
{
|
{
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
void QueueAction(Action ActionMthd);
|
void QueueAction(Action ActionMthd);
|
||||||
|
|
||||||
void RunActions();
|
void RunActions();
|
||||||
|
|
|
@ -6,8 +6,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
{
|
{
|
||||||
private static bool Initialized = false;
|
private static bool Initialized = false;
|
||||||
|
|
||||||
|
private static bool Debug;
|
||||||
private static bool EnhancedLayouts;
|
private static bool EnhancedLayouts;
|
||||||
|
|
||||||
|
public static bool HasDebug()
|
||||||
|
{
|
||||||
|
EnsureInitialized();
|
||||||
|
|
||||||
|
return Debug;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool HasEnhancedLayouts()
|
public static bool HasEnhancedLayouts()
|
||||||
{
|
{
|
||||||
EnsureInitialized();
|
EnsureInitialized();
|
||||||
|
@ -22,6 +30,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Debug = HasExtension("GL_KHR_debug");
|
||||||
EnhancedLayouts = HasExtension("GL_ARB_enhanced_layouts");
|
EnhancedLayouts = HasExtension("GL_ARB_enhanced_layouts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
using OpenTK;
|
||||||
|
using OpenTK.Graphics.OpenGL;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Gal.OpenGL
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
{
|
{
|
||||||
|
@ -19,6 +22,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
|
|
||||||
private ConcurrentQueue<Action> ActionsQueue;
|
private ConcurrentQueue<Action> ActionsQueue;
|
||||||
|
|
||||||
|
private DebugProc DebugProcDelegate;
|
||||||
|
|
||||||
public OGLRenderer()
|
public OGLRenderer()
|
||||||
{
|
{
|
||||||
Buffer = new OGLConstBuffer();
|
Buffer = new OGLConstBuffer();
|
||||||
|
@ -36,6 +41,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
ActionsQueue = new ConcurrentQueue<Action>();
|
ActionsQueue = new ConcurrentQueue<Action>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
if (GraphicsConfig.DebugMode && OGLExtension.HasDebug())
|
||||||
|
{
|
||||||
|
DebugProcDelegate = DebugCallback;
|
||||||
|
|
||||||
|
GL.DebugMessageCallback(DebugProcDelegate, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void QueueAction(Action ActionMthd)
|
public void QueueAction(Action ActionMthd)
|
||||||
{
|
{
|
||||||
ActionsQueue.Enqueue(ActionMthd);
|
ActionsQueue.Enqueue(ActionMthd);
|
||||||
|
@ -50,5 +65,35 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
RenderAction();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
11
Ryujinx.Graphics/Gal/OpenGL/OpenGLException.cs
Normal file
11
Ryujinx.Graphics/Gal/OpenGL/OpenGLException.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
|
{
|
||||||
|
class OpenGLException : Exception
|
||||||
|
{
|
||||||
|
public OpenGLException() : base() { }
|
||||||
|
|
||||||
|
public OpenGLException(string Message) : base(Message) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,10 @@
|
||||||
public static class GraphicsConfig
|
public static class GraphicsConfig
|
||||||
{
|
{
|
||||||
|
public static bool DebugMode;
|
||||||
|
|
||||||
|
public static bool DebugFatalErrors;
|
||||||
|
|
||||||
|
public static bool DebugEnableInfo;
|
||||||
|
|
||||||
public static string ShadersDumpPath;
|
public static string ShadersDumpPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,10 @@ namespace Ryujinx
|
||||||
|
|
||||||
IniParser Parser = new IniParser(IniPath);
|
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.Debug, Convert.ToBoolean(Parser.Value("Logging_Enable_Debug")));
|
||||||
Device.Log.SetEnable(LogLevel.Stub, Convert.ToBoolean(Parser.Value("Logging_Enable_Stub")));
|
Device.Log.SetEnable(LogLevel.Stub, Convert.ToBoolean(Parser.Value("Logging_Enable_Stub")));
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
#Enable cpu memory checks (slow)
|
#Enable cpu memory checks (slow)
|
||||||
Enable_Memory_Checks = false
|
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`)
|
#Dump shaders in local directory (e.g. `C:\ShaderDumps`)
|
||||||
Graphics_Shaders_Dump_Path =
|
Graphics_Shaders_Dump_Path =
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,8 @@ namespace Ryujinx
|
||||||
: base(1280, 720,
|
: base(1280, 720,
|
||||||
new GraphicsMode(), "Ryujinx", 0,
|
new GraphicsMode(), "Ryujinx", 0,
|
||||||
DisplayDevice.Default, 3, 3,
|
DisplayDevice.Default, 3, 3,
|
||||||
GraphicsContextFlags.ForwardCompatible)
|
GraphicsContextFlags.ForwardCompatible |
|
||||||
|
(GraphicsConfig.DebugMode ? GraphicsContextFlags.Debug : 0))
|
||||||
{
|
{
|
||||||
this.Device = Device;
|
this.Device = Device;
|
||||||
this.Renderer = Renderer;
|
this.Renderer = Renderer;
|
||||||
|
@ -96,6 +97,8 @@ namespace Ryujinx
|
||||||
|
|
||||||
Visible = true;
|
Visible = true;
|
||||||
|
|
||||||
|
Renderer.Initialize();
|
||||||
|
|
||||||
Renderer.FrameBuffer.SetWindowSize(Width, Height);
|
Renderer.FrameBuffer.SetWindowSize(Width, Height);
|
||||||
|
|
||||||
Context.MakeCurrent(null);
|
Context.MakeCurrent(null);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue