From 0129250c2e169c7386f7e2868cc055f8ec55c005 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Wed, 19 May 2021 19:05:43 +0100 Subject: Pass CbufSlot when getting info from the texture descriptor (#2291) * Pass CbufSlot when getting info from the texture descriptor Fixes some issues with bindless textures, when CbufSlot is not equal to the current TextureBufferIndex. Specifically fixes a random chance of full screen colour flickering in Super Mario Party. * Apply suggestions from code review Oops Co-authored-by: gdkchan Co-authored-by: gdkchan --- Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs | 2 +- Ryujinx.Graphics.Gpu/Shader/CachedGpuAccessor.cs | 3 ++- Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs | 7 ++++--- .../Shader/TextureDescriptorCapableGpuAccessor.cs | 17 ++++++++++------- 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Shader') diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs index 1ec4ab74..f6caddef 100644 --- a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs +++ b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs @@ -417,7 +417,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache { foreach (int textureHandle in context.TextureHandlesForCache) { - GuestTextureDescriptor textureDescriptor = ((Image.TextureDescriptor)gpuAccessor.GetTextureDescriptor(textureHandle)).ToCache(); + GuestTextureDescriptor textureDescriptor = ((Image.TextureDescriptor)gpuAccessor.GetTextureDescriptor(textureHandle, -1)).ToCache(); textureDescriptor.Handle = (uint)textureHandle; diff --git a/Ryujinx.Graphics.Gpu/Shader/CachedGpuAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/CachedGpuAccessor.cs index f714d97b..a7bd4edb 100644 --- a/Ryujinx.Graphics.Gpu/Shader/CachedGpuAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/CachedGpuAccessor.cs @@ -140,8 +140,9 @@ namespace Ryujinx.Graphics.Gpu.Shader /// Gets the texture descriptor for a given texture on the pool. /// /// Index of the texture (this is the word offset of the handle in the constant buffer) + /// Constant buffer slot for the texture handle /// Texture descriptor - public override Image.ITextureDescriptor GetTextureDescriptor(int handle) + public override Image.ITextureDescriptor GetTextureDescriptor(int handle, int cbufSlot) { if (!_textureDescriptors.TryGetValue(handle, out GuestTextureDescriptor textureDescriptor)) { diff --git a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs index c0ad481e..f5373bd6 100644 --- a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs @@ -184,16 +184,17 @@ namespace Ryujinx.Graphics.Gpu.Shader /// Gets the texture descriptor for a given texture on the pool. /// /// Index of the texture (this is the word offset of the handle in the constant buffer) + /// Constant buffer slot for the texture handle /// Texture descriptor - public override Image.ITextureDescriptor GetTextureDescriptor(int handle) + public override Image.ITextureDescriptor GetTextureDescriptor(int handle, int cbufSlot) { if (_compute) { - return _context.Methods.TextureManager.GetComputeTextureDescriptor(_state, handle); + return _context.Methods.TextureManager.GetComputeTextureDescriptor(_state, handle, cbufSlot); } else { - return _context.Methods.TextureManager.GetGraphicsTextureDescriptor(_state, _stageIndex, handle); + return _context.Methods.TextureManager.GetGraphicsTextureDescriptor(_state, _stageIndex, handle, cbufSlot); } } diff --git a/Ryujinx.Graphics.Gpu/Shader/TextureDescriptorCapableGpuAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/TextureDescriptorCapableGpuAccessor.cs index dc0e392b..904a0fd4 100644 --- a/Ryujinx.Graphics.Gpu/Shader/TextureDescriptorCapableGpuAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/TextureDescriptorCapableGpuAccessor.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Gpu.Shader { public abstract T MemoryRead(ulong address) where T : unmanaged; - public abstract ITextureDescriptor GetTextureDescriptor(int handle); + public abstract ITextureDescriptor GetTextureDescriptor(int handle, int cbufSlot); /// /// Queries texture format information, for shaders using image load or store. @@ -18,10 +18,11 @@ namespace Ryujinx.Graphics.Gpu.Shader /// If the format of the texture is a compressed, depth or unsupported format, then a default value is returned. /// /// Texture handle + /// Constant buffer slot for the texture handle /// Color format of the non-compressed texture - public TextureFormat QueryTextureFormat(int handle) + public TextureFormat QueryTextureFormat(int handle, int cbufSlot = -1) { - var descriptor = GetTextureDescriptor(handle); + var descriptor = GetTextureDescriptor(handle, cbufSlot); if (!FormatTable.TryGetTextureFormat(descriptor.UnpackFormat(), descriptor.UnpackSrgb(), out FormatInfo formatInfo)) { @@ -78,20 +79,22 @@ namespace Ryujinx.Graphics.Gpu.Shader /// Queries texture target information. /// /// Texture handle + /// Constant buffer slot for the texture handle /// True if the texture is a buffer texture, false otherwise - public bool QueryIsTextureBuffer(int handle) + public bool QueryIsTextureBuffer(int handle, int cbufSlot = -1) { - return GetTextureDescriptor(handle).UnpackTextureTarget() == TextureTarget.TextureBuffer; + return GetTextureDescriptor(handle, cbufSlot).UnpackTextureTarget() == TextureTarget.TextureBuffer; } /// /// Queries texture target information. /// /// Texture handle + /// Constant buffer slot for the texture handle /// True if the texture is a rectangle texture, false otherwise - public bool QueryIsTextureRectangle(int handle) + public bool QueryIsTextureRectangle(int handle, int cbufSlot = -1) { - var descriptor = GetTextureDescriptor(handle); + var descriptor = GetTextureDescriptor(handle, cbufSlot); TextureTarget target = descriptor.UnpackTextureTarget(); -- cgit v1.2.3