Skip to content

Commit

Permalink
Optimize update root-constant resource views for Metal
Browse files Browse the repository at this point in the history
  • Loading branch information
egorodet committed Sep 26, 2024
1 parent 24a72ca commit de67bb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rhi::IProgramBindings::IArgumentBindingCallback>::Emit(
&Rhi::IProgramBindings::IArgumentBindingCallback::OnProgramArgumentBindingRootConstantChanged,
std::cref(*this), std::cref(root_constant)
);
return true;
}

void ProgramArgumentBinding::UpdateArgumentBufferOffsets(const Program& program)
{
META_FUNCTION_TASK();
Expand All @@ -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<Rhi::IProgramBindings::IArgumentBindingCallback>::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)
Expand Down

0 comments on commit de67bb0

Please sign in to comment.