Skip to content

Commit

Permalink
Fix RootConstant setup in ProgramBindings constructor for DirectX
Browse files Browse the repository at this point in the history
  • Loading branch information
egorodet committed Sep 12, 2024
1 parent 293dd66 commit c3418b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>::max();;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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

0 comments on commit c3418b5

Please sign in to comment.