1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-14 05:16:39 +00:00
Ryujinx/Ryujinx.Graphics.Vulkan/Queries/Counters.cs
riperiperi e7cf4e6eaf
Vulkan: Reset queries on same command buffer (#4329)
* Reset queries on same command buffer

Vulkan seems to complain when the queries are reset on another command buffer. No idea why, the spec really could be written better in this regard. This fixes complaints, and hopefully any implementations that care extensively about them.

This change _guesses_ how many queries need to be reset and resets as many as possible at the same time to avoid splitting render passes. If it resets too many queries, we didn't waste too much time - if it runs out of resets it will batch reset 10 more.

The number of queries reset is the maximum number of queries in the last 3 frames. This has been worked into the AutoFlushCounter so that it only resets up to 32 if it is yet to force a command buffer submission in this attachment.

This is only done for samples passed queries right now, as they have by far the most resets.

* Address Feedback
2023-01-24 13:32:56 -03:00

71 lines
1.9 KiB
C#

using Ryujinx.Graphics.GAL;
using Silk.NET.Vulkan;
using System;
namespace Ryujinx.Graphics.Vulkan.Queries
{
class Counters : IDisposable
{
private readonly CounterQueue[] _counterQueues;
private readonly PipelineFull _pipeline;
public Counters(VulkanRenderer gd, Device device, PipelineFull pipeline)
{
_pipeline = pipeline;
int count = Enum.GetNames(typeof(CounterType)).Length;
_counterQueues = new CounterQueue[count];
for (int index = 0; index < count; index++)
{
CounterType type = (CounterType)index;
_counterQueues[index] = new CounterQueue(gd, device, pipeline, type);
}
}
public void ResetCounterPool()
{
foreach (var queue in _counterQueues)
{
queue.ResetCounterPool();
}
}
public void ResetFutureCounters(CommandBuffer cmd, int count)
{
_counterQueues[(int)CounterType.SamplesPassed].ResetFutureCounters(cmd, count);
}
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved)
{
return _counterQueues[(int)type].QueueReport(resultHandler, _pipeline.DrawCount, hostReserved);
}
public void QueueReset(CounterType type)
{
_counterQueues[(int)type].QueueReset(_pipeline.DrawCount);
}
public void Update()
{
foreach (var queue in _counterQueues)
{
queue.Flush(false);
}
}
public void Flush(CounterType type)
{
_counterQueues[(int)type].Flush(true);
}
public void Dispose()
{
foreach (var queue in _counterQueues)
{
queue.Dispose();
}
}
}
}