gfx/shader: Add profiling code and fix problems with properties

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-11-25 21:33:32 +01:00
parent e1b7e6eaf2
commit 93a20c7dd4

View file

@ -19,6 +19,7 @@
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include "obs/gs/gs-helper.hpp"
#include "obs/obs-tools.hpp" #include "obs/obs-tools.hpp"
#include "plugin.hpp" #include "plugin.hpp"
@ -265,9 +266,13 @@ bool streamfx::gfx::shader::shader::on_refresh_properties(obs_properties_t* prop
// Rebuild new parameters. // Rebuild new parameters.
obs_data_t* data = obs_source_get_settings(_self); obs_data_t* data = obs_source_get_settings(_self);
for (auto kv : _shader_params) { for (auto kv : _shader_params) {
kv.second->properties(grp, data); try {
kv.second->defaults(data); kv.second->properties(grp, data);
kv.second->update(data); kv.second->defaults(data);
kv.second->update(data);
} catch (...) {
// ToDo: Do something with these?
}
} }
obs_source_update(_self, data); obs_source_update(_self, data);
} }
@ -497,7 +502,12 @@ void streamfx::gfx::shader::shader::render(gs_effect* effect)
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
if (!_rt_up_to_date) { if (!_rt_up_to_date) {
auto op = _rt->render(width(), height()); #ifdef ENABLE_PROFILING
::streamfx::obs::gs::debug_marker profiler1{::streamfx::obs::gs::debug_color_cache, "Render Cache"};
#endif
auto op = _rt->render(width(), height());
vec4 zero = {0, 0, 0, 0}; vec4 zero = {0, 0, 0, 0};
gs_ortho(0, 1, 0, 1, 0, 1); gs_ortho(0, 1, 0, 1, 0, 1);
gs_clear(GS_CLEAR_COLOR, &zero, 0, 0); gs_clear(GS_CLEAR_COLOR, &zero, 0, 0);
@ -517,9 +527,15 @@ void streamfx::gfx::shader::shader::render(gs_effect* effect)
_rt_up_to_date = true; _rt_up_to_date = true;
} }
gs_effect_set_texture(gs_effect_get_param_by_name(effect, "image"), _rt->get_texture()->get_object()); if (auto tex = _rt->get_texture(); tex) {
while (gs_effect_loop(effect, "Draw")) { #ifdef ENABLE_PROFILING
gs_draw_sprite(nullptr, 0, width(), height()); ::streamfx::obs::gs::debug_marker profiler1{::streamfx::obs::gs::debug_color_render, "Draw Cache"};
#endif
gs_effect_set_texture_srgb(gs_effect_get_param_by_name(effect, "image"), tex->get_object());
while (gs_effect_loop(effect, "Draw")) {
gs_draw_sprite(nullptr, 0, width(), height());
}
} }
} }