Selaa lähdekoodia

Multi-GPU RPI copy tests

Signed-off-by: Martin Sattlecker <[email protected]>
Martin Sattlecker 1 vuosi sitten
vanhempi
commit
075972a28a

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

@@ -85,6 +85,12 @@ namespace AtomSampleViewer
         m_pipeline = AZ::RPI::RenderPipeline::CreateRenderPipelineForWindow(pipelineDesc, *m_windowContext);
         m_scene->AddRenderPipeline(m_pipeline);
 
+        const AZStd::string copyPipelineName("MultiGPUCopyTestPipeline");
+        AZ::RPI::RenderPipelineDescriptor copyPipelineDesc;
+        copyPipelineDesc.m_name = copyPipelineName;
+        copyPipelineDesc.m_rootPassTemplate = "MultiGPUCopyTestPipeline";
+        m_copyPipeline = AZ::RPI::RenderPipeline::CreateRenderPipelineForWindow(copyPipelineDesc, *m_windowContext);
+
         m_imguiScope = AZ::Render::ImGuiActiveContextScope::FromPass({ "MultiGPUPipeline", "ImGuiPass" });
     }
 
@@ -102,6 +108,9 @@ namespace AtomSampleViewer
         m_scene->AddRenderPipeline(m_originalPipeline);
 
         m_pipeline = nullptr;
+        m_copyPipeline = nullptr;
+        m_useCopyPipeline = false;
+        m_currentlyUsingCopyPipline = false;
 
         AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler::BusDisconnect();
 
@@ -110,6 +119,43 @@ namespace AtomSampleViewer
 
     void MultiGPURPIExampleComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint timePoint)
     {
+        if (m_currentlyUsingCopyPipline != m_useCopyPipeline)
+        {
+            AZ::RPI::RenderPipelinePtr prevPipeline = m_scene->GetDefaultRenderPipeline();
+            if (m_useCopyPipeline)
+            {
+                m_copyPipeline->GetRootPass()->SetEnabled(true);
+                m_scene->AddRenderPipeline(m_copyPipeline);
+                m_scene->RemoveRenderPipeline(prevPipeline->GetId());
+
+                m_imguiScope = {};
+                m_imguiScope = AZ::Render::ImGuiActiveContextScope::FromPass({ m_copyPipeline->GetId().GetCStr(), "ImGuiPass" });
+            }
+            else
+            {
+                m_pipeline->GetRootPass()->SetEnabled(true);
+                m_scene->AddRenderPipeline(m_pipeline);
+                m_scene->RemoveRenderPipeline(prevPipeline->GetId());
+
+                m_imguiScope = {};
+                m_imguiScope = AZ::Render::ImGuiActiveContextScope::FromPass({ m_pipeline->GetId().GetCStr(), "ImGuiPass" });
+            }
+            m_currentlyUsingCopyPipline = m_useCopyPipeline;
+        }
+        if (m_imguiSidebar.Begin())
+        {
+            ImGui::Spacing();
+            ImGui::Checkbox("Use copy test pipeline", &m_useCopyPipeline);
+            if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
+            {
+                ImGui::SetTooltip("Add additional device to device copy passes to test the modes of the copy pass:\n"
+                                  "image to buffer\n"
+                                  "buffer to buffer\n"
+                                  "buffer to image\n"
+                                  "image to image\n");
+            }
+            m_imguiSidebar.End();
+        }
     }
 
     void MultiGPURPIExampleComponent::OnAllAssetsReadyActivate()

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

@@ -68,10 +68,15 @@ namespace AtomSampleViewer
         AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
 
         AZ::RPI::RenderPipelinePtr m_pipeline;
+        AZ::RPI::RenderPipelinePtr m_copyPipeline;
         AZ::RPI::RenderPipelinePtr m_originalPipeline;
         AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
 
         AZ::Render::ImGuiActiveContextScope m_imguiScope;
