From 7f27b791f821f892f89abdda74bc2da1ad60b71e Mon Sep 17 00:00:00 2001 From: Jacobwasbeast Date: Fri, 7 Feb 2025 04:16:27 -0600 Subject: [PATCH] Refactor Share Buffer Implementation to Follow Code Style Guidelines --- .../Engine/Compute/ComputeClass.cs | 4 +- .../Engine/Dma/DmaClass.cs | 6 +- .../InlineToMemory/InlineToMemoryClass.cs | 2 +- .../Engine/MME/MacroHLE.cs | 4 +- .../Threed/ComputeDraw/VtgAsComputeContext.cs | 4 +- .../Threed/ComputeDraw/VtgAsComputeState.cs | 8 +-- .../Engine/Threed/ConstantBufferUpdater.cs | 2 +- .../Engine/Threed/StateUpdater.cs | 8 +-- .../Engine/Twod/TwodClass.cs | 4 +- src/Ryujinx.Graphics.Gpu/GpuChannel.cs | 2 +- src/Ryujinx.Graphics.Gpu/Image/PoolCache.cs | 3 +- .../Image/SamplerPoolCache.cs | 1 + .../Image/TextureBindingsArrayCache.cs | 2 +- .../Image/TextureBindingsManager.cs | 14 ++--- .../Image/TextureManager.cs | 3 +- src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs | 16 +++--- .../Memory/BufferCache.cs | 12 ++-- .../Memory/BufferManager.cs | 56 +++++++++---------- .../Memory/MemoryManager.cs | 2 +- .../Shader/GpuAccessor.cs | 3 +- .../Shader/ShaderCache.cs | 4 +- src/Ryujinx.HLE/HOS/Services/Vi/ViServer.cs | 19 ++++--- 22 files changed, 92 insertions(+), 87 deletions(-) diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs b/src/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs index ed8e8a916..f1df333b7 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs @@ -107,7 +107,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute shaderGpuVa += (uint)qmd.ProgramOffset; - var shaderCache = memoryManager.GetBackingMemory(shaderGpuVa).ShaderCache; + ShaderCache shaderCache = memoryManager.GetBackingMemory(shaderGpuVa).ShaderCache; int localMemorySize = qmd.ShaderLocalMemoryLowSize + qmd.ShaderLocalMemoryHighSize; @@ -158,7 +158,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute { BufferDescriptor sb = info.SBuffers[index]; - (var physical, ulong sbDescAddress) = _channel.BufferManager.GetComputeUniformBufferAddress(sb.SbCbSlot); + (PhysicalMemory physical, ulong sbDescAddress) = _channel.BufferManager.GetComputeUniformBufferAddress(sb.SbCbSlot); sbDescAddress += (ulong)sb.SbCbOffset * 4; SbDescriptor sbDescriptor = physical.Read(sbDescAddress); diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Dma/DmaClass.cs b/src/Ryujinx.Graphics.Gpu/Engine/Dma/DmaClass.cs index 949bfaaa6..031ff0d12 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Dma/DmaClass.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Dma/DmaClass.cs @@ -216,8 +216,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma _3dEngine.CreatePendingSyncs(); _3dEngine.FlushUboDirty(); - var srcPhysical = memoryManager.GetBackingMemory(srcGpuVa); - var dstPhysical = memoryManager.GetBackingMemory(dstGpuVa); + PhysicalMemory srcPhysical = memoryManager.GetBackingMemory(srcGpuVa); + PhysicalMemory dstPhysical = memoryManager.GetBackingMemory(dstGpuVa); if (copy2D) { @@ -465,7 +465,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma } else { - var bufferCache = dstPhysical.BufferCache; + BufferCache bufferCache = dstPhysical.BufferCache; if (remap && _state.State.SetRemapComponentsDstX == SetRemapComponentsDst.ConstA && _state.State.SetRemapComponentsDstY == SetRemapComponentsDst.ConstA && diff --git a/src/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs b/src/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs index 08c199906..1e6224f2d 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs @@ -185,7 +185,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory // Right now the copy code at the bottom assumes that it is used on both which might be incorrect. if (!_isLinear) { - var target = memoryManager.GetBackingMemory(_dstGpuVa).TextureCache.FindTexture( + Image.Texture target = memoryManager.GetBackingMemory(_dstGpuVa).TextureCache.FindTexture( memoryManager, _dstGpuVa, 1, diff --git a/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLE.cs b/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLE.cs index adafaf4db..444b5a0ac 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLE.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLE.cs @@ -493,8 +493,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME } } } - var indirectBufferCache = _processor.MemoryManager.GetBackingMemory(indirectBufferGpuVa).BufferCache; - var parameterBufferCache = _processor.MemoryManager.GetBackingMemory(parameterBufferGpuVa).BufferCache; + BufferCache indirectBufferCache = _processor.MemoryManager.GetBackingMemory(indirectBufferGpuVa).BufferCache; + BufferCache parameterBufferCache = _processor.MemoryManager.GetBackingMemory(parameterBufferGpuVa).BufferCache; ulong indirectBufferSize = (ulong)maxDrawCount * (ulong)stride; diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeContext.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeContext.cs index 6de50fb2e..eba1b6030 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeContext.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeContext.cs @@ -67,7 +67,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw { if (disposing) { - foreach (var texture in _cache.Values) + foreach (ITexture texture in _cache.Values) { texture.Release(); } @@ -620,7 +620,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw DestroyIfNotNull(ref _geometryIndexDataBuffer.Handle); DestroyIfNotNull(ref _sequentialIndexBuffer); - foreach (var indexBuffer in _topologyRemapBuffers.Values) + foreach (IndexBuffer indexBuffer in _topologyRemapBuffers.Values) { _context.Renderer.DeleteBuffer(indexBuffer.Handle); } diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeState.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeState.cs index 8903f38f2..9363290ca 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeState.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/ComputeDraw/VtgAsComputeState.cs @@ -127,7 +127,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw for (int index = 0; index < Constants.TotalVertexAttribs; index++) { - var vertexAttrib = _state.State.VertexAttribState[index]; + VertexAttribState vertexAttrib = _state.State.VertexAttribState[index]; if (!FormatTable.TryGetSingleComponentAttribFormat(vertexAttrib.UnpackFormat(), out Format format, out int componentsCount)) { @@ -154,7 +154,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw int bufferIndex = vertexAttrib.UnpackBufferIndex(); GpuVa endAddress = _state.State.VertexBufferEndAddress[bufferIndex]; - var vertexBuffer = _state.State.VertexBufferState[bufferIndex]; + VertexBufferState vertexBuffer = _state.State.VertexBufferState[bufferIndex]; bool instanced = _state.State.VertexBufferInstanced[bufferIndex]; ulong address = vertexBuffer.Address.Pack(); @@ -369,7 +369,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw /// Size of the buffer in bytes private readonly void SetBufferTexture(ResourceReservations reservations, int index, Format format, ulong address, ulong size) { - var memoryManager = _channel.MemoryManager; + MemoryManager memoryManager = _channel.MemoryManager; BufferRange range = memoryManager.GetBackingMemory(address).BufferCache.GetBufferRange(memoryManager.GetPhysicalRegions(address, size), BufferStage.VertexBuffer); @@ -410,7 +410,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw indexOffset <<= shift; size <<= shift; - var memoryManager = _channel.MemoryManager; + MemoryManager memoryManager = _channel.MemoryManager; ulong misalign = address & ((ulong)_context.Capabilities.TextureBufferOffsetAlignment - 1); BufferRange range = memoryManager.GetBackingMemory(address).BufferCache.GetBufferRange( diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/ConstantBufferUpdater.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/ConstantBufferUpdater.cs index 38baa3488..30369dcb7 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/ConstantBufferUpdater.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/ConstantBufferUpdater.cs @@ -114,7 +114,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed if (_ubFollowUpAddress != 0) { MemoryManager memoryManager = _channel.MemoryManager; - var physicalMemory = memoryManager.GetBackingMemory(_ubBeginGpuAddress); + PhysicalMemory physicalMemory = memoryManager.GetBackingMemory(_ubBeginGpuAddress); Span data = MemoryMarshal.Cast(_ubData.AsSpan(0, (int)(_ubByteCount / 4))); diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index f58f90396..c9b9e3b28 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -381,7 +381,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed { BufferDescriptor sb = info.SBuffers[index]; - (var physical, ulong sbDescAddress) = _channel.BufferManager.GetGraphicsUniformBufferAddress(stage, sb.SbCbSlot); + (PhysicalMemory physical, ulong sbDescAddress) = _channel.BufferManager.GetGraphicsUniformBufferAddress(stage, sb.SbCbSlot); sbDescAddress += (ulong)sb.SbCbOffset * 4; SbDescriptor sbDescriptor = physical.Read(sbDescAddress); @@ -505,7 +505,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed rtNoAlphaMask |= 1u << index; } - var colorTextureCache = memoryManager.GetBackingMemory(colorState.Address.Pack()).TextureCache; + TextureCache colorTextureCache = memoryManager.GetBackingMemory(colorState.Address.Pack()).TextureCache; Image.Texture color = colorTextureCache.FindOrCreateTexture( memoryManager, @@ -545,7 +545,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed { RtDepthStencilState dsState = _state.State.RtDepthStencilState; Size3D dsSize = _state.State.RtDepthStencilSize; - var dsTextureCache = memoryManager.GetBackingMemory(dsState.Address.Pack()).TextureCache; + TextureCache dsTextureCache = memoryManager.GetBackingMemory(dsState.Address.Pack()).TextureCache; depthStencil = dsTextureCache.FindOrCreateTexture( memoryManager, @@ -1436,7 +1436,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed // Shader stages on different address spaces are not supported right now, // but it should never happen in practice anyway. - var shaderCache = _channel.MemoryManager.GetBackingMemory(addresses.VertexB).ShaderCache; + ShaderCache shaderCache = _channel.MemoryManager.GetBackingMemory(addresses.VertexB).ShaderCache; CachedShaderProgram gs = shaderCache.GetGraphicsShader( ref _state.State, ref _pipeline, diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Twod/TwodClass.cs b/src/Ryujinx.Graphics.Gpu/Engine/Twod/TwodClass.cs index f8157501f..cba3ac854 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Twod/TwodClass.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Twod/TwodClass.cs @@ -234,8 +234,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod TwodTexture dstCopyTexture = Unsafe.As(ref _state.State.SetDstFormat); TwodTexture srcCopyTexture = Unsafe.As(ref _state.State.SetSrcFormat); - var srcTextureCache = memoryManager.GetBackingMemory(srcCopyTexture.Address.Pack()).TextureCache; - var dstTextureCache = memoryManager.GetBackingMemory(dstCopyTexture.Address.Pack()).TextureCache; + TextureCache srcTextureCache = memoryManager.GetBackingMemory(srcCopyTexture.Address.Pack()).TextureCache; + TextureCache dstTextureCache = memoryManager.GetBackingMemory(dstCopyTexture.Address.Pack()).TextureCache; long srcX = ((long)_state.State.SetPixelsFromMemorySrcX0Int << 32) | (long)(ulong)_state.State.SetPixelsFromMemorySrcX0Frac; long srcY = ((long)_state.State.PixelsFromMemorySrcY0Int << 32) | (long)(ulong)_state.State.SetPixelsFromMemorySrcY0Frac; diff --git a/src/Ryujinx.Graphics.Gpu/GpuChannel.cs b/src/Ryujinx.Graphics.Gpu/GpuChannel.cs index a4355d371..e8f5dd720 100644 --- a/src/Ryujinx.Graphics.Gpu/GpuChannel.cs +++ b/src/Ryujinx.Graphics.Gpu/GpuChannel.cs @@ -140,7 +140,7 @@ namespace Ryujinx.Graphics.Gpu _processor.Dispose(); TextureManager.Dispose(); - var oldMemoryManager = Interlocked.Exchange(ref _memoryManager, null); + MemoryManager oldMemoryManager = Interlocked.Exchange(ref _memoryManager, null); if (oldMemoryManager != null) { oldMemoryManager.DetachFromChannel(BufferManager.Rebind); diff --git a/src/Ryujinx.Graphics.Gpu/Image/PoolCache.cs b/src/Ryujinx.Graphics.Gpu/Image/PoolCache.cs index 2b5404b60..0cbbcb958 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/PoolCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/PoolCache.cs @@ -113,9 +113,10 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// GPU context that the pool belongs to /// GPU channel that the pool belongs to + /// GPU backing memory of the pool /// Address of the pool in guest memory /// Maximum ID of the pool (equal to maximum minus one) - protected abstract T CreatePool(GpuContext context, GpuChannel channel, PhysicalMemory physical, ulong address, int maximumId); + protected abstract T CreatePool(GpuContext context, GpuChannel channel, PhysicalMemory physicalMemory, ulong address, int maximumId); public void Dispose() { diff --git a/src/Ryujinx.Graphics.Gpu/Image/SamplerPoolCache.cs b/src/Ryujinx.Graphics.Gpu/Image/SamplerPoolCache.cs index 9d6e4cfda..7d8e0ba55 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/SamplerPoolCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/SamplerPoolCache.cs @@ -22,6 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// GPU context that the sampler pool belongs to /// GPU channel that the texture pool belongs to + /// GPU backing memory of the pool /// Address of the sampler pool in guest memory /// Maximum sampler ID of the sampler pool (equal to maximum samplers minus one) protected override SamplerPool CreatePool(GpuContext context, GpuChannel channel, PhysicalMemory physicalMemory, ulong address, int maximumId) diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs index 824ad50c5..f6f44e880 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs @@ -900,7 +900,7 @@ namespace Ryujinx.Graphics.Gpu.Image if (hostTexture != null && texture.Target == Target.TextureBuffer) { - var bufferCache = textureBufferBounds.BufferCache; + BufferCache bufferCache = textureBufferBounds.BufferCache; // Ensure that the buffer texture is using the correct buffer as storage. // Buffers are frequently re-created to accommodate larger data, so we need to re-bind diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs index c6c7763c3..ae4c9a3f8 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs @@ -524,7 +524,7 @@ namespace Ryujinx.Graphics.Gpu.Image // Ensure that the buffer texture is using the correct buffer as storage. // Buffers are frequently re-created to accommodate larger data, so we need to re-bind // to ensure we're not using a old buffer that was already deleted. - var bufferCache = _channel.MemoryManager.GetBackingMemory(descriptor.UnpackAddress()).BufferCache; + BufferCache bufferCache = _channel.MemoryManager.GetBackingMemory(descriptor.UnpackAddress()).BufferCache; _channel.BufferManager.SetBufferTextureStorage(stage, hostTexture, bufferCache, texture.Range, bindingInfo, false); // Cache is not used for buffer texture, it must always rebind. @@ -660,7 +660,7 @@ namespace Ryujinx.Graphics.Gpu.Image // Buffers are frequently re-created to accommodate larger data, so we need to re-bind // to ensure we're not using a old buffer that was already deleted. - var bufferCache = _channel.MemoryManager.GetBackingMemory(descriptor.UnpackAddress()).BufferCache; + BufferCache bufferCache = _channel.MemoryManager.GetBackingMemory(descriptor.UnpackAddress()).BufferCache; _channel.BufferManager.SetBufferTextureStorage(stage, hostTexture, bufferCache, texture.Range, bindingInfo, true); // Cache is not used for buffer texture, it must always rebind. @@ -717,7 +717,7 @@ namespace Ryujinx.Graphics.Gpu.Image int packedId = ReadPackedId(stageIndex, handle, textureBufferIndex, samplerBufferIndex); int textureId = TextureHandle.UnpackTextureId(packedId); - var physical = _channel.MemoryManager.GetBackingMemory(poolGpuVa); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(poolGpuVa); ulong poolAddress = _channel.MemoryManager.Translate(poolGpuVa); TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, physical, poolAddress, maximumId, _bindingsArrayCache); @@ -754,7 +754,7 @@ namespace Ryujinx.Graphics.Gpu.Image { (int textureWordOffset, int samplerWordOffset, TextureHandleType handleType) = TextureHandle.UnpackOffsets(wordOffset); - (var texturePhysicalMemory, ulong textureBufferAddress) = _isCompute + (PhysicalMemory texturePhysicalMemory, ulong textureBufferAddress) = _isCompute ? _channel.BufferManager.GetComputeUniformBufferAddress(textureBufferIndex) : _channel.BufferManager.GetGraphicsUniformBufferAddress(stageIndex, textureBufferIndex); @@ -774,7 +774,7 @@ namespace Ryujinx.Graphics.Gpu.Image if (handleType != TextureHandleType.SeparateConstantSamplerHandle) { - (var samplerPhysicalMemory, ulong samplerBufferAddress) = _isCompute + (PhysicalMemory samplerPhysicalMemory, ulong samplerBufferAddress) = _isCompute ? _channel.BufferManager.GetComputeUniformBufferAddress(samplerBufferIndex) : _channel.BufferManager.GetGraphicsUniformBufferAddress(stageIndex, samplerBufferIndex); @@ -816,7 +816,7 @@ namespace Ryujinx.Graphics.Gpu.Image if (poolAddress != MemoryManager.PteUnmapped) { - var physical = _channel.MemoryManager.GetBackingMemory(_texturePoolGpuVa); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(_texturePoolGpuVa); texturePool = _texturePoolCache.FindOrCreate(_channel, physical, poolAddress, _texturePoolMaximumId, _bindingsArrayCache); _texturePool = texturePool; } @@ -828,7 +828,7 @@ namespace Ryujinx.Graphics.Gpu.Image if (poolAddress != MemoryManager.PteUnmapped) { - var physical = _channel.MemoryManager.GetBackingMemory(_samplerPoolGpuVa); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(_samplerPoolGpuVa); samplerPool = _samplerPoolCache.FindOrCreate(_channel, physical, poolAddress, _samplerPoolMaximumId, _bindingsArrayCache); _samplerPool = samplerPool; } diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index 84cd4487d..65e243c1f 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -1,5 +1,6 @@ using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Gpu.Engine.Types; +using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Gpu.Shader; using System; @@ -385,7 +386,7 @@ namespace Ryujinx.Graphics.Gpu.Image public TexturePool GetTexturePool(ulong poolGpuVa, int maximumId) { ulong poolAddress = _channel.MemoryManager.Translate(poolGpuVa); - var physical = _channel.MemoryManager.GetBackingMemory(poolAddress); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(poolAddress); TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, physical, poolAddress, maximumId, _bindingsArrayCache); diff --git a/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs b/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs index 42912a6e8..9854ea531 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs @@ -193,9 +193,9 @@ namespace Ryujinx.Graphics.Gpu.Image return ref descriptor; } - var info = GetInfo(descriptor, out int layerSize); - var memoryManager = _channel.MemoryManager; - var textureCache = memoryManager.GetBackingMemory(descriptor.UnpackAddress()).TextureCache; + TextureInfo info = GetInfo(descriptor, out int layerSize); + MemoryManager memoryManager = _channel.MemoryManager; + TextureCache textureCache = memoryManager.GetBackingMemory(descriptor.UnpackAddress()).TextureCache; texture = textureCache.FindOrCreateTexture(memoryManager, TextureSearchFlags.ForSampler, info, layerSize); // If this happens, then the texture address is invalid, we can't add it to the cache. @@ -364,7 +364,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// If true, queue the dereference to happen on the render thread, otherwise dereference immediately public void ForceRemove(Texture texture, int id, bool deferred) { - Texture previous = Interlocked.Exchange(ref Items[id], null); + Texture previous = Interlocked.Exchange(ref Items[id], null); if (deferred) { @@ -424,8 +424,8 @@ namespace Ryujinx.Graphics.Gpu.Image continue; } - var textureCache = _channel.MemoryManager.GetBackingMemory(address).TextureCache; - var range = textureCache.UpdatePartiallyMapped(_channel.MemoryManager, address, texture); + TextureCache textureCache = _channel.MemoryManager.GetBackingMemory(address).TextureCache; + MultiRange range = textureCache.UpdatePartiallyMapped(_channel.MemoryManager, address, texture); // If the texture is not mapped at all, delete its reference. @@ -485,7 +485,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// Size of the range being invalidated protected override void InvalidateRangeImpl(ulong address, ulong size) { - var memoryManager = _channel.MemoryManager; + MemoryManager memoryManager = _channel.MemoryManager; ProcessDereferenceQueue(); ulong endAddress = address + size; @@ -510,7 +510,7 @@ namespace Ryujinx.Graphics.Gpu.Image if (texture.HasOneReference()) { - var textureCache = memoryManager.GetBackingMemory(descriptor.UnpackAddress()).TextureCache; + TextureCache textureCache = memoryManager.GetBackingMemory(descriptor.UnpackAddress()).TextureCache; textureCache.AddShortCache(texture, ref cachedDescriptor); } diff --git a/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs b/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs index 9d1323461..20e634a75 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs @@ -742,11 +742,11 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Size in bytes of the copy public static void CopyBuffer(GpuContext context, MemoryManager memoryManager, ulong srcVa, ulong dstVa, ulong size) { - var srcPhysical = memoryManager.GetBackingMemory(srcVa); - var dstPhysical = memoryManager.GetBackingMemory(dstVa); + PhysicalMemory srcPhysical = memoryManager.GetBackingMemory(srcVa); + PhysicalMemory dstPhysical = memoryManager.GetBackingMemory(dstVa); - var srcRange = srcPhysical.BufferCache.TranslateAndCreateBuffer(memoryManager, srcVa, size, BufferStage.Copy); - var dstRange = dstPhysical.BufferCache.TranslateAndCreateBuffer(memoryManager, dstVa, size, BufferStage.Copy); + MultiRange srcRange = srcPhysical.BufferCache.TranslateAndCreateBuffer(memoryManager, srcVa, size, BufferStage.Copy); + MultiRange dstRange = dstPhysical.BufferCache.TranslateAndCreateBuffer(memoryManager, dstVa, size, BufferStage.Copy); if (srcRange.Count == 1 && dstRange.Count == 1) { @@ -810,8 +810,8 @@ namespace Ryujinx.Graphics.Gpu.Memory ulong dstAddress, ulong size) { - var srcBuffer = srcPhysical.BufferCache.GetBuffer(srcAddress, size, BufferStage.Copy); - var dstBuffer = dstPhysical.BufferCache.GetBuffer(dstAddress, size, BufferStage.Copy); + Buffer srcBuffer = srcPhysical.BufferCache.GetBuffer(srcAddress, size, BufferStage.Copy); + Buffer dstBuffer = dstPhysical.BufferCache.GetBuffer(dstAddress, size, BufferStage.Copy); int srcOffset = (int)(srcAddress - srcBuffer.Address); int dstOffset = (int)(dstAddress - dstBuffer.Address); diff --git a/src/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs b/src/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs index a837708b7..48e10800b 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs @@ -157,7 +157,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Type of each index buffer element public void SetIndexBuffer(ulong gpuVa, ulong size, IndexType type) { - var bufferCache = _channel.MemoryManager.GetBackingMemory(gpuVa).BufferCache; + BufferCache bufferCache = _channel.MemoryManager.GetBackingMemory(gpuVa).BufferCache; MultiRange range = bufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size, BufferStage.IndexBuffer); _indexBuffer.BufferCache = bufferCache; @@ -189,7 +189,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Vertex divisor of the buffer, for instanced draws public void SetVertexBuffer(int index, ulong gpuVa, ulong size, int stride, int divisor) { - var bufferCache = _channel.MemoryManager.GetBackingMemory(gpuVa).BufferCache; + BufferCache bufferCache = _channel.MemoryManager.GetBackingMemory(gpuVa).BufferCache; MultiRange range = bufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size, BufferStage.VertexBuffer); ref VertexBuffer vb = ref _vertexBuffers[index]; @@ -220,8 +220,8 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Size in bytes of the transform feedback buffer public void SetTransformFeedbackBuffer(int index, ulong gpuVa, ulong size) { - var physical = _channel.MemoryManager.GetBackingMemory(gpuVa); - var range = physical.BufferCache.TranslateAndCreateMultiBuffers(_channel.MemoryManager, gpuVa, size, BufferStage.TransformFeedback); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(gpuVa); + MultiRange range = physical.BufferCache.TranslateAndCreateMultiBuffers(_channel.MemoryManager, gpuVa, size, BufferStage.TransformFeedback); _transformFeedbackBuffers[index] = new BufferBounds(physical, range); _transformFeedbackBuffersDirty = true; @@ -268,8 +268,8 @@ namespace Ryujinx.Graphics.Gpu.Memory gpuVa = BitUtils.AlignDown(gpuVa, (ulong)_context.Capabilities.StorageBufferOffsetAlignment); - var physical = _channel.MemoryManager.GetBackingMemory(gpuVa); - var range = physical.BufferCache.TranslateAndCreateMultiBuffers(_channel.MemoryManager, gpuVa, size, BufferStageUtils.ComputeStorage(flags)); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(gpuVa); + MultiRange range = physical.BufferCache.TranslateAndCreateMultiBuffers(_channel.MemoryManager, gpuVa, size, BufferStageUtils.ComputeStorage(flags)); _cpStorageBuffers.SetBounds(index, physical, range, flags); } @@ -293,7 +293,7 @@ namespace Ryujinx.Graphics.Gpu.Memory gpuVa = BitUtils.AlignDown(gpuVa, (ulong)_context.Capabilities.StorageBufferOffsetAlignment); - var physical = _channel.MemoryManager.GetBackingMemory(gpuVa); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(gpuVa); MultiRange range = physical.BufferCache.TranslateAndCreateMultiBuffers(_channel.MemoryManager, gpuVa, size, BufferStageUtils.GraphicsStorage(stage, flags)); if (!buffers.Buffers[index].Range.Equals(range)) @@ -313,7 +313,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Size in bytes of the storage buffer public void SetComputeUniformBuffer(int index, ulong gpuVa, ulong size) { - var physical = _channel.MemoryManager.GetBackingMemory(gpuVa); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(gpuVa); MultiRange range = physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size, BufferStage.Compute); _cpUniformBuffers.SetBounds(index, physical, range); @@ -329,7 +329,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Size in bytes of the storage buffer public void SetGraphicsUniformBuffer(int stage, int index, ulong gpuVa, ulong size) { - var physical = _channel.MemoryManager.GetBackingMemory(gpuVa); + PhysicalMemory physical = _channel.MemoryManager.GetBackingMemory(gpuVa); MultiRange range = _channel.MemoryManager.GetBackingMemory(gpuVa).BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size, BufferStageUtils.FromShaderStage(stage)); _gpUniformBuffers[stage].SetBounds(index, physical, range); @@ -430,7 +430,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// The uniform buffer address, or an undefined value if the buffer is not currently bound public (PhysicalMemory, ulong) GetComputeUniformBufferAddress(int index) { - ref var buffer = ref _cpUniformBuffers.Buffers[index]; + ref BufferBounds buffer = ref _cpUniformBuffers.Buffers[index]; return (buffer.Physical, buffer.Range.GetSubRange(0).Address); } @@ -452,7 +452,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// The uniform buffer address, or an undefined value if the buffer is not currently bound public (PhysicalMemory, ulong) GetGraphicsUniformBufferAddress(int stage, int index) { - ref var buffer = ref _gpUniformBuffers[stage].Buffers[index]; + ref BufferBounds buffer = ref _gpUniformBuffers[stage].Buffers[index]; return (buffer.Physical, buffer.Range.GetSubRange(0).Address); } @@ -511,10 +511,10 @@ namespace Ryujinx.Graphics.Gpu.Memory { if (_bufferTextures.Count > 0) { - foreach (var binding in _bufferTextures) + foreach (BufferTextureBinding binding in _bufferTextures) { - var isStore = binding.BindingInfo.Flags.HasFlag(TextureUsageFlags.ImageStore); - var range = binding.BufferCache.GetBufferRange(binding.Range, BufferStageUtils.TextureBuffer(binding.Stage, binding.BindingInfo.Flags), isStore); + bool isStore = binding.BindingInfo.Flags.HasFlag(TextureUsageFlags.ImageStore); + BufferRange range = binding.BufferCache.GetBufferRange(binding.Range, BufferStageUtils.TextureBuffer(binding.Stage, binding.BindingInfo.Flags), isStore); binding.Texture.SetStorage(range); // The texture must be rebound to use the new storage if it was updated. @@ -536,19 +536,19 @@ namespace Ryujinx.Graphics.Gpu.Memory { ITexture[] textureArray = new ITexture[1]; - foreach (var binding in _bufferTextureArrays) + foreach (BufferTextureArrayBinding binding in _bufferTextureArrays) { - var range = binding.BufferCache.GetBufferRange(binding.Range, BufferStage.None); + BufferRange range = binding.BufferCache.GetBufferRange(binding.Range, BufferStage.None); binding.Texture.SetStorage(range); textureArray[0] = binding.Texture; binding.Array.SetTextures(binding.Index, textureArray); } - foreach (var binding in _bufferImageArrays) + foreach (BufferTextureArrayBinding binding in _bufferImageArrays) { - var isStore = binding.BindingInfo.Flags.HasFlag(TextureUsageFlags.ImageStore); - var range = binding.BufferCache.GetBufferRange(binding.Range, BufferStage.None, isStore); + bool isStore = binding.BindingInfo.Flags.HasFlag(TextureUsageFlags.ImageStore); + BufferRange range = binding.BufferCache.GetBufferRange(binding.Range, BufferStage.None, isStore); binding.Texture.SetStorage(range); textureArray[0] = binding.Texture; @@ -760,19 +760,19 @@ namespace Ryujinx.Graphics.Gpu.Memory for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++) { - ref var buffers = ref bindings[(int)stage - 1]; + ref BuffersPerStage buffers = ref bindings[(int)stage - 1]; BufferStage bufferStage = BufferStageUtils.FromShaderStage(stage); for (int index = 0; index < buffers.Count; index++) { - ref var bindingInfo = ref buffers.Bindings[index]; + ref BufferDescriptor bindingInfo = ref buffers.Bindings[index]; BufferBounds bounds = buffers.Buffers[bindingInfo.Slot]; if (!bounds.IsUnmapped) { - var isWrite = bounds.Flags.HasFlag(BufferUsageFlags.Write); - var range = isStorage + bool isWrite = bounds.Flags.HasFlag(BufferUsageFlags.Write); + BufferRange range = isStorage ? bounds.BufferCache.GetBufferRangeAligned(bounds.Range, bufferStage | BufferStageUtils.FromUsage(bounds.Flags), isWrite) : bounds.BufferCache.GetBufferRange(bounds.Range, bufferStage); @@ -801,14 +801,14 @@ namespace Ryujinx.Graphics.Gpu.Memory for (int index = 0; index < buffers.Count; index++) { - ref var bindingInfo = ref buffers.Bindings[index]; + ref BufferDescriptor bindingInfo = ref buffers.Bindings[index]; BufferBounds bounds = buffers.Buffers[bindingInfo.Slot]; if (!bounds.IsUnmapped) { - var isWrite = bounds.Flags.HasFlag(BufferUsageFlags.Write); - var range = isStorage + bool isWrite = bounds.Flags.HasFlag(BufferUsageFlags.Write); + BufferRange range = isStorage ? bounds.BufferCache.GetBufferRangeAligned(bounds.Range, BufferStageUtils.ComputeStorage(bounds.Flags), isWrite) : bounds.BufferCache.GetBufferRange(bounds.Range, BufferStage.Compute); @@ -850,11 +850,11 @@ namespace Ryujinx.Graphics.Gpu.Memory { for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++) { - ref var buffers = ref bindings[(int)stage - 1]; + ref BuffersPerStage buffers = ref bindings[(int)stage - 1]; for (int index = 0; index < buffers.Count; index++) { - ref var binding = ref buffers.Bindings[index]; + ref BufferDescriptor binding = ref buffers.Bindings[index]; BufferBounds bounds = buffers.Buffers[binding.Slot]; diff --git a/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index c5d10f12f..cfbeb503e 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -611,7 +611,7 @@ namespace Ryujinx.Graphics.Gpu.Memory int pages = (int)((endVaRounded - va) / PageSize); - var regions = new List(); + List regions = new(); for (int page = 0; page < pages - 1; page++) { diff --git a/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs b/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs index f32a271a3..2f1563032 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs @@ -1,5 +1,6 @@ using Ryujinx.Common.Logging; using Ryujinx.Graphics.Gpu.Image; +using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Shader; using Ryujinx.Graphics.Shader.Translation; using System; @@ -66,7 +67,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// public uint ConstantBuffer1Read(int offset) { - (var physical, ulong baseAddress) = _compute + (PhysicalMemory physical, ulong baseAddress) = _compute ? _channel.BufferManager.GetComputeUniformBufferAddress(1) : _channel.BufferManager.GetGraphicsUniformBufferAddress(_stageIndex, 1); diff --git a/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 1516280ee..0285d5517 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -733,7 +733,7 @@ namespace Ryujinx.Graphics.Gpu.Shader byte[] codeB, bool asCompute) { - (var physical, ulong cb1DataAddress) = channel.BufferManager.GetGraphicsUniformBufferAddress(0, 1); + (PhysicalMemory physical, ulong cb1DataAddress) = channel.BufferManager.GetGraphicsUniformBufferAddress(0, 1); MemoryManager memoryManager = channel.MemoryManager; @@ -775,7 +775,7 @@ namespace Ryujinx.Graphics.Gpu.Shader { MemoryManager memoryManager = channel.MemoryManager; - (var physical, ulong cb1DataAddress) = context.Stage == ShaderStage.Compute + (PhysicalMemory physical, ulong cb1DataAddress) = context.Stage == ShaderStage.Compute ? channel.BufferManager.GetComputeUniformBufferAddress(1) : channel.BufferManager.GetGraphicsUniformBufferAddress(StageToStageIndex(context.Stage), 1); diff --git a/src/Ryujinx.HLE/HOS/Services/Vi/ViServer.cs b/src/Ryujinx.HLE/HOS/Services/Vi/ViServer.cs index 6de3972a0..416f72458 100644 --- a/src/Ryujinx.HLE/HOS/Services/Vi/ViServer.cs +++ b/src/Ryujinx.HLE/HOS/Services/Vi/ViServer.cs @@ -5,6 +5,7 @@ using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap; using Ryujinx.HLE.HOS.Services.SurfaceFlinger; using Ryujinx.HLE.HOS.Services.SurfaceFlinger.Types; using Ryujinx.HLE.HOS.Services.Vi.Types; +using Ryujinx.Memory; using System.Runtime.CompilerServices; namespace Ryujinx.HLE.HOS.Services @@ -87,9 +88,9 @@ namespace Ryujinx.HLE.HOS.Services public void ConnectSharedLayer(long layerId) { - var producer = _surfaceFlinger.GetProducerByLayerId(layerId); + IGraphicBufferProducer producer = _surfaceFlinger.GetProducerByLayerId(layerId); - producer.Connect(null, NativeWindowApi.NVN, false, out var output); + producer.Connect(null, NativeWindowApi.NVN, false, out IGraphicBufferProducer.QueueBufferOutput output); GraphicBuffer graphicBuffer = new GraphicBuffer(); @@ -137,14 +138,14 @@ namespace Ryujinx.HLE.HOS.Services public void DisconnectSharedLayer(long layerId) { - var producer = _surfaceFlinger.GetProducerByLayerId(layerId); + IGraphicBufferProducer producer = _surfaceFlinger.GetProducerByLayerId(layerId); producer.Disconnect(NativeWindowApi.NVN); } public int DequeueFrameBuffer(long layerId, out AndroidFence fence) { - var producer = _surfaceFlinger.GetProducerByLayerId(layerId); + IGraphicBufferProducer producer = _surfaceFlinger.GetProducerByLayerId(layerId); Status status = producer.DequeueBuffer(out int slot, out fence, false, _fbWidth, _fbHeight, _fbFormat, (uint)_fbUsage); @@ -168,9 +169,9 @@ namespace Ryujinx.HLE.HOS.Services public void QueueFrameBuffer(long layerId, int slot, Rect crop, NativeWindowTransform transform, int swapInterval, AndroidFence fence) { - var producer = _surfaceFlinger.GetProducerByLayerId(layerId); + IGraphicBufferProducer producer = _surfaceFlinger.GetProducerByLayerId(layerId); - var input = new IGraphicBufferProducer.QueueBufferInput(); + IGraphicBufferProducer.QueueBufferInput input = new(); input.Crop = crop; input.Transform = transform; @@ -182,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services public void CancelFrameBuffer(long layerId, int slot) { - var producer = _surfaceFlinger.GetProducerByLayerId(layerId); + IGraphicBufferProducer producer = _surfaceFlinger.GetProducerByLayerId(layerId); AndroidFence fence = default; producer.CancelBuffer(slot, ref fence); @@ -222,8 +223,8 @@ namespace Ryujinx.HLE.HOS.Services public int GetApplicationLastPresentedFrameHandle(GpuContext gpuContext) { - var texture = gpuContext.Window.GetLastPresentedData(); - var selfAs = KernelStatic.GetProcessByPid(_pid).CpuMemory; + TextureData texture = gpuContext.Window.GetLastPresentedData(); + IVirtualMemoryManagerTracked selfAs = KernelStatic.GetProcessByPid(_pid).CpuMemory; int fbIndex = (int)_fbCount; // Place it after all our frame buffers. selfAs.Write(_fbsBaseAddress + _bufferMap.SharedBuffers[fbIndex].Offset, texture.Data);