0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/Ryujinx.Graphics.Gpu/Memory/GpuRegionHandle.cs
riperiperi d92fff541b
Replace CacheResourceWrite with more general "precise" write (#2684)
* Replace CacheResourceWrite with more general "precise" write

The goal of CacheResourceWrite was to notify GPU resources when they were modified directly, by looking up the modified address/size in a structure and calling a method on each resource. The downside of this is that each resource cache has to be queried individually, they all have to implement their own way to do this, and it can only signal to resources using the same PhysicalMemory instance.

This PR adds the ability to signal a write as "precise" on the tracking, which signals a special handler (if present) which can be used to avoid unnecessary flush actions, or maybe even more. For buffers, precise writes specifically do not flush, and instead punch a hole in the modified range list to indicate that the data on GPU has been replaced.

The downside is that precise actions must ignore the page protection bits and always signal - as they need to notify the target resource to ignore the sequence number optimization.

I had to reintroduce the sequence number increment after I2M, as removing it was causing issues in rabbids kingdom battle. However - all resources modified by I2M are notified directly to lower their sequence number, so the problem is likely that another unrelated resource is not being properly updated. Thankfully, doing this does not affect performance in the games I tested.

This should fix regressions from #2624. Test any games that were broken by that. (RF4, rabbids kingdom battle)

I've also added a sequence number increment to ThreedClass.IncrementSyncpoint, as it seems to fix buffer corruption in OpenGL homebrew. (this was a regression from removing sequence number increment from constant buffer update - another unrelated resource thing)

* Add tests.

* Add XML docs for GpuRegionHandle

* Skip UpdateProtection if only precise actions were called

This allows precise actions to skip reprotection costs.
2021-09-29 02:27:03 +02:00

102 lines
3.1 KiB
C#

using Ryujinx.Cpu.Tracking;
using Ryujinx.Memory.Tracking;
using System;
namespace Ryujinx.Graphics.Gpu.Memory
{
/// <summary>
/// A tracking handle for a region of GPU VA, represented by one or more tracking handles in CPU VA.
/// </summary>
class GpuRegionHandle : IRegionHandle
{
private readonly CpuRegionHandle[] _cpuRegionHandles;
public bool Dirty
{
get
{
foreach (var regionHandle in _cpuRegionHandles)
{
if (regionHandle.Dirty)
{
return true;
}
}
return false;
}
}
public ulong Address => throw new NotSupportedException();
public ulong Size => throw new NotSupportedException();
public ulong EndAddress => throw new NotSupportedException();
/// <summary>
/// Create a new GpuRegionHandle, made up of mulitple CpuRegionHandles.
/// </summary>
/// <param name="cpuRegionHandles">The CpuRegionHandles that make up this handle</param>
public GpuRegionHandle(CpuRegionHandle[] cpuRegionHandles)
{
_cpuRegionHandles = cpuRegionHandles;
}
/// <summary>
/// Dispose the child handles.
/// </summary>
public void Dispose()
{
foreach (var regionHandle in _cpuRegionHandles)
{
regionHandle.Dispose();
}
}
/// <summary>
/// Register an action to perform when the tracked region is read or written.
/// The action is automatically removed after it runs.
/// </summary>
/// <param name="action">Action to call on read or write</param>
public void RegisterAction(RegionSignal action)
{
foreach (var regionHandle in _cpuRegionHandles)
{
regionHandle.RegisterAction(action);
}
}
/// <summary>
/// Register an action to perform when a precise access occurs (one with exact address and size).
/// If the action returns true, read/write tracking are skipped.
/// </summary>
/// <param name="action">Action to call on read or write</param>
public void RegisterPreciseAction(PreciseRegionSignal action)
{
foreach (var regionHandle in _cpuRegionHandles)
{
regionHandle.RegisterPreciseAction(action);
}
}
/// <summary>
/// Consume the dirty flag for the handles, and reprotect so it can be set on the next write.
/// </summary>
public void Reprotect(bool asDirty = false)
{
foreach (var regionHandle in _cpuRegionHandles)
{
regionHandle.Reprotect(asDirty);
}
}
/// <summary>
/// Force the handles to be dirty, without reprotecting.
/// </summary>
public void ForceDirty()
{
foreach (var regionHandle in _cpuRegionHandles)
{
regionHandle.ForceDirty();
}
}
}
}