aboutsummaryrefslogtreecommitdiff
path: root/sdk/lowlevel/include/NvBlastTypes.h
blob: c53182f6ea6454f706879f7a46a930ab058a8250 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
// This code contains NVIDIA Confidential Information and is disclosed to you
// under a form of NVIDIA software license agreement provided separately to you.
//
// Notice
// NVIDIA Corporation and its licensors retain all intellectual property and
// proprietary rights in and to this software and related documentation and
// any modifications thereto. Any use, reproduction, disclosure, or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA Corporation is strictly prohibited.
//
// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Information and code furnished is believed to be accurate and reliable.
// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.


#ifndef NVBLASTTYPES_H
#define NVBLASTTYPES_H


#include "NvBlastPreprocessor.h"
#include <stdint.h>


///////////////////////////////////////////////////////////////////////////////
//	NvBlast common types
///////////////////////////////////////////////////////////////////////////////
///@{

/**
Types of log messages.
*/
struct NvBlastMessage
{
	enum Type
	{
		Error,		//!< Error messages
		Warning,	//!< Warning messages
		Info,		//!< Information messages
		Debug		//!< Used only in debug version of dll
	};
};


/**
Function pointer type for logging.

When a function with this signature is passed into Blast functions with an NvBlastLog argument,
Blast will use it to report errors, warnings, and other information.
*/
typedef void(*NvBlastLog)(int type, const char* msg, const char* file, int line);


/**
ID used to identify assets.
*/
struct NvBlastID
{
	char data[16];
};


/**
Time spent (in ticks) in various parts of Blast.
These values may be filled in during the execution of various API functions.
To convert to seconds, use NvBlastTicksToSeconds(ticks).

In profile build configurations, if a pointer to an instance of this struct is passed into
Blast functions with an NvBlastTimers argument, then Blast will add to appropriate fields
the time measured in corresponding sections of code.  The user must clear the timer fields
with NvBlastTimersReset to initialize or reset.
*/
struct NvBlastTimers
{
	int64_t  material;		//!< Time spent in material function
	int64_t  fracture;		//!< Time spent applying damage
	int64_t  island;		//!< Time spent discovering islands
	int64_t  partition;		//!< Time spent partitioning the graph
	int64_t  visibility;	//!< Time spent updating visibility
};


/**
Generic data block header for all data blocks.
*/
struct NvBlastDataBlock
{
	/**
	Enum of data block types
	*/
	enum Type
	{
		AssetDataBlock,
		FamilyDataBlock,

		Count
	};


	/**
	A data type keeps value from Type enum
	*/
	uint32_t	dataType;

	/**
	A number which is incremented every time the data layout changes. Depending on dataType corresponding	data 
	format is kept. See NvBlastAssetDataFormat, NvBlastFamilyDataFormat enum.
	*/
	uint32_t	formatVersion;

	/**
	The size of the family, including this header.

	Memory sizes are restricted to 32-bit representable values.
	*/
	uint32_t	size;

	/**
	Reserved to be possibly used in future versions
	*/
	uint32_t	reserved;
};

///@} End NvBlast common types


///////////////////////////////////////////////////////////////////////////////
//	NvBlastAsset related types
///////////////////////////////////////////////////////////////////////////////
///@{

/**
Represents a piece of a destructible asset which may be realized as an entity with a physical and graphical component.

Chunks may form a hierarchical decomposition of the asset.  They contain parent and child chunk index information which
defines the hierarchy.  The parent and child chunk indices are their positions with the NvBlastAsset::chunks array.

Child chunk indices are contiguous, starting at firstChildIndex and ending with childIndexStop - 1.
*/
struct NvBlastChunk
{
	/**
	Central position for the chunk's volume
	*/
	float		centroid[3];

	/**
	Volume of the chunk
	*/
	float		volume;

	/**
	Index of parent (UINT32_MAX denotes no parent)
	*/
	uint32_t	parentChunkIndex;

	/**
	Index of first child
	*/
	uint32_t	firstChildIndex;

	/**
	Stop for child indices
	*/
	uint32_t	childIndexStop;

	/**
	Field for user to associate with external data
	*/
	uint32_t	userData;
};


/**
Represents the interface between two chunks.  At most one bond is created for a chunk pair.
*/
struct NvBlastBond
{
	/**
	Interface average normal
	*/
	float		normal[3];

	/**
	Area of interface
	*/
	float		area;

	/**
	Central position on the interface between chunks
	*/
	float		centroid[3];

	/**
	Extra data associated with bond, e.g. whether or not to create a joint
	*/
	uint32_t	userData;
};


