From cd48576f5846aa89a36bfc833e9de5dde9627aed Mon Sep 17 00:00:00 2001 From: riperiperi Date: Mon, 4 May 2020 03:24:59 +0100 Subject: Implement Counter Queue and Partial Host Conditional Rendering (#1167) * Implementation of query queue and host conditional rendering * Resolve some comments. * Use overloads instead of passing object. * Wake the consumer threads when incrementing syncpoints. Also, do a busy loop when awaiting the counter for a blocking flush, rather than potentially sleeping the thread. * Ensure there's a command between begin and end query. --- Ryujinx.Graphics.Gpu/Memory/CounterCache.cs | 59 +++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Memory/CounterCache.cs') diff --git a/Ryujinx.Graphics.Gpu/Memory/CounterCache.cs b/Ryujinx.Graphics.Gpu/Memory/CounterCache.cs index 3110cdcc..90b9187b 100644 --- a/Ryujinx.Graphics.Gpu/Memory/CounterCache.cs +++ b/Ryujinx.Graphics.Gpu/Memory/CounterCache.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using Ryujinx.Graphics.GAL; +using System.Collections.Generic; namespace Ryujinx.Graphics.Gpu.Memory { @@ -10,10 +11,12 @@ namespace Ryujinx.Graphics.Gpu.Memory private struct CounterEntry { public ulong Address { get; } + public ICounterEvent Event { get; } - public CounterEntry(ulong address) + public CounterEntry(ulong address, ICounterEvent evt) { Address = address; + Event = evt; } } @@ -31,11 +34,11 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Adds a new counter to the counter cache, or updates a existing one. /// /// GPU virtual address where the counter will be written in memory - public void AddOrUpdate(ulong gpuVa) + public void AddOrUpdate(ulong gpuVa, ICounterEvent evt) { int index = BinarySearch(gpuVa); - CounterEntry entry = new CounterEntry(gpuVa); + CounterEntry entry = new CounterEntry(gpuVa, evt); if (index < 0) { @@ -76,6 +79,16 @@ namespace Ryujinx.Graphics.Gpu.Memory count++; } + // Notify the removed counter events that their result should no longer be written out. + for (int i = 0; i < count; i++) + { + ICounterEvent evt = _items[index + i].Event; + if (evt != null) + { + evt.Invalid = true; + } + } + _items.RemoveRange(index, count); } @@ -101,6 +114,44 @@ namespace Ryujinx.Graphics.Gpu.Memory return BinarySearch(gpuVa) >= 0; } + /// + /// Flush any counter value written to the specified GPU virtual memory address. + /// + /// GPU virtual address + /// True if any counter value was written on the specified address, false otherwise + public bool FindAndFlush(ulong gpuVa) + { + int index = BinarySearch(gpuVa); + if (index > 0) + { + _items[index].Event?.Flush(); + + return true; + } + else + { + return false; + } + } + + /// + /// Find any counter event that would write to the specified GPU virtual memory address. + /// + /// GPU virtual address + /// The counter event, or null if not present + public ICounterEvent FindEvent(ulong gpuVa) + { + int index = BinarySearch(gpuVa); + if (index > 0) + { + return _items[index].Event; + } + else + { + return null; + } + } + /// /// Performs binary search of an address on the list. /// -- cgit v1.2.3