Berserk
RHIDefs.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of Berserk Engine project */
3 /* https://github.com/EgorOrachyov/Berserk */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2018 - 2021 Egor Orachyov */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef BERSERK_RHIDEFS_HPP
29 #define BERSERK_RHIDEFS_HPP
30 
31 #include <core/Config.hpp>
32 #include <core/Typedefs.hpp>
33 
34 #include <core/string/String.hpp>
35 
37 
43 enum class RHIType : uint8 {
44  OpenGL,
45  Vulkan,
46  Unknown
47 };
48 
50 enum class RHIBufferUsage : uint8 {
52  Static,
54  Dynamic
55 };
56 
57 enum class RHIIndexType : uint8 {
58  Uint32,
59  Uint16,
60  Unknown
61 };
62 
64 enum class RHIVertexFrequency : uint8 {
66  PerVertex = 0,
69 };
70 
72  Float1 = 0,
73  Float2,
74  Float3,
75  Float4,
76  Int1,
77  Int2,
78  Int3,
79  Int4,
80  Unknown
81 };
82 
83 enum class RHIShaderDataType : uint8 {
84  Float1,
85  Float2,
86  Float3,
87  Float4,
88  Int1,
89  Int2,
90  Int3,
91  Int4,
92  Uint1,
93  Uint2,
94  Uint3,
95  Uint4,
96  Bool1,
97  Bool2,
98  Bool3,
99  Bool4,
100  Mat2,
101  Mat3,
102  Mat4,
103  Unknown
104 };
105 
106 enum class RHIShaderParamType : uint8 {
107  Sampler2d,
109  Sampler3d,
110  SamplerCube,
111  Unknown
112 };
113 
114 enum class RHITextureType : uint8 {
115  Texture2d,
117  Texture3d,
118  TextureCube,
119  Unknown
120 };
121 
122 enum class RHIShaderType : uint8 {
123  Vertex = 0,
124  Fragment = 1
125 };
126 
127 enum class RHIShaderLanguage : uint8 {
128  GLSL410GL = 1,
129  GLSL450GL = 2,
130  GLSL450VK = 3,
131  Unknown
132 };
133 
135 enum class RHITextureFormat : uint8 {
136  R8,
137  R8_SNORM,
138  R16,
139  R16_SNORM,
140  RG8,
141  RG8_SNORM,
142  RG16,
143  RG16_SNORM,
144  RGB8,
145  RGB8_SNORM,
146  RGB16_SNORM,
147  RGBA8,
148  RGBA8_SNORM,
149  RGBA16,
150  SRGB8,
151  SRGB8_ALPHA8,
152  R16F,
153  RG16F,
154  RGB16F,
155  RGBA16F,
156  R32F,
157  RG32F,
158  RGB32F,
159  RGBA32F,
160  DEPTH32F,
163  Unknown
164 };
165 
166 enum class RHITextureUsage : uint8 {
168  Sampling = 1,
170  ColorAttachment = 2,
172  DepthAttachment = 3,
175 };
176 
178  PositiveX = 0,
179  NegativeX = 1,
180  PositiveY = 2,
181  NegativeY = 3,
182  PositiveZ = 4,
183  NegativeZ = 5,
184 };
185 
187  Nearest,
188  Linear
189 };
190 
193  Nearest,
195  Linear,
204 };
205 
207  Repeat,
209  ClampToEdge,
212 };
213 
215  Black,
216  White
217 };
218 
220 enum class RHIPrimitivesType : uint8 {
221  Triangles,
222  Lines,
223  Points
224 };
225 
227 enum class RHIPolygonMode : uint8 {
228  Fill,
229  Line,
230  Point
231 };
232 
233 enum class RHIPolygonCullMode : uint8 {
234  Disabled,
235  Front,
236  Back,
238 };
239 
242  Clockwise,
244 };
245 
246 enum class RHICompareFunction : uint8 {
247  Never,
248  Less,
249  Equal,
250  LessEqual,
251  Greater,
252  GreaterEqual,
253  NotEqual,
254  Always
255 };
256 
257 enum class RHIOperation : uint8 {
258  Keep,
259  Zero,
260  Replace,
261  Increment,
262  Decrement,
263  Invert
264 };
265 
266 enum class RHIBlendFactor : uint8 {
268  Zero,
270  One,
272  SrcColor,
276  DstColor,
280  SrcAlpha,
284  DstAlpha,
287 };
288 
289 enum class RHIBlendOperation : uint8 {
291  Add,
293  Subtract,
297  Min,
299  Max
300 };
301 
303  ClearStore,
304  ClearDiscard,
305  LoadStore,
306  LoadDiscard,
307  DiscardStore,
309 };
310 
312 struct RHILimits {
314  static const uint32 MAX_VERTEX_ATTRIBUTES = 8;
315 
317  static const uint32 MAX_VERTEX_BUFFERS = 8;
318 
320  static const uint32 MAX_COLOR_ATTACHMENTS = 8;
321 
323  static const uint32 MAX_SHADER_PARAM_NAME = 1024;
324 
326  static const uint32 MAX_SHADER_PARAMS_COUNT = 1024;
327 
329  static const uint32 MAX_TEXTURE_MIPMAPS = 16;
330 
332  static const uint32 MAX_SHADER_STAGES = 2;
333 
335  static const uint32 MAX_TEXTURE_CUBE_FACES = 6;
336 
338  static const uint32 MAX_FRAMES_IN_FLIGHT = 2;
339 
341  static const uint32 MAX_RESOURCE_SETS = 3;
342 };
343 
358 };
359 
362  const uint32 fBase = 4;
363  const uint32 iBase = 4;
364  const uint32 uBase = 4;
365  const uint32 bBase = 4;
366 
367  switch (type) {
369  return fBase * 1;
371  return fBase * 2;
373  return fBase * 3;
375  return fBase * 4;
377  return iBase * 1;
379  return iBase * 2;
381  return iBase * 3;
383  return iBase * 4;
385  return uBase * 1;
387  return uBase * 2;
389  return uBase * 3;
391  return uBase * 4;
393  return bBase * 1;
395  return bBase * 2;
397  return bBase * 3;
399  return bBase * 4;
401  return fBase * 2 * 2;
403  return fBase * 3 * 3;
405  return fBase * 4 * 4;
406  default:
407  return 0;
408  }
409 }
410 
411 inline const char *RHIGetShaderDataIdGLSL(RHIShaderDataType type) {
412  switch (type) {
414  return "float";
416  return "vec2";
418  return "vec3";
420  return "vec4";
422  return "int";
424  return "ivec2";
426  return "ivec3";
428  return "ivec4";
430  return "uint";
432  return "uvec2";
434  return "uvec3";
436  return "uvec4";
438  return "bool";
440  return "bvec2";
442  return "bvec3";
444  return "bvec4";
446  return "mat2";
448  return "mat3";
450  return "mat4";
451  default:
452  return "__none__";
453  }
454 }
455 
456 inline const char *RHIGetShaderParamIdGLSL(RHIShaderParamType type) {
457  switch (type) {
459  return "sampler2D";
461  return "sampler2DArray";
463  return "sampler3D";
465  return "samplerCube";
466  default:
467  return "__none__";
468  }
469 }
470 
472  switch (type) {
485  return true;
486  default:
487  return false;
488  }
489 }
490 
492  switch (type) {
500  return true;
501  default:
502  return false;
503  }
504 }
505 
507  switch (type) {
512  return true;
513  default:
514  return false;
515  }
516 }
517 
519  switch (type) {
536  return true;
537  default:
538  return false;
539  }
540 }
541 
543  switch (type) {
548  return 1;
553  return 2;
558  return 3;
563  return 4;
564  default:
565  return 0;
566  }
567 }
568 
570  switch (type) {
575  return 1;
580  return 2;
585  return 3;
590  return 4;
592  return 2 * 2;
594  return 3 * 3;
596  return 4 * 4;
597  default:
598  return 0;
599  }
600 }
601 
602 inline void RHIGetMatrixSize(RHIShaderDataType type, uint32 &rows, uint32 &cols) {
603  switch (type) {
605  rows = cols = 2u;
606  return;
608  rows = cols = 3u;
609  return;
611  rows = cols = 4u;
612  return;
613  default:
614  return;
615  }
616 }
617 
618 inline RHIShaderLanguage RHIParseShaderLanguage(const char *language) {
619  static String g_GLSL410GL("GLSL410GL");
620  static String g_GLSL450GL("GLSL450GL");
621  static String g_GLSL450VK("GLSL450VK");
622 
623  if (g_GLSL410GL == language)
625  else if (g_GLSL450GL == language)
627  else if (g_GLSL450VK == language)
629  else
631 }
632 
634  switch (type) {
636  return sizeof(uint32);
638  return sizeof(uint16);
639  default:
640  return 0;
641  }
642 }
643 
649 
650 #endif//BERSERK_RHIDEFS_HPP
#define BRK_NS_END
Definition: Config.hpp:48
std::uint8_t uint8
Definition: Typedefs.hpp:38
std::uint32_t uint32
Definition: Typedefs.hpp:44
std::uint16_t uint16
Definition: Typedefs.hpp:41
Utf-8 encoded std based default string class.
bool RHIIsVectorType(RHIShaderDataType type)
Definition: RHIDefs.hpp:518
RHITextureCubemapFace
Definition: RHIDefs.hpp:177
RHIShaderParamType
Definition: RHIDefs.hpp:106
RHIShaderDataType
Definition: RHIDefs.hpp:83
RHITextureFormat
Definition: RHIDefs.hpp:135
uint32 GetRHIShaderDataTypeSize(RHIShaderDataType type)
Definition: RHIDefs.hpp:361
RHIVertexFrequency
Definition: RHIDefs.hpp:64
RHIShaderLanguage RHIParseShaderLanguage(const char *language)
Definition: RHIDefs.hpp:618
RHIIndexType
Definition: RHIDefs.hpp:57
RHIBufferUsage
Definition: RHIDefs.hpp:50
RHIPolygonFrontFace
Definition: RHIDefs.hpp:241
bool RHIIsIntegralBaseSignedType(RHIShaderDataType type)
Definition: RHIDefs.hpp:506
RHIBlendOperation
Definition: RHIDefs.hpp:289
RHIRenderTargetOption
Definition: RHIDefs.hpp:302
const char * RHIGetShaderParamIdGLSL(RHIShaderParamType type)
Definition: RHIDefs.hpp:456
bool RHIIsFloatBaseType(RHIShaderDataType type)
Definition: RHIDefs.hpp:491
RHIType
Definition: RHIDefs.hpp:43
RHIShaderType
Definition: RHIDefs.hpp:122
RHITextureType
Definition: RHIDefs.hpp:114
RHIOperation
Definition: RHIDefs.hpp:257
RHIPolygonMode
Definition: RHIDefs.hpp:227
RHISamplerBorderColor
Definition: RHIDefs.hpp:214
RHICompareFunction
Definition: RHIDefs.hpp:246
RHIVertexElementType
Definition: RHIDefs.hpp:71
uint32 RHIGetBaseElementsCount(RHIShaderDataType type)
Definition: RHIDefs.hpp:569
uint32 RHIGetIndexSize(RHIIndexType type)
Definition: RHIDefs.hpp:633
RHIPolygonCullMode
Definition: RHIDefs.hpp:233
RHISamplerMagFilter
Definition: RHIDefs.hpp:186
void RHIGetMatrixSize(RHIShaderDataType type, uint32 &rows, uint32 &cols)
Definition: RHIDefs.hpp:602
RHITextureUsage
Definition: RHIDefs.hpp:166
RHISamplerMinFilter
Definition: RHIDefs.hpp:191
RHISamplerRepeatMode
Definition: RHIDefs.hpp:206
RHIBlendFactor
Definition: RHIDefs.hpp:266
uint32 RHIGetVectorComponentsCount(RHIShaderDataType type)
Definition: RHIDefs.hpp:542
bool RHIIsIntegralBaseType(RHIShaderDataType type)
Definition: RHIDefs.hpp:471
RHIPrimitivesType
Definition: RHIDefs.hpp:220
const char * RHIGetShaderDataIdGLSL(RHIShaderDataType type)
Definition: RHIDefs.hpp:411
RHIShaderLanguage
Definition: RHIDefs.hpp:127
Definition: GLDevice.cpp:46
RHI device capabilities.
Definition: RHIDefs.hpp:345
float maxAnisotropy
Definition: RHIDefs.hpp:356
uint32 maxTextureArrayLayers
Definition: RHIDefs.hpp:348
uint32 maxTextureUnits
Definition: RHIDefs.hpp:351
uint32 maxColorAttachments
Definition: RHIDefs.hpp:352
uint32 maxVertexAttributes
Definition: RHIDefs.hpp:346
uint32 uniformBlockOffsetAlignment
Definition: RHIDefs.hpp:355
bool supportAnisotropy
Definition: RHIDefs.hpp:357
uint32 maxFramebufferHeight
Definition: RHIDefs.hpp:354
uint32 maxTexture3dSize
Definition: RHIDefs.hpp:349
uint32 maxFramebufferWidth
Definition: RHIDefs.hpp:353
uint32 maxCombinedUniformBlocks
Definition: RHIDefs.hpp:347
uint32 maxTextureSize
Definition: RHIDefs.hpp:350
RHI common device limits.
Definition: RHIDefs.hpp:312
static const uint32 MAX_TEXTURE_MIPMAPS
Definition: RHIDefs.hpp:329
static const uint32 MAX_VERTEX_ATTRIBUTES
Definition: RHIDefs.hpp:314
static const uint32 MAX_FRAMES_IN_FLIGHT
Definition: RHIDefs.hpp:338
static const uint32 MAX_SHADER_PARAM_NAME
Definition: RHIDefs.hpp:323
static const uint32 MAX_VERTEX_BUFFERS
Definition: RHIDefs.hpp:317
static const uint32 MAX_TEXTURE_CUBE_FACES
Definition: RHIDefs.hpp:335
static const uint32 MAX_RESOURCE_SETS
Definition: RHIDefs.hpp:341
static const uint32 MAX_SHADER_STAGES
Definition: RHIDefs.hpp:332
static const uint32 MAX_SHADER_PARAMS_COUNT
Definition: RHIDefs.hpp:326
static const uint32 MAX_COLOR_ATTACHMENTS
Definition: RHIDefs.hpp:320