MeshletsSystemComponent.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Modifications 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 <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/Serialization/EditContextConstants.inl>
  11. #include <Atom/RHI/Factory.h>
  12. #include <Atom/RPI.Public/RPISystemInterface.h>
  13. #include <Atom/RPI.Public/FeatureProcessorFactory.h>
  14. #include <MeshletsSystemComponent.h>
  15. #include <MeshletsFeatureProcessor.h>
  16. #include <MultiDispatchComputePass.h>
  17. namespace AZ
  18. {
  19. namespace Meshlets
  20. {
  21. void MeshletsSystemComponent::Reflect(AZ::ReflectContext* context)
  22. {
  23. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  24. {
  25. serialize->Class<MeshletsSystemComponent, AZ::Component>()
  26. ->Version(0)
  27. ;
  28. if (AZ::EditContext* ec = serialize->GetEditContext())
  29. {
  30. ec->Class<MeshletsSystemComponent>("Meshlets", "[Description of functionality provided by this System Component]")
  31. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  32. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  33. ;
  34. }
  35. }
  36. Meshlets::MeshletsFeatureProcessor::Reflect(context);
  37. }
  38. void MeshletsSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  39. {
  40. provided.push_back(AZ_CRC_CE("MeshletsService"));
  41. }
  42. void MeshletsSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  43. {
  44. incompatible.push_back(AZ_CRC_CE("MeshletsService"));
  45. }
  46. void MeshletsSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  47. {
  48. required.push_back(AZ::RHI::Factory::GetComponentService());
  49. required.push_back(AZ_CRC_CE("AssetDatabaseService"));
  50. required.push_back(AZ_CRC_CE("RPISystem"));
  51. }
  52. void MeshletsSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  53. {
  54. }
  55. MeshletsSystemComponent::MeshletsSystemComponent()
  56. {
  57. if (MeshletsInterface::Get() == nullptr)
  58. {
  59. MeshletsInterface::Register(this);
  60. }
  61. }
  62. MeshletsSystemComponent::~MeshletsSystemComponent()
  63. {
  64. if (MeshletsInterface::Get() == this)
  65. {
  66. MeshletsInterface::Unregister(this);
  67. }
  68. }
  69. void MeshletsSystemComponent::Init()
  70. {
  71. }
  72. void MeshletsSystemComponent::LoadPassTemplateMappings()
  73. {
  74. auto* passSystem = AZ::RPI::PassSystemInterface::Get();
  75. AZ_Assert(passSystem, "Meshlets Gem - cannot get the pass system.");
  76. const char* passTemplatesFile = "Passes/MeshletsPassTemplates.azasset";
  77. passSystem->LoadPassTemplateMappings(passTemplatesFile);
  78. }
  79. void MeshletsSystemComponent::Activate()
  80. {
  81. // Feature processor
  82. AZ::RPI::FeatureProcessorFactory::Get()->RegisterFeatureProcessor<Meshlets::MeshletsFeatureProcessor>();
  83. auto* passSystem = AZ::RPI::PassSystemInterface::Get();
  84. AZ_Assert(passSystem, "Cannot get the pass system.");
  85. // Setup handler for load pass templates mappings
  86. m_loadTemplatesHandler = AZ::RPI::PassSystemInterface::OnReadyLoadTemplatesEvent::Handler([this]() { this->LoadPassTemplateMappings(); });
  87. passSystem->ConnectEvent(m_loadTemplatesHandler);
  88. passSystem->AddPassCreator(AZ::Name("MultiDispatchComputePass"), &MultiDispatchComputePass::Create);
  89. passSystem->AddPassCreator(AZ::Name("MeshletsRenderPass"), &MeshletsRenderPass::Create);
  90. MeshletsRequestBus::Handler::BusConnect();
  91. AZ::TickBus::Handler::BusConnect();
  92. }
  93. void MeshletsSystemComponent::Deactivate()
  94. {
  95. AZ::TickBus::Handler::BusDisconnect();
  96. MeshletsRequestBus::Handler::BusDisconnect();
  97. AZ::RPI::FeatureProcessorFactory::Get()->UnregisterFeatureProcessor<Meshlets::MeshletsFeatureProcessor>();
  98. }
  99. void MeshletsSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
  100. {
  101. }
  102. } // namespace Meshlets
  103. } // namespace AZ