Foundation
Loading...
Searching...
No Matches
Common.hpp
Go to the documentation of this file.
1#pragma once
2#include <Core/Container.hpp>
3#include <Core/Enums.hpp>
4#include <Math/Math.hpp>
5#include "Details.hpp"
6namespace Foundation::RHI {
7 using namespace Core;
8 constexpr static size_t kFullSize = -1;
9 using RHIExtent1D = glm::vec<1, uint32_t>;
10 using RHIExtent2D = glm::vec<2, uint32_t>;
11 using RHIExtent3D = glm::vec<3, uint32_t>;
12 using RHIOffset1D = glm::vec<1, int32_t>;
13 using RHIOffset2D = glm::vec<2, int32_t>;
14 using RHIOffset3D = glm::vec<3, int32_t>;
15 // [RGBA]
16 using RHIClearColor = glm::vec<4, float>;
17 // [Depth Clear Value, Stencil Clear Value]
19
22
33
113
114 constexpr bool IsFormatSRGB(RHIResourceFormat format)
115 {
116 switch (format)
117 {
125 return true;
126 default:
127 return false;
128 }
129 }
130
131 enum class RHIColorSpace {
135 };
141
145
146 bool operator==(const RHISurfaceFormat& other) const {
147 return format == other.format && colorSpace == other.colorSpace;
148 }
149 };
150
152 uint32_t location; // Index into shader input
153 uint32_t offset; // In bytes
155 uint32_t binding = 0; // 0-indexed index into bindings
156 };
157
159 // The command pool is persistent, meaning command buffers can be reused
161 // The command pool is meant to be used once
162 Transient,
163 };
164 enum class RHIDeviceType {
165 Other,
167 Discrete,
168 Virtual, // e.x. MoltenVK, SwiftShader
169 Software,// e.x. Lavapipe
170 };
178
179 enum class RHIDeviceQueueType : uint32_t {
180 Undefined = ~0u,
181 Graphics = 0,
182 Compute = 1,
183 Transfer = 2,
184 Present = 3
185 };
193
194 BITMASK_ENUM_BEGIN(RHIDeviceQueueFlags, uint32_t)
195 Graphics = 1u << 0,
196 Compute = 1u << 1,
197 Transfer = 1u << 2,
198 Present = 1u << 3
200
201 enum class RHIDevicePipelineType {
202 Graphics,
203 Compute,
204 RayTracing
205 };
206 ENUM_NAME_CONV_BEGIN(RHIDevicePipelineType)
209 ENUM_NAME(RayTracing)
211
212 enum class RHIDeviceHeapType {
213 Local,
214 Upload,
216 };
217
229
231 {
234 };
235
237 {
238 Build,
239 Update
240 };
241
243 {
244 Triangles,
245 AABBs,
247 };
248
250 Invisible,
251 ReadWrite, // r/w are possible
252 WriteOnly // write only, reads are undefined
253 };
254
263
272
274 E1, E2, E4, E8, E16
275 };
277 E1D, E2D, E3D,
279 };
280
281 BITMASK_ENUM_BEGIN(RHIShaderStage, uint32_t)
282 // Vertex Shader
283 Vertex = 1 << 0,
284 // Fragment Shader (aka Pixel)
285 Fragment = 1 << 1,
286 // Compute Shader
287 Compute = 1 << 2,
288 // Ray Tracing Ray Generation
290 // Ray Tracing Ray Any Hit
291 RayAnyHit = 1 << 4,
292 // Ray Tracing Ray Closest Hit
294 // Ray Tracing Ray Miss
295 RayMiss = 1 << 6,
296 // Ray Tracing Ray Intersection
298 // Mesh Shading (aka Amplification)
299 Task = 1 << 8,
300 // Mesh Shading
301 Mesh = 1 << 9,
302 All = ~0u
304
305 ENUM_NAME_CONV_BEGIN(RHIShaderStageBits)
306 case Vertex: return "Vertex Shader";
307 case Fragment: return "Fragment Shader";
308 case Compute: return "Compute Shader";
309 case RayGeneration: return "RT Ray Generation";
310 case RayAnyHit: return "RT Any Hit";
311 case RayClosestHit: return "RT Closest Hit";
312 case RayMiss: return "RT Miss";
313 case RayIntersection: return "RT Intersection";
314 case Task: return "Task Shader";
315 case Mesh: return "Mesh Shader";
317
318 BITMASK_ENUM_BEGIN(RHIResourceAccess, uint32_t)
324 TransferRead = 1 << 5,
325 ShaderWrite = 1 << 6,
326 ShaderRead = 1 << 7,
327 UniformRead = 1 << 8,
328 HostWrite = 1 << 9,
329 HostRead = 1 << 10,
334
335 // https://gpuopen.com/learn/vulkan-barriers-explained/
336 // https://docs.vulkan.org/spec/latest/chapters/synchronization.html#synchronization-pipeline-barriers
337 BITMASK_ENUM_BEGIN(RHIPipelineStage, uint32_t)
338 DrawIndirect = 1 << 1,
339 VertexShader = 1 << 2,
343 MeshShader = 1 << 6,
344 TaskShader = 1 << 7,
346 Transfer = 1 << 9,
350 // ---
351 Host = 1 << 27,
352 AllGraphics = 1 << 28,
353 TopOfPipe = 1 << 29,
354 BottomOfPipe = 1 << 30,
356
357 BITMASK_ENUM_BEGIN(RHIBufferUsage, uint32_t)
358 VertexBuffer = 1 << 0,
359 IndexBuffer = 1 << 1,
360 // i.e. Uniform Buffer
362 // i.e. Structured Buffer
372
373 BITMASK_ENUM_BEGIN(RHITextureUsage, uint32_t)
374 RenderTarget = 1 << 0,
375 DepthStencil = 1 << 1,
376 SampledImage = 1 << 2,
377 StorageImage = 1 << 3,
378 TransferSource = 1 << 4,
379 TransferDestination = 1 << 5
381
382 BITMASK_ENUM_BEGIN(RHITextureAspectFlag, uint32_t)
383 Color = 1 << 0,
384 Depth = 1 << 1,
385 Stencil = 1 << 2
387
388 BITMASK_ENUM_BEGIN(RHIAccelerationStructureBuildFlags, uint32_t)
389 AllowUpdate = 1 << 0,
393 LowMemory = 1 << 4
395
396 BITMASK_ENUM_BEGIN(RHIAccelerationGeometryInstanceFlags, uint32_t)
397 TriangleCullDisable = 1 << 0,
399}
#define ENUM_NAME_CONV_BEGIN(T)
Defines convince to_string() method and format_as() [fmt] for the respective enum class Example usage...
Definition Enums.hpp:82
#define BITMASK_ENUM_BEGIN(T, INT_T)
Defines a bitmask enum type {T}Bits with underlying integer type INT_T whilst defining a wrapper clas...
Definition Enums.hpp:47
#define ENUM_NAME(E)
Definition Enums.hpp:93
std::pair< First, Second > Pair
Alias for std::pair
Definition Container.hpp:33
Low-level Rendering Hardware Interface (RHI) abstractions.
Definition Application.hpp:3
constexpr bool IsFormatSRGB(RHIResourceFormat format)
Definition Common.hpp:114
DeviceAddress
Definition Common.hpp:367
MeshShader
Definition Common.hpp:343
RayTracingShader
Definition Common.hpp:342
glm::vec< 2, int32_t > RHIOffset2D
Definition Common.hpp:13
RHIAccelerationStructureBuildOp
Definition Common.hpp:237
IndexBuffer
Definition Common.hpp:359
AccelerationStructureBuildReadOnly
Definition Common.hpp:369
FragmentShader
Definition Common.hpp:340
glm::vec< 3, int32_t > RHIOffset3D
Definition Common.hpp:14
PreferFastBuild
Definition Common.hpp:392
RHITextureLayout
Definition Common.hpp:218
Task
Definition Common.hpp:299
Depth
Definition Common.hpp:384
UniformRead
Definition Common.hpp:327
VertexShader
Definition Common.hpp:339
RayGeneration
Definition Common.hpp:289
RHIAttachmentLoadOp
Definition Common.hpp:20
ShaderBindingTable
Definition Common.hpp:370
TopOfPipe
Definition Common.hpp:353
Present
Definition Common.hpp:198
RenderTargetOutput
Definition Common.hpp:345
All
Definition Common.hpp:302
Compute
Definition Common.hpp:196
Host
Definition Common.hpp:351
RenderTargetRead
Definition Common.hpp:320
ComputeShader
Definition Common.hpp:341
AccelerationBuild
Definition Common.hpp:349
RHIDeviceHeapType
Definition Common.hpp:212
RHIAccelerationStructureType
Definition Common.hpp:231
Color
Definition Common.hpp:383
RHIDeviceType
Definition Common.hpp:164
glm::vec< 4, float > RHIClearColor
Definition Common.hpp:16
glm::vec< 3, uint32_t > RHIExtent3D
Definition Common.hpp:11
EarlyFragmentTests
Definition Common.hpp:347
TransferRead
Definition Common.hpp:324
AccelerationStructureWrite
Definition Common.hpp:331
TransferSource
Definition Common.hpp:365
RHIColorSpace
Definition Common.hpp:131
UniformBuffer
Definition Common.hpp:361
AccelerationStructureRead
Definition Common.hpp:330
AccelerationStructureStorage
Definition Common.hpp:368
ShaderRead
Definition Common.hpp:326
RHIDeviceQueueType
Definition Common.hpp:179
RHIAccelerationGeometryType
Definition Common.hpp:243
TaskShader
Definition Common.hpp:344
VertexBuffer
Definition Common.hpp:358
HostRead
Definition Common.hpp:329
StorageBuffer
Definition Common.hpp:363
IndirectCommandRead
Definition Common.hpp:332
DepthStencil
Definition Common.hpp:375
AllowCompaction
Definition Common.hpp:390
Pair< float, uint32_t > RHIClearDepthStencil
Definition Common.hpp:18
Transfer
Definition Common.hpp:197
RHITextureDimension
Definition Common.hpp:276
RayAnyHit
Definition Common.hpp:291
RHIDescriptorType
Definition Common.hpp:255
LateFragmentTests
Definition Common.hpp:348
RayClosestHit
Definition Common.hpp:293
HostWrite
Definition Common.hpp:328
PreferFastTrace
Definition Common.hpp:391
RHIResourceFormat
Definition Common.hpp:34
static constexpr size_t kFullSize
Definition Common.hpp:8
AllowUpdate
Definition Common.hpp:389
BottomOfPipe
Definition Common.hpp:354
RenderTargetWrite
Definition Common.hpp:319
DepthStencilWrite
Definition Common.hpp:321
Mesh
Definition Common.hpp:301
glm::vec< 1, uint32_t > RHIExtent1D
Definition Common.hpp:9
RHICommandPoolType
Definition Common.hpp:158
Stencil
Definition Common.hpp:385
TransferDestination
Definition Common.hpp:366
ShaderWrite
Definition Common.hpp:325
TransferWrite
Definition Common.hpp:323
RayMiss
Definition Common.hpp:295
RHIMultisampleCount
Definition Common.hpp:273
DepthStencilRead
Definition Common.hpp:322
RHIResourceHostAccess
Definition Common.hpp:249
SampledImage
Definition Common.hpp:376
RHIAttachmentStoreOp
Definition Common.hpp:21
Graphics
Definition Common.hpp:195
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
Fragment
Definition Common.hpp:285
DrawIndirect
Definition Common.hpp:338
IndirectBuffer
Definition Common.hpp:364
glm::vec< 1, int32_t > RHIOffset1D
Definition Common.hpp:12
RenderTarget
Definition Common.hpp:374
StorageImage
Definition Common.hpp:377
Vertex
Definition Common.hpp:283
AllGraphics
Definition Common.hpp:352
LowMemory
Definition Common.hpp:393
RayIntersection
Definition Common.hpp:297
RHIClearColor clearColor
Definition Common.hpp:26
RHIAttachmentLoadOp loadOp
Definition Common.hpp:25
RHIAttachmentLoadOp loadOp
Definition Common.hpp:30
RHIClearDepthStencil clearValue
Definition Common.hpp:31
Definition Common.hpp:142
bool operator==(const RHISurfaceFormat &other) const
Definition Common.hpp:146
RHIResourceFormat format
Definition Common.hpp:143
RHIColorSpace colorSpace
Definition Common.hpp:144
Definition Common.hpp:151
uint32_t location
Definition Common.hpp:152
uint32_t offset
Definition Common.hpp:153
RHIResourceFormat format
Definition Common.hpp:154
uint32_t binding
Definition Common.hpp:155