1 /*
2 * Copyright (C) 2023 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 /** Handle to gpu buffer.
55 Byte offset to buffer.
56 Index buffer type.
57 */
58 struct IndexBuffer {
59 /** Buffer handle */
60 RenderHandle bufferHandle;
61 /** Buffer offset */
62 uint32_t bufferOffset { 0 };
63 /** Byte size */
64 uint32_t byteSize { PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE };
65 /** Index type */
66 IndexType indexType { IndexType::CORE_INDEX_TYPE_MAX_ENUM };
67 };
68
69 /** Helper struct for descriptor types and their counts.
70 */
71 struct DescriptorCounts {
72 /** Typed count */
73 struct TypedCount {
74 /** Type */
75 DescriptorType type { CORE_DESCRIPTOR_TYPE_MAX_ENUM };
76 /** Count */
77 uint32_t count { 0u };
78 };
79
80 /** Counts list */
81 BASE_NS::vector<TypedCount> counts;
82 };
83
84 /** Acceleration AABB */
85 struct AabbPositions {
86 /** Min x */
87 float minX { 0.0f };
88 /** Min y */
89 float minY { 0.0f };
90 /** Min z */
91 float minZ { 0.0f };
92 /** Max x */
93 float maxX { 0.0f };
94 /** Max y */
95 float maxY { 0.0f };
96 /** Max z */
97 float maxZ { 0.0f };
98 };
99
100 /** Render slot sort type */
101 enum class RenderSlotSortType : uint32_t {
102 /** Node */
103 NONE = 0,
104 /** Front to back */
105 FRONT_TO_BACK = 1,
106 /** Back to front */
107 BACK_TO_FRONT = 2,
108 /** By material */
109 BY_MATERIAL = 3,
110 };
111
112 /** Render slot cull type */
113 enum class RenderSlotCullType : uint32_t {
114 /** None */
115 NONE = 0,
116 /** View frustum cull */
117 VIEW_FRUSTUM_CULL = 1,
118 };
119
120 /** Render node graph resource type */
121 enum class RenderNodeGraphResourceLocationType : uint32_t {
122 /** Default, fetch with name */
123 DEFAULT = 0,
124 /** Get with input index from render node graph share */
125 FROM_RENDER_GRAPH_INPUT = 1,
126 /** Get with output index from render node graph share */
127 FROM_RENDER_GRAPH_OUTPUT = 2,
128 /** Get output index from previous render node */
129 FROM_PREVIOUS_RENDER_NODE_OUTPUT = 3,
130 /** Get output index from named render node */
131 FROM_NAMED_RENDER_NODE_OUTPUT = 4,
132 };
133
134 /** Set for default command buffer recording.
135 Requested queue type and index.
136 */
137 struct ContextInitDescription {
138 /** Requested queue */
139 GpuQueue requestedQueue;
140 };
141
142 /** Render node resource */
143 struct RenderNodeResource {
144 /** Set of this resource */
145 uint32_t set { ~0u };
146 /** Binding */
147 uint32_t binding { ~0u };
148 /** Handle */
149 RenderHandle handle {};
150 /** Second handle (e.g. sampler for combined image sampler) */
151 RenderHandle secondHandle {};
152 };
153
154 /** Render node attachment */
155 struct RenderNodeAttachment {
156 /** Handle */
157 RenderHandle handle;
158
159 /** Load operation */
160 AttachmentLoadOp loadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
161 /** Store operation */
162 AttachmentStoreOp storeOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
163
164 /** Stencil load operation */
165 AttachmentLoadOp stencilLoadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
166 /** Stencil store operation */
167 AttachmentStoreOp stencilStoreOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
168
169 /** Clear value */
170 ClearValue clearValue;
171 };
172
173 /** RenderNodeHandles.
174 Helper struct for inputs that can be defined in pipeline initilization phase.
175 */
176 struct RenderNodeHandles {
177 /** Input render pass */
178 struct InputRenderPass {
179 /** Attachments array */
180 BASE_NS::vector<RenderNodeAttachment> attachments;
181
182 /** Subpass index, if subpass index is other that zero, render pass is patched to previous render passes */
183 uint32_t subpassIndex { 0u };
184
185 /** Subpass count, automatically calculated from render node graph setup */
186 uint32_t subpassCount { 1u };
187
188 // render pass subpass attachment indices
189 /** Depth attachment index */
190 uint32_t depthAttachmentIndex { ~0u };
191 /** Depth resolve attachment index */
192 uint32_t depthResolveAttachmentIndex { ~0u };
193 /** Input attachment indices */
194 BASE_NS::vector<uint32_t> inputAttachmentIndices;
195 /** Color attachment indices */
196 BASE_NS::vector<uint32_t> colorAttachmentIndices;
197 /** Resolve attachment indices */
198 BASE_NS::vector<uint32_t> resolveAttachmentIndices;
199
200 /** Depth resolve mode flag bit */
201 ResolveModeFlagBits depthResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
202 /** Stencil resolve mode flag bit */
203 ResolveModeFlagBits stencilResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
204 };
205
206 /** Input resources */
207 struct InputResources {
208 /** Buffers */
209 BASE_NS::vector<RenderNodeResource> buffers;
210 /** Images */
211 BASE_NS::vector<RenderNodeResource> images;
212 /** Samplers */
213 BASE_NS::vector<RenderNodeResource> samplers;
214
215 /** Custom input buffers */
216 BASE_NS::vector<RenderNodeResource> customInputBuffers;
217 /** Custom output buffers */
218 BASE_NS::vector<RenderNodeResource> customOutputBuffers;
219
220 /** Custom input images */
221 BASE_NS::vector<RenderNodeResource> customInputImages;
222 /** Custom output images */
223 BASE_NS::vector<RenderNodeResource> customOutputImages;
224 };
225 };
226
227 /** Register all the inputs, outputs, resources etc. for RenderNode to use.
228 */
229 struct RenderNodeGraphInputs {
230 /** Resource */
231 struct Resource {
232 /** Set */
233 uint32_t set { ~0u };
234 /** Binding */
235 uint32_t binding { ~0u };
236 /** Name, optionally with FROM_NAMED_RENDER_NODE_OUTPUT the registered name */
237 RenderDataConstants::RenderDataFixedString name;
238 /** Usage name, optional usage name for some render nodes
239 * e.g. "depth", this should be handled as depth image
240 */
241 RenderDataConstants::RenderDataFixedString usageName;
242
243 /** From where is the input routed. Default uses named GPU resource from GPU resource manager. */
244 RenderNodeGraphResourceLocationType resourceLocation { RenderNodeGraphResourceLocationType::DEFAULT };
245 /** Index of the routed input. */
246 uint32_t resourceIndex { ~0u };
247 /** Node name, with FROM_NAMED_RENDER_NODE_OUTPUT */
248 RenderDataConstants::RenderDataFixedString nodeName;
249 };
250
251 /** Attachment */
252 struct Attachment {
253 /** Load operation */
254 AttachmentLoadOp loadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
255 /** Store operation */
256 AttachmentStoreOp storeOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
257
258 /** Stencil load operation */
259 AttachmentLoadOp stencilLoadOp { AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_DONT_CARE };
260 /** Stencil store operation */
261 AttachmentStoreOp stencilStoreOp { AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_DONT_CARE };
262
263 /** Clear value */
264 ClearValue clearValue {};
265
266 /** Name, optionally with FROM_NAMED_RENDER_NODE_OUTPUT the registered name */
267 RenderDataConstants::RenderDataFixedString name;
268 /** From where is the input routed. Default uses named GPU resource from GPU resource manager. */
269 RenderNodeGraphResourceLocationType resourceLocation { RenderNodeGraphResourceLocationType::DEFAULT };
270 /** Index of the routed input. */
271 uint32_t resourceIndex { ~0u };
272 /** Node name, with FROM_NAMED_RENDER_NODE_OUTPUT */
273 RenderDataConstants::RenderDataFixedString nodeName;
274 };
275
276 /** Shader input */
277 struct ShaderInput {
278 /** Name */
279 RenderDataConstants::RenderDataFixedString name;
280 };
281
282 /** Input render pass */
283 struct InputRenderPass {
284 /** Render pass attachments */
285 BASE_NS::vector<Attachment> attachments;
286
287 /** Subpass index, if subpass index is not zero, this subpass is patched to previous render pass */
288 uint32_t subpassIndex { 0u };
289
290 /** Subpass count, calculated automatically when loading render node graph */
291 uint32_t subpassCount { 1u };
292
293 // render pass subpass attachment indices
294 /** Depth attachment index */
295 uint32_t depthAttachmentIndex { ~0u };
296 /** Depth resolve attachment index */
297 uint32_t depthResolveAttachmentIndex { ~0u };
298 /** Input attachment indices */
299 BASE_NS::vector<uint32_t> inputAttachmentIndices;
300 /** Color attachment indices */
301 BASE_NS::vector<uint32_t> colorAttachmentIndices;
302 /** Resolve attachment indices */
303 BASE_NS::vector<uint32_t> resolveAttachmentIndices;
304
305 /** Depth resolve mode flag bit */
306 ResolveModeFlagBits depthResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
307 /** Stencil resolve mode flag bit */
308 ResolveModeFlagBits stencilResolveModeFlagBit { ResolveModeFlagBits::CORE_RESOLVE_MODE_NONE };
309 };
310
311 /** Input resources (Descriptor sets etc.) */
312 struct InputResources {
313 // descriptors
314 /** Buffers */
315 BASE_NS::vector<Resource> buffers;
316 /** Images */
317 BASE_NS::vector<Resource> images;
318 /** Samplers */
319 BASE_NS::vector<Resource> samplers;
320
321 /** Custom input buffers */
322 BASE_NS::vector<Resource> customInputBuffers;
323 /** Custom output buffers */
324 BASE_NS::vector<Resource> customOutputBuffers;
325
326 /** Custom input images */
327 BASE_NS::vector<Resource> customInputImages;
328 /** Custom output images */
329 BASE_NS::vector<Resource> customOutputImages;
330 };
331
332 /** Render node graph GPU buffer descriptor */
333 struct RenderNodeGraphGpuBufferDesc {
334 /** Name */
335 RenderDataConstants::RenderDataFixedString name;
336 /** Dependency buffer name */
337 RenderDataConstants::RenderDataFixedString dependencyBufferName;
338 /** Render node graph share name */
339 RenderDataConstants::RenderDataFixedString shareName;
340 /** Buffer descriptor (Contains: usage flags, memory property flags, engine buffer creation flags and byte size)
341 */
342 GpuBufferDesc desc;
343 };
344
345 /** Render node graph GPU image descriptor */
346 struct RenderNodeGraphGpuImageDesc {
347 /** Name */
348 RenderDataConstants::RenderDataFixedString name;
349 /** Dependency image name */
350 RenderDataConstants::RenderDataFixedString dependencyImageName;
351 /** Render node graph share name */
352 RenderDataConstants::RenderDataFixedString shareName;
353 /** Dependency flag bits */
354 enum DependencyFlagBits : uint32_t {
355 /** Format */
356 FORMAT = 1,
357 /** Size */
358 SIZE = 2,
359 /** Mip count */
360 MIP_COUNT = 4,
361 /** Layer count */
362 LAYER_COUNT = 8,
363 /** Samples */
364 SAMPLES = 16,
365 /** Max enumeration */
366 MAX_DEPENDENCY_FLAG_ENUM = 0x7FFFFFFF
367 };
368 /** Container for dependency flag bits */
369 using DependencyFlags = uint32_t;
370 /** Dependency flags */
371 DependencyFlags dependencyFlags { 0 };
372 /** Dependency size scale (scales only the size if size is a dependency) */
373 float dependencySizeScale { 1.0f };
374 /** Image descriptor (GpuImageDesc) */
375 GpuImageDesc desc;
376 };
377
378 /** Resource creation description */
379 struct ResourceCreationDescription {
380 /** GPU buffer descriptors */
381 BASE_NS::vector<RenderNodeGraphGpuBufferDesc> gpuBufferDescs;
382 /** GPU image descriptors */
383 BASE_NS::vector<RenderNodeGraphGpuImageDesc> gpuImageDescs;
384 };
385
386 /** CPU dependencies */
387 struct CpuDependencies {
388 /** Render node type based dependancy. Finds previous render node of type */
389 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> typeNames;
390 /** Render node name based dependancy. Finds previous render node of name */
391 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> nodeNames;
392 };
393
394 /** GPU queue wait signal dependencies */
395 struct GpuQueueWaitForSignals {
396 /** Render node type based dependancy. Finds previous render node of type */
397 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> typeNames;
398 /** Render node name based dependancy. Finds previous render node of name */
399 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> nodeNames;
400 };
401
402 /** Render data store */
403 struct RenderDataStore {
404 /** Data store name */
405 RenderDataConstants::RenderDataFixedString dataStoreName;
406 /** Type name */
407 RenderDataConstants::RenderDataFixedString typeName;
408 /** Configuration name */
409 RenderDataConstants::RenderDataFixedString configurationName;
410 };
411
412 /** Queue */
413 GpuQueue queue;
414 /** CPU dependency */
415 CpuDependencies cpuDependencies;
416 /** GPU queue wait for signals */
417 GpuQueueWaitForSignals gpuQueueWaitForSignals;
418 /** Base render data store hook */
419 RenderDataConstants::RenderDataFixedString nodeDataStoreName;
420 };
421
422 /** Rendering configuration */
423 struct RenderingConfiguration {
424 /** Render backend */
425 DeviceBackendType renderBackend { DeviceBackendType::VULKAN };
426 /** NDC origin enumeration */
427 enum class NdcOrigin {
428 /** Undefined */
429 UNDEFINED = 0,
430 /** "Topleft (Vulkan, Default)" */
431 TOP_LEFT = 1,
432 /** "Bottomleft (OpenGL, OpenGL ES)" */
433 BOTTOM_LEFT = 2
434 };
435 /** NDC origin */
436 NdcOrigin ndcOrigin { NdcOrigin::TOP_LEFT };
437 /** Render timings
438 *(.x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint)) */
439 BASE_NS::Math::Vec4 renderTimings { 0.0f, 0.0f, 0.0f, 0.0f };
440 };
441
442 /** Render node graph data */
443 struct RenderNodeGraphData {
444 /** Render node graph name */
445 RenderDataConstants::RenderDataFixedString renderNodeGraphName;
446 /** Name of the first (access point) data store */
447 RenderDataConstants::RenderDataFixedString renderNodeGraphDataStoreName;
448 /** Rendering configuration */
449 RenderingConfiguration renderingConfiguration;
450 };
451 /** @} */
452 RENDER_END_NAMESPACE()
453
454 #endif // API_RENDER_RENDER_DATA_STRUCTURES_H
455