소스 검색

Added logic to boostrap component that run BRDF pipeline in console mode (#18531)

Co-authored-by: Piotr Jaroszek <[email protected]>
Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 8 달 전
부모
커밋
0ccf93c524
2개의 변경된 파일51개의 추가작업 그리고 35개의 파일을 삭제
  1. 48 35
      Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.cpp
  2. 3 0
      Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.h

+ 48 - 35
Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.cpp

@@ -446,6 +446,16 @@ namespace AZ
                         CreateDefaultRenderPipeline();
                     }
                 }
+                else
+                {
+                    AZ::ApplicationTypeQuery appType;
+                    AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType);
+                    // Run BRDF pipeline for the app in console mode, to use it in render-to-texture pipelines.
+                    if (appType.IsConsoleMode())
+                    {
+                        RunBRDFPipeline(m_defaultScene, nullptr);
+                    }
+                }
             }
 
             void BootstrapSystemComponent::OnWindowCreated(AzFramework::NativeWindowHandle windowHandle)
@@ -609,41 +619,7 @@ namespace AZ
                     }
                 }
 
-                // BRDF Texture Pipeline
-                {
-                    // As part of our initialization we need to create the BRDF texture generation pipeline
-
-                    // Save a reference to the generated BRDF texture so it doesn't get deleted if all the passes refering to it get deleted
-                    // and it's ref count goes to zero
-                    if (!m_brdfTexture)
-                    {
-                        const AZStd::shared_ptr<const RPI::PassTemplate> brdfTextureTemplate =
-                            RPI::PassSystemInterface::Get()->GetPassTemplate(Name("BRDFTextureTemplate"));
-                        Data::Asset<RPI::AttachmentImageAsset> brdfImageAsset = RPI::AssetUtils::LoadAssetById<RPI::AttachmentImageAsset>(
-                            brdfTextureTemplate->m_imageAttachments[0].m_assetRef.m_assetId, RPI::AssetUtils::TraceLevel::Error);
-                        if (brdfImageAsset.IsReady())
-                        {
-                            m_brdfTexture = RPI::AttachmentImage::FindOrCreate(brdfImageAsset);
-                        }
-                    }
-
-                    AZ::RPI::RenderPipelineDescriptor pipelineDesc;
-                    pipelineDesc.m_mainViewTagName = "MainCamera";
-                    pipelineDesc.m_rootPassTemplate = "BRDFTexturePipeline";
-                    pipelineDesc.m_executeOnce = true;
-
-                    for (int deviceIndex{ 0 }; deviceIndex < RHI::RHISystemInterface::Get()->GetDeviceCount(); ++deviceIndex)
-                    {
-                        pipelineDesc.m_name = AZStd::string::format("BRDFTexturePipeline_%d_%d", viewportContext->GetId(), deviceIndex);
-
-                        if (!scene->GetRenderPipeline(AZ::Name(pipelineDesc.m_name)))
-                        {
-                            RPI::RenderPipelinePtr brdfTexturePipeline = AZ::RPI::RenderPipeline::CreateRenderPipeline(pipelineDesc);
-                            brdfTexturePipeline->GetRootPass()->SetDeviceIndex(deviceIndex);
-                            scene->AddRenderPipeline(brdfTexturePipeline);
-                        }
-                    }
-                }
+                RunBRDFPipeline(scene, viewportContext);
 
                 // Load XR pipelines if applicable
                 if (xrSystem)
@@ -690,6 +666,43 @@ namespace AZ
                 return true;
             }
 
+            void BootstrapSystemComponent::RunBRDFPipeline(AZ::RPI::ScenePtr scene, AZ::RPI::ViewportContextPtr viewportContext)
+            {
+                // As part of our initialization we need to create the BRDF texture generation pipeline
+
+                // Save a reference to the generated BRDF texture so it doesn't get deleted if all the passes refering to it get deleted
+                // and it's ref count goes to zero
+                if (!m_brdfTexture)
+                {
+
+                    const AZStd::shared_ptr<const RPI::PassTemplate> brdfTextureTemplate =
+                        RPI::PassSystemInterface::Get()->GetPassTemplate(Name("BRDFTextureTemplate"));
+                    Data::Asset<RPI::AttachmentImageAsset> brdfImageAsset = RPI::AssetUtils::LoadAssetById<RPI::AttachmentImageAsset>(
+                        brdfTextureTemplate->m_imageAttachments[0].m_assetRef.m_assetId, RPI::AssetUtils::TraceLevel::Error);
+                    if (brdfImageAsset.IsReady())
+                    {
+                        m_brdfTexture = RPI::AttachmentImage::FindOrCreate(brdfImageAsset);
+                    }
+                }
+
+                AZ::RPI::RenderPipelineDescriptor pipelineDesc;
+                pipelineDesc.m_mainViewTagName = "MainCamera";
+                pipelineDesc.m_rootPassTemplate = "BRDFTexturePipeline";
+                pipelineDesc.m_executeOnce = true;
+                const AzFramework::ViewportId viewportId = viewportContext ? viewportContext->GetId() : AzFramework::InvalidViewportId;
+                for (int deviceIndex{ 0 }; deviceIndex < RHI::RHISystemInterface::Get()->GetDeviceCount(); ++deviceIndex)
+                {
+                    pipelineDesc.m_name = AZStd::string::format("BRDFTexturePipeline_%d_%d", viewportId, deviceIndex);
+
+                    if (!scene->GetRenderPipeline(AZ::Name(pipelineDesc.m_name)))
+                    {
+                        RPI::RenderPipelinePtr brdfTexturePipeline = AZ::RPI::RenderPipeline::CreateRenderPipeline(pipelineDesc);
+                        brdfTexturePipeline->GetRootPass()->SetDeviceIndex(deviceIndex);
+                        scene->AddRenderPipeline(brdfTexturePipeline);
+                    }
+                }
+            }
+
             void BootstrapSystemComponent::SwitchRenderPipeline(const AZ::RPI::RenderPipelineDescriptor& newRenderPipelineDesc, AZ::RPI::ViewportContextPtr viewportContext)
             {
                 AZ::RPI::RenderPipelineDescriptor pipelineDescriptor = newRenderPipelineDesc;

+ 3 - 0
Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.h

@@ -105,6 +105,9 @@ namespace AZ
                 void CreateViewportContext();
                 void SetWindowResolution();
 
+                //! Run the BRDF pipeline to generate the BRDF texture
+                void RunBRDFPipeline(AZ::RPI::ScenePtr scene, AZ::RPI::ViewportContextPtr viewportContext);
+
                 //! Load a render pipeline from disk and add it to the scene
                 RPI::RenderPipelinePtr LoadPipeline(
                     const AZ::RPI::ScenePtr scene,