Force copy when auto-deleting a texture with dependencies (#2687)

When a texture is deleted by falling to the bottom of the AutoDeleteCache, its data is flushed to preserve any GPU writes that occurred. This ensures that the data appears in any textures recreated in the future, but didn't account for a texture that already existed with a copy dependency.

This change forces copy dependencies to complete if a texture falls out from from the AutoDeleteCache. (not removed via overlap, as that would be wasted effort)

Fixes broken lighting caused by pausing in SMO's Metro Kingdom. May fix some other issues.
This commit is contained in:
riperiperi 2021-09-29 01:11:05 +01:00 committed by GitHub
parent fd7567a6b5
commit b6e093b0fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 4 deletions

View file

@ -41,13 +41,13 @@ namespace Ryujinx.Graphics.Gpu.Image
{ {
Texture oldestTexture = _textures.First.Value; Texture oldestTexture = _textures.First.Value;
oldestTexture.SynchronizeMemory(); if (oldestTexture.IsModified && !oldestTexture.CheckModified(false))
if (oldestTexture.IsModified && !oldestTexture.CheckModified(true))
{ {
// The texture must be flushed if it falls out of the auto delete cache. // The texture must be flushed if it falls out of the auto delete cache.
// Flushes out of the auto delete cache do not trigger write tracking, // Flushes out of the auto delete cache do not trigger write tracking,
// as it is expected that other overlapping textures exist that have more up-to-date contents. // as it is expected that other overlapping textures exist that have more up-to-date contents.
oldestTexture.Group.SynchronizeDependents(oldestTexture);
oldestTexture.Flush(false); oldestTexture.Flush(false);
} }

View file

@ -234,6 +234,23 @@ namespace Ryujinx.Graphics.Gpu.Image
} }
} }
/// <summary>
/// Synchronize dependent textures, if any of them have deferred a copy from the given texture.
/// </summary>
/// <param name="texture">The texture to synchronize dependents of</param>
public void SynchronizeDependents(Texture texture)
{
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
{
for (int i = 0; i < regionCount; i++)
{
TextureGroupHandle group = _handles[baseHandle + i];
group.SynchronizeDependents();
}
});
}
/// <summary> /// <summary>
/// Signal that a texture in the group has been modified by the GPU. /// Signal that a texture in the group has been modified by the GPU.
/// </summary> /// </summary>

View file

@ -140,6 +140,22 @@ namespace Ryujinx.Graphics.Gpu.Image
_bindCount = Math.Max(0, _bindCount + (bound ? 1 : -1)); _bindCount = Math.Max(0, _bindCount + (bound ? 1 : -1));
} }
/// <summary>
/// Synchronize dependent textures, if any of them have deferred a copy from this texture.
/// </summary>
public void SynchronizeDependents()
{
foreach (TextureDependency dependency in Dependencies)
{
TextureGroupHandle otherHandle = dependency.Other.Handle;
if (otherHandle.DeferredCopy == this)
{
otherHandle._group.Storage.SynchronizeMemory();
}
}
}
/// <summary> /// <summary>
/// Signal that a copy dependent texture has been modified, and must have its data copied to this one. /// Signal that a copy dependent texture has been modified, and must have its data copied to this one.
/// </summary> /// </summary>