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
220 // render pass subpass attachment indices
221 /** Depth attachment index */
222 uint32_t depthAttachmentIndex { ~0u };
223 /** Depth resolve attachment index */
224 uint32_t depthResolveAttachmentIndex { ~0u };
225 /** Input attachment indices */
226 BASE_NS::vector<uint32_t> inputAttachmentIndices;
227 /** Color attachment indices */
228 BASE_NS::vector<uint32_t> colorAttachmentIndices;
229 /** Resolve attachment indices */
230 BASE_NS::vector<uint32_t> resolveAttachmentIndices;
231 /** Fragment shading rate attachment index */
232 uint32_t fragmentShadingRateAttachmentIndex { ~0u };
233
234 /** Depth resolve mode flag bit */
235 ResolveModeFlagBits depthResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
236 /** Stencil resolve mode flag bit */
237 ResolveModeFlagBits stencilResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
238
239 /** Shading rate attachment texel size for subpass */
240 Size2D shadingRateTexelSize { 1u, 1u };
241 /** Multi-view bitfield of view indices. Multi-view is ignored while zero. */
242 uint32_t viewMask { 0u };
243 };
244
245 /** Input resources */
246 struct InputResources {
247 /** Buffers */
248 BASE_NS::vector<RenderNodeResource> buffers;
249 /** Images */
250 BASE_NS::vector<RenderNodeResource> images;
251 /** Samplers */
252 BASE_NS::vector<RenderNodeResource> samplers;
253
254 /** Custom input buffers */
255 BASE_NS::vector<RenderNodeResource> customInputBuffers;
256 /** Custom output buffers */
257 BASE_NS::vector<RenderNodeResource> customOutputBuffers;
258
259 /** Custom input images */
260 BASE_NS::vector<RenderNodeResource> customInputImages;
261 /** Custom output images */
262 BASE_NS::vector<RenderNodeResource> customOutputImages;
263 };
264 };
265
266 /** Register all the inputs, outputs, resources etc. for RenderNode to use.
267 */
268 struct RenderNodeGraphInputs {
269 /** Resource */
270 struct Resource {
271 /** Set */
272 uint32_t set { ~0u };
273 /** Binding */
274 uint32_t binding { ~0u };
275 /** Name, optionally with FROM_NAMED_RENDER_NODE_OUTPUT the registered name */
276 RenderDataConstants::RenderDataFixedString name;
277 /** Usage name, optional usage name for some render nodes
278 * e.g. "depth", this should be handled as depth image
279 */
280 RenderDataConstants::RenderDataFixedString usageName;
281
282 /** From where is the input routed. Default uses named GPU resource from GPU resource manager. */
283 RenderNodeGraphResourceLocationType resourceLocation { RenderNodeGraphResourceLocationType::DEFAULT };
284 /** Index of the routed input. */
285 uint32_t resourceIndex { ~0u };
286 /** Node name, with FROM_NAMED_RENDER_NODE_OUTPUT */
287 RenderDataConstants::RenderDataFixedString nodeName;
288
289 /** Additional binding information */
290
291 /** Mip level for image binding */
292 uint32_t mip { PipelineStateConstants::GPU_IMAGE_ALL_MIP_LEVELS };
293 /** Layer for image binding */
294 uint32_t layer { PipelineStateConstants::GPU_IMAGE_ALL_LAYERS };
295 };
296
297 /** Attachment */
298 struct Attachment {
299 /** Load operation */
300 AttachmentLoadOp loadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
301 /** Store operation */
302 AttachmentStoreOp storeOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
303
304 /** Stencil load operation */
305 AttachmentLoadOp stencilLoadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
306 /** Stencil store operation */
307 AttachmentStoreOp stencilStoreOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
308
309 /** Clear value */
310 ClearValue clearValue {};
311
312 /** Name, optionally with FROM_NAMED_RENDER_NODE_OUTPUT the registered name */
313 RenderDataConstants::RenderDataFixedString name;
314 /** From where is the input routed. Default uses named GPU resource from GPU resource manager. */
315 RenderNodeGraphResourceLocationType resourceLocation { RenderNodeGraphResourceLocationType::DEFAULT };
316 /** Index of the routed input. */
317 uint32_t resourceIndex { ~0u };
318 /** Node name, with FROM_NAMED_RENDER_NODE_OUTPUT */
319 RenderDataConstants::RenderDataFixedString nodeName;
320
321 /** Mip level */
322 uint32_t mip { 0u };
323 /** Layer */
324 uint32_t layer { 0u };
325 };
326
327 /** Shader input */
328 struct ShaderInput {
329 /** Name */
330 RenderDataConstants::RenderDataFixedString name;
331 };
332
333 /** Input render pass */
334 struct InputRenderPass {
335 /** Render pass attachments */
336 BASE_NS::vector<Attachment> attachments;
337
338 /** Subpass index, if subpass index is not zero, this subpass is patched to previous render pass */
339 uint32_t subpassIndex { 0u };
340 /** Subpass count, calculated automatically when loading render node graph */
341 uint32_t subpassCount { 1u };
342
343 /** Render pass subpass contents */
344 SubpassContents subpassContents { SubpassContents::CORE_SUBPASS_CONTENTS_INLINE };
345
346 /** Depth attachment index */
347 uint32_t depthAttachmentIndex { ~0u };
348 /** Depth resolve attachment index */
349 uint32_t depthResolveAttachmentIndex { ~0u };
350 /** Input attachment indices */
351 BASE_NS::vector<uint32_t> inputAttachmentIndices;
352 /** Color attachment indices */
353 BASE_NS::vector<uint32_t> colorAttachmentIndices;
354 /** Resolve attachment indices */
355 BASE_NS::vector<uint32_t> resolveAttachmentIndices;
356 /** Fragment shading rate attachment index */
357 uint32_t fragmentShadingRateAttachmentIndex { ~0u };
358
359 /** Depth resolve mode flag bit */
360 ResolveModeFlagBits depthResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
361 /** Stencil resolve mode flag bit */
362 ResolveModeFlagBits stencilResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
363
364 /** Shading rate attachment texel size for subpass
365 */
366 Size2D shadingRateTexelSize { 1u, 1u };
367 /** Multi-view bitfield of view indices. Multi-view is ignored while zero. */
368 uint32_t viewMask { 0u };
369 };
370
371 /** Input resources (Descriptor sets etc.) */
372 struct InputResources {
373 // descriptors
374 /** Buffers */
375 BASE_NS::vector<Resource> buffers;
376 /** Images */
377 BASE_NS::vector<Resource> images;
378 /** Samplers */
379 BASE_NS::vector<Resource> samplers;
380
381 /** Custom input buffers */
382 BASE_NS::vector<Resource> customInputBuffers;
383 /** Custom output buffers */
384 BASE_NS::vector<Resource> customOutputBuffers;
385
386 /** Custom input images */
387 BASE_NS::vector<Resource> customInputImages;
388 /** Custom output images */
389 BASE_NS::vector<Resource> customOutputImages;
390 };
391
392 /** Render node graph GPU buffer descriptor */
393 struct RenderNodeGraphGpuBufferDesc {
394 /** Name */
395 RenderDataConstants::RenderDataFixedString name;
396 /** Dependency buffer name */
397 RenderDataConstants::RenderDataFixedString dependencyBufferName;
398 /** Render node graph share name */
399 RenderDataConstants::RenderDataFixedString shareName;
400 /** Buffer descriptor (Contains: usage flags, memory property flags, engine buffer creation flags and byte size)
401 */
402 GpuBufferDesc desc;
403 };
404
405 /** Render node graph GPU image descriptor */
406 struct RenderNodeGraphGpuImageDesc {
407 /** Name */
408 RenderDataConstants::RenderDataFixedString name;
409 /** Dependency image name */
410 RenderDataConstants::RenderDataFixedString dependencyImageName;
411 /** Render node graph share name */
412 RenderDataConstants::RenderDataFixedString shareName;
413 /** Dependency flag bits */
414 enum DependencyFlagBits : uint32_t {
415 /** Format */
416 FORMAT = 1,
417 /** Size */
418 SIZE = 2,
419 /** Mip count */
420 MIP_COUNT = 4,
421 /** Layer count */
422 LAYER_COUNT = 8,
423 /** Samples */
424 SAMPLES = 16,
425 /** Max enumeration */
426 MAX_DEPENDENCY_FLAG_ENUM = 0x7FFFFFFF
427 };
428 /** Container for dependency flag bits */
429 using DependencyFlags = uint32_t;
430 /** Dependency flags */
431 DependencyFlags dependencyFlags { 0 };
432 /** Dependency size scale (scales only the size if size is a dependency) */
433 float dependencySizeScale { 1.0f };
434 /** Fragment shading rate requested texel size
435 * Will check the valid values and divides the size
436 */
437 Size2D shadingRateTexelSize { 1u, 1u };
438 /** Image descriptor (GpuImageDesc) */
439 GpuImageDesc desc;
440 };
441
442 /** Resource creation description */
443 struct ResourceCreationDescription {
444 /** GPU buffer descriptors */
445 BASE_NS::vector<RenderNodeGraphGpuBufferDesc> gpuBufferDescs;
446 /** GPU image descriptors */
447 BASE_NS::vector<RenderNodeGraphGpuImageDesc> gpuImageDescs;
448 };
449
450 /** CPU dependencies */
451 struct CpuDependencies {
452 /** Render node type based dependancy. Finds previous render node of type */
453 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> typeNames;
454 /** Render node name based dependancy. Finds previous render node of name */
455 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> nodeNames;
456 };
457
458 /** GPU queue wait signal dependencies */
459 struct GpuQueueWaitForSignals {
460 /** Render node type based dependancy. Finds previous render node of type */
461 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> typeNames;
462 /** Render node name based dependancy. Finds previous render node of name */
463 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> nodeNames;
464 };
465
466 /** Render data store */
467 struct RenderDataStore {
468 /** Data store name */
469 RenderDataConstants::RenderDataFixedString dataStoreName;
470 /** Type name */
471 RenderDataConstants::RenderDataFixedString typeName;
472 /** Configuration name */
473 RenderDataConstants::RenderDataFixedString configurationName;
474 };
475
476 /** Queue */
477 GpuQueue queue;
478 /** CPU dependency */
479 CpuDependencies cpuDependencies;
480 /** GPU queue wait for signals */
481 GpuQueueWaitForSignals gpuQueueWaitForSignals;
482 /** Base render data store hook */
483 RenderDataConstants::RenderDataFixedString nodeDataStoreName;
484 };
485
486 /** Rendering configuration */
487 struct RenderingConfiguration {
488 /** Render backend */
489 DeviceBackendType renderBackend { DeviceBackendType::VULKAN };
490 /** NDC origin enumeration */
491 enum class NdcOrigin {
492 /** Undefined */
493 UNDEFINED = 0,
494 /** "Topleft (Vulkan, Default)" */
495 TOP_LEFT = 1,
496 /** "Bottomleft (OpenGL, OpenGL ES)" */
497 BOTTOM_LEFT = 2
498 };
499 /** NDC origin */
500 NdcOrigin ndcOrigin { NdcOrigin::TOP_LEFT };
501 /** Render timings
502 *(.x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint)) */
503 BASE_NS::Math::Vec4 renderTimings { 0.0f, 0.0f, 0.0f, 0.0f };
504 };
505
506 /** Render node graph data */
507 struct RenderNodeGraphData {
508 /** Render node graph name */
509 RenderDataConstants::RenderDataFixedString renderNodeGraphName;
510 /** Name of the first (access point) data store */
511 RenderDataConstants::RenderDataFixedString renderNodeGraphDataStoreName;
512 /** Rendering configuration */
513 RenderingConfiguration renderingConfiguration;
514 };
515 /** @} */
516 RENDER_END_NAMESPACE()
517
518 #endif // API_RENDER_RENDER_DATA_STRUCTURES_H
519