소스 검색

Update subpass examples to match new API (#689)

Signed-off-by: Akio Gaule <[email protected]>
Akio Gaule 10 달 전
부모
커밋
a36d288e09

+ 2 - 1
Gem/Code/Source/RHI/SubpassExampleComponent.cpp

@@ -391,6 +391,7 @@ namespace AtomSampleViewer
                     AZ::RHI::ScopeAttachmentStage::EarlyFragmentTest | AZ::RHI::ScopeAttachmentStage::LateFragmentTest);
             }
 
+            frameGraph.SetGroupId(AZ::Name(SubpassInputExample::SampleName));
             frameGraph.SetEstimatedItemCount(m_meshCount);
         };
 
@@ -499,7 +500,7 @@ namespace AtomSampleViewer
                     dsDesc, RHI::ScopeAttachmentAccess::Read,
                     RHI::ScopeAttachmentStage::EarlyFragmentTest | RHI::ScopeAttachmentStage::LateFragmentTest);
             }
-
+            frameGraph.SetGroupId(AZ::Name(SubpassInputExample::SampleName));
             frameGraph.SetEstimatedItemCount(1);
         };
 

+ 9 - 7
Gem/Code/Source/Subpass_RPI_ExampleComponent.cpp

@@ -84,17 +84,18 @@ namespace AtomSampleViewer
         }
 
         // Create the pipeline.
-        const auto pipelineOptionIdx = static_cast<size_t>(pipelineOption);
         AZ::RPI::RenderPipelineDescriptor pipelineDesc;
         pipelineDesc.m_mainViewTagName = "MainCamera";
         pipelineDesc.m_materialPipelineTag = "MultiViewPipeline";
-        pipelineDesc.m_name = PipelineOptions[pipelineOptionIdx].m_pipelineName;
-        pipelineDesc.m_rootPassTemplate = PipelineOptions[pipelineOptionIdx].m_rootPassTemplate;
+        pipelineDesc.m_name = "SubpassesPipeline";
+        pipelineDesc.m_rootPassTemplate = "SubpassesPipelineTemplate";
         pipelineDesc.m_renderSettings.m_multisampleState.m_samples = 1;
+        pipelineDesc.m_allowSubpassMerging = pipelineOption == AvailablePipelines::TwoSubpassesPipeline;
 
         m_activePipeline = AZ::RPI::RenderPipeline::CreateRenderPipelineForWindow(pipelineDesc, *m_windowContext);
-        AZ_Assert(m_activePipeline != nullptr, "Failed to create render pipeline with name='%s' and template='%s'.",
-            PipelineOptions[pipelineOptionIdx].m_pipelineName, PipelineOptions[pipelineOptionIdx].m_rootPassTemplate);
+        AZ_Assert(
+            m_activePipeline != nullptr, "Failed to create render pipeline with name='%s' and template='%s'.", pipelineDesc.m_name.c_str(),
+            pipelineDesc.m_rootPassTemplate.c_str());
 
         // Activate the pipeline
         m_activePipeline->GetRootPass()->SetEnabled(true); // PassSystem::RemoveRenderPipeline was calling SetEnabled(false)
@@ -106,8 +107,9 @@ namespace AtomSampleViewer
         }
 
         m_activePipelineOption = pipelineOption;
-        AZ_TracePrintf(LogName, "New active pipeline is '%s' from template '%s'",
-            PipelineOptions[pipelineOptionIdx].m_pipelineName,  PipelineOptions[pipelineOptionIdx].m_rootPassTemplate);
+        AZ_TracePrintf(
+            LogName, "New active pipeline is '%s' from template '%s'", pipelineDesc.m_name.c_str(),
+            pipelineDesc.m_rootPassTemplate.c_str());
     }
 
     void Subpass_RPI_ExampleComponent::RestoreOriginalPipeline()

+ 0 - 11
Gem/Code/Source/Subpass_RPI_ExampleComponent.h

@@ -86,17 +86,6 @@ namespace AtomSampleViewer
         static constexpr char DefaultModelPath[] = "materialeditor/viewportmodels/hermanubis.fbx.azmodel";
         static constexpr char DefaultGroundPlaneModelPath[] = "objects/plane.fbx.azmodel";
 
-        struct PipelineOption
-        {
-            char m_pipelineName[256];
-            char m_rootPassTemplate[256];
-        };
-
-        const AZStd::array<PipelineOption, 2> PipelineOptions = {{
-            { "TwoSubpassesPipeline", "TwoSubpassesPipelineTemplate" },
-            { "TwoPassesPipeline", "TwoPassesPipelineTemplate" }
-        }};
-
         AvailablePipelines m_activePipelineOption = AvailablePipelines::TwoSubpassesPipeline;
 
         //! Original render pipeline when the sample was started.

+ 4 - 12
Passes/ASV/PassTemplates.azasset

