Dummy out gl queries with 0 draws, remove glFlush call (#1773)

This commit is contained in:
riperiperi 2020-12-03 18:42:59 +00:00 committed by GitHub
parent 2c39a4f15d
commit c00d39b675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 11 deletions

View File

@ -10,6 +10,8 @@ namespace Ryujinx.Graphics.OpenGL
{ {
class Pipeline : IPipeline, IDisposable class Pipeline : IPipeline, IDisposable
{ {
internal ulong DrawCount { get; private set; }
private Program _program; private Program _program;
private bool _rasterizerDiscard; private bool _rasterizerDiscard;
@ -1196,6 +1198,8 @@ namespace Ryujinx.Graphics.OpenGL
private void PreDraw() private void PreDraw()
{ {
DrawCount++;
_vertexArray.Validate(); _vertexArray.Validate();
if (_unit0Texture != null) if (_unit0Texture != null)

View File

@ -46,7 +46,6 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public unsafe void End() public unsafe void End()
{ {
GL.Flush();
GL.EndQuery(_type); GL.EndQuery(_type);
GL.BindBuffer(BufferTarget.QueryBuffer, _buffer); GL.BindBuffer(BufferTarget.QueryBuffer, _buffer);

View File

@ -38,7 +38,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
_queryPool.Enqueue(new BufferedQuery(glType)); _queryPool.Enqueue(new BufferedQuery(glType));
} }
_current = new CounterQueueEvent(this, glType); _current = new CounterQueueEvent(this, glType, 0);
_consumerThread = new Thread(EventConsumer); _consumerThread = new Thread(EventConsumer);
_consumerThread.Start(); _consumerThread.Start();
@ -95,19 +95,32 @@ namespace Ryujinx.Graphics.OpenGL.Queries
} }
} }
public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler) public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler, ulong lastDrawIndex)
{ {
CounterQueueEvent result; CounterQueueEvent result;
ulong draws = lastDrawIndex - _current.DrawIndex;
lock (_lock) lock (_lock)
{ {
_current.Complete(); // A query's result only matters if more than one draw was performed during it.
_events.Enqueue(_current); // Otherwise, dummy it out and return 0 immediately.
if (draws > 0)
{
_current.Complete();
_events.Enqueue(_current);
_current.OnResult += resultHandler;
}
else
{
_current.Dispose();
resultHandler(_current, 0);
}
result = _current; result = _current;
result.OnResult += resultHandler;
_current = new CounterQueueEvent(this, GetTarget(Type)); _current = new CounterQueueEvent(this, GetTarget(Type), lastDrawIndex);
} }
_queuedEvent.Set(); _queuedEvent.Set();

View File

@ -16,18 +16,22 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public bool Disposed { get; private set; } public bool Disposed { get; private set; }
public bool Invalid { get; set; } public bool Invalid { get; set; }
public ulong DrawIndex { get; }
private CounterQueue _queue; private CounterQueue _queue;
private BufferedQuery _counter; private BufferedQuery _counter;
private object _lock = new object(); private object _lock = new object();
public CounterQueueEvent(CounterQueue queue, QueryTarget type) public CounterQueueEvent(CounterQueue queue, QueryTarget type, ulong drawIndex)
{ {
_queue = queue; _queue = queue;
_counter = queue.GetQueryObject(); _counter = queue.GetQueryObject();
Type = type; Type = type;
DrawIndex = drawIndex;
_counter.Begin(); _counter.Begin();
} }

View File

@ -23,9 +23,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries
} }
} }
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler) public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, ulong lastDrawIndex)
{ {
return _counterQueues[(int)type].QueueReport(resultHandler); return _counterQueues[(int)type].QueueReport(resultHandler, lastDrawIndex);
} }
public void QueueReset(CounterType type) public void QueueReset(CounterType type)

View File

@ -113,7 +113,7 @@ namespace Ryujinx.Graphics.OpenGL
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler) public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler)
{ {
return _counters.QueueReport(type, resultHandler); return _counters.QueueReport(type, resultHandler, _pipeline.DrawCount);
} }
public void Initialize(GraphicsDebugLevel glLogLevel) public void Initialize(GraphicsDebugLevel glLogLevel)