+        ImGuiSidebar m_imguiSidebar;
+
+        bool m_useCopyPipeline = false;
+        bool m_currentlyUsingCopyPipline = false;
     };
 
 } // namespace AtomSampleViewer

+ 16 - 0
Passes/ASV/PassTemplates.azasset

@@ -68,6 +68,22 @@
                 "Name": "MultiGPUPipeline",
                 "Path": "Passes/MultiGPUPipeline.pass"
             },
+            {
+                "Name": "MultiGPUCopyTestPipeline",
+                "Path": "Passes/MultiGPUCopyTestPipeline.pass"
+            },
+            {
+                "Name": "MultiGPUCopyImageToBufferPassTemplate",
+                "Path": "Passes/MultiGPUCopyImageToBuffer.pass"
+            },
+            {
+                "Name": "MultiGPUCopyBufferToBufferPassTemplate",
+                "Path": "Passes/MultiGPUCopyBufferToBuffer.pass"
+            },
+            {
+                "Name": "MultiGPUCopyBufferToImagePassTemplate",
+                "Path": "Passes/MultiGPUCopyBufferToImage.pass"
+            },
             {
                 "Name": "MultiGPUCompositePassTemplate",
                 "Path": "Passes/MultiGPUCompositePass.pass"

+ 52 - 0
Passes/MultiGPUCopyBufferToBuffer.pass

@@ -0,0 +1,52 @@
+{
+    "Type": "JsonSerialization",
+    "Version": 1,
+    "ClassName": "PassAsset",
+    "ClassData": {
+        "PassTemplate": {
+            "Name": "MultiGPUCopyImageToBufferPassTemplate",
+            "PassClass": "CopyPass",
+            "Slots": [
+                {
+                    "Name": "Input",
+                    "SlotType": "Input",
+                    "ScopeAttachmentUsage": "Copy",
+                    "BufferViewDesc": {
+                        "m_elementOffset": 0,
+                        "m_elementCount": 153600,
+                        "m_elementSize": 4
+                    }
+                },
+                {
+                    "Name": "Output",
+                    "SlotType": "Output",
+                    "ScopeAttachmentUsage": "Copy",
+                    "BufferViewDesc": {
+                        "m_elementOffset": 0,
+                        "m_elementCount": 153600,
+                        "m_elementSize": 4
+                    }
+                }
+            ],
+            "BufferAttachments": [
+                {
+                    "Name": "OutputAttachment",
+                    "BufferDescriptor": {
+                        "m_byteCount": 614400,
+                        "m_alignment": 16,
+                        "m_bindFlags": "ShaderReadWrite"
+                    }
+                }
+            ],
+            "Connections": [
+                {
+                    "LocalSlot": "Output",
+                    "AttachmentRef": {
+                        "Pass": "This",
+                        "Attachment": "OutputAttachment"
+                    }
+                }
+            ]
+        }
+    }
+}

+ 50 - 0
Passes/MultiGPUCopyBufferToImage.pass

@@ -0,0 +1,50 @@
+{
+    "Type": "JsonSerialization",
+    "Version": 1,
+    "ClassName": "PassAsset",
+    "ClassData": {
+        "PassTemplate": {
+            "Name": "MultiGPUCopyImageToBufferPassTemplate",
+            "PassClass": "CopyPass",
+            "Slots": [
+                {
+                    "Name": "Input",
+                    "SlotType": "Input",
+                    "ScopeAttachmentUsage": "Copy",
+                    "BufferViewDesc": {
+                        "m_elementOffset": 0,
+                        "m_elementCount": 153600,
+                        "m_elementSize": 4
+                    }
+                },
+                {
+                    "Name": "Output",
+                    "SlotType": "Output",
+                    "ScopeAttachmentUsage": "Copy"
+                }
+            ],
+            "ImageAttachments": [
+                {
+                    "Name": "OutputAttachment",
+                    "ImageDescriptor": {
+                        "Format": "R8G8B8A8_UNORM",
+                        "Size": {
+                            "Width": 320,
+                            "Height": 480,
+                            "Depth": 1
+                        }
+                    }
+                }
+            ],
+            "Connections": [
+                {
+                    "LocalSlot": "Output",
+                    "AttachmentRef": {
+                        "Pass": "This",
+                        "Attachment": "OutputAttachment"
+                    }
+                }
+            ]
+        }
+    }
+}

+ 47 - 0
Passes/MultiGPUCopyImageToBuffer.pass

@@ -0,0 +1,47 @@
+{
+    "Type": "JsonSerialization",
+    "Version": 1,
+    "ClassName": "PassAsset",
+    "ClassData": {
+        "PassTemplate": {
+            "Name": "MultiGPUCopyImageToBufferPassTemplate",
+            "PassClass": "CopyPass",
+            "Slots": [
+                {
+                    "Name": "Input",
+                    "SlotType": "Input",
+                    "ScopeAttachmentUsage": "Copy"
+                },
+                {
+                    "Name": "Output",
+                    "SlotType": "Output",
+                    "ScopeAttachmentUsage": "Copy",
+                    "BufferViewDesc": {
+                        "m_elementOffset": 0,
+                        "m_elementCount": 153600,
+                        "m_elementSize": 4
+                    }
+                }
+            ],
+            "BufferAttachments": [
+                {
+                    "Name": "OutputAttachment",
+                    "BufferDescriptor": {
+                        "m_byteCount": 614400,
+                        "m_alignment": 16,
+                        "m_bindFlags": "ShaderReadWrite"
+                    }
+                }
+            ],
+            "Connections": [
+                {
+                    "LocalSlot": "Output",
+                    "AttachmentRef": {
+                        "Pass": "This",
+                        "Attachment": "OutputAttachment"
+                    }
+                }
+            ]
+        }
+    }
+}

+ 299 - 0
Passes/MultiGPUCopyTestPipeline.pass

@@ -0,0 +1,299 @@
+{
+    "Type": "JsonSerialization",
+    "Version": 1,
+    "ClassName": "PassAsset",
+    "ClassData": {
+        "PassTemplate": {
+            "Name": "MultiGPUCopyTestPipeline",
+            "PassClass": "ParentPass",
+            "Slots": [
+                {
+                    "Name": "PipelineOutput",
+                    "SlotType": "InputOutput",
+                    "ScopeAttachmentUsage": "RenderTarget"
+                }
+            ],
+            "ImageAttachments": [
+                {
+                    "Name": "TriangleAttachment1",
+                    "ImageDescriptor": {
+                        "Format": "R8G8B8A8_UNORM",
+                        "Size": {
+                            "Width": 320,
+                            "Height": 480,
+                            "Depth": 1
+                        }
+                    }
+                },
+                {
+                    "Name": "TriangleAttachment2",
+                    "ImageDescriptor": {
+                        "Format": "R8G8B8A8_UNORM",
+                        "Size": {
+                            "Width": 320,
+                            "Height": 480,
+                            "Depth": 1
+                        }
+                    }
+                }
+            ],
+            "PassRequests": [
+                {
+                    "Name": "TrianglePass1",
+                    "TemplateName": "MultiGPUTrianglePassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Output",
+                            "AttachmentRef": {
+                                "Pass": "Parent",
+                                "Attachment": "TriangleAttachment1"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "FullscreenTrianglePassData",
+                        "ShaderAsset": {
+                            "FilePath": "Shaders/MultiGPURPIExample/Triangle.shader"
+                        },
+                        "ShaderDataMappings": {
+                            "Matrix4x4Mappings": [
+                                {
+                                    "Name": "m_objectMatrix",
+                                    "Value": [
+                                        2.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        1.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        1.0,
+                                        0.0,
+                                        1.0,
+                                        0.0,
+                                        0.0,
+                                        1.0
+                                    ]
+                                }
+                            ]
+                        }
+                    }
+                },
+                {
+                    "Name": "TrianglePass2",
+                    "TemplateName": "MultiGPUTrianglePassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Output",
+                            "AttachmentRef": {
+                                "Pass": "Parent",
+                                "Attachment": "TriangleAttachment2"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "FullscreenTrianglePassData",
+                        "ShaderAsset": {
+                            "FilePath": "Shaders/MultiGPURPIExample/Triangle.shader"
+                        },
+                        "DeviceIndex": 1,
+                        "ShaderDataMappings": {
+                            "Matrix4x4Mappings": [
+                                {
+                                    "Name": "m_objectMatrix",
+                                    "Value": [
+                                        2.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        1.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        0.0,
+                                        1.0,
+                                        0.0,
+                                        -1.0,
+                                        0.0,
+                                        0.0,
+                                        1.0
+                                    ]
+                                }
+                            ]
+                        }
+                    }
+                },
+                {
+                    "Name": "CopyPass1",
+                    "TemplateName": "MultiGPUCopyImageToBufferPassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Input",
+                            "AttachmentRef": {
+                                "Pass": "TrianglePass2",
+                                "Attachment": "Output"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "CopyPassData",
+                        "CloneInput": false,
+                        "SourceDeviceIndex": 1,
+                        "DestinationDeviceIndex": 0
+                    }
+                },
+                {
+                    "Name": "CopyPass2",
+                    "TemplateName": "MultiGPUCopyBufferToBufferPassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Input",
+                            "AttachmentRef": {
+                                "Pass": "CopyPass1",
+                                "Attachment": "Output"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "CopyPassData",
+                        "CloneInput": true,
+                        "SourceDeviceIndex": 0,
+                        "DestinationDeviceIndex": 1
+                    }
+                },
+                {
+                    "Name": "CopyPass3",
+                    "TemplateName": "MultiGPUCopyBufferToImagePassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Input",
+                            "AttachmentRef": {
+                                "Pass": "CopyPass2",
+                                "Attachment": "Output"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "CopyPassData",
+                        "CloneInput": false,
+                        "SourceDeviceIndex": 1,
+                        "DestinationDeviceIndex": 0,
+                        "BufferSourceOffset": 0,
+                        "BufferSourceBytesPerRow": 1280,
+                        "BufferSourceBytesPerImage": 614400,
+                        "ImageSourceSize": {
+                            "Width": 320,
+                            "Height": 480
+                        }
+                    }
+                },
+                {
+                    "Name": "CopyPass4",
+                    "TemplateName": "CopyPassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Input",
+                            "AttachmentRef": {
+                                "Pass": "CopyPass3",
+                                "Attachment": "Output"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "CopyPassData",
+                        "CloneInput": true,
+                        "SourceDeviceIndex": 0,
+                        "DestinationDeviceIndex": 1
+                    }
+                },
+                {
+                    "Name": "CopyPass5",
+                    "TemplateName": "CopyPassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Input",
+                            "AttachmentRef": {
+                                "Pass": "CopyPass4",
+                                "Attachment": "Output"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "CopyPassData",
+                        "CloneInput": true,
+                        "SourceDeviceIndex": 1,
+                        "DestinationDeviceIndex": 0
+                    }
+                },
+                {
+                    "Name": "CompositePass",
+                    "TemplateName": "MultiGPUCompositePassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Input1",
+                            "AttachmentRef": {
+                                "Pass": "TrianglePass1",
+                                "Attachment": "Output"
+                            }
+                        },
+                        {
+                            "LocalSlot": "Input2",
+                            "AttachmentRef": {
+                                "Pass": "CopyPass5",
+                                "Attachment": "Output"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "FullscreenTrianglePassData",
+                        "ShaderAsset": {
+                            "FilePath": "Shaders/MultiGPURPIExample/Composite.shader"
+                        }
+                    }
+                },
+                {
+                    "Name": "ImGuiPass",
+                    "TemplateName": "ImGuiPassTemplate",
+                    "Enabled": true,
+                    "Connections": [
+                        {
+                            "LocalSlot": "InputOutput",
+                            "AttachmentRef": {
+                                "Pass": "CompositePass",
+                                "Attachment": "Output"
+                            }
+                        }
+                    ],
+                    "PassData": {
+                        "$type": "ImGuiPassData",
+                        "IsDefaultImGui": true
+                    }
+                },
+                {
+                    "Name": "CopyToSwapChain",
+                    "TemplateName": "FullscreenCopyTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Input",
+                            "AttachmentRef": {
+                                "Pass": "ImGuiPass",
+                                "Attachment": "InputOutput"
+                            }
+                        },
+                        {
+                            "LocalSlot": "Output",
+                            "AttachmentRef": {
+                                "Pass": "Parent",
+                                "Attachment": "PipelineOutput"
+                            }
+                        }
+                    ]
+                }
+            ]
+        }
+    }
+}

