Bläddra i källkod

Add option to migrate the second triangle pass. (#686)

- By default runs on device 1 and migrates to device 0.
- Disables the copy pass when everything runs on device 0.
- Changes the input connection of the composite pass.

Signed-off-by: Joerg H. Mueller <[email protected]>
jhmueller-huawei 11 månader sedan
förälder
incheckning
0d47b8720e

+ 46 - 2
Gem/Code/Source/MultiGPURPIExampleComponent.cpp

@@ -14,10 +14,11 @@
 
 #include <Atom/RHI/RHISystemInterface.h>
 
-#include <Atom/RPI.Public/ViewProviderBus.h>
+#include <Atom/RPI.Public/Pass/PassFilter.h>
+#include <Atom/RPI.Public/RPISystemInterface.h>
 #include <Atom/RPI.Public/RenderPipeline.h>
 #include <Atom/RPI.Public/Scene.h>
-#include <Atom/RPI.Public/RPISystemInterface.h>
+#include <Atom/RPI.Public/ViewProviderBus.h>
 #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
 #include <Atom/RPI.Reflect/Model/ModelAsset.h>
 
@@ -111,6 +112,8 @@ namespace AtomSampleViewer
         m_copyPipeline = nullptr;
         m_useCopyPipeline = false;
         m_currentlyUsingCopyPipline = false;
+        m_migrate = false;
+        m_currentlyMigrated = false;
 
         AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler::BusDisconnect();
 
@@ -142,6 +145,39 @@ namespace AtomSampleViewer
             }
             m_currentlyUsingCopyPipline = m_useCopyPipeline;
         }
+
+        if (m_currentlyMigrated != m_migrate)
+        {
+            AZ::RPI::PassFilter trianglePassFilter = AZ::RPI::PassFilter::CreateWithPassName(Name("TrianglePass2"), m_scene);
+            AZ::RPI::PassFilter copyPassFilter = AZ::RPI::PassFilter::CreateWithPassName(Name("CopyPass"), m_scene);
+            AZ::RPI::PassFilter compositePassFilter = AZ::RPI::PassFilter::CreateWithPassName(Name("CompositePass"), m_scene);
+
+            RPI::RenderPass* trianglePass =
+                azrtti_cast<RPI::RenderPass*>(AZ::RPI::PassSystemInterface::Get()->FindFirstPass(trianglePassFilter));
+            RPI::Pass* copyPass = AZ::RPI::PassSystemInterface::Get()->FindFirstPass(copyPassFilter);
+            RPI::Pass* compositePass = AZ::RPI::PassSystemInterface::Get()->FindFirstPass(compositePassFilter);
+            AZ_Assert(trianglePass && copyPass && compositePass, "Couldn't find passes");
+
+            if (m_migrate)
+            {
+                trianglePass->SetDeviceIndex(0);
+                copyPass->SetEnabled(false);
+                auto& attachmentBinding = compositePass->GetInputBinding(1);
+                attachmentBinding.m_connectedBinding = &trianglePass->GetOutputBinding(0);
+                attachmentBinding.UpdateConnection(false);
+            }
+            else
+            {
+                trianglePass->SetDeviceIndex(1);
+                copyPass->SetEnabled(true);
+                auto& attachmentBinding = compositePass->GetInputBinding(1);
+                attachmentBinding.m_connectedBinding = &copyPass->GetOutputBinding(0);
+                attachmentBinding.UpdateConnection(false);
+            }
+
+            m_currentlyMigrated = m_migrate;
+        }
+
         if (m_imguiSidebar.Begin())
         {
             ImGui::Spacing();
@@ -154,6 +190,14 @@ namespace AtomSampleViewer
                                   "buffer to image\n"
                                   "image to image\n");
             }
+            if (!m_useCopyPipeline)
+            {
+                ImGui::Checkbox("Migrate", &m_migrate);
+                if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
+                {
+                    ImGui::SetTooltip("Migrate all passes to the first GPU.");
+                }
+            }
             m_imguiSidebar.End();
         }
     }

+ 2 - 0
Gem/Code/Source/MultiGPURPIExampleComponent.h

@@ -74,6 +74,8 @@ namespace AtomSampleViewer
 
         bool m_useCopyPipeline = false;
         bool m_currentlyUsingCopyPipline = false;
+        bool m_migrate = false;
+        bool m_currentlyMigrated = false;
     };
 
 } // namespace AtomSampleViewer