Debugger, Pipeline

This commit is contained in:
Isaac Marovitz 2024-05-09 20:04:29 -04:00
parent 1d18ed2ba2
commit 0c88c23b30
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
2 changed files with 62 additions and 48 deletions

View file

@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.OpenGL
public static void Initialize(GL gl, GraphicsDebugLevel logLevel) public static void Initialize(GL gl, GraphicsDebugLevel logLevel)
{ {
// Disable everything // Disable everything
gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, false); gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint[])null, false);
if (logLevel == GraphicsDebugLevel.None) if (logLevel == GraphicsDebugLevel.None)
{ {
@ -30,16 +30,16 @@ namespace Ryujinx.Graphics.OpenGL
if (logLevel == GraphicsDebugLevel.Error) if (logLevel == GraphicsDebugLevel.Error)
{ {
gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true);
} }
else if (logLevel == GraphicsDebugLevel.Slowdowns) else if (logLevel == GraphicsDebugLevel.Slowdowns)
{ {
gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true);
gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (int[])null, true); gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (uint[])null, true);
} }
else else
{ {
gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, true); gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint[])null, true);
} }
_counter = 0; _counter = 0;
@ -61,7 +61,10 @@ namespace Ryujinx.Graphics.OpenGL
{ {
string msg = Marshal.PtrToStringUTF8(message).Replace('\n', ' '); string msg = Marshal.PtrToStringUTF8(message).Replace('\n', ' ');
switch (type) DebugType debugType = (DebugType)type;
DebugSource debugSource = (DebugSource)source;
switch (debugType)
{ {
case DebugType.DebugTypeError: case DebugType.DebugTypeError:
Logger.Error?.Print(LogClass.Gpu, $"{severity}: {msg}\nCallStack={Environment.StackTrace}", "GLERROR"); Logger.Error?.Print(LogClass.Gpu, $"{severity}: {msg}\nCallStack={Environment.StackTrace}", "GLERROR");
@ -76,7 +79,7 @@ namespace Ryujinx.Graphics.OpenGL
Logger.Info?.Print(LogClass.Gpu, $"}} ({id}) {severity}: {msg}", "GLINFO"); Logger.Info?.Print(LogClass.Gpu, $"}} ({id}) {severity}: {msg}", "GLINFO");
break; break;
default: default:
if (source == DebugSource.DebugSourceApplication) if (debugSource == DebugSource.DebugSourceApplication)
{ {
Logger.Info?.Print(LogClass.Gpu, $"{type} {severity}: {msg}", "GLINFO"); Logger.Info?.Print(LogClass.Gpu, $"{type} {severity}: {msg}", "GLINFO");
} }
@ -93,7 +96,7 @@ namespace Ryujinx.Graphics.OpenGL
{ {
int counter = Interlocked.Increment(ref _counter); int counter = Interlocked.Increment(ref _counter);
gl.PushDebugGroup(DebugSource.DebugSourceApplication, counter, dbgMsg.Length, dbgMsg); gl.PushDebugGroup(DebugSource.DebugSourceApplication, (uint)counter, (uint)dbgMsg.Length, dbgMsg);
} }
public static void PopGroup(GL gl) public static void PopGroup(GL gl)
@ -103,7 +106,7 @@ namespace Ryujinx.Graphics.OpenGL
public static void Print(GL gl, string dbgMsg, DebugType type = DebugType.DebugTypeMarker, DebugSeverity severity = DebugSeverity.DebugSeverityNotification, int id = 999999) public static void Print(GL gl, string dbgMsg, DebugType type = DebugType.DebugTypeMarker, DebugSeverity severity = DebugSeverity.DebugSeverityNotification, int id = 999999)
{ {
gl.DebugMessageInsert(DebugSource.DebugSourceApplication, type, id, severity, dbgMsg.Length, dbgMsg); gl.DebugMessageInsert(DebugSource.DebugSourceApplication, type, (uint)id, severity, (uint)dbgMsg.Length, dbgMsg);
} }
} }
} }

View file