@@ -120,25 +120,17 @@
                 "Name": "DeferredLightingPassTemplate",
                 "Path": "Passes/PrototypeDeferredPipeline/DeferredLighting.pass"
             },
-            {
-                "Name": "ForwardPassExampleTemplate",
-                "Path": "Passes/SubpassExample/TwoPasses/ForwardPass.pass"
-            },
-            {
-                "Name": "TwoPassesPipelineTemplate",
-                "Path": "Passes/SubpassExample/TwoPasses/TwoPassesPipeline.pass"
-            },
             {
                 "Name": "ForwardSubpassExampleTemplate",
-                "Path": "Passes/SubpassExample/TwoSubpasses/ForwardSubpass.pass"
+                "Path": "Passes/SubpassExample/ForwardSubpass.pass"
             },
             {
                 "Name": "SkyBoxSubpassExampleTemplate",
-                "Path": "Passes/SubpassExample/TwoSubpasses/SkyBoxSubpass.pass"
+                "Path": "Passes/SubpassExample/SkyBoxSubpass.pass"
             },
             {
-                "Name": "TwoSubpassesPipelineTemplate",
-                "Path": "Passes/SubpassExample/TwoSubpasses/TwoSubpassesPipeline.pass"
+                "Name": "SubpassesPipelineTemplate",
+                "Path": "Passes/SubpassExample/SubpassesPipeline.pass"
             }
         ]
     }

+ 0 - 3
Passes/SubpassExample/TwoSubpasses/ForwardSubpass.pass → Passes/SubpassExample/ForwardSubpass.pass

@@ -32,9 +32,6 @@
                         },
                         "LoadAction": "Clear",
                         "LoadActionStencil": "DontCare",
-                        // The depth buffer won't be used after the two subpasses are completed.
-                        // For efficiency's sake do not Store.
-                        "StoreAction": "DontCare",
                         "StoreActionStencil": "DontCare"
                     }
                 },

+ 0 - 0
Passes/SubpassExample/TwoSubpasses/SkyBoxSubpass.pass → Passes/SubpassExample/SkyBoxSubpass.pass


+ 1 - 1
Passes/SubpassExample/TwoSubpasses/TwoSubpassesPipeline.pass → Passes/SubpassExample/SubpassesPipeline.pass

