Skip to content

Commit

Permalink
Fix static_analysis issues with const_cast: remove const from context…
Browse files Browse the repository at this point in the history
… reference in Program constructor
  • Loading branch information
egorodet committed Dec 29, 2024
1 parent 2bef25d commit a3456c9
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Program
friend class ProgramBindings;

public:
Program(const Context& context, const Settings& settings);
Program(Context& context, const Settings& settings);

// IProgram interface
const Settings& GetSettings() const noexcept final { return m_settings; }
Expand Down Expand Up @@ -104,7 +104,7 @@ class Program
const std::map<std::string_view, Rhi::ShaderTypes, std::less<>>& shader_types_by_argument_name_map);
void InitFrameConstantArgumentBindings();

const Context& m_context;
Context& m_context;
Settings m_settings;
const ShadersByType m_shaders_by_type;
const Rhi::ShaderTypes m_shader_types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ static Rhi::ShaderTypes CreateShaderTypes(const Ptrs<Rhi::IShader>& shaders)
return shader_types;
}

Program::Program(const Context& context, const Settings& settings)
Program::Program(Context& context, const Settings& settings)
: m_context(context)
, m_settings(settings)
, m_shaders_by_type(CreateShadersByType(settings.shaders))
, m_shader_types(CreateShaderTypes(settings.shaders))
// FIXME: get rid of const-cast required to Connect to signal
, m_root_constant_buffer(const_cast<Context&>(context), "Program Root Constant Buffer")
, m_root_mutable_buffer(const_cast<Context&>(context), "Program Root Mutable Buffer")
, m_root_constant_buffer(context, "Program Root Constant Buffer")
, m_root_mutable_buffer(context, "Program Root Mutable Buffer")
{ }

const Ptr<Rhi::IShader>& Program::GetShader(Rhi::ShaderType shader_type) const
Expand Down Expand Up @@ -176,7 +175,7 @@ void Program::InitFrameConstantArgumentBindings()

// Create frame-constant argument bindings only when program is created in render context
m_frame_bindings_by_argument.clear();
const auto& render_context = static_cast<const RenderContext&>(m_context);
auto& render_context = static_cast<RenderContext&>(m_context);
const uint32_t frame_buffers_count = render_context.GetSettings().frame_buffers_count;
META_CHECK_GREATER_OR_EQUAL(frame_buffers_count, 2);

Expand Down Expand Up @@ -217,8 +216,7 @@ RootConstantBuffer& Program::GetRootFrameConstantBuffer(Data::Index frame_index)
while (frame_index >= m_root_frame_constant_buffers.size())
{
m_root_frame_constant_buffers.emplace_back(
std::make_unique<RootConstantBuffer>(const_cast<Context&>(m_context), // FIXME: remove const cast
GetRootFrameConstantBufferName(GetName(), frame_index))
std::make_unique<RootConstantBuffer>(m_context, GetRootFrameConstantBufferName(GetName(), frame_index))
);
}
return *m_root_frame_constant_buffers[frame_index];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Context
return std::make_shared<Shader>(type, *this, settings);
}

[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) const final
[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) final
{
META_FUNCTION_TASK();
return std::make_shared<Program>(*this, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Program final : public Base::Program // NOSONAR - this class requires dest
friend class ProgramBindings;

public:
Program(const Base::Context& context, const Settings& settings);
Program(Base::Context& context, const Settings& settings);
~Program() override;

// IProgram interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void InitArgumentAsDescriptorTable(std::vector<CD3DX12_DESCRIPTOR_RANGE1>
descriptor_offset += bind_settings.resource_count;
}

Program::Program(const Base::Context& context, const Settings& settings)
Program::Program(Base::Context& context, const Settings& settings)
: Base::Program(context, settings)
, m_dx_context(dynamic_cast<const IContext&>(context))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct IContext
[[nodiscard]] virtual Ptr<ICommandQueue> CreateCommandQueue(CommandListType type) const = 0;
[[nodiscard]] virtual Ptr<ICommandKit> CreateCommandKit(CommandListType type) const = 0;
[[nodiscard]] virtual Ptr<IShader> CreateShader(ShaderType type, const ShaderSettings& settings) const = 0;
[[nodiscard]] virtual Ptr<IProgram> CreateProgram(const ProgramSettings& settings) const = 0;
[[nodiscard]] virtual Ptr<IProgram> CreateProgram(const ProgramSettings& settings) = 0;
[[nodiscard]] virtual Ptr<IComputeState> CreateComputeState(const ComputeStateSettings& settings) const = 0;
[[nodiscard]] virtual Ptr<IBuffer> CreateBuffer(const BufferSettings& settings) const = 0;
[[nodiscard]] virtual Ptr<ITexture> CreateTexture(const TextureSettings& settings) const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct IProgram
const Argument& argument);

