diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index 00ac3a73..8b0a86aa 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -10,6 +10,8 @@ namespace Ryujinx.Graphics.OpenGL { class Pipeline : IPipeline, IDisposable { + internal ulong DrawCount { get; private set; } + private Program _program; private bool _rasterizerDiscard; @@ -1196,6 +1198,8 @@ namespace Ryujinx.Graphics.OpenGL private void PreDraw() { + DrawCount++; + _vertexArray.Validate(); if (_unit0Texture != null) diff --git a/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index 76c94126..b4c5259c 100644 --- a/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -46,7 +46,6 @@ namespace Ryujinx.Graphics.OpenGL.Queries public unsafe void End() { - GL.Flush(); GL.EndQuery(_type); GL.BindBuffer(BufferTarget.QueryBuffer, _buffer); diff --git a/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs b/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs index f34bc86d..a864a200 100644 --- a/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs +++ b/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs @@ -38,7 +38,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries _queryPool.Enqueue(new BufferedQuery(glType)); } - _current = new CounterQueueEvent(this, glType); + _current = new CounterQueueEvent(this, glType, 0); _consumerThread = new Thread(EventConsumer); _consumerThread.Start(); @@ -95,19 +95,32 @@ namespace Ryujinx.Graphics.OpenGL.Queries } } - public CounterQueueEvent QueueReport(EventHandler resultHandler) + public CounterQueueEvent QueueReport(EventHandler resultHandler, ulong lastDrawIndex) { CounterQueueEvent result; + ulong draws = lastDrawIndex - _current.DrawIndex; lock (_lock) { - _current.Complete(); - _events.Enqueue(_current); + // A query's result only matters if more than one draw was performed during it. + // 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.OnResult += resultHandler; - _current = new CounterQueueEvent(this, GetTarget(Type)); + _current = new CounterQueueEvent(this, GetTarget(Type), lastDrawIndex); } _queuedEvent.Set(); diff --git a/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index 0fba24a1..e21ce55d 100644 --- a/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -16,18 +16,22 @@ namespace Ryujinx.Graphics.OpenGL.Queries public bool Disposed { get; private set; } public bool Invalid { get; set; } + public ulong DrawIndex { get; } + private CounterQueue _queue; private BufferedQuery _counter; private object _lock = new object(); - public CounterQueueEvent(CounterQueue queue, QueryTarget type) + public CounterQueueEvent(CounterQueue queue, QueryTarget type, ulong drawIndex) { _queue = queue; _counter = queue.GetQueryObject(); Type = type; + DrawIndex = drawIndex; + _counter.Begin(); } diff --git a/Ryujinx.Graphics.OpenGL/Queries/Counters.cs b/Ryujinx.Graphics.OpenGL/Queries/Counters.cs index 7560fb17..ac441d5f 100644 --- a/Ryujinx.Graphics.OpenGL/Queries/Counters.cs +++ b/Ryujinx.Graphics.OpenGL/Queries/Counters.cs @@ -23,9 +23,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries } } - public CounterQueueEvent QueueReport(CounterType type, EventHandler resultHandler) + public CounterQueueEvent QueueReport(CounterType type, EventHandler resultHandler, ulong lastDrawIndex) { - return _counterQueues[(int)type].QueueReport(resultHandler); + return _counterQueues[(int)type].QueueReport(resultHandler, lastDrawIndex); } public void QueueReset(CounterType type) diff --git a/Ryujinx.Graphics.OpenGL/Renderer.cs b/Ryujinx.Graphics.OpenGL/Renderer.cs index f66acce3..acbc24de 100644 --- a/Ryujinx.Graphics.OpenGL/Renderer.cs +++ b/Ryujinx.Graphics.OpenGL/Renderer.cs @@ -113,7 +113,7 @@ namespace Ryujinx.Graphics.OpenGL public ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler) { - return _counters.QueueReport(type, resultHandler); + return _counters.QueueReport(type, resultHandler, _pipeline.DrawCount); } public void Initialize(GraphicsDebugLevel glLogLevel)