Skip to content

Commit

Permalink
Merge pull request #103 from crud89/remove-unnecessary-indirections
Browse files Browse the repository at this point in the history
Improve core guideline conformance.
  • Loading branch information
crud89 authored Nov 4, 2023
2 parents 449c9cc + dc0b252 commit 6bea79b
Show file tree
Hide file tree
Showing 78 changed files with 1,717 additions and 1,717 deletions.
1 change: 1 addition & 0 deletions docs/release-logs/0.4.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- A novel `Enumerable` container is introduced to pass around immutable collections.
- Some places that previously used `std::ranges::generate` or `std::generate` now use `std::generator`.
- Builders are now `constexpr` where possible and are implemented using `deducing this` in place of CRTP, which makes them more lightweight.
- Improvements to C++ core guideline conformance ([See PR #103](https://github.com/crud89/LiteFX/pull/103)).
- New event infrastructure. ([See PR #81](https://github.com/crud89/LiteFX/pull/81))
- Add support for user-defined debug markers. ([See PR #82](https://github.com/crud89/LiteFX/pull/82))
- Improved resource allocation and binding: ([See PR #83](https://github.com/crud89/LiteFX/pull/83))
Expand Down
15 changes: 6 additions & 9 deletions src/AppModel/include/litefx/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ namespace LiteFX {
/// Returns the new window width.
/// </summary>
/// <returns>The new window width.</returns>
const int& width() const noexcept {
inline int width() const noexcept {
return m_width;
}

/// <summary>
/// Returns the new window height.
/// </summary>
/// <returns>The new window height.</returns>
const int& height() const noexcept {
inline int height() const noexcept {
return m_height;
}
};
Expand Down Expand Up @@ -449,21 +449,21 @@ namespace LiteFX {
/// </summary>
/// <param name="type">The backend type for which the active backend should be stopped.</param>
/// <seealso cref="stopBackend" />
virtual void stopActiveBackends(const BackendType& type) const;
virtual void stopActiveBackends(BackendType type) const;

/// <summary>
/// Returns the active backend of the provided backend <paramref name="type" />.
/// </summary>
/// <param name="type">The type of the backend.</param>
/// <returns>The active backend of the provided backend type, or <c>std::nullptr</c>, if no backend is active.</returns>
virtual IBackend* activeBackend(const BackendType& type) const;
virtual IBackend* activeBackend(BackendType type) const;

/// <summary>
/// Returns the type index of the active backend of the provided backend <paramref name="type" />.
/// </summary>
/// <param name="type">The type of the backend.</param>
/// <returns>Type index of the active backend of the provided backend type, or the type index of <c>std::nullptr_t</c>, if no backend is active.</returns>
virtual std::type_index activeBackendType(const BackendType& type) const;
virtual std::type_index activeBackendType(BackendType type) const;

private:
/// <summary>
Expand Down Expand Up @@ -619,12 +619,9 @@ namespace LiteFX {
/// <summary>
/// Called, if the application window resizes.
/// </summary>
/// <remarks>
/// Calling this method ensures, that the <paramref name="width" /> and <paramref name="height" /> parameters are valid.
/// </remarks>
/// <param name="width">The new width of the application window.</param>
/// <param name="height">The new height of the application window.</param>
void resize(int& width, int& height);
void resize(int width, int height);

public:
/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/AppModel/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ void App::stopBackend(std::type_index type) const
}
}

void App::stopActiveBackends(const BackendType& type) const
void App::stopActiveBackends(BackendType type) const
{
for (auto& backend : m_impl->m_backends | std::views::filter([type](const auto& b) { return b.second->type() == type && b.second->state() == BackendState::Active; }))
this->stopBackend(backend.first);
}

IBackend* App::activeBackend(const BackendType& type) const
IBackend* App::activeBackend(BackendType type) const
{
for (auto& backend : m_impl->m_backends | std::views::filter([type](const auto& b) { return b.second->type() == type && b.second->state() == BackendState::Active; }))
return backend.second.get();

return nullptr;
}

std::type_index App::activeBackendType(const BackendType& type) const
std::type_index App::activeBackendType(BackendType type) const
{
for (auto& backend : m_impl->m_backends | std::views::filter([type](const auto& b) { return b.second->type() == type && b.second->state() == BackendState::Active; }))
return backend.first;
Expand Down Expand Up @@ -193,7 +193,7 @@ void App::run()
this->shutdown(this, { });
}

void App::resize(int& width, int& height)
void App::resize(int width, int height)
{
// Ensure the area is at least 1 pixel into each direction.
width = std::max(width, 1);
Expand Down
525 changes: 263 additions & 262 deletions src/Backends/DirectX12/include/litefx/backends/dx12.hpp

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions src/Backends/DirectX12/include/litefx/backends/dx12_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,115 +107,115 @@ namespace LiteFX::Rendering::Backends {
/// <summary>
///
/// </summary>
Format LITEFX_DIRECTX12_API getFormat(const DXGI_FORMAT& format);
constexpr inline Format LITEFX_DIRECTX12_API getFormat(const DXGI_FORMAT& format);

/// <summary>
///
/// </summary>
DXGI_FORMAT LITEFX_DIRECTX12_API getFormat(const Format& format);
constexpr inline DXGI_FORMAT LITEFX_DIRECTX12_API getFormat(Format format);

/// <summary>
///
/// </summary>
DXGI_FORMAT LITEFX_DIRECTX12_API getFormat(const BufferFormat& format);
constexpr inline DXGI_FORMAT LITEFX_DIRECTX12_API getFormat(BufferFormat format);

/// <summary>
///
/// </summary>
bool LITEFX_DIRECTX12_API isSRGB(const Format& format);
constexpr inline bool LITEFX_DIRECTX12_API isSRGB(Format format);

/// <summary>
///
/// </summary>
D3D12_RESOURCE_DIMENSION LITEFX_DIRECTX12_API getImageType(const ImageDimensions& dimensions);
constexpr inline D3D12_RESOURCE_DIMENSION LITEFX_DIRECTX12_API getImageType(ImageDimensions dimensions);

/// <summary>
///
/// </summary>
PolygonMode LITEFX_DIRECTX12_API getPolygonMode(const D3D12_FILL_MODE& mode);
constexpr inline PolygonMode LITEFX_DIRECTX12_API getPolygonMode(const D3D12_FILL_MODE& mode);

/// <summary>
///
/// </summary>
D3D12_FILL_MODE LITEFX_DIRECTX12_API getPolygonMode(const PolygonMode& mode);
constexpr inline D3D12_FILL_MODE LITEFX_DIRECTX12_API getPolygonMode(PolygonMode mode);

/// <summary>
///
/// </summary>
CullMode LITEFX_DIRECTX12_API getCullMode(const D3D12_CULL_MODE& mode);
constexpr inline CullMode LITEFX_DIRECTX12_API getCullMode(const D3D12_CULL_MODE& mode);

/// <summary>
///
/// </summary>
D3D12_CULL_MODE LITEFX_DIRECTX12_API getCullMode(const CullMode& mode);
constexpr inline D3D12_CULL_MODE LITEFX_DIRECTX12_API getCullMode(CullMode mode);

/// <summary>
///
/// </summary>
PrimitiveTopology LITEFX_DIRECTX12_API getPrimitiveTopology(const D3D12_PRIMITIVE_TOPOLOGY& topology);
constexpr inline PrimitiveTopology LITEFX_DIRECTX12_API getPrimitiveTopology(const D3D12_PRIMITIVE_TOPOLOGY& topology);

/// <summary>
///
/// </summary>
D3D12_PRIMITIVE_TOPOLOGY LITEFX_DIRECTX12_API getPrimitiveTopology(const PrimitiveTopology& topology);
constexpr inline D3D12_PRIMITIVE_TOPOLOGY LITEFX_DIRECTX12_API getPrimitiveTopology(PrimitiveTopology topology);

/// <summary>
///
/// </summary>
D3D12_PRIMITIVE_TOPOLOGY_TYPE LITEFX_DIRECTX12_API getPrimitiveTopologyType(const PrimitiveTopology& topology);
constexpr inline D3D12_PRIMITIVE_TOPOLOGY_TYPE LITEFX_DIRECTX12_API getPrimitiveTopologyType(PrimitiveTopology topology);

/// <summary>
///
/// </summary>
LPCTSTR LITEFX_DIRECTX12_API getSemanticName(const AttributeSemantic& semantic);
constexpr inline LPCTSTR LITEFX_DIRECTX12_API getSemanticName(AttributeSemantic semantic);

/// <summary>
///
/// </summary>
/// <param name="vendorId"></param>
/// <returns></returns>
String LITEFX_DIRECTX12_API getVendorName(const UInt32& vendorId);
constexpr inline String LITEFX_DIRECTX12_API getVendorName(UInt32 vendorId);

/// <summary>
///
/// </summary>
D3D12_COMPARISON_FUNC LITEFX_DIRECTX12_API getCompareOp(const CompareOperation& compareOp);
constexpr inline D3D12_COMPARISON_FUNC LITEFX_DIRECTX12_API getCompareOp(CompareOperation compareOp);

/// <summary>
///
/// </summary>
D3D12_STENCIL_OP LITEFX_DIRECTX12_API getStencilOp(const StencilOperation& stencilOp);
constexpr inline D3D12_STENCIL_OP LITEFX_DIRECTX12_API getStencilOp(StencilOperation stencilOp);

/// <summary>
///
/// </summary>
D3D12_BLEND LITEFX_DIRECTX12_API getBlendFactor(const BlendFactor& blendFactor);
constexpr inline D3D12_BLEND LITEFX_DIRECTX12_API getBlendFactor(BlendFactor blendFactor);

/// <summary>
///
/// </summary>
D3D12_BLEND_OP LITEFX_DIRECTX12_API getBlendOperation(const BlendOperation& blendOperation);
constexpr inline D3D12_BLEND_OP LITEFX_DIRECTX12_API getBlendOperation(BlendOperation blendOperation);

/// <summary>
///
/// </summary>
D3D12_BARRIER_SYNC LITEFX_DIRECTX12_API getPipelineStage(const PipelineStage& pipelineStage);
constexpr inline D3D12_BARRIER_SYNC LITEFX_DIRECTX12_API getPipelineStage(PipelineStage pipelineStage);

/// <summary>
///
/// </summary>
D3D12_BARRIER_ACCESS LITEFX_DIRECTX12_API getResourceAccess(const ResourceAccess& resourceAccess);
constexpr inline D3D12_BARRIER_ACCESS LITEFX_DIRECTX12_API getResourceAccess(ResourceAccess resourceAccess);

/// <summary>
///
/// </summary>
D3D12_BARRIER_LAYOUT LITEFX_DIRECTX12_API getImageLayout(const ImageLayout& imageLayout);
constexpr inline D3D12_BARRIER_LAYOUT LITEFX_DIRECTX12_API getImageLayout(ImageLayout imageLayout);
}

/// <summary>
/// Implements a DirectX12 <see cref="IGraphicsAdapter" />.
/// </summary>
class LITEFX_DIRECTX12_API DirectX12GraphicsAdapter : public IGraphicsAdapter, public ComResource<IDXGIAdapter4> {
class LITEFX_DIRECTX12_API DirectX12GraphicsAdapter final : public IGraphicsAdapter, public ComResource<IDXGIAdapter4> {
LITEFX_IMPLEMENTATION(DirectX12GraphicsAdapterImpl);

public:
Expand All @@ -230,40 +230,40 @@ namespace LiteFX::Rendering::Backends {

public:
/// <inheritdoc />
virtual String name() const noexcept override;
String name() const noexcept override;

/// <inheritdoc />
virtual UInt64 uniqueId() const noexcept override;
UInt64 uniqueId() const noexcept override;

/// <inheritdoc />
virtual UInt32 vendorId() const noexcept override;
UInt32 vendorId() const noexcept override;

/// <inheritdoc />
virtual UInt32 deviceId() const noexcept override;
UInt32 deviceId() const noexcept override;

/// <inheritdoc />
virtual GraphicsAdapterType type() const noexcept override;
GraphicsAdapterType type() const noexcept override;

/// <inheritdoc />
/// <remarks>
/// This property is not supported by DirectX 12. The method always returns `0`.
/// </remarks>
virtual UInt32 driverVersion() const noexcept override;
UInt32 driverVersion() const noexcept override;

/// <inheritdoc />
/// <remarks>
/// This property is not supported by DirectX 12. The method always returns `0`.
/// </remarks>
virtual UInt32 apiVersion() const noexcept override;
UInt32 apiVersion() const noexcept override;

/// <inheritdoc />
virtual UInt64 dedicatedMemory() const noexcept override;
UInt64 dedicatedMemory() const noexcept override;
};

/// <summary>
/// Implements a DirectX12 <see cref="ISurface" />.
/// </summary>
class LITEFX_DIRECTX12_API DirectX12Surface : public ISurface, public Resource<HWND> {
class LITEFX_DIRECTX12_API DirectX12Surface final : public ISurface, public Resource<HWND> {
public:
/// <summary>
/// Initializes a new DirectX 12 surface.
Expand Down
6 changes: 3 additions & 3 deletions src/Backends/DirectX12/src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DirectX12Backend::DirectX12BackendImpl : public Implement<DirectX12Backend
return factory;
}

void loadAdapters(const bool& enableWarp = false)
void loadAdapters(bool enableWarp = false)
{
ComPtr<IDXGIAdapter1> adapterInterface;
ComPtr<IDXGIAdapter4> adapterInstance;
Expand Down Expand Up @@ -76,7 +76,7 @@ class DirectX12Backend::DirectX12BackendImpl : public Implement<DirectX12Backend
// Shared interface.
// ------------------------------------------------------------------------------------------------

DirectX12Backend::DirectX12Backend(const App& app, const bool& useAdvancedSoftwareRasterizer) :
DirectX12Backend::DirectX12Backend(const App& app, bool useAdvancedSoftwareRasterizer) :
m_impl(makePimpl<DirectX12BackendImpl>(this, app)), ComResource<IDXGIFactory7>(nullptr)
{
this->handle() = m_impl->initialize();
Expand Down Expand Up @@ -162,7 +162,7 @@ UniquePtr<DirectX12Surface> DirectX12Backend::createSurface(const HWND& hwnd) co
return makeUnique<DirectX12Surface>(hwnd);
}

void DirectX12Backend::enableAdvancedSoftwareRasterizer(const bool& enable)
void DirectX12Backend::enableAdvancedSoftwareRasterizer(bool enable)
{
m_impl->loadAdapters(enable);
}
22 changes: 11 additions & 11 deletions src/Backends/DirectX12/src/barrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DirectX12Barrier::DirectX12BarrierImpl : public Implement<DirectX12Barrier
Array<ImageBarrier> m_imageBarriers;

public:
DirectX12BarrierImpl(DirectX12Barrier* parent, const PipelineStage& syncBefore, const PipelineStage& syncAfter) :
DirectX12BarrierImpl(DirectX12Barrier* parent, PipelineStage syncBefore, PipelineStage syncAfter) :
base(parent), m_syncBefore(syncBefore), m_syncAfter(syncAfter)
{
}
Expand All @@ -32,7 +32,7 @@ class DirectX12Barrier::DirectX12BarrierImpl : public Implement<DirectX12Barrier
// Shared interface.
// ------------------------------------------------------------------------------------------------

constexpr DirectX12Barrier::DirectX12Barrier(const PipelineStage& syncBefore, const PipelineStage& syncAfter) noexcept :
constexpr DirectX12Barrier::DirectX12Barrier(PipelineStage syncBefore, PipelineStage syncAfter) noexcept :
m_impl(makePimpl<DirectX12BarrierImpl>(this, syncBefore, syncAfter))
{
}
Expand All @@ -44,7 +44,7 @@ constexpr DirectX12Barrier::DirectX12Barrier() noexcept :

constexpr DirectX12Barrier::~DirectX12Barrier() noexcept = default;

constexpr const PipelineStage& DirectX12Barrier::syncBefore() const noexcept
constexpr PipelineStage DirectX12Barrier::syncBefore() const noexcept
{
return m_impl->m_syncBefore;
}
Expand All @@ -54,7 +54,7 @@ constexpr PipelineStage& DirectX12Barrier::syncBefore() noexcept
return m_impl->m_syncBefore;
}

constexpr const PipelineStage& DirectX12Barrier::syncAfter() const noexcept
constexpr PipelineStage DirectX12Barrier::syncAfter() const noexcept
{
return m_impl->m_syncAfter;
}
Expand All @@ -64,37 +64,37 @@ constexpr PipelineStage& DirectX12Barrier::syncAfter() noexcept
return m_impl->m_syncAfter;
}

constexpr void DirectX12Barrier::wait(const ResourceAccess& accessBefore, const ResourceAccess& accessAfter) noexcept
constexpr void DirectX12Barrier::wait(ResourceAccess accessBefore, ResourceAccess accessAfter) noexcept
{
m_impl->m_globalBarriers.push_back({ accessBefore, accessAfter });
}

constexpr void DirectX12Barrier::transition(IDirectX12Buffer& buffer, const ResourceAccess& accessBefore, const ResourceAccess& accessAfter)
constexpr void DirectX12Barrier::transition(IDirectX12Buffer& buffer, ResourceAccess accessBefore, ResourceAccess accessAfter)
{
m_impl->m_bufferBarriers.push_back({ accessBefore, accessAfter, buffer, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES });
}

constexpr void DirectX12Barrier::transition(IDirectX12Buffer& buffer, const UInt32& element, const ResourceAccess& accessBefore, const ResourceAccess& accessAfter)
constexpr void DirectX12Barrier::transition(IDirectX12Buffer& buffer, UInt32 element, ResourceAccess accessBefore, ResourceAccess accessAfter)
{
m_impl->m_bufferBarriers.push_back({ accessBefore, accessAfter, buffer, element });
}

constexpr void DirectX12Barrier::transition(IDirectX12Image& image, const ResourceAccess& accessBefore, const ResourceAccess& accessAfter, const ImageLayout& layout)
constexpr void DirectX12Barrier::transition(IDirectX12Image& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout)
{
m_impl->m_imageBarriers.push_back({ accessBefore, accessAfter, image, std::nullopt, layout, 0, image.levels(), 0, image.layers(), 0 });
}

constexpr void DirectX12Barrier::transition(IDirectX12Image& image, const ResourceAccess& accessBefore, const ResourceAccess& accessAfter, const ImageLayout& fromLayout, const ImageLayout& toLayout)
constexpr void DirectX12Barrier::transition(IDirectX12Image& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout)
{
m_impl->m_imageBarriers.push_back({ accessBefore, accessAfter, image, fromLayout, toLayout, 0, image.levels(), 0, image.layers(), 0 });
}

constexpr void DirectX12Barrier::transition(IDirectX12Image& image, const UInt32& level, const UInt32& levels, const UInt32& layer, const UInt32& layers, const UInt32& plane, const ResourceAccess& accessBefore, const ResourceAccess& accessAfter, const ImageLayout& layout)
constexpr void DirectX12Barrier::transition(IDirectX12Image& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout)
{
m_impl->m_imageBarriers.push_back({ accessBefore, accessAfter, image, std::nullopt, layout, level, levels, layer, layers, plane });
}

constexpr void DirectX12Barrier::transition(IDirectX12Image& image, const UInt32& level, const UInt32& levels, const UInt32& layer, const UInt32& layers, const UInt32& plane, const ResourceAccess& accessBefore, const ResourceAccess& accessAfter, const ImageLayout& fromLayout, const ImageLayout& toLayout)
constexpr void DirectX12Barrier::transition(IDirectX12Image& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout)
{
m_impl->m_imageBarriers.push_back({ accessBefore, accessAfter, image, fromLayout, toLayout, level, levels, layer, layers, plane });
}
Expand Down
Loading

0 comments on commit 6bea79b

Please sign in to comment.