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

Selective Barriers & Feedback Loops change #496

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Ryujinx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ryujinx.Graphics.Rdna3Vulkan", "src\Ryujinx.Graphics.Rdna3Vulkan\Ryujinx.Graphics.Rdna3Vulkan.csproj", "{5D8C99F7-AC66-43CF-AE84-68ADA27CCED7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -259,6 +261,10 @@ Global
{81EA598C-DBA1-40B0-8DA4-4796B78F2037}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81EA598C-DBA1-40B0-8DA4-4796B78F2037}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81EA598C-DBA1-40B0-8DA4-4796B78F2037}.Release|Any CPU.Build.0 = Release|Any CPU
{5D8C99F7-AC66-43CF-AE84-68ADA27CCED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D8C99F7-AC66-43CF-AE84-68ADA27CCED7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D8C99F7-AC66-43CF-AE84-68ADA27CCED7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D8C99F7-AC66-43CF-AE84-68ADA27CCED7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
24 changes: 2 additions & 22 deletions src/Ryujinx.Common/GraphicsDriver/DriverUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
using Ryujinx.Common.Utilities;
using System;

namespace Ryujinx.Common.GraphicsDriver
{
public static class DriverUtilities
{
private static void AddMesaFlags(string envVar, string newFlags)
{
string existingFlags = Environment.GetEnvironmentVariable(envVar);

string flags = existingFlags == null ? newFlags : $"{existingFlags},{newFlags}";

OsUtils.SetEnvironmentVariableNoCaching(envVar, flags);
}

public static void InitDriverConfig(bool oglThreading)
{
if (OperatingSystem.IsLinux())
{
AddMesaFlags("RADV_DEBUG", "nodcc");
}

ToggleOGLThreading(oglThreading);
}

public static void ToggleOGLThreading(bool enabled)
{
OsUtils.SetEnvironmentVariableNoCaching("mesa_glthread", enabled.ToString().ToLower());
OsUtils.SetEnvironmentVariableNoCaching("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");
Environment.SetEnvironmentVariable("mesa_glthread", enabled.ToString().ToLower());
Environment.SetEnvironmentVariable("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");

try
{
Expand Down
24 changes: 0 additions & 24 deletions src/Ryujinx.Common/Utilities/OsUtils.cs

This file was deleted.

191 changes: 191 additions & 0 deletions src/Ryujinx.Graphics.Rdna3Vulkan/Auto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
using System;
using System.Diagnostics;
using System.Threading;

namespace Ryujinx.Graphics.Rdna3Vulkan
{
interface IAuto
{
bool HasCommandBufferDependency(CommandBufferScoped cbs);

void IncrementReferenceCount();
void DecrementReferenceCount(int cbIndex);
void DecrementReferenceCount();
}

interface IAutoPrivate : IAuto
{
void AddCommandBufferDependencies(CommandBufferScoped cbs);
}

interface IMirrorable<T> where T : IDisposable
{
Auto<T> GetMirrorable(CommandBufferScoped cbs, ref int offset, int size, out bool mirrored);
void ClearMirrors(CommandBufferScoped cbs, int offset, int size);
}

class Auto<T> : IAutoPrivate, IDisposable where T : IDisposable
{
private int _referenceCount;
private T _value;

private readonly BitMap _cbOwnership;
private readonly MultiFenceHolder _waitable;
private readonly IAutoPrivate[] _referencedObjs;
private readonly IMirrorable<T> _mirrorable;

private bool _disposed;
private bool _destroyed;

public Auto(T value)
{
_referenceCount = 1;
_value = value;
_cbOwnership = new BitMap(CommandBufferPool.MaxCommandBuffers);
}

public Auto(T value, IMirrorable<T> mirrorable, MultiFenceHolder waitable, params IAutoPrivate[] referencedObjs) : this(value, waitable, referencedObjs)
{
_mirrorable = mirrorable;
}

public Auto(T value, MultiFenceHolder waitable, params IAutoPrivate[] referencedObjs) : this(value)
{
_waitable = waitable;
_referencedObjs = referencedObjs;

for (int i = 0; i < referencedObjs.Length; i++)
{
referencedObjs[i].IncrementReferenceCount();
}
}

public T GetMirrorable(CommandBufferScoped cbs, ref int offset, int size, out bool mirrored)
{
var mirror = _mirrorable.GetMirrorable(cbs, ref offset, size, out mirrored);
mirror._waitable?.AddBufferUse(cbs.CommandBufferIndex, offset, size, false);
return mirror.Get(cbs);
}

public T Get(CommandBufferScoped cbs, int offset, int size, bool write = false)
{
_mirrorable?.ClearMirrors(cbs, offset, size);
_waitable?.AddBufferUse(cbs.CommandBufferIndex, offset, size, write);
return Get(cbs);
}

public T GetUnsafe()
{
return _value;
}

public T Get(CommandBufferScoped cbs)
{
if (!_destroyed)
{
AddCommandBufferDependencies(cbs);
}

return _value;
}

public bool HasCommandBufferDependency(CommandBufferScoped cbs)
{
return _cbOwnership.IsSet(cbs.CommandBufferIndex);
}

public bool HasRentedCommandBufferDependency(CommandBufferPool cbp)
{
return _cbOwnership.AnySet();
}

public void AddCommandBufferDependencies(CommandBufferScoped cbs)
{
// We don't want to add a reference to this object to the command buffer
// more than once, so if we detect that the command buffer already has ownership
// of this object, then we can just return without doing anything else.
if (_cbOwnership.Set(cbs.CommandBufferIndex))
{
if (_waitable != null)
{
cbs.AddWaitable(_waitable);
}

cbs.AddDependant(this);

// We need to add a dependency on the command buffer to all objects this object
// references aswell.
if (_referencedObjs != null)
{
for (int i = 0; i < _referencedObjs.Length; i++)
{
_referencedObjs[i].AddCommandBufferDependencies(cbs);
}
}
}
}

public bool TryIncrementReferenceCount()
{
int lastValue;
do
{
lastValue = _referenceCount;

if (lastValue == 0)
{
return false;
}
}
while (Interlocked.CompareExchange(ref _referenceCount, lastValue + 1, lastValue) != lastValue);

return true;
}

public void IncrementReferenceCount()
{
if (Interlocked.Increment(ref _referenceCount) == 1)
{
Interlocked.Decrement(ref _referenceCount);
throw new InvalidOperationException("Attempted to increment the reference count of an object that was already destroyed.");
}
}

public void DecrementReferenceCount(int cbIndex)
{
_cbOwnership.Clear(cbIndex);
DecrementReferenceCount();
}

public void DecrementReferenceCount()
{
if (Interlocked.Decrement(ref _referenceCount) == 0)
{
_value.Dispose();
_value = default;
_destroyed = true;

// Value is no longer in use by the GPU, dispose all other
// resources that it references.
if (_referencedObjs != null)
{
for (int i = 0; i < _referencedObjs.Length; i++)
{
_referencedObjs[i].DecrementReferenceCount();
}
}
}

Debug.Assert(_referenceCount >= 0);
}

public void Dispose()
{
if (!_disposed)
{
DecrementReferenceCount();
_disposed = true;
}
}
}
}
Loading
Loading