diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs
index 7fea7ebe0c..ae610a7669 100644
--- a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs
+++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs
@@ -398,10 +398,11 @@ namespace Ryujinx.Graphics.Gpu.Image
/// The current GPU state
/// 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)
+ public TextureDescriptor GetTextureDescriptor(GpuState state, int stageIndex, int handle, int cbufSlot)
{
- int packedId = ReadPackedId(stageIndex, handle, state.Get(MethodOffset.TextureBufferIndex));
+ int packedId = ReadPackedId(stageIndex, handle, cbufSlot < 0 ? state.Get(MethodOffset.TextureBufferIndex) : cbufSlot);
int textureId = UnpackTextureId(packedId);
var poolState = state.Get(MethodOffset.TexturePoolState);
diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs
index 17bb553f3e..e08e55eea6 100644
--- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs
+++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs
@@ -340,10 +340,11 @@ namespace Ryujinx.Graphics.Gpu.Image
///
/// Current GPU state
/// Shader "fake" handle of the texture
+ /// Shader constant buffer slot of the texture
/// The texture descriptor
- public TextureDescriptor GetComputeTextureDescriptor(GpuState state, int handle)
+ public TextureDescriptor GetComputeTextureDescriptor(GpuState state, int handle, int cbufSlot)
{
- return _cpBindingsManager.GetTextureDescriptor(state, 0, handle);
+ return _cpBindingsManager.GetTextureDescriptor(state, 0, handle, cbufSlot);
}
///
@@ -352,10 +353,11 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Current GPU state
/// 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)
+ public TextureDescriptor GetGraphicsTextureDescriptor(GpuState state, int stageIndex, int handle, int cbufSlot)
{
- return _gpBindingsManager.GetTextureDescriptor(state, stageIndex, handle);
+ return _gpBindingsManager.GetTextureDescriptor(state, stageIndex, handle, cbufSlot);
}
///
@@ -1297,4 +1299,4 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs
index 1ec4ab74cc..f6caddef19 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 f714d97bd0..a7bd4edb96 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 c0ad481ea3..f5373bd6f8 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 dc0e392bc7..904a0fd453 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();
diff --git a/Ryujinx.Graphics.Shader/IGpuAccessor.cs b/Ryujinx.Graphics.Shader/IGpuAccessor.cs
index fe034c57cb..1e05cdcd61 100644
--- a/Ryujinx.Graphics.Shader/IGpuAccessor.cs
+++ b/Ryujinx.Graphics.Shader/IGpuAccessor.cs
@@ -44,12 +44,12 @@
return 0xffff;
}
- bool QueryIsTextureBuffer(int handle)
+ bool QueryIsTextureBuffer(int handle, int cbufSlot = -1)
{
return false;
}
- bool QueryIsTextureRectangle(int handle)
+ bool QueryIsTextureRectangle(int handle, int cbufSlot = -1)
{
return false;
}
@@ -74,7 +74,7 @@
return true;
}
- TextureFormat QueryTextureFormat(int handle)
+ TextureFormat QueryTextureFormat(int handle, int cbufSlot = -1)
{
return TextureFormat.R8G8B8A8Unorm;
}
diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs
index f462cedbc4..f91a00ebad 100644
--- a/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs
+++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs
@@ -65,7 +65,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
if (src0.Type == OperandType.ConstantBuffer)
{
texOp.SetHandle(src0.GetCbufOffset(), src0.GetCbufSlot());
- texOp.Format = config.GetTextureFormat(texOp.Handle);
+ texOp.Format = config.GetTextureFormat(texOp.Handle, texOp.CbufSlot);
}
}
}
diff --git a/Ryujinx.Graphics.Shader/Translation/Rewriter.cs b/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
index a928f93571..5427c013a8 100644
--- a/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
+++ b/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
@@ -142,7 +142,7 @@ namespace Ryujinx.Graphics.Shader.Translation
bool hasInvalidOffset = (hasOffset || hasOffsets) && !config.GpuAccessor.QuerySupportsNonConstantTextureOffset();
- bool isRect = config.GpuAccessor.QueryIsTextureRectangle(texOp.Handle);
+ bool isRect = config.GpuAccessor.QueryIsTextureRectangle(texOp.Handle, texOp.CbufSlot);
if (!(hasInvalidOffset || isRect))
{
@@ -433,7 +433,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
TextureOperation texOp = (TextureOperation)node.Value;
- TextureFormat format = config.GpuAccessor.QueryTextureFormat(texOp.Handle);
+ TextureFormat format = config.GpuAccessor.QueryTextureFormat(texOp.Handle, texOp.CbufSlot);
int maxPositive = format switch
{
diff --git a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
index c71a839842..077ce70d90 100644
--- a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
+++ b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
@@ -91,7 +91,7 @@ namespace Ryujinx.Graphics.Shader.Translation
return count + 1;
}
- public TextureFormat GetTextureFormat(int handle)
+ public TextureFormat GetTextureFormat(int handle, int cbufSlot = -1)
{
// When the formatted load extension is supported, we don't need to
// specify a format, we can just declare it without a format and the GPU will handle it.
@@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.Shader.Translation
return TextureFormat.Unknown;
}
- var format = GpuAccessor.QueryTextureFormat(handle);
+ var format = GpuAccessor.QueryTextureFormat(handle, cbufSlot);
if (format == TextureFormat.Unknown)
{