From 459c4caebac0bc16c04467d9dcd2ef7a9fc0bd92 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Fri, 9 Dec 2022 17:41:40 -0300
Subject: [PATCH] Fix HasUnalignedStorageBuffers value when buffers are always
 unaligned (#4078)

---
 .../Engine/Threed/SpecializationStateUpdater.cs           | 7 ++++++-
 Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs        | 8 +++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/SpecializationStateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/SpecializationStateUpdater.cs
index 9e888f506c..13b332f436 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Threed/SpecializationStateUpdater.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Threed/SpecializationStateUpdater.cs
@@ -253,14 +253,19 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
         /// Indicates that any storage buffer use is unaligned.
         /// </summary>
         /// <param name="value">The new value</param>
-        public void SetHasUnalignedStorageBuffer(bool value)
+        /// <returns>True if the unaligned state changed, false otherwise</returns>
+        public bool SetHasUnalignedStorageBuffer(bool value)
         {
             if (value != _graphics.HasUnalignedStorageBuffer)
             {
                 _graphics.HasUnalignedStorageBuffer = value;
 
                 Signal();
+
+                return true;
             }
+
+            return false;
         }
 
         /// <summary>
diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
index b611f4e700..572f7fb01b 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
@@ -304,14 +304,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
         /// </summary>
         private void CommitBindings()
         {
-            var buffers = _channel.BufferManager;
-            var hasUnaligned = buffers.HasUnalignedStorageBuffers;
-
             UpdateStorageBuffers();
 
-            if (!_channel.TextureManager.CommitGraphicsBindings(_shaderSpecState) || (buffers.HasUnalignedStorageBuffers != hasUnaligned))
+            bool unalignedChanged = _currentSpecState.SetHasUnalignedStorageBuffer(_channel.BufferManager.HasUnalignedStorageBuffers);
+
+            if (!_channel.TextureManager.CommitGraphicsBindings(_shaderSpecState) || unalignedChanged)
             {
-                _currentSpecState.SetHasUnalignedStorageBuffer(buffers.HasUnalignedStorageBuffers);
                 // Shader must be reloaded. _vtgWritesRtLayer should not change.
                 UpdateShaderState();
             }