Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TextureGroup.ClearModified thread safe #6686

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Gpu/Image/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void RemoveView(Texture texture)
{
_views.Remove(texture);

Group.RemoveView(texture);
Group.RemoveView(_views, texture);

texture._viewStorage = texture;

Expand Down
18 changes: 12 additions & 6 deletions src/Ryujinx.Graphics.Gpu/Image/TextureGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class TextureGroup : IDisposable
private MultiRange TextureRange => Storage.Range;

/// <summary>
/// The views list from the storage texture.
/// The views array from the storage texture.
/// </summary>
private List<Texture> _views;
private Texture[] _views;
private TextureGroupHandle[] _handles;
private bool[] _loadNeeded;

Expand Down Expand Up @@ -1074,7 +1074,7 @@ private TextureGroupHandle GenerateHandles(int viewStart, int views)
public void UpdateViews(List<Texture> views, Texture texture)
{
// This is saved to calculate overlapping views for each handle.
_views = views;
_views = views.ToArray();

bool layerViews = _hasLayerViews;
bool mipViews = _hasMipViews;
Expand Down Expand Up @@ -1136,9 +1136,13 @@ public void UpdateViews(List<Texture> views, Texture texture)
/// <summary>
/// Removes a view from the group, removing it from all overlap lists.
/// </summary>
/// <param name="views">The views list of the storage texture</param>
/// <param name="view">View to remove from the group</param>
public void RemoveView(Texture view)
public void RemoveView(List<Texture> views, Texture view)
{
// This is saved to calculate overlapping views for each handle.
_views = views.ToArray();

int offset = FindOffset(view);

foreach (TextureGroupHandle handle in _handles)
Expand Down Expand Up @@ -1605,9 +1609,11 @@ public void ClearModified(MultiRange range, TextureGroup ignore = null)

Storage.SignalModifiedDirty();

if (_views != null)
Texture[] views = _views;

if (views != null)
{
foreach (Texture texture in _views)
foreach (Texture texture in views)
{
texture.SignalModifiedDirty();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx.Graphics.Gpu/Image/TextureGroupHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class TextureGroupHandle : ISyncActionHandler, IDisposable
public TextureGroupHandle(TextureGroup group,
int offset,
ulong size,
List<Texture> views,
IEnumerable<Texture> views,
int firstLayer,
int firstLevel,
int baseSlice,
Expand Down Expand Up @@ -201,8 +201,8 @@ public void DiscardData()
/// Calculate a list of which views overlap this handle.
/// </summary>
/// <param name="group">The parent texture group, used to find a view's base CPU VA offset</param>
/// <param name="views">The list of views to search for overlaps</param>
public void RecalculateOverlaps(TextureGroup group, List<Texture> views)
/// <param name="views">The views to search for overlaps</param>
public void RecalculateOverlaps(TextureGroup group, IEnumerable<Texture> views)
{
// Overlaps can be accessed from the memory tracking signal handler, so access must be atomic.
lock (Overlaps)
Expand Down