2020-04-22 02:00:11 -04:00
|
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-03 22:24:59 -04:00
|
|
|
|
using Ryujinx.Graphics.GAL;
|
2021-06-29 13:32:02 -04:00
|
|
|
|
using Ryujinx.Graphics.Gpu.Memory;
|
2020-04-22 02:00:11 -04:00
|
|
|
|
using Ryujinx.Graphics.Gpu.State;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Engine
|
|
|
|
|
{
|
|
|
|
|
partial class Methods
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if draws and clears should be performed, according
|
|
|
|
|
/// to currently set conditional rendering conditions.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">GPU state</param>
|
|
|
|
|
/// <returns>True if rendering is enabled, false otherwise</returns>
|
2020-05-03 22:24:59 -04:00
|
|
|
|
private ConditionalRenderEnabled GetRenderEnable(GpuState state)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
|
|
|
|
ConditionState condState = state.Get<ConditionState>(MethodOffset.ConditionState);
|
|
|
|
|
|
|
|
|
|
switch (condState.Condition)
|
|
|
|
|
{
|
|
|
|
|
case Condition.Always:
|
2020-05-03 22:24:59 -04:00
|
|
|
|
return ConditionalRenderEnabled.True;
|
2020-04-22 02:00:11 -04:00
|
|
|
|
case Condition.Never:
|
2020-05-03 22:24:59 -04:00
|
|
|
|
return ConditionalRenderEnabled.False;
|
2020-04-22 02:00:11 -04:00
|
|
|
|
case Condition.ResultNonZero:
|
2021-06-29 13:32:02 -04:00
|
|
|
|
return CounterNonZero(state, condState.Address.Pack());
|
2020-04-22 02:00:11 -04:00
|
|
|
|
case Condition.Equal:
|
2021-06-29 13:32:02 -04:00
|
|
|
|
return CounterCompare(state, condState.Address.Pack(), true);
|
2020-04-22 02:00:11 -04:00
|
|
|
|
case Condition.NotEqual:
|
2021-06-29 13:32:02 -04:00
|
|
|
|
return CounterCompare(state, condState.Address.Pack(), false);
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
|
Logger.Warning?.Print(LogClass.Gpu, $"Invalid conditional render condition \"{condState.Condition}\".");
|
2020-04-22 02:00:11 -04:00
|
|
|
|
|
2020-05-03 22:24:59 -04:00
|
|
|
|
return ConditionalRenderEnabled.True;
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the counter value at a given GPU memory address is non-zero.
|
|
|
|
|
/// </summary>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
/// <param name="state">GPU state</param>
|
2020-04-22 02:00:11 -04:00
|
|
|
|
/// <param name="gpuVa">GPU virtual address of the counter value</param>
|
2020-05-03 22:24:59 -04:00
|
|
|
|
/// <returns>True if the value is not zero, false otherwise. Returns host if handling with host conditional rendering</returns>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
private ConditionalRenderEnabled CounterNonZero(GpuState state, ulong gpuVa)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ICounterEvent evt = state.Channel.MemoryManager.CounterCache.FindEvent(gpuVa);
|
2020-05-03 22:24:59 -04:00
|
|
|
|
|
|
|
|
|
if (evt == null)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2020-05-03 22:24:59 -04:00
|
|
|
|
return ConditionalRenderEnabled.False;
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 22:24:59 -04:00
|
|
|
|
if (_context.Renderer.Pipeline.TryHostConditionalRendering(evt, 0L, false))
|
|
|
|
|
{
|
|
|
|
|
return ConditionalRenderEnabled.Host;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
evt.Flush();
|
2021-06-29 13:32:02 -04:00
|
|
|
|
return (state.Channel.MemoryManager.Read<ulong>(gpuVa) != 0) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False;
|
2020-05-03 22:24:59 -04:00
|
|
|
|
}
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the counter at a given GPU memory address passes a specified equality comparison.
|
|
|
|
|
/// </summary>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
/// <param name="state">GPU state</param>
|
2020-04-22 02:00:11 -04:00
|
|
|
|
/// <param name="gpuVa">GPU virtual address</param>
|
|
|
|
|
/// <param name="isEqual">True to check if the values are equal, false to check if they are not equal</param>
|
2020-05-03 22:24:59 -04:00
|
|
|
|
/// <returns>True if the condition is met, false otherwise. Returns host if handling with host conditional rendering</returns>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
private ConditionalRenderEnabled CounterCompare(GpuState state, ulong gpuVa, bool isEqual)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ICounterEvent evt = FindEvent(state.Channel.MemoryManager.CounterCache, gpuVa);
|
|
|
|
|
ICounterEvent evt2 = FindEvent(state.Channel.MemoryManager.CounterCache, gpuVa + 16);
|
2020-05-03 22:24:59 -04:00
|
|
|
|
|
|
|
|
|
bool useHost;
|
|
|
|
|
|
|
|
|
|
if (evt != null && evt2 == null)
|
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, state.Channel.MemoryManager.Read<ulong>(gpuVa + 16), isEqual);
|
2020-05-03 22:24:59 -04:00
|
|
|
|
}
|
|
|
|
|
else if (evt == null && evt2 != null)
|
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt2, state.Channel.MemoryManager.Read<ulong>(gpuVa), isEqual);
|
2020-05-03 22:24:59 -04:00
|
|
|
|
}
|
2021-01-26 16:42:12 -05:00
|
|
|
|
else if (evt != null && evt2 != null)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2020-05-03 22:24:59 -04:00
|
|
|
|
useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, evt2, isEqual);
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
2021-01-26 16:42:12 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
useHost = false;
|
|
|
|
|
}
|
2020-04-22 02:00:11 -04:00
|
|
|
|
|
2020-05-03 22:24:59 -04:00
|
|
|
|
if (useHost)
|
|
|
|
|
{
|
|
|
|
|
return ConditionalRenderEnabled.Host;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
evt?.Flush();
|
|
|
|
|
evt2?.Flush();
|
2020-04-22 02:00:11 -04:00
|
|
|
|
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong x = state.Channel.MemoryManager.Read<ulong>(gpuVa);
|
|
|
|
|
ulong y = state.Channel.MemoryManager.Read<ulong>(gpuVa + 16);
|
2020-05-03 22:24:59 -04:00
|
|
|
|
|
|
|
|
|
return (isEqual ? x == y : x != y) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False;
|
|
|
|
|
}
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tries to find a counter that is supposed to be written at the specified address,
|
2020-05-03 22:24:59 -04:00
|
|
|
|
/// returning the related event.
|
2020-04-22 02:00:11 -04:00
|
|
|
|
/// </summary>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
/// <param name="counterCache">GPU counter cache to search on</param>
|
2020-04-22 02:00:11 -04:00
|
|
|
|
/// <param name="gpuVa">GPU virtual address where the counter is supposed to be written</param>
|
2020-05-03 22:24:59 -04:00
|
|
|
|
/// <returns>The counter event, or null if not present</returns>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
private static ICounterEvent FindEvent(CounterCache counterCache, ulong gpuVa)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
return counterCache.FindEvent(gpuVa);
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|