HairSkinningComputePass.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #pragma once
  9. #include <AzCore/Memory/SystemAllocator.h>
  10. #include <Atom/RHI.Reflect/Size.h>
  11. #include <Atom/RHI/DispatchItem.h>
  12. #include <Atom/RPI.Public/Pass/ComputePass.h>
  13. #include <Atom/RPI.Public/Shader/Shader.h>
  14. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  15. namespace AZ
  16. {
  17. namespace RHI
  18. {
  19. class DispatchItem;
  20. }
  21. namespace Render
  22. {
  23. namespace Hair
  24. {
  25. class HairDispatchItem;
  26. class HairFeatureProcessor;
  27. class HairRenderObject;
  28. enum class DispatchLevel;
  29. // This pass class serves for all skinning and simulation hair compute passes.
  30. //! The Skinning Compute passes are all using the following Srgs via the dispatchItem:
  31. //! - PerPassSrg: shared by all hair passes for the shared dynamic buffer and the PPLL buffers
  32. //! - HairGenerationSrg: dictates how to construct the hair vertices and skinning
  33. //! - HairSimSrg: defines vertices and tangent data shared between all passes
  34. class HairSkinningComputePass final
  35. : public RPI::ComputePass
  36. {
  37. AZ_RPI_PASS(HairSkinningComputePass);
  38. public:
  39. AZ_RTTI(HairSkinningComputePass, "{DC8D323E-41FF-4FED-89C6-A254FD6809FC}", RPI::ComputePass);
  40. AZ_CLASS_ALLOCATOR(HairSkinningComputePass, SystemAllocator);
  41. ~HairSkinningComputePass() = default;
  42. // Creates a HairSkinningComputePass
  43. static RPI::Ptr<HairSkinningComputePass> Create(const RPI::PassDescriptor& descriptor);
  44. bool BuildDispatchItem(HairRenderObject* hairObject, DispatchLevel dispatchLevel );
  45. //! Thread-safe function for adding the frame's dispatch items
  46. void AddDispatchItems(AZStd::list<Data::Instance<HairRenderObject>>& renderObjects);
  47. // Pass behavior overrides
  48. void CompileResources(const RHI::FrameGraphCompileContext& context) override;
  49. virtual bool IsEnabled() const override;
  50. //! Returns the shader held by the ComputePass
  51. Data::Instance<RPI::Shader> GetShader();
  52. void SetFeatureProcessor(HairFeatureProcessor* featureProcessor)
  53. {
  54. m_featureProcessor = featureProcessor;
  55. }
  56. void SetAllowIterations(bool allowIterations)
  57. {
  58. m_allowSimIterations = allowIterations;
  59. }
  60. protected:
  61. HairSkinningComputePass(const RPI::PassDescriptor& descriptor);
  62. void SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph) override;
  63. void BuildCommandListInternal(const RHI::FrameGraphExecuteContext& context) override;
  64. // Attach here all the pass buffers
  65. void InitializeInternal() override;
  66. void BuildInternal() override;
  67. void FrameBeginInternal(FramePrepareParams params) override;
  68. // ShaderReloadNotificationBus::Handler overrides...
  69. void OnShaderReinitialized(const AZ::RPI::Shader& shader) override;
  70. void OnShaderAssetReinitialized(const Data::Asset<AZ::RPI::ShaderAsset>& shaderAsset) override;
  71. void OnShaderVariantReinitialized(const AZ::RPI::ShaderVariant& shaderVariant) override;
  72. bool AcquireFeatureProcessor();
  73. void BuildShaderAndRenderData();
  74. private:
  75. HairFeatureProcessor* m_featureProcessor = nullptr;
  76. bool m_allowSimIterations = false;
  77. bool m_initialized = false;
  78. bool m_buildShaderAndData = false; // If shader is updated, mark it for build
  79. AZStd::mutex m_mutex;
  80. //! list of dispatch items, each represents a single hair object that
  81. //! will be used by the skinning compute shader.
  82. AZStd::unordered_set<const RHI::DispatchItem*> m_dispatchItems;
  83. //! List of new render objects that their Per Object (dynamic) Srg should be bound
  84. //! to the resources. Done once per pass per object only.
  85. AZStd::unordered_set<HairRenderObject*> m_newRenderObjects;
  86. };
  87. } // namespace Hair
  88. } // namespace Render
  89. } // namespace AZ