@ -220,7 +220,7 @@ namespace Ryujinx.Graphics.OpenGL
PrepareForDispatch(); PrepareForDispatch();
_api.DispatchCompute(groupsX, groupsY, groupsZ); _api.DispatchCompute((uint)groupsX, (uint)groupsY, (uint)groupsZ);
} }
public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance) public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance)
@ -256,10 +256,10 @@ namespace Ryujinx.Graphics.OpenGL
int firstInstance) int firstInstance)
{ {
// TODO: Instanced rendering. // TODO: Instanced rendering.
int quadsCount = vertexCount / 4; uint quadsCount = (uint)(vertexCount / 4);
int[] firsts = new int[quadsCount]; int[] firsts = new int[quadsCount];
int[] counts = new int[quadsCount]; uint[] counts = new uint[quadsCount];
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
{ {
@ -280,19 +280,19 @@ namespace Ryujinx.Graphics.OpenGL
int firstVertex, int firstVertex,
int firstInstance) int firstInstance)
{ {
int quadsCount = (vertexCount - 2) / 2; uint quadsCount = (uint)((vertexCount - 2) / 2);
if (firstInstance != 0 || instanceCount != 1) if (firstInstance != 0 || instanceCount != 1)
{ {
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
{ {
_api.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, instanceCount, firstInstance); _api.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, (uint)instanceCount, (uint)firstInstance);
} }
} }
else else
{ {
int[] firsts = new int[quadsCount]; int[] firsts = new int[quadsCount];
int[] counts = new int[quadsCount]; uint[] counts = new uint[quadsCount];
firsts[0] = firstVertex; firsts[0] = firstVertex;
counts[0] = 4; counts[0] = 4;
@ -319,20 +319,20 @@ namespace Ryujinx.Graphics.OpenGL
{ {
if (firstInstance == 0 && instanceCount == 1) if (firstInstance == 0 && instanceCount == 1)
{ {
_api.DrawArrays(_primitiveType, firstVertex, vertexCount); _api.DrawArrays(_primitiveType, firstVertex, (uint)vertexCount);
} }
else if (firstInstance == 0) else if (firstInstance == 0)
{ {
_api.DrawArraysInstanced(_primitiveType, firstVertex, vertexCount, instanceCount); _api.DrawArraysInstanced(_primitiveType, firstVertex, (uint)vertexCount, (uint)instanceCount);
} }
else else
{ {
_api.DrawArraysInstancedBaseInstance( _api.DrawArraysInstancedBaseInstance(
_primitiveType, _primitiveType,
firstVertex, firstVertex,
vertexCount, (uint)vertexCount,
instanceCount, (uint)instanceCount,
firstInstance); (uint)firstInstance);
} }
} }
@ -398,7 +398,7 @@ namespace Ryujinx.Graphics.OpenGL
PostDraw(); PostDraw();
} }
private void DrawQuadsIndexedImpl( private unsafe void DrawQuadsIndexedImpl(
int indexCount, int indexCount,
int instanceCount, int instanceCount,
IntPtr indexBaseOffset, IntPtr indexBaseOffset,
@ -419,9 +419,9 @@ namespace Ryujinx.Graphics.OpenGL
4, 4,
_elementsType, _elementsType,
indexBaseOffset + quadIndex * 4 * indexElemSize, indexBaseOffset + quadIndex * 4 * indexElemSize,
instanceCount, (uint)instanceCount,
firstVertex, firstVertex,
firstInstance); (uint)firstInstance);
} }
} }
else if (firstInstance != 0) else if (firstInstance != 0)
@ -433,8 +433,8 @@ namespace Ryujinx.Graphics.OpenGL
4, 4,
_elementsType, _elementsType,
indexBaseOffset + quadIndex * 4 * indexElemSize, indexBaseOffset + quadIndex * 4 * indexElemSize,
instanceCount, (uint)instanceCount,
firstInstance); (uint)firstInstance);
} }
} }
else else
@ -446,38 +446,43 @@ namespace Ryujinx.Graphics.OpenGL
4, 4,
_elementsType, _elementsType,
indexBaseOffset + quadIndex * 4 * indexElemSize, indexBaseOffset + quadIndex * 4 * indexElemSize,
instanceCount); (uint)instanceCount);
} }
} }
} }
else else
{ {
IntPtr[] indices = new IntPtr[quadsCount]; void*[] indices = new void*[quadsCount];
int[] counts = new int[quadsCount]; uint[] counts = new uint[quadsCount];
int[] baseVertices = new int[quadsCount]; int[] baseVertices = new int[quadsCount];
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
{ {
indices[quadIndex] = indexBaseOffset + quadIndex * 4 * indexElemSize; indices[quadIndex] = (void*)(indexBaseOffset + quadIndex * 4 * indexElemSize);
counts[quadIndex] = 4; counts[quadIndex] = 4;
baseVertices[quadIndex] = firstVertex; baseVertices[quadIndex] = firstVertex;
} }
_api.MultiDrawElementsBaseVertex( fixed (uint* countsPtr = counts)
PrimitiveType.TriangleFan, fixed (void* indicesPtr = indices)
counts, fixed (int* baseVerticesPtr = baseVertices)
_elementsType, {
indices, _api.MultiDrawElementsBaseVertex(
quadsCount, PrimitiveType.TriangleFan,
baseVertices); countsPtr,
_elementsType,
indicesPtr,
(uint)quadsCount,
baseVerticesPtr);
}
} }
} }
private void DrawQuadStripIndexedImpl( private unsafe void DrawQuadStripIndexedImpl(
int indexCount, int indexCount,
int instanceCount, int instanceCount,
IntPtr indexBaseOffset, IntPtr indexBaseOffset,
@ -488,13 +493,13 @@ namespace Ryujinx.Graphics.OpenGL
// TODO: Instanced rendering. // TODO: Instanced rendering.
int quadsCount = (indexCount - 2) / 2; int quadsCount = (indexCount - 2) / 2;
IntPtr[] indices = new IntPtr[quadsCount]; void*[] indices = new void*[quadsCount];
int[] counts = new int[quadsCount]; uint[] counts = new uint[quadsCount];
int[] baseVertices = new int[quadsCount]; int[] baseVertices = new int[quadsCount];
indices[0] = indexBaseOffset; indices[0] = (void*)indexBaseOffset;
counts[0] = 4; counts[0] = 4;
@ -502,20 +507,25 @@ namespace Ryujinx.Graphics.OpenGL
for (int quadIndex = 1; quadIndex < quadsCount; quadIndex++) for (int quadIndex = 1; quadIndex < quadsCount; quadIndex++)
{ {
indices[quadIndex] = indexBaseOffset + quadIndex * 2 * indexElemSize; indices[quadIndex] = (void*)(indexBaseOffset + quadIndex * 2 * indexElemSize);
counts[quadIndex] = 4; counts[quadIndex] = 4;
baseVertices[quadIndex] = firstVertex; baseVertices[quadIndex] = firstVertex;
} }
_api.MultiDrawElementsBaseVertex( fixed (uint* countsPtr = counts)
PrimitiveType.TriangleFan, fixed (void* indicesPtr = indices)
counts, fixed (int* baseVerticesPtr = baseVertices)
_elementsType, {
indices, _api.MultiDrawElementsBaseVertex(
quadsCount, PrimitiveType.TriangleFan,
baseVertices); countsPtr,
_elementsType,
indicesPtr,
(uint)quadsCount,
baseVerticesPtr);
}
} }
private void DrawIndexedImpl( private void DrawIndexedImpl(
@ -725,6 +735,7 @@ namespace Ryujinx.Graphics.OpenGL
_api.ClipControl(ClipControlOrigin.UpperLeft, ClipControlDepth.NegativeOneToOne); _api.ClipControl(ClipControlOrigin.UpperLeft, ClipControlDepth.NegativeOneToOne);
_drawTexture.Draw( _drawTexture.Draw(
_api,
view, view,
samp, samp,
dstRegion.X1, dstRegion.X1,