nvidia/cuda/cuda: Convert to global Singleton

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-06-15 01:10:02 +02:00
parent 9658c1ee0f
commit 5530d2d416
3 changed files with 17 additions and 3 deletions

View file

@ -606,7 +606,7 @@ bool face_tracking_instance::button_profile(obs_properties_t* props, obs_propert
face_tracking_factory::face_tracking_factory() face_tracking_factory::face_tracking_factory()
{ {
// Try and load CUDA. // Try and load CUDA.
_cuda = std::make_shared<::nvidia::cuda::cuda>(); _cuda = ::nvidia::cuda::cuda::get();
// Try and load AR. // Try and load AR.
_ar = std::make_shared<::nvidia::ar::ar>(); _ar = std::make_shared<::nvidia::ar::ar>();

View file

@ -18,8 +18,8 @@
*/ */
#include "nvidia-cuda.hpp" #include "nvidia-cuda.hpp"
#include <stdexcept> #include "common.hpp"
#include <util/platform.h> #include <mutex>
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
#define CUDA_NAME "nvcuda.dll" #define CUDA_NAME "nvcuda.dll"
@ -121,3 +121,15 @@ nvidia::cuda::cuda::~cuda()
{ {
os_dlclose(_library); os_dlclose(_library);
} }
std::shared_ptr<nvidia::cuda::cuda> nvidia::cuda::cuda::get()
{
static std::shared_ptr<nvidia::cuda::cuda> instance;
static std::mutex lock;
std::unique_lock<std::mutex> ul(lock);
if (!instance) {
instance = std::make_shared<nvidia::cuda::cuda>();
}
return instance;
}

View file

@ -396,6 +396,8 @@ namespace nvidia::cuda {
CUDA_DEFINE_FUNCTION(cuGraphicsD3D11RegisterResource, graphics_resource_t* resource, CUDA_DEFINE_FUNCTION(cuGraphicsD3D11RegisterResource, graphics_resource_t* resource,
ID3D11Resource* d3dresource, std::uint32_t flags); ID3D11Resource* d3dresource, std::uint32_t flags);
#endif #endif
public:
static std::shared_ptr<cuda> get();
}; };
} // namespace nvidia::cuda } // namespace nvidia::cuda