upscaling: Check if NVIDIA component is available

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-09-30 05:37:41 +02:00 committed by Xaymar
parent 4ebc96997e
commit 34e754d474
3 changed files with 31 additions and 17 deletions

View file

@ -6,4 +6,18 @@ cmake_minimum_required(VERSION 3.26)
project("Upscaling")
list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ")
streamfx_add_component("Upscaling")
streamfx_add_component("Upscaling"
RESOLVER streamfx_upscaling_resolver
)
streamfx_add_component_dependency("NVIDIA" OPTIONAL)
function(streamfx_upscaling_resolver)
# Providers
#- NVIDIA
streamfx_enabled_component("NVIDIA" T_CHECK)
if(T_CHECK)
target_compile_definitions(${COMPONENT_TARGET}
ENABLE_NVIDIA
)
endif()
endfunction()

View file

@ -30,7 +30,7 @@
#define ST_I18N_PROVIDER ST_I18N "." ST_KEY_PROVIDER
#define ST_I18N_PROVIDER_NVIDIA_SUPERRES ST_I18N_PROVIDER ".NVIDIA.SuperResolution"
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
#define ST_KEY_NVIDIA_SUPERRES "NVIDIA.SuperRes"
#define ST_I18N_NVIDIA_SUPERRES ST_I18N "." ST_KEY_NVIDIA_SUPERRES
#define ST_KEY_NVIDIA_SUPERRES_STRENGTH "NVIDIA.SuperRes.Strength"
@ -123,7 +123,7 @@ upscaling_instance::~upscaling_instance()
// TODO: Make this asynchronous.
switch (_provider) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
nvvfxsr_unload();
break;
@ -159,7 +159,7 @@ void upscaling_instance::update(obs_data_t* data)
std::unique_lock<std::mutex> ul(_provider_lock);
switch (_provider) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
nvvfxsr_update(data);
break;
@ -173,7 +173,7 @@ void upscaling_instance::update(obs_data_t* data)
void streamfx::filter::upscaling::upscaling_instance::properties(obs_properties_t* properties)
{
switch (_provider_ui) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
nvvfxsr_properties(properties);
break;
@ -206,7 +206,7 @@ void upscaling_instance::video_tick(float time)
std::unique_lock<std::mutex> ul(_provider_lock);
switch (_provider) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
nvvfxsr_size();
break;
@ -291,7 +291,7 @@ void upscaling_instance::video_render(gs_effect_t* effect)
::streamfx::obs::gs::debug_marker profiler1{::streamfx::obs::gs::debug_color_convert, "Process"};
#endif
switch (_provider) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
nvvfxsr_process();
break;
@ -384,7 +384,7 @@ void streamfx::filter::upscaling::upscaling_instance::task_switch_provider(util:
try {
// 3. Unload the previous provider.
switch (spd->provider) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
nvvfxsr_unload();
break;
@ -395,7 +395,7 @@ void streamfx::filter::upscaling::upscaling_instance::task_switch_provider(util:
// 4. Load the new provider.
switch (_provider) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
nvvfxsr_load();
{
@ -420,7 +420,7 @@ void streamfx::filter::upscaling::upscaling_instance::task_switch_provider(util:
}
}
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
void streamfx::filter::upscaling::upscaling_instance::nvvfxsr_load()
{
_nvidia_fx = std::make_shared<::streamfx::nvidia::vfx::superresolution>();
@ -489,7 +489,7 @@ upscaling_factory::upscaling_factory()
bool any_available = false;
// 1. Try and load any configured providers.
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
try {
// Load CVImage and Video Effects SDK.
_nvcuda = ::streamfx::nvidia::cuda::obs::get();
@ -539,7 +539,7 @@ void upscaling_factory::get_defaults2(obs_data_t* data)
{
obs_data_set_default_int(data, ST_KEY_PROVIDER, static_cast<int64_t>(upscaling_provider::AUTOMATIC));
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
obs_data_set_default_double(data, ST_KEY_NVIDIA_SUPERRES_SCALE, 150.);
obs_data_set_default_double(data, ST_KEY_NVIDIA_SUPERRES_STRENGTH, 0.);
#endif
@ -606,7 +606,7 @@ bool upscaling_factory::on_manual_open(obs_properties_t* props, obs_property_t*
bool streamfx::filter::upscaling::upscaling_factory::is_provider_available(upscaling_provider provider)
{
switch (provider) {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
case upscaling_provider::NVIDIA_SUPERRESOLUTION:
return _nvidia_available;
#endif

View file

@ -16,7 +16,7 @@
#include <mutex>
#include "warning-enable.hpp"
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
#include "nvidia/vfx/nvidia-vfx-superresolution.hpp"
#endif
@ -49,7 +49,7 @@ namespace streamfx::filter::upscaling {
std::shared_ptr<::streamfx::obs::gs::texture> _output;
bool _dirty;
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
std::shared_ptr<::streamfx::nvidia::vfx::superresolution> _nvidia_fx;
#endif
@ -72,7 +72,7 @@ namespace streamfx::filter::upscaling {
void switch_provider(upscaling_provider provider);
void task_switch_provider(util::threadpool::task_data_t data);
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
void nvvfxsr_load();
void nvvfxsr_unload();
void nvvfxsr_size();
@ -83,7 +83,7 @@ namespace streamfx::filter::upscaling {
};
class upscaling_factory : public ::streamfx::obs::source_factory<::streamfx::filter::upscaling::upscaling_factory, ::streamfx::filter::upscaling::upscaling_instance> {
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_NVIDIA
bool _nvidia_available;
std::shared_ptr<::streamfx::nvidia::cuda::obs> _nvcuda;
std::shared_ptr<::streamfx::nvidia::cv::cv> _nvcvi;