Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1db417d652 | |||
| ae1fea3597 |
@@ -0,0 +1,35 @@
|
|||||||
|
namespace Ryujinx.Common
|
||||||
|
{
|
||||||
|
public class BitTricks
|
||||||
|
{
|
||||||
|
// Never actually written bit packing logic before, so I looked it up.
|
||||||
|
// This code is from https://gist.github.com/Alan-FGR/04938e93e2bffdf5802ceb218a37c195
|
||||||
|
|
||||||
|
public static ulong PackBitFields(uint[] values, byte[] bitFields)
|
||||||
|
{
|
||||||
|
ulong retVal = values[0]; //we set the first value right away
|
||||||
|
for (int f = 1; f < values.Length; f++)
|
||||||
|
{
|
||||||
|
retVal <<= bitFields[f]; // we shift the previous value
|
||||||
|
retVal += values[f];// and add our current value
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint[] UnpackBitFields(ulong packed, byte[] bitFields)
|
||||||
|
{
|
||||||
|
int fields = bitFields.Length - 1; // number of fields to unpack
|
||||||
|
uint[] retArr = new uint[fields + 1]; // init return array
|
||||||
|
int curPos = 0; // current field bit position (start)
|
||||||
|
int lastEnd; // position where last field ended
|
||||||
|
for (int f = fields; f >= 0; f--) // loop from last
|
||||||
|
{
|
||||||
|
lastEnd = curPos; // we store where the last value ended
|
||||||
|
curPos += bitFields[f]; // we get where the current value starts
|
||||||
|
int leftShift = 64 - curPos; // we figure how much left shift we gotta apply for the other numbers to overflow into oblivion
|
||||||
|
retArr[f] = (uint)((packed << leftShift) >> leftShift + lastEnd); // we do magic
|
||||||
|
}
|
||||||
|
return retArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Gommon;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -15,14 +14,12 @@ namespace Ryujinx.Common.Configuration
|
|||||||
public record EnabledDirtyHack(DirtyHacks Hack, int Value)
|
public record EnabledDirtyHack(DirtyHacks Hack, int Value)
|
||||||
{
|
{
|
||||||
public static readonly byte[] PackedFormat = [8, 32];
|
public static readonly byte[] PackedFormat = [8, 32];
|
||||||
|
|
||||||
private uint[] Raw => [(uint)Hack, (uint)Value.CoerceAtLeast(0)];
|
public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], PackedFormat);
|
||||||
|
|
||||||
public ulong Pack() => Raw.PackBitFields(PackedFormat);
|
|
||||||
|
|
||||||
public static EnabledDirtyHack Unpack(ulong packedHack)
|
public static EnabledDirtyHack Unpack(ulong packedHack)
|
||||||
{
|
{
|
||||||
var unpackedFields = packedHack.UnpackBitFields(PackedFormat);
|
var unpackedFields = BitTricks.UnpackBitFields(packedHack, PackedFormat);
|
||||||
if (unpackedFields is not [var hack, var value])
|
if (unpackedFields is not [var hack, var value])
|
||||||
throw new ArgumentException(nameof(packedHack));
|
throw new ArgumentException(nameof(packedHack));
|
||||||
|
|
||||||
@@ -32,17 +29,26 @@ namespace Ryujinx.Common.Configuration
|
|||||||
|
|
||||||
public class DirtyHackCollection : Dictionary<DirtyHacks, int>
|
public class DirtyHackCollection : Dictionary<DirtyHacks, int>
|
||||||
{
|
{
|
||||||
public DirtyHackCollection(IEnumerable<EnabledDirtyHack> hacks)
|
public DirtyHackCollection(EnabledDirtyHack[] hacks)
|
||||||
=> hacks.ForEach(edh => Add(edh.Hack, edh.Value));
|
{
|
||||||
|
foreach ((DirtyHacks dirtyHacks, int value) in hacks)
|
||||||
public DirtyHackCollection(ulong[] packedHacks) : this(packedHacks.Select(EnabledDirtyHack.Unpack)) {}
|
{
|
||||||
|
Add(dirtyHacks, value);
|
||||||
public ulong[] PackEntries()
|
}
|
||||||
=> Entries.Select(it => it.Pack()).ToArray();
|
}
|
||||||
|
|
||||||
public EnabledDirtyHack[] Entries
|
public DirtyHackCollection(ulong[] packedHacks)
|
||||||
=> this
|
{
|
||||||
.Select(it => new EnabledDirtyHack(it.Key, it.Value))
|
foreach ((DirtyHacks dirtyHacks, int value) in packedHacks.Select(EnabledDirtyHack.Unpack))
|
||||||
|
{
|
||||||
|
Add(dirtyHacks, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong[] PackEntries() =>
|
||||||
|
this
|
||||||
|
.Select(it =>
|
||||||
|
BitTricks.PackBitFields([(uint)it.Key, (uint)it.Value], EnabledDirtyHack.PackedFormat))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
public static implicit operator DirtyHackCollection(EnabledDirtyHack[] hacks) => new(hacks);
|
public static implicit operator DirtyHackCollection(EnabledDirtyHack[] hacks) => new(hacks);
|
||||||
|
|||||||
@@ -40,35 +40,5 @@ namespace Ryujinx.Common
|
|||||||
|
|
||||||
return (value >> 32) | (value << 32);
|
return (value >> 32) | (value << 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never actually written bit packing logic before, so I looked it up.
|
|
||||||
// This code is from https://gist.github.com/Alan-FGR/04938e93e2bffdf5802ceb218a37c195
|
|
||||||
|
|
||||||
public static ulong PackBitFields(this uint[] values, byte[] bitFields)
|
|
||||||
{
|
|
||||||
ulong retVal = values[0]; //we set the first value right away
|
|
||||||
for (int f = 1; f < values.Length; f++)
|
|
||||||
{
|
|
||||||
retVal <<= bitFields[f]; // we shift the previous value
|
|
||||||
retVal += values[f];// and add our current value
|
|
||||||
}
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static uint[] UnpackBitFields(this ulong packed, byte[] bitFields)
|
|
||||||
{
|
|
||||||
int fields = bitFields.Length - 1; // number of fields to unpack
|
|
||||||
uint[] retArr = new uint[fields + 1]; // init return array
|
|
||||||
int curPos = 0; // current field bit position (start)
|
|
||||||
int lastEnd; // position where last field ended
|
|
||||||
for (int f = fields; f >= 0; f--) // loop from last
|
|
||||||
{
|
|
||||||
lastEnd = curPos; // we store where the last value ended
|
|
||||||
curPos += bitFields[f]; // we get where the current value starts
|
|
||||||
int leftShift = 64 - curPos; // we figure how much left shift we gotta apply for the other numbers to overflow into oblivion
|
|
||||||
retArr[f] = (uint)((packed << leftShift) >> leftShift + lastEnd); // we do magic
|
|
||||||
}
|
|
||||||
return retArr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using Gommon;
|
|
||||||
using Ryujinx.Ava.Utilities.Configuration.System;
|
using Ryujinx.Ava.Utilities.Configuration.System;
|
||||||
using Ryujinx.Ava.Utilities.Configuration.UI;
|
using Ryujinx.Ava.Utilities.Configuration.UI;
|
||||||
using Ryujinx.Common.Configuration;
|
using Ryujinx.Common.Configuration;
|
||||||
@@ -10,6 +9,7 @@ using Ryujinx.Common.Logging;
|
|||||||
using Ryujinx.HLE;
|
using Ryujinx.HLE;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Ryujinx.Ava.Utilities.Configuration
|
namespace Ryujinx.Ava.Utilities.Configuration
|
||||||
{
|
{
|
||||||
@@ -752,12 +752,14 @@ namespace Ryujinx.Ava.Utilities.Configuration
|
|||||||
Hacks.ShowDirtyHacks.Value = configurationFileFormat.ShowDirtyHacks;
|
Hacks.ShowDirtyHacks.Value = configurationFileFormat.ShowDirtyHacks;
|
||||||
|
|
||||||
{
|
{
|
||||||
DirtyHackCollection hacks = new (configurationFileFormat.DirtyHacks ?? []);
|
EnabledDirtyHack[] hacks = (configurationFileFormat.DirtyHacks ?? []).Select(EnabledDirtyHack.Unpack).ToArray();
|
||||||
|
|
||||||
Hacks.Xc2MenuSoftlockFix.Value = hacks.IsEnabled(DirtyHacks.Xc2MenuSoftlockFix);
|
Hacks.Xc2MenuSoftlockFix.Value = hacks.Any(it => it.Hack == DirtyHacks.Xc2MenuSoftlockFix);
|
||||||
|
|
||||||
Hacks.EnableShaderTranslationDelay.Value = hacks.IsEnabled(DirtyHacks.ShaderCompilationThreadSleep);
|
var shaderCompilationThreadSleep = hacks.FirstOrDefault(it =>
|
||||||
Hacks.ShaderTranslationDelay.Value = hacks[DirtyHacks.ShaderCompilationThreadSleep].CoerceAtLeast(0);
|
it.Hack == DirtyHacks.ShaderCompilationThreadSleep);
|
||||||
|
Hacks.EnableShaderTranslationDelay.Value = shaderCompilationThreadSleep != null;
|
||||||
|
Hacks.ShaderTranslationDelay.Value = shaderCompilationThreadSleep?.Value ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configurationFileUpdated)
|
if (configurationFileUpdated)
|
||||||
|
|||||||
Reference in New Issue
Block a user