From dfb905b269e6ed3a42a524812061a34db2919f6a Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 16 Jun 2022 00:32:53 +0100 Subject: [PATCH] Address Feedback Part 1 --- .../Engine/Compute/ComputeClass.cs | 4 ++-- .../Engine/Threed/StateUpdater.cs | 4 ++-- .../Image/TextureBindingsManager.cs | 14 ++------------ Ryujinx.Graphics.Gpu/Image/TextureManager.cs | 4 ++-- Ryujinx.Graphics.Gpu/Image/TexturePool.cs | 2 +- .../Shader/ShaderSpecializationState.cs | 3 +-- Ryujinx.Graphics.Shader/TextureHandle.cs | 16 ++++++++++++++++ 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs b/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs index d62d4c26c..a1a9b481f 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs @@ -188,8 +188,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute _channel.BufferManager.SetComputeStorageBufferBindings(info.SBuffers); _channel.BufferManager.SetComputeUniformBufferBindings(info.CBuffers); - int maxTextureBinding = 0; - int maxImageBinding = 0; + int maxTextureBinding = -1; + int maxImageBinding = -1; TextureBindingInfo[] textureBindings = _channel.TextureManager.RentComputeTextureBindings(info.Textures.Count); diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index 1f69f9bee..41c0dfad3 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -1153,8 +1153,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed return; } - int maxTextureBinding = 0; - int maxImageBinding = 0; + int maxTextureBinding = -1; + int maxImageBinding = -1; Span textureBindings = _channel.TextureManager.RentGraphicsTextureBindings(stage, info.Textures.Count); diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs index 6e200a137..f15f88850 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// class TextureBindingsManager : IDisposable { - private const int InitialTextureStateSize = 32; // Should match binding range for host. + private const int InitialTextureStateSize = 32; private const int InitialImageStateSize = 8; private readonly GpuContext _context; @@ -484,7 +484,7 @@ namespace Ryujinx.Graphics.Gpu.Image } else { - samplerId = UnpackSamplerId(packedId); + samplerId = TextureHandle.UnpackSamplerId(packedId); } ref TextureStatePerStage state = ref _textureState[bindingInfo.Binding]; @@ -749,16 +749,6 @@ namespace Ryujinx.Graphics.Gpu.Image return handle; } - /// - /// Unpacks the sampler ID from the real texture handle. - /// - /// The real texture handle - /// The sampler ID - private static int UnpackSamplerId(int packedId) - { - return (packedId >> 20) & 0xfff; - } - /// /// Force all bound textures and images to be rebound the next time CommitBindings is called. /// diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index dea0c9688..628c31596 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -361,7 +361,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// Commits bindings on the compute pipeline. /// /// Specialization state for the bound shader - /// True if all bound textures match the current shader specialiation state, false otherwise + /// True if all bound textures match the current shader specialization state, false otherwise public bool CommitComputeBindings(ShaderSpecializationState specState) { // Every time we switch between graphics and compute work, @@ -379,7 +379,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// Commits bindings on the graphics pipeline. /// /// Specialization state for the bound shader - /// True if all bound textures match the current shader specialiation state, false otherwise + /// True if all bound textures match the current shader specialization state, false otherwise public bool CommitGraphicsBindings(ShaderSpecializationState specState) { bool result = _gpBindingsManager.CommitBindings(specState); diff --git a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs index b8002be4d..75974c43b 100644 --- a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs +++ b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// ID of the texture. This is effectively a zero-based index /// The texture with the given ID /// The texture descriptor with the given ID - public ref readonly TextureDescriptor GetInternal(int id, out Texture texture) + private ref readonly TextureDescriptor GetInternal(int id, out Texture texture) { texture = Items[id]; diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs index 33130ca1f..5375ebd18 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs @@ -216,7 +216,7 @@ namespace Ryujinx.Graphics.Gpu.Shader for (int i = 0; i < stages.Length; i++) { CachedShaderStage stage = stages[i]; - if (stage != null && stage.Info != null) + if (stage?.Info != null) { var textures = stage.Info.Textures; var images = stage.Info.Images; @@ -600,7 +600,6 @@ namespace Ryujinx.Graphics.Gpu.Shader /// Texture specialization state /// Texture descriptor /// True if the state matches, false otherwise - [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool MatchesTexture(Box specializationState, in Image.TextureDescriptor descriptor) { diff --git a/Ryujinx.Graphics.Shader/TextureHandle.cs b/Ryujinx.Graphics.Shader/TextureHandle.cs index 83b2dbe8d..d468188b8 100644 --- a/Ryujinx.Graphics.Shader/TextureHandle.cs +++ b/Ryujinx.Graphics.Shader/TextureHandle.cs @@ -52,12 +52,28 @@ namespace Ryujinx.Graphics.Shader return (handle & 0x3fff, (handle >> 14) & 0x3fff, (TextureHandleType)((uint)handle >> 28)); } + /// + /// Unpacks the texture ID from the real texture handle. + /// + /// The real texture handle + /// The texture ID [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int UnpackTextureId(int packedId) { return (packedId >> 0) & 0xfffff; } + /// + /// Unpacks the sampler ID from the real texture handle. + /// + /// The real texture handle + /// The sampler ID + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int UnpackSamplerId(int packedId) + { + return (packedId >> 20) & 0xfff; + } + /// /// Reads a packed texture and sampler ID (basically, the real texture handle) /// from a given texture/sampler constant buffer.