1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef API_RENDER_RENDER_DATA_STRUCTURES_H
17 #define API_RENDER_RENDER_DATA_STRUCTURES_H
18
19 #include <cstdint>
20
21 #include <base/containers/fixed_string.h>
22 #include <base/containers/vector.h>
23 #include <base/math/vector.h>
24 #include <base/util/formats.h>
25 #include <render/device/gpu_resource_desc.h>
26 #include <render/device/intf_device.h>
27 #include <render/device/pipeline_state_desc.h>
28 #include <render/namespace.h>
29 #include <render/resource_handle.h>
30
RENDER_BEGIN_NAMESPACE()31 RENDER_BEGIN_NAMESPACE()
32 /** \addtogroup group_render_renderdatastructures
33 * @{
34 */
35 /** Render data constants */
36 namespace RenderDataConstants {
37 static constexpr uint32_t MAX_DEFAULT_NAME_LENGTH { 128 };
38 using RenderDataFixedString = BASE_NS::fixed_string<RenderDataConstants::MAX_DEFAULT_NAME_LENGTH>;
39 } // namespace RenderDataConstants
40
41 /** Handle to gpu buffer.
42 Byte offset to buffer.
43 Byte size for vertex buffer.
44 */
45 struct VertexBuffer {
46 /** Buffer handle */
47 RenderHandle bufferHandle;
48 /** Buffer offset */
49 uint32_t bufferOffset { 0 };
50 /** Byte size */
51 uint32_t byteSize { PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE };
52 };
53
54 /** Index buffer */
55 struct IndexBuffer {
56 /** Buffer handle */
57 RenderHandle bufferHandle;
58 /** Buffer offset */
59 uint32_t bufferOffset { 0 };
60 /** Byte size */
61 uint32_t byteSize { PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE };
62 /** Index type */
63 IndexType indexType { IndexType::CORE_INDEX_TYPE_UINT32 };
64 };
65
66 /** Vertex buffer with render handle reference */
67 struct VertexBufferWithHandleReference {
68 /** Buffer handle */
69 RenderHandleReference bufferHandle;
70 /** Buffer offset */
71 uint32_t bufferOffset { 0 };
72 /** Byte size */
73 uint32_t byteSize { PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE };
74 };
75
76 /** Index buffer with render handle reference */
77 struct IndexBufferWithHandleReference {
78 /** Buffer handle */
79 RenderHandleReference bufferHandle;
80 /** Buffer offset */
81 uint32_t bufferOffset { 0 };
82 /** Byte size */
83 uint32_t byteSize { PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE };
84 /** Index type */
85 IndexType indexType { IndexType::CORE_INDEX_TYPE_UINT32 };
86 };
87
88 /** Helper struct for descriptor types and their counts.
89 */
90 struct DescriptorCounts {
91 /** Typed count */
92 struct TypedCount {
93 /** Type */
94 DescriptorType type { DescriptorType::CORE_DESCRIPTOR_TYPE_MAX_ENUM };
95 /** Count */
96 uint32_t count { 0u };
97 };
98
99 /** Counts list */
100 BASE_NS::vector<TypedCount> counts;
101 };
102
103 /** Acceleration AABB */
104 struct AabbPositions {
105 /** Min x */
106 float minX { 0.0f };
107 /** Min y */
108 float minY { 0.0f };
109 /** Min z */
110 float minZ { 0.0f };
111 /** Max x */
112 float maxX { 0.0f };
113 /** Max y */
114 float maxY { 0.0f };
115 /** Max z */
116 float maxZ { 0.0f };
117 };
118
119 /** Render slot sort type */
120 enum class RenderSlotSortType : uint32_t {
121 /** Node */
122 NONE = 0,
123 /** Front to back */
124 FRONT_TO_BACK = 1,
125 /** Back to front */
126 BACK_TO_FRONT = 2,
127 /** By material */
128 BY_MATERIAL = 3,
129 };
130
131 /** Render slot cull type */
132 enum class RenderSlotCullType : uint32_t {
133 /** None */
134 NONE = 0,
135 /** View frustum cull */
136 VIEW_FRUSTUM_CULL = 1,
137 };
138
139 /** Render node graph resource type */
140 enum class RenderNodeGraphResourceLocationType : uint32_t {
141 /** Default, fetch with name */
142 DEFAULT = 0,
143 /** Get with input index from render node graph share */
144 FROM_RENDER_GRAPH_INPUT = 1,
145 /** Get with output index from render node graph share */
146 FROM_RENDER_GRAPH_OUTPUT = 2,
147 /** Get output index from previous render node */
148 FROM_PREVIOUS_RENDER_NODE_OUTPUT = 3,
149 /** Get output index from named render node */
150 FROM_NAMED_RENDER_NODE_OUTPUT = 4,
151 /** Get output from the previous render node graph */
152 FROM_PREVIOUS_RENDER_NODE_GRAPH_OUTPUT = 5,
153 };
154
155 /** Set for default command buffer recording.
156 Requested queue type and index.
157 */
158 struct ContextInitDescription {
159 /** Requested queue */
160 GpuQueue requestedQueue;
161 };
162
163 /** Render node resource */
164 struct RenderNodeResource {
165 /** Set of this resource */
166 uint32_t set { ~0u };
167 /** Binding */
168 uint32_t binding { ~0u };
169 /** Handle */
170 RenderHandle handle {};
171 /** Second handle (e.g. sampler for combined image sampler) */
172 RenderHandle secondHandle {};
173 /** Mip level for image binding */
174 uint32_t mip { PipelineStateConstants::GPU_IMAGE_ALL_MIP_LEVELS };
175 /** Layer for image binding */
176 uint32_t layer { PipelineStateConstants::GPU_IMAGE_ALL_LAYERS };
177 };
178
179 /** Render node attachment */
180 struct RenderNodeAttachment {
181 /** Handle */
182 RenderHandle handle;
183
184 /** Load operation */
185 AttachmentLoadOp loadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
186 /** Store operation */
187 AttachmentStoreOp storeOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
188
189 /** Stencil load operation */
190 AttachmentLoadOp stencilLoadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
191 /** Stencil store operation */
192 AttachmentStoreOp stencilStoreOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
193
194 /** Clear value */
195 ClearValue clearValue;
196
197 /** Mip level */
198 uint32_t mip { 0u };
199 /** Layer */
200 uint32_t layer { 0u };
201 };
202
203 /** RenderNodeHandles.
204 Helper struct for inputs that can be defined in pipeline initilization phase.
205 */
206 struct RenderNodeHandles {
207 /** Input render pass */
208 struct InputRenderPass {
209 /** Attachments array */
210 BASE_NS::vector<RenderNodeAttachment> attachments;
211
212 /** Subpass index, if subpass index is other that zero, render pass is patched to previous render passes */
213 uint32_t subpassIndex { 0u };
214 /** Subpass count, automatically calculated from render node graph setup */
215 uint32_t subpassCount { 1u };
216
217 /** Render pass subpass contents */
218 SubpassContents subpassContents { SubpassContents::CORE_SUBPASS_CONTENTS_INLINE };
219 /** Render pass subpass flags. */
220 SubpassFlags subpassFlags { 0u };
221
222 // render pass subpass attachment indices
223 /** Depth attachment index */
224 uint32_t depthAttachmentIndex { ~0u };
225 /** Depth resolve attachment index */
226 uint32_t depthResolveAttachmentIndex { ~0u };
227 /** Input attachment indices */
228 BASE_NS::vector<uint32_t> inputAttachmentIndices;
229 /** Color attachment indices */
230 BASE_NS::vector<uint32_t> colorAttachmentIndices;
231 /** Resolve attachment indices */
232 BASE_NS::vector<uint32_t> resolveAttachmentIndices;
233 /** Fragment shading rate attachment index */
234 uint32_t fragmentShadingRateAttachmentIndex { ~0u };
235
236 /** Depth resolve mode flags */
237 ResolveModeFlags depthResolveModeFlags { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
238 /** Stencil resolve mode flags */
239 ResolveModeFlags stencilResolveModeFlags { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
240
241 /** Shading rate attachment texel size for subpass */
242 Size2D shadingRateTexelSize { 1u, 1u };
243 /** Multi-view bitfield of view indices. Multi-view is ignored while zero. */
244 uint32_t viewMask { 0u };
245 };
246
247 /** Input resources */
248 struct InputResources {
249 /** Buffers */
250 BASE_NS::vector<RenderNodeResource> buffers;
251 /** Images */
252 BASE_NS::vector<RenderNodeResource> images;
253 /** Samplers */
254 BASE_NS::vector<RenderNodeResource> samplers;
255
256 /** Custom input buffers */
257 BASE_NS::vector<RenderNodeResource> customInputBuffers;
258 /** Custom output buffers */
259 BASE_NS::vector<RenderNodeResource> customOutputBuffers;
260
261 /** Custom input images */
262 BASE_NS::vector<RenderNodeResource> customInputImages;
263 /** Custom output images */
264 BASE_NS::vector<RenderNodeResource> customOutputImages;
265 };
266 };
267
268 /** Register all the inputs, outputs, resources etc. for RenderNode to use.
269 */
270 struct RenderNodeGraphInputs {
271 /** Resource */
272 struct Resource {
273 /** Set */
274 uint32_t set { ~0u };
275 /** Binding */
276 uint32_t binding { ~0u };
277 /** Name, optionally with FROM_NAMED_RENDER_NODE_OUTPUT the registered name */
278 RenderDataConstants::RenderDataFixedString name;
279 /** Usage name, optional usage name for some render nodes
280 * e.g. "depth", this should be handled as depth image
281 */
282 RenderDataConstants::RenderDataFixedString usageName;
283
284 /** From where is the input routed. Default uses named GPU resource from GPU resource manager. */
285 RenderNodeGraphResourceLocationType resourceLocation { RenderNodeGraphResourceLocationType::DEFAULT };
286 /** Index of the routed input. */
287 uint32_t resourceIndex { ~0u };
288 /** Node name, with FROM_NAMED_RENDER_NODE_OUTPUT */
289 RenderDataConstants::RenderDataFixedString nodeName;
290
291 /** Additional binding information */
292
293 /** Mip level for image binding */
294 uint32_t mip { PipelineStateConstants::GPU_IMAGE_ALL_MIP_LEVELS };
295 /** Layer for image binding */
296 uint32_t layer { PipelineStateConstants::GPU_IMAGE_ALL_LAYERS };
297 };
298
299 /** Attachment */
300 struct Attachment {
301 /** Load operation */
302 AttachmentLoadOp loadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
303 /** Store operation */
304 AttachmentStoreOp storeOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
305
306 /** Stencil load operation */
307 AttachmentLoadOp stencilLoadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
308 /** Stencil store operation */
309 AttachmentStoreOp stencilStoreOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
310
311 /** Clear value */
312 ClearValue clearValue {};
313
314 /** Name, optionally with FROM_NAMED_RENDER_NODE_OUTPUT the registered name */
315 RenderDataConstants::RenderDataFixedString name;
316 /** From where is the input routed. Default uses named GPU resource from GPU resource manager. */
317 RenderNodeGraphResourceLocationType resourceLocation { RenderNodeGraphResourceLocationType::DEFAULT };
318 /** Index of the routed input. */
319 uint32_t resourceIndex { ~0u };
320 /** Node name, with FROM_NAMED_RENDER_NODE_OUTPUT */
321 RenderDataConstants::RenderDataFixedString nodeName;
322
323 /** Mip level */
324 uint32_t mip { 0u };
325 /** Layer */
326 uint32_t layer { 0u };
327 };
328
329 /** Shader input */
330 struct ShaderInput {
331 /** Name */
332 RenderDataConstants::RenderDataFixedString name;
333 };
334
335 /** Input render pass */
336 struct InputRenderPass {
337 /** Render pass attachments */
338 BASE_NS::vector<Attachment> attachments;
339
340 /** Subpass index, if subpass index is not zero, this subpass is patched to previous render pass */
341 uint32_t subpassIndex { 0u };
342 /** Subpass count, calculated automatically when loading render node graph */
343 uint32_t subpassCount { 1u };
344
345 /** Render pass subpass contents */
346 SubpassContents subpassContents { SubpassContents::CORE_SUBPASS_CONTENTS_INLINE };
347 /** Render pass subpass flags */
348 SubpassFlags subpassFlags { 0u };
349
350 /** Depth attachment index */
351 uint32_t depthAttachmentIndex { ~0u };
352 /** Depth resolve attachment index */
353 uint32_t depthResolveAttachmentIndex { ~0u };
354 /** Input attachment indices */
355 BASE_NS::vector<uint32_t> inputAttachmentIndices;
356 /** Color attachment indices */
357 BASE_NS::vector<uint32_t> colorAttachmentIndices;
358 /** Resolve attachment indices */
359 BASE_NS::vector<uint32_t> resolveAttachmentIndices;
360 /** Fragment shading rate attachment index */
361 uint32_t fragmentShadingRateAttachmentIndex { ~0u };
362
363 /** Depth resolve mode flag bit */
364 ResolveModeFlags depthResolveModeFlags { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
365 /** Stencil resolve mode flag bit */
366 ResolveModeFlags stencilResolveModeFlags { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
367
368 /** Shading rate attachment texel size for subpass
369 */
370 Size2D shadingRateTexelSize { 1u, 1u };
371 /** Multi-view bitfield of view indices. Multi-view is ignored while zero. */
372 uint32_t viewMask { 0u };
373 };
374
375 /** Input resources (Descriptor sets etc.) */
376 struct InputResources {
377 // descriptors
378 /** Buffers */
379 BASE_NS::vector<Resource> buffers;
380 /** Images */
381 BASE_NS::vector<Resource> images;
382 /** Samplers */
383 BASE_NS::vector<Resource> samplers;
384
385 /** Custom input buffers */
386 BASE_NS::vector<Resource> customInputBuffers;
387 /** Custom output buffers */
388 BASE_NS::vector<Resource> customOutputBuffers;
389
390 /** Custom input images */
391 BASE_NS::vector<Resource> customInputImages;
392 /** Custom output images */
393 BASE_NS::vector<Resource> customOutputImages;
394 };
395
396 /** Render node graph GPU buffer descriptor */
397 struct RenderNodeGraphGpuBufferDesc {
398 /** Name */
399 RenderDataConstants::RenderDataFixedString name;
400 /** Dependency buffer name */
401 RenderDataConstants::RenderDataFixedString dependencyBufferName;
402 /** Render node graph share name */
403 RenderDataConstants::RenderDataFixedString shareName;
404 /** Buffer descriptor (Contains: usage flags, memory property flags, engine buffer creation flags and byte size)
405 */
406 GpuBufferDesc desc;
407 };
408
409 /** Render node graph GPU image descriptor */
410 struct RenderNodeGraphGpuImageDesc {
411 /** Name */
412 RenderDataConstants::RenderDataFixedString name;
413 /** Dependency image name */
414 RenderDataConstants::RenderDataFixedString dependencyImageName;
415 /** Render node graph share name */
416 RenderDataConstants::RenderDataFixedString shareName;
417 /** Dependency flag bits */
418 enum DependencyFlagBits : uint32_t {
419 /** Format */
420 FORMAT = 1,
421 /** Size */
422 SIZE = 2,
423 /** Mip count */
424 MIP_COUNT = 4,
425 /** Layer count */
426 LAYER_COUNT = 8,
427 /** Samples */
428 SAMPLES = 16,
429 /** Max enumeration */
430 MAX_DEPENDENCY_FLAG_ENUM = 0x7FFFFFFF
431 };
432 /** Container for dependency flag bits */
433 using DependencyFlags = uint32_t;
434 /** Dependency flags */
435 DependencyFlags dependencyFlags { 0 };
436 /** Dependency size scale (scales only the size if size is a dependency) */
437 float dependencySizeScale { 1.0f };
438 /** Fragment shading rate requested texel size
439 * Will check the valid values and divides the size
440 */
441 Size2D shadingRateTexelSize { 1u, 1u };
442 /** Image descriptor (GpuImageDesc) */
443 GpuImageDesc desc;
444 };
445
446 /** Resource creation description */
447 struct ResourceCreationDescription {
448 /** GPU buffer descriptors */
449 BASE_NS::vector<RenderNodeGraphGpuBufferDesc> gpuBufferDescs;
450 /** GPU image descriptors */
451 BASE_NS::vector<RenderNodeGraphGpuImageDesc> gpuImageDescs;
452 };
453
454 /** CPU dependencies */
455 struct CpuDependencies {
456 /** Render node type based dependancy. Finds previous render node of type */
457 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> typeNames;
458 /** Render node name based dependancy. Finds previous render node of name */
459 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> nodeNames;
460 };
461
462 /** GPU queue wait signal dependencies */
463 struct GpuQueueWaitForSignals {
464 /** Render node type based dependancy. Finds previous render node of type */
465 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> typeNames;
466 /** Render node name based dependancy. Finds previous render node of name */
467 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> nodeNames;
468 };
469
470 /** Render data store */
471 struct RenderDataStore {
472 /** Data store name */
473 RenderDataConstants::RenderDataFixedString dataStoreName;
474 /** Type name */
475 RenderDataConstants::RenderDataFixedString typeName;
476 /** Configuration name */
477 RenderDataConstants::RenderDataFixedString configurationName;
478 };
479
480 /** Queue */
481 GpuQueue queue;
482 /** CPU dependency */
483 CpuDependencies cpuDependencies;
484 /** GPU queue wait for signals */
485 GpuQueueWaitForSignals gpuQueueWaitForSignals;
486 /** Base render data store hook */
487 RenderDataConstants::RenderDataFixedString nodeDataStoreName;
488 };
489
490 /** Rendering configuration */
491 struct RenderingConfiguration {
492 /** Render backend */
493 DeviceBackendType renderBackend { DeviceBackendType::VULKAN };
494 /** NDC origin enumeration */
495 enum class NdcOrigin {
496 /** Undefined */
497 UNDEFINED = 0,
498 /** "Topleft (Vulkan, Default)" */
499 TOP_LEFT = 1,
500 /** "Bottomleft (OpenGL, OpenGL ES)" */
501 BOTTOM_LEFT = 2
502 };
503 /** NDC origin */
504 NdcOrigin ndcOrigin { NdcOrigin::TOP_LEFT };
505 /** Render timings
506 *(.x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint)) */
507 BASE_NS::Math::Vec4 renderTimings { 0.0f, 0.0f, 0.0f, 0.0f };
508 };
509
510 /** Render node graph data */
511 struct RenderNodeGraphData {
512 /** Render node graph name */
513 RenderDataConstants::RenderDataFixedString renderNodeGraphName;
514 /** Name of the first (access point) data store */
515 RenderDataConstants::RenderDataFixedString renderNodeGraphDataStoreName;
516 /** Rendering configuration */
517 RenderingConfiguration renderingConfiguration;
518 };
519 /** @} */
520 RENDER_END_NAMESPACE()
521
522 #endif // API_RENDER_RENDER_DATA_STRUCTURES_H
523