From de67bb019901ab3c430cfe78689d2529a113dc8b Mon Sep 17 00:00:00 2001 From: Evgeny Gorodetskiy Date: Thu, 26 Sep 2024 23:57:32 +0300 Subject: [PATCH] Optimize update root-constant resource views for Metal --- .../Graphics/Metal/ProgramArgumentBinding.hh | 5 ++-- .../Graphics/Metal/ProgramArgumentBinding.mm | 26 ++++--------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/ProgramArgumentBinding.hh b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/ProgramArgumentBinding.hh index 6b66ba490..55b9f3992 100644 --- a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/ProgramArgumentBinding.hh +++ b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/ProgramArgumentBinding.hh @@ -63,7 +63,6 @@ public: // IArgumentBinding interface bool SetResourceViews(const Rhi::ResourceViews& resource_views) override; - bool SetRootConstant(const Rhi::RootConstant& root_constant) override; void UpdateArgumentBufferOffsets(const Program& program); @@ -78,8 +77,8 @@ public: const NativeOffsets& GetBufferOffsets() const noexcept { return m_mtl_buffer_offsets; } protected: - // IRootConstantBufferCallback overrides... - void OnRootConstantBufferChanged(Base::RootConstantBuffer& root_constant_buffer) override; + // Base::ProgramArgumentBinding overrides... + bool UpdateRootConstantResourceViews() override; private: void SetMetalResourcesForViews(const Rhi::ResourceViews& resource_views); diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramArgumentBinding.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramArgumentBinding.mm index 418cbd161..5a0440d8a 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramArgumentBinding.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramArgumentBinding.mm @@ -121,23 +121,6 @@ static MTLRenderStages ConvertShaderTypeToMetalRenderStages(Rhi::ShaderType shad return true; } -bool ProgramArgumentBinding::SetRootConstant(const Rhi::RootConstant& root_constant) -{ - META_FUNCTION_TASK(); - CallbackBlocker callback_blocker(*this); - - if (!Base::ProgramArgumentBinding::SetRootConstant(root_constant)) - return false; - - SetMetalResourcesForViews(Base::ProgramArgumentBinding::GetResourceViews()); - - Data::Emitter::Emit( - &Rhi::IProgramBindings::IArgumentBindingCallback::OnProgramArgumentBindingRootConstantChanged, - std::cref(*this), std::cref(root_constant) - ); - return true; -} - void ProgramArgumentBinding::UpdateArgumentBufferOffsets(const Program& program) { META_FUNCTION_TASK(); @@ -162,18 +145,19 @@ static MTLRenderStages ConvertShaderTypeToMetalRenderStages(Rhi::ShaderType shad } } -void ProgramArgumentBinding::OnRootConstantBufferChanged(Base::RootConstantBuffer& root_constant_buffer) +bool ProgramArgumentBinding::UpdateRootConstantResourceViews() { - META_FUNCTION_TASK(); - Base::ProgramArgumentBinding::OnRootConstantBufferChanged(root_constant_buffer); + if (!Base::ProgramArgumentBinding::UpdateRootConstantResourceViews()) + return false; SetMetalResourcesForViews(Base::ProgramArgumentBinding::GetResourceViews()); const Rhi::RootConstant root_constants = GetRootConstant(); Data::Emitter::Emit( - &Rhi::IProgramBindings::IArgumentBindingCallback::OnProgramArgumentBindingRootConstantChanged, + &Rhi::IProgramArgumentBindingCallback::OnProgramArgumentBindingRootConstantChanged, std::cref(*this), std::cref(root_constants) ); + return true; } void ProgramArgumentBinding::SetMetalResourcesForViews(const Rhi::ResourceViews& resource_views)