Compare commits
2 Commits
Canary-1.2
...
Canary-1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
172869bfba | ||
|
|
b6f88514f9 |
@@ -1,35 +0,0 @@
|
|||||||
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,4 +1,5 @@
|
|||||||
using System;
|
using Gommon;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -15,11 +16,13 @@ namespace Ryujinx.Common.Configuration
|
|||||||
{
|
{
|
||||||
public static readonly byte[] PackedFormat = [8, 32];
|
public static readonly byte[] PackedFormat = [8, 32];
|
||||||
|
|
||||||
public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], PackedFormat);
|
private uint[] Raw => [(uint)Hack, (uint)Value.CoerceAtLeast(0)];
|
||||||
|
|
||||||
|
public ulong Pack() => Raw.PackBitFields(PackedFormat);
|
||||||
|
|
||||||
public static EnabledDirtyHack Unpack(ulong packedHack)
|
public static EnabledDirtyHack Unpack(ulong packedHack)
|
||||||
{
|
{
|
||||||
var unpackedFields = BitTricks.UnpackBitFields(packedHack, PackedFormat);
|
var unpackedFields = packedHack.UnpackBitFields(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));
|
||||||
|
|
||||||
@@ -29,26 +32,17 @@ namespace Ryujinx.Common.Configuration
|
|||||||
|
|
||||||
public class DirtyHackCollection : Dictionary<DirtyHacks, int>
|
public class DirtyHackCollection : Dictionary<DirtyHacks, int>
|
||||||
{
|
{
|
||||||
public DirtyHackCollection(EnabledDirtyHack[] hacks)
|
public DirtyHackCollection(IEnumerable<EnabledDirtyHack> hacks)
|
||||||
{
|
=> hacks.ForEach(edh => Add(edh.Hack, edh.Value));
|
||||||
foreach ((DirtyHacks dirtyHacks, int value) in hacks)
|
|
||||||
{
|
|
||||||
Add(dirtyHacks, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirtyHackCollection(ulong[] packedHacks)
|
public DirtyHackCollection(ulong[] packedHacks) : this(packedHacks.Select(EnabledDirtyHack.Unpack)) {}
|
||||||
{
|
|
||||||
foreach ((DirtyHacks dirtyHacks, int value) in packedHacks.Select(EnabledDirtyHack.Unpack))
|
|
||||||
{
|
|
||||||
Add(dirtyHacks, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ulong[] PackEntries() =>
|
public ulong[] PackEntries()
|
||||||
this
|
=> Entries.Select(it => it.Pack()).ToArray();
|
||||||
.Select(it =>
|
|
||||||
BitTricks.PackBitFields([(uint)it.Key, (uint)it.Value], EnabledDirtyHack.PackedFormat))
|
public EnabledDirtyHack[] Entries
|
||||||
|
=> this
|
||||||
|
.Select(it => new EnabledDirtyHack(it.Key, it.Value))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
public static implicit operator DirtyHackCollection(EnabledDirtyHack[] hacks) => new(hacks);
|
public static implicit operator DirtyHackCollection(EnabledDirtyHack[] hacks) => new(hacks);
|
||||||
|
|||||||
@@ -40,5 +40,35 @@ 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,3 +1,4 @@
|
|||||||
|
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;
|
||||||
@@ -9,7 +10,6 @@ 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,14 +752,12 @@ namespace Ryujinx.Ava.Utilities.Configuration
|
|||||||
Hacks.ShowDirtyHacks.Value = configurationFileFormat.ShowDirtyHacks;
|
Hacks.ShowDirtyHacks.Value = configurationFileFormat.ShowDirtyHacks;
|
||||||
|
|
||||||
{
|
{
|
||||||
EnabledDirtyHack[] hacks = (configurationFileFormat.DirtyHacks ?? []).Select(EnabledDirtyHack.Unpack).ToArray();
|
DirtyHackCollection hacks = new (configurationFileFormat.DirtyHacks ?? []);
|
||||||
|
|
||||||
Hacks.Xc2MenuSoftlockFix.Value = hacks.Any(it => it.Hack == DirtyHacks.Xc2MenuSoftlockFix);
|
Hacks.Xc2MenuSoftlockFix.Value = hacks.IsEnabled(DirtyHacks.Xc2MenuSoftlockFix);
|
||||||
|
|
||||||
var shaderCompilationThreadSleep = hacks.FirstOrDefault(it =>
|
Hacks.EnableShaderTranslationDelay.Value = hacks.IsEnabled(DirtyHacks.ShaderCompilationThreadSleep);
|
||||||
it.Hack == DirtyHacks.ShaderCompilationThreadSleep);
|
Hacks.ShaderTranslationDelay.Value = hacks[DirtyHacks.ShaderCompilationThreadSleep].CoerceAtLeast(0);
|
||||||
Hacks.EnableShaderTranslationDelay.Value = shaderCompilationThreadSleep != null;
|
|
||||||
Hacks.ShaderTranslationDelay.Value = shaderCompilationThreadSleep?.Value ?? 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configurationFileUpdated)
|
if (configurationFileUpdated)
|
||||||
|
|||||||
Reference in New Issue
Block a user