misc: chore: Use explicit types in GPU, Device, and Host1x projects

This commit is contained in:
Evan Husted 2025-01-25 14:05:44 -06:00
parent 5099548856
commit 1ae349efb1
55 changed files with 350 additions and 339 deletions

View file

@ -80,7 +80,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="cpuMemorySize">The amount of physical CPU Memory Avaiable on the device.</param>
public void Initialize(GpuContext context, ulong cpuMemorySize)
{
var cpuMemorySizeGiB = cpuMemorySize / GiB;
ulong cpuMemorySizeGiB = cpuMemorySize / GiB;
if (cpuMemorySizeGiB < 6 || context.Capabilities.MaximumGpuMemory == 0)
{
@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.Gpu.Image
MaxTextureSizeCapacity = TextureSizeCapacity12GiB;
}
var cacheMemory = (ulong)(context.Capabilities.MaximumGpuMemory * MemoryScaleFactor);
ulong cacheMemory = (ulong)(context.Capabilities.MaximumGpuMemory * MemoryScaleFactor);
_maxCacheMemoryUsage = Math.Clamp(cacheMemory, MinTextureSizeCapacity, MaxTextureSizeCapacity);
@ -232,7 +232,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>The texture if found, null otherwise</returns>
public Texture FindShortCache(in TextureDescriptor descriptor)
{
if (_shortCacheLookup.Count > 0 && _shortCacheLookup.TryGetValue(descriptor, out var entry))
if (_shortCacheLookup.Count > 0 && _shortCacheLookup.TryGetValue(descriptor, out ShortTextureCacheEntry entry))
{
if (entry.InvalidatedSequence == entry.Texture.InvalidatedSequence)
{
@ -277,7 +277,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="descriptor">Last used texture descriptor</param>
public void AddShortCache(Texture texture, ref TextureDescriptor descriptor)
{
var entry = new ShortTextureCacheEntry(descriptor, texture);
ShortTextureCacheEntry entry = new ShortTextureCacheEntry(descriptor, texture);
_shortCacheBuilder.Add(entry);
_shortCacheLookup.Add(entry.Descriptor, entry);
@ -296,7 +296,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
if (texture.ShortCacheEntry != null)
{
var entry = new ShortTextureCacheEntry(texture);
ShortTextureCacheEntry entry = new ShortTextureCacheEntry(texture);
_shortCacheBuilder.Add(entry);
@ -314,7 +314,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
HashSet<ShortTextureCacheEntry> toRemove = _shortCache;
foreach (var entry in toRemove)
foreach (ShortTextureCacheEntry entry in toRemove)
{
entry.Texture.DecrementReferenceCount();

View file

@ -704,7 +704,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>True if the format is valid, false otherwise</returns>
public static bool TryGetSingleComponentAttribFormat(uint encoded, out Format format, out int componentsCount)
{
bool result = _singleComponentAttribFormats.TryGetValue((VertexAttributeFormat)encoded, out var tuple);
bool result = _singleComponentAttribFormats.TryGetValue((VertexAttributeFormat)encoded, out (Format, int) tuple);
format = tuple.Item1;
componentsCount = tuple.Item2;

View file

@ -536,7 +536,7 @@ namespace Ryujinx.Graphics.Gpu.Image
// All views must be recreated against the new storage.
foreach (var view in _views)
foreach (Texture view in _views)
{
Logger.Debug?.Print(LogClass.Gpu, $" Recreating view {Info.Width}x{Info.Height} {Info.FormatInfo.Format}.");
view.ScaleFactor = scale;
@ -553,7 +553,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
ScaleMode = newScaleMode;
foreach (var view in _views)
foreach (Texture view in _views)
{
view.ScaleMode = newScaleMode;
}
@ -899,7 +899,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
using (result)
{
var converted = PixelConverter.ConvertR4G4ToR4G4B4A4(result.Span, width);
MemoryOwner<byte> converted = PixelConverter.ConvertR4G4ToR4G4B4A4(result.Span, width);
if (_context.Capabilities.SupportsR4G4B4A4Format)
{
@ -1650,7 +1650,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
lock (_poolOwners)
{
foreach (var owner in _poolOwners)
foreach (TexturePoolOwner owner in _poolOwners)
{
owner.Pool.ForceRemove(this, owner.ID, deferred);
}
@ -1680,7 +1680,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
ulong address = 0;
foreach (var owner in _poolOwners)
foreach (TexturePoolOwner owner in _poolOwners)
{
if (address == 0 || address == owner.GpuAddress)
{

View file

@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.Gpu.Image
// Any texture that has been unmapped at any point or is partially unmapped
// should update their pool references after the remap completes.
foreach (var texture in _partiallyMappedTextures)
foreach (Texture texture in _partiallyMappedTextures)
{
texture.UpdatePoolMappings();
}
@ -253,7 +253,7 @@ namespace Ryujinx.Graphics.Gpu.Image
for (int i = 0; i < overlapCount; i++)
{
var other = _textureOverlaps[i];
Texture other = _textureOverlaps[i];
if (texture != other &&
(texture.IsViewCompatible(other.Info, other.Range, true, other.LayerSize, _context.Capabilities, out _, out _) != TextureViewCompatibility.Incompatible ||
@ -486,7 +486,7 @@ namespace Ryujinx.Graphics.Gpu.Image
int layerSize = !isLinear ? colorState.LayerSize * 4 : 0;
var flags = TextureSearchFlags.WithUpscale;
TextureSearchFlags flags = TextureSearchFlags.WithUpscale;
if (discard)
{
@ -560,7 +560,7 @@ namespace Ryujinx.Graphics.Gpu.Image
target,
formatInfo);
var flags = TextureSearchFlags.WithUpscale;
TextureSearchFlags flags = TextureSearchFlags.WithUpscale;
if (discard)
{
@ -947,7 +947,7 @@ namespace Ryujinx.Graphics.Gpu.Image
bool hasLayerViews = false;
bool hasMipViews = false;
var incompatibleOverlaps = new List<TextureIncompatibleOverlap>();
List<TextureIncompatibleOverlap> incompatibleOverlaps = new List<TextureIncompatibleOverlap>();
for (int index = 0; index < overlapsCount; index++)
{

View file

@ -231,7 +231,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
bool flushed = false;
foreach (var overlap in _incompatibleOverlaps)
foreach (TextureIncompatibleOverlap overlap in _incompatibleOverlaps)
{
flushed |= overlap.Group.Storage.FlushModified(true);
}
@ -403,7 +403,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
if (_loadNeeded[baseHandle + i])
{
var info = GetHandleInformation(baseHandle + i);
(int BaseLayer, int BaseLevel, int Levels, int Layers, int Index) info = GetHandleInformation(baseHandle + i);
// Ensure the data for this handle is loaded in the span.
if (spanEndIndex <= i - 1)
@ -426,7 +426,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
var endInfo = spanEndIndex == i ? info : GetHandleInformation(baseHandle + spanEndIndex);
(int BaseLayer, int BaseLevel, int Levels, int Layers, int Index) endInfo = spanEndIndex == i ? info : GetHandleInformation(baseHandle + spanEndIndex);
spanBase = _allOffsets[info.Index];
int spanLast = _allOffsets[endInfo.Index + endInfo.Layers * endInfo.Levels - 1];
@ -479,7 +479,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>True if flushes should be tracked, false otherwise</returns>
private bool ShouldFlushTriggerTracking()
{
foreach (var overlap in _incompatibleOverlaps)
foreach (TextureIncompatibleOverlap overlap in _incompatibleOverlaps)
{
if (overlap.Group._flushIncompatibleOverlaps)
{
@ -637,7 +637,7 @@ namespace Ryujinx.Graphics.Gpu.Image
bool canImport = Storage.Info.IsLinear && Storage.Info.Stride >= Storage.Info.Width * Storage.Info.FormatInfo.BytesPerPixel;
var hostPointer = canImport ? _physicalMemory.GetHostPointer(Storage.Range) : 0;
IntPtr hostPointer = canImport ? _physicalMemory.GetHostPointer(Storage.Range) : 0;
if (hostPointer != 0 && _context.Renderer.PrepareHostMapping(hostPointer, Storage.Size))
{
@ -1019,7 +1019,7 @@ namespace Ryujinx.Graphics.Gpu.Image
int endOffset = _allOffsets[viewEnd] + _sliceSizes[lastLevel];
int size = endOffset - offset;
var result = new List<RegionHandle>();
List<RegionHandle> result = new List<RegionHandle>();
for (int i = 0; i < TextureRange.Count; i++)
{
@ -1053,7 +1053,7 @@ namespace Ryujinx.Graphics.Gpu.Image
offset = _allOffsets[viewStart];
ulong maxSize = Storage.Size - (ulong)offset;
var groupHandle = new TextureGroupHandle(
TextureGroupHandle groupHandle = new TextureGroupHandle(
this,
offset,
Math.Min(maxSize, (ulong)size),
@ -1160,17 +1160,17 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="relativeOffset">The offset of the old handles in relation to the new ones</param>
private void InheritHandles(TextureGroupHandle[] oldHandles, TextureGroupHandle[] handles, int relativeOffset)
{
foreach (var group in handles)
foreach (TextureGroupHandle group in handles)
{
foreach (var handle in group.Handles)
foreach (RegionHandle handle in group.Handles)
{
bool dirty = false;
foreach (var oldGroup in oldHandles)
foreach (TextureGroupHandle oldGroup in oldHandles)
{
if (group.OverlapsWith(oldGroup.Offset + relativeOffset, oldGroup.Size))
{
foreach (var oldHandle in oldGroup.Handles)
foreach (RegionHandle oldHandle in oldGroup.Handles)
{
if (handle.OverlapsWith(oldHandle.Address, oldHandle.Size))
{
@ -1194,7 +1194,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
foreach (var oldGroup in oldHandles)
foreach (TextureGroupHandle oldGroup in oldHandles)
{
oldGroup.Modified = false;
}
@ -1254,7 +1254,7 @@ namespace Ryujinx.Graphics.Gpu.Image
continue;
}
foreach (var oldGroup in _handles)
foreach (TextureGroupHandle oldGroup in _handles)
{
if (!groupHandle.OverlapsWith(oldGroup.Offset, oldGroup.Size))
{
@ -1265,7 +1265,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
bool hasMatch = false;
foreach (var oldHandle in oldGroup.Handles)
foreach (RegionHandle oldHandle in oldGroup.Handles)
{
if (oldHandle.RangeEquals(handle))
{
@ -1292,9 +1292,9 @@ namespace Ryujinx.Graphics.Gpu.Image
InheritHandles(_handles, handles, 0);
foreach (var oldGroup in _handles)
foreach (TextureGroupHandle oldGroup in _handles)
{
foreach (var oldHandle in oldGroup.Handles)
foreach (RegionHandle oldHandle in oldGroup.Handles)
{
oldHandle.Dispose();
}
@ -1320,12 +1320,12 @@ namespace Ryujinx.Graphics.Gpu.Image
else if (!(_hasMipViews || _hasLayerViews))
{
// Single dirty region.
var cpuRegionHandles = new RegionHandle[TextureRange.Count];
RegionHandle[] cpuRegionHandles = new RegionHandle[TextureRange.Count];
int count = 0;
for (int i = 0; i < TextureRange.Count; i++)
{
var currentRange = TextureRange.GetSubRange(i);
MemoryRange currentRange = TextureRange.GetSubRange(i);
if (currentRange.Address != MemoryManager.PteUnmapped)
{
cpuRegionHandles[count++] = GenerateHandle(currentRange.Address, currentRange.Size);
@ -1337,7 +1337,7 @@ namespace Ryujinx.Graphics.Gpu.Image
Array.Resize(ref cpuRegionHandles, count);
}
var groupHandle = new TextureGroupHandle(this, 0, Storage.Size, _views, 0, 0, 0, _allOffsets.Length, cpuRegionHandles);
TextureGroupHandle groupHandle = new TextureGroupHandle(this, 0, Storage.Size, _views, 0, 0, 0, _allOffsets.Length, cpuRegionHandles);
handles = new TextureGroupHandle[] { groupHandle };
}
@ -1355,7 +1355,7 @@ namespace Ryujinx.Graphics.Gpu.Image
if (_is3D)
{
var handlesList = new List<TextureGroupHandle>();
List<TextureGroupHandle> handlesList = new List<TextureGroupHandle>();
for (int i = 0; i < levelHandles; i++)
{
@ -1438,8 +1438,8 @@ namespace Ryujinx.Graphics.Gpu.Image
// Get the location of each texture within its storage, so we can find the handles to apply the dependency to.
// This can consist of multiple disjoint regions, for example if this is a mip slice of an array texture.
var targetRange = new List<(int BaseHandle, int RegionCount)>();
var otherRange = new List<(int BaseHandle, int RegionCount)>();
List<(int BaseHandle, int RegionCount)> targetRange = new List<(int BaseHandle, int RegionCount)>();
List<(int BaseHandle, int RegionCount)> otherRange = new List<(int BaseHandle, int RegionCount)>();
EvaluateRelevantHandles(firstLayer, firstLevel, other.Info.GetSlices(), other.Info.Levels, (baseHandle, regionCount, split) => targetRange.Add((baseHandle, regionCount)));
otherGroup.EvaluateRelevantHandles(other, (baseHandle, regionCount, split) => otherRange.Add((baseHandle, regionCount)));

View file

@ -118,7 +118,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>Texture with the requested format, or null if not found</returns>
public Texture Find(Format format)
{
foreach (var alias in _aliases)
foreach (Alias alias in _aliases)
{
if (alias.Format == format)
{
@ -134,7 +134,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
public void Destroy()
{
foreach (var entry in _aliases)
foreach (Alias entry in _aliases)
{
entry.Texture.DecrementReferenceCount();
}
@ -361,7 +361,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="deferred">If true, queue the dereference to happen on the render thread, otherwise dereference immediately</param>
public void ForceRemove(Texture texture, int id, bool deferred)
{
var previous = Interlocked.Exchange(ref Items[id], null);
Texture previous = Interlocked.Exchange(ref Items[id], null);
if (deferred)
{