From c3418b58e65aa202579613eca00facb46e32a374 Mon Sep 17 00:00:00 2001 From: Evgeny Gorodetsky Date: Thu, 12 Sep 2024 23:19:18 +0300 Subject: [PATCH] Fix RootConstant setup in ProgramBindings constructor for DirectX --- .../Graphics/DirectX/ProgramArgumentBinding.h | 6 ++++ .../DirectX/ProgramArgumentBinding.cpp | 30 +++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Modules/Graphics/RHI/DirectX/Include/Methane/Graphics/DirectX/ProgramArgumentBinding.h b/Modules/Graphics/RHI/DirectX/Include/Methane/Graphics/DirectX/ProgramArgumentBinding.h index ba687174e..4fab5e44f 100644 --- a/Modules/Graphics/RHI/DirectX/Include/Methane/Graphics/DirectX/ProgramArgumentBinding.h +++ b/Modules/Graphics/RHI/DirectX/Include/Methane/Graphics/DirectX/ProgramArgumentBinding.h @@ -97,7 +97,13 @@ class ProgramArgumentBinding final // NOSONAR - custom destructor is required void SetDescriptorRange(const DescriptorRange& descriptor_range); void SetDescriptorHeapReservation(const DescriptorHeapReservation* p_reservation); +protected: + // IRootConstantBufferCallback overrides... + void OnRootConstantBufferChanged(Base::RootConstantBuffer& root_constant_buffer) override; + private: + void UpdateDirectResourceViews(const Rhi::ResourceViews& resource_views); + const Settings m_settings_dx; const Rhi::ResourceUsageMask m_shader_usage; uint32_t m_root_parameter_index = std::numeric_limits::max();; diff --git a/Modules/Graphics/RHI/DirectX/Sources/Methane/Graphics/DirectX/ProgramArgumentBinding.cpp b/Modules/Graphics/RHI/DirectX/Sources/Methane/Graphics/DirectX/ProgramArgumentBinding.cpp index 6014781cb..d68c2b168 100644 --- a/Modules/Graphics/RHI/DirectX/Sources/Methane/Graphics/DirectX/ProgramArgumentBinding.cpp +++ b/Modules/Graphics/RHI/DirectX/Sources/Methane/Graphics/DirectX/ProgramArgumentBinding.cpp @@ -148,15 +148,7 @@ bool ProgramArgumentBinding::SetRootConstant(const Rhi::RootConstant& root_const if (!Base::ProgramArgumentBinding::SetRootConstant(root_constant)) return false; - const Rhi::ResourceViews& resource_views = Base::ProgramArgumentBinding::GetResourceViews(); - - m_resource_views_dx.clear(); - std::transform(resource_views.begin(), resource_views.end(), std::back_inserter(m_resource_views_dx), - [this](const Rhi::ResourceView& resource_view) - { return ResourceView(resource_view, m_shader_usage); }); - - // Request complete initialization to update root constant buffer views - GetContext().RequestDeferredAction(Rhi::ContextDeferredAction::CompleteInitialization); + UpdateDirectResourceViews(Base::ProgramArgumentBinding::GetResourceViews()); return true; } @@ -185,4 +177,24 @@ void ProgramArgumentBinding::SetDescriptorHeapReservation(const DescriptorHeapRe m_p_descriptor_heap_reservation = p_reservation; } +void ProgramArgumentBinding::OnRootConstantBufferChanged(Base::RootConstantBuffer& root_constant_buffer) +{ + META_FUNCTION_TASK(); + Base::ProgramArgumentBinding::OnRootConstantBufferChanged(root_constant_buffer); + UpdateDirectResourceViews(Base::ProgramArgumentBinding::GetResourceViews()); +} + +void ProgramArgumentBinding::UpdateDirectResourceViews(const Rhi::ResourceViews& resource_views) +{ + META_FUNCTION_TASK(); + m_resource_views_dx.clear(); + + std::transform(resource_views.begin(), resource_views.end(), std::back_inserter(m_resource_views_dx), + [this](const Rhi::ResourceView& resource_view) + { return ResourceView(resource_view, m_shader_usage); }); + + // Request complete initialization to update root constant buffer views + GetContext().RequestDeferredAction(Rhi::ContextDeferredAction::CompleteInitialization); +} + } // namespace Methane::Graphics::DirectX