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

Gpu: Fix thread safety of ReregisterRanges #3865

Merged
merged 1 commit into from Nov 18, 2022
Merged
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
8 changes: 5 additions & 3 deletions Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs
Expand Up @@ -325,13 +325,15 @@ public void InheritRanges(BufferModifiedRangeList ranges, Action<ulong, ulong> r
public void ReregisterRanges(Action<ulong, ulong> rangeAction)
{
ref var ranges = ref ThreadStaticArray<BufferModifiedRange>.Get();
int count;

// Range list must be consistent for this operation.
lock (_lock)
{
if (ranges.Length < Count)
count = Count;
if (ranges.Length < count)
{
Array.Resize(ref ranges, Count);
Array.Resize(ref ranges, count);
}

int i = 0;
Expand All @@ -342,7 +344,7 @@ public void ReregisterRanges(Action<ulong, ulong> rangeAction)
}

ulong currentSync = _context.SyncNumber;
for (int i = 0; i < Count; i++)
for (int i = 0; i < count; i++)
{
BufferModifiedRange range = ranges[i];
if (range.SyncNumber != currentSync)
Expand Down