diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b40186..6c51d19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,7 +230,9 @@ else() set(ENABLE_SOURCE_SHADER TRUE) set(ENABLE_TRANSITION_SHADER TRUE) endif() +## Encoders set(${PropertyPrefix}ENABLE_ENCODER_FFMPEG ${ENABLE_ENCODER_FFMPEG} CACHE BOOL "Enable FFmpeg Encoder") +## Filters set(${PropertyPrefix}ENABLE_FILTER_BLUR ${ENABLE_FILTER_BLUR} CACHE BOOL "Enable Blur Filter") set(${PropertyPrefix}ENABLE_FILTER_COLOR_GRADE ${ENABLE_FILTER_COLOR_GRADE} CACHE BOOL "Enable Color Grade Filter") set(${PropertyPrefix}ENABLE_FILTER_DISPLACEMENT ${ENABLE_FILTER_DISPLACEMENT} CACHE BOOL "Enable Displacement Filter") @@ -239,9 +241,13 @@ set(${PropertyPrefix}ENABLE_FILTER_NVIDIA_FACE_TRACKING ${ENABLE_FILTER_NVIDIA_F set(${PropertyPrefix}ENABLE_FILTER_SDF_EFFECTS ${ENABLE_FILTER_SDF_EFFECTS} CACHE BOOL "Enable SDF Effects Filter") set(${PropertyPrefix}ENABLE_FILTER_SHADER ${ENABLE_FILTER_SHADER} CACHE BOOL "Enable Shader Filter") set(${PropertyPrefix}ENABLE_FILTER_TRANSFORM ${ENABLE_FILTER_TRANSFORM} CACHE BOOL "Enable Transform Filter") +## Sources set(${PropertyPrefix}ENABLE_SOURCE_MIRROR ${ENABLE_SOURCE_MIRROR} CACHE BOOL "Enable Mirror Source") set(${PropertyPrefix}ENABLE_SOURCE_SHADER ${ENABLE_SOURCE_SHADER} CACHE BOOL "Enable Shader Source") +## Transitions set(${PropertyPrefix}ENABLE_TRANSITION_SHADER ${ENABLE_TRANSITION_SHADER} CACHE BOOL "Enable Shader Transition") +## Debugging +set(${PropertyPrefix}ENABLE_PROFILING FALSE CACHE BOOL "Enable CPU and GPU performance tracking, which has a non-zero overhead at all times. Do not enable this for release builds.") ################################################################################ # CMake / Compiler Dependencies @@ -806,6 +812,13 @@ if(${PropertyPrefix}ENABLE_TRANSITION_SHADER) ) endif() +## Features - Performance Profiling +if(${PropertyPrefix}ENABLE_PROFILING) + list(APPEND PROJECT_DEFINITIONS + ENABLE_PROFILING + ) +endif() + ## Parts if(REQUIRE_SHADER_CODE) list(APPEND PROJECT_PRIVATE_SOURCE diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index b4d0489..d5085d5 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -367,13 +367,17 @@ void blur_instance::video_render(gs_effect_t* effect) return; } - auto gdm = - gs::debug_marker(gs::debug_color_azure_radiance, "%s '%s'", __FUNCTION_SIG__, obs_source_get_name(_self)); +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Blur '%s'", obs_source_get_name(_self)}; +#endif if (!_source_rendered) { // Source To Texture { - auto gdm = gs::debug_marker(gs::debug_color_cache, "Cache"); +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_cache, "Cache"}; +#endif + if (obs_source_process_filter_begin(this->_self, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) { { auto op = this->_source_rt->render(baseW, baseH); @@ -419,12 +423,21 @@ void blur_instance::video_render(gs_effect_t* effect) } if (!_output_rendered) { - _blur->set_input(_source_texture); - _output_texture = _blur->render(); + { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Blur"}; +#endif + + _blur->set_input(_source_texture); + _output_texture = _blur->render(); + } // Mask if (_mask.enabled) { - auto gdm = gs::debug_marker(gs::debug_color_convert, "Mask"); +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Mask"}; +#endif + gs_blend_state_push(); gs_reset_blend_state(); gs_enable_color(true, true, true, true); @@ -479,6 +492,11 @@ void blur_instance::video_render(gs_effect_t* effect) } } +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_capture, "Capture '%s'", + obs_source_get_name(_mask.source.source_texture->get_object())}; +#endif + this->_mask.source.texture = this->_mask.source.source_texture->render(source_width, source_height); } @@ -510,7 +528,10 @@ void blur_instance::video_render(gs_effect_t* effect) // Draw source { - auto gdm = gs::debug_marker(gs::debug_color_render, "Render"); +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_render, "Render"}; +#endif + // It is important that we do not modify the blend state here, as it is set correctly by OBS gs_set_cull_mode(GS_NEITHER); gs_enable_color(true, true, true, true); diff --git a/source/filters/filter-color-grade.cpp b/source/filters/filter-color-grade.cpp index 6abcfaf..27132a3 100644 --- a/source/filters/filter-color-grade.cpp +++ b/source/filters/filter-color-grade.cpp @@ -20,6 +20,7 @@ #include "filter-color-grade.hpp" #include "strings.hpp" #include +#include "obs/gs/gs-helper.hpp" #include "util-math.hpp" // OBS @@ -186,7 +187,15 @@ void color_grade_instance::video_render(gs_effect_t* effect) return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Color Grading '%s'", obs_source_get_name(_self)}; +#endif + if (!_source_updated) { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_cache, "Cache"}; +#endif + if (obs_source_process_filter_begin(_self, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) { auto op = _rt_source->render(width, height); gs_blend_state_push(); @@ -207,6 +216,10 @@ void color_grade_instance::video_render(gs_effect_t* effect) } if (!_grade_updated) { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Calculate"}; +#endif + { auto op = _rt_grade->render(width, height); gs_blend_state_push(); @@ -245,6 +258,10 @@ void color_grade_instance::video_render(gs_effect_t* effect) // Render final result. { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_render, "Render"}; +#endif + auto shader = obs_get_base_effect(OBS_EFFECT_DEFAULT); gs_enable_depth_test(false); while (gs_effect_loop(shader, "Draw")) { diff --git a/source/filters/filter-displacement.cpp b/source/filters/filter-displacement.cpp index e583c57..34a857a 100644 --- a/source/filters/filter-displacement.cpp +++ b/source/filters/filter-displacement.cpp @@ -21,6 +21,7 @@ #include "strings.hpp" #include #include +#include "obs/gs/gs-helper.hpp" #define ST "Filter.Displacement" #define ST_FILE "Filter.Displacement.File" @@ -95,6 +96,11 @@ void displacement_instance::video_render(gs_effect_t*) return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Displacement Mapping '%s' on '%s'", obs_source_get_name(_self), + obs_source_get_name(obs_filter_get_parent(_self))}; +#endif + if (!obs_source_process_filter_begin(_self, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) { obs_source_skip_video_filter(_self); return; diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index ac7f371..b1bc4bf 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "obs/gs/gs-helper.hpp" // Filter to allow dynamic masking // Allow any channel to affect any other channel @@ -201,10 +202,19 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect) return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Dynamic Mask '%s' on '%s'", obs_source_get_name(_self), + obs_source_get_name(obs_filter_get_parent(_self))}; +#endif + gs_effect_t* default_effect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_DEFAULT); try { // Capture filter and input if (!_have_filter_texture) { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_cache, "Cache"}; +#endif + if (obs_source_process_filter_begin(_self, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) { auto op = _filter_rt->render(width, height); @@ -237,12 +247,21 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect) } if (!_have_input_texture) { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_capture, "Capture '%s'", + obs_source_get_name(_input_capture->get_object())}; +#endif + _input_texture = _input_capture->render(_input->width(), _input->height()); _have_input_texture = true; } // Draw source if (!_have_final_texture) { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Masking"}; +#endif + { auto op = _final_rt->render(width, height); @@ -296,6 +315,10 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect) // Draw source { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_render, "Render"}; +#endif + // It is important that we do not modify the blend state here, as it is set correctly by OBS gs_set_cull_mode(GS_NEITHER); gs_enable_color(true, true, true, true); diff --git a/source/filters/filter-nv-face-tracking.cpp b/source/filters/filter-nv-face-tracking.cpp index e3d1711..a813786 100644 --- a/source/filters/filter-nv-face-tracking.cpp +++ b/source/filters/filter-nv-face-tracking.cpp @@ -79,7 +79,7 @@ face_tracking_instance::face_tracking_instance(obs_data_t* settings, obs_source_ minPrio + ((maxPrio - minPrio) / 2)); } -#ifdef _DEBUG +#ifdef ENABLE_PROFILING // Profiling _profile_capture = util::profiler::create(); _profile_capture_realloc = util::profiler::create(); @@ -247,10 +247,10 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) // Check if things exist as planned. if (!_ar_texture || (_ar_texture->get_width() != _size.first) || (_ar_texture->get_height() != _size.second)) { -#ifdef _DEBUG - auto prof = _profile_capture_realloc->track(); -#endif +#ifdef ENABLE_PROFILING + auto prof = _profile_capture_realloc->track(); gs::debug_marker marker{gs::debug_color_allocate, "Reallocate GPU Buffer"}; +#endif _ar_texture = std::make_shared(_size.first, _size.second, GS_RGBA, 1, nullptr, gs::texture::flags::None); @@ -258,10 +258,10 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) } { // Copy texture -#ifdef _DEBUG - auto prof = _profile_capture_copy->track(); -#endif +#ifdef ENABLE_PROFILING + auto prof = _profile_capture_copy->track(); gs::debug_marker marker{gs::debug_color_copy, "Copy Capture", obs_source_get_name(_self)}; +#endif gs_copy_texture(_ar_texture->get_object(), _rt->get_texture()->get_object()); } @@ -279,17 +279,19 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) return; } + // Acquire GS context. + gs::context gctx; + // Update the current CUDA context for working. auto cctx = std::make_shared<::nvidia::cuda::context_stack>(_cuda, _cuda_ctx); // Refresh any now broken buffers. if (!_ar_texture_cuda_fresh) { -#ifdef _DEBUG - auto prof = _profile_ar_realloc->track(); -#endif - gs::context gctx; +#ifdef ENABLE_PROFILING + auto prof = _profile_ar_realloc->track(); gs::debug_marker marker{gs::debug_color_allocate, "%s: Reallocate CUDA Buffers", obs_source_get_name(_self)}; +#endif // Assign new texture and allocate new memory. std::size_t pitch = _size.first * 4ul; @@ -320,10 +322,9 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) } { // Copy from CUDA array to CUDA device memory. -#ifdef _DEBUG +#ifdef ENABLE_PROFILING auto prof = _profile_ar_copy->track(); #endif - gs::context gctx; ::nvidia::cuda::cu_memcpy2d_t mc; mc.src_x_in_bytes = 0; @@ -350,10 +351,10 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) } { // Convert from RGBA 32-bit to BGR 24-bit. -#ifdef _DEBUG +#ifdef ENABLE_PROFILING auto prof = _profile_ar_transfer->track(); #endif - gs::context gctx; + if (NvCV_Status res = _ar_library->image_transfer(&_ar_image, &_ar_image_bgr, 1.0, reinterpret_cast(_cuda_stream->get()), &_ar_image_temp); @@ -364,10 +365,10 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) } { // Track any faces. -#ifdef _DEBUG +#ifdef ENABLE_PROFILING auto prof = _profile_ar_run->track(); #endif - gs::context gctx; + if (NvCV_Status res = _ar_library->run(_ar_feature.get()); res != NVCV_SUCCESS) { LOG_ERROR("<%s> Failed to run tracking.", obs_source_get_name(_self)); return; @@ -377,9 +378,10 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) if ((_ar_bboxes.num_boxes == 0) || (_ar_bboxes_confidence.at(0) < 0.5)) { // Not confident enough or not tracking anything, return to full frame after a bit. } else { -#ifdef _DEBUG +#ifdef ENABLE_PROFILING auto prof = _profile_ar_calc->track(); #endif + double_t aspect = double_t(_size.first) / double_t(_size.second); // Store values and center. @@ -482,35 +484,49 @@ void face_tracking_instance::video_tick(float_t seconds) void face_tracking_instance::video_render(gs_effect_t* effect) { - gs::debug_marker gdm_main{gs::debug_color_source, "%s", obs_source_get_name(_self)}; - obs_source_t* filter_parent = obs_filter_get_parent(_self); - obs_source_t* filter_target = obs_filter_get_target(_self); - gs_effect_t* default_effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); + obs_source_t* filter_parent = obs_filter_get_parent(_self); + obs_source_t* filter_target = obs_filter_get_target(_self); + gs_effect_t* default_effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); if (!filter_parent || !filter_target || !_size.first || !_size.second || !_ar_loaded) { obs_source_skip_video_filter(_self); return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Nvidia Face Tracking '%s' on '%s'", obs_source_get_name(_self), + obs_source_get_name(obs_filter_get_parent(_self))}; +#endif + if (!_rt_is_fresh) { // Capture the filter stack "below" us. -#ifdef _DEBUG +#ifdef ENABLE_PROFILING auto prof = _profile_capture->track(); #endif - gs::debug_marker marker{gs::debug_color_capture, "Capture"}; - if (obs_source_process_filter_begin(_self, _rt->get_color_format(), OBS_ALLOW_DIRECT_RENDERING)) { - auto op = _rt->render(_size.first, _size.second); - vec4 clr = {0., 0., 0., 0.}; - gs_ortho(0., static_cast(_size.first), 0., static_cast(_size.second), 0., 1.); - gs_clear(GS_CLEAR_COLOR, &clr, 0., 0.); + { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_cache, "Cache"}; +#endif - obs_source_process_filter_tech_end(_self, default_effect, _size.first, _size.second, "Draw"); - } else { - obs_source_skip_video_filter(_self); - return; + if (obs_source_process_filter_begin(_self, _rt->get_color_format(), OBS_ALLOW_DIRECT_RENDERING)) { + auto op = _rt->render(_size.first, _size.second); + vec4 clr = {0., 0., 0., 0.}; + + gs_ortho(0., static_cast(_size.first), 0., static_cast(_size.second), 0., 1.); + gs_clear(GS_CLEAR_COLOR, &clr, 0., 0.); + + obs_source_process_filter_tech_end(_self, default_effect, _size.first, _size.second, "Draw"); + } else { + obs_source_skip_video_filter(_self); + return; + } } if (_ar_tracked) { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Trigger Async Tracking Task"}; +#endif + async_track(nullptr); refresh_geometry(); } @@ -518,18 +534,22 @@ void face_tracking_instance::video_render(gs_effect_t* effect) _rt_is_fresh = true; } - // Draw Texture - gs::debug_marker marker{gs::debug_color_render, "Render"}; - gs_effect_set_texture(gs_effect_get_param_by_name(effect ? effect : default_effect, "image"), - _rt->get_texture()->get_object()); - gs_load_vertexbuffer(_roi_geom->update()); - while (gs_effect_loop(effect ? effect : default_effect, "Draw")) { - gs_draw(gs_draw_mode::GS_TRISTRIP, 0, _roi_geom->size()); + { // Draw Texture +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_render, "Render"}; +#endif + + gs_effect_set_texture(gs_effect_get_param_by_name(effect ? effect : default_effect, "image"), + _rt->get_texture()->get_object()); + gs_load_vertexbuffer(_roi_geom->update()); + while (gs_effect_loop(effect ? effect : default_effect, "Draw")) { + gs_draw(gs_draw_mode::GS_TRISTRIP, 0, _roi_geom->size()); + } + gs_load_vertexbuffer(nullptr); } - gs_load_vertexbuffer(nullptr); } -#ifdef _DEBUG +#ifdef ENABLE_PROFILING bool face_tracking_instance::button_profile(obs_properties_t* props, obs_property_t* property) { LOG_INFO("%-22s: %-10s %-10s %-10s %-10s %-10s", "Task", "Total", "Count", "Average", "99.9%ile", "95.0%ile"); @@ -634,7 +654,7 @@ obs_properties_t* face_tracking_factory::get_properties2(face_tracking_instance* } } } -#ifdef _DEBUG +#ifdef ENABLE_PROFILING { obs_properties_add_button2( pr, "Profile", "Profile", diff --git a/source/filters/filter-nv-face-tracking.hpp b/source/filters/filter-nv-face-tracking.hpp index 347944e..2dbffbb 100644 --- a/source/filters/filter-nv-face-tracking.hpp +++ b/source/filters/filter-nv-face-tracking.hpp @@ -74,7 +74,7 @@ namespace streamfx::filter::nvidia { NvCVImage _ar_image_bgr; NvCVImage _ar_image_temp; -#ifdef _DEBUG +#ifdef ENABLE_PROFILING // Profiling std::shared_ptr _profile_capture; std::shared_ptr _profile_capture_realloc; @@ -114,7 +114,7 @@ namespace streamfx::filter::nvidia { virtual void video_render(gs_effect_t* effect) override; -#ifdef _DEBUG +#ifdef ENABLE_PROFILING bool button_profile(obs_properties_t* props, obs_property_t* property); #endif }; diff --git a/source/filters/filter-sdf-effects.cpp b/source/filters/filter-sdf-effects.cpp index e532695..5a5e993 100644 --- a/source/filters/filter-sdf-effects.cpp +++ b/source/filters/filter-sdf-effects.cpp @@ -281,6 +281,11 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "SDF Effects '%s' on '%s'", obs_source_get_name(_self), + obs_source_get_name(obs_filter_get_parent(_self))}; +#endif + auto gctx = gs::context(); vec4 color_transparent = {0, 0, 0, 0}; @@ -302,6 +307,10 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) if (!_source_rendered) { // Store input texture. { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_cache, "Cache"}; +#endif + auto op = _source_rt->render(baseW, baseH); gs_ortho(0, (float)baseW, 0, (float)baseH, -1, 1); gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &color_transparent, 0, 0); @@ -340,6 +349,10 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) } { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Update Distance Field"}; +#endif + auto op = _sdf_write->render(uint32_t(sdfW), uint32_t(sdfH)); gs_ortho(0, (float)sdfW, 0, (float)sdfH, -1, 1); gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &color_transparent, 0, 0); @@ -394,6 +407,10 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) // Optimized Render path. try { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Calculate"}; +#endif + auto op = _output_rt->render(baseW, baseH); gs_ortho(0, 1, 0, 1, 0, 1); @@ -486,12 +503,18 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) return; } - gs_eparam_t* ep = gs_effect_get_param_by_name(final_effect, "image"); - if (ep) { - gs_effect_set_texture(ep, _output_texture->get_object()); - } - while (gs_effect_loop(final_effect, "Draw")) { - gs_draw_sprite(0, 0, baseW, baseH); + { +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_render, "Render"}; +#endif + + gs_eparam_t* ep = gs_effect_get_param_by_name(final_effect, "image"); + if (ep) { + gs_effect_set_texture(ep, _output_texture->get_object()); + } + while (gs_effect_loop(final_effect, "Draw")) { + gs_draw_sprite(0, 0, baseW, baseH); + } } } diff --git a/source/filters/filter-shader.cpp b/source/filters/filter-shader.cpp index 751a3c5..5c0aa30 100644 --- a/source/filters/filter-shader.cpp +++ b/source/filters/filter-shader.cpp @@ -85,9 +85,17 @@ void shader_instance::video_render(gs_effect_t* effect) return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Shader Filter '%s' on '%s'", obs_source_get_name(_self), + obs_source_get_name(obs_filter_get_parent(_self))}; +#endif + { - gs::debug_marker _marker_cache{gs::debug_color_source, "%s: Capture", obs_source_get_name(_self)}; - auto op = _rt->render(_fx->width(), _fx->height()); +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_source, "Cache"}; +#endif + + auto op = _rt->render(_fx->width(), _fx->height()); gs_ortho(0, static_cast(_fx->width()), 0, static_cast(_fx->height()), -1, 1); @@ -116,7 +124,9 @@ void shader_instance::video_render(gs_effect_t* effect) } { - gs::debug_marker _marker_cache{gs::debug_color_render, "%s: Render", obs_source_get_name(_self)}; +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_render, "Render"}; +#endif _fx->prepare_render(); _fx->set_input_a(_rt->get_texture()); diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index 0543a8a..16d32e3 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -286,7 +286,10 @@ void transform_instance::video_render(gs_effect_t* effect) return; } - gs::debug_marker marker{gs::debug_color_source, "3D Transform: %s", obs_source_get_name(_self)}; +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "3D Transform '%s' on '%s'", obs_source_get_name(_self), + obs_source_get_name(obs_filter_get_parent(_self))}; +#endif std::uint32_t cache_width = base_width; std::uint32_t cache_height = base_height; @@ -310,8 +313,11 @@ void transform_instance::video_render(gs_effect_t* effect) } if (!_cache_rendered) { - gs::debug_marker _marker_cache{gs::debug_color_cache, "Cache"}; - auto op = _cache_rt->render(cache_width, cache_height); +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_cache, "Cache"}; +#endif + + auto op = _cache_rt->render(cache_width, cache_height); gs_ortho(0, static_cast(base_width), 0, static_cast(base_height), -1, 1); @@ -347,13 +353,18 @@ void transform_instance::video_render(gs_effect_t* effect) } if (_mipmap_enabled) { - gs::debug_marker _marker_mipmap{gs::debug_color_convert, "Mipmap"}; +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Mipmap"}; +#endif if (!_mipmap_texture || (_mipmap_texture->get_width() != cache_width) || (_mipmap_texture->get_height() != cache_height)) { +#ifdef ENABLE_PROFILING + gs::debug_marker gdr{gs::debug_color_allocate, "Allocate Mipmapped Texture"}; +#endif + std::size_t mip_levels = std::max(util::math::get_power_of_two_exponent_ceil(cache_width), util::math::get_power_of_two_exponent_ceil(cache_height)); - _mipmap_texture = std::make_shared(cache_width, cache_height, GS_RGBA, mip_levels, nullptr, gs::texture::flags::None); } @@ -367,8 +378,11 @@ void transform_instance::video_render(gs_effect_t* effect) } { - gs::debug_marker _marker_draw{gs::debug_color_cache_render, "Geometry"}; - auto op = _source_rt->render(base_width, base_height); +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_convert, "Transform"}; +#endif + + auto op = _source_rt->render(base_width, base_height); gs_blend_state_push(); gs_reset_blend_state(); @@ -412,7 +426,10 @@ void transform_instance::video_render(gs_effect_t* effect) } { - gs::debug_marker _marker_draw{gs::debug_color_cache_render, "Final"}; +#ifdef ENABLE_PROFILING + gs::debug_marker gdm{gs::debug_color_render, "Render"}; +#endif + gs_effect_set_texture(gs_effect_get_param_by_name(effect, "image"), _source_texture->get_object()); while (gs_effect_loop(effect, "Draw")) { gs_draw_sprite(nullptr, 0, base_width, base_height); diff --git a/source/gfx/blur/gfx-blur-box-linear.cpp b/source/gfx/blur/gfx-blur-box-linear.cpp index 4c00bd7..a7e66cc 100644 --- a/source/gfx/blur/gfx-blur-box-linear.cpp +++ b/source/gfx/blur/gfx-blur-box-linear.cpp @@ -246,7 +246,10 @@ double_t gfx::blur::box_linear::get_step_scale_y() std::shared_ptr<::gs::texture> gfx::blur::box_linear::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Box Linear Blur"); +#endif float_t width = float_t(_input_texture->get_width()); float_t height = float_t(_input_texture->get_height()); @@ -275,8 +278,11 @@ std::shared_ptr<::gs::texture> gfx::blur::box_linear::render() effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f))); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Horizontal"); - auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -288,8 +294,11 @@ std::shared_ptr<::gs::texture> gfx::blur::box_linear::render() effect.get_parameter("pImageTexel").set_float2(0., float_t(1.f / height)); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Vertical"); - auto op = _rendertarget->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -327,7 +336,10 @@ void gfx::blur::box_linear_directional::set_angle(double_t angle) std::shared_ptr<::gs::texture> gfx::blur::box_linear_directional::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Box Linear Directional Blur"); +#endif float_t width = float_t(_input_texture->get_width()); float_t height = float_t(_input_texture->get_height()); diff --git a/source/gfx/blur/gfx-blur-box.cpp b/source/gfx/blur/gfx-blur-box.cpp index da90cf0..7e4b66b 100644 --- a/source/gfx/blur/gfx-blur-box.cpp +++ b/source/gfx/blur/gfx-blur-box.cpp @@ -254,7 +254,10 @@ double_t gfx::blur::box::get_step_scale_y() std::shared_ptr<::gs::texture> gfx::blur::box::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Box Blur"); +#endif float_t width = float_t(_input_texture->get_width()); float_t height = float_t(_input_texture->get_height()); @@ -283,8 +286,11 @@ std::shared_ptr<::gs::texture> gfx::blur::box::render() effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f))); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Horizontal"); - auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -296,8 +302,11 @@ std::shared_ptr<::gs::texture> gfx::blur::box::render() effect.get_parameter("pImageTexel").set_float2(0.f, float_t(1.f / height)); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Vertical"); - auto op = _rendertarget->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -335,7 +344,10 @@ void gfx::blur::box_directional::set_angle(double_t angle) std::shared_ptr<::gs::texture> gfx::blur::box_directional::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Box Directional Blur"); +#endif float_t width = float_t(_input_texture->get_width()); float_t height = float_t(_input_texture->get_height()); @@ -407,7 +419,10 @@ void gfx::blur::box_rotational::set_angle(double_t angle) std::shared_ptr<::gs::texture> gfx::blur::box_rotational::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Box Rotational Blur"); +#endif float_t width = float_t(_input_texture->get_width()); float_t height = float_t(_input_texture->get_height()); @@ -470,7 +485,10 @@ void gfx::blur::box_zoom::get_center(double_t& x, double_t& y) std::shared_ptr<::gs::texture> gfx::blur::box_zoom::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Box Zoom Blur"); +#endif float_t width = float_t(_input_texture->get_width()); float_t height = float_t(_input_texture->get_height()); diff --git a/source/gfx/blur/gfx-blur-dual-filtering.cpp b/source/gfx/blur/gfx-blur-dual-filtering.cpp index 12cc32d..d0d70ed 100644 --- a/source/gfx/blur/gfx-blur-dual-filtering.cpp +++ b/source/gfx/blur/gfx-blur-dual-filtering.cpp @@ -229,7 +229,10 @@ void gfx::blur::dual_filtering::get_step_scale(double_t&, double_t&) {} std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Dual-Filtering Blur"); +#endif auto effect = _data->get_effect(); if (!effect) { @@ -256,14 +259,15 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render() // Downsample for (std::size_t n = 1; n <= actual_iterations; n++) { - // Idx 0 is a simply considered as a straight copy of the original and not rendered to. +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Down %lld", n); +#endif // Select Texture std::shared_ptr tex_cur; if (n > 1) { tex_cur = _rts[n - 1]->get_texture(); - } else { + } else { // Idx 0 is a simply considered as a straight copy of the original and not rendered to. tex_cur = _input_texture; } @@ -292,8 +296,9 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render() // Upsample for (std::size_t n = actual_iterations; n > 0; n--) { - // Idx max is a simply considered as a straight copy of the downscale and not rendered to. +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Up %lld", n); +#endif // Select Texture std::shared_ptr tex_in = _rts[n]->get_texture(); diff --git a/source/gfx/blur/gfx-blur-gaussian-linear.cpp b/source/gfx/blur/gfx-blur-gaussian-linear.cpp index 8739134..6916ca9 100644 --- a/source/gfx/blur/gfx-blur-gaussian-linear.cpp +++ b/source/gfx/blur/gfx-blur-gaussian-linear.cpp @@ -292,7 +292,10 @@ double_t gfx::blur::gaussian_linear::get_step_scale_y() std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Gaussian Linear Blur"); +#endif gs::effect effect = _data->get_effect(); auto kernel = _data->get_kernel(size_t(_size)); @@ -328,8 +331,11 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear::render() effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), 0.f); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Horizontal"); - auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -345,8 +351,11 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear::render() effect.get_parameter("pImageTexel").set_float2(0.f, float_t(1.f / height)); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Vertical"); - auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -388,7 +397,10 @@ void gfx::blur::gaussian_linear_directional::set_angle(double_t angle) std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear_directional::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Gaussian Linear Directional Blur"); +#endif gs::effect effect = _data->get_effect(); auto kernel = _data->get_kernel(size_t(_size)); diff --git a/source/gfx/blur/gfx-blur-gaussian.cpp b/source/gfx/blur/gfx-blur-gaussian.cpp index 99daac8..f0e8574 100644 --- a/source/gfx/blur/gfx-blur-gaussian.cpp +++ b/source/gfx/blur/gfx-blur-gaussian.cpp @@ -298,7 +298,10 @@ double_t gfx::blur::gaussian::get_step_scale_y() std::shared_ptr<::gs::texture> gfx::blur::gaussian::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Gaussian Blur"); +#endif gs::effect effect = _data->get_effect(); auto kernel = _data->get_kernel(size_t(_size)); @@ -334,8 +337,11 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian::render() effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), 0.f); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Horizontal"); - auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -351,8 +357,11 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian::render() effect.get_parameter("pImageTexel").set_float2(0.f, float_t(1.f / height)); { +#ifdef ENABLE_PROFILING auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Vertical"); - auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); +#endif + + auto op = _rendertarget2->render(uint32_t(width), uint32_t(height)); gs_ortho(0, 1., 0, 1., 0, 1.); while (gs_effect_loop(effect.get_object(), "Draw")) { gs_draw_sprite(nullptr, 0, 1, 1); @@ -394,7 +403,10 @@ void gfx::blur::gaussian_directional::set_angle(double_t angle) std::shared_ptr<::gs::texture> gfx::blur::gaussian_directional::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Gaussian Directional Blur"); +#endif gs::effect effect = _data->get_effect(); auto kernel = _data->get_kernel(size_t(_size)); @@ -449,7 +461,10 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_directional::render() std::shared_ptr<::gs::texture> gfx::blur::gaussian_rotational::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Gaussian Rotational Blur"); +#endif gs::effect effect = _data->get_effect(); auto kernel = _data->get_kernel(size_t(_size)); @@ -527,7 +542,10 @@ void gfx::blur::gaussian_rotational::set_angle(double_t angle) std::shared_ptr<::gs::texture> gfx::blur::gaussian_zoom::render() { auto gctx = gs::context(); + +#ifdef ENABLE_PROFILING auto gdmp = gs::debug_marker(gs::debug_color_azure_radiance, "Gaussian Zoom Blur"); +#endif gs::effect effect = _data->get_effect(); auto kernel = _data->get_kernel(size_t(_size)); diff --git a/source/gfx/gfx-source-texture.cpp b/source/gfx/gfx-source-texture.cpp index bf9dd55..5a8e367 100644 --- a/source/gfx/gfx-source-texture.cpp +++ b/source/gfx/gfx-source-texture.cpp @@ -17,6 +17,7 @@ #include "gfx-source-texture.hpp" #include +#include "obs/gs/gs-helper.hpp" gfx::source_texture::~source_texture() { @@ -117,17 +118,17 @@ std::shared_ptr gfx::source_texture::render(std::size_t width, std: return nullptr; } - { - GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_ITEM, "gfx::source_texture"); + if (_child) { +#ifdef ENABLE_PROFILING + auto cctr = + gs::debug_marker(gs::debug_color_capture, "gfx::source_texture '%s'", obs_source_get_name(_child->get())); +#endif auto op = _rt->render((uint32_t)width, (uint32_t)height); vec4 black; vec4_zero(&black); gs_ortho(0, (float_t)width, 0, (float_t)height, 0, 1); gs_clear(GS_CLEAR_COLOR, &black, 0, 0); - if (_child) { - obs_source_video_render(_child->get()); - } - GS_DEBUG_MARKER_END(); + obs_source_video_render(_child->get()); } std::shared_ptr tex; diff --git a/source/obs/gs/gs-helper.cpp b/source/obs/gs/gs-helper.cpp index ccf900c..89eb64d 100644 --- a/source/obs/gs/gs-helper.cpp +++ b/source/obs/gs/gs-helper.cpp @@ -29,11 +29,6 @@ gs::context::~context() obs_leave_graphics(); } -/*gs::debug_marker::debug_marker(const float color[4], std::string name) : _name(name) -{ - gs_debug_marker_begin(color, _name.c_str()); -}*/ - gs::debug_marker::debug_marker(const float_t color[4], const char* format, ...) { std::size_t size; diff --git a/source/obs/gs/gs-mipmapper.cpp b/source/obs/gs/gs-mipmapper.cpp index 55715ae..f11e876 100644 --- a/source/obs/gs/gs-mipmapper.cpp +++ b/source/obs/gs/gs-mipmapper.cpp @@ -137,7 +137,10 @@ void gs::mipmapper::rebuild(std::shared_ptr source, std::shared_ptr size_t max_mip_level = 1; { +#ifdef ENABLE_PROFILING auto cctr = gs::debug_marker(gs::debug_color_azure_radiance, "Mip Level %lld", 0); +#endif + #ifdef _WIN32 if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) { { // Retrieve maximum mip map level. @@ -161,7 +164,9 @@ void gs::mipmapper::rebuild(std::shared_ptr source, std::shared_ptr // Render each mip map level. for (size_t mip = 1; mip < max_mip_level; mip++) { +#ifdef ENABLE_PROFILING auto cctr = gs::debug_marker(gs::debug_color_azure_radiance, "Mip Level %lld", mip); +#endif uint32_t cwidth = std::max(width >> mip, 1); uint32_t cheight = std::max(height >> mip, 1); diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index e9e43b0..258c64d 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -141,6 +141,11 @@ void mirror_instance::video_render(gs_effect_t* effect) if ((obs_source_get_output_flags(_source.get()) & OBS_SOURCE_VIDEO) == 0) return; +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Source Mirror '%s' for '%s'", obs_source_get_name(_self), + obs_source_get_name(_source.get())}; +#endif + obs_source_video_render(_source.get()); } diff --git a/source/sources/source-shader.cpp b/source/sources/source-shader.cpp index 00fd022..5dbb377 100644 --- a/source/sources/source-shader.cpp +++ b/source/sources/source-shader.cpp @@ -20,6 +20,7 @@ #include "source-shader.hpp" #include "strings.hpp" #include +#include "obs/gs/gs-helper.hpp" #include "utility.hpp" #define ST "Source.Shader" @@ -79,6 +80,10 @@ void shader_instance::video_render(gs_effect_t* effect) return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Shader Source '%s'", obs_source_get_name(_self)}; +#endif + _fx->prepare_render(); _fx->render(); } diff --git a/source/transitions/transition-shader.cpp b/source/transitions/transition-shader.cpp index 815c758..8c844c1 100644 --- a/source/transitions/transition-shader.cpp +++ b/source/transitions/transition-shader.cpp @@ -20,6 +20,7 @@ #include "transition-shader.hpp" #include "strings.hpp" #include +#include "obs/gs/gs-helper.hpp" #include "utility.hpp" #define ST "Transition.Shader" @@ -81,6 +82,10 @@ void shader_instance::video_render(gs_effect_t* effect) return; } +#ifdef ENABLE_PROFILING + gs::debug_marker gdmp{gs::debug_color_source, "Shader Transition '%s'", obs_source_get_name(_self)}; +#endif + _fx->prepare_render(); obs_transition_video_render( _self, [](void* data, gs_texture_t* a, gs_texture_t* b, float t, std::uint32_t cx, std::uint32_t cy) {