Structural and Memory Safety Improvements, Analyzer Cleanup (ryubing/ryujinx!47)

See merge request ryubing/ryujinx!47
This commit is contained in:
MrKev 2025-06-11 17:58:27 -05:00 committed by LotP
parent d03ae9c164
commit ea027d65a7
309 changed files with 1018 additions and 1247 deletions

View file

@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Texture.Astc
{
[StructLayout(LayoutKind.Sequential)]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AstcPixel
{
internal const int StructSize = 12;

View file

@ -1,14 +1,12 @@
using Ryujinx.Common.Utilities;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Ryujinx.Graphics.Texture.Astc
{
public struct BitStream128
{
#pragma warning disable IDE0044 // Make field readonly
private Buffer16 _data;
#pragma warning restore IDE0044
public int BitsLeft { get; set; }
public BitStream128(Buffer16 data)
@ -27,13 +25,11 @@ namespace Ryujinx.Graphics.Texture.Astc
}
int mask = (1 << bitCount) - 1;
int value = _data.As<int>() & mask;
int value = Unsafe.As<Buffer16, int>(ref _data) & mask;
Span<ulong> span = _data.AsSpan<ulong>();
ulong carry = span[1] << (64 - bitCount);
span[0] = (span[0] >> bitCount) | carry;
span[1] >>= bitCount;
ulong carry = _data.High << (64 - bitCount);
_data.Low = (_data.Low >> bitCount) | carry;
_data.High >>= bitCount;
BitsLeft -= bitCount;
@ -51,23 +47,21 @@ namespace Ryujinx.Graphics.Texture.Astc
ulong maskedValue = (uint)(value & ((1 << bitCount) - 1));
Span<ulong> span = _data.AsSpan<ulong>();
if (BitsLeft < 64)
{
ulong lowMask = maskedValue << BitsLeft;
span[0] |= lowMask;
_data.Low |= lowMask;
}
if (BitsLeft + bitCount > 64)
{
if (BitsLeft > 64)
{
span[1] |= maskedValue << (BitsLeft - 64);
_data.High |= maskedValue << (BitsLeft - 64);
}
else
{
span[1] |= maskedValue >> (64 - BitsLeft);
_data.High |= maskedValue >> (64 - BitsLeft);
}
}