AtomRenderOptions.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "AtomRenderOptions.h"
  9. #include <AzCore/Debug/Trace.h>
  10. #include <AzCore/Settings/SettingsRegistry.h>
  11. #include <AzCore/std/containers/queue.h>
  12. #include <AzCore/std/containers/unordered_set.h>
  13. #include <AzCore/std/containers/span.h>
  14. #include <Atom/RPI.Public/Pass/ParentPass.h>
  15. #include <Atom/RPI.Public/Pass/Pass.h>
  16. #include <Atom/RPI.Public/Pass/PassFilter.h>
  17. #include <Atom/RPI.Public/RPISystemInterface.h>
  18. #include <Atom/RPI.Public/RenderPipeline.h>
  19. #include <Atom/RPI.Public/ViewportContext.h>
  20. #include <Atom/RPI.Public/ViewportContextBus.h>
  21. namespace AZ::Render
  22. {
  23. RPI::RenderPipelinePtr GetDefaultViewportPipelinePtr()
  24. {
  25. RPI::RPISystemInterface* rpiSystem = RPI::RPISystemInterface::Get();
  26. if (!rpiSystem)
  27. {
  28. return nullptr;
  29. }
  30. AzFramework::NativeWindowHandle windowHandle = RPI::ViewportContextRequests::Get()->GetDefaultViewportContext()->GetWindowHandle();
  31. if (!windowHandle)
  32. {
  33. return nullptr;
  34. }
  35. return rpiSystem->GetRenderPipelineForWindow(windowHandle);
  36. }
  37. bool IsPassEnabled(const RPI::RenderPipeline& pipeline, const Name& name)
  38. {
  39. const RPI::Pass* pass = RPI::PassSystemInterface::Get()->FindFirstPass(RPI::PassFilter::CreateWithPassName(name, &pipeline));
  40. return pass ? pass->IsEnabled() : false;
  41. }
  42. bool EnablePass(const RPI::RenderPipeline& pipeline, const Name& passName, bool enable)
  43. {
  44. bool found = false;
  45. RPI::PassFilter passFilter = RPI::PassFilter::CreateWithPassName(passName, &pipeline);
  46. RPI::PassSystemInterface::Get()->ForEachPass(
  47. passFilter,
  48. [enable, &found](RPI::Pass* pass) -> RPI::PassFilterExecutionFlow
  49. {
  50. found = true;
  51. pass->SetEnabled(enable);
  52. return RPI::PassFilterExecutionFlow::ContinueVisitingPasses;
  53. });
  54. return found;
  55. }
  56. static void GetAllowedPassNamesInViewportOptionsMenu(AZStd::unordered_set<Name>& passNamesOut)
  57. {
  58. if (const auto* settingsRegistry = SettingsRegistry::Get(); settingsRegistry)
  59. {
  60. [[maybe_unused]] const bool found =
  61. settingsRegistry->GetObject(passNamesOut, "/O3DE/AtomRenderOptions/PassNamesInViewportOptionsMenu");
  62. AZ_Warning("AtomRenderOptions", found, "No AtomRenderOptions settings found from the settings registry");
  63. }
  64. }
  65. void GetViewportOptionsPasses(const RPI::RenderPipeline& pipeline, AZStd::vector<AZ::Name>& passNamesOut)
  66. {
  67. const auto& rootPass = pipeline.GetRootPass();
  68. if (!rootPass)
  69. {
  70. return;
  71. }
  72. AZStd::unordered_set<Name> allowedPassNames;
  73. GetAllowedPassNamesInViewportOptionsMenu(allowedPassNames);
  74. AZStd::queue<const RPI::Pass*> passes;
  75. passes.push(rootPass.get());
  76. while (!passes.empty())
  77. {
  78. const auto* pass = passes.front();
  79. passes.pop();
  80. if (allowedPassNames.contains(pass->GetName()))
  81. {
  82. passNamesOut.push_back(pass->GetName());
  83. }
  84. const auto* asParent = pass->AsParent();
  85. if (!asParent)
  86. {
  87. continue;
  88. }
  89. for (const auto& child : asParent->GetChildren())
  90. {
  91. passes.push(child.get());
  92. }
  93. }
  94. }
  95. } // namespace AZ::Render