@@ -4,7 +4,7 @@
     "ClassName": "PassAsset",
     "ClassData": {
         "PassTemplate": {
-            "Name": "TwoSubpassesPipelineTemplate",
+            "Name": "SubpassesPipelineTemplate",
             "PassClass": "ParentPass",
             "Slots": [
                 {

+ 0 - 105
Passes/SubpassExample/TwoPasses/ForwardPass.pass

@@ -1,105 +0,0 @@
-{
-    "Type": "JsonSerialization",
-    "Version": 1,
-    "ClassName": "PassAsset",
-    "ClassData": {
-        "PassTemplate": {
-            "Name": "ForwardPassExampleTemplate",
-            "PassClass": "RasterPass",
-            "Slots": [
-                // Inputs...
-                {
-                    "Name": "BRDFTextureInput",
-                    "ShaderInputName": "m_brdfMap",
-                    "SlotType": "Input",
-                    "ScopeAttachmentUsage": "Shader"
-                },
-                // Outputs...
-                {
-                    "Name": "DepthOutput",
-                    "SlotType": "Output",
-                    "ScopeAttachmentUsage": "DepthStencil",
-                    // Specifying the AspectFlags is very important
-                    // when using Subpasses because it avoids Validation errors.
-                    "ImageViewDesc": {
-                        "AspectFlags": [
-                            "Depth"
-                        ]
-                    },
-                    "LoadStoreAction": {
-                        "ClearValue": {
-                            "Type": "DepthStencil"
-                        },
-                        "LoadAction": "Clear",
-                        "LoadActionStencil": "DontCare",
-                        // Very important to Store the tile back to memory when using independent passes.
-                        "StoreAction": "Store",
-                        "StoreActionStencil": "DontCare"
-                    }
-                },
-                {
-                    "Name": "LightingOutput",
-                    "SlotType": "Output",
-                    "ScopeAttachmentUsage": "RenderTarget",
-                    "LoadStoreAction": {
-                        "ClearValue": {
-                            "Value": [
-                                0.0,
-                                0.0,
-                                0.0,
-                                0.0
-                            ]
-                        },
-                        "LoadAction": "Clear",
-                        "StoreAction": "Store"
-                    }
-                }
-            ],
-            "ImageAttachments": [          
-                {
-                    "Name": "DepthAttachment",
-                    "SizeSource": {
-                      "Source": {
-                        "Pass": "Parent",
-                        "Attachment": "PipelineOutput"
-                      }
-                    },
-                    "ImageDescriptor": {
-                      "Format": "D32_FLOAT_S8X24_UINT",
-                      "SharedQueueMask": "Graphics"
-                    }
-                },
-                {
-                    "Name": "BRDFTexture",
-                    "Lifetime": "Imported",
-                    "AssetRef": {
-                        "FilePath": "Textures/BRDFTexture.attimage"
-                    }
-                }
-            ],
-            "Connections": [
-                {
-                  "LocalSlot": "DepthOutput",
-                  "AttachmentRef": {
-                    "Pass": "This",
-                    "Attachment": "DepthAttachment"
-                  }
-                },
-                {
-                    "LocalSlot": "LightingOutput",
-                    "AttachmentRef": {
-                        "Pass": "Parent",
-                        "Attachment": "PipelineOutput"
-                    }
-                },
-                {
-                    "LocalSlot": "BRDFTextureInput",
-                    "AttachmentRef": {
-                        "Pass": "This",
-                        "Attachment": "BRDFTexture"
-                    }
-                }
-            ]
-        }
-    }
-}

+ 0 - 61
Passes/SubpassExample/TwoPasses/TwoPassesPipeline.pass

@@ -1,61 +0,0 @@
-{
-    "Type": "JsonSerialization",
-    "Version": 1,
-    "ClassName": "PassAsset",
-    "ClassData": {
-        "PassTemplate": {
-            "Name": "TwoPassesPipelineTemplate",
-            "PassClass": "ParentPass",
-            "Slots": [
-                {
-                    "Name": "PipelineOutput",
-                    "SlotType": "InputOutput"
-                }
-            ],
-            "PassData": {
-                "$type": "PassData",
-                "PipelineGlobalConnections": [
-                    {
-                        "GlobalName": "PipelineOutput",
-                        "Slot": "PipelineOutput"
-                    }
-                ]
-            },
-            "PassRequests": [
-                {
-                    "Name": "ForwardPass",
-                    "TemplateName": "ForwardPassExampleTemplate",
-                    "PassData": {
-                        "$type": "RasterPassData",
-                        "DrawListTag": "multiViewForward",
-                        "BindViewSrg": true,
-                        "PassSrgShaderAsset": {
-                            "FilePath": "Shaders/ForwardPassSrg.shader"
-                        }
-                    }
-                },
-                {
-                    "Name": "SkyBoxPass",
-                    "TemplateName": "MultiViewSkyBoxTemplate",
-                    "Enabled": true,
-                    "Connections": [
-                        {
-                            "LocalSlot": "SpecularInputOutput",
-                            "AttachmentRef": {
-                                "Pass": "ForwardPass",
-                                "Attachment": "LightingOutput"
-                            }
-                        },
-                        {
-                            "LocalSlot": "SkyBoxDepth",
-                            "AttachmentRef": {
-                                "Pass": "ForwardPass",
-                                "Attachment": "DepthOutput"
-                            }
-                        }
-                    ]
-                }
-            ]
-        }
-    }
-}

+ 4 - 3
Shaders/RHI/SubpassInputComposition.azsl

@@ -51,9 +51,10 @@ PSOutput MainPS(float4 screenPos : SV_POSITION)
 
     PSOutput OUT;
 
-    float3 position = SubpassInputsSrg::m_position.SubpassLoad().xyz;
-    float3 normal = SubpassInputsSrg::m_normal.SubpassLoad().xyz;
-    float4 albedo = SubpassInputsSrg::m_albedo.SubpassLoad();
+    int3 loadPos = int3(screenPos.x, screenPos.y, 0);
+    float3 position = SubpassInputsSrg::m_position.SubpassLoad(loadPos).xyz;
+    float3 normal = SubpassInputsSrg::m_normal.SubpassLoad(loadPos).xyz;
+    float4 albedo = SubpassInputsSrg::m_albedo.SubpassLoad(loadPos);
 
     // Ambient part
     const float3 lightDir = normalize(float3(-1, -1, -1));

+ 2 - 1
Shaders/SubpassExample/SkyBoxSubpass.azsl

@@ -128,7 +128,8 @@ PSOutput MainPS(VSOutput input)
         discard;
     }
 
-    const float zDepth = PassSrg::m_depthInput.SubpassLoad().x;
+    int3 loadPos = int3(input.m_position.x, input.m_position.y, 0);
+    const float zDepth = PassSrg::m_depthInput.SubpassLoad(loadPos).x;
     if (zDepth > 0.0)
     {
         //TODO: discard or clip(-1)?

+ 16 - 1
Shaders/SubpassExample/SkyBoxSubpass.shader

@@ -22,5 +22,20 @@
           "type": "Fragment"
         }
       ]
-    }
+    },
+    "Supervariants":
+    [
+        {
+            "Name": "",
+            "AddBuildArguments": {
+                "azslc": ["--no-subpass-input"]
+            }
+        },
+        {
+            "Name": "SubpassInput",
+            "RemoveBuildArguments": {
+                "azslc": ["--no-subpass-input"]
+            }
+        }
+    ]
 }