Skip to content

Commit

Permalink
Add program bindings tests of root-constant values
Browse files Browse the repository at this point in the history
  • Loading branch information
egorodet committed Oct 5, 2024
1 parent 6ec0bd1 commit e9aaa06
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ class Program
Program(const Context& context, const Settings& settings);

// IProgram interface
const Settings& GetSettings() const noexcept final { return m_settings; }
const Rhi::ShaderTypes& GetShaderTypes() const noexcept final { return m_shader_types; }
const Settings& GetSettings() const noexcept final { return m_settings; }
const Rhi::ShaderTypes& GetShaderTypes() const noexcept final { return m_shader_types; }
const Ptr<Rhi::IShader>& GetShader(Rhi::ShaderType shader_type) const final;
bool HasShader(Rhi::ShaderType shader_type) const { return !!GetShader(shader_type); }
Data::Size GetBindingsCount() const noexcept final { return m_bindings_count; }
bool HasShader(Rhi::ShaderType shader_type) const { return !!GetShader(shader_type); }
Data::Size GetBindingsCount() const noexcept final { return m_bindings_count; }

// IObject overrides
bool SetName(std::string_view name) override;

const Context& GetContext() const { return m_context; }
RootConstantBuffer& GetRootConstantBuffer() { return m_root_constant_buffer; }
RootConstantBuffer& GetRootMutableBuffer() { return m_root_mutable_buffer; }
RootConstantBuffer& GetRootFrameConstantBuffer(Data::Index frame_index);
RootConstantBuffer& GetRootConstantBuffer(Rhi::ProgramArgumentAccessType access_type, uint32_t frame_index = 0U);
const Context& GetContext() const { return m_context; }
RootConstantBuffer& GetRootConstantBuffer() { return m_root_constant_buffer; }
RootConstantBuffer& GetRootMutableBuffer() { return m_root_mutable_buffer; }
RootConstantBuffer& GetRootFrameConstantBuffer(Data::Index frame_index);
RootConstantBuffer& GetRootConstantBuffer(Rhi::ProgramArgumentAccessType access_type, uint32_t frame_index = 0U);

protected:
using ArgumentBinding = ProgramBindings::ArgumentBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ void Program::InitArgumentBindings()
}

if (m_context.GetType() != Rhi::IContext::Type::Render)
{
const auto frame_constant_binding_by_arg_it =
std::find_if(m_binding_by_argument.begin(), m_binding_by_argument.end(),
[](const std::pair<Rhi::ProgramArgument, Ptr<ArgumentBinding>>& arg_binding)
{ return arg_binding.second->GetSettings().argument.IsFrameConstant(); });
META_CHECK_TRUE_DESCR(frame_constant_binding_by_arg_it == m_binding_by_argument.end(),
"frame-constant argument binding was found for program created with non-render context");
return;
}

// Create frame-constant argument bindings only when program is created in render context
m_frame_bindings_by_argument.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Program // NOSONAR - constructors and assignment operators are required to
using Arguments = ProgramArguments;
using ArgumentAccessor = ProgramArgumentAccessor;
using ArgumentAccessors = ProgramArgumentAccessors;
using BindingValueByArgument = IProgram::BindingValueByArgument;
using BindingValueByArgument = ProgramBindingValueByArgument;

META_PIMPL_DEFAULT_CONSTRUCT_METHODS_DECLARE(Program);
META_PIMPL_METHODS_COMPARE_DECLARE(Program);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct ResourceArgumentDesc
{
Rhi::ResourceType resource_type;
uint32_t resource_count;
uint32_t buffer_size;
};

using ResourceArgumentDescs = std::map<Rhi::ProgramArgumentAccessor, ResourceArgumentDesc>;
Expand All @@ -50,7 +51,7 @@ class Shader final
void InitArgumentBindings(const ResourceArgumentDescs& argument_descriptions);

private:
Ptrs<Base::ProgramArgumentBinding> m_argument_bindings;
ResourceArgumentDescs m_argument_descriptions;
};

} // namespace Methane::Graphics::Null
23 changes: 14 additions & 9 deletions Modules/Graphics/RHI/Null/Sources/Methane/Graphics/Null/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ namespace Methane::Graphics::Null

Ptrs<Base::ProgramArgumentBinding> Shader::GetArgumentBindings(const Rhi::ProgramArgumentAccessors&) const
{
return m_argument_bindings;
}
// Argument binding pointers are not stored by shader, so that program is the only owner of them:
Ptrs<Base::ProgramArgumentBinding> argument_bindings;
argument_bindings.reserve(m_argument_descriptions.size());

void Shader::InitArgumentBindings(const ResourceArgumentDescs& argument_descriptions)
{
m_argument_bindings.clear();
m_argument_bindings.reserve(argument_descriptions.size());
for(const auto& [argument_accessor, argument_desc] : argument_descriptions)
for(const auto& [argument_accessor, argument_desc] : m_argument_descriptions)
{
if (argument_accessor.GetShaderType() != GetType())
continue;
Expand All @@ -50,11 +47,19 @@ void Shader::InitArgumentBindings(const ResourceArgumentDescs& argument_descript
{
argument_accessor,
argument_desc.resource_type,
argument_desc.resource_count
argument_desc.resource_count,
argument_desc.buffer_size
});

m_argument_bindings.push_back(std::static_pointer_cast<Base::ProgramArgumentBinding>(argument_binding_ptr));
argument_bindings.push_back(std::static_pointer_cast<Base::ProgramArgumentBinding>(argument_binding_ptr));
}

return argument_bindings;
}

void Shader::InitArgumentBindings(const ResourceArgumentDescs& argument_descriptions)
{
m_argument_descriptions = argument_descriptions;
}

} // namespace Methane::Graphics::Null
Loading

0 comments on commit e9aaa06

Please sign in to comment.