CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPUDevice.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Common.hpp"
11#include "Forward.hpp"
12
14#include "GPUSwapchain.hpp"
15
18
25
26#include <any>
27#include <ostream>
28
29namespace CeresEngine {
30
32 enum class CE_SCRIPT_EXPORT() Origin {
36
40 };
41
47
51 };
52
58 bool hasRenderTargets = false;
59
62 bool has3DImages = false;
63
66 bool hasCubeImages = false;
67
70 bool hasArrayImages = false;
71
74 bool hasCubeArrayImages = false;
75
78 bool hasMultiSampleImages = false;
79
82 bool hasSamplers = false;
83
87 bool hasConstantBuffers = false;
88
92 bool hasStorageBuffers = false;
93
96 bool hasGeometryShaders = false;
97
100 bool hasTessellationShaders = false;
101
104 bool hasComputeShaders = false;
105
108 bool hasInstancing = false;
109
113 bool hasOffsetInstancing = false;
114
118 bool hasViewportArrays = false;
119
122 bool hasConservativeRasterization = false;
123
126 bool hasStreamOutputs = false;
127
130 bool hasLogicOp = false;
131
134 bool hasPipelineStatistics = false;
135
138 bool hasRenderCondition = false;
139
142 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
143 CE_REFL_DATA(hasRenderTargets);
144 CE_REFL_DATA(has3DImages);
145 CE_REFL_DATA(hasCubeImages);
146 CE_REFL_DATA(hasArrayImages);
147 CE_REFL_DATA(hasCubeArrayImages);
148 CE_REFL_DATA(hasMultiSampleImages);
149 CE_REFL_DATA(hasSamplers);
150 CE_REFL_DATA(hasConstantBuffers);
151 CE_REFL_DATA(hasStorageBuffers);
152 CE_REFL_DATA(hasGeometryShaders);
153 CE_REFL_DATA(hasTessellationShaders);
154 CE_REFL_DATA(hasComputeShaders);
155 CE_REFL_DATA(hasInstancing);
156 CE_REFL_DATA(hasOffsetInstancing);
157 CE_REFL_DATA(hasViewportArrays);
158 CE_REFL_DATA(hasConservativeRasterization);
159 CE_REFL_DATA(hasStreamOutputs);
160 CE_REFL_DATA(hasLogicOp);
161 CE_REFL_DATA(hasPipelineStatistics);
162 CE_REFL_DATA(hasRenderCondition);
163 }
164 };
165
171 float lineWidthRange[2] = {1.0f, 1.0f};
172
176 float lineWidthGranularity;
177
181 UInt32 maxImageArrayLayers = 0;
182
187 UInt32 maxColorAttachments = 0;
188
191 UInt32 maxPatchVertices = 0;
192
195 UInt32 max1DImageSize = 0;
196
200 UInt32 max2DImageSize = 0;
201
205 UInt32 max3DImageSize = 0;
206
210 UInt32 maxCubeImageSize = 0;
211
214 UInt32 maxAnisotropy = 0;
215
217 TVector3<UInt32> maxComputeShaderWorkGroups = {0, 0, 0};
218
220 TVector3<UInt32> maxComputeShaderWorkGroupSize = {0, 0, 0};
221
225 UInt32 maxViewports = 0;
226
229 TExtent2<UInt32> maxViewportSize = {0u, 0u};
230
236 UInt64 maxBufferSize = 0;
237
243 UInt64 maxConstantBufferSize = 0;
244
247 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
248 // CE_REFL_DATA(lineWidthRange);
249 CE_REFL_DATA(lineWidthGranularity);
250 CE_REFL_DATA(maxImageArrayLayers);
251 CE_REFL_DATA(maxColorAttachments);
252 CE_REFL_DATA(maxPatchVertices);
253 CE_REFL_DATA(max1DImageSize);
254 CE_REFL_DATA(max2DImageSize);
255 CE_REFL_DATA(max3DImageSize);
256 CE_REFL_DATA(maxCubeImageSize);
257 CE_REFL_DATA(maxAnisotropy);
258 CE_REFL_DATA(maxComputeShaderWorkGroups);
259 CE_REFL_DATA(maxComputeShaderWorkGroupSize);
260 CE_REFL_DATA(maxViewports);
261 CE_REFL_DATA(maxViewportSize);
262 CE_REFL_DATA(maxBufferSize);
263 CE_REFL_DATA(maxConstantBufferSize);
264 }
265 };
266
274 Origin screenSpaceOrigin = Origin::UpperLeft;
275
279 Origin imageSpaceOrigin = Origin::UpperLeft;
280
283 ClippingRange clippingRange = ClippingRange::ZeroToOne;
284
286 Vector<Format> imageFormats;
287
293
299
302 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
303 CE_REFL_DATA(screenSpaceOrigin);
304 CE_REFL_DATA(imageSpaceOrigin);
305 CE_REFL_DATA(clippingRange);
306 CE_REFL_DATA(imageFormats);
307 CE_REFL_DATA(features);
308 CE_REFL_DATA(limits);
309 }
310 };
311
316 GPURenderingFeatures enabledFeatures;
317
319 Any rendererDescriptor;
320
323 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
324 CE_REFL_DATA(enabledFeatures);
325 // CE_REFL_DATA(rendererDescriptor);
326 }
327 };
328
333 String rendererName;
334
337 String deviceName;
338
341 String vendorName;
342
345 String shadingLanguageName;
346
349 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
350 CE_REFL_DATA(rendererName);
351 CE_REFL_DATA(deviceName);
352 CE_REFL_DATA(vendorName);
353 CE_REFL_DATA(shadingLanguageName);
354 }
355 };
356
358 public:
359 CE_SCRIPT_EXPORT(pass = "ref", readonly = true)
360 ExecutionContext& transferExecutionContext;
361
363 const GPUDeviceInfo& information;
364
366 const GPURenderingCapabilities& capabilities;
367
368 public:
374 explicit GPUDevice(ExecutionContext& transferExecutionContext, const GPUDeviceInfo& information, const GPURenderingCapabilities& capabilities);
375
377 ~GPUDevice() override = default;
378
380 GPUDevice(const GPUDevice&) = delete;
381 GPUDevice& operator=(const GPUDevice&) = delete;
382
384 GPUDevice(GPUDevice&&) = delete;
385 GPUDevice& operator=(GPUDevice&&) = delete;
386
387 public: // Factory methods
392 [[nodiscard]] CE_SCRIPT_EXPORT()
393 virtual GPUCommandBufferPtr createCommandBuffer(const GPUCommandBufferDescriptor& descriptor) = 0;
394
399 [[nodiscard]] CE_SCRIPT_EXPORT()
400 virtual GPURenderPassPtr createRenderPass(const GPURenderPassDescriptor& descriptor) = 0;
401
406 [[nodiscard]] CE_SCRIPT_EXPORT()
407 virtual GPUPipelineLayoutPtr createPipelineLayout(const GPUPipelineLayoutDescriptor& descriptor) = 0;
408
413 [[nodiscard]] CE_SCRIPT_EXPORT()
414 virtual GPUGraphicsPipelinePtr createGraphicsPipeline(const GPUGraphicsPipelineDescriptor& descriptor) = 0;
415
420 [[nodiscard]] CE_SCRIPT_EXPORT()
421 virtual GPUComputePipelinePtr createComputePipeline(const GPUComputePipelineDescriptor& descriptor) = 0;
422
427 [[nodiscard]] CE_SCRIPT_EXPORT()
428 virtual GPUShaderPtr createShader(const GPUShaderDescriptor& descriptor) = 0;
429
434 [[nodiscard]] CE_SCRIPT_EXPORT()
435 virtual GPUShaderProgramPtr createShaderProgram(const GPUShaderProgramDescriptor& descriptor) = 0;
436
441 [[nodiscard]] CE_SCRIPT_EXPORT()
442 virtual GPURenderTargetPtr createRenderTarget(const GPURenderTargetDescriptor& descriptor) = 0;
443
448 [[nodiscard]] CE_SCRIPT_EXPORT()
449 virtual GPUBufferPtr createBuffer(const GPUBufferDescriptor& descriptor) = 0;
450
455 [[nodiscard]] virtual Async<GPUBufferPtr> createBufferAsync(const GPUBufferDescriptor& descriptor);
456
461 [[nodiscard]] CE_SCRIPT_EXPORT()
462 virtual GPUImagePtr createImage(const GPUImageDescriptor& descriptor) = 0;
463
468 [[nodiscard]] virtual Async<GPUImagePtr> createImageAsync(const GPUImageDescriptor& descriptor);
469
474 [[nodiscard]] CE_SCRIPT_EXPORT()
475 virtual GPUSamplerPtr createSampler(const GPUSamplerDescriptor& descriptor) = 0;
476
481 [[nodiscard]] CE_SCRIPT_EXPORT()
482 virtual GPUFencePtr createFence(const GPUFenceDescriptor& descriptor) = 0;
483
488 [[nodiscard]] virtual GPUTimerQueryPtr createTimerQuery(const GPUTimerQueryDescriptor& descriptor) = 0;
489
494 [[nodiscard]] virtual GPUOcclusionQueryPtr createOcclusionQuery(const GPUOcclusionQueryDescriptor& descriptor) = 0;
495
500 [[nodiscard]] virtual GPUSwapchainPtr createSwapchain(const GPUSwapchainDescriptor& descriptor) = 0;
501
502 public:
504 [[nodiscard]] CE_SCRIPT_EXPORT()
505 virtual GPUCommandQueuePtr getGraphicsQueue() = 0;
506
508 [[nodiscard]] CE_SCRIPT_EXPORT()
509 virtual GPUCommandQueuePtr getTransferQueue() = 0;
510
512 [[nodiscard]] CE_SCRIPT_EXPORT()
513 virtual GPUCommandQueuePtr getComputeQueue() = 0;
514 };
515
524 using ValidateRenderingCapabilitiesFunc = std::function<bool(const String& info, const String& attrib)>;
525
565 [[nodiscard]] bool validateRenderingCapabilities(const GPURenderingCapabilities& presentCaps, const GPURenderingCapabilities& requiredCaps,
566 const ValidateRenderingCapabilitiesFunc& callback = nullptr) noexcept;
567
572 std::ostream& operator<<(std::ostream& os, const GPUDeviceInfo& info);
573
578 std::ostream& operator<<(std::ostream& os, Origin origin);
579
584 std::ostream& operator<<(std::ostream& os, ClippingRange clippingRange);
585
590 std::ostream& operator<<(std::ostream& os, const GPURenderingFeatures& features);
591
596 std::ostream& operator<<(std::ostream& os, const GPURenderingLimits& limits);
597
602 std::ostream& operator<<(std::ostream& os, const GPURenderingCapabilities& capabilities);
603
604} // namespace CeresEngine
605
608
611
614
617
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Definition Any.hpp:13
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
A context for function object execution.
Definition ExecutionContext.hpp:90
Definition GPUDevice.hpp:357
Definition Common.hpp:16
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
std::function< bool(const String &info, const String &attrib)> ValidateRenderingCapabilitiesFunc
Callback interface for the validateRenderingCapabilities function.
Definition GPUDevice.hpp:524
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
Origin
Screen coordinate system origin enumeration.
Definition GPUDevice.hpp:32
@ UpperLeft
Specifies a screen origin in the upper-left.
@ LowerLeft
Specifies a screen origin in the lower-left.
Format
Definition TextureFormat.hpp:54
ClippingRange
Clipping depth range enumeration.
Definition GPUDevice.hpp:43
@ ZeroToOne
Specifies the clipping depth range [0, 1].
@ MinusOneToOne
Specifies the clipping depth range [-1, 1].
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
Hardware buffer descriptor structure.
Definition GPUBuffer.hpp:92
Command buffer descriptor structure.
Definition GPUCommandBuffer.hpp:32
Compute pipeline descriptor structure.
Definition GPUComputePipeline.hpp:25
Device descriptor structure.
Definition GPUDevice.hpp:313
Renderer basic information structure.
Definition GPUDevice.hpp:330
Definition GPUFence.hpp:23
Definition GPUGraphicsPipeline.hpp:721
Definition GPUImage.hpp:247
Definition GPUQuery.hpp:171
Pipeline layout descriptor structure.
Definition GPUPipelineLayout.hpp:70
Render pass descriptor structure.
Definition GPURenderPass.hpp:112
Definition GPURenderTarget.hpp:78
Structure with all attributes describing the rendering capabilities of the render system.
Definition GPUDevice.hpp:269
Contains the attributes for all supported rendering features.
Definition GPUDevice.hpp:54
Contains all rendering limitations such as maximum buffer size, maximum image resolution etc.
Definition GPUDevice.hpp:168
Image sampler descriptor structure.
Definition GPUSampler.hpp:61
Shader source and binary code descriptor structure.
Definition GPUShader.hpp:193
Descriptor structure for shader programs.
Definition GPUShader.hpp:303
Swapchain descriptor structure.
Definition GPUSwapchain.hpp:50
A descriptor structure for TimerQuery.
Definition GPUQuery.hpp:29