PxDirectGPUAPI
Defined in include/PxDirectGPUAPI.h
-
class PxDirectGPUAPI
PxDirectGPUAPI exposes an API that enables batched direct access to GPU data for a PxScene.
The functions in this class allow batched direct access to GPU data for PxRigidDynamic, PxArticulationReducedCoordinate and PxShape types. This allows interoperation with GPU post- and preprocessing for users and allows the user to implement more efficient CPU-GPU data copies based on the specific needs of the application.
Using this direct-API will disable the existing CPU-based API for all the data exposed in the direct-API. For any API function that does not have a counterpart in this direct-API, the existing API will continue to work.
To use this API, PxSceneFlag::eENABLE_DIRECT_GPU_API needs to be raised, in combination with PxSceneFlag::eENABLE_GPU_DYNAMICS and PxBroadphaseType::eGPU. Note that these options are immutable and cannot be changed after the scene has been created.
Due to the internal architecture of the GPU-accelerated parts of PhysX, using this API comes with caveats:
1) All GPU-CPU copies for data exposed in this API will be disabled. This means that the existing CPU-based API will return outdated data, and any setters for data exposed in the interface will not work. On the other hand, significant speedups can be achieved because of the reduced amount of GPU-CPU memory copies.
2) Due to the internal architecture of the GPU-accelerated PhysX, this API will only work after a first simulation step has been taken. The reason for this is that the PxScene first needs to know all the actors it will have to simulate, and setup the sizes of the GPU-based structures. For setup, the existing CPU API should be used.
Note
Due to the fact that this API is exposing low-level data, we do reserve the right to change this API without deprecation in case of changes in the internal implementations.
Public Functions
-
virtual bool getRigidDynamicData(void *data, const PxRigidDynamicGPUIndex *gpuIndices, PxRigidDynamicGPUAPIReadType::Enum dataType, PxU32 nbElements, CUevent startEvent = NULL, CUevent finishEvent = NULL) const = 0
Copies the simulation state for a set of PxRigidDynamic actors into a user-provided GPU data buffer.
See also
PxRigidDynamic::getGPUIndex(). The size of this buffer needs to be nbElements * sizeof(PxRigidDynamicGPUIndex). The data requested for the PxRigidDynamic with its GPU index at position x in the gpuIndices array will be located at position x in the data array.
See also
PxRigidDynamicGPUAPIReadType.
- Parameters
data – [out] User-provided GPU data buffer which has size nbElements * sizeof(type). For the types, see the dataType options in PxRigidDynamicGPUAPIReadType.
gpuIndices – [in] User-provided GPU index buffer containing elements of PxRigidDynamicGPUIndex. This buffer contains the GPU indices of the PxRigidDynamic objects that are part of this get operation.
dataType – [in] The type of data to get.
nbElements – [in] The number of rigid bodies to be copied.
startEvent – [in] User-provided CUDA event that is awaited at the start of this function. Defaults to NULL which means the function will dispatch the copy immediately.
finishEvent – [in] User-provided CUDA event that is recorded at the end of this function. Defaults to NULL which means the function will wait for the copy to finish before returning.
- Returns
bool Whether the operation was successful. Note that this might not include asynchronous CUDA errors.
-
virtual bool setRigidDynamicData(const void *data, const PxRigidDynamicGPUIndex *gpuIndices, PxRigidDynamicGPUAPIWriteType::Enum dataType, PxU32 nbElements, CUevent startEvent = NULL, CUevent finishEvent = NULL) = 0
Sets the simulation state for a set of PxRigidDynamic actors from a user-provided GPU data buffer.
See also
PxRigidDynamic::getGPUIndex(). The size of this buffer needs to be nbElements * sizeof(PxRigidDynamicGPUIndex). The data for the PxRigidDynamic with its GPU index at position x in the gpuIndices array needs to be located at position x in the data array.
See also
PxRigidDynamicGPUAPIWriteType.
- Parameters
data – [in] User-provided GPU data buffer which has size nbElements * sizeof(type). For the types, see the dataType options in PxRigidDynamicGPUAPIWriteType.
gpuIndices – [in] User-provided GPU index buffer containing elements of PxRigidDynamicGPUIndex. This buffer contains the GPU indices of the PxRigidDynamic objects that are part of this set operation.
dataType – [in] The type of data to set.
nbElements – [in] The number of rigid bodies to be set.
startEvent – [in] User-provided CUDA event that is awaited at the start of this function. Defaults to NULL which means the function will dispatch the copy immediately.
finishEvent – [in] User-provided CUDA event that is recorded at the end of this function. Defaults to NULL which means the function will wait for the copy to finish before returning.
- Returns
bool Whether the operation was successful. Note that this might not include asynchronous CUDA errors.
-
virtual bool getArticulationData(void *data, const PxArticulationGPUIndex *gpuIndices, PxArticulationGPUAPIReadType::Enum dataType, PxU32 nbElements, CUevent startEvent = NULL, CUevent finishEvent = NULL) const = 0
Gets the simulation state for a set of articulations, i.e.
PxArticulationReducedCoordinate objects and copies into a user-provided GPU data buffer.
The data buffer must be sized according to the maximum component counts across all articulations in the PxScene, as summarised in PxArticulationGPUAPIMaxCounts. The data buffer is split into sequential blocks that are of equal size and can hold the data for all components of an articulation. For example, for a link-centric data type (PxArticulationGPUAPIReadType::eLINK_GLOBAL_POSE, for example) each of these blocks has to be maxLinks * sizeof(dataType). The size of the complete buffer would then be nbElements * maxLinks * sizeof(dataType). For a dof-centric data type, the block size would be maxDofs * sizeof(dataType). The specific layout for each dataType is detailed in the API documentation of PxArticulationGPUAPIReadType. The max counts for a scene can be obtained by calling PxDirectGPUAPI::getArticulationGPUAPIMaxCounts().
See also
PxArticulationReducedCoordinate::getGPUIndex(). The size of this buffer needs to be nbElements * sizeof(PxArticulationGPUIndex). The data for the PxArticulationReducedCoordinate with its GPU index at position x in the gpuIndices array will have its data block located at position x in the data array.
See also
PxArticulationGPUAPIReadType.
The link and dof indexing of these blocks then follows the same pattern as the PxArticulationCache API. We refer to the user guide for an explanation.
- Parameters
data – [out] User-provided GPU data buffer that is appropriately sized for the data being requested. The sizing is explained in detail below.
gpuIndices – [in] User-provided GPU index buffer containing elements of PxArticulationGPUIndex. This buffer contains the GPU indices of the PxArticulationReducedCoordinate objects that are part of this get operation.
dataType – [in] The type of data to get.
nbElements – [in] The number of articulations to copy data from.
startEvent – [in] User-provided CUDA event that is awaited at the start of this function. Defaults to NULL which means the function will dispatch the copy immediately.
finishEvent – [in] User-provided CUDA event that is recorded at the end of this function. Defaults to NULL which means the function will wait for the copy to finish before returning.
- Returns
bool Whether the operation was successful. Note that this might not include asynchronous CUDA errors.
-
virtual bool setArticulationData(const void *data, const PxArticulationGPUIndex *gpuIndices, PxArticulationGPUAPIWriteType::Enum dataType, PxU32 nbElements, CUevent startEvent = NULL, CUevent finishEvent = NULL) = 0
Sets the simulation state for a set of articulations, i.e.
PxArticulationReducedCoordinate objects from a user-provided GPU data buffer.
The data buffer must be sized according to the maximum component counts across all articulations in the PxScene, as summarised in PxArticulationGPUAPIMaxCounts. The data buffer is split into sequential blocks that are of equal size and can hold the data for all components of an articulation. For example, for a link-centric data type (PxArticulationGPUAPIWriteType::eLINK_FORCE, for example) each of these blocks has to be maxLinks * sizeof(dataType). The size of the complete buffer would then be nbElements * maxLinks * sizeof(dataType). For a dof-centric data type, the block size would be maxDofs * sizeof(dataType). The specific layout for each dataType is detailed in the API documentation of PxArticulationGPUAPIWriteType. The max counts for a scene can be obtained by calling PxDirectGPUAPI::getArticulationGPUAPIMaxCounts().
See also
PxArticulationReducedCoordinate::getGPUIndex(). The size of this buffer needs to be nbElements * sizeof(PxArticulationGPUIndex). The data for the PxArticulationReducedCoordinate with its GPU index at position x in the gpuIndices array needs to have its data block located at position x in the data array.
See also
PxArticulationGPUAPIWriteType.
The internal indexing of these blocks then follows the same pattern as the PxArticulationCache API. We refer to the user guide for an explanation.
- Parameters
data – [in] User-provided GPU data buffer that is appropriately sized for the data to be set. The sizing is explained in detail below.
gpuIndices – [in] User-provided GPU index buffer containing elements of PxArticulationGPUIndex. This buffer contains the GPU indices of the PxArticulationReducedCoordinate objects that are part of this set operation.
dataType – [in] The type of data to set.
nbElements – [in] The number of articulations to set data for.
startEvent – [in] User-provided CUDA event that is awaited at the start of this function. Defaults to NULL which means the function will dispatch the copy immediately.
finishEvent – [in] User-provided CUDA event that is recorded at the end of this function. Defaults to NULL which means the function will wait for the copy to finish before returning.
- Returns
bool Whether the operation was successful. Note that this might not include asynchronous CUDA errors.
-
virtual bool computeArticulationData(void *data, const PxArticulationGPUIndex *gpuIndices, PxArticulationGPUAPIComputeType::Enum operation, PxU32 nbElements, CUevent startEvent = NULL, CUevent finishEvent = NULL) = 0
performs a compute operation on a set of articulations, i.e.
PxArticulationReducedCoordinate objects.
The appropriate sizing of the data buffer as well as the data layout is documented alongside the compute operations in the API documentation of PxArticulationGPUAPIComputeType.
See also
PxArticulationReducedCoordinate::getGPUIndex(). The size of this buffer needs to be nbElements * sizeof(PxArticulationGPUIndex).
- Parameters
data – [inout] User-provided GPU data buffer that is appropriately sized for the operation to be performed. Depending on the operation, can be input or output data.
gpuIndices – [in] User-provided GPU index buffer containing elements of PxArticulationGPUIndex. This buffer contains the GPU indices of the PxArticulationReducedCoordinate objects that are part of this compute operation.
operation – [in] The operation to perform. See PxArticulationGPUAPIComputeType::Enum.
nbElements – [in] The number of articulations to perform this compute operation on.
startEvent – [in] User-provided CUDA event that is awaited at the start of this function. Defaults to NULL which means the function will dispatch the computation immediately.
finishEvent – [in] User-provided CUDA event that is recorded at the end of this function. Defaults to NULL which means the function will wait for the computation to finish before returning.
- Returns
bool Whether the operation was successful. Note that this might not include asynchronous CUDA errors.
-
virtual bool copyContactData(void *data, PxU32 *nbContactPairs, PxU32 maxPairs, CUevent startEvent = NULL, CUevent finishEvent = NULL) const = 0
Copy rigid body (PxRigidBody) and articulation (PxArticulationReducedCoordinate) contact data to a user-provided GPU data buffer.
Note
This function only reports contact data for actor pairs where both actors are either rigid bodies or articulations.
Note
The contact data contains pointers to internal state and is only valid until the next call to simulate().
- Parameters
data – [out] User-provided GPU data buffer, which should be the size of PxGpuContactPair * maxPairs
nbContactPairs – [out] User-provided GPU data buffer of 1 * sizeof(PxU32) that contains the actual number of pairs that was written.
maxPairs – [in] The maximum number of pairs that the buffer can contain.
startEvent – [in] User-provided CUDA event that is awaited at the start of this function. Defaults to NULL which means the function will dispatch the copy immediately.
finishEvent – [in] User-provided CUDA event that is recorded at the end of this function. Defaults to NULL which means the function will wait for the copy to finish before returning.
- Returns
bool Whether the operation was successful. Note that this might not include asynchronous CUDA errors.
-
virtual bool evaluateSDFDistances(PxVec4 *localGradientAndSDFConcatenated, const PxShapeGPUIndex *shapeIndices, const PxVec4 *localSamplePointsConcatenated, const PxU32 *samplePointCountPerShape, PxU32 nbElements, PxU32 maxPointCount, CUevent startEvent = NULL, CUevent finishEvent = NULL) const = 0
Evaluate sample point distances on SDF shapes.
See also
PxShape::getGPUIndex(). The size of this buffer needs to be nbElements * sizeof(PxShapeGPUIndex). The shapes must be triangle mesh shapes with SDFs.
- Parameters
localGradientAndSDFConcatenated – [out] User-provided GPU buffer where the evaluated distances and gradients in SDF local space get stored. It has the same structure as localSamplePointsConcatenated.
shapeIndices – [in] User-provided GPU index buffer containing elements of PxShapeGPUIndex. This buffer contains the GPU indices of the PxShape objects that are part of this operation.
localSamplePointsConcatenated – [in] User-provided GPU buffer containing the sample point locations for every shape in the shapes’ local space. The buffer stride is maxPointCount.
samplePointCountPerShape – [in] User-provided GPU buffer containing the number of sample points for every shape.
nbElements – [in] The number of shapes to be queried.
maxPointCount – [in] The maximum value in the array samplePointCountPerShape
startEvent – [in] User-provided CUDA event that is awaited at the start of this function. Defaults to NULL which means the function will dispatch the computation immediately.
finishEvent – [in] User-provided CUDA event that is recorded at the end of this function. Defaults to NULL which means the function will wait for the computation to finish before returning.
- Returns
bool Whether the operation was successful. Note that this might not include asynchronous CUDA errors.
-
virtual PxArticulationGPUAPIMaxCounts getArticulationGPUAPIMaxCounts() const = 0
Get the maximal articulation index and component counts for a PxScene.
Get the maximal articulation index and component counts for a PxScene. This is a helper function to ease the derivation of the correct data layout for the articulation functions in PxDirectGPUAPI. Specifically, this function will return maxLinks, maxDofs, maxFixedTendons, maxFixedTendonJoints, maxSpatialTendons and maxSpatialTendonAttachments for a scene.
See also
PxArticulationGPUAPIMaxCounts.
See also
PxDirectGPUAPI::getArticulationData, PxDirectGPUAPI::setArticulationData, PxDirectGPUAPI::computeArticulationData
- Returns
PxArticulationGPUAPIMaxCounts the max counts across the scene for all articulation indices and components.
-
virtual bool getRigidDynamicData(void *data, const PxRigidDynamicGPUIndex *gpuIndices, PxRigidDynamicGPUAPIReadType::Enum dataType, PxU32 nbElements, CUevent startEvent = NULL, CUevent finishEvent = NULL) const = 0