/**
Describes the connectivity between support chunks via bonds.

Vertices in the support graph are termed "nodes," and represent particular chunks (NvBlastChunk) in an NvBlastAsset.
The indexing for nodes is not the same as that for chunks.  Only some chunks are represented by nodes in the graph,
and these chunks are called "support chunks."

Adjacent node indices and adjacent bond indices are stored for each node, and therefore each bond is represented twice in this graph,
going from node[i] -> node[j] and from node[j] -> node[i].  Therefore the size of the adjacentNodeIndices and adjacentBondIndices
arrays are twice the number of bonds stored in the corresponding NvBlastAsset. 

The graph is used as follows.  Given a NvBlastSupportGraph "graph" and node index i, (0 <= i < graph.nodeCount), one may find all
adjacent bonds and nodes using:

	// adj is the lookup value in graph.adjacentNodeIndices and graph.adjacentBondIndices
	for (uint32_t adj = graph.adjacencyPartition[i]; adj < graph.adjacencyPartition[i+1]; ++adj)
	{
		// An adjacent node:
		uint32_t adjacentNodeIndex = graph.adjacentNodeIndices[adj];
	
		// The corresponding bond (that connects node index i with node indexed adjacentNodeIndex:
		uint32_t adjacentBondIndex = graph.adjacentBondIndices[adj];
	}

For a graph node with index i, the corresponding asset chunk index is found using graph.chunkIndices[i].  The reverse mapping
(obtaining a graph node index from an asset chunk index) can be done using the

	NvBlastAssetGetChunkToGraphNodeMap(asset, logFn)

function.  See the documentation for its use.  The returned "node index" for a non-support chunk is the invalid value 0xFFFFFFFF.
*/
struct NvBlastSupportGraph
{
	/**
	Total number of nodes in the support graph.
	*/
	uint32_t	nodeCount;

	/**
	Indices of chunks represented by the nodes, an array of size nodeCount.
	*/
	uint32_t*	chunkIndices;

	/**
	Partitions both the adjacentNodeIndices and the adjacentBondIndices arrays into subsets corresponding to each node.
	The size of this array is nodeCount+1.
	For 0 <= i < nodeCount, adjacencyPartition[i] is the index of the first element in adjacentNodeIndices (or adjacentBondIndices) for nodes adjacent to the node with index i.
	adjacencyPartition[nodeCount] is the size of the adjacentNodeIndices and adjacentBondIndices arrays.
	This allows one to easily count the number of nodes adjacent to a node with index i, using adjacencyPartition[i+1] - adjacencyPartition[i].
	*/
	uint32_t*	adjacencyPartition;

	/**
	Array composed of subarrays holding the indices of nodes adjacent to a given node.  The subarrays may be accessed through the adjacencyPartition array.
	*/
	uint32_t*	adjacentNodeIndices;

	/**
	Array composed of subarrays holding the indices of bonds (NvBlastBond) for a given node.  The subarrays may be accessed through the adjacencyPartition array.
	*/
	uint32_t*	adjacentBondIndices;
};


/**
Asset (opaque)

Static destructible data, used to create actor families.

Pointer to this struct can be created with NvBlastCreateAsset.

The NvBlastAsset includes a ID which may be used to match it with physics and graphics data.
*/
struct NvBlastAsset {};


/**
Chunk descriptor used to build an asset.  See NvBlastAssetDesc.
*/
struct NvBlastChunkDesc
{
	enum Flags
	{
		NoFlags = 0,

		/** If this flag is set then the chunk will become a support chunk, unless an ancestor chunk is also marked as support. */
		SupportFlag = (1 << 0)
	};

	/** Central position in chunk. */
	float		centroid[3];

	/** Volume of chunk. */
	float		volume;

	/** Index of this chunk's parent.  If this is a root chunk, then this value must be UINT32_MAX. */
	uint32_t	parentChunkIndex;

	/** See Flags enum for possible flags. */
	uint32_t	flags;

	/** User-supplied data which will be accessible to the user in chunk fracture events. */
	uint32_t	userData;
};


/**
Chunk bond descriptor used to build an asset.  See NvBlastAssetDesc.
*/
struct NvBlastBondDesc
{
	/** Bond data (see NvBlastBond). */
	NvBlastBond	bond;

	/**
	The indices of the chunks linked by this bond.  They must be different support chunk indices.
	If one of the chunk indices is the invalid index (UINT32_MAX), then this will create a bond between
	the chunk indexed by the other index (which must be valid) and "the world."  Any actor containing
	this bond will cause the function NvBlastActorIsBoundToWorld to return true.
	*/
	uint32_t	chunkIndices[2];
};


