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-07-11 16:20:40 -04:00
|
|
|
|
using Ryujinx.Graphics.Gpu.Engine.Types;
|
2021-06-29 13:32:02 -04:00
|
|
|
|
using Ryujinx.Graphics.Gpu.Memory;
|
2020-04-22 02:00:11 -04:00
|
|
|
|
|
2021-07-11 16:20:40 -04:00
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2021-07-11 16:20:40 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper methods used for conditional rendering.
|
|
|
|
|
/// </summary>
|
|
|
|
|
static class ConditionalRendering
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if draws and clears should be performed, according
|
|
|
|
|
/// to currently set conditional rendering conditions.
|
|
|
|
|
/// </summary>
|
2021-07-11 16:20:40 -04:00
|
|
|
|
/// <param name="context">GPU context</param>
|
|
|
|
|
/// <param name="memoryManager">Memory manager bound to the channel currently executing</param>
|
|
|
|
|
/// <param name="address">Conditional rendering buffer address</param>
|
|
|
|
|
/// <param name="condition">Conditional rendering condition</param>
|
2020-04-22 02:00:11 -04:00
|
|
|
|
/// <returns>True if rendering is enabled, false otherwise</returns>
|
2021-07-11 16:20:40 -04:00
|
|
|
|
public static ConditionalRenderEnabled GetRenderEnable(GpuContext context, MemoryManager memoryManager, GpuVa address, Condition condition)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2021-07-11 16:20:40 -04:00
|
|
|
|
switch (condition)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
|
|
|
|
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-07-11 16:20:40 -04:00
|
|
|
|
return CounterNonZero(context, memoryManager, address.Pack());
|
2020-04-22 02:00:11 -04:00
|
|
|
|
case Condition.Equal:
|
2021-07-11 16:20:40 -04:00
|
|
|
|
return CounterCompare(context, memoryManager, address.Pack(), true);
|
2020-04-22 02:00:11 -04:00
|
|
|
|
case Condition.NotEqual:
|
2021-07-11 16:20:40 -04:00
|
|
|
|
return CounterCompare(context, memoryManager, address.Pack(), false);
|
2020-04-22 02:00:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 16:20:40 -04:00
|
|
|
|
Logger.Warning?.Print(LogClass.Gpu, $"Invalid conditional render condition \"{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-07-11 16:20:40 -04:00
|
|
|
|
/// <param name="context">GPU context</param>
|
|
|
|
|
/// <param name="memoryManager">Memory manager bound to the channel currently executing</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-07-11 16:20:40 -04:00
|
|
|
|
private static ConditionalRenderEnabled CounterNonZero(GpuContext context, MemoryManager memoryManager, ulong gpuVa)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2021-07-11 16:20:40 -04:00
|
|
|
|
ICounterEvent evt = 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
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 16:20:40 -04:00
|
|
|
|
if (context.Renderer.Pipeline.TryHostConditionalRendering(evt, 0L, false))
|
2020-05-03 22:24:59 -04:00
|
|
|
|
{
|
|
|
|
|
return ConditionalRenderEnabled.Host;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
evt.Flush();
|
2021-07-11 16:20:40 -04:00
|
|
|
|
return (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-07-11 16:20:40 -04:00
|
|
|
|
/// <param name="context">GPU context</param>
|
|
|
|
|
/// <param name="memoryManager">Memory manager bound to the channel currently executing</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-07-11 16:20:40 -04:00
|
|
|
|
private static ConditionalRenderEnabled CounterCompare(GpuContext context, MemoryManager memoryManager, ulong gpuVa, bool isEqual)
|
2020-04-22 02:00:11 -04:00
|
|
|
|
{
|
2021-07-11 16:20:40 -04:00
|
|
|
|
ICounterEvent evt = FindEvent(memoryManager.CounterCache, gpuVa);
|
|
|
|
|
ICounterEvent evt2 = FindEvent(memoryManager.CounterCache, gpuVa + 16);
|
2020-05-03 22:24:59 -04:00
|
|
|
|
|
|
|
|
|
bool useHost;
|
|
|
|
|
|
|
|
|
|
if (evt != null && evt2 == null)
|
|
|
|
|
{
|
2021-07-11 16:20:40 -04:00
|
|
|
|
useHost = context.Renderer.Pipeline.TryHostConditionalRendering(evt, memoryManager.Read<ulong>(gpuVa + 16), isEqual);
|
2020-05-03 22:24:59 -04:00
|
|
|
|
}
|
|
|
|
|
else if (evt == null && evt2 != null)
|
|
|
|
|
{
|
2021-07-11 16:20:40 -04:00
|
|
|
|
useHost = context.Renderer.Pipeline.TryHostConditionalRendering(evt2, 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
|
|
|
|
{
|
2021-07-11 16:20:40 -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-07-11 16:20:40 -04:00
|
|
|
|
ulong x = memoryManager.Read<ulong>(gpuVa);
|
|
|
|
|
ulong y = 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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|