Implement lazy flush-on-read for Buffers (SSBO/Copy) (#1790)
* Initial implementation of buffer flush (VERY WIP) * Host shaders need to be rebuilt for the SSBO write flag. * New approach with reserved regions and gl sync * Fix a ton of buffer issues. * Remove unused buffer unmapped behaviour * Revert "Remove unused buffer unmapped behaviour" This reverts commit f1700e52fb8760180ac5e0987a07d409d1e70ece. * Delete modified ranges on unmap Fixes potential crashes in Super Smash Bros, where a previously modified range could lie on either side of an unmap. * Cache some more delegates. * Dispose Sync on Close * Also create host sync for GPFifo syncpoint increment. * Copy buffer optimization, add docs * Fix race condition with OpenGL Sync * Enable read tracking on CommandBuffer, insert syncpoint on WaitForIdle * Performance: Only flush individual pages of SSBO at a time This avoids flushing large amounts of data when only a small amount is actually used. * Signal Modified rather than flushing after clear * Fix some docs and code style. * Introduce a new test for tracking memory protection. Sucessfully demonstrates that the bug causing write protection to be cleared by a read action has been fixed. (these tests fail on master) * Address Comments * Add host sync for SetReference This ensures that any indirect draws will correctly flush any related buffer data written before them. Fixes some flashing and misplaced world geometry in MH rise. * Make PageAlign static * Re-enable read tracking, for reads.
This commit is contained in:
parent
c4f56c5704
commit
a1f77a5b6a
28 changed files with 1073 additions and 57 deletions
|
@ -421,5 +421,68 @@ namespace Ryujinx.Memory.Tests
|
|||
|
||||
Assert.AreEqual((0, 0), _tracking.GetRegionCounts());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAndWriteProtection()
|
||||
{
|
||||
MemoryPermission protection = MemoryPermission.ReadAndWrite;
|
||||
|
||||
_memoryManager.OnProtect += (va, size, newProtection) =>
|
||||
{
|
||||
Assert.AreEqual((0, PageSize), (va, size)); // Should protect the exact region all the operations use.
|
||||
protection = newProtection;
|
||||
};
|
||||
|
||||
RegionHandle handle = _tracking.BeginTracking(0, PageSize);
|
||||
|
||||
// After creating the handle, there is no protection yet.
|
||||
Assert.AreEqual(MemoryPermission.ReadAndWrite, protection);
|
||||
|
||||
bool dirtyInitial = handle.Dirty;
|
||||
Assert.True(dirtyInitial); // Handle starts dirty.
|
||||
|
||||
handle.Reprotect();
|
||||
|
||||
// After a reprotect, there is write protection, which will set a dirty flag when any write happens.
|
||||
Assert.AreEqual(MemoryPermission.Read, protection);
|
||||
|
||||
(ulong address, ulong size)? readTrackingTriggered = null;
|
||||
handle.RegisterAction((address, size) =>
|
||||
{
|
||||
readTrackingTriggered = (address, size);
|
||||
});
|
||||
|
||||
// Registering an action adds read/write protection.
|
||||
Assert.AreEqual(MemoryPermission.None, protection);
|
||||
|
||||
bool dirtyAfterReprotect = handle.Dirty;
|
||||
Assert.False(dirtyAfterReprotect); // Handle is no longer dirty.
|
||||
|
||||
// First we should read, which will trigger the action. This _should not_ remove write protection on the memory.
|
||||
|
||||
_tracking.VirtualMemoryEvent(0, 4, false);
|
||||
|
||||
bool dirtyAfterRead = handle.Dirty;
|
||||
Assert.False(dirtyAfterRead); // Not dirtied, as this was a read.
|
||||
|
||||
Assert.AreEqual(readTrackingTriggered, (0UL, 4UL)); // Read action was triggered.
|
||||
|
||||
Assert.AreEqual(MemoryPermission.Read, protection); // Write protection is still present.
|
||||
|
||||
readTrackingTriggered = null;
|
||||
|
||||
// Now, perform a write.
|
||||
|
||||
_tracking.VirtualMemoryEvent(0, 4, true);
|
||||
|
||||
bool dirtyAfterWriteAfterRead = handle.Dirty;
|
||||
Assert.True(dirtyAfterWriteAfterRead); // Should be dirty.
|
||||
|
||||
Assert.AreEqual(MemoryPermission.ReadAndWrite, protection); // All protection is now be removed from the memory.
|
||||
|
||||
Assert.IsNull(readTrackingTriggered); // Read tracking was removed when the action fired, as it can only fire once.
|
||||
|
||||
handle.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue