Skip to content

Commit

Permalink
Only yield descriptors from base interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
crud89 committed Jan 16, 2024
1 parent aae3cf6 commit 3f49dd7
Show file tree
Hide file tree
Showing 33 changed files with 432 additions and 428 deletions.
80 changes: 33 additions & 47 deletions src/Backends/DirectX12/include/litefx/backends/dx12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace LiteFX::Rendering::Backends {
/// <param name="vertexSize">The size of a single vertex.</param>
/// <param name="binding">The binding point of the vertex buffers using this layout.</param>
/// <param name="attributes">The attributes to initialize the layout with.</param>
explicit DirectX12VertexBufferLayout(size_t vertexSize, UInt32 binding = 0, std::initializer_list<BufferAttribute> attributes);
explicit DirectX12VertexBufferLayout(size_t vertexSize, UInt32 binding, std::initializer_list<BufferAttribute> attributes);

/// <inheritdoc cref="DirectX12VertexBufferLayout(size_t, UInt32, const std::initializer_list{{BufferAttribute}})" />
explicit DirectX12VertexBufferLayout(size_t vertexSize, UInt32 binding = 0, Span<BufferAttribute> attributes = { });
Expand Down Expand Up @@ -297,7 +297,7 @@ namespace LiteFX::Rendering::Backends {

public:
/// <inheritdoc />
Enumerable<const DirectX12ShaderModule*> modules() const noexcept override;
const Array<UniquePtr<const DirectX12ShaderModule>>& modules() const noexcept override;

/// <inheritdoc />
virtual SharedPtr<DirectX12PipelineLayout> reflectPipelineLayout() const;
Expand Down Expand Up @@ -457,6 +457,8 @@ namespace LiteFX::Rendering::Backends {
LITEFX_IMPLEMENTATION(DirectX12DescriptorSetLayoutImpl);
LITEFX_BUILDER(DirectX12DescriptorSetLayoutBuilder);
friend class DirectX12PipelineLayout;
friend class DirectX12Device;
friend class DirectX12CommandBuffer;

public:
using base_type = DescriptorSetLayout<DirectX12DescriptorLayout, DirectX12DescriptorSet>;
Expand All @@ -482,12 +484,12 @@ namespace LiteFX::Rendering::Backends {
/// <param name="device">The device, the descriptor set layout is created on.</param>
explicit DirectX12DescriptorSetLayout(const DirectX12Device& device) noexcept;

public:
protected:
/// <summary>
/// Returns the index of the descriptor set root parameter.
/// </summary>
/// <returns>The index of the descriptor set root parameter.</returns>
virtual UInt32 rootParameterIndex() const noexcept;
virtual UInt32& rootParameterIndex() const noexcept;

/// <summary>
/// Returns the index of the first descriptor for a certain binding. The offset is relative to the heap for the descriptor (i.e. sampler for sampler descriptors and
Expand All @@ -504,13 +506,6 @@ namespace LiteFX::Rendering::Backends {
/// <returns>A reference of the parent device.</returns>
virtual const DirectX12Device& device() const noexcept;

protected:
/// <summary>
/// Returns a reference of the index of the descriptor set root parameter.
/// </summary>
/// <returns>A reference of the index of the descriptor set root parameter.</returns>
virtual UInt32& rootParameterIndex() noexcept;

/// <summary>
/// Returns <c>true</c>, if the descriptor set contains an (unbounded) runtime array.
/// </summary>
Expand All @@ -522,7 +517,7 @@ namespace LiteFX::Rendering::Backends {

public:
/// <inheritdoc />
Enumerable<const DirectX12DescriptorLayout*> descriptors() const noexcept override;
const Array<UniquePtr<const DirectX12DescriptorLayout>>& descriptors() const noexcept override;

/// <inheritdoc />
const DirectX12DescriptorLayout& descriptor(UInt32 binding) const override;
Expand Down Expand Up @@ -559,13 +554,13 @@ namespace LiteFX::Rendering::Backends {
UniquePtr<DirectX12DescriptorSet> allocate(UInt32 descriptors, Span<DescriptorBinding> bindings = { }) const override;

/// <inheritdoc />
Enumerable<UniquePtr<DirectX12DescriptorSet>> allocateMultiple(UInt32 descriptorSets, Array<Span<DescriptorBinding>> bindings = { }) const override;
Enumerable<UniquePtr<DirectX12DescriptorSet>> allocateMultiple(UInt32 descriptorSets, const Array<Span<DescriptorBinding>>& bindings = { }) const override;

/// <inheritdoc />
Enumerable<UniquePtr<DirectX12DescriptorSet>> allocateMultiple(UInt32 descriptorSets, std::function<Enumerable<DescriptorBinding>(UInt32)> bindingFactory) const override;

/// <inheritdoc />
Enumerable<UniquePtr<DirectX12DescriptorSet>> allocateMultiple(UInt32 descriptorSets, UInt32 descriptors, Array<Span<DescriptorBinding>> bindings = { }) const override;
Enumerable<UniquePtr<DirectX12DescriptorSet>> allocateMultiple(UInt32 descriptorSets, UInt32 descriptors, const Array<Span<DescriptorBinding>>& bindings = { }) const override;

/// <inheritdoc />
Enumerable<UniquePtr<DirectX12DescriptorSet>> allocateMultiple(UInt32 descriptorSets, UInt32 descriptors, std::function<Enumerable<DescriptorBinding>(UInt32)> bindingFactory) const override;
Expand All @@ -581,6 +576,8 @@ namespace LiteFX::Rendering::Backends {
class LITEFX_DIRECTX12_API DirectX12PushConstantsRange final : public IPushConstantsRange {
LITEFX_IMPLEMENTATION(DirectX12PushConstantsRangeImpl);
friend class DirectX12PipelineLayout;
friend class DirectX12Device;
friend class DirectX12CommandBuffer;

public:
/// <summary>
Expand Down Expand Up @@ -612,19 +609,12 @@ namespace LiteFX::Rendering::Backends {
/// <inheritdoc />
ShaderStage stage() const noexcept override;

public:
protected:
/// <summary>
/// Returns the index of the root parameter, the range is bound to.
/// </summary>
/// <returns>The index of the root parameter, the range is bound to.</returns>
virtual UInt32 rootParameterIndex() const noexcept;

protected:
/// <summary>
/// Returns a reference of the index of the root parameter, the range is bound to.
/// </summary>
/// <returns>A reference of the index of the root parameter, the range is bound to.</returns>
virtual UInt32& rootParameterIndex() noexcept;
UInt32& rootParameterIndex() const noexcept;
};

/// <summary>
Expand Down Expand Up @@ -669,14 +659,7 @@ namespace LiteFX::Rendering::Backends {
const DirectX12PushConstantsRange& range(ShaderStage stage) const override;

/// <inheritdoc />
Enumerable<const DirectX12PushConstantsRange*> ranges() const noexcept override;

protected:
/// <summary>
/// Returns an array of pointers to the push constant ranges of the layout.
/// </summary>
/// <returns>An array of pointers to the push constant ranges of the layout.</returns>
virtual Enumerable<DirectX12PushConstantsRange*> ranges() noexcept;
const Array<UniquePtr<const DirectX12PushConstantsRange>>& ranges() const noexcept override;
};

/// <summary>
Expand Down Expand Up @@ -719,7 +702,7 @@ namespace LiteFX::Rendering::Backends {
const DirectX12DescriptorSetLayout& descriptorSet(UInt32 space) const override;

/// <inheritdoc />
Enumerable<const DirectX12DescriptorSetLayout*> descriptorSets() const noexcept override;
const Array<UniquePtr<const DirectX12DescriptorSetLayout>>& descriptorSets() const noexcept override;

/// <inheritdoc />
const DirectX12PushConstantsLayout* pushConstants() const noexcept override;
Expand Down Expand Up @@ -753,10 +736,10 @@ namespace LiteFX::Rendering::Backends {

public:
/// <inheritdoc />
Enumerable<const DirectX12VertexBufferLayout*> vertexBufferLayouts() const noexcept override;
const Array<UniquePtr<const DirectX12VertexBufferLayout>>& vertexBufferLayouts() const noexcept override;

/// <inheritdoc />
const DirectX12VertexBufferLayout* vertexBufferLayout(UInt32 binding) const override;
const DirectX12VertexBufferLayout& vertexBufferLayout(UInt32 binding) const override;

/// <inheritdoc />
const DirectX12IndexBufferLayout* indexBufferLayout() const noexcept override;
Expand Down Expand Up @@ -959,7 +942,7 @@ namespace LiteFX::Rendering::Backends {
void execute(SharedPtr<const DirectX12CommandBuffer> commandBuffer) const override;

/// <inheritdoc />
void execute(Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const override;
void execute(Span<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const override;

private:
void releaseSharedState() const override;
Expand Down Expand Up @@ -1071,6 +1054,7 @@ namespace LiteFX::Rendering::Backends {
/// <seealso cref="DirectX12RenderPass" />
class LITEFX_DIRECTX12_API DirectX12FrameBuffer final : public FrameBuffer<DirectX12CommandBuffer> {
LITEFX_IMPLEMENTATION(DirectX12FrameBufferImpl);
friend class DirectX12RenderPass;

public:
/// <summary>
Expand Down Expand Up @@ -1120,6 +1104,8 @@ namespace LiteFX::Rendering::Backends {
/// <seealso cref="depthStencilTargetHeap" />
UInt32 depthStencilTargetDescriptorSize() const noexcept;

protected:
/// <summary>
/// Returns a reference to the value of the fence that indicates the last submission drawing into the frame buffer.
/// </summary>
/// <remarks>
Expand All @@ -1146,13 +1132,13 @@ namespace LiteFX::Rendering::Backends {
size_t getHeight() const noexcept override;

/// <inheritdoc />
Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers() const noexcept override;
const Array<SharedPtr<const DirectX12CommandBuffer>>& commandBuffers() const noexcept override;

/// <inheritdoc />
SharedPtr<const DirectX12CommandBuffer> commandBuffer(UInt32 index) const override;

/// <inheritdoc />
Enumerable<IDirectX12Image*> images() const noexcept override;
const Array<IDirectX12Image*>& images() const noexcept override;

/// <inheritdoc />
IDirectX12Image& image(UInt32 location) const override;
Expand Down Expand Up @@ -1255,10 +1241,10 @@ namespace LiteFX::Rendering::Backends {
const DirectX12Queue& commandQueue() const noexcept override;

/// <inheritdoc />
Enumerable<const DirectX12FrameBuffer*> frameBuffers() const noexcept override;
const Array<UniquePtr<const DirectX12FrameBuffer>>& frameBuffers() const noexcept override;

/// <inheritdoc />
Enumerable<const DirectX12RenderPipeline*> pipelines() const noexcept override;
const Array<UniquePtr<const DirectX12RenderPipeline>>& pipelines() const noexcept override;

/// <inheritdoc />
const RenderTarget& renderTarget(UInt32 location) const override;
Expand Down Expand Up @@ -1389,10 +1375,10 @@ namespace LiteFX::Rendering::Backends {
// SwapChain interface.
public:
/// <inheritdoc />
Enumerable<SharedPtr<TimingEvent>> timingEvents() const noexcept override;
const Array<SharedPtr<const TimingEvent>>& timingEvents() const noexcept override;

/// <inheritdoc />
SharedPtr<TimingEvent> timingEvent(UInt32 queryId) const override;
SharedPtr<const TimingEvent> timingEvent(UInt32 queryId) const override;

/// <inheritdoc />
UInt64 readTimingEvent(SharedPtr<const TimingEvent> timingEvent) const override;
Expand All @@ -1410,10 +1396,10 @@ namespace LiteFX::Rendering::Backends {
const Size2d& renderArea() const noexcept override;

/// <inheritdoc />
IDirectX12Image* image(UInt32 backBuffer) const override;
IDirectX12Image& image(UInt32 backBuffer) const override;

/// <inheritdoc />
Enumerable<IDirectX12Image*> images() const noexcept override;
const Array<UniquePtr<IDirectX12Image>>& images() const noexcept override;

/// <inheritdoc />
void present(const DirectX12FrameBuffer& frameBuffer) const override;
Expand All @@ -1423,10 +1409,10 @@ namespace LiteFX::Rendering::Backends {

public:
/// <inheritdoc />
Enumerable<Format> getSurfaceFormats() const noexcept override;
Array<Format> getSurfaceFormats() const noexcept override;

/// <inheritdoc />
void addTimingEvent(SharedPtr<TimingEvent> timingEvent) override;
void addTimingEvent(SharedPtr<const TimingEvent> timingEvent) override;

/// <inheritdoc />
void reset(Format surfaceFormat, const Size2d& renderArea, UInt32 buffers) override;
Expand Down Expand Up @@ -1497,7 +1483,7 @@ namespace LiteFX::Rendering::Backends {
UInt64 submit(SharedPtr<const DirectX12CommandBuffer> commandBuffer) const override;

/// <inheritdoc />
UInt64 submit(const Enumerable<SharedPtr<const DirectX12CommandBuffer>>& commandBuffers) const override;
UInt64 submit(Span<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const override;

/// <inheritdoc />
void waitFor(UInt64 fence) const noexcept override;
Expand Down Expand Up @@ -1816,7 +1802,7 @@ namespace LiteFX::Rendering::Backends {
// RenderBackend interface.
public:
/// <inheritdoc />
Enumerable<const DirectX12GraphicsAdapter*> listAdapters() const override;
const Array<UniquePtr<const DirectX12GraphicsAdapter>>& adapters() const override;

/// <inheritdoc />
const DirectX12GraphicsAdapter* findAdapter(const Optional<UInt64>& adapterId = std::nullopt) const override;
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 @@ -11,7 +11,7 @@ class DirectX12Backend::DirectX12BackendImpl : public Implement<DirectX12Backend
friend class DirectX12Backend;

private:
Array<UniquePtr<DirectX12GraphicsAdapter>> m_adapters{ };
Array<UniquePtr<const DirectX12GraphicsAdapter>> m_adapters{ };
Dictionary<String, UniquePtr<DirectX12Device>> m_devices;
ComPtr<ID3D12Debug> m_debugInterface;
const App& m_app;
Expand Down Expand Up @@ -105,9 +105,9 @@ void DirectX12Backend::deactivate()
this->state() = BackendState::Inactive;
}

Enumerable<const DirectX12GraphicsAdapter*> DirectX12Backend::listAdapters() const
const Array<UniquePtr<const DirectX12GraphicsAdapter>>& DirectX12Backend::adapters() const
{
return m_impl->m_adapters | std::views::transform([](const UniquePtr<DirectX12GraphicsAdapter>& adapter) { return adapter.get(); });
return m_impl->m_adapters;
}

const DirectX12GraphicsAdapter* DirectX12Backend::findAdapter(const Optional<UInt64>& adapterId) const
Expand Down
4 changes: 2 additions & 2 deletions src/Backends/DirectX12/src/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void DirectX12CommandBuffer::drawIndexed(UInt32 indices, UInt32 instances, UInt3

void DirectX12CommandBuffer::pushConstants(const DirectX12PushConstantsLayout& layout, const void* const memory) const noexcept
{
std::ranges::for_each(layout.ranges(), [this, &layout, &memory](const DirectX12PushConstantsRange* range) { this->handle()->SetGraphicsRoot32BitConstants(range->rootParameterIndex(), range->size() / 4, reinterpret_cast<const char* const>(memory) + range->offset(), 0); });
std::ranges::for_each(layout.ranges(), [this, &layout, &memory](auto& range) { this->handle()->SetGraphicsRoot32BitConstants(range->rootParameterIndex(), range->size() / 4, reinterpret_cast<const char* const>(memory) + range->offset(), 0); });
}

void DirectX12CommandBuffer::writeTimingEvent(SharedPtr<const TimingEvent> timingEvent) const
Expand All @@ -400,7 +400,7 @@ void DirectX12CommandBuffer::execute(SharedPtr<const DirectX12CommandBuffer> com
this->handle()->ExecuteBundle(commandBuffer->handle().Get());
}

void DirectX12CommandBuffer::execute(Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const
void DirectX12CommandBuffer::execute(Span<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const
{
std::ranges::for_each(commandBuffers, [this](auto& bundle) { this->handle()->ExecuteBundle(bundle->handle().Get()); });
}
Expand Down
Loading

0 comments on commit 3f49dd7

Please sign in to comment.