MorphTargetDispatchItem.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <Atom/Feature/MorphTargets/MorphTargetInputBuffers.h>
  10. #include <Atom/RPI.Public/Shader/ShaderReloadNotificationBus.h>
  11. #include <Atom/RHI/DispatchItem.h>
  12. #include <Atom/RHI/ConstantsData.h>
  13. #include <AtomCore/Instance/Instance.h>
  14. namespace AZ
  15. {
  16. namespace RHI
  17. {
  18. class BufferView;
  19. class PipelineState;
  20. }
  21. namespace RPI
  22. {
  23. class Buffer;
  24. class ModelLod;
  25. class Shader;
  26. class ShaderResourceGroup;
  27. }
  28. namespace Render
  29. {
  30. class SkinnedMeshFeatureProcessor;
  31. //! Holds and manages an RHI DispatchItem for a specific morph target, and the resources that are needed to build and maintain it.
  32. class MorphTargetDispatchItem
  33. : private RPI::ShaderReloadNotificationBus::Handler
  34. {
  35. public:
  36. AZ_CLASS_ALLOCATOR(MorphTargetDispatchItem, AZ::SystemAllocator);
  37. MorphTargetDispatchItem() = delete;
  38. //! Create one dispatch item per morph target
  39. explicit MorphTargetDispatchItem(
  40. const AZStd::intrusive_ptr<MorphTargetInputBuffers> inputBuffers,
  41. const MorphTargetComputeMetaData& morphTargetMetaData,
  42. SkinnedMeshFeatureProcessor* skinnedMeshFeatureProcessor,
  43. MorphTargetInstanceMetaData morphInstanceMetaData,
  44. float accumulatedDeltaRange
  45. );
  46. ~MorphTargetDispatchItem();
  47. // The event handler cannot be copied
  48. AZ_DISABLE_COPY_MOVE(MorphTargetDispatchItem);
  49. bool Init();
  50. const AZ::RHI::DispatchItem& GetRHIDispatchItem() const;
  51. void SetWeight(float weight);
  52. float GetWeight() const;
  53. private:
  54. bool InitPerInstanceSRG();
  55. void InitRootConstants(const RHI::ConstantsLayout* rootConstantsLayout);
  56. // ShaderInstanceNotificationBus::Handler overrides
  57. void OnShaderReinitialized(const RPI::Shader& shader) override;
  58. void OnShaderAssetReinitialized(const Data::Asset<RPI::ShaderAsset>& shaderAsset) override;
  59. void OnShaderVariantReinitialized(const RPI::ShaderVariant& shaderVariant) override;
  60. RHI::DispatchItem m_dispatchItem;
  61. // The morph target shader used for this instance
  62. Data::Instance<RPI::Shader> m_morphTargetShader;
  63. // The vertex deltas
  64. AZStd::intrusive_ptr<MorphTargetInputBuffers> m_inputBuffers;
  65. // The per-object shader resource group
  66. Data::Instance<RPI::ShaderResourceGroup> m_instanceSrg;
  67. // Metadata used to set the root constants for the shader
  68. MorphTargetComputeMetaData m_morphTargetComputeMetaData;
  69. AZ::RHI::ConstantsData m_rootConstantData;
  70. // Per-SkinnedMeshInstance constants for morph targets
  71. MorphTargetInstanceMetaData m_morphInstanceMetaData;
  72. // A conservative value for encoding/decoding the accumulated deltas
  73. float m_accumulatedDeltaIntegerEncoding;
  74. // Keep track of the constant index of m_weight since it is updated frequently
  75. RHI::ShaderInputConstantIndex m_weightIndex;
  76. };
  77. } // namespace Render
  78. } // namespace AZ