/**
Asset descriptor, used to build an asset with NvBlastCreateAsset

A valid asset descriptor must have a non-zero chunkCount and valid chunkDescs.

The user may create an asset with no bonds (e.g. a single-chunk asset).  In this case bondCount should be
zero and bondDescs is ignored.
*/
struct NvBlastAssetDesc
{
	/** The number of chunk descriptors. */
	uint32_t				chunkCount;

	/** Array of chunk descriptors of size chunkCount. */
	const NvBlastChunkDesc*	chunkDescs;

	/** The number of bond descriptors. */
	uint32_t				bondCount;

	/** Array of bond descriptors of size bondCount. */
	const NvBlastBondDesc*	bondDescs;
};

///@} End NvBlastAsset related types


///////////////////////////////////////////////////////////////////////////////
//	NvBlastActor related types
///////////////////////////////////////////////////////////////////////////////
///@{

/**
Family (opaque)

a family can be created by the NvBlastAssetCreateFamily function and released 
by the NvBlastFamilyRelease.  Family is needed to create first actor.  All the following
actors which can be created with NvBlastActorSplit function (as a result of fracture) will share the same family
block.  NvBlastFamilyGetActorCount can be used to know if family can be safely released.
*/
struct NvBlastFamily {};


/**
Actor (opaque)

Actors can be generated by the NvBlastFamilyCreateFirstActor
and NvBlastActorSplit functions.  Opaque NvBlastActor pointers reference data within the family
generated during NvBlastFamilyCreateFirstActor, and represent the actor in all actor-related API
functions.
*/
struct NvBlastActor {};


/**
Actor descriptor, used to create an instance of an NvBlastAsset with NvBlastFamilyCreateFirstActor

See NvBlastFamilyCreateFirstActor.
*/
struct NvBlastActorDesc
{
	/**
	Initial health of all bonds, if initialBondHealths is NULL (see initialBondHealths).
	*/
	float			uniformInitialBondHealth;

	/**
	Initial bond healths.  If not NULL, this array must be of length NvBlastAssetGetChunkCount(asset, logFn).
	If NULL, uniformInitialBondHealth must be set.
	*/
	const float*	initialBondHealths;

	/**
	Initial health of all lower-support chunks, if initialSupportChunkHealths is NULL (see initialSupportChunkHealths).
	*/
	float			uniformInitialLowerSupportChunkHealth;

	/**
	Initial health of all support chunks.  If not NULL, this must be of length
	NvBlastAssetGetSupportChunkCount(asset, logFn).nodeCount. The elements in the initialSupportChunkHealth
	array will correspond to the chunk indices in the NvBlastAssetGetSupportGraph(asset, logFn).chunkIndices
	array.  Every descendent of a support chunk will have its health initialized to its ancestor support
	chunk's health, so this initializes all lower-support chunk healths.
	If NULL, uniformInitialLowerSupportChunkHealth must be set.
	*/
	const float*	initialSupportChunkHealths;
};

///@} End NvBlastActor related types


///////////////////////////////////////////////////////////////////////////////
//	Types used for damage and fracturing
///////////////////////////////////////////////////////////////////////////////
///@{


/**
Fracture Data for Chunks

Data interpretation varies depending on the function used. 
@see NvBlastActorGenerateFracture NvBlastActorApplyFracture NvBlastFractureBuffers
*/
struct NvBlastChunkFractureData
{
	uint32_t	userdata;	//!<	chunk's user data
	uint32_t	chunkIndex;	//!<	asset chunk index
	float		health;		//!<	health value (damage or remains)
};


/**
Fracture Data for Bonds

Data interpretation varies depending on the function used.
@see NvBlastActorGenerateFracture NvBlastActorApplyFracture NvBlastFractureBuffers
*/
struct NvBlastBondFractureData
{
	uint32_t	userdata;	//!<	bond's user data
	uint32_t	nodeIndex0;	//!<	graph node index of bond
	uint32_t	nodeIndex1;	//!<	pair graph node index of bond
	float		health;		//!<	health value (damage or remains)
};


/**
Memory to be used by fracture functions.

Used as input and output target.
@see NvBlastActorGenerateFracture NvBlastActorApplyFracture
*/
struct NvBlastFractureBuffers
{
	uint32_t					bondFractureCount;		//!<	available elements in bondFractures
	uint32_t					chunkFractureCount;		//!<	available elements in chunkFractures
	NvBlastBondFractureData*	bondFractures;			//!<	memory to be filled by fracture functions
	NvBlastChunkFractureData*	chunkFractures;			//!<	memory to be filled by fracture functions
};


