Plasma Engine  2.0
Loading...
Searching...
No Matches
RendererFoundationDLL.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Reflection/Reflection.h>
5#include <Foundation/Types/Id.h>
6#include <Foundation/Types/RefCounted.h>
7
8// Configure the DLL Import/Export Define
9#if PL_ENABLED(PL_COMPILE_ENGINE_AS_DLL)
10# ifdef BUILDSYSTEM_BUILDING_RENDERERFOUNDATION_LIB
11# define PL_RENDERERFOUNDATION_DLL PL_DECL_EXPORT
12# else
13# define PL_RENDERERFOUNDATION_DLL PL_DECL_IMPORT
14# endif
15#else
16# define PL_RENDERERFOUNDATION_DLL
17#endif
18
19// #TODO_SHADER obsolete, DX11 only
20#define PL_GAL_MAX_CONSTANT_BUFFER_COUNT 16
21#define PL_GAL_MAX_SAMPLER_COUNT 16
22
23// Necessary array sizes
24#define PL_GAL_MAX_VERTEX_BUFFER_COUNT 16
25#define PL_GAL_MAX_RENDERTARGET_COUNT 8
26
27// Forward declarations
28
45
46class plGALSwapChain;
47class plGALShader;
49class plGALTexture;
51class plGALBuffer;
53class plGALBlendState;
63class plGALDevice;
65
66// Basic enums
68{
69 using StorageType = plUInt8;
70 enum Enum
71 {
72 // keep this order, it is used to allocate the desired number of indices in plMeshBufferResourceDescriptor::AllocateStreams
73 Points, // 1 index per primitive
74 Lines, // 2 indices per primitive
75 Triangles, // 3 indices per primitive
76 ENUM_COUNT,
77 Default = Triangles
78 };
79
80 static plUInt32 VerticesPerPrimitive(plGALPrimitiveTopology::Enum e) { return (plUInt32)e + 1; }
81};
82
83struct PL_RENDERERFOUNDATION_DLL plGALIndexType
84{
85 enum Enum
86 {
87 None, // indices are not used, vertices are just used in order to form primitives
88 UShort, // 16 bit indices are used to select which vertices shall form a primitive, thus meshes can only use up to 65535 vertices
89 UInt, // 32 bit indices are used to select which vertices shall form a primitive
90
91 ENUM_COUNT
92 };
93
94
96 static plUInt8 GetSize(plGALIndexType::Enum format) { return s_Size[format]; }
97
98private:
99 static const plUInt8 s_Size[plGALIndexType::ENUM_COUNT];
100};
101
104struct PL_RENDERERFOUNDATION_DLL plGALShaderStage
105{
106 using StorageType = plUInt8;
107
108 enum Enum : plUInt8
109 {
110 VertexShader,
111 HullShader,
112 DomainShader,
113 GeometryShader,
114 PixelShader,
115 ComputeShader,
116 /*
117 // #TODO_SHADER: Future work:
118 TaskShader,
119 MeshShader,
120 RayGenShader,
121 RayAnyHitShader,
122 RayClosestHitShader,
123 RayMissShader,
124 RayIntersectionShader,
125 */
126 ENUM_COUNT,
127 Default = VertexShader
128 };
129
130 static const char* Names[ENUM_COUNT];
131};
132
135struct PL_RENDERERFOUNDATION_DLL plGALShaderStageFlags
136{
137 using StorageType = plUInt16;
138
139 enum Enum : plUInt16
140 {
141 VertexShader = PL_BIT(0),
142 HullShader = PL_BIT(1),
143 DomainShader = PL_BIT(2),
144 GeometryShader = PL_BIT(3),
145 PixelShader = PL_BIT(4),
146 ComputeShader = PL_BIT(5),
147 /*
148 // #TODO_SHADER: Future work:
149 TaskShader = PL_BIT(6),
150 MeshShader = PL_BIT(7),
151 RayGenShader = PL_BIT(8),
152 RayAnyHitShader = PL_BIT(9),
153 RayClosestHitShader = PL_BIT(10),
154 RayMissShader = PL_BIT(11),
155 RayIntersectionShader = PL_BIT(12),
156 */
157 Default = 0
158 };
159
160 struct Bits
161 {
162 StorageType VertexShader : 1;
163 StorageType HullShader : 1;
164 StorageType DomainShader : 1;
165 StorageType GeometryShader : 1;
166 StorageType PixelShader : 1;
167 StorageType ComputeShader : 1;
168 };
169
170 inline static plGALShaderStageFlags::Enum MakeFromShaderStage(plGALShaderStage::Enum stage)
171 {
172 return static_cast<plGALShaderStageFlags::Enum>(PL_BIT(stage));
173 }
174};
175PL_DECLARE_FLAGS_OPERATORS(plGALShaderStageFlags);
176
177
178struct PL_RENDERERFOUNDATION_DLL plGALMSAASampleCount
179{
180 using StorageType = plUInt8;
181
182 enum Enum
183 {
184 None = 1,
185 TwoSamples = 2,
186 FourSamples = 4,
187 EightSamples = 8,
188
189 ENUM_COUNT = 4,
190
191 Default = None
192 };
193};
194
196{
197 using StorageType = plUInt8;
198
199 enum Enum
200 {
201 Invalid = -1,
202 Texture2D = 0,
203 TextureCube,
204 Texture3D,
205 Texture2DProxy,
206 Texture2DShared,
207
208 ENUM_COUNT,
209
210 Default = Texture2D
211 };
212};
213
215{
216 using StorageType = plUInt8;
217
218 enum Enum
219 {
220 Zero = 0,
221 One,
222 SrcColor,
223 InvSrcColor,
224 SrcAlpha,
225 InvSrcAlpha,
226 DestAlpha,
227 InvDestAlpha,
228 DestColor,
229 InvDestColor,
230 SrcAlphaSaturated,
231 BlendFactor,
232 InvBlendFactor,
233
234 ENUM_COUNT,
235
236 Default = One
237 };
238};
239
241{
242 using StorageType = plUInt8;
243
244 enum Enum
245 {
246 Add = 0,
247 Subtract,
248 RevSubtract,
249 Min,
250 Max,
251
252 ENUM_COUNT,
253 Default = Add
254 };
255};
256
258{
259 using StorageType = plUInt8;
260
261 enum Enum
262 {
263 Keep = 0,
264 Zero,
265 Replace,
266 IncrementSaturated,
267 DecrementSaturated,
268 Invert,
269 Increment,
270 Decrement,
271
272 ENUM_COUNT,
273
274 Default = Keep
275 };
276};
277
279{
280 using StorageType = plUInt8;
281
282 enum Enum
283 {
284 Never = 0,
285 Less,
286 Equal,
287 LessEqual,
288 Greater,
289 NotEqual,
290 GreaterEqual,
291 Always,
292
293 ENUM_COUNT,
294
295 Default = Never
296 };
297};
298
301{
302 using StorageType = plUInt8;
303
305 enum Enum
306 {
307 None = 0,
308 Front = 1,
310 Back = 2,
312
313 ENUM_COUNT,
314
315 Default = Back
316 };
317};
318
320{
321 using StorageType = plUInt8;
322
323 enum Enum
324 {
325 Point = 0,
326 Linear,
327 Anisotropic,
328
329 Default = Linear
330 };
331};
332
342
345{
346 using StorageType = plUInt8;
347
348 enum Enum
349 {
353 Default = Expired
354 };
355};
356
357// Basic structs
359{
360 plUInt32 m_uiMipLevel = 0;
361 plUInt32 m_uiArraySlice = 0;
362};
363
365{
366 void* m_pData = nullptr;
367 plUInt32 m_uiRowPitch = 0;
368 plUInt32 m_uiSlicePitch = 0;
369};
370
372template <typename CreationDescription>
374{
375public:
376 plGALObject(const CreationDescription& description)
377 : m_Description(description)
378 {
379 }
380
381 PL_ALWAYS_INLINE const CreationDescription& GetDescription() const { return m_Description; }
382
383protected:
384 const CreationDescription m_Description;
385};
386
387// Handles
388namespace plGAL
389{
390 using pl16_16Id = plGenericId<16, 16>;
391 using pl18_14Id = plGenericId<18, 14>;
392 using pl20_12Id = plGenericId<20, 12>;
393 using pl20_44Id = plGenericId<20, 44>;
394} // namespace plGAL
395
397{
398 PL_DECLARE_HANDLE_TYPE(plGALSwapChainHandle, plGAL::pl16_16Id);
399
400 friend class plGALDevice;
401};
402
404{
405 PL_DECLARE_HANDLE_TYPE(plGALShaderHandle, plGAL::pl18_14Id);
406
407 friend class plGALDevice;
408};
409
411{
412 PL_DECLARE_HANDLE_TYPE(plGALTextureHandle, plGAL::pl18_14Id);
413
414 friend class plGALDevice;
415};
416
418{
419 PL_DECLARE_HANDLE_TYPE(plGALBufferHandle, plGAL::pl18_14Id);
420
421 friend class plGALDevice;
422};
423
425{
426 PL_DECLARE_HANDLE_TYPE(plGALTextureResourceViewHandle, plGAL::pl18_14Id);
427
428 friend class plGALDevice;
429};
430
432{
433 PL_DECLARE_HANDLE_TYPE(plGALBufferResourceViewHandle, plGAL::pl18_14Id);
434
435 friend class plGALDevice;
436};
437
439{
441
442 friend class plGALDevice;
443};
444
446{
448
449 friend class plGALDevice;
450};
451
453{
454 PL_DECLARE_HANDLE_TYPE(plGALRenderTargetViewHandle, plGAL::pl18_14Id);
455
456 friend class plGALDevice;
457};
458
460{
461 PL_DECLARE_HANDLE_TYPE(plGALDepthStencilStateHandle, plGAL::pl16_16Id);
462
463 friend class plGALDevice;
464};
465
467{
468 PL_DECLARE_HANDLE_TYPE(plGALBlendStateHandle, plGAL::pl16_16Id);
469
470 friend class plGALDevice;
471};
472
474{
475 PL_DECLARE_HANDLE_TYPE(plGALRasterizerStateHandle, plGAL::pl16_16Id);
476
477 friend class plGALDevice;
478};
479
481{
482 PL_DECLARE_HANDLE_TYPE(plGALSamplerStateHandle, plGAL::pl16_16Id);
483
484 friend class plGALDevice;
485};
486
488{
489 PL_DECLARE_HANDLE_TYPE(plGALVertexDeclarationHandle, plGAL::pl18_14Id);
490
491 friend class plGALDevice;
492};
493
497using plGALFenceHandle = plUInt64;
498
499namespace plGAL
500{
502 {
503 PL_ALWAYS_INLINE void Reset()
504 {
505 m_uiMin = plInvalidIndex;
506 m_uiMax = 0;
507 }
508
509 PL_FORCE_INLINE void SetToIncludeValue(plUInt32 value)
510 {
511 m_uiMin = plMath::Min(m_uiMin, value);
512 m_uiMax = plMath::Max(m_uiMax, value);
513 }
514
515 PL_FORCE_INLINE void SetToIncludeRange(plUInt32 uiMin, plUInt32 uiMax)
516 {
517 m_uiMin = plMath::Min(m_uiMin, uiMin);
518 m_uiMax = plMath::Max(m_uiMax, uiMax);
519 }
520
521 PL_ALWAYS_INLINE bool IsValid() const { return m_uiMin <= m_uiMax; }
522
523 PL_ALWAYS_INLINE plUInt32 GetCount() const { return m_uiMax - m_uiMin + 1; }
524
525 plUInt32 m_uiMin = plInvalidIndex;
526 plUInt32 m_uiMax = 0;
527 };
528} // namespace plGAL
Definition RendererFoundationDLL.h:467
Definition State.h:7
Definition RendererFoundationDLL.h:418
Definition Buffer.h:8
Definition RendererFoundationDLL.h:432
Definition ResourceView.h:30
Definition RendererFoundationDLL.h:446
Definition UnorderedAccesView.h:28
Definition CommandEncoder.h:11
Definition RendererFoundationDLL.h:460
Definition State.h:20
The plRenderDevice class is the primary interface for interactions with rendering APIs It contains a ...
Definition Device.h:19
Base class for GAL objects, stores a creation description of the object and also allows for reference...
Definition RendererFoundationDLL.h:374
Definition RendererFoundationDLL.h:474
Definition State.h:33
Definition RenderTargetSetup.h:19
Definition RendererFoundationDLL.h:453
Definition RenderTargetView.h:8
Definition Resource.h:9
Definition RendererFoundationDLL.h:481
Definition State.h:46
Definition RendererFoundationDLL.h:404
Definition Shader.h:7
Optional interface for plGALTexture if it was created via plGALDevice::CreateSharedTexture....
Definition Texture.h:33
Definition RendererFoundationDLL.h:397
Definition SwapChain.h:11
Definition RendererFoundationDLL.h:411
Definition Texture.h:8
Definition RendererFoundationDLL.h:425
Definition ResourceView.h:11
Definition RendererFoundationDLL.h:439
Definition UnorderedAccesView.h:11
Definition RendererFoundationDLL.h:488
Definition VertexDeclaration.h:8
Base class for reference counted objects.
Definition RefCounted.h:52
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39
Definition RendererFoundationDLL.h:502
The current state of an async operations in the renderer.
Definition RendererFoundationDLL.h:345
Enum
Definition RendererFoundationDLL.h:349
@ Pending
The async operation is still running, retry later.
Definition RendererFoundationDLL.h:351
@ Ready
The async operation has finished and the result is ready.
Definition RendererFoundationDLL.h:350
@ Expired
The async operation is too old and the result was thrown away. Pending results should be queried ever...
Definition RendererFoundationDLL.h:352
Definition RendererFoundationDLL.h:215
Definition RendererFoundationDLL.h:241
Definition Descriptors.h:70
Definition Descriptors.h:169
Definition Descriptors.h:211
Definition RendererFoundationDLL.h:279
Defines which sides of a polygon gets culled by the graphics card.
Definition RendererFoundationDLL.h:301
Enum
Defines which sides of a polygon gets culled by the graphics card.
Definition RendererFoundationDLL.h:306
@ Front
Definition RendererFoundationDLL.h:308
@ Back
Definition RendererFoundationDLL.h:310
@ None
Triangles do not get culled.
Definition RendererFoundationDLL.h:307
Definition Descriptors.h:39
Definition RendererFoundationDLL.h:84
static plUInt8 GetSize(plGALIndexType::Enum format)
The size in bytes of a single element of the given index format.
Definition RendererFoundationDLL.h:96
Definition RendererFoundationDLL.h:179
Definition RendererFoundationDLL.h:68
Describes the settings for a new rasterizer state. See plGALDevice::CreateRasterizerState.
Definition Descriptors.h:105
Definition Descriptors.h:220
Definition Descriptors.h:118
Definition Descriptors.h:44
Definition RendererFoundationDLL.h:161
A set of shader stages.
Definition RendererFoundationDLL.h:136
The stage of a shader. A complete shader can consist of multiple stages.
Definition RendererFoundationDLL.h:105
Definition RendererFoundationDLL.h:258
Definition Descriptors.h:34
Definition RendererFoundationDLL.h:365
Definition Descriptors.h:177
Definition RendererFoundationDLL.h:320
Definition RendererFoundationDLL.h:359
Definition RendererFoundationDLL.h:196
Definition RendererFoundationDLL.h:334
Enum
Definition RendererFoundationDLL.h:336
@ NoOverwrite
User is responsible for synchronizing access between GPU and CPU.
Definition RendererFoundationDLL.h:338
@ CopyToTempStorage
Upload to temp buffer, then buffer to buffer transfer at the current time in the command buffer.
Definition RendererFoundationDLL.h:339
@ Discard
Buffer must be completely overwritten. No old data will be read. Data will not persist across frames.
Definition RendererFoundationDLL.h:337
Definition Descriptors.h:153
Definition Descriptors.h:20
A generic id class that holds an id combined of an instance index and a generation counter.
Definition Id.h:52