Przeglądaj źródła

Make sure shared samplers are always initialized (#19094)

Signed-off-by: Karl Haubenwallner <[email protected]>
Karl Haubenwallner 3 tygodni temu
rodzic
commit
0efc14c77e

+ 1 - 1
Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Material/MaterialSystem.h

@@ -60,7 +60,7 @@ namespace AZ::RPI
     private:
         bool LoadMaterialSrgShaderAsset();
         void CreateSceneMaterialSrg();
-        void UpdateSceneMaterialSrg();
+        bool UpdateSceneMaterialSrg();
         bool UpdateSharedSamplerStates();
         void PrepareMaterialParameterBuffers();
         void UpdateChangedMaterialParameters();

+ 16 - 6
Gems/Atom/RPI/Code/Source/RPI.Public/Material/MaterialSystem.cpp

@@ -85,6 +85,7 @@ namespace AZ::RPI
                     "SceneMaterialSrg::m_samplers[] has size %d, expected size is AZ_TRAITS_SCENE_MATERIALS_MAX_SAMPLERS (%d)",
                     maxTextureSamplerStates,
                     AZ_TRAITS_SCENE_MATERIALS_MAX_SAMPLERS);
+                m_sharedSamplerStatesDirty = true;
             }
         }
     }
@@ -573,7 +574,7 @@ namespace AZ::RPI
         return false;
     }
 
-    void MaterialSystem::UpdateSceneMaterialSrg()
+    bool MaterialSystem::UpdateSceneMaterialSrg()
     {
         auto createBuffer = [](const size_t numElements)
         {
@@ -632,7 +633,9 @@ namespace AZ::RPI
 
             // register the buffer in the SRG and compile it
             m_sceneMaterialSrg->SetBuffer(m_materialTypeBufferInputIndex, m_materialTypeBufferIndicesBuffer);
+            return true;
         }
+        return false;
     }
 
     void MaterialSystem::Compile()
@@ -640,19 +643,26 @@ namespace AZ::RPI
         bool compileSceneMaterialSrg = false;
         if (m_sharedSamplerStatesDirty)
         {
-            m_sharedSamplerStatesDirty = false;
-            compileSceneMaterialSrg = UpdateSharedSamplerStates();
+            if (UpdateSharedSamplerStates())
+            {
+                // make sure we try again if we didn't update the samplers successfully
+                m_sharedSamplerStatesDirty = false;
+                compileSceneMaterialSrg = true;
+            }
         }
 
         if (m_bufferReadIndicesDirty)
         {
             PrepareMaterialParameterBuffers();
-            UpdateSceneMaterialSrg();
-            m_bufferReadIndicesDirty = false;
+            if (UpdateSceneMaterialSrg())
+            {
+                // make sure we try again if we didn't update the SceneMaterialSrg successfully
+                m_bufferReadIndicesDirty = false;
+                compileSceneMaterialSrg = true;
+            }
 #ifdef DEBUG_MATERIALINSTANCES
             DebugPrintMaterialInstances();
 #endif
-            compileSceneMaterialSrg = true;
         }
         UpdateChangedMaterialParameters();
         if (m_sceneMaterialSrg && compileSceneMaterialSrg)