mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2025-04-17 14:34:05 -05:00

* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA1069 warnings * Address or silence dotnet format CA2211 warnings * Address remaining dotnet format analyzer warnings * Address review comments * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Another rebase, another dotnet format run * Run dotnet format style after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Remove a few unused parameters * Replace MmeShadowScratch with Array256<uint> * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Run dotnet format after rebase * Address IDE0251 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First pass of dotnet format * Add unsafe dotnet format changes * Fix typos * Add trailing commas * Disable formatting for FormatTable * Address review feedback
116 lines
3.8 KiB
C#
116 lines
3.8 KiB
C#
using Ryujinx.Common;
|
|
using Ryujinx.Graphics.GAL;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender
|
|
{
|
|
/// <summary>
|
|
/// Advanced blend manager.
|
|
/// </summary>
|
|
class AdvancedBlendManager
|
|
{
|
|
private const int InstructionRamSize = 128;
|
|
private const int InstructionRamSizeMask = InstructionRamSize - 1;
|
|
|
|
private readonly DeviceStateWithShadow<ThreedClassState> _state;
|
|
|
|
private readonly uint[] _code;
|
|
private int _ip;
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of the advanced blend manager.
|
|
/// </summary>
|
|
/// <param name="state">GPU state of the channel owning this manager</param>
|
|
public AdvancedBlendManager(DeviceStateWithShadow<ThreedClassState> state)
|
|
{
|
|
_state = state;
|
|
_code = new uint[InstructionRamSize];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the start offset of the blend microcode in memory.
|
|
/// </summary>
|
|
/// <param name="argument">Method call argument</param>
|
|
public void LoadBlendUcodeStart(int argument)
|
|
{
|
|
_ip = argument;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pushes one word of blend microcode.
|
|
/// </summary>
|
|
/// <param name="argument">Method call argument</param>
|
|
public void LoadBlendUcodeInstruction(int argument)
|
|
{
|
|
_code[_ip++ & InstructionRamSizeMask] = (uint)argument;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to identify the current advanced blend function being used,
|
|
/// given the current state and microcode that was uploaded.
|
|
/// </summary>
|
|
/// <param name="descriptor">Advanced blend descriptor</param>
|
|
/// <returns>True if the function was found, false otherwise</returns>
|
|
public bool TryGetAdvancedBlend(out AdvancedBlendDescriptor descriptor)
|
|
{
|
|
Span<uint> currentCode = new(_code);
|
|
byte codeLength = (byte)_state.State.BlendUcodeSize;
|
|
|
|
if (currentCode.Length > codeLength)
|
|
{
|
|
currentCode = currentCode[..codeLength];
|
|
}
|
|
|
|
Hash128 hash = XXHash128.ComputeHash(MemoryMarshal.Cast<uint, byte>(currentCode));
|
|
|
|
descriptor = default;
|
|
|
|
if (!AdvancedBlendPreGenTable.Entries.TryGetValue(hash, out var entry))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (entry.Constants != null)
|
|
{
|
|
bool constantsMatch = true;
|
|
|
|
for (int i = 0; i < entry.Constants.Length; i++)
|
|
{
|
|
RgbFloat constant = entry.Constants[i];
|
|
RgbHalf constant2 = _state.State.BlendUcodeConstants[i];
|
|
|
|
if ((Half)constant.R != constant2.UnpackR() ||
|
|
(Half)constant.G != constant2.UnpackG() ||
|
|
(Half)constant.B != constant2.UnpackB())
|
|
{
|
|
constantsMatch = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!constantsMatch)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (entry.Alpha.Enable != _state.State.BlendUcodeEnable)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (entry.Alpha.Enable == BlendUcodeEnable.EnableRGBA &&
|
|
(entry.Alpha.AlphaOp != _state.State.BlendStateCommon.AlphaOp ||
|
|
entry.Alpha.AlphaSrcFactor != _state.State.BlendStateCommon.AlphaSrcFactor ||
|
|
entry.Alpha.AlphaDstFactor != _state.State.BlendStateCommon.AlphaDstFactor))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
descriptor = new AdvancedBlendDescriptor(entry.Op, entry.Overlap, entry.SrcPreMultiplied);
|
|
return true;
|
|
}
|
|
}
|
|
}
|