From 8b44eb1c981d7106be37107755c7c71c3c3c0ce4 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 7 Jul 2021 20:56:06 -0300 Subject: Separate GPU engines and make state follow official docs (part 1/2) (#2422) * Use DeviceState for compute and i2m * Migrate 2D class, more comments * Migrate DMA copy engine * Remove now unused code * Replace GpuState by GpuAccessorState on GpuAcessor, since compute no longer has a GpuState * More comments * Add logging (disabled) * Add back i2m on 3D engine --- .../Image/TextureBindingsManager.cs | 20 +++++++++++------ Ryujinx.Graphics.Gpu/Image/TextureCache.cs | 25 +++++++++++++++------- Ryujinx.Graphics.Gpu/Image/TextureManager.cs | 22 +++++++++++++------ 3 files changed, 46 insertions(+), 21 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Image') diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs index 14bc27a9..b247f99f 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs @@ -425,22 +425,28 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// Gets the texture descriptor for a given texture handle. /// - /// The current GPU state + /// GPU virtual address of the texture pool + /// Index of the constant buffer with texture handles + /// Maximum ID of the texture pool /// The stage number where the texture is bound /// The texture handle /// The texture handle's constant buffer slot /// The texture descriptor for the specified texture - public TextureDescriptor GetTextureDescriptor(GpuState state, int stageIndex, int handle, int cbufSlot) + public TextureDescriptor GetTextureDescriptor( + ulong poolGpuVa, + int bufferIndex, + int maximumId, + int stageIndex, + int handle, + int cbufSlot) { - int textureBufferIndex = cbufSlot < 0 ? state.Get(MethodOffset.TextureBufferIndex) : cbufSlot & SlotMask; + int textureBufferIndex = cbufSlot < 0 ? bufferIndex : cbufSlot & SlotMask; int packedId = ReadPackedId(stageIndex, handle, textureBufferIndex, textureBufferIndex); int textureId = UnpackTextureId(packedId); - var poolState = state.Get(MethodOffset.TexturePoolState); + ulong poolAddress = _channel.MemoryManager.Translate(poolGpuVa); - ulong poolAddress = _channel.MemoryManager.Translate(poolState.Address.Pack()); - - TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, poolState.MaximumId); + TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, maximumId); return texturePool.GetDescriptor(textureId); } diff --git a/Ryujinx.Graphics.Gpu/Image/TextureCache.cs b/Ryujinx.Graphics.Gpu/Image/TextureCache.cs index 37a2219f..106dc8e8 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureCache.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureCache.cs @@ -753,21 +753,30 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// GPU memory manager where the texture is mapped /// The texture information - /// The copy buffer parameters - /// The copy buffer swizzle + /// GPU virtual address of the texture + /// Bytes per pixel + /// If is true, should have the texture stride, otherwise ignored + /// Number of pixels to be copied per line + /// Number of lines to be copied /// True if the texture has a linear layout, false otherwise /// A matching texture, or null if there is no match - public Texture FindTexture(MemoryManager memoryManager, CopyBufferTexture tex, CopyBufferParams cbp, CopyBufferSwizzle swizzle, bool linear) + public Texture FindTexture( + MemoryManager memoryManager, + CopyBufferTexture tex, + ulong gpuVa, + int bpp, + int stride, + int xCount, + int yCount, + bool linear) { - ulong address = memoryManager.Translate(cbp.DstAddress.Pack()); + ulong address = memoryManager.Translate(gpuVa); if (address == MemoryManager.PteUnmapped) { return null; } - int bpp = swizzle.UnpackDstComponentsCount() * swizzle.UnpackComponentSize(); - int addressMatches = _textures.FindOverlaps(address, ref _textureOverlaps); for (int i = 0; i < addressMatches; i++) @@ -786,7 +795,7 @@ namespace Ryujinx.Graphics.Gpu.Image { // Size is not available for linear textures. Use the stride and end of the copy region instead. - match = texture.Info.IsLinear && texture.Info.Stride == cbp.DstStride && tex.RegionY + cbp.YCount <= texture.Info.Height; + match = texture.Info.IsLinear && texture.Info.Stride == stride && tex.RegionY + yCount <= texture.Info.Height; } else { @@ -794,7 +803,7 @@ namespace Ryujinx.Graphics.Gpu.Image // Due to the way linear strided and block layouts work, widths can be multiplied by Bpp for comparison. // Note: tex.Width is the aligned texture size. Prefer param.XCount, as the destination should be a texture with that exact size. - bool sizeMatch = cbp.XCount * bpp == texture.Info.Width * format.BytesPerPixel && tex.Height == texture.Info.Height; + bool sizeMatch = xCount * bpp == texture.Info.Width * format.BytesPerPixel && tex.Height == texture.Info.Height; bool formatMatch = !texture.Info.IsLinear && texture.Info.GobBlocksInY == tex.MemoryLayout.UnpackGobBlocksInY() && texture.Info.GobBlocksInZ == tex.MemoryLayout.UnpackGobBlocksInZ(); diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index 9cab343a..fcc67f72 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -313,26 +313,36 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// Gets a texture descriptor used on the compute pipeline. /// - /// Current GPU state + /// GPU virtual address of the texture pool + /// Index of the constant buffer with texture handles + /// Maximum ID of the texture pool /// Shader "fake" handle of the texture /// Shader constant buffer slot of the texture /// The texture descriptor - public TextureDescriptor GetComputeTextureDescriptor(GpuState state, int handle, int cbufSlot) + public TextureDescriptor GetComputeTextureDescriptor(ulong poolGpuVa, int bufferIndex, int maximumId, int handle, int cbufSlot) { - return _cpBindingsManager.GetTextureDescriptor(state, 0, handle, cbufSlot); + return _cpBindingsManager.GetTextureDescriptor(poolGpuVa, bufferIndex, maximumId, 0, handle, cbufSlot); } /// /// Gets a texture descriptor used on the graphics pipeline. /// - /// Current GPU state + /// GPU virtual address of the texture pool + /// Index of the constant buffer with texture handles + /// Maximum ID of the texture pool /// Index of the shader stage where the texture is bound /// Shader "fake" handle of the texture /// Shader constant buffer slot of the texture /// The texture descriptor - public TextureDescriptor GetGraphicsTextureDescriptor(GpuState state, int stageIndex, int handle, int cbufSlot) + public TextureDescriptor GetGraphicsTextureDescriptor( + ulong poolGpuVa, + int bufferIndex, + int maximumId, + int stageIndex, + int handle, + int cbufSlot) { - return _gpBindingsManager.GetTextureDescriptor(state, stageIndex, handle, cbufSlot); + return _gpBindingsManager.GetTextureDescriptor(poolGpuVa, bufferIndex, maximumId, stageIndex, handle, cbufSlot); } /// -- cgit v1.2.3