Commit 126a53dc authored by Florian Oetke's avatar Florian Oetke
Browse files

fixed Timestamp-Queries not becoming ready after pipeline recreation, or...

fixed Timestamp-Queries not becoming ready after pipeline recreation, or worked around it. Don't know, don't care...
parent f7dc2c68
......@@ -318,7 +318,10 @@ namespace mirrage {
_draw_settings_window();
if(_show_profiler) {
_meta_system.renderer().profiler().enable();
_draw_profiler_window();
} else {
_meta_system.renderer().profiler().disable();
}
}
......@@ -507,9 +510,6 @@ namespace mirrage {
_gui.centered_right(310, 380),
NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_TITLE | NK_WINDOW_MINIMIZABLE)) {
// TODO: disable when window is hidden
_meta_system.renderer().profiler().enable();
nk_layout_row_dynamic(ctx, 20, 1);
if(nk_button_label(ctx, "Reset")) {
_meta_system.renderer().profiler().reset();
......
......@@ -111,6 +111,9 @@ namespace mirrage::graphic {
public:
explicit Profiler(Device&, std::size_t max_elements = 32);
Profiler(Profiler&&) = default;
Profiler& operator =(Profiler&&) noexcept;
~Profiler();
void enable() noexcept { _active = true; }
void disable() noexcept { _active = false; }
......@@ -143,6 +146,7 @@ namespace mirrage::graphic {
Profiler_result _last_results;
Query_pools _query_pools;
bool _active = false;
bool _full = false;
Result_stack _current_stack;
util::maybe<vk::CommandBuffer> _current_command_buffer;
......@@ -155,5 +159,7 @@ namespace mirrage::graphic {
auto _generate_query_id() -> std::uint32_t;
void _update_result(Profiler_result&, const std::vector<std::uint32_t>& data);
void _wait_done();
};
}
......@@ -81,10 +81,41 @@ namespace mirrage::graphic {
})
, _query_used(max_elements, false) {}
Profiler& Profiler::operator=(Profiler&& rhs) noexcept {
_wait_done();
_device = std::move(rhs._device);
_ns_per_tick = std::move(rhs._ns_per_tick);
_query_ids = std::move(rhs._query_ids);
_next_query_id = std::move(rhs._next_query_id);
_last_results = std::move(rhs._last_results);
_query_pools = std::move(rhs._query_pools);
_current_stack = std::move(rhs._current_stack);
_current_command_buffer = std::move(rhs._current_command_buffer);
_query_result_buffer = std::move(rhs._query_result_buffer);
_query_used = std::move(rhs._query_used);
return *this;
}
Profiler::~Profiler() { _wait_done(); }
void Profiler::_wait_done() {
_query_pools.pop_while([&](auto& pool) {
auto status = _device.getQueryPoolResults<std::uint32_t>(*pool,
0,
_next_query_id,
_query_result_buffer,
sizeof(std::uint32_t),
vk::QueryResultFlagBits::eWait);
INVARIANT(status == vk::Result::eSuccess, "getQueryPoolResults failed!");
return true;
});
}
void Profiler::reset() noexcept { _last_results.reset(); }
void Profiler::start(vk::CommandBuffer cb) {
if(!_active)
if(!_active || _full)
return;
INVARIANT(_current_stack.empty(), "Profiler::start can not be nested!");
......@@ -102,26 +133,25 @@ namespace mirrage::graphic {
_current_command_buffer = cb;
}
void Profiler::end() {
if(!_active)
return;
if(_active && !_full) {
INVARIANT(_current_stack.size() == 1, "Unbalanced profiler stack!");
auto& cb = _current_command_buffer.get_or_throw(
"No active command buffer! Has Profiler::start been called?");
INVARIANT(_current_stack.size() == 1, "Unbalanced profiler stack!");
auto& cb = _current_command_buffer.get_or_throw(
"No active command buffer! Has Profiler::start been called?");
cb.writeTimestamp(vk::PipelineStageFlagBits::eAllCommands,
*_query_pools.head(),
_last_results.query_id_end());
cb.writeTimestamp(
vk::PipelineStageFlagBits::eAllCommands, *_query_pools.head(), _last_results.query_id_end());
_query_used[_last_results.query_id_end()] = true;
_query_used[_last_results.query_id_end()] = true;
_current_stack.pop_back();
INVARIANT(_current_stack.empty(), "Unbalanced calls to Profiler::push!");
_current_stack.pop_back();
INVARIANT(_current_stack.empty(), "Unbalanced calls to Profiler::push!");
// request timestamps for all unused queryIds
for(auto i = 0u; i < _next_query_id; i++) {
if(!_query_used[i]) {
WARN("Unclosed Timestamp-Query!");
cb.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *_query_pools.head(), i);
// request timestamps for all unused queryIds
for(auto i = 0u; i < _next_query_id; i++) {
if(!_query_used[i]) {
cb.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *_query_pools.head(), i);
}
}
}
......@@ -145,8 +175,9 @@ namespace mirrage::graphic {
return true;
});
bool success = _query_pools.advance_head();
INVARIANT(success, "Too many frames in flight!");
if(_active || _full) {
_full = !_query_pools.advance_head();
}
_current_command_buffer = util::nothing;
}
......@@ -163,7 +194,7 @@ namespace mirrage::graphic {
}
auto Profiler::push(const std::string& name, vk::PipelineStageFlagBits stage) -> Push_raii {
if(!_active)
if(!_active || _full)
return {};
INVARIANT(!_current_stack.empty(), "Profiler::push called without calling start first!");
......
......@@ -149,6 +149,7 @@ namespace mirrage::renderer {
std::vector<Deferred_renderer*> _renderer_instances;
bool _recreation_pending = false;
void _present();
auto _rank_device(vk::PhysicalDevice, util::maybe<std::uint32_t> gqueue) -> int;
auto _init_device(vk::PhysicalDevice, util::maybe<std::uint32_t> gqueue)
-> graphic::Device_create_info;
......@@ -234,7 +235,5 @@ namespace mirrage::renderer {
void _write_global_uniform_descriptor_set();
void _update_global_uniforms(vk::CommandBuffer, const Camera_state& camera);
auto operator=(Deferred_renderer &&) -> Deferred_renderer& = default;
};
}
......@@ -83,8 +83,6 @@ namespace mirrage::renderer {
*this, *_entity_manager, _meta_system, write_first_pp_buffer);
}
_write_global_uniform_descriptor_set();
device().wait_idle();
}
......@@ -249,6 +247,17 @@ namespace mirrage::renderer {
}
void Deferred_renderer_factory::finish_frame() {
_present();
if(_recreation_pending) {
_recreation_pending = false;
for(auto& inst : _renderer_instances) {
inst->recreate();
}
}
}
void Deferred_renderer_factory::_present() {
if(_aquired_swapchain_image.is_nothing())
return; // nothing drawn, nothing to do
......@@ -288,14 +297,6 @@ namespace mirrage::renderer {
_swapchain.present(_queue, _aquired_swapchain_image.get_or_throw(), *_image_presented);
_aquired_swapchain_image = util::nothing;
_window.on_present();
if(_recreation_pending) {
_recreation_pending = false;
for(auto& inst : _renderer_instances) {
inst->recreate();
}
}
}
auto Deferred_renderer_factory::_rank_device(vk::PhysicalDevice gpu, util::maybe<std::uint32_t> gqueue)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment