-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ComputeState implementation for Metal backend and RHI PIMPL class
- Loading branch information
Showing
11 changed files
with
417 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
Modules/Graphics/RHI/Impl/Include/Methane/Graphics/RHI/ComputeState.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/****************************************************************************** | ||
Copyright 2023 Evgeny Gorodetskiy | ||
Licensed under the Apache License, Version 2.0 (the "License"), | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
******************************************************************************* | ||
FILE: Methane/Graphics/RHI/ComputeState.h | ||
Methane ComputeState PIMPL wrappers for direct calls to final implementation. | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <Methane/Pimpl.h> | ||
#include "Program.h" | ||
|
||
#include <Methane/Graphics/RHI/IComputeState.h> | ||
|
||
namespace Methane::Graphics::META_GFX_NAME | ||
{ | ||
class ComputeState; | ||
} | ||
|
||
namespace Methane::Graphics::Rhi | ||
{ | ||
|
||
struct ComputeStateSettingsImpl | ||
{ | ||
Program program; | ||
|
||
META_PIMPL_API static ComputeStateSettings Convert(const ComputeStateSettingsImpl& settings); | ||
}; | ||
|
||
class RenderContext; | ||
|
||
class ComputeState // NOSONAR - constructors and assignment operators are required to use forward declared Impl and Ptr<Impl> in header | ||
{ | ||
public: | ||
using Settings = ComputeStateSettingsImpl; | ||
|
||
META_PIMPL_DEFAULT_CONSTRUCT_METHODS_DECLARE(ComputeState); | ||
META_PIMPL_METHODS_COMPARE_DECLARE(ComputeState); | ||
|
||
META_PIMPL_API explicit ComputeState(const Ptr<IComputeState>& interface_ptr); | ||
META_PIMPL_API explicit ComputeState(IComputeState& interface_ref); | ||
META_PIMPL_API ComputeState(const RenderContext& context, const Settings& settings); | ||
|
||
META_PIMPL_API bool IsInitialized() const META_PIMPL_NOEXCEPT; | ||
META_PIMPL_API IComputeState& GetInterface() const META_PIMPL_NOEXCEPT; | ||
META_PIMPL_API Ptr<IComputeState> GetInterfacePtr() const META_PIMPL_NOEXCEPT; | ||
|
||
// IObject interface methods | ||
META_PIMPL_API bool SetName(std::string_view name) const; | ||
META_PIMPL_API std::string_view GetName() const META_PIMPL_NOEXCEPT; | ||
|
||
// Data::IEmitter<IObjectCallback> interface methods | ||
META_PIMPL_API void Connect(Data::Receiver<IObjectCallback>& receiver) const; | ||
META_PIMPL_API void Disconnect(Data::Receiver<IObjectCallback>& receiver) const; | ||
|
||
// IComputeState interface methods | ||
[[nodiscard]] META_PIMPL_API const ComputeStateSettings& GetSettings() const META_PIMPL_NOEXCEPT; | ||
META_PIMPL_API void Reset(const Settings& settings) const; | ||
META_PIMPL_API void Reset(const IComputeState::Settings& settings) const; | ||
|
||
META_PIMPL_API Program GetProgram() const; | ||
|
||
private: | ||
using Impl = Methane::Graphics::META_GFX_NAME::ComputeState; | ||
|
||
Ptr<Impl> m_impl_ptr; | ||
}; | ||
|
||
} // namespace Methane::Graphics::Rhi | ||
|
||
#ifdef META_PIMPL_INLINE | ||
|
||
#include <Methane/Graphics/RHI/ComputeState.cpp> | ||
|
||
#endif // META_PIMPL_INLINE |
119 changes: 119 additions & 0 deletions
119
Modules/Graphics/RHI/Impl/Sources/Methane/Graphics/RHI/ComputeState.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/****************************************************************************** | ||
Copyright 2023 Evgeny Gorodetskiy | ||
Licensed under the Apache License, Version 2.0 (the "License"), | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
******************************************************************************* | ||
FILE: Methane/Graphics/RHI/ComputeState.cpp | ||
Methane ComputeState PIMPL wrappers for direct calls to final implementation. | ||
******************************************************************************/ | ||
|
||
#include <Methane/Graphics/RHI/ComputeState.h> | ||
#include <Methane/Graphics/RHI/RenderContext.h> | ||
|
||
#include <Methane/Pimpl.hpp> | ||
|
||
#ifdef META_GFX_METAL | ||
#include <ComputeState.hh> | ||
#else | ||
#include <ComputeState.h> | ||
#endif | ||
|
||
namespace Methane::Graphics::Rhi | ||
{ | ||
|
||
ComputeStateSettings ComputeStateSettingsImpl::Convert(const ComputeStateSettingsImpl& settings) | ||
{ | ||
return ComputeStateSettings | ||
{ | ||
settings.program.GetInterfacePtr() | ||
}; | ||
} | ||
|
||
META_PIMPL_DEFAULT_CONSTRUCT_METHODS_IMPLEMENT(ComputeState); | ||
META_PIMPL_METHODS_COMPARE_IMPLEMENT(ComputeState); | ||
|
||
ComputeState::ComputeState(const Ptr<IComputeState>& interface_ptr) | ||
: m_impl_ptr(std::dynamic_pointer_cast<Impl>(interface_ptr)) | ||
{ | ||
} | ||
|
||
ComputeState::ComputeState(IComputeState& interface_ref) | ||
: ComputeState(interface_ref.GetDerivedPtr<IComputeState>()) | ||
{ | ||
} | ||
|
||
ComputeState::ComputeState(const RenderContext& context, const Settings& settings) | ||
: ComputeState(IComputeState::Create(context.GetInterface(), ComputeStateSettingsImpl::Convert(settings))) | ||
{ | ||
} | ||
|
||
bool ComputeState::IsInitialized() const META_PIMPL_NOEXCEPT | ||
{ | ||
return static_cast<bool>(m_impl_ptr); | ||
} | ||
|
||
IComputeState& ComputeState::GetInterface() const META_PIMPL_NOEXCEPT | ||
{ | ||
return *m_impl_ptr; | ||
} | ||
|
||
Ptr<IComputeState> ComputeState::GetInterfacePtr() const META_PIMPL_NOEXCEPT | ||
{ | ||
return m_impl_ptr; | ||
} | ||
|
||
bool ComputeState::SetName(std::string_view name) const | ||
{ | ||
return GetImpl(m_impl_ptr).SetName(name); | ||
} | ||
|
||
std::string_view ComputeState::GetName() const META_PIMPL_NOEXCEPT | ||
{ | ||
return GetImpl(m_impl_ptr).GetName(); | ||
} | ||
|
||
void ComputeState::Connect(Data::Receiver<IObjectCallback>& receiver) const | ||
{ | ||
GetImpl(m_impl_ptr).Data::Emitter<IObjectCallback>::Connect(receiver); | ||
} | ||
|
||
void ComputeState::Disconnect(Data::Receiver<IObjectCallback>& receiver) const | ||
{ | ||
GetImpl(m_impl_ptr).Data::Emitter<IObjectCallback>::Disconnect(receiver); | ||
} | ||
|
||
const ComputeStateSettings& ComputeState::GetSettings() const META_PIMPL_NOEXCEPT | ||
{ | ||
return GetImpl(m_impl_ptr).GetSettings(); | ||
} | ||
|
||
void ComputeState::Reset(const Settings& settings) const | ||
{ | ||
return GetImpl(m_impl_ptr).Reset(ComputeStateSettingsImpl::Convert(settings)); | ||
} | ||
|
||
void ComputeState::Reset(const IComputeState::Settings& settings) const | ||
{ | ||
return GetImpl(m_impl_ptr).Reset(settings); | ||
} | ||
|
||
Program ComputeState::GetProgram() const | ||
{ | ||
return Program(GetSettings().program_ptr); | ||
} | ||
|
||
} // namespace Methane::Graphics::Rhi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/ComputeState.hh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/****************************************************************************** | ||
Copyright 2023 Evgeny Gorodetskiy | ||
Licensed under the Apache License, Version 2.0 (the "License"), | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
******************************************************************************* | ||
FILE: Methane/Graphics/Metal/ComputeState.hh | ||
Metal implementation of the render state interface. | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <Methane/Graphics/Base/ComputeState.h> | ||
|
||
#import <Metal/Metal.h> | ||
|
||
#include <vector> | ||
|
||
namespace Methane::Graphics::Metal | ||
{ | ||
|
||
class Device; | ||
|
||
class ComputeState final | ||
: public Base::ComputeState | ||
{ | ||
public: | ||
ComputeState(const Rhi::IContext& context, const Settings& settings); | ||
|
||
// IComputeState interface | ||
void Reset(const Settings& settings) override; | ||
|
||
// Base::ComputeState interface | ||
void Apply(Base::ComputeCommandList& command_list) override; | ||
|
||
// IObject interface | ||
bool SetName(std::string_view name) override; | ||
|
||
void InitializeNativeStates(); | ||
void InitializeNativePipelineState(); | ||
void InitializeNativeDepthStencilState(); | ||
|
||
id<MTLComputePipelineState> GetNativePipelineState(); | ||
|
||
private: | ||
void ResetNativeState(); | ||
|
||
const Device& m_device; | ||
MTLComputePipelineDescriptor* m_mtl_pipeline_state_desc = nil; | ||
id<MTLComputePipelineState> m_mtl_pipeline_state = nil; | ||
}; | ||
|
||
} // namespace Methane::Graphics::Metal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ubuntu_VK_SonarScan Tests Code Coverage
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MacOS_MTL_SonarScan Tests Code Coverage
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win64_DX_SonarScan Tests Code Coverage
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ubuntu_VK_Release Test Results
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MacOS_MTL_Release Test Results
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win64_DX_Release Test Results
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win32_VK_Release Test Results
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win64_VK_Release Test Results
6680506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win32_DX_Release Test Results