/**
Description of a NvBlastActorSplit result.
This tells the user about changes in the actor, or creation of children.
*/
struct NvBlastActorSplitEvent
{
	NvBlastActor*	deletedActor;	//!<	deleted actor or nullptr if actor has not changed
	NvBlastActor**	newActors;		//!<	list of created actors
};


/**
A single actor's representation used by NvBlastGraphShaderFunction.
*/
struct NvBlastGraphShaderActor
{
	uint32_t			actorIndex;				//!<	Actor's index.
	uint32_t			graphNodeCount;			//!<	Actor's graph node count.
	uint32_t			assetNodeCount;			//!<	Asset node count.
	uint32_t			firstGraphNodeIndex;	//!<	Entry index for graphNodeIndexLinks
	const uint32_t*		graphNodeIndexLinks;	//!<	Linked index list of connected nodes.  Traversable with nextIndex = graphNodeIndexLinks[currentIndex], terminates with 0xFFFFFFFF.
	const uint32_t*		chunkIndices;			//!<	Graph's map from node index to support chunk index.
	const uint32_t*		adjacencyPartition;		//!<	See NvBlastSupportGraph::adjacencyPartition.
	const uint32_t*		adjacentNodeIndices;	//!<	See NvBlastSupportGraph::adjacentNodeIndices.
	const uint32_t*		adjacentBondIndices;	//!<	See NvBlastSupportGraph::adjacentBondIndices.
	const NvBlastBond*	assetBonds;				//!<	NvBlastBonds geometry in the NvBlastAsset.
	const NvBlastChunk*	assetChunks;			//!<	NvBlastChunks geometry in the NvBlastAsset.
	const float*		familyBondHealths;		//!<	Actual bond health values for broken bond detection.
	const float*		supportChunkHealths;	//!<	Actual chunk health values for dead chunk detection.
	const uint32_t*		nodeActorIndices;		//!<	Family's map from node index to actor index.
};


/**
A single actor's representation used by NvBlastSubgraphShaderFunction.
*/
struct NvBlastSubgraphShaderActor
{
	uint32_t			chunkIndex;		//!<	Index of chunk represented by this actor.
	const NvBlastChunk*	assetChunks;	//!<	NvBlastChunks geometry in the NvBlastAsset.
};


/**
Damage shader for actors with more then one node in support graph.

From a an input actor data (NvBlastGraphShaderActor) and user custom data (params),
creates a list of NvBlastFractureCommand to be applied to the respective NvBlastActor.

\param[in,out]	commandBuffers			The resulting health damage to apply.
										Typically requires an array of size (number of support chunks) + (number of bonds) of the processed asset
										but may depend on the actual implementation.
\param[in]		actor					The actor representation used for creating commands.
\param[in]		programParams			A set of parameters defined by the damage shader implementer.

Interpretation of NvBlastFractureBuffers:
As input:
Counters denote available entries for FractureData.
Chunk and Bond userdata are not used.
Health values are not used.

As output:
Counters denote valid entires in FractureData arrays.
Chunks and Bond userdata reflect the respective userdata set during asset initialization.
Health values denote how much damage is to be applied.

@see NvBlastFractureBuffers NvBlastGraphShaderActor
*/
typedef void(*NvBlastGraphShaderFunction)(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const void* programParams);


/**
Damage shader for actors with single chunk.

From a an input actor data (NvBlastSubgraphShaderActor) and user custom data (params),
creates a list of NvBlastFractureCommand to be applied to the respective NvBlastActor.

\param[in,out]	commandBuffers			The resulting health damage to apply.
										Typically requires an array of size (number of support chunks) + (number of bonds) of the processed asset
										but may depend on the actual implementation.
\param[in]		actor					The actor representation used for creating commands.
\param[in]		programParams			A set of parameters defined by the damage shader implementer.

Interpretation of NvBlastFractureBuffers:
As input:
Counters denote available entries for FractureData.
Chunk and Bond userdata are not used.
Health values are not used.

As output:
Counters denote valid entires in FractureData arrays.
Chunks and Bond userdata reflect the respective userdata set during asset initialization.
Health values denote how much damage is to be applied.

@see NvBlastFractureBuffers NvBlastSubgraphShaderActor
*/
typedef void(*NvBlastSubgraphShaderFunction)(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const void* programParams);


/**
Damage Program. 

Contains both graph and subgraph shader. When used on actor appropriate shader will be called.
Any shader can be nullptr to be skipped.

@see NvBlastGraphShaderFunction NvBlastSubgraphShaderFunction
*/
struct NvBlastDamageProgram
{
	NvBlastGraphShaderFunction		graphShaderFunction;
	NvBlastSubgraphShaderFunction	subgraphShaderFunction;
};


///@} End of types used for damage and fracturing


#endif // ifndef NVBLASTTYPES_H