2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2021-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2021-04-25 22:32:35 +00:00
|
|
|
|
|
|
|
#include "nvidia-cuda-obs.hpp"
|
|
|
|
#include "obs/gs/gs-helper.hpp"
|
|
|
|
#include "util/util-logging.hpp"
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define ST_PREFIX "<%s> "
|
|
|
|
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
|
|
|
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
|
|
|
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
|
|
|
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define ST_PREFIX "<nvidia::cuda::obs> "
|
|
|
|
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
|
|
|
|
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
|
|
|
|
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
|
|
|
|
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2021-06-16 10:16:35 +00:00
|
|
|
streamfx::nvidia::cuda::obs::~obs()
|
2021-04-25 22:32:35 +00:00
|
|
|
{
|
|
|
|
D_LOG_DEBUG("Finalizing... (Addr: 0x%" PRIuPTR ")", this);
|
|
|
|
|
2021-06-08 02:38:24 +00:00
|
|
|
auto gctx = streamfx::obs::gs::context{};
|
2021-04-25 22:32:35 +00:00
|
|
|
{
|
|
|
|
auto stack = _context->enter();
|
|
|
|
_stream->synchronize();
|
|
|
|
_context->synchronize();
|
2021-06-17 10:15:38 +00:00
|
|
|
_stream.reset();
|
2021-04-25 22:32:35 +00:00
|
|
|
}
|
|
|
|
_context.reset();
|
|
|
|
_cuda.reset();
|
|
|
|
}
|
|
|
|
|
2021-06-16 10:16:35 +00:00
|
|
|
streamfx::nvidia::cuda::obs::obs() : _cuda(::streamfx::nvidia::cuda::cuda::get()), _context()
|
2021-04-25 22:32:35 +00:00
|
|
|
{
|
|
|
|
D_LOG_DEBUG("Initializating... (Addr: 0x%" PRIuPTR ")", this);
|
|
|
|
|
2021-06-08 02:38:24 +00:00
|
|
|
auto gctx = streamfx::obs::gs::context{};
|
2021-04-25 22:32:35 +00:00
|
|
|
|
|
|
|
// Create Context
|
|
|
|
#ifdef WIN32
|
|
|
|
if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) {
|
2023-05-13 12:35:46 +00:00
|
|
|
_context = std::make_shared<::streamfx::nvidia::cuda::context>(reinterpret_cast<ID3D11Device*>(gs_get_device_obj()));
|
2021-04-25 22:32:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (gs_get_device_type() == GS_DEVICE_OPENGL) {
|
|
|
|
throw std::runtime_error("Not yet implemented.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Stream
|
|
|
|
auto stack = _context->enter();
|
2021-06-16 10:16:35 +00:00
|
|
|
_stream = std::make_shared<::streamfx::nvidia::cuda::stream>();
|
2021-04-25 22:32:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 10:16:35 +00:00
|
|
|
std::shared_ptr<streamfx::nvidia::cuda::obs> streamfx::nvidia::cuda::obs::get()
|
2021-04-25 22:32:35 +00:00
|
|
|
{
|
2021-06-16 10:16:35 +00:00
|
|
|
static std::weak_ptr<streamfx::nvidia::cuda::obs> instance;
|
|
|
|
static std::mutex lock;
|
2021-04-25 22:32:35 +00:00
|
|
|
|
|
|
|
std::unique_lock<std::mutex> ul(lock);
|
|
|
|
if (instance.expired()) {
|
2021-06-16 10:16:35 +00:00
|
|
|
std::shared_ptr<streamfx::nvidia::cuda::obs> hard_instance;
|
|
|
|
hard_instance = std::make_shared<streamfx::nvidia::cuda::obs>();
|
2021-04-25 22:32:35 +00:00
|
|
|
instance = hard_instance;
|
|
|
|
return hard_instance;
|
|
|
|
}
|
|
|
|
return instance.lock();
|
|
|
|
}
|
|
|
|
|
2021-06-16 10:16:35 +00:00
|
|
|
std::shared_ptr<streamfx::nvidia::cuda::cuda> streamfx::nvidia::cuda::obs::get_cuda()
|
2021-04-25 22:32:35 +00:00
|
|
|
{
|
|
|
|
return _cuda;
|
|
|
|
}
|
|
|
|
|
2021-06-16 10:16:35 +00:00
|
|
|
std::shared_ptr<streamfx::nvidia::cuda::context> streamfx::nvidia::cuda::obs::get_context()
|
2021-04-25 22:32:35 +00:00
|
|
|
{
|
|
|
|
return _context;
|
|
|
|
}
|
|
|
|
|
2021-06-16 10:16:35 +00:00
|
|
|
std::shared_ptr<streamfx::nvidia::cuda::stream> streamfx::nvidia::cuda::obs::get_stream()
|
2021-04-25 22:32:35 +00:00
|
|
|
{
|
|
|
|
return _stream;
|
|
|
|
}
|