| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | #ifndef PX_GPU_TASK_H |
| 13 | #define PX_GPU_TASK_H |
| 14 | |
| 15 | #include "pxtask/PxTask.h" |
| 16 | #include "pxtask/PxGpuDispatcher.h" |
| 17 | |
| 18 | #ifndef PX_DOXYGEN |
| 19 | namespace physx |
| 20 | { |
| 21 | #endif |
| 22 | |
| 23 | PX_PUSH_PACK_DEFAULT |
| 24 | |
| 25 | /** \brief Define the 'flavor' of a PxGpuTask |
| 26 | * |
| 27 | * Each PxGpuTask should have a specific function; either copying data to the |
| 28 | * device, running kernels on that data, or copying data from the device. |
| 29 | * |
| 30 | * For optimal performance, the dispatcher should run all available HtoD tasks |
| 31 | * before running all Kernel tasks, and all Kernel tasks before running any DtoH |
| 32 | * tasks. This provides maximal kernel overlap and the least number of CUDA |
| 33 | * flushes. |
| 34 | */ |
| 35 | struct PxGpuTaskHint |
| 36 | { |
| 37 | /// \brief Enums for the type of GPU task |
| 38 | enum Enum |
| 39 | { |
| 40 | HostToDevice, |
| 41 | Kernel, |
| 42 | DeviceToHost, |
| 43 | |
| 44 | NUM_GPU_TASK_HINTS |
| 45 | }; |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * \brief PxTask implementation for launching CUDA work |
| 50 | */ |
| 51 | class PxGpuTask : public PxTask |
| 52 | { |
| 53 | public: |
| 54 | PxGpuTask() : mComp(NULL) {} |
| 55 | |
| 56 | /** |
| 57 | * \brief iterative "run" function for a PxGpuTask |
| 58 | * |
| 59 | * The GpuDispatcher acquires the CUDA context for the duration of this |
| 60 | * function call, and it is highly recommended that the PxGpuTask use the |
| 61 | * provided CUstream for all kernels. |
| 62 | * |
| 63 | * kernelIndex will be 0 for the initial call and incremented before each |
| 64 | * subsequent call. Once launchInstance() returns false, its PxGpuTask is |
| 65 | * considered completed and is released. |
| 66 | */ |
| 67 | virtual bool launchInstance(CUstream stream, int kernelIndex) = 0; |
| 68 | |
| 69 | /** |
| 70 | * \brief Returns a hint indicating the function of this task |
| 71 | */ |
| 72 | virtual PxGpuTaskHint::Enum getTaskHint() const = 0; |
| 73 | |
| 74 | /** |
| 75 | * \brief Specify a task that will have its reference count decremented |
| 76 | * when this task is released |
| 77 | */ |
| 78 | void setCompletionTask(PxBaseTask& task) |
| 79 | { |
| 80 | mComp = &task; |
| 81 | } |
| 82 | |
| 83 | void release() |
| 84 | { |
| 85 | if (mComp) |
| 86 | { |
| 87 | mComp->removeReference(); |
| 88 | mComp = NULL; |
| 89 | } |
| 90 | PxTask::release(); |
| 91 | } |
| 92 | |
| 93 | protected: |
| 94 | /// \brief A pointer to the completion task |
| 95 | PxBaseTask* mComp; |
| 96 | }; |
| 97 | |
| 98 | PX_POP_PACK |
| 99 | |
| 100 | #ifndef PX_DOXYGEN |
| 101 | } // end physx namespace |
| 102 | #endif |
| 103 | |
| 104 | #endif |
| 105 | |