+ 50 - 0
Passes/MultiGPUPipeline.pass

@@ -13,10 +13,51 @@
                     "ScopeAttachmentUsage": "RenderTarget"
                 }
             ],
+            "ImageAttachments": [
+                {
+                    "Name": "TriangleAttachment1",
+                    "SizeSource": {
+                        "Source": {
+                            "Pass": "This",
+                            "Attachment": "PipelineOutput"
+                        },
+                        "Multipliers": {
+                            "WidthMultiplier": "0.5"
+                        }
+                    },
+                    "ImageDescriptor": {
+                        "Format": "R8G8B8A8_UNORM"
+                    }
+                },
+                {
+                    "Name": "TriangleAttachment2",
+                    "SizeSource": {
+                        "Source": {
+                            "Pass": "This",
+                            "Attachment": "PipelineOutput"
+                        },
+                        "Multipliers": {
+                            "WidthMultiplier": "0.5"
+                        }
+                    },
+                    "ImageDescriptor": {
+                        "Format": "R8G8B8A8_UNORM"
+                    }
+                }
+            ],
             "PassRequests": [
                 {
                     "Name": "TrianglePass1",
                     "TemplateName": "MultiGPUTrianglePassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Output",
+                            "AttachmentRef": {
+                                "Pass": "Parent",
+                                "Attachment": "TriangleAttachment1"
+                            }
+                        }
+                    ],
                     "PassData": {
                         "$type": "FullscreenTrianglePassData",
                         "ShaderAsset": {
@@ -52,6 +93,15 @@
                 {
                     "Name": "TrianglePass2",
                     "TemplateName": "MultiGPUTrianglePassTemplate",
+                    "Connections": [
+                        {
+                            "LocalSlot": "Output",
+                            "AttachmentRef": {
+                                "Pass": "Parent",
+                                "Attachment": "TriangleAttachment2"
+                            }
+                        }
+                    ],
                     "PassData": {
                         "$type": "FullscreenTrianglePassData",
                         "ShaderAsset": {

+ 0 - 26
Passes/MultiGPUTrianglePass.pass

@@ -23,32 +23,6 @@
                         "LoadAction": "Clear"
                     }
                 }
-            ],
-            "ImageAttachments": [
-                {
-                    "Name": "OutputAttachment",
-                    "SizeSource": {
-                        "Source": {
-                            "Pass": "Parent",
-                            "Attachment": "PipelineOutput"
-                        },
-                        "Multipliers": {
-                            "WidthMultiplier": "0.5"
-                        }
-                    },
-                    "ImageDescriptor": {
-                        "Format": "R8G8B8A8_UNORM"
-                    }
-                }
-            ],
-            "Connections": [
-                {
-                    "LocalSlot": "Output",
-                    "AttachmentRef": {
-                        "Pass": "This",
-                        "Attachment": "OutputAttachment"
-                    }
-                }
             ]
         }
     }