// Create IProgram instance
[[nodiscard]] static Ptr<IProgram> Create(const IContext& context, const Settings& settings);
[[nodiscard]] static Ptr<IProgram> Create(IContext& context, const Settings& settings);

// IProgram interface
[[nodiscard]] virtual Ptr<IProgramBindings> CreateBindings(const BindingValueByArgument& binding_value_by_argument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ProgramArgumentAccessor* IProgram::FindArgumentAccessor(const ArgumentAcce
return arg_access_it == argument_accessors.end() ? nullptr : &*arg_access_it;
}

Ptr<IProgram> IProgram::Create(const IContext& context, const Settings& settings)
Ptr<IProgram> IProgram::Create(IContext& context, const Settings& settings)
{
META_FUNCTION_TASK();
return context.CreateProgram(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Context
return std::make_shared<Shader>(type, *this, settings);
}

[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) const final
[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) final
{
META_FUNCTION_TASK();
return std::make_shared<Program>(*this, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public:

using ShaderArgumentBufferLayouts = std::vector<ShaderArgumentBufferLayout>;

Program(const Base::Context& context, const Settings& settings);
Program(Base::Context& context, const Settings& settings);

// IProgram interface
[[nodiscard]] Ptr<Rhi::IProgramBindings> CreateBindings(const BindingValueByArgument& binding_value_by_argument, Data::Index frame_index) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
namespace Methane::Graphics::Metal
{

Program::Program(const Base::Context& context, const Settings& settings)
Program::Program(Base::Context& context, const Settings& settings)
: Base::Program(context, settings)
{
META_FUNCTION_TASK();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Context
return std::make_shared<Shader>(type, *this, settings);
}

[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) const final
[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) final
{
return std::make_shared<Program>(*this, settings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Program final
: public Base::Program
{
public:
Program(const Base::Context& context, const Settings& settings);
Program(Base::Context& context, const Settings& settings);

// IProgram interface
[[nodiscard]] Ptr<Rhi::IProgramBindings> CreateBindings(const BindingValueByArgument& binding_value_by_argument, Data::Index frame_index) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Null implementation of the program interface.
namespace Methane::Graphics::Null
{

Program::Program(const Base::Context& context, const Settings& settings)
Program::Program(Base::Context& context, const Settings& settings)
: Base::Program(context, settings)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Context
return std::make_shared<Shader>(type, *this, settings);
}

[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) const final
[[nodiscard]] Ptr<Rhi::IProgram> CreateProgram(const Rhi::ProgramSettings& settings) final
{
META_FUNCTION_TASK();
return std::make_shared<Program>(*this, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Program final
std::vector<ByteCodeMaps> byte_code_maps_for_arguments; // related bytecode maps for each binding/argument
};

Program(const Base::Context& context, const Settings& settings);
Program(Base::Context& context, const Settings& settings);

// IProgram interface
[[nodiscard]] Ptr<Rhi::IProgramBindings> CreateBindings(const BindingValueByArgument& binding_value_by_argument, Data::Index frame_index) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Vulkan implementation of the program interface.
namespace Methane::Graphics::Vulkan
{

Program::Program(const Base::Context& context, const Settings& settings)
Program::Program(Base::Context& context, const Settings& settings)
: Base::Program(context, settings)
, m_vk_context(dynamic_cast<const IContext&>(context))
{
Expand Down

0 comments on commit a3456c9

Please sign in to comment.