From 360630ad6b2f6385cd136adfc7e9c2be6ae4147c Mon Sep 17 00:00:00 2001 From: Gabriel A Date: Tue, 14 Nov 2023 00:09:51 -0300 Subject: [PATCH] Update bindless textures on data modification --- src/Ryujinx.Graphics.Gpu/Image/Texture.cs | 16 ++++++++++++++-- src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs | 6 ++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Ryujinx.Graphics.Gpu/Image/Texture.cs b/src/Ryujinx.Graphics.Gpu/Image/Texture.cs index 5742bae9a..a5360f922 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/Texture.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/Texture.cs @@ -621,6 +621,10 @@ namespace Ryujinx.Graphics.Gpu.Image public void SignalGroupDirty() { _dirty = true; + + // If this used as a bindless texture, we must force it to be updated on next use, + // since the CPU modified the data. + ForceTexturePoolUpdate(); } /// @@ -1471,9 +1475,12 @@ namespace Ryujinx.Graphics.Gpu.Image /// private void ForceTexturePoolUpdate() { - foreach (TexturePoolOwner poolOwner in _poolOwners) + lock (_poolOwners) { - poolOwner.Pool.ForceModifiedEntry(poolOwner.ID); + foreach (TexturePoolOwner poolOwner in _poolOwners) + { + poolOwner.Pool.ForceModifiedEntry(poolOwner.ID); + } } } @@ -1538,6 +1545,11 @@ namespace Ryujinx.Graphics.Gpu.Image _poolOwners.Add(new TexturePoolOwner { Pool = pool, ID = id, GpuAddress = gpuVa }); } + if (_dirty) + { + pool.ForceModifiedEntry(id); + } + _referenceCount++; if (ShortCacheEntry != null) diff --git a/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs b/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs index b0121b61f..43e839076 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs @@ -254,8 +254,6 @@ namespace Ryujinx.Graphics.Gpu.Image return; } - Items[textureId]?.SynchronizeMemory(); - bool textureModified = ModifiedEntries.Clear(textureId); if (samplerPool != null) @@ -304,6 +302,10 @@ namespace Ryujinx.Graphics.Gpu.Image /// ID of the texture private void UpdateBindlessInternal(IRenderer renderer, int id) { + // If the texture already exists, check if it has not been modified since the last use. + // If it was, update the data. + Items[id]?.SynchronizeMemory(); + Texture texture = Items[id] ?? GetValidated(id); if (texture != null)