LiteFX 0.3.1.2022
Computer Graphics Engine
dx12_builders.hpp
1#pragma once
2
3#include <litefx/rendering_builders.hpp>
4#include "dx12_api.hpp"
5#include "dx12.hpp"
6
7#if defined(BUILD_DEFINE_BUILDERS)
9 using namespace LiteFX::Math;
10 using namespace LiteFX::Rendering;
11
16 class LITEFX_DIRECTX12_API DirectX12ShaderProgramBuilder : public ShaderProgramBuilder<DirectX12ShaderProgramBuilder, DirectX12ShaderProgram> {
17 LITEFX_IMPLEMENTATION(DirectX12ShaderProgramBuilderImpl);
18
19 public:
24 explicit DirectX12ShaderProgramBuilder(const DirectX12Device& device);
25 DirectX12ShaderProgramBuilder(const DirectX12ShaderProgramBuilder&) = delete;
26 DirectX12ShaderProgramBuilder(DirectX12ShaderProgramBuilder&&) = delete;
27 virtual ~DirectX12ShaderProgramBuilder() noexcept;
28
29 // Builder interface.
30 protected:
32 virtual void build() override;
33
34 // ShaderProgramBuilder interface.
35 public:
37 virtual DirectX12ShaderProgramBuilder& withShaderModule(const ShaderStage& type, const String& fileName, const String& entryPoint = "main") override;
38
40 virtual DirectX12ShaderProgramBuilder& withShaderModule(const ShaderStage& type, std::istream& stream, const String& name, const String& entryPoint = "main") override;
41
43 virtual DirectX12ShaderProgramBuilder& withVertexShaderModule(const String& fileName, const String& entryPoint = "main") override;
44
46 virtual DirectX12ShaderProgramBuilder& withVertexShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
47
49 virtual DirectX12ShaderProgramBuilder& withTessellationControlShaderModule(const String& fileName, const String& entryPoint = "main") override;
50
52 virtual DirectX12ShaderProgramBuilder& withTessellationControlShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
53
55 virtual DirectX12ShaderProgramBuilder& withTessellationEvaluationShaderModule(const String& fileName, const String& entryPoint = "main") override;
56
58 virtual DirectX12ShaderProgramBuilder& withTessellationEvaluationShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
59
61 virtual DirectX12ShaderProgramBuilder& withGeometryShaderModule(const String& fileName, const String& entryPoint = "main") override;
62
64 virtual DirectX12ShaderProgramBuilder& withGeometryShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
65
67 virtual DirectX12ShaderProgramBuilder& withFragmentShaderModule(const String& fileName, const String& entryPoint = "main") override;
68
70 virtual DirectX12ShaderProgramBuilder& withFragmentShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
71
73 virtual DirectX12ShaderProgramBuilder& withComputeShaderModule(const String& fileName, const String& entryPoint = "main") override;
74
76 virtual DirectX12ShaderProgramBuilder& withComputeShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
77 };
78
83 class LITEFX_DIRECTX12_API DirectX12RasterizerBuilder : public RasterizerBuilder<DirectX12RasterizerBuilder, DirectX12Rasterizer> {
84 LITEFX_IMPLEMENTATION(DirectX12RasterizerBuilderImpl);
85
86 public:
90 explicit DirectX12RasterizerBuilder() noexcept;
91 DirectX12RasterizerBuilder(const DirectX12RasterizerBuilder&) noexcept = delete;
92 DirectX12RasterizerBuilder(DirectX12RasterizerBuilder&&) noexcept = delete;
93 virtual ~DirectX12RasterizerBuilder() noexcept;
94
95 // Builder interface.
96 public:
98 virtual void build() override;
99
100 // RasterizerBuilder interface.
101 public:
103 virtual DirectX12RasterizerBuilder& polygonMode(const PolygonMode& mode = PolygonMode::Solid) noexcept override;
104
106 virtual DirectX12RasterizerBuilder& cullMode(const CullMode& cullMode = CullMode::BackFaces) noexcept override;
107
109 virtual DirectX12RasterizerBuilder& cullOrder(const CullOrder& cullOrder = CullOrder::CounterClockWise) noexcept override;
110
112 virtual DirectX12RasterizerBuilder& lineWidth(const Float& lineWidth = 1.f) noexcept override;
113
115 virtual DirectX12RasterizerBuilder& depthBias(const DepthStencilState::DepthBias& depthBias) noexcept override;
116
118 virtual DirectX12RasterizerBuilder& depthState(const DepthStencilState::DepthState& depthState) noexcept override;
119
121 virtual DirectX12RasterizerBuilder& stencilState(const DepthStencilState::StencilState& stencilState) noexcept override;
122 };
123
129 class LITEFX_DIRECTX12_API DirectX12VertexBufferLayoutBuilder : public VertexBufferLayoutBuilder<DirectX12VertexBufferLayoutBuilder, DirectX12VertexBufferLayout, DirectX12InputAssemblerBuilder> {
130 public:
131 using VertexBufferLayoutBuilder<DirectX12VertexBufferLayoutBuilder, DirectX12VertexBufferLayout, DirectX12InputAssemblerBuilder>::VertexBufferLayoutBuilder;
132
133 public:
135 virtual DirectX12VertexBufferLayoutBuilder& withAttribute(UniquePtr<BufferAttribute>&& attribute) override;
136
137 public:
148 virtual DirectX12VertexBufferLayoutBuilder& withAttribute(const BufferFormat& format, const UInt32& offset, const AttributeSemantic& semantic = AttributeSemantic::Unknown, const UInt32& semanticIndex = 0);
149
158 virtual DirectX12VertexBufferLayoutBuilder& withAttribute(const UInt32& location, const BufferFormat& format, const UInt32& offset, const AttributeSemantic& semantic = AttributeSemantic::Unknown, const UInt32& semanticIndex = 0);
159 };
160
165 class LITEFX_DIRECTX12_API DirectX12InputAssemblerBuilder : public InputAssemblerBuilder<DirectX12InputAssemblerBuilder, DirectX12InputAssembler> {
166 LITEFX_IMPLEMENTATION(DirectX12InputAssemblerBuilderImpl);
167
168 public:
172 explicit DirectX12InputAssemblerBuilder() noexcept;
173 DirectX12InputAssemblerBuilder(const DirectX12InputAssemblerBuilder&) noexcept = delete;
174 DirectX12InputAssemblerBuilder(DirectX12InputAssemblerBuilder&&) noexcept = delete;
175 virtual ~DirectX12InputAssemblerBuilder() noexcept;
176
177 // Builder interface.
178 public:
180 virtual void build() override;
181
182 // InputAssemblerBuilder interface.
183 public:
185 virtual DirectX12InputAssemblerBuilder& topology(const PrimitiveTopology& topology) override;
186
188 virtual void use(UniquePtr<DirectX12VertexBufferLayout>&& layout) override;
189
191 virtual void use(UniquePtr<DirectX12IndexBufferLayout>&& layout) override;
192
193 public:
199 virtual DirectX12VertexBufferLayoutBuilder vertexBuffer(const size_t& elementSize, const UInt32& binding = 0);
200
205 virtual DirectX12InputAssemblerBuilder& indexType(const IndexType& type);
206 };
207
214 class LITEFX_DIRECTX12_API DirectX12DescriptorSetLayoutBuilder : public DescriptorSetLayoutBuilder<DirectX12DescriptorSetLayoutBuilder, DirectX12DescriptorSetLayout, DirectX12PipelineLayoutBuilder> {
215 LITEFX_IMPLEMENTATION(DirectX12DescriptorSetLayoutBuilderImpl);
216
217 public:
226 explicit DirectX12DescriptorSetLayoutBuilder(DirectX12PipelineLayoutBuilder& parent, const UInt32& space = 0, const ShaderStage& stages = ShaderStage::Fragment | ShaderStage::Geometry | ShaderStage::TessellationControl | ShaderStage::TessellationEvaluation | ShaderStage::Vertex, const UInt32& poolSize = 0, const UInt32& maxUnboundedArraySize = 0);
227 DirectX12DescriptorSetLayoutBuilder(const DirectX12DescriptorSetLayoutBuilder&) = delete;
228 DirectX12DescriptorSetLayoutBuilder(DirectX12DescriptorSetLayoutBuilder&&) = delete;
229 virtual ~DirectX12DescriptorSetLayoutBuilder() noexcept;
230
231 // Builder interface.
232 public:
234 virtual void build() override;
235
236 // DescriptorSetLayoutBuilder interface.
237 public:
239 virtual DirectX12DescriptorSetLayoutBuilder& withDescriptor(UniquePtr<DirectX12DescriptorLayout>&& layout) override;
240
242 virtual DirectX12DescriptorSetLayoutBuilder& withDescriptor(const DescriptorType& type, const UInt32& binding, const UInt32& descriptorSize, const UInt32& descriptors = 1) override;
243
245 virtual DirectX12DescriptorSetLayoutBuilder& withStaticSampler(const UInt32& binding, const FilterMode& magFilter = FilterMode::Nearest, const FilterMode& minFilter = FilterMode::Nearest, const BorderMode& borderU = BorderMode::Repeat, const BorderMode& borderV = BorderMode::Repeat, const BorderMode& borderW = BorderMode::Repeat, const MipMapMode& mipMapMode = MipMapMode::Nearest, const Float& mipMapBias = 0.f, const Float& minLod = 0.f, const Float& maxLod = std::numeric_limits<Float>::max(), const Float& anisotropy = 0.f) override;
246
247 // DirectX12DescriptorSetLayoutBuilder.
248 public:
253 virtual DirectX12DescriptorSetLayoutBuilder& space(const UInt32& space) noexcept;
254
259 virtual DirectX12DescriptorSetLayoutBuilder& shaderStages(const ShaderStage& stages) noexcept;
260
265 virtual DirectX12DescriptorSetLayoutBuilder& poolSize(const UInt32& poolSize) noexcept;
266 };
267
272 class LITEFX_DIRECTX12_API DirectX12PushConstantsLayoutBuilder : public PushConstantsLayoutBuilder<DirectX12PushConstantsLayoutBuilder, DirectX12PushConstantsLayout, DirectX12PipelineLayoutBuilder> {
273 LITEFX_IMPLEMENTATION(DirectX12PushConstantsLayoutBuilderImpl);
274
275 public:
281 explicit DirectX12PushConstantsLayoutBuilder(DirectX12PipelineLayoutBuilder& parent, const UInt32& size);
282 DirectX12PushConstantsLayoutBuilder(const DirectX12PushConstantsLayoutBuilder&) = delete;
283 DirectX12PushConstantsLayoutBuilder(DirectX12PushConstantsLayoutBuilder&&) = delete;
284 virtual ~DirectX12PushConstantsLayoutBuilder() noexcept;
285
286 // Builder interface.
287 public:
289 virtual void build() override;
290
291 // PushConstantsLayoutBuilder interface.
292 public:
293 virtual DirectX12PushConstantsLayoutBuilder& withRange(const ShaderStage& shaderStages, const UInt32& offset, const UInt32& size, const UInt32& space, const UInt32& binding) override;
294 };
295
302 class LITEFX_DIRECTX12_API DirectX12PipelineLayoutBuilder : public PipelineLayoutBuilder<DirectX12PipelineLayoutBuilder, DirectX12PipelineLayout> {
303 LITEFX_IMPLEMENTATION(DirectX12PipelineLayoutBuilderImpl);
304 friend class DirectX12DescriptorSetLayoutBuilder;
305
306 public:
310 DirectX12PipelineLayoutBuilder(const DirectX12Device& device);
311 DirectX12PipelineLayoutBuilder(DirectX12PipelineLayoutBuilder&&) = delete;
312 DirectX12PipelineLayoutBuilder(const DirectX12PipelineLayoutBuilder&) = delete;
313 virtual ~DirectX12PipelineLayoutBuilder() noexcept;
314
315 // Builder interface.
316 public:
318 virtual void build() override;
319
320 // PipelineBuilder interface.
321 public:
323 virtual void use(UniquePtr<DirectX12DescriptorSetLayout>&& layout) override;
324
326 virtual void use(UniquePtr<DirectX12PushConstantsLayout>&& layout) override;
327
328 // DirectX12PipelineLayoutBuilder.
329 public:
336 virtual DirectX12DescriptorSetLayoutBuilder descriptorSet(const UInt32& space = 0, const ShaderStage& stages = ShaderStage::Compute | ShaderStage::Fragment | ShaderStage::Geometry | ShaderStage::TessellationControl | ShaderStage::TessellationEvaluation | ShaderStage::Vertex, const UInt32& poolSize = 0);
337
342 virtual DirectX12PushConstantsLayoutBuilder pushConstants(const UInt32& size);
343
344 private:
349 virtual const DirectX12Device& device() const noexcept;
350 };
351
356 class LITEFX_DIRECTX12_API DirectX12RenderPipelineBuilder : public RenderPipelineBuilder<DirectX12RenderPipelineBuilder, DirectX12RenderPipeline> {
357 LITEFX_IMPLEMENTATION(DirectX12RenderPipelineBuilderImpl);
358
359 public:
365 explicit DirectX12RenderPipelineBuilder(const DirectX12RenderPass& renderPass, const String& name = "");
366 DirectX12RenderPipelineBuilder(DirectX12RenderPipelineBuilder&&) = delete;
367 DirectX12RenderPipelineBuilder(const DirectX12RenderPipelineBuilder&) = delete;
368 virtual ~DirectX12RenderPipelineBuilder() noexcept;
369
370 // Builder interface.
371 public:
373 virtual void build() override;
374
375 // RenderPipelineBuilder interface.
376 public:
378 virtual DirectX12RenderPipelineBuilder& shaderProgram(SharedPtr<DirectX12ShaderProgram> shaderProgram) override;
379
381 virtual DirectX12RenderPipelineBuilder& layout(SharedPtr<DirectX12PipelineLayout> layout) override;
382
384 virtual DirectX12RenderPipelineBuilder& rasterizer(SharedPtr<DirectX12Rasterizer> rasterizer) override;
385
387 virtual DirectX12RenderPipelineBuilder& inputAssembler(SharedPtr<DirectX12InputAssembler> inputAssembler) override;
388
390 virtual DirectX12RenderPipelineBuilder& viewport(SharedPtr<IViewport> viewport) override;
391
393 virtual DirectX12RenderPipelineBuilder& scissor(SharedPtr<IScissor> scissor) override;
394
396 virtual DirectX12RenderPipelineBuilder& enableAlphaToCoverage(const bool& enable = true) override;
397 };
398
403 class LITEFX_DIRECTX12_API DirectX12ComputePipelineBuilder : public ComputePipelineBuilder<DirectX12ComputePipelineBuilder, DirectX12ComputePipeline> {
404 LITEFX_IMPLEMENTATION(DirectX12ComputePipelineBuilderImpl);
405
406 public:
412 explicit DirectX12ComputePipelineBuilder(const DirectX12Device& device, const String& name = "");
413 DirectX12ComputePipelineBuilder(DirectX12ComputePipelineBuilder&&) = delete;
414 DirectX12ComputePipelineBuilder(const DirectX12ComputePipelineBuilder&) = delete;
415 virtual ~DirectX12ComputePipelineBuilder() noexcept;
416
417 // Builder interface.
418 public:
420 virtual void build() override;
421
422 // ComputePipelineBuilder interface.
423 public:
425 virtual DirectX12ComputePipelineBuilder& shaderProgram(SharedPtr<DirectX12ShaderProgram> program) override;
426
428 virtual DirectX12ComputePipelineBuilder& layout(SharedPtr<DirectX12PipelineLayout> layout) override;
429 };
430
435 class LITEFX_DIRECTX12_API DirectX12RenderPassBuilder : public RenderPassBuilder<DirectX12RenderPassBuilder, DirectX12RenderPass> {
436 LITEFX_IMPLEMENTATION(DirectX12RenderPassBuilderImpl)
437
438 public:
444 explicit DirectX12RenderPassBuilder(const DirectX12Device& device, const String& name = "") noexcept;
445
452 explicit DirectX12RenderPassBuilder(const DirectX12Device& device, const MultiSamplingLevel& samples = MultiSamplingLevel::x1, const String& name = "") noexcept;
453
460 explicit DirectX12RenderPassBuilder(const DirectX12Device& device, const UInt32& commandBuffers, const String& name = "") noexcept;
461
469 explicit DirectX12RenderPassBuilder(const DirectX12Device& device, const UInt32& commandBuffers, const MultiSamplingLevel& multiSamplingLevel, const String& name = "") noexcept;
470 DirectX12RenderPassBuilder(const DirectX12RenderPassBuilder&) noexcept = delete;
471 DirectX12RenderPassBuilder(DirectX12RenderPassBuilder&&) noexcept = delete;
472 virtual ~DirectX12RenderPassBuilder() noexcept;
473
474 // Builder interface.
475 public:
477 virtual void build() override;
478
479 // RenderPassBuilder interface.
480 public:
482 virtual DirectX12RenderPassBuilder& commandBuffers(const UInt32& count) override;
483
485 virtual DirectX12RenderPassBuilder& multiSamplingLevel(const MultiSamplingLevel& samples) override;
486
488 virtual DirectX12RenderPassBuilder& renderTarget(const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
489
491 virtual DirectX12RenderPassBuilder& renderTarget(const String& name, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
492
494 virtual DirectX12RenderPassBuilder& renderTarget(const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
495
497 virtual DirectX12RenderPassBuilder& renderTarget(const String& name, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
498
500 virtual DirectX12RenderPassBuilder& renderTarget(DirectX12InputAttachmentMapping& output, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
501
503 virtual DirectX12RenderPassBuilder& renderTarget(const String& name, DirectX12InputAttachmentMapping& output, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
504
506 virtual DirectX12RenderPassBuilder& renderTarget(DirectX12InputAttachmentMapping& output, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
507
509 virtual DirectX12RenderPassBuilder& renderTarget(const String& name, DirectX12InputAttachmentMapping& output, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
510
512 virtual DirectX12RenderPassBuilder& inputAttachment(const DirectX12InputAttachmentMapping& inputAttachment) override;
513
515 virtual DirectX12RenderPassBuilder& inputAttachment(const UInt32& inputLocation, const DirectX12RenderPass& renderPass, const UInt32& outputLocation) override;
516
518 virtual DirectX12RenderPassBuilder& inputAttachment(const UInt32& inputLocation, const DirectX12RenderPass& renderPass, const RenderTarget& renderTarget) override;
519 };
520}
521#endif // defined(BUILD_DEFINE_BUILDERS)
Definition: math.hpp:349
Stores the depth/stencil state of a see IRasterizer.
Definition: rendering_api.hpp:2066
The interface of a scissor.
Definition: rendering_api.hpp:2415
Interface for a viewport.
Definition: rendering_api.hpp:2331
Implements a render target.
Definition: rendering_api.hpp:1994
Definition: math.hpp:30
uint32_t UInt32
Definition: math.hpp:37
float_t Float
Definition: math.hpp:40
Definition: dx12.hpp:8
Definition: dx12.hpp:8
std::string String
Definition: string.hpp:19
std::shared_ptr< T > SharedPtr
Represents a shared pointer, that expresses non-exclusive ownership.
Definition: containers.hpp:94
std::unique_ptr< T, TDeleter > UniquePtr
Represents a unique pointer, that expresses exclusive ownership.
Definition: containers.hpp:87
Definition: graphics.hpp:11