From e94d178219d3c3b8b441206e57730aab20fbf8d1 Mon Sep 17 00:00:00 2001 From: Egor Orachyov Date: Fri, 11 Oct 2024 00:50:29 +0300 Subject: [PATCH] gh-76: support gpu profiling time events --- engine/plugins/assimp/assimp_asset_loader.cpp | 4 +- engine/plugins/assimp/assimp_importer.cpp | 8 +- .../freetype/freetype_asset_loader.cpp | 4 +- engine/plugins/freetype/freetype_font.cpp | 4 +- .../runtime/asset/default_asset_loader.cpp | 4 +- .../runtime/asset/image_asset_loader.cpp | 4 +- .../runtime/asset/shader_asset_loader.cpp | 4 +- .../runtime/asset/texture_asset_loader.cpp | 6 +- .../runtime/asset/wav_asset_loader.cpp | 4 +- engine/runtime/asset/asset_library_fs.cpp | 10 +- engine/runtime/asset/asset_manager.cpp | 12 +- engine/runtime/audio/audio_stream_wav.cpp | 4 +- engine/runtime/audio/openal/al_bus.cpp | 8 +- engine/runtime/audio/openal/al_engine.cpp | 18 +- engine/runtime/audio/openal/al_playback.cpp | 4 +- engine/runtime/core/async.cpp | 6 +- engine/runtime/core/callback_queue.cpp | 6 +- engine/runtime/core/callback_stream.cpp | 6 +- engine/runtime/core/task.cpp | 4 +- engine/runtime/core/task_manager.cpp | 10 +- engine/runtime/core/task_parallel_for.cpp | 4 +- engine/runtime/core/task_runtime.cpp | 12 +- engine/runtime/ecs/ecs_memory.cpp | 14 +- engine/runtime/ecs/ecs_world.cpp | 22 +- engine/runtime/engine.hpp | 3 +- engine/runtime/gfx/gfx_driver.hpp | 11 +- engine/runtime/gfx/vulkan/vk_cmd_list.cpp | 74 +++---- engine/runtime/gfx/vulkan/vk_cmd_manager.cpp | 8 +- engine/runtime/gfx/vulkan/vk_defs.cpp | 26 ++- engine/runtime/gfx/vulkan/vk_defs.hpp | 12 +- engine/runtime/gfx/vulkan/vk_desc_manager.cpp | 2 +- engine/runtime/gfx/vulkan/vk_desc_set.cpp | 4 +- engine/runtime/gfx/vulkan/vk_driver.cpp | 134 +++++++----- engine/runtime/gfx/vulkan/vk_driver.hpp | 4 +- engine/runtime/gfx/vulkan/vk_pipeline.cpp | 10 +- engine/runtime/gfx/vulkan/vk_render_pass.cpp | 6 +- engine/runtime/gfx/vulkan/vk_shader.cpp | 8 +- engine/runtime/gfx/vulkan/vk_texture.cpp | 26 +-- engine/runtime/gfx/vulkan/vk_window.cpp | 22 +- engine/runtime/glsl/glsl_shader_compiler.cpp | 12 +- engine/runtime/grc/font.cpp | 2 +- engine/runtime/grc/image.cpp | 14 +- engine/runtime/grc/pso_cache.cpp | 6 +- engine/runtime/grc/shader.cpp | 14 +- engine/runtime/grc/shader_cache.cpp | 8 +- engine/runtime/grc/shader_library.cpp | 14 +- engine/runtime/grc/shader_manager.cpp | 18 +- engine/runtime/grc/texture.cpp | 17 +- engine/runtime/grc/texture_manager.cpp | 19 +- engine/runtime/grc/texture_resize.cpp | 4 +- engine/runtime/io/async_file_system.cpp | 4 +- engine/runtime/io/compression.cpp | 8 +- engine/runtime/io/serialization.hpp | 2 +- engine/runtime/io/stream_file.cpp | 6 +- engine/runtime/io/tree_yaml.cpp | 4 +- engine/runtime/mesh/array_mesh.cpp | 2 +- engine/runtime/mesh/mesh.cpp | 2 +- engine/runtime/mesh/mesh_batch.cpp | 2 +- engine/runtime/mesh/mesh_builder.cpp | 4 +- engine/runtime/mesh/mesh_manager.cpp | 2 +- engine/runtime/mesh/mesh_processors.cpp | 4 +- engine/runtime/pfx/pfx_component_runtime.cpp | 6 +- engine/runtime/pfx/pfx_effect.cpp | 2 +- engine/runtime/pfx/pfx_emitter.cpp | 4 +- engine/runtime/pfx/pfx_scene.cpp | 4 +- engine/runtime/platform/file_system.cpp | 20 +- engine/runtime/platform/glfw/glfw_input.cpp | 20 +- engine/runtime/platform/glfw/glfw_window.cpp | 8 +- .../platform/glfw/glfw_window_manager.cpp | 14 +- engine/runtime/profiler/profiler.cpp | 206 ------------------ engine/runtime/profiler/profiler.hpp | 203 ----------------- engine/runtime/profiler/profiler_capture.cpp | 163 ++++++++++++++ engine/runtime/profiler/profiler_capture.hpp | 60 +++++ engine/runtime/profiler/profiler_cpu.cpp | 94 ++++++++ engine/runtime/profiler/profiler_cpu.hpp | 128 +++++++++++ engine/runtime/profiler/profiler_gpu.cpp | 150 +++++++++++++ engine/runtime/profiler/profiler_gpu.hpp | 138 ++++++++++++ engine/runtime/rdg/rdg_graph.cpp | 2 +- engine/runtime/render/aux_draw_manager.cpp | 20 +- engine/runtime/render/canvas.cpp | 8 +- engine/runtime/render/culling.cpp | 4 +- engine/runtime/render/deferred_pipeline.cpp | 8 +- engine/runtime/render/graphics_pipeline.cpp | 2 +- engine/runtime/render/model.cpp | 2 +- engine/runtime/render/render_engine.cpp | 24 +- engine/runtime/render/render_queue.cpp | 6 +- engine/runtime/render/render_scene.cpp | 4 +- engine/runtime/rtti/struct.cpp | 10 +- engine/runtime/scene/scene.cpp | 8 +- engine/runtime/scene/scene_data.cpp | 2 +- engine/runtime/scene/scene_manager.cpp | 32 +-- engine/runtime/scene/scene_packed.cpp | 2 +- engine/runtime/scene/scene_prefab.cpp | 2 +- engine/runtime/system/application.cpp | 11 +- engine/runtime/system/config_file.cpp | 8 +- engine/runtime/system/console.cpp | 8 +- engine/runtime/system/engine.cpp | 18 +- engine/runtime/system/engine.hpp | 3 +- engine/runtime/system/hooks.cpp | 34 ++- template/assets/textures/skybox.asset | 1 - template/main.cpp | 20 +- 101 files changed, 1273 insertions(+), 886 deletions(-) delete mode 100644 engine/runtime/profiler/profiler.cpp delete mode 100644 engine/runtime/profiler/profiler.hpp create mode 100644 engine/runtime/profiler/profiler_capture.cpp create mode 100644 engine/runtime/profiler/profiler_capture.hpp create mode 100644 engine/runtime/profiler/profiler_cpu.cpp create mode 100644 engine/runtime/profiler/profiler_cpu.hpp create mode 100644 engine/runtime/profiler/profiler_gpu.cpp create mode 100644 engine/runtime/profiler/profiler_gpu.hpp diff --git a/engine/plugins/assimp/assimp_asset_loader.cpp b/engine/plugins/assimp/assimp_asset_loader.cpp index 75f9e273b..838d25f31 100644 --- a/engine/plugins/assimp/assimp_asset_loader.cpp +++ b/engine/plugins/assimp/assimp_asset_loader.cpp @@ -36,7 +36,7 @@ #include "mesh/mesh_builder.hpp" #include "mesh/mesh_manager.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -59,7 +59,7 @@ namespace wmoge { } Status AssimpMeshAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("AssimpMeshAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("AssimpMeshAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); diff --git a/engine/plugins/assimp/assimp_importer.cpp b/engine/plugins/assimp/assimp_importer.cpp index c328b8abc..ecd915b70 100644 --- a/engine/plugins/assimp/assimp_importer.cpp +++ b/engine/plugins/assimp/assimp_importer.cpp @@ -30,7 +30,7 @@ #include "core/data.hpp" #include "core/log.hpp" #include "math/math_utils3d.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -39,7 +39,7 @@ namespace wmoge { Status AssimpImporter::read(std::string file_name, array_view data, const AssimpProcess& flags) { - WG_AUTO_PROFILE_ASSET("AssimpImporter::read"); + WG_PROFILE_CPU_ASSET("AssimpImporter::read"); if (flags.triangulate) m_options |= aiProcess_Triangulate; if (flags.tangent_space) m_options |= aiProcess_CalcTangentSpace; @@ -75,7 +75,7 @@ namespace wmoge { } Status AssimpImporter::process_node(aiNode* node, const Mat4x4f& parent_transform, const Mat4x4f& inv_parent_transform, std::optional parent) { - WG_AUTO_PROFILE_ASSET("AssimpImporter::process_node"); + WG_PROFILE_CPU_ASSET("AssimpImporter::process_node"); Mat4x4f local_transform; Mat4x4f inv_local_transform; @@ -115,7 +115,7 @@ namespace wmoge { } Status AssimpMeshImporter::process_mesh(aiMesh* mesh, const Mat4x4f& transform, const Mat4x4f& inv_transform, std::optional parent) { - WG_AUTO_PROFILE_ASSET("AssimpMeshImporter::process_mesh"); + WG_PROFILE_CPU_ASSET("AssimpMeshImporter::process_mesh"); const Vec3f aabb_min = Vec3f(mesh->mAABB.mMin.x, mesh->mAABB.mMin.y, mesh->mAABB.mMin.z); const Vec3f aabb_max = Vec3f(mesh->mAABB.mMax.x, mesh->mAABB.mMax.y, mesh->mAABB.mMax.z); diff --git a/engine/plugins/freetype/freetype_asset_loader.cpp b/engine/plugins/freetype/freetype_asset_loader.cpp index 3811eab5e..128c1c2f4 100644 --- a/engine/plugins/freetype/freetype_asset_loader.cpp +++ b/engine/plugins/freetype/freetype_asset_loader.cpp @@ -30,7 +30,7 @@ #include "core/ioc_container.hpp" #include "freetype_font.hpp" #include "freetype_import_data.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -49,7 +49,7 @@ namespace wmoge { } Status FreetypeAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("FreetypeAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("FreetypeAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); diff --git a/engine/plugins/freetype/freetype_font.cpp b/engine/plugins/freetype/freetype_font.cpp index 283497436..bf65a93c0 100644 --- a/engine/plugins/freetype/freetype_font.cpp +++ b/engine/plugins/freetype/freetype_font.cpp @@ -32,7 +32,7 @@ #include "grc/image.hpp" #include "grc/texture.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -45,7 +45,7 @@ namespace wmoge { } Status FreetypeFont::load(const Ref& font, array_view ttf_data, int height, int glyphs_in_row) { - WG_AUTO_PROFILE_ASSET("FreetypeFont::load"); + WG_PROFILE_CPU_ASSET("FreetypeFont::load"); static const int GLYPHS_SIZE_SHIFT = 6; static const int GLYPHS_BITMAP_OFFSET = 2; diff --git a/engine/plugins/runtime/asset/default_asset_loader.cpp b/engine/plugins/runtime/asset/default_asset_loader.cpp index 17f44ee2b..3a0f47bcb 100644 --- a/engine/plugins/runtime/asset/default_asset_loader.cpp +++ b/engine/plugins/runtime/asset/default_asset_loader.cpp @@ -30,7 +30,7 @@ #include "core/ioc_container.hpp" #include "io/tree_yaml.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "rtti/type_storage.hpp" namespace wmoge { @@ -50,7 +50,7 @@ namespace wmoge { } Status DefaultAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("DefaultAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("DefaultAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); diff --git a/engine/plugins/runtime/asset/image_asset_loader.cpp b/engine/plugins/runtime/asset/image_asset_loader.cpp index b07a24224..3bbb4759d 100644 --- a/engine/plugins/runtime/asset/image_asset_loader.cpp +++ b/engine/plugins/runtime/asset/image_asset_loader.cpp @@ -28,7 +28,7 @@ #include "image_asset_loader.hpp" #include "image_import_data.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -47,7 +47,7 @@ namespace wmoge { } Status ImageAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("ImageAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("ImageAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); diff --git a/engine/plugins/runtime/asset/shader_asset_loader.cpp b/engine/plugins/runtime/asset/shader_asset_loader.cpp index de9c3e6ae..82635f8fb 100644 --- a/engine/plugins/runtime/asset/shader_asset_loader.cpp +++ b/engine/plugins/runtime/asset/shader_asset_loader.cpp @@ -32,7 +32,7 @@ #include "grc/shader_file.hpp" #include "grc/shader_manager.hpp" #include "io/tree_yaml.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -51,7 +51,7 @@ namespace wmoge { } Status ShaderAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("ShaderAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("ShaderAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); diff --git a/engine/plugins/runtime/asset/texture_asset_loader.cpp b/engine/plugins/runtime/asset/texture_asset_loader.cpp index bd4a39f00..90069590c 100644 --- a/engine/plugins/runtime/asset/texture_asset_loader.cpp +++ b/engine/plugins/runtime/asset/texture_asset_loader.cpp @@ -35,7 +35,7 @@ #include "grc/texture.hpp" #include "grc/texture_manager.hpp" #include "grc/texture_resize.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -54,7 +54,7 @@ namespace wmoge { } Status Texture2dAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("Texture2dAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("Texture2dAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); @@ -140,7 +140,7 @@ namespace wmoge { } Status TextureCubeAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("TextureCubeAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("TextureCubeAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); diff --git a/engine/plugins/runtime/asset/wav_asset_loader.cpp b/engine/plugins/runtime/asset/wav_asset_loader.cpp index 3f34cdad6..898003e72 100644 --- a/engine/plugins/runtime/asset/wav_asset_loader.cpp +++ b/engine/plugins/runtime/asset/wav_asset_loader.cpp @@ -28,7 +28,7 @@ #include "wav_asset_loader.hpp" #include "asset/wav_import_data.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -47,7 +47,7 @@ namespace wmoge { } Status WavAssetLoader::load_typed(AssetLoadContext& context, const AssetId& asset_id, const AssetLoadResult& result, Ref& asset) { - WG_AUTO_PROFILE_ASSET("WavAssetLoader::load_typed"); + WG_PROFILE_CPU_ASSET("WavAssetLoader::load_typed"); Ref import_data = context.asset_meta.import_data.cast(); assert(import_data); diff --git a/engine/runtime/asset/asset_library_fs.cpp b/engine/runtime/asset/asset_library_fs.cpp index 320339260..f95dab161 100644 --- a/engine/runtime/asset/asset_library_fs.cpp +++ b/engine/runtime/asset/asset_library_fs.cpp @@ -34,7 +34,7 @@ #include "io/tree.hpp" #include "io/tree_yaml.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "rtti/type_storage.hpp" namespace wmoge { @@ -55,12 +55,12 @@ namespace wmoge { } bool AssetLibraryFileSystem::has_asset(const AssetId& name) { - WG_AUTO_PROFILE_ASSET("AssetLibraryFileSystem::has_asset"); + WG_PROFILE_CPU_ASSET("AssetLibraryFileSystem::has_asset"); return m_file_system->exists(make_asset_meta_path(m_directory, name, m_asset_ext)); } Status AssetLibraryFileSystem::find_asset_meta(const AssetId& name, AssetMeta& meta) { - WG_AUTO_PROFILE_ASSET("AssetLibraryFileSystem::find_asset_meta"); + WG_PROFILE_CPU_ASSET("AssetLibraryFileSystem::find_asset_meta"); IoContext context; context.add(m_file_system); @@ -78,7 +78,7 @@ namespace wmoge { } Status AssetLibraryFileSystem::find_asset_data_meta(const Strid& name, AssetDataMeta& meta) { - WG_AUTO_PROFILE_ASSET("AssetLibraryFileSystem::find_asset_data_meta"); + WG_PROFILE_CPU_ASSET("AssetLibraryFileSystem::find_asset_data_meta"); WG_CHECKED(m_file_system->get_file_size(make_asset_data_path(m_directory, name), meta.size)); meta.size_compressed = 0; @@ -89,7 +89,7 @@ namespace wmoge { } Async AssetLibraryFileSystem::read_data(const Strid& name, array_view data) { - WG_AUTO_PROFILE_ASSET("AssetLibraryFileSystem::read_data"); + WG_PROFILE_CPU_ASSET("AssetLibraryFileSystem::read_data"); return m_async_file_system->read_file(make_asset_data_path(m_directory, name), data).as_async(); } diff --git a/engine/runtime/asset/asset_manager.cpp b/engine/runtime/asset/asset_manager.cpp index dc8c3bff0..cf17d192d 100644 --- a/engine/runtime/asset/asset_manager.cpp +++ b/engine/runtime/asset/asset_manager.cpp @@ -31,7 +31,7 @@ #include "core/ioc_container.hpp" #include "core/timer.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "rtti/type_storage.hpp" #include @@ -55,7 +55,7 @@ namespace wmoge { } AsyncResult> AssetManager::load_async(const AssetId& name) { - WG_AUTO_PROFILE_ASSET("AssetManager::load_async"); + WG_PROFILE_CPU_ASSET("AssetManager::load_async"); std::lock_guard guard(m_mutex); @@ -177,7 +177,7 @@ namespace wmoge { } Ref AssetManager::load(const AssetId& name) { - WG_AUTO_PROFILE_ASSET("AssetManager::load"); + WG_PROFILE_CPU_ASSET("AssetManager::load"); Ref fast_look_up = find(name); if (fast_look_up) { @@ -190,7 +190,7 @@ namespace wmoge { } Ref AssetManager::find(const AssetId& name) { - WG_AUTO_PROFILE_ASSET("AssetManager::find"); + WG_PROFILE_CPU_ASSET("AssetManager::find"); std::lock_guard guard(m_mutex); @@ -237,14 +237,14 @@ namespace wmoge { } void AssetManager::clear() { - WG_AUTO_PROFILE_ASSET("AssetManager::clear"); + WG_PROFILE_CPU_ASSET("AssetManager::clear"); std::lock_guard guard(m_mutex); m_assets.clear(); } void AssetManager::load_loaders() { - WG_AUTO_PROFILE_ASSET("AssetManager::load_loaders"); + WG_PROFILE_CPU_ASSET("AssetManager::load_loaders"); std::vector loaders = m_type_storage->find_classes([](const Ref& type) { return type->is_subtype_of(AssetLoader::get_class_static()) && type->can_instantiate(); diff --git a/engine/runtime/audio/audio_stream_wav.cpp b/engine/runtime/audio/audio_stream_wav.cpp index b44e9ec5a..1af22d52d 100644 --- a/engine/runtime/audio/audio_stream_wav.cpp +++ b/engine/runtime/audio/audio_stream_wav.cpp @@ -27,7 +27,7 @@ #include "audio_stream_wav.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -36,7 +36,7 @@ namespace wmoge { Status AudioStreamWav::load(array_view file_data) { - WG_AUTO_PROFILE_ASSET("AudioStreamWav::load"); + WG_PROFILE_CPU_ASSET("AudioStreamWav::load"); std::vector data; data.resize(file_data.size()); diff --git a/engine/runtime/audio/openal/al_bus.cpp b/engine/runtime/audio/openal/al_bus.cpp index b00c74df0..2dbe85211 100644 --- a/engine/runtime/audio/openal/al_bus.cpp +++ b/engine/runtime/audio/openal/al_bus.cpp @@ -28,7 +28,7 @@ #include "al_bus.hpp" #include "audio/openal/al_engine.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -60,7 +60,7 @@ namespace wmoge { m_playbacks.erase(playback); } void ALAudioBus::make_active() { - WG_AUTO_PROFILE_OPENAL("ALAudioBus::make_active"); + WG_PROFILE_CPU_OPENAL("ALAudioBus::make_active"); std::lock_guard guard(m_engine.get_mutex()); @@ -72,7 +72,7 @@ namespace wmoge { } } void ALAudioBus::make_inactive() { - WG_AUTO_PROFILE_OPENAL("ALAudioBus::make_inactive"); + WG_PROFILE_CPU_OPENAL("ALAudioBus::make_inactive"); std::lock_guard guard(m_engine.get_mutex()); @@ -98,7 +98,7 @@ namespace wmoge { } } void ALAudioBus::get_playbacks(std::vector>& playbacks) { - WG_AUTO_PROFILE_OPENAL("ALAudioBus::get_playbacks"); + WG_PROFILE_CPU_OPENAL("ALAudioBus::get_playbacks"); std::lock_guard guard(m_engine.get_mutex()); diff --git a/engine/runtime/audio/openal/al_engine.cpp b/engine/runtime/audio/openal/al_engine.cpp index fa9488bad..20a781644 100644 --- a/engine/runtime/audio/openal/al_engine.cpp +++ b/engine/runtime/audio/openal/al_engine.cpp @@ -27,12 +27,12 @@ #include "al_engine.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { ALAudioEngine::ALAudioEngine() { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::ALAudioEngine"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::ALAudioEngine"); init_device(); init_context(); @@ -53,10 +53,10 @@ namespace wmoge { } void ALAudioEngine::update() { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::update"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::update"); } void ALAudioEngine::shutdown() { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::shutdown"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::shutdown"); if (m_device) { m_bus.clear(); @@ -73,7 +73,7 @@ namespace wmoge { } Ref ALAudioEngine::make_playback(Ref stream, const Strid& bus, const Strid& name) { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::make_playback"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::make_playback"); std::lock_guard guard(m_mutex); @@ -93,7 +93,7 @@ namespace wmoge { return make_ref(std::move(stream), bus, name, *this); } Ref ALAudioEngine::make_bus(const Strid& name) { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::make_bus"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::make_bus"); std::lock_guard guard(m_mutex); @@ -137,7 +137,7 @@ namespace wmoge { } bool ALAudioEngine::init_device() { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::init_device"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::init_device"); m_device = alcOpenDevice(nullptr); if (!m_device) { @@ -150,7 +150,7 @@ namespace wmoge { return true; } bool ALAudioEngine::init_context() { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::init_context"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::init_context"); WG_ALC_CHECK(m_context = alcCreateContext(m_device, nullptr)); if (!m_context) { @@ -169,7 +169,7 @@ namespace wmoge { return true; } bool ALAudioEngine::init_caps() { - WG_AUTO_PROFILE_OPENAL("ALAudioEngine::init_caps"); + WG_PROFILE_CPU_OPENAL("ALAudioEngine::init_caps"); auto str_or_null = [](const ALCchar* str) { return str ? str : ""; }; diff --git a/engine/runtime/audio/openal/al_playback.cpp b/engine/runtime/audio/openal/al_playback.cpp index 28ecbfc90..ed7212b02 100644 --- a/engine/runtime/audio/openal/al_playback.cpp +++ b/engine/runtime/audio/openal/al_playback.cpp @@ -28,7 +28,7 @@ #include "al_playback.hpp" #include "audio/openal/al_engine.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -37,7 +37,7 @@ namespace wmoge { ALAudioPlayback::ALAudioPlayback(Ref stream, Strid bus, const Strid& name, class ALAudioEngine& engine) : m_engine(engine) { - WG_AUTO_PROFILE_OPENAL("ALAudioPlayback::ALAudioPlayback"); + WG_PROFILE_CPU_OPENAL("ALAudioPlayback::ALAudioPlayback"); assert(stream); assert(!bus.empty()); diff --git a/engine/runtime/core/async.cpp b/engine/runtime/core/async.cpp index b4bb51942..8347bf4e2 100644 --- a/engine/runtime/core/async.cpp +++ b/engine/runtime/core/async.cpp @@ -28,12 +28,12 @@ #include "core/async.hpp" #include "async.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { Async Async::join(array_view dependencies) { - WG_AUTO_PROFILE_CORE("Async::join"); + WG_PROFILE_CPU_CORE("Async::join"); if (dependencies.empty()) { auto state = make_ref>(); @@ -48,7 +48,7 @@ namespace wmoge { } void notify(AsyncStatus status, AsyncStateBase* invoker) override { - WG_AUTO_PROFILE_CORE("AsyncStateJoin::notify"); + WG_PROFILE_CPU_CORE("AsyncStateJoin::notify"); assert(m_deps_to_wait > 0); diff --git a/engine/runtime/core/callback_queue.cpp b/engine/runtime/core/callback_queue.cpp index 6514da65d..09f6acc5c 100644 --- a/engine/runtime/core/callback_queue.cpp +++ b/engine/runtime/core/callback_queue.cpp @@ -27,12 +27,12 @@ #include "callback_queue.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { void CallbackQueue::flush() { - WG_AUTO_PROFILE_CORE("CallbackQueue::flush"); + WG_PROFILE_CPU_CORE("CallbackQueue::flush"); std::vector> to_flush; { @@ -46,7 +46,7 @@ namespace wmoge { } void CallbackQueue::clear() { - WG_AUTO_PROFILE_CORE("CallbackQueue::clear"); + WG_PROFILE_CPU_CORE("CallbackQueue::clear"); std::lock_guard guard(m_mutex); m_queue.clear(); diff --git a/engine/runtime/core/callback_stream.cpp b/engine/runtime/core/callback_stream.cpp index 95f8d8a54..6a687e32e 100644 --- a/engine/runtime/core/callback_stream.cpp +++ b/engine/runtime/core/callback_stream.cpp @@ -27,7 +27,7 @@ #include "callback_stream.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -57,7 +57,7 @@ namespace wmoge { } void CallbackStream::wait() { - WG_AUTO_PROFILE_CORE("CmdStream::wait"); + WG_PROFILE_CPU_CORE("CmdStream::wait"); std::atomic_bool marker{false}; @@ -69,7 +69,7 @@ namespace wmoge { } void CallbackStream::push_close() { - WG_AUTO_PROFILE_CORE("CmdStream::push_close"); + WG_PROFILE_CPU_CORE("CmdStream::push_close"); m_is_closed.store(true); } diff --git a/engine/runtime/core/task.cpp b/engine/runtime/core/task.cpp index 715a37e24..80e05853d 100644 --- a/engine/runtime/core/task.cpp +++ b/engine/runtime/core/task.cpp @@ -29,7 +29,7 @@ #include "core/ioc_container.hpp" #include "core/task_runtime.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -43,7 +43,7 @@ namespace wmoge { } TaskHnd Task::schedule(TaskManager* task_manager, Async depends_on) { - WG_AUTO_PROFILE_CORE("Task::schedule"); + WG_PROFILE_CPU_CORE("Task::schedule"); assert(m_runnable); assert(task_manager); diff --git a/engine/runtime/core/task_manager.cpp b/engine/runtime/core/task_manager.cpp index cc772c1ce..5af3010ec 100644 --- a/engine/runtime/core/task_manager.cpp +++ b/engine/runtime/core/task_manager.cpp @@ -29,7 +29,7 @@ #include "core/log.hpp" #include "core/task_runtime.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -38,8 +38,6 @@ namespace wmoge { m_worker_prefix = std::move(worker_prefix); - Profiler* profiler = Profiler::instance(); - for (int i = 0; i < workers_count; i++) { std::thread worker([this, i]() { TaskContext context; @@ -55,7 +53,7 @@ namespace wmoge { } }); - profiler->add_tid(worker.get_id(), SID(m_worker_prefix + "-" + std::to_string(i))); + ProfilerCpu::instance()->add_thread(m_worker_prefix + "-" + std::to_string(i), worker.get_id()); m_workers.push_back(std::move(worker)); } } @@ -65,7 +63,7 @@ namespace wmoge { } void TaskManager::submit(Ref task) { - WG_AUTO_PROFILE_CORE("TaskManager::submit"); + WG_PROFILE_CPU_CORE("TaskManager::submit"); assert(task); @@ -80,7 +78,7 @@ namespace wmoge { } void TaskManager::shutdown() { - WG_AUTO_PROFILE_CORE("TaskManager::shutdown"); + WG_PROFILE_CPU_CORE("TaskManager::shutdown"); WG_LOG_INFO("shutdown manager=" << m_worker_prefix << " and join already started tasks"); diff --git a/engine/runtime/core/task_parallel_for.cpp b/engine/runtime/core/task_parallel_for.cpp index e2005d8f8..de7aeeb3c 100644 --- a/engine/runtime/core/task_parallel_for.cpp +++ b/engine/runtime/core/task_parallel_for.cpp @@ -29,7 +29,7 @@ #include "core/ioc_container.hpp" #include "core/task_runtime.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -43,7 +43,7 @@ namespace wmoge { } TaskHnd TaskParallelFor::schedule(TaskManager* task_manager, int num_elements, int batch_size, Async depends_on) { - WG_AUTO_PROFILE_CORE("TaskParallelFor::schedule"); + WG_PROFILE_CPU_CORE("TaskParallelFor::schedule"); assert(m_runnable); assert(task_manager); diff --git a/engine/runtime/core/task_runtime.cpp b/engine/runtime/core/task_runtime.cpp index 914a2d2d2..2a28aafee 100644 --- a/engine/runtime/core/task_runtime.cpp +++ b/engine/runtime/core/task_runtime.cpp @@ -30,7 +30,7 @@ #include "core/log.hpp" #include "core/string_utils.hpp" #include "math/math_utils.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -57,17 +57,17 @@ namespace wmoge { } void TaskRuntime::wait_completed() { - WG_AUTO_PROFILE_TASK("TaskRuntime::wait_completed", m_name.str()); + WG_PROFILE_CPU_TASK("TaskRuntime::wait_completed", m_name.str()); AsyncState::wait_completed(); } void TaskRuntime::submit() { - WG_AUTO_PROFILE_TASK("TaskRuntime::submit", m_name.str()); + WG_PROFILE_CPU_TASK("TaskRuntime::submit", m_name.str()); m_task_manager->submit(Ref(this)); } void TaskRuntime::execute(TaskContext& context) { - WG_AUTO_PROFILE_TASK("TaskRuntime::execute", m_name.str()); + WG_PROFILE_CPU_TASK("TaskRuntime::execute", m_name.str()); auto ret = m_runnable(context); @@ -109,12 +109,12 @@ namespace wmoge { } void TaskRuntimeParallelFor::wait_completed() { - WG_AUTO_PROFILE_TASK("TaskRuntimeParallelFor::wait_completed", m_name.str()); + WG_PROFILE_CPU_TASK("TaskRuntimeParallelFor::wait_completed", m_name.str()); AsyncState::wait_completed(); } void TaskRuntimeParallelFor::submit() { - WG_AUTO_PROFILE_TASK("TaskRuntimeParallelFor::submit", m_name.str()); + WG_PROFILE_CPU_TASK("TaskRuntimeParallelFor::submit", m_name.str()); Ref shared_state(this); diff --git a/engine/runtime/ecs/ecs_memory.cpp b/engine/runtime/ecs/ecs_memory.cpp index 36804f030..53a8edb31 100644 --- a/engine/runtime/ecs/ecs_memory.cpp +++ b/engine/runtime/ecs/ecs_memory.cpp @@ -29,7 +29,7 @@ #include "core/ioc_container.hpp" #include "ecs/ecs_registry.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -46,7 +46,7 @@ namespace wmoge { } } void EcsPool::acquire_chunk() { - WG_AUTO_PROFILE_ECS("EcsPool::acquire_chunk"); + WG_PROFILE_CPU_ECS("EcsPool::acquire_chunk"); m_chunks.push_back(m_pool->allocate()); } void* EcsPool::get_element_raw(int idx) const { @@ -54,7 +54,7 @@ namespace wmoge { } EcsArchStorage::EcsArchStorage(EcsRegistry* ecs_registry, EcsArch arch) : m_arch(arch) { - WG_AUTO_PROFILE_ECS("EcsArchStorage::EcsArchStorage"); + WG_PROFILE_CPU_ECS("EcsArchStorage::EcsArchStorage"); m_chunk_size = ecs_registry->get_chunk_size(); m_pool.back() = EcsPool(sizeof(EcsEntity), m_chunk_size, &ecs_registry->get_entity_pool()); @@ -67,12 +67,12 @@ namespace wmoge { } EcsArchStorage::~EcsArchStorage() { - WG_AUTO_PROFILE_ECS("EcsArchStorage::~EcsArchStorage"); + WG_PROFILE_CPU_ECS("EcsArchStorage::~EcsArchStorage"); clear(); } void EcsArchStorage::make_entity(const EcsEntity& entity, std::uint32_t& out_entity_idx) { - WG_AUTO_PROFILE_ECS("EcsArchStorage::make_entity"); + WG_PROFILE_CPU_ECS("EcsArchStorage::make_entity"); assert(entity.is_valid()); @@ -97,7 +97,7 @@ namespace wmoge { m_size += 1; } void EcsArchStorage::destroy_entity(const std::uint32_t& in_entity_idx, bool& was_swapped) { - WG_AUTO_PROFILE_ECS("EcsArchStorage::destroy_entity"); + WG_PROFILE_CPU_ECS("EcsArchStorage::destroy_entity"); assert(int(in_entity_idx) < m_size); assert(m_size > 0); @@ -130,7 +130,7 @@ namespace wmoge { } void EcsArchStorage::clear() { - WG_AUTO_PROFILE_ECS("EcsArchStorage::clear"); + WG_PROFILE_CPU_ECS("EcsArchStorage::clear"); for (int entity_idx = 0; entity_idx < m_size; entity_idx++) { *m_pool.back().get_element(entity_idx) = EcsEntity(); diff --git a/engine/runtime/ecs/ecs_world.cpp b/engine/runtime/ecs/ecs_world.cpp index 9f4795262..520baca3f 100644 --- a/engine/runtime/ecs/ecs_world.cpp +++ b/engine/runtime/ecs/ecs_world.cpp @@ -31,7 +31,7 @@ #include "core/task.hpp" #include "core/task_parallel_for.hpp" #include "math/math_utils.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -45,7 +45,7 @@ namespace wmoge { } EcsEntity EcsWorld::allocate_entity() { - WG_AUTO_PROFILE_ECS("EcsWorld::allocate_entity"); + WG_PROFILE_CPU_ECS("EcsWorld::allocate_entity"); std::lock_guard guard(m_mutex); @@ -62,7 +62,7 @@ namespace wmoge { } void EcsWorld::make_entity(const EcsEntity& entity, const EcsArch& arch) { - WG_AUTO_PROFILE_ECS("EcsWorld::make_entity"); + WG_PROFILE_CPU_ECS("EcsWorld::make_entity"); assert(entity.is_valid()); @@ -82,7 +82,7 @@ namespace wmoge { } void EcsWorld::swap_entity(const EcsEntity& left, const EcsEntity& right) { - WG_AUTO_PROFILE_ECS("EcsWorld::swap_entity"); + WG_PROFILE_CPU_ECS("EcsWorld::swap_entity"); assert(left.is_valid()); assert(left.idx < m_entity_info.size()); @@ -105,7 +105,7 @@ namespace wmoge { } void EcsWorld::rearch_entity(const EcsEntity& entity, const EcsArch& new_arch) { - WG_AUTO_PROFILE_ECS("EcsWorld::rearch_entity"); + WG_PROFILE_CPU_ECS("EcsWorld::rearch_entity"); assert(new_arch.any()); assert(entity.is_valid()); @@ -130,7 +130,7 @@ namespace wmoge { } void EcsWorld::destroy_entity(const EcsEntity& entity) { - WG_AUTO_PROFILE_ECS("EcsWorld::destroy_entity"); + WG_PROFILE_CPU_ECS("EcsWorld::destroy_entity"); assert(entity.is_valid()); assert(entity.idx < m_entity_info.size()); @@ -193,7 +193,7 @@ namespace wmoge { } void EcsWorld::execute(const EcsQuery& query, const EcsQueuryFunction& func) { - WG_AUTO_PROFILE_ECS("EcsWorld::execute"); + WG_PROFILE_CPU_ECS("EcsWorld::execute"); for (int arch_idx = 0; arch_idx < m_arch_storage.size(); arch_idx++) { if (!query.match(m_arch_by_idx[arch_idx])) { @@ -210,7 +210,7 @@ namespace wmoge { } Async EcsWorld::execute_async(Async depends_on, const EcsQuery& query, const EcsQueuryFunction& func) { - WG_AUTO_PROFILE_ECS("EcsWorld::execute_async"); + WG_PROFILE_CPU_ECS("EcsWorld::execute_async"); Task task(query.name, [query, func, this](TaskContext&) { for (int arch_idx = 0; arch_idx < m_arch_storage.size(); arch_idx++) { @@ -233,7 +233,7 @@ namespace wmoge { } Async EcsWorld::execute_parallel(Async depends_on, const EcsQuery& query, const EcsQueuryFunction& func) { - WG_AUTO_PROFILE_ECS("EcsWorld::execute_parallel"); + WG_PROFILE_CPU_ECS("EcsWorld::execute_parallel"); TaskParallelFor task(query.name, [query, func, this](TaskContext&, int batch_id, int batch_count) { for (int arch_idx = 0; arch_idx < m_arch_storage.size(); arch_idx++) { @@ -255,7 +255,7 @@ namespace wmoge { } void EcsWorld::clear() { - WG_AUTO_PROFILE_ECS("EcsWorld::clear"); + WG_PROFILE_CPU_ECS("EcsWorld::clear"); m_queue.clear(); @@ -279,7 +279,7 @@ namespace wmoge { } void EcsWorld::sync() { - WG_AUTO_PROFILE_ECS("EcsWorld::sync"); + WG_PROFILE_CPU_ECS("EcsWorld::sync"); m_queue.flush(); } diff --git a/engine/runtime/engine.hpp b/engine/runtime/engine.hpp index e44a8c9dd..2c9a9d5a3 100644 --- a/engine/runtime/engine.hpp +++ b/engine/runtime/engine.hpp @@ -177,7 +177,8 @@ #include "platform/window.hpp" #include "platform/window_manager.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" +#include "profiler/profiler_gpu.hpp" #include "rdg/rdg_graph.hpp" #include "rdg/rdg_pass.hpp" diff --git a/engine/runtime/gfx/gfx_driver.hpp b/engine/runtime/gfx/gfx_driver.hpp index 06c016347..fbd20210d 100644 --- a/engine/runtime/gfx/gfx_driver.hpp +++ b/engine/runtime/gfx/gfx_driver.hpp @@ -89,11 +89,12 @@ namespace wmoge { virtual Async make_psos_graphics(const Ref& request) = 0; virtual Async make_psos_compute(const Ref& request) = 0; - virtual void begin_frame(std::size_t frame_id, const array_view>& windows) = 0; - virtual GfxCmdListRef acquire_cmd_list(GfxQueueType queue_type = GfxQueueType::Graphics) = 0; - virtual void submit_cmd_list(const GfxCmdListRef& cmd_list) = 0; - virtual void query_results(const GfxQueryPoolRef& query_pool, int count, array_view buffer) = 0; - virtual void end_frame(bool swap_buffers = true) = 0; + virtual void begin_frame(std::size_t frame_id, const array_view>& windows) = 0; + virtual GfxCmdListRef acquire_cmd_list(GfxQueueType queue_type = GfxQueueType::Graphics) = 0; + virtual void submit_cmd_list(const GfxCmdListRef& cmd_list) = 0; + virtual void query_results(const GfxQueryPoolRef& query_pool, array_view buffer) = 0; + virtual void query_callibration(std::uint64_t& gpu_time, std::uint64_t& gpu_freq) = 0; + virtual void end_frame(bool swap_buffers = true) = 0; [[nodiscard]] virtual const GfxDeviceCaps& device_caps() const = 0; [[nodiscard]] virtual const Strid& driver_name() const = 0; diff --git a/engine/runtime/gfx/vulkan/vk_cmd_list.cpp b/engine/runtime/gfx/vulkan/vk_cmd_list.cpp index df69f214e..80709d9c8 100644 --- a/engine/runtime/gfx/vulkan/vk_cmd_list.cpp +++ b/engine/runtime/gfx/vulkan/vk_cmd_list.cpp @@ -30,7 +30,7 @@ #include "gfx/vulkan/vk_defs.hpp" #include "gfx/vulkan/vk_driver.hpp" #include "gfx/vulkan/vk_query.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -48,7 +48,7 @@ namespace wmoge { } void VKCmdList::update_vert_buffer(const Ref& buffer, int offset, int range, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::update_vert_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::update_vert_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -56,7 +56,7 @@ namespace wmoge { dynamic_cast(buffer.get())->update(m_cmd_buffer, offset, range, data); } void VKCmdList::update_index_buffer(const Ref& buffer, int offset, int range, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::update_index_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::update_index_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -64,7 +64,7 @@ namespace wmoge { dynamic_cast(buffer.get())->update(m_cmd_buffer, offset, range, data); } void VKCmdList::update_uniform_buffer(const Ref& buffer, int offset, int range, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::update_uniform_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::update_uniform_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -72,7 +72,7 @@ namespace wmoge { dynamic_cast(buffer.get())->update(m_cmd_buffer, offset, range, data); } void VKCmdList::update_storage_buffer(const Ref& buffer, int offset, int range, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::update_storage_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::update_storage_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -80,7 +80,7 @@ namespace wmoge { dynamic_cast(buffer.get())->update(m_cmd_buffer, offset, range, data); } void VKCmdList::update_texture_2d(const Ref& texture, int mip, Rect2i region, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::update_texture_2d"); + WG_PROFILE_CPU_VULKAN("VKCmdList::update_texture_2d"); assert(texture); assert(!m_in_render_pass); @@ -88,7 +88,7 @@ namespace wmoge { dynamic_cast(texture.get())->update_2d(m_cmd_buffer, mip, region, data); } void VKCmdList::update_texture_2d_array(const Ref& texture, int mip, int slice, Rect2i region, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::update_texture_2d_array"); + WG_PROFILE_CPU_VULKAN("VKCmdList::update_texture_2d_array"); assert(texture); assert(!m_in_render_pass); @@ -96,7 +96,7 @@ namespace wmoge { dynamic_cast(texture.get())->update_2d_array(m_cmd_buffer, mip, slice, region, data); } void VKCmdList::update_texture_cube(const Ref& texture, int mip, int face, Rect2i region, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::update_texture_cube"); + WG_PROFILE_CPU_VULKAN("VKCmdList::update_texture_cube"); assert(texture); assert(!m_in_render_pass); @@ -105,7 +105,7 @@ namespace wmoge { } void* VKCmdList::map_vert_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::map_vert_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::map_vert_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -113,7 +113,7 @@ namespace wmoge { return (dynamic_cast(buffer.get()))->map(); } void* VKCmdList::map_index_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::map_index_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::map_index_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -121,7 +121,7 @@ namespace wmoge { return (dynamic_cast(buffer.get()))->map(); } void* VKCmdList::map_uniform_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::map_uniform_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::map_uniform_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -129,7 +129,7 @@ namespace wmoge { return (dynamic_cast(buffer.get()))->map(); } void* VKCmdList::map_storage_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::map_storage_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::map_storage_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -137,7 +137,7 @@ namespace wmoge { return (dynamic_cast(buffer.get()))->map(); } void VKCmdList::unmap_vert_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::unmap_vert_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::unmap_vert_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -146,7 +146,7 @@ namespace wmoge { flush_barriers(); } void VKCmdList::unmap_index_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::unmap_index_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::unmap_index_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -155,7 +155,7 @@ namespace wmoge { flush_barriers(); } void VKCmdList::unmap_uniform_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::unmap_uniform_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::unmap_uniform_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -164,7 +164,7 @@ namespace wmoge { flush_barriers(); } void VKCmdList::unmap_storage_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::unmap_storage_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::unmap_storage_buffer"); assert(buffer); assert(!m_in_render_pass); @@ -174,38 +174,38 @@ namespace wmoge { } void VKCmdList::barrier_image(const Ref& texture, GfxTexBarrierType src, GfxTexBarrierType dst) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::barrier_image"); + WG_PROFILE_CPU_VULKAN("VKCmdList::barrier_image"); barrier(dynamic_cast(texture.get()), src, dst); flush_barriers(); } void VKCmdList::barrier_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::barrier_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::barrier_buffer"); barrier(dynamic_cast(buffer.get())); flush_barriers(); } void VKCmdList::barrier_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::barrier_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::barrier_buffer"); barrier(dynamic_cast(buffer.get())); flush_barriers(); } void VKCmdList::barrier_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::barrier_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::barrier_buffer"); barrier(dynamic_cast(buffer.get())); flush_barriers(); } void VKCmdList::barrier_buffer(const Ref& buffer) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::barrier_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::barrier_buffer"); barrier(dynamic_cast(buffer.get())); flush_barriers(); } void VKCmdList::barrier_images(array_view textures, GfxTexBarrierType src, GfxTexBarrierType dst) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::barrier_images"); + WG_PROFILE_CPU_VULKAN("VKCmdList::barrier_images"); for (GfxTexture* texture : textures) { barrier(dynamic_cast(texture), src, dst); @@ -214,7 +214,7 @@ namespace wmoge { } void VKCmdList::barrier_buffers(array_view buffers) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::barrier_buffers"); + WG_PROFILE_CPU_VULKAN("VKCmdList::barrier_buffers"); for (GfxBuffer* buffer : buffers) { barrier(dynamic_cast(buffer)); @@ -223,7 +223,7 @@ namespace wmoge { } void VKCmdList::begin_render_pass(const GfxRenderPassBeginInfo& pass_desc) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::begin_render_pass"); + WG_PROFILE_CPU_VULKAN("VKCmdList::begin_render_pass"); assert(!m_in_render_pass); @@ -268,14 +268,14 @@ namespace wmoge { vkCmdBeginRenderPass(m_cmd_buffer, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE); } void VKCmdList::peek_render_pass(GfxRenderPassRef& rp) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::peek_render_pass"); + WG_PROFILE_CPU_VULKAN("VKCmdList::peek_render_pass"); assert(m_in_render_pass); rp = m_current_pass; } void VKCmdList::viewport(const Rect2i& viewport) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::viewport"); + WG_PROFILE_CPU_VULKAN("VKCmdList::viewport"); assert(m_in_render_pass); @@ -298,7 +298,7 @@ namespace wmoge { vkCmdSetScissor(m_cmd_buffer, 0, 1, &vk_scissor); } void VKCmdList::bind_pso(const Ref& pipeline) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::bind_pso"); + WG_PROFILE_CPU_VULKAN("VKCmdList::bind_pso"); assert(m_in_render_pass); assert(pipeline); @@ -311,7 +311,7 @@ namespace wmoge { m_pipeline_bound_graphics = true; } void VKCmdList::bind_pso(const Ref& pipeline) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::bind_pso"); + WG_PROFILE_CPU_VULKAN("VKCmdList::bind_pso"); assert(!m_in_render_pass); assert(pipeline); @@ -324,7 +324,7 @@ namespace wmoge { m_pipeline_bound_compute = true; } void VKCmdList::bind_vert_buffer(const Ref& buffer, int index, int offset) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::bind_vert_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::bind_vert_buffer"); assert(m_pipeline_bound_graphics); assert(buffer); @@ -338,7 +338,7 @@ namespace wmoge { vkCmdBindVertexBuffers(m_cmd_buffer, index, 1, &vk_vert_buffer, &vk_vert_buffer_offset); } void VKCmdList::bind_index_buffer(const Ref& buffer, GfxIndexType index_type, int offset) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::bind_index_buffer"); + WG_PROFILE_CPU_VULKAN("VKCmdList::bind_index_buffer"); assert(m_pipeline_bound_graphics); assert(buffer); @@ -347,7 +347,7 @@ namespace wmoge { vkCmdBindIndexBuffer(m_cmd_buffer, m_current_index_buffer->buffer(), offset, VKDefs::get_index_type(index_type)); } void VKCmdList::bind_desc_set(const Ref& set, int index) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::bind_desc_set"); + WG_PROFILE_CPU_VULKAN("VKCmdList::bind_desc_set"); assert(m_pipeline_bound_graphics || m_pipeline_bound_compute); assert(set); @@ -365,7 +365,7 @@ namespace wmoge { vkCmdBindDescriptorSets(m_cmd_buffer, bind_point, m_current_pso_layout->layout(), index, 1, &m_desc_sets[index], 0, nullptr); } void VKCmdList::bind_desc_sets(const array_view& sets, int offset) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::bind_desc_sets"); + WG_PROFILE_CPU_VULKAN("VKCmdList::bind_desc_sets"); assert(m_pipeline_bound_graphics || m_pipeline_bound_compute); assert(!sets.empty()); @@ -389,28 +389,28 @@ namespace wmoge { vkCmdBindDescriptorSets(m_cmd_buffer, bind_point, m_current_pso_layout->layout(), offset, count, &m_desc_sets[offset], 0, nullptr); } void VKCmdList::draw(int vertex_count, int base_vertex, int instance_count) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::draw"); + WG_PROFILE_CPU_VULKAN("VKCmdList::draw"); assert(m_pipeline_bound_graphics); vkCmdDraw(m_cmd_buffer, vertex_count, instance_count, base_vertex, 0); } void VKCmdList::draw_indexed(int index_count, int base_vertex, int instance_count) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::draw_indexed"); + WG_PROFILE_CPU_VULKAN("VKCmdList::draw_indexed"); assert(m_pipeline_bound_graphics); vkCmdDrawIndexed(m_cmd_buffer, index_count, instance_count, 0, base_vertex, 0); } void VKCmdList::dispatch(Vec3i group_count) { - WG_AUTO_PROFILE_VULKAN("VKCmdList::dispatch"); + WG_PROFILE_CPU_VULKAN("VKCmdList::dispatch"); assert(m_pipeline_bound_compute); vkCmdDispatch(m_cmd_buffer, std::uint32_t(group_count.x()), std::uint32_t(group_count.y()), std::uint32_t(group_count.z())); } void VKCmdList::end_render_pass() { - WG_AUTO_PROFILE_VULKAN("VKCmdList::end_render_pass"); + WG_PROFILE_CPU_VULKAN("VKCmdList::end_render_pass"); assert(m_in_render_pass); @@ -562,7 +562,7 @@ namespace wmoge { } void VKCmdList::flush_barriers() { - WG_AUTO_PROFILE_VULKAN("VKCmdList::flush_barriers"); + WG_PROFILE_CPU_VULKAN("VKCmdList::flush_barriers"); if (m_barriers_buffer.empty() && m_barriers_image.empty()) { return; diff --git a/engine/runtime/gfx/vulkan/vk_cmd_manager.cpp b/engine/runtime/gfx/vulkan/vk_cmd_manager.cpp index efc3854d1..01cb32755 100644 --- a/engine/runtime/gfx/vulkan/vk_cmd_manager.cpp +++ b/engine/runtime/gfx/vulkan/vk_cmd_manager.cpp @@ -29,7 +29,7 @@ #include "gfx/vulkan/vk_driver.hpp" #include "gfx/vulkan/vk_queues.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -58,7 +58,7 @@ namespace wmoge { } void VKCmdManager::update(std::size_t frame_id) { - WG_AUTO_PROFILE_VULKAN("VKCmdManager::update"); + WG_PROFILE_CPU_VULKAN("VKCmdManager::update"); m_frame_id = frame_id; m_index = m_frame_id % GfxLimits::FRAMES_IN_FLIGHT; @@ -119,7 +119,7 @@ namespace wmoge { } void VKCmdManager::submit(GfxQueueType queue_type, VkCommandBuffer buffer, array_view wait, array_view signal, VkFence fence) { - WG_AUTO_PROFILE_VULKAN("VKCmdManager::submit"); + WG_PROFILE_CPU_VULKAN("VKCmdManager::submit"); assert(buffer); @@ -180,7 +180,7 @@ namespace wmoge { } void VKCmdManager::flush(array_view wait, array_view signal) { - WG_AUTO_PROFILE_VULKAN("VKCmdManager::flush"); + WG_PROFILE_CPU_VULKAN("VKCmdManager::flush"); buffered_vector wait_flags; diff --git a/engine/runtime/gfx/vulkan/vk_defs.cpp b/engine/runtime/gfx/vulkan/vk_defs.cpp index 104dd84a4..2c6f2bbe2 100644 --- a/engine/runtime/gfx/vulkan/vk_defs.cpp +++ b/engine/runtime/gfx/vulkan/vk_defs.cpp @@ -31,24 +31,30 @@ namespace wmoge { - PFN_vkCreateDebugUtilsMessengerEXT VKDebug::vkCreateDebugUtilsMessengerEXT = nullptr; - PFN_vkDestroyDebugUtilsMessengerEXT VKDebug::vkDestroyDebugUtilsMessengerEXT = nullptr; - PFN_vkSetDebugUtilsObjectNameEXT VKDebug::vkSetDebugUtilsObjectNameEXT = nullptr; - PFN_vkCmdBeginDebugUtilsLabelEXT VKDebug::vkCmdBeginDebugUtilsLabelEXT = nullptr; - PFN_vkCmdEndDebugUtilsLabelEXT VKDebug::vkCmdEndDebugUtilsLabelEXT = nullptr; + PFN_vkCreateDebugUtilsMessengerEXT VKDebug::vkCreateDebugUtilsMessengerEXT = nullptr; + PFN_vkDestroyDebugUtilsMessengerEXT VKDebug::vkDestroyDebugUtilsMessengerEXT = nullptr; + PFN_vkSetDebugUtilsObjectNameEXT VKDebug::vkSetDebugUtilsObjectNameEXT = nullptr; + PFN_vkCmdBeginDebugUtilsLabelEXT VKDebug::vkCmdBeginDebugUtilsLabelEXT = nullptr; + PFN_vkCmdEndDebugUtilsLabelEXT VKDebug::vkCmdEndDebugUtilsLabelEXT = nullptr; + PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT VKDebug::vkGetPhysicalDeviceCalibrateableTimeDomainsEXT = nullptr; + PFN_vkGetCalibratedTimestampsEXT VKDebug::vkGetCalibratedTimestampsEXT = nullptr; void VKDebug::load_inst_functions(VkInstance instance) { - vkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"); - vkDestroyDebugUtilsMessengerEXT = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"); - vkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT) vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT"); - vkCmdBeginDebugUtilsLabelEXT = (PFN_vkCmdBeginDebugUtilsLabelEXT) vkGetInstanceProcAddr(instance, "vkCmdBeginDebugUtilsLabelEXT"); - vkCmdEndDebugUtilsLabelEXT = (PFN_vkCmdEndDebugUtilsLabelEXT) vkGetInstanceProcAddr(instance, "vkCmdEndDebugUtilsLabelEXT"); + vkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"); + vkDestroyDebugUtilsMessengerEXT = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"); + vkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT) vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT"); + vkCmdBeginDebugUtilsLabelEXT = (PFN_vkCmdBeginDebugUtilsLabelEXT) vkGetInstanceProcAddr(instance, "vkCmdBeginDebugUtilsLabelEXT"); + vkCmdEndDebugUtilsLabelEXT = (PFN_vkCmdEndDebugUtilsLabelEXT) vkGetInstanceProcAddr(instance, "vkCmdEndDebugUtilsLabelEXT"); + vkGetPhysicalDeviceCalibrateableTimeDomainsEXT = (PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT) vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"); + vkGetCalibratedTimestampsEXT = (PFN_vkGetCalibratedTimestampsEXT) vkGetInstanceProcAddr(instance, "vkGetCalibratedTimestampsEXT"); assert(vkCreateDebugUtilsMessengerEXT); assert(vkDestroyDebugUtilsMessengerEXT); assert(vkSetDebugUtilsObjectNameEXT); assert(vkCmdBeginDebugUtilsLabelEXT); assert(vkCmdEndDebugUtilsLabelEXT); + assert(vkGetPhysicalDeviceCalibrateableTimeDomainsEXT); + assert(vkGetCalibratedTimestampsEXT); } void VKDebug::add_debug_name(VkDevice device, void* object, VkObjectType object_type, const char* name) { if (vkSetDebugUtilsObjectNameEXT) { diff --git a/engine/runtime/gfx/vulkan/vk_defs.hpp b/engine/runtime/gfx/vulkan/vk_defs.hpp index 41d04cd53..e4679529c 100644 --- a/engine/runtime/gfx/vulkan/vk_defs.hpp +++ b/engine/runtime/gfx/vulkan/vk_defs.hpp @@ -114,11 +114,13 @@ namespace wmoge { static void begin_label(VkCommandBuffer buffer, const Strid& name, const Vec3f& color = Vec3f(1, 1, 1)); static void end_label(VkCommandBuffer buffer); - static PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT; - static PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT; - static PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT; - static PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT; - static PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT; + static PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT; + static PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT; + static PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT; + static PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT; + static PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT; + static PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT vkGetPhysicalDeviceCalibrateableTimeDomainsEXT; + static PFN_vkGetCalibratedTimestampsEXT vkGetCalibratedTimestampsEXT; }; class VKDefs { diff --git a/engine/runtime/gfx/vulkan/vk_desc_manager.cpp b/engine/runtime/gfx/vulkan/vk_desc_manager.cpp index e2ed3a88f..8cf643a6b 100644 --- a/engine/runtime/gfx/vulkan/vk_desc_manager.cpp +++ b/engine/runtime/gfx/vulkan/vk_desc_manager.cpp @@ -28,7 +28,7 @@ #include "vk_desc_manager.hpp" #include "gfx/vulkan/vk_driver.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { diff --git a/engine/runtime/gfx/vulkan/vk_desc_set.cpp b/engine/runtime/gfx/vulkan/vk_desc_set.cpp index 1ac9ca1c5..c77164006 100644 --- a/engine/runtime/gfx/vulkan/vk_desc_set.cpp +++ b/engine/runtime/gfx/vulkan/vk_desc_set.cpp @@ -29,7 +29,7 @@ #include "gfx/vulkan/vk_desc_manager.hpp" #include "gfx/vulkan/vk_driver.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -98,7 +98,7 @@ namespace wmoge { } } void VKDescSet::update(const GfxDescSetResources& resources) { - WG_AUTO_PROFILE_VULKAN("VKDescSet::update"); + WG_PROFILE_CPU_VULKAN("VKDescSet::update"); std::array write_infos{}; std::array image_infos{}; diff --git a/engine/runtime/gfx/vulkan/vk_driver.cpp b/engine/runtime/gfx/vulkan/vk_driver.cpp index 57208a03d..f099a3734 100644 --- a/engine/runtime/gfx/vulkan/vk_driver.cpp +++ b/engine/runtime/gfx/vulkan/vk_driver.cpp @@ -40,7 +40,7 @@ #include "gfx/vulkan/vk_shader.hpp" #include "gfx/vulkan/vk_texture.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -54,7 +54,7 @@ namespace wmoge { }; VKDriver::VKDriver(const VKInitInfo& info) { - WG_AUTO_PROFILE_VULKAN("VKDriver::VKDriver"); + WG_PROFILE_CPU_VULKAN("VKDriver::VKDriver"); IocContainer* ioc = info.ioc; m_file_system = ioc->resolve_value(); @@ -92,12 +92,17 @@ namespace wmoge { WG_LOG_INFO("request " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } + if (m_use_timestamps) { + m_required_device_extensions.emplace_back(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME); + WG_LOG_INFO("request " << VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME); + + m_required_device_extensions.emplace_back(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME); + WG_LOG_INFO("request " << VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME); + } + m_required_device_extensions.emplace_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); WG_LOG_INFO("request " << VK_KHR_SWAPCHAIN_EXTENSION_NAME); - m_required_device_extensions.emplace_back(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME); - WG_LOG_INFO("request " << VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME); - m_pipeline_cache_path = "cache/pipelines_vk.cache"; // load vulkan functions from volk @@ -145,7 +150,7 @@ namespace wmoge { WG_LOG_INFO("init vulkan gfx driver"); } VKDriver::~VKDriver() { - WG_AUTO_PROFILE_VULKAN("VKDriver::~VKDriver"); + WG_PROFILE_CPU_VULKAN("VKDriver::~VKDriver"); shutdown(); @@ -153,7 +158,7 @@ namespace wmoge { } void VKDriver::shutdown() { - WG_AUTO_PROFILE_VULKAN("VKDriver::shutdown"); + WG_PROFILE_CPU_VULKAN("VKDriver::shutdown"); auto flush_release = [&]() { for (int i = 0; i < GfxLimits::FRAMES_IN_FLIGHT; i++) { @@ -204,53 +209,53 @@ namespace wmoge { } Ref VKDriver::make_query_pool(const GfxQueryPoolDesc& desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_query_pool"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_query_pool"); return make_ref(desc, name, *this); } Ref VKDriver::make_vert_format(const GfxVertElements& elements, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_vert_format"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_vert_format"); return make_ref(elements, name); } Ref VKDriver::make_vert_buffer(int size, GfxMemUsage usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_vert_buffer"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_vert_buffer"); auto buffer = make_ref(*this); buffer->create(size, usage, name); return buffer; } Ref VKDriver::make_index_buffer(int size, GfxMemUsage usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_index_buffer"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_index_buffer"); auto buffer = make_ref(*this); buffer->create(size, usage, name); return buffer; } Ref VKDriver::make_uniform_buffer(int size, GfxMemUsage usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_uniform_buffer"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_uniform_buffer"); auto buffer = make_ref(*this); buffer->create(size, usage, name); return buffer; } Ref VKDriver::make_storage_buffer(int size, GfxMemUsage usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_storage_buffer"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_storage_buffer"); auto buffer = make_ref(*this); buffer->create(size, usage, name); return buffer; } Ref VKDriver::make_shader(GfxShaderDesc desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_shader"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_shader"); auto shader = make_ref(name, *this); shader->create(std::move(desc)); return shader; } Ref VKDriver::make_program(GfxShaderProgramDesc desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_program"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_program"); auto program = make_ref(name, *this); program->create(std::move(desc)); @@ -258,7 +263,7 @@ namespace wmoge { } Ref VKDriver::make_texture(const GfxTextureDesc& desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_texture"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_texture"); auto texture = make_ref(*this); texture->create(desc, name); @@ -266,28 +271,28 @@ namespace wmoge { } Ref VKDriver::make_texture_2d(int width, int height, int mips, GfxFormat format, GfxTexUsages usages, GfxMemUsage mem_usage, GfxTexSwizz swizz, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_texture_2d"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_texture_2d"); auto texture = make_ref(*this); texture->create_2d(width, height, mips, format, usages, mem_usage, swizz, name); return texture; } Ref VKDriver::make_texture_2d_array(int width, int height, int mips, int slices, GfxFormat format, GfxTexUsages usages, GfxMemUsage mem_usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_texture_2d_array"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_texture_2d_array"); auto texture = make_ref(*this); texture->create_2d_array(width, height, mips, slices, format, usages, mem_usage, name); return texture; } Ref VKDriver::make_texture_cube(int width, int height, int mips, GfxFormat format, GfxTexUsages usages, GfxMemUsage mem_usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_texture_cube"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_texture_cube"); auto texture = make_ref(*this); texture->create_cube(width, height, mips, format, usages, mem_usage, name); return texture; } Ref VKDriver::make_sampler(const GfxSamplerDesc& desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_sampler"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_sampler"); auto& sampler = m_samplers[desc]; if (!sampler) { @@ -300,24 +305,24 @@ namespace wmoge { return sampler; } Ref VKDriver::make_pso_layout(const GfxDescSetLayouts& layouts, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_pso_layout"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_pso_layout"); return make_ref(layouts, name, *this); } Ref VKDriver::make_pso_graphics(const GfxPsoStateGraphics& state, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_pso_graphics"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_pso_graphics"); Ref pipeline = make_ref(name, *this); return pipeline->compile(state) ? pipeline : Ref(); } Ref VKDriver::make_pso_compute(const GfxPsoStateCompute& state, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_pso_compute"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_pso_compute"); Ref pipeline = make_ref(name, *this); return pipeline->compile(state) ? pipeline : Ref(); } Ref VKDriver::make_render_pass(const GfxRenderPassDesc& pass_desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_render_pass"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_render_pass"); auto& render_pass = m_render_passes[pass_desc]; if (!render_pass) { @@ -328,29 +333,29 @@ namespace wmoge { return render_pass; } Ref VKDriver::make_render_pass(const Ref& window, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_render_pass"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_render_pass"); return Ref(); } Ref VKDriver::make_frame_buffer(const GfxFrameBufferDesc& desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_frame_buffer"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_frame_buffer"); return make_ref(desc, name, *this); } Ref VKDriver::make_desc_layout(const GfxDescSetLayoutDesc& desc, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_desc_layout"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_desc_layout"); return make_ref(desc, name, *this); } Ref VKDriver::make_desc_set(const GfxDescSetResources& resources, const Ref& layout, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_desc_set"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_desc_set"); assert(layout); return make_ref(resources, layout.cast(), name, *this); } Async VKDriver::make_shaders(const Ref& request) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_shaders"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_shaders"); request->shaders.resize(request->desc.size()); @@ -364,7 +369,7 @@ namespace wmoge { return task.schedule(m_task_manager, int(request->desc.size()), 1).as_async(); } Async VKDriver::make_psos_graphics(const Ref& request) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_psos_graphics"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_psos_graphics"); request->pso.resize(request->states.size()); @@ -379,7 +384,7 @@ namespace wmoge { return task.schedule(m_task_manager, int(request->states.size()), 1).as_async(); } Async VKDriver::make_psos_compute(const Ref& request) { - WG_AUTO_PROFILE_VULKAN("VKDriver::make_psos_compute"); + WG_PROFILE_CPU_VULKAN("VKDriver::make_psos_compute"); request->pso.resize(request->states.size()); @@ -395,7 +400,7 @@ namespace wmoge { } void VKDriver::begin_frame(std::size_t frame_id, const array_view>& windows) { - WG_AUTO_PROFILE_VULKAN("VKDriver::begin_frame"); + WG_PROFILE_CPU_VULKAN("VKDriver::begin_frame"); m_frame_id = frame_id; m_index = m_frame_id % GfxLimits::FRAMES_IN_FLIGHT; @@ -421,13 +426,13 @@ namespace wmoge { } GfxCmdListRef VKDriver::acquire_cmd_list(GfxQueueType queue_type) { - WG_AUTO_PROFILE_VULKAN("VKDriver::acquire_cmd_list"); + WG_PROFILE_CPU_VULKAN("VKDriver::acquire_cmd_list"); return make_ref(m_cmd_manager->allocate(queue_type), queue_type, *this); } void VKDriver::submit_cmd_list(const GfxCmdListRef& cmd_list) { - WG_AUTO_PROFILE_VULKAN("VKDriver::submit_cmd_list"); + WG_PROFILE_CPU_VULKAN("VKDriver::submit_cmd_list"); assert(cmd_list); @@ -435,21 +440,48 @@ namespace wmoge { m_cmd_manager->submit(vk_cmd_list->get_queue_type(), vk_cmd_list->get_handle()); } - void VKDriver::query_results(const GfxQueryPoolRef& query_pool, int count, array_view buffer) { - WG_AUTO_PROFILE_VULKAN("VKDriver::query_results"); + void VKDriver::query_results(const GfxQueryPoolRef& query_pool, array_view buffer) { + WG_PROFILE_CPU_VULKAN("VKDriver::query_results"); assert(query_pool); - assert(count > 0); - assert(count * sizeof(std::uint64_t) == buffer.size()); + assert(buffer.size() > 0); WG_VK_CHECK(vkGetQueryPoolResults(m_device, query_pool.cast()->handle(), - 0, static_cast(count), - buffer.size(), buffer.data(), + 0, static_cast(buffer.size()), + buffer.size() * sizeof(std::uint64_t), buffer.data(), sizeof(std::uint64_t), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT)); } + void VKDriver::query_callibration(std::uint64_t& gpu_time, std::uint64_t& gpu_freq) { + WG_PROFILE_CPU_VULKAN("VKDriver::query_callibration"); + + gpu_time = 0; + gpu_freq = 0; + + if (!m_use_timestamps) { + return; + } + if (!VKDebug::vkGetPhysicalDeviceCalibrateableTimeDomainsEXT) { + return; + } + if (!VKDebug::vkGetCalibratedTimestampsEXT) { + return; + } + + VkCalibratedTimestampInfoEXT timestamp_info; + timestamp_info.sType = VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT; + timestamp_info.pNext = nullptr; + timestamp_info.timeDomain = VK_TIME_DOMAIN_DEVICE_EXT; + + uint64_t timestamp = 0, max_deviation = 0; + VKDebug::vkGetCalibratedTimestampsEXT(m_device, 1, ×tamp_info, ×tamp, &max_deviation); + + gpu_time = timestamp; + gpu_freq = static_cast(m_device_caps.timestamp_period); + } + void VKDriver::end_frame(bool swap_buffers) { - WG_AUTO_PROFILE_VULKAN("VKDriver::end_frame"); + WG_PROFILE_CPU_VULKAN("VKDriver::end_frame"); Ref cmd = acquire_cmd_list(GfxQueueType::Graphics).cast(); @@ -495,7 +527,7 @@ namespace wmoge { } void VKDriver::init_functions() { - WG_AUTO_PROFILE_VULKAN("VKDriver::init_functions"); + WG_PROFILE_CPU_VULKAN("VKDriver::init_functions"); auto res = volkInitialize(); @@ -505,7 +537,7 @@ namespace wmoge { } } void VKDriver::init_instance() { - WG_AUTO_PROFILE_VULKAN("VKDriver::init_instance"); + WG_PROFILE_CPU_VULKAN("VKDriver::init_instance"); auto extensions = pack_strings(m_required_extensions); auto layers = pack_strings(m_required_layers); @@ -549,7 +581,7 @@ namespace wmoge { } } void VKDriver::init_physical_device_and_queues(VKWindow& window) { - WG_AUTO_PROFILE_VULKAN("VKDriver::init_physical_device_and_queues"); + WG_PROFILE_CPU_VULKAN("VKDriver::init_physical_device_and_queues"); uint32_t device_count; WG_VK_CHECK(vkEnumeratePhysicalDevices(m_instance, &device_count, nullptr)); @@ -675,7 +707,7 @@ namespace wmoge { #endif } void VKDriver::init_device() { - WG_AUTO_PROFILE_VULKAN("VKDriver::init_device"); + WG_PROFILE_CPU_VULKAN("VKDriver::init_device"); VkPhysicalDeviceFeatures features; vkGetPhysicalDeviceFeatures(m_phys_device, &features); @@ -729,7 +761,7 @@ namespace wmoge { WG_VK_CHECK(vkCreateDevice(m_phys_device, &device_create_info, nullptr, &m_device)); } void VKDriver::init_pipeline_cache() { - WG_AUTO_PROFILE_VULKAN("VKDriver::init_pipeline_cache"); + WG_PROFILE_CPU_VULKAN("VKDriver::init_pipeline_cache"); std::vector cache_data; if (!m_file_system->read_file(m_pipeline_cache_path, cache_data)) { @@ -748,7 +780,7 @@ namespace wmoge { WG_VK_NAME(m_device, m_pipeline_cache, VK_OBJECT_TYPE_PIPELINE_CACHE, m_pipeline_cache_path); } void VKDriver::release_pipeline_cache() { - WG_AUTO_PROFILE_VULKAN("VKDriver::release_pipeline_cache"); + WG_PROFILE_CPU_VULKAN("VKDriver::release_pipeline_cache"); if (m_pipeline_cache) { size_t cache_size = 0; @@ -764,7 +796,7 @@ namespace wmoge { } } void VKDriver::init_sync_fences() { - WG_AUTO_PROFILE_VULKAN("VKDriver::init_sync_fences"); + WG_PROFILE_CPU_VULKAN("VKDriver::init_sync_fences"); VkFenceCreateInfo fence_info{}; fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; @@ -774,7 +806,7 @@ namespace wmoge { WG_VK_NAME(m_device, m_sync_fence, VK_OBJECT_TYPE_FENCE, "sync_fence"); } void VKDriver::release_sync_fences() { - WG_AUTO_PROFILE_VULKAN("VKDriver::release_sync_fences"); + WG_PROFILE_CPU_VULKAN("VKDriver::release_sync_fences"); if (m_sync_fence) { vkDestroyFence(m_device, m_sync_fence, nullptr); @@ -782,7 +814,7 @@ namespace wmoge { } bool VKDriver::supports(const std::string& extension) { - WG_AUTO_PROFILE_VULKAN("VKDriver::supports"); + WG_PROFILE_CPU_VULKAN("VKDriver::supports"); for (auto& ext : m_device_extensions) { if (extension == ext.extensionName) { @@ -794,7 +826,7 @@ namespace wmoge { } void VKDriver::release_resources(uint64_t index) { - WG_AUTO_PROFILE_VULKAN("VKDriver::release_resources"); + WG_PROFILE_CPU_VULKAN("VKDriver::release_resources"); m_deferred_release[index].flush(); } diff --git a/engine/runtime/gfx/vulkan/vk_driver.hpp b/engine/runtime/gfx/vulkan/vk_driver.hpp index e5d1f209f..a527b601c 100644 --- a/engine/runtime/gfx/vulkan/vk_driver.hpp +++ b/engine/runtime/gfx/vulkan/vk_driver.hpp @@ -93,7 +93,8 @@ namespace wmoge { void begin_frame(std::size_t frame_id, const array_view>& windows) override; GfxCmdListRef acquire_cmd_list(GfxQueueType queue_type) override; void submit_cmd_list(const GfxCmdListRef& cmd_list) override; - void query_results(const GfxQueryPoolRef& query_pool, int count, array_view buffer) override; + void query_results(const GfxQueryPoolRef& query_pool, array_view buffer) override; + void query_callibration(std::uint64_t& gpu_time, std::uint64_t& gpu_freq) override; void end_frame(bool swap_buffers) override; const GfxDeviceCaps& device_caps() const override { return m_device_caps; } @@ -174,6 +175,7 @@ namespace wmoge { std::vector m_required_extensions; std::vector m_required_device_extensions; bool m_use_validation = false; + bool m_use_timestamps = true; FileSystem* m_file_system = nullptr; TaskManager* m_task_manager = nullptr; diff --git a/engine/runtime/gfx/vulkan/vk_pipeline.cpp b/engine/runtime/gfx/vulkan/vk_pipeline.cpp index 419a4271c..8ed49d999 100644 --- a/engine/runtime/gfx/vulkan/vk_pipeline.cpp +++ b/engine/runtime/gfx/vulkan/vk_pipeline.cpp @@ -30,7 +30,7 @@ #include "core/task.hpp" #include "core/timer.hpp" #include "gfx/vulkan/vk_driver.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -70,7 +70,7 @@ namespace wmoge { } Status VKPsoGraphics::compile(const GfxPsoStateGraphics& state) { - WG_AUTO_PROFILE_VULKAN("VKPsoGraphics::compile"); + WG_PROFILE_CPU_VULKAN("VKPsoGraphics::compile"); Timer timer; timer.start(); @@ -232,7 +232,7 @@ namespace wmoge { return WG_OK; } void VKPsoGraphics::release() { - WG_AUTO_PROFILE_VULKAN("VKPsoGraphics::release"); + WG_PROFILE_CPU_VULKAN("VKPsoGraphics::release"); if (m_pipeline) { vkDestroyPipeline(m_driver.device(), m_pipeline, nullptr); @@ -247,7 +247,7 @@ namespace wmoge { release(); } Status VKPsoCompute::compile(const GfxPsoStateCompute& state) { - WG_AUTO_PROFILE_VULKAN("VKPsoCompute::compile"); + WG_PROFILE_CPU_VULKAN("VKPsoCompute::compile"); Timer timer; timer.start(); @@ -285,7 +285,7 @@ namespace wmoge { return WG_OK; } void VKPsoCompute::release() { - WG_AUTO_PROFILE_VULKAN("VKPsoCompute::release"); + WG_PROFILE_CPU_VULKAN("VKPsoCompute::release"); if (m_pipeline) { vkDestroyPipeline(m_driver.device(), m_pipeline, nullptr); diff --git a/engine/runtime/gfx/vulkan/vk_render_pass.cpp b/engine/runtime/gfx/vulkan/vk_render_pass.cpp index 4a97fec78..1cae3776e 100644 --- a/engine/runtime/gfx/vulkan/vk_render_pass.cpp +++ b/engine/runtime/gfx/vulkan/vk_render_pass.cpp @@ -30,7 +30,7 @@ #include "core/crc32.hpp" #include "gfx/vulkan/vk_driver.hpp" #include "gfx/vulkan/vk_texture.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -110,7 +110,7 @@ namespace wmoge { m_has_depth_stencil = has_depth_stencil; } VKRenderPass::~VKRenderPass() { - WG_AUTO_PROFILE_VULKAN("VKRenderPass::~VKRenderPass"); + WG_PROFILE_CPU_VULKAN("VKRenderPass::~VKRenderPass"); if (m_render_pass) { vkDestroyRenderPass(m_driver.device(), m_render_pass, nullptr); @@ -156,7 +156,7 @@ namespace wmoge { WG_VK_NAME(m_driver.device(), m_framebuffer, VK_OBJECT_TYPE_FRAMEBUFFER, m_name.str()); } VKFrameBuffer::~VKFrameBuffer() { - WG_AUTO_PROFILE_VULKAN("VKFrameBuffer::~VKFrameBuffer"); + WG_PROFILE_CPU_VULKAN("VKFrameBuffer::~VKFrameBuffer"); if (m_framebuffer) { vkDestroyFramebuffer(m_driver.device(), m_framebuffer, nullptr); diff --git a/engine/runtime/gfx/vulkan/vk_shader.cpp b/engine/runtime/gfx/vulkan/vk_shader.cpp index 867b7e58f..5b36fbe14 100644 --- a/engine/runtime/gfx/vulkan/vk_shader.cpp +++ b/engine/runtime/gfx/vulkan/vk_shader.cpp @@ -28,7 +28,7 @@ #include "vk_shader.hpp" #include "gfx/vulkan/vk_driver.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -37,7 +37,7 @@ namespace wmoge { } VKShader::~VKShader() { - WG_AUTO_PROFILE_VULKAN("VKShader::~VKShader"); + WG_PROFILE_CPU_VULKAN("VKShader::~VKShader"); if (m_module) { vkDestroyShaderModule(m_driver.device(), m_module, nullptr); @@ -45,7 +45,7 @@ namespace wmoge { } void VKShader::create(GfxShaderDesc desc) { - WG_AUTO_PROFILE_VULKAN("VKShader::create"); + WG_PROFILE_CPU_VULKAN("VKShader::create"); m_desc = std::move(desc); @@ -63,7 +63,7 @@ namespace wmoge { } void VKShaderProgram::create(GfxShaderProgramDesc desc) { - WG_AUTO_PROFILE_VULKAN("VKShaderProgram::create"); + WG_PROFILE_CPU_VULKAN("VKShaderProgram::create"); m_desc = std::move(desc); } diff --git a/engine/runtime/gfx/vulkan/vk_texture.cpp b/engine/runtime/gfx/vulkan/vk_texture.cpp index 8ed17a2c4..07501521d 100644 --- a/engine/runtime/gfx/vulkan/vk_texture.cpp +++ b/engine/runtime/gfx/vulkan/vk_texture.cpp @@ -28,14 +28,14 @@ #include "vk_texture.hpp" #include "gfx/vulkan/vk_driver.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { VKTexture::VKTexture(class VKDriver& driver) : VKResource(driver) { } VKTexture::~VKTexture() { - WG_AUTO_PROFILE_VULKAN("VKTexture::~VKTexture"); + WG_PROFILE_CPU_VULKAN("VKTexture::~VKTexture"); for (auto view : m_rt_views) { vkDestroyImageView(m_driver.device(), view, nullptr); @@ -56,7 +56,7 @@ namespace wmoge { init_rt_views(); } void VKTexture::create_2d(int width, int height, VkImage image, VkFormat format, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKTexture::create_2d"); + WG_PROFILE_CPU_VULKAN("VKTexture::create_2d"); m_desc.tex_type = GfxTex::Tex2d; m_desc.width = width; @@ -87,7 +87,7 @@ namespace wmoge { init_view(); } void VKTexture::create_2d(int width, int height, int mips, GfxFormat format, GfxTexUsages usages, GfxMemUsage mem_usage, GfxTexSwizz swizz, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKTexture::create_2d"); + WG_PROFILE_CPU_VULKAN("VKTexture::create_2d"); GfxTextureDesc desc; desc.tex_type = GfxTex::Tex2d; @@ -104,7 +104,7 @@ namespace wmoge { create(desc, name); } void VKTexture::create_2d_array(int width, int height, int mips, int slices, GfxFormat format, GfxTexUsages usages, GfxMemUsage mem_usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKTexture::create_2d_array"); + WG_PROFILE_CPU_VULKAN("VKTexture::create_2d_array"); GfxTextureDesc desc; desc.tex_type = GfxTex::Tex2dArray; @@ -120,7 +120,7 @@ namespace wmoge { create(desc, name); } void VKTexture::create_cube(int width, int height, int mips, GfxFormat format, GfxTexUsages usages, GfxMemUsage mem_usage, const Strid& name) { - WG_AUTO_PROFILE_VULKAN("VKTexture::create_cube"); + WG_PROFILE_CPU_VULKAN("VKTexture::create_cube"); GfxTextureDesc desc; desc.tex_type = GfxTex::TexCube; @@ -136,17 +136,17 @@ namespace wmoge { create(desc, name); } void VKTexture::update_2d(VkCommandBuffer cmd, int mip, const Rect2i& region, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKTexture::update_2d"); + WG_PROFILE_CPU_VULKAN("VKTexture::update_2d"); update(cmd, mip, 0, region, data); } void VKTexture::update_2d_array(VkCommandBuffer cmd, int mip, int slice, const Rect2i& region, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKTexture::update_2d_array"); + WG_PROFILE_CPU_VULKAN("VKTexture::update_2d_array"); update(cmd, mip, slice, region, data); } void VKTexture::update_cube(VkCommandBuffer cmd, int mip, int face, const Rect2i& region, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKTexture::update_cube"); + WG_PROFILE_CPU_VULKAN("VKTexture::update_cube"); update(cmd, mip, face, region, data); } @@ -194,7 +194,7 @@ namespace wmoge { } void VKTexture::init_image() { - WG_AUTO_PROFILE_VULKAN("VKTexture::init_image"); + WG_PROFILE_CPU_VULKAN("VKTexture::init_image"); m_usage_flags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; @@ -251,7 +251,7 @@ namespace wmoge { WG_VK_NAME(m_driver.device(), m_image, VK_OBJECT_TYPE_IMAGE, name().str()); } void VKTexture::init_view() { - WG_AUTO_PROFILE_VULKAN("VKTexture::init_view"); + WG_PROFILE_CPU_VULKAN("VKTexture::init_view"); VkImageViewCreateInfo view_info{}; view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; @@ -281,7 +281,7 @@ namespace wmoge { WG_VK_NAME(m_driver.device(), m_view, VK_OBJECT_TYPE_IMAGE_VIEW, name().str()); } void VKTexture::init_rt_views() { - WG_AUTO_PROFILE_VULKAN("VKTexture::init_rt_views"); + WG_PROFILE_CPU_VULKAN("VKTexture::init_rt_views"); if (!m_desc.usages.get(GfxTexUsageFlag::ColorTarget) && !m_desc.usages.get(GfxTexUsageFlag::DepthTarget) && @@ -317,7 +317,7 @@ namespace wmoge { } void VKTexture::update(VkCommandBuffer cmd, int mip, int slice, const Rect2i& region, array_view data) { - WG_AUTO_PROFILE_VULKAN("VKTexture::update"); + WG_PROFILE_CPU_VULKAN("VKTexture::update"); assert(mip < m_desc.mips_count); assert(slice < m_desc.array_slices); diff --git a/engine/runtime/gfx/vulkan/vk_window.cpp b/engine/runtime/gfx/vulkan/vk_window.cpp index 121cb2c36..b4670a775 100644 --- a/engine/runtime/gfx/vulkan/vk_window.cpp +++ b/engine/runtime/gfx/vulkan/vk_window.cpp @@ -31,7 +31,7 @@ #include "gfx/vulkan/vk_driver.hpp" #include "gfx/vulkan/vk_texture.hpp" #include "math/math_utils.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -41,7 +41,7 @@ namespace wmoge { } VKWindow::~VKWindow() { - WG_AUTO_PROFILE_VULKAN("VKWindow::~VKWindow"); + WG_PROFILE_CPU_VULKAN("VKWindow::~VKWindow"); WG_VK_CHECK(vkDeviceWaitIdle(m_driver.device())); @@ -60,7 +60,7 @@ namespace wmoge { } void VKWindow::init(VKCmdList* cmd) { - WG_AUTO_PROFILE_VULKAN("VKWindow::init"); + WG_PROFILE_CPU_VULKAN("VKWindow::init"); create_image_semaphores(); select_properties(); @@ -68,7 +68,7 @@ namespace wmoge { } void VKWindow::get_support_info(VkPhysicalDevice device, uint32_t prs_family, VKSwapChainSupportInfo& info) const { - WG_AUTO_PROFILE_VULKAN("VKWindow::get_support_info"); + WG_PROFILE_CPU_VULKAN("VKWindow::get_support_info"); WG_VK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, m_surface, &info.capabilities)); @@ -88,7 +88,7 @@ namespace wmoge { } void VKWindow::create_image_semaphores() { - WG_AUTO_PROFILE_VULKAN("VKWindow::create_image_semaphores"); + WG_PROFILE_CPU_VULKAN("VKWindow::create_image_semaphores"); VkSemaphoreCreateInfo semaphore_info{}; semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; @@ -103,7 +103,7 @@ namespace wmoge { } void VKWindow::select_properties() { - WG_AUTO_PROFILE_VULKAN("VKWindow::select_properties"); + WG_PROFILE_CPU_VULKAN("VKWindow::select_properties"); VKSwapChainSupportInfo support_info{}; get_support_info(m_driver.phys_device(), m_driver.queues()->prs_queue_family(), support_info); @@ -134,7 +134,7 @@ namespace wmoge { } void VKWindow::create_swapchain(VKCmdList* cmd) { - WG_AUTO_PROFILE_VULKAN("VKWindow::create_swapchain"); + WG_PROFILE_CPU_VULKAN("VKWindow::create_swapchain"); WG_VK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(m_driver.phys_device(), m_surface, &m_capabilities)) @@ -210,7 +210,7 @@ namespace wmoge { } void VKWindow::release_swapchain() { - WG_AUTO_PROFILE_VULKAN("VKWindow::release_swapchain"); + WG_PROFILE_CPU_VULKAN("VKWindow::release_swapchain"); if (m_swapchain) { m_color_targets.clear(); @@ -222,7 +222,7 @@ namespace wmoge { } void VKWindow::recreate_swapchain(VKCmdList* cmd) { - WG_AUTO_PROFILE_VULKAN("VKWindow::recreate_swapchain"); + WG_PROFILE_CPU_VULKAN("VKWindow::recreate_swapchain"); // ensure that window resources are no more used WG_VK_CHECK(vkDeviceWaitIdle(m_driver.device())); @@ -236,7 +236,7 @@ namespace wmoge { } void VKWindow::acquire_next(VKCmdList* cmd) { - WG_AUTO_PROFILE_VULKAN("VKWindow::acquire_next"); + WG_PROFILE_CPU_VULKAN("VKWindow::acquire_next"); check_requested_size(); @@ -269,7 +269,7 @@ namespace wmoge { } Ref VKWindowManager::get_or_create(VKCmdList* cmd, const Ref& window) { - WG_AUTO_PROFILE_VULKAN("VKWindowManager::get_or_create"); + WG_PROFILE_CPU_VULKAN("VKWindowManager::get_or_create"); auto query = m_windows.find(window->id()); if (query != m_windows.end()) { diff --git a/engine/runtime/glsl/glsl_shader_compiler.cpp b/engine/runtime/glsl/glsl_shader_compiler.cpp index 436f8d0fd..08681a4a1 100644 --- a/engine/runtime/glsl/glsl_shader_compiler.cpp +++ b/engine/runtime/glsl/glsl_shader_compiler.cpp @@ -35,7 +35,7 @@ #include "glsl/glsl_include_processor.hpp" #include "io/enum.hpp" #include "io/stream.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -57,7 +57,7 @@ namespace wmoge { } Status GlslShaderCompiler::compile(ShaderCompilerRequest& request) { - WG_AUTO_PROFILE_VULKAN("GlslShaderCompiler::compile"); + WG_PROFILE_CPU_VULKAN("GlslShaderCompiler::compile"); Timer timer; timer.start(); @@ -79,7 +79,7 @@ namespace wmoge { const auto messages = static_cast(EShMsgDefault | EShMsgCascadingErrors); auto dump_file = [&](const std::string& code) { - WG_AUTO_PROFILE_VULKAN("GlslShaderCompiler::dump_file"); + WG_PROFILE_CPU_VULKAN("GlslShaderCompiler::dump_file"); if (input.options.dump_on_failure) { std::stringstream file_content; @@ -96,7 +96,7 @@ namespace wmoge { }; auto compile_single_shader = [&](EShLanguage language, glslang::TShader& shader, const ShaderCompilerInputFile& file, Sha256& source_hash) { - WG_AUTO_PROFILE_VULKAN("GlslShaderCompiler::compile_shader"); + WG_PROFILE_CPU_VULKAN("GlslShaderCompiler::compile_shader"); GlslIncludeProcessor include_processor(input.env, *fs, collect_code); @@ -302,7 +302,7 @@ namespace wmoge { } { - WG_AUTO_PROFILE_VULKAN("GlslShaderCompiler::link_program"); + WG_PROFILE_CPU_VULKAN("GlslShaderCompiler::link_program"); if (!program.link(messages)) { WG_LOG_ERROR("failed to link program: " << program.getInfoLog()); @@ -315,7 +315,7 @@ namespace wmoge { std::size_t spirv_size = 0; auto extract_spirv = [&](EShLanguage langugage, std::vector& spirv, Ref& spirv_data, Sha256& spirv_hash) { - WG_AUTO_PROFILE_VULKAN("GlslShaderCompiler::extract_spirv"); + WG_PROFILE_CPU_VULKAN("GlslShaderCompiler::extract_spirv"); glslang::SpvOptions spv_options; diff --git a/engine/runtime/grc/font.cpp b/engine/runtime/grc/font.cpp index c23911e58..19a3559a7 100644 --- a/engine/runtime/grc/font.cpp +++ b/engine/runtime/grc/font.cpp @@ -30,7 +30,7 @@ #include "gfx/gfx_driver.hpp" #include "grc/image.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include diff --git a/engine/runtime/grc/image.cpp b/engine/runtime/grc/image.cpp index 6aff5a1c6..69d3bb6c1 100644 --- a/engine/runtime/grc/image.cpp +++ b/engine/runtime/grc/image.cpp @@ -29,7 +29,7 @@ #include "core/ioc_container.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -38,7 +38,7 @@ namespace wmoge { void Image::create(int width, int height, int channels, int pixel_size) { - WG_AUTO_PROFILE_ASSET("Image::create"); + WG_PROFILE_CPU_ASSET("Image::create"); if (!width || !height || !pixel_size || !channels) { WG_LOG_ERROR("an attempt to make empty image"); @@ -52,7 +52,7 @@ namespace wmoge { m_pixel_data = make_ref(width * height * pixel_size); } Status Image::load(FileSystem* fs, const std::string& path, int channels) { - WG_AUTO_PROFILE_ASSET("Image::load"); + WG_PROFILE_CPU_ASSET("Image::load"); std::vector pixel_data; WG_CHECKED(fs->read_file(path, pixel_data)); @@ -60,7 +60,7 @@ namespace wmoge { return load(pixel_data, channels); } Status Image::load(array_view pixel_data, int channels) { - WG_AUTO_PROFILE_ASSET("Image::load"); + WG_PROFILE_CPU_ASSET("Image::load"); int w, h, n; channels = Math::clamp(channels, 0, 4); @@ -82,7 +82,7 @@ namespace wmoge { return WG_OK; } Status Image::save(std::filesystem::path filepath) { - WG_AUTO_PROFILE_ASSET("Image::save"); + WG_PROFILE_CPU_ASSET("Image::save"); if (!m_width || !m_height) { WG_LOG_ERROR("cannot save empty image"); @@ -93,7 +93,7 @@ namespace wmoge { return stbi_write_png(filepath_str.c_str(), m_width, m_height, m_channels, m_pixel_data->buffer(), m_width * m_pixel_size) ? StatusCode::Ok : StatusCode::Error; } Status Image::resize(int new_width, int new_height) { - WG_AUTO_PROFILE_ASSET("Image::resize"); + WG_PROFILE_CPU_ASSET("Image::resize"); if (!new_width || !new_height) { WG_LOG_ERROR("cannot resize image " << get_name() << " to " << new_width << "x" << new_height); @@ -119,7 +119,7 @@ namespace wmoge { } Status Image::generate_mip_chain(std::vector>& mips) { - WG_AUTO_PROFILE_ASSET("Image::generate_mip_chain"); + WG_PROFILE_CPU_ASSET("Image::generate_mip_chain"); assert(mips.empty()); diff --git a/engine/runtime/grc/pso_cache.cpp b/engine/runtime/grc/pso_cache.cpp index acb6e6431..80f1fab2e 100644 --- a/engine/runtime/grc/pso_cache.cpp +++ b/engine/runtime/grc/pso_cache.cpp @@ -32,7 +32,7 @@ #include "gfx/gfx_driver.hpp" #include "grc/shader_compiler.hpp" #include "grc/shader_library.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -192,7 +192,7 @@ namespace wmoge { } Async PsoCache::precache_psos(const array_view& states, const array_view& names, Async depends_on) { - WG_AUTO_PROFILE_GRC("PsoCache::precache_psos"); + WG_PROFILE_CPU_GRC("PsoCache::precache_psos"); assert(states.size() == names.size()); @@ -242,7 +242,7 @@ namespace wmoge { return task.schedule(m_task_manager, depends_on).as_async(); } Async PsoCache::precache_psos(const array_view& states, const array_view& names, Async depends_on) { - WG_AUTO_PROFILE_GRC("PsoCache::precache_psos"); + WG_PROFILE_CPU_GRC("PsoCache::precache_psos"); assert(states.size() == names.size()); diff --git a/engine/runtime/grc/shader.cpp b/engine/runtime/grc/shader.cpp index 0e19f336e..7c05dcd26 100644 --- a/engine/runtime/grc/shader.cpp +++ b/engine/runtime/grc/shader.cpp @@ -30,7 +30,7 @@ #include "core/log.hpp" #include "grc/shader_builder.hpp" #include "grc/shader_compiler.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -50,7 +50,7 @@ namespace wmoge { } Status Shader::fill_layout_desc(GfxDescSetLayoutDesc& desc, std::int16_t space) const { - WG_AUTO_PROFILE_GRC("Shader::fill_layout_desc"); + WG_PROFILE_CPU_GRC("Shader::fill_layout_desc"); assert(0 <= space && space < m_reflection.spaces.size()); @@ -93,7 +93,7 @@ namespace wmoge { } Status Shader::fill_compiler_env(GfxShaderLang lang, GfxShaderPlatform platform, const ShaderPermutation& permutation, ShaderCompiler* compiler, ShaderCompilerEnv& compiler_env) { - WG_AUTO_PROFILE_GRC("Shader::fill_compiler_env"); + WG_PROFILE_CPU_GRC("Shader::fill_compiler_env"); compiler_env.set_define(SID(GfxShaderPlatformGlslDefines[int(platform)])); compiler_env.set_define(SID("TECHNIQUE_IDX"), permutation.technique_idx); @@ -118,7 +118,7 @@ namespace wmoge { } Status Shader::fill_compiler_input(GfxShaderLang lang, GfxShaderPlatform platform, const ShaderPermutation& permutation, ShaderCompiler* compiler, ShaderCompilerInput& compiler_input) { - WG_AUTO_PROFILE_GRC("Shader::fill_compiler_input"); + WG_PROFILE_CPU_GRC("Shader::fill_compiler_input"); std::string program_name; if (!fill_program_name(lang, platform, permutation, program_name)) { @@ -148,7 +148,7 @@ namespace wmoge { } Status Shader::fill_program_name(GfxShaderLang lang, GfxShaderPlatform platform, const ShaderPermutation& permutation, std::string& name) { - WG_AUTO_PROFILE_GRC("Shader::fill_program_name"); + WG_PROFILE_CPU_GRC("Shader::fill_program_name"); std::stringstream stream; @@ -180,7 +180,7 @@ namespace wmoge { } Status Shader::fill_declarations(GfxShaderLang lang, ShaderCompiler* compiler, std::string& out_declarations) { - WG_AUTO_PROFILE_GRC("Shader::fill_declarations"); + WG_PROFILE_CPU_GRC("Shader::fill_declarations"); assert(lang == GfxShaderLang::GlslVk450); @@ -296,7 +296,7 @@ namespace wmoge { } Status Shader::fill_vertex_input(GfxShaderLang lang, ShaderCompiler* compiler, const ShaderPermutation& permutation, std::string& out_input) { - WG_AUTO_PROFILE_GRC("Shader::fill_vertex_input"); + WG_PROFILE_CPU_GRC("Shader::fill_vertex_input"); assert(lang == GfxShaderLang::GlslVk450); diff --git a/engine/runtime/grc/shader_cache.cpp b/engine/runtime/grc/shader_cache.cpp index 671d4c933..fe0be1618 100644 --- a/engine/runtime/grc/shader_cache.cpp +++ b/engine/runtime/grc/shader_cache.cpp @@ -5,7 +5,7 @@ #include "grc/shader_library.hpp" #include "io/stream_file.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "rtti/traits.hpp" #include @@ -89,7 +89,7 @@ namespace wmoge { } void ShaderCache::dump_programs(GfxShaderPlatform platform, std::vector& out_programs) { - WG_AUTO_PROFILE_GRC("ShaderCache::dump_programs"); + WG_PROFILE_CPU_GRC("ShaderCache::dump_programs"); assert(int(platform) < GfxLimits::NUM_PLATFORMS); m_maps[int(platform)].dump_programs(out_programs); @@ -109,7 +109,7 @@ namespace wmoge { } Status ShaderCache::load_cache(FileSystem* file_system, const std::string& file_path, GfxShaderPlatform platform, bool allow_missing) { - WG_AUTO_PROFILE_GRC("ShaderCache::load_cache"); + WG_PROFILE_CPU_GRC("ShaderCache::load_cache"); IoStreamFile stream; IoContext context; @@ -146,7 +146,7 @@ namespace wmoge { } Status ShaderCache::save_cache(FileSystem* file_system, const std::string& file_path, GfxShaderPlatform platform) { - WG_AUTO_PROFILE_GRC("ShaderCache::save_cache"); + WG_PROFILE_CPU_GRC("ShaderCache::save_cache"); std::vector programs; dump_programs(platform, programs); diff --git a/engine/runtime/grc/shader_library.cpp b/engine/runtime/grc/shader_library.cpp index 3ca50eca1..35a566e4f 100644 --- a/engine/runtime/grc/shader_library.cpp +++ b/engine/runtime/grc/shader_library.cpp @@ -34,7 +34,7 @@ #include "gfx/gfx_driver.hpp" #include "io/stream_file.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "rtti/traits.hpp" #include @@ -162,7 +162,7 @@ namespace wmoge { ShaderLibrary::~ShaderLibrary() = default; Ref ShaderLibrary::get_or_create_shader(GfxShaderPlatform platform, GfxShaderModule module_type, const Sha256& bytecode_hash) { - WG_AUTO_PROFILE_GRC("ShaderLibrary::get_or_create_shader"); + WG_PROFILE_CPU_GRC("ShaderLibrary::get_or_create_shader"); auto query = find_shader(platform, module_type, bytecode_hash); if (query) { @@ -177,7 +177,7 @@ namespace wmoge { } std::optional> ShaderLibrary::find_shader(GfxShaderPlatform platform, GfxShaderModule module_type, const Sha256& bytecode_hash) { - WG_AUTO_PROFILE_GRC("ShaderLibrary::find_shader"); + WG_PROFILE_CPU_GRC("ShaderLibrary::find_shader"); std::shared_lock lock(m_mutex); @@ -186,7 +186,7 @@ namespace wmoge { } void ShaderLibrary::fit_module(GfxShaderPlatform platform, ShaderModule& module) { - WG_AUTO_PROFILE_GRC("ShaderLibrary::fit_module"); + WG_PROFILE_CPU_GRC("ShaderLibrary::fit_module"); std::unique_lock lock(m_mutex); @@ -195,7 +195,7 @@ namespace wmoge { } void ShaderLibrary::dump_modules(GfxShaderPlatform platform, std::vector& out_modules) { - WG_AUTO_PROFILE_GRC("ShaderLibrary::dump_modules"); + WG_PROFILE_CPU_GRC("ShaderLibrary::dump_modules"); std::shared_lock lock(m_mutex); @@ -213,7 +213,7 @@ namespace wmoge { } Status ShaderLibrary::load_cache(FileSystem* file_system, const std::string& folder, const GfxShaderPlatform platform) { - WG_AUTO_PROFILE_GRC("ShaderLibrary::load_cache"); + WG_PROFILE_CPU_GRC("ShaderLibrary::load_cache"); const std::string file_path = make_cache_file_name(folder, platform); IoStreamFile stream; @@ -255,7 +255,7 @@ namespace wmoge { } Status ShaderLibrary::save_cache(FileSystem* file_system, const std::string& folder, const GfxShaderPlatform platform) { - WG_AUTO_PROFILE_GRC("ShaderLibrary::save_cache"); + WG_PROFILE_CPU_GRC("ShaderLibrary::save_cache"); std::vector modules; dump_modules(platform, modules); diff --git a/engine/runtime/grc/shader_manager.cpp b/engine/runtime/grc/shader_manager.cpp index 09120d2d7..3862b0bf9 100644 --- a/engine/runtime/grc/shader_manager.cpp +++ b/engine/runtime/grc/shader_manager.cpp @@ -41,7 +41,7 @@ #include "io/enum.hpp" #include "math/math_utils.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "rtti/type_storage.hpp" #include "system/console.hpp" @@ -54,7 +54,7 @@ namespace wmoge { ShaderManager::ShaderManager(IocContainer* ioc) { - WG_AUTO_PROFILE_GRC("ShaderManager::ShaderManager"); + WG_PROFILE_CPU_GRC("ShaderManager::ShaderManager"); m_task_manager = ioc->resolve_value(); m_file_system = ioc->resolve_value(); @@ -86,7 +86,7 @@ namespace wmoge { } Status ShaderManager::load_shader_reflection(const ShaderFile& file, ShaderReflection& reflection) { - WG_AUTO_PROFILE_GRC("ShaderManager::load_shader"); + WG_PROFILE_CPU_GRC("ShaderManager::load_shader"); ShaderBuilder builder; @@ -312,7 +312,7 @@ namespace wmoge { } Ref ShaderManager::get_or_create_program(Shader* shader, GfxShaderPlatform platform, const ShaderPermutation& permutation) { - WG_AUTO_PROFILE_GRC("ShaderManager::get_or_create_program"); + WG_PROFILE_CPU_GRC("ShaderManager::get_or_create_program"); Ref fast_lookup = find_program(shader, platform, permutation); if (fast_lookup) { @@ -365,7 +365,7 @@ namespace wmoge { } Task cache_task(request->input.name, [shader_library = m_shader_library, permutation, platform, request, weak_shader_entry = WeakRef(&shader_entry)](TaskContext&) { - WG_AUTO_PROFILE_GRC("Shader::cache_compiled_program"); + WG_PROFILE_CPU_GRC("Shader::cache_compiled_program"); Ref shader_entry = weak_shader_entry.acquire(); if (!shader_entry) { @@ -448,13 +448,13 @@ namespace wmoge { } Async ShaderManager::precache_program(Shader* shader, GfxShaderPlatform platform, const ShaderPermutation& permutation) { - WG_AUTO_PROFILE_GRC("ShaderManager::precache_program"); + WG_PROFILE_CPU_GRC("ShaderManager::precache_program"); return Async(); } Async ShaderManager::compile_program(Shader* shader, GfxShaderPlatform platform, const ShaderPermutation& permutation, Ref& request, Async depends_on) { - WG_AUTO_PROFILE_GRC("ShaderManager::compile_program"); + WG_PROFILE_CPU_GRC("ShaderManager::compile_program"); Async result = Async::failed(); @@ -482,7 +482,7 @@ namespace wmoge { } Status ShaderManager::load_cache(Shader* shader, GfxShaderPlatform platform, bool allow_missing) { - WG_AUTO_PROFILE_GRC("ShaderManager::load_cache"); + WG_PROFILE_CPU_GRC("ShaderManager::load_cache"); auto& entry = get_entry_ref(shader); std::unique_lock lock(entry.mutex); @@ -492,7 +492,7 @@ namespace wmoge { } Status ShaderManager::save_cache(Shader* shader, GfxShaderPlatform platform) { - WG_AUTO_PROFILE_GRC("ShaderManager::save_cache"); + WG_PROFILE_CPU_GRC("ShaderManager::save_cache"); auto& entry = get_entry_ref(shader); std::unique_lock lock(entry.mutex); diff --git a/engine/runtime/grc/texture.cpp b/engine/runtime/grc/texture.cpp index 2fe528561..05c3a3167 100644 --- a/engine/runtime/grc/texture.cpp +++ b/engine/runtime/grc/texture.cpp @@ -33,7 +33,8 @@ #include "core/string_utils.hpp" #include "gfx/gfx_driver.hpp" #include "io/tree.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" +#include "profiler/profiler_gpu.hpp" #include @@ -73,7 +74,7 @@ namespace wmoge { } Status Texture::generate_mips() { - WG_AUTO_PROFILE_ASSET("Texture::generate_mips"); + WG_PROFILE_CPU_ASSET("Texture::generate_mips"); std::vector> mips; @@ -97,7 +98,7 @@ namespace wmoge { return WG_OK; } Status Texture::generate_compressed_data() { - WG_AUTO_PROFILE_ASSET("Texture::generate_compressed_data"); + WG_PROFILE_CPU_ASSET("Texture::generate_compressed_data"); if (!m_flags.get(TextureFlag::Compressed)) { WG_LOG_INFO("no compression flag on texutre " << get_name()); @@ -161,7 +162,7 @@ namespace wmoge { } Status Texture::create_gfx_resource(TexturePool& pool) { - WG_AUTO_PROFILE_ASSET("Texture::create_gfx_resource"); + WG_PROFILE_CPU_ASSET("Texture::create_gfx_resource"); assert(m_flags.get(TextureFlag::Pooled)); const GfxTextureDesc desc = get_desc(); @@ -171,7 +172,7 @@ namespace wmoge { } Status Texture::delete_gfx_resource(TexturePool& pool) { - WG_AUTO_PROFILE_ASSET("Texture::delete_gfx_resource"); + WG_PROFILE_CPU_ASSET("Texture::delete_gfx_resource"); assert(m_flags.get(TextureFlag::Pooled)); pool.release(m_texture); @@ -181,6 +182,8 @@ namespace wmoge { } Status Texture::upload_gfx_data(GfxCmdListRef& cmd) { + WG_PROFILE_GPU_SCOPE(cmd.get(), "Texture::upload_gfx_data"); + assert(m_depth == 1); assert(m_array_slices >= 1); assert(m_mips >= 1); @@ -190,7 +193,11 @@ namespace wmoge { assert(is_compressed || m_format_compressed == GfxFormat::Unknown); for (int array_slice = 0; array_slice < m_array_slices; array_slice++) { + WG_PROFILE_GPU_SCOPE(cmd.get(), "upload_slice"); + for (int mip = 0; mip < m_mips; mip++) { + WG_PROFILE_GPU_SCOPE(cmd.get(), "upload_mip"); + const int index = array_slice * m_mips + mip; Ref data = m_images[index]->get_pixel_data(); diff --git a/engine/runtime/grc/texture_manager.cpp b/engine/runtime/grc/texture_manager.cpp index c6e61d4eb..66273e161 100644 --- a/engine/runtime/grc/texture_manager.cpp +++ b/engine/runtime/grc/texture_manager.cpp @@ -29,14 +29,15 @@ #include "core/array_view.hpp" #include "core/ioc_container.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" +#include "profiler/profiler_gpu.hpp" #include namespace wmoge { TextureManager::TextureManager(IocContainer* ioc) { - WG_AUTO_PROFILE_GRC("TextureManager::TextureManager"); + WG_PROFILE_CPU_GRC("TextureManager::TextureManager"); m_gfx_driver = ioc->resolve_value(); m_pool = std::make_unique(*m_gfx_driver); @@ -100,7 +101,7 @@ namespace wmoge { } void TextureManager::update() { - WG_AUTO_PROFILE_GRC("TextureManager::update"); + WG_PROFILE_CPU_GRC("TextureManager::update"); std::lock_guard guard(m_mutex); upload_default_textures(); @@ -118,7 +119,7 @@ namespace wmoge { } void TextureManager::init_default_samplers() { - WG_AUTO_PROFILE_GRC("TextureManager::init_default_samplers"); + WG_PROFILE_CPU_GRC("TextureManager::init_default_samplers"); const GfxSamplerDesc samp_descs[int(DefaultSampler::Total)] = { GfxSamplerDesc(), @@ -138,7 +139,7 @@ namespace wmoge { } void TextureManager::init_default_textures() { - WG_AUTO_PROFILE_GRC("TextureManager::init_default_textures"); + WG_PROFILE_CPU_GRC("TextureManager::init_default_textures"); const char* tex_names[int(DefaultTexture::Total)] = { "white", @@ -155,7 +156,7 @@ namespace wmoge { } void TextureManager::upload_default_textures() { - WG_AUTO_PROFILE_GRC("TextureManager::upload_default_textures"); + WG_PROFILE_CPU_GRC("TextureManager::upload_default_textures"); if (!m_need_upload_default) { return; @@ -183,7 +184,7 @@ namespace wmoge { } void TextureManager::init_textures() { - WG_AUTO_PROFILE_GRC("TextureManager::init_textures"); + WG_PROFILE_CPU_GRC("TextureManager::init_textures"); std::vector for_upload; for (auto& iter : m_textures) { @@ -212,12 +213,16 @@ namespace wmoge { } auto cmd = m_gfx_driver->acquire_cmd_list(GfxQueueType::Graphics); + WG_PROFILE_GPU_BEGIN(cmd.get()); + cmd->barrier_images(for_barrier, GfxTexBarrierType::Undefined, GfxTexBarrierType::CopyDestination); for (Texture* texture : for_upload) { texture->upload_gfx_data(cmd); } cmd->barrier_images(for_barrier, GfxTexBarrierType::CopyDestination, GfxTexBarrierType::Sampling); + m_gfx_driver->submit_cmd_list(cmd); + WG_PROFILE_GPU_END(cmd.get()); WG_LOG_INFO("uploaded " << for_upload.size() << " textures to gpu"); } diff --git a/engine/runtime/grc/texture_resize.cpp b/engine/runtime/grc/texture_resize.cpp index 174889d7d..8c4627f44 100644 --- a/engine/runtime/grc/texture_resize.cpp +++ b/engine/runtime/grc/texture_resize.cpp @@ -28,12 +28,12 @@ #include "texture_resize.hpp" #include "math/math_utils.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { Status TexResize::resize(const TexResizeParams& params, Image& image) { - WG_AUTO_PROFILE_RENDER("TexResize::resize"); + WG_PROFILE_CPU_RENDER("TexResize::resize"); TexSizePreset preset = params.preset; diff --git a/engine/runtime/io/async_file_system.cpp b/engine/runtime/io/async_file_system.cpp index dbba43eda..e37fc77f8 100644 --- a/engine/runtime/io/async_file_system.cpp +++ b/engine/runtime/io/async_file_system.cpp @@ -29,7 +29,7 @@ #include "core/ioc_container.hpp" #include "core/task.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -38,7 +38,7 @@ namespace wmoge { } AsyncResult IoAsyncFileSystem::read_file(const std::string& filepath, BufferView buffer_view) { - WG_AUTO_PROFILE_IO("IoAsyncFileSystem::read_file"); + WG_PROFILE_CPU_IO("IoAsyncFileSystem::read_file"); AsyncOp async_result = make_async_op(); diff --git a/engine/runtime/io/compression.cpp b/engine/runtime/io/compression.cpp index 97868c65c..f52d570a5 100644 --- a/engine/runtime/io/compression.cpp +++ b/engine/runtime/io/compression.cpp @@ -27,14 +27,14 @@ #include "compression.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include namespace wmoge { Status Compression::estimate_lz4(const void* in, int size, int& max_compressed_size) { - WG_AUTO_PROFILE_IO("Compression::estimate_lz4"); + WG_PROFILE_CPU_IO("Compression::estimate_lz4"); max_compressed_size = LZ4_compressBound(size); @@ -42,7 +42,7 @@ namespace wmoge { } Status Compression::compress_lz4(const void* in, int size, int max_compressed_size, int& compressed_size, std::uint8_t* out) { - WG_AUTO_PROFILE_IO("Compression::compress_lz4"); + WG_PROFILE_CPU_IO("Compression::compress_lz4"); compressed_size = LZ4_compress_default(reinterpret_cast(in), reinterpret_cast(out), size, max_compressed_size); if (compressed_size > 0) { @@ -53,7 +53,7 @@ namespace wmoge { } Status Compression::decompress_lz4(const void* in, int compressed_size, int decompressed_size, std::uint8_t* out) { - WG_AUTO_PROFILE_IO("Compression::decompress_lz4"); + WG_PROFILE_CPU_IO("Compression::decompress_lz4"); const int decompressed_bytes = LZ4_decompress_safe(reinterpret_cast(in), reinterpret_cast(out), compressed_size, decompressed_size); if (decompressed_bytes == decompressed_size) { diff --git a/engine/runtime/io/serialization.hpp b/engine/runtime/io/serialization.hpp index 9d4d55604..ed882478a 100644 --- a/engine/runtime/io/serialization.hpp +++ b/engine/runtime/io/serialization.hpp @@ -108,7 +108,7 @@ namespace wmoge { if constexpr (std::is_same_v && std::is_same_v) { \ profile_mark_name = profile_mark_archive_write; \ } \ - WG_AUTO_PROFILE_IO(profile_mark_name); + WG_PROFILE_CPU_IO(profile_mark_name); #define WG_IO_FIELD_EXT(field, name, flags) \ if constexpr (std::is_same_v) { \ diff --git a/engine/runtime/io/stream_file.cpp b/engine/runtime/io/stream_file.cpp index bf7dcd3e3..4a1184a2c 100644 --- a/engine/runtime/io/stream_file.cpp +++ b/engine/runtime/io/stream_file.cpp @@ -29,7 +29,7 @@ #include "io/compression.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -146,7 +146,7 @@ namespace wmoge { } Status IoStreamFile::flush_compressed() { - WG_AUTO_PROFILE_IO("IoStreamFile::flush_compressed"); + WG_PROFILE_CPU_IO("IoStreamFile::flush_compressed"); IoContext dummy; @@ -174,7 +174,7 @@ namespace wmoge { } Status IoStreamFile::fetch_decompressed() { - WG_AUTO_PROFILE_IO("IoStreamFile::fetch_decompressed"); + WG_PROFILE_CPU_IO("IoStreamFile::fetch_decompressed"); IoContext dummy; diff --git a/engine/runtime/io/tree_yaml.cpp b/engine/runtime/io/tree_yaml.cpp index 017e3a25d..fbb5d6c9f 100644 --- a/engine/runtime/io/tree_yaml.cpp +++ b/engine/runtime/io/tree_yaml.cpp @@ -29,7 +29,7 @@ #include "core/ioc_container.hpp" #include "platform/file_system.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -57,7 +57,7 @@ namespace wmoge { } Status IoYamlTree::parse_data(const array_view& data) { - WG_AUTO_PROFILE_IO("IoYamlTree::parse_data"); + WG_PROFILE_CPU_IO("IoYamlTree::parse_data"); assert(m_stack.empty()); auto str_view = ryml::csubstr(reinterpret_cast(data.data()), data.size()); m_tree = std::move(ryml::parse_in_arena(str_view)); diff --git a/engine/runtime/mesh/array_mesh.cpp b/engine/runtime/mesh/array_mesh.cpp index 7b29ea2d5..c8619dfc8 100644 --- a/engine/runtime/mesh/array_mesh.cpp +++ b/engine/runtime/mesh/array_mesh.cpp @@ -28,7 +28,7 @@ #include "array_mesh.hpp" #include "io/enum.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include diff --git a/engine/runtime/mesh/mesh.cpp b/engine/runtime/mesh/mesh.cpp index 423397ec1..6601bab43 100644 --- a/engine/runtime/mesh/mesh.cpp +++ b/engine/runtime/mesh/mesh.cpp @@ -29,7 +29,7 @@ #include "core/string_utils.hpp" #include "gfx/gfx_driver.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { diff --git a/engine/runtime/mesh/mesh_batch.cpp b/engine/runtime/mesh/mesh_batch.cpp index 069d22fee..cb51478ab 100644 --- a/engine/runtime/mesh/mesh_batch.cpp +++ b/engine/runtime/mesh/mesh_batch.cpp @@ -31,7 +31,7 @@ #include "material/material.hpp" #include "mesh/mesh_bucket.hpp" #include "mesh/mesh_processors.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "render/render_engine.hpp" #include "render/render_scene.hpp" diff --git a/engine/runtime/mesh/mesh_builder.cpp b/engine/runtime/mesh/mesh_builder.cpp index 08d4a8566..02d4bbdd9 100644 --- a/engine/runtime/mesh/mesh_builder.cpp +++ b/engine/runtime/mesh/mesh_builder.cpp @@ -30,7 +30,7 @@ #include "core/class.hpp" #include "core/data.hpp" #include "core/log.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -48,7 +48,7 @@ namespace wmoge { } Status MeshBuilder::build() { - WG_AUTO_PROFILE_MESH("MeshBuilder::build"); + WG_PROFILE_CPU_MESH("MeshBuilder::build"); assert(m_mesh); diff --git a/engine/runtime/mesh/mesh_manager.cpp b/engine/runtime/mesh/mesh_manager.cpp index a04fa7626..89a1bd272 100644 --- a/engine/runtime/mesh/mesh_manager.cpp +++ b/engine/runtime/mesh/mesh_manager.cpp @@ -29,7 +29,7 @@ #include "core/ioc_container.hpp" #include "gfx/gfx_driver.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include diff --git a/engine/runtime/mesh/mesh_processors.cpp b/engine/runtime/mesh/mesh_processors.cpp index 41eba04f4..7718939f2 100644 --- a/engine/runtime/mesh/mesh_processors.cpp +++ b/engine/runtime/mesh/mesh_processors.cpp @@ -30,7 +30,7 @@ #include "gfx/gfx_driver.hpp" #include "material/material.hpp" #include "mesh/mesh_batch.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -38,7 +38,7 @@ namespace wmoge { return true; } Status MeshPassProcessorGBuffer::compile(const MeshBatch& batch, Ref& out_pipeline) { - WG_AUTO_PROFILE_MESH("MeshPassProcessorGBuffer::compile"); + WG_PROFILE_CPU_MESH("MeshPassProcessorGBuffer::compile"); // Material* material = batch.material; // Shader* shader = material->get_shader().get(); diff --git a/engine/runtime/pfx/pfx_component_runtime.cpp b/engine/runtime/pfx/pfx_component_runtime.cpp index c1c97fca6..d77fce686 100644 --- a/engine/runtime/pfx/pfx_component_runtime.cpp +++ b/engine/runtime/pfx/pfx_component_runtime.cpp @@ -30,7 +30,7 @@ #include "core/log.hpp" #include "gfx/gfx_vert_format.hpp" #include "pfx/pfx_emitter.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -50,7 +50,7 @@ namespace wmoge { } void PfxComponentRuntime::emit(const PfxSpawnParams& params) { - WG_AUTO_PROFILE_PFX("PfxComponentRuntime::emit"); + WG_PROFILE_CPU_PFX("PfxComponentRuntime::emit"); const auto& attributes = m_storage->get_attributes(); @@ -109,7 +109,7 @@ namespace wmoge { m_is_active = m_active_amount > 0; } void PfxComponentRuntime::update(float dt) { - WG_AUTO_PROFILE_PFX("PfxComponentRuntime::update"); + WG_PROFILE_CPU_PFX("PfxComponentRuntime::update"); for (int i = 0; i < m_component->get_features_count(); i++) { m_component->get_feature(i)->on_update(*this, dt); diff --git a/engine/runtime/pfx/pfx_effect.cpp b/engine/runtime/pfx/pfx_effect.cpp index 41d12e738..554b1fff0 100644 --- a/engine/runtime/pfx/pfx_effect.cpp +++ b/engine/runtime/pfx/pfx_effect.cpp @@ -27,7 +27,7 @@ #include "pfx_effect.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { diff --git a/engine/runtime/pfx/pfx_emitter.cpp b/engine/runtime/pfx/pfx_emitter.cpp index 416f4c50e..3c4cfda8d 100644 --- a/engine/runtime/pfx/pfx_emitter.cpp +++ b/engine/runtime/pfx/pfx_emitter.cpp @@ -28,7 +28,7 @@ #include "pfx_emitter.hpp" #include "pfx/pfx_effect.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { @@ -57,7 +57,7 @@ namespace wmoge { m_time += delta_time; } void PfxEmitter::update() { - WG_AUTO_PROFILE_PFX("PfxEmitter::update"); + WG_PROFILE_CPU_PFX("PfxEmitter::update"); buffered_vector emit_queue; { diff --git a/engine/runtime/pfx/pfx_scene.cpp b/engine/runtime/pfx/pfx_scene.cpp index 8a226be2b..22605f97a 100644 --- a/engine/runtime/pfx/pfx_scene.cpp +++ b/engine/runtime/pfx/pfx_scene.cpp @@ -27,7 +27,7 @@ #include "pfx_scene.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -46,7 +46,7 @@ namespace wmoge { m_emitters.erase(emitter); } void PfxScene::update(float dt) { - WG_AUTO_PROFILE_PFX("PfxScene::update"); + WG_PROFILE_CPU_PFX("PfxScene::update"); for (auto& emitter : m_emitters) { emitter->advance_time(dt); diff --git a/engine/runtime/platform/file_system.cpp b/engine/runtime/platform/file_system.cpp index af71b9430..bb191a7ce 100644 --- a/engine/runtime/platform/file_system.cpp +++ b/engine/runtime/platform/file_system.cpp @@ -31,7 +31,7 @@ #include "core/ioc_container.hpp" #include "core/log.hpp" #include "platform/common/mount_volume_physical.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include "system/config.hpp" #include @@ -115,7 +115,7 @@ namespace wmoge { } Status FileSystem::read_file(const std::string& path, std::string& data) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::read_file"); + WG_PROFILE_CPU_PLATFORM("FileSystem::read_file"); FileOpenModeFlags mode = {FileOpenMode::In, FileOpenMode::Binary}; Ref file; @@ -139,7 +139,7 @@ namespace wmoge { } Status FileSystem::read_file(const std::string& path, Ref& data) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::read_file"); + WG_PROFILE_CPU_PLATFORM("FileSystem::read_file"); FileOpenModeFlags mode = {FileOpenMode::In, FileOpenMode::Binary}; Ref file; @@ -163,7 +163,7 @@ namespace wmoge { } Status FileSystem::read_file(const std::string& path, std::vector& data) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::read_file"); + WG_PROFILE_CPU_PLATFORM("FileSystem::read_file"); FileOpenModeFlags mode = {FileOpenMode::In, FileOpenMode::Binary}; Ref file; @@ -187,7 +187,7 @@ namespace wmoge { } Status FileSystem::open_file(const std::string& path, Ref& file, const FileOpenModeFlags& mode) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::open_file"); + WG_PROFILE_CPU_PLATFORM("FileSystem::open_file"); for (const MountPoint& mount_point : m_mount_points) { const auto& prefix = mount_point.first; @@ -205,7 +205,7 @@ namespace wmoge { } Status FileSystem::open_file_physical(const std::string& path, std::fstream& fstream, std::ios_base::openmode mode) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::open_file_physical"); + WG_PROFILE_CPU_PLATFORM("FileSystem::open_file_physical"); for (const MountPoint& mount_point : m_mount_points) { const auto& prefix = mount_point.first; @@ -223,7 +223,7 @@ namespace wmoge { } Status FileSystem::save_file(const std::string& path, const std::string& data) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::save_file"); + WG_PROFILE_CPU_PLATFORM("FileSystem::save_file"); FileOpenModeFlags mode = {FileOpenMode::Out, FileOpenMode::Binary}; Ref file; @@ -240,7 +240,7 @@ namespace wmoge { } Status FileSystem::save_file(const std::string& path, const std::vector& data) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::save_file"); + WG_PROFILE_CPU_PLATFORM("FileSystem::save_file"); FileOpenModeFlags mode = {FileOpenMode::Out, FileOpenMode::Binary}; Ref file; @@ -257,7 +257,7 @@ namespace wmoge { } Status FileSystem::hash_file(const std::string& path, Sha256& file_hash) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::hash_file"); + WG_PROFILE_CPU_PLATFORM("FileSystem::hash_file"); std::vector file_data; WG_CHECKED(read_file(path, file_data)); @@ -269,7 +269,7 @@ namespace wmoge { } void FileSystem::watch(const std::string& path, std::function callback) { - WG_AUTO_PROFILE_PLATFORM("FileSystem::watch"); + WG_PROFILE_CPU_PLATFORM("FileSystem::watch"); auto resolved_path = resolve_physical(path); diff --git a/engine/runtime/platform/glfw/glfw_input.cpp b/engine/runtime/platform/glfw/glfw_input.cpp index fb35646c7..ae9b3d8f1 100644 --- a/engine/runtime/platform/glfw/glfw_input.cpp +++ b/engine/runtime/platform/glfw/glfw_input.cpp @@ -29,7 +29,7 @@ #include "core/string_utf.hpp" #include "platform/glfw/glfw_window_manager.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include @@ -38,7 +38,7 @@ namespace wmoge { static GlfwInput* g_glfw_input = nullptr; GlfwInput::GlfwInput(class GlfwWindowManager& manager) : m_manager(manager) { - WG_AUTO_PROFILE_GLFW("GlfwInput::GlfwInput"); + WG_PROFILE_CPU_GLFW("GlfwInput::GlfwInput"); g_glfw_input = this; m_mouse = make_ref(); @@ -73,7 +73,7 @@ namespace wmoge { } void GlfwInput::subscribe_window(GLFWwindow* window) { - WG_AUTO_PROFILE_GLFW("GlfwInput::subscribe_window"); + WG_PROFILE_CPU_GLFW("GlfwInput::subscribe_window"); glfwSetDropCallback(window, drop_callback); glfwSetCursorPosCallback(window, mouse_position_callback); @@ -84,7 +84,7 @@ namespace wmoge { } void GlfwInput::update() { - WG_AUTO_PROFILE_GLFW("GlfwInput::update"); + WG_PROFILE_CPU_GLFW("GlfwInput::update"); for (auto& joystick : m_joysticks) { if (joystick->state() == InputDeviceState::Connected) { @@ -118,7 +118,7 @@ namespace wmoge { } void GlfwInput::drop_callback(GLFWwindow*, int count, const char** paths) { - WG_AUTO_PROFILE_GLFW("GlfwInput::drop_callback"); + WG_PROFILE_CPU_GLFW("GlfwInput::drop_callback"); if (count > 0) { std::vector paths_vector; @@ -134,7 +134,7 @@ namespace wmoge { } void GlfwInput::mouse_position_callback(GLFWwindow*, double x, double y) { - WG_AUTO_PROFILE_GLFW("GlfwInput::mouse_position_callback"); + WG_PROFILE_CPU_GLFW("GlfwInput::mouse_position_callback"); auto mouse = g_glfw_input->m_mouse; @@ -149,7 +149,7 @@ namespace wmoge { } void GlfwInput::mouse_buttons_callback(GLFWwindow*, int button, int action, int mods) { - WG_AUTO_PROFILE_GLFW("GlfwInput::mouse_buttons_callback"); + WG_PROFILE_CPU_GLFW("GlfwInput::mouse_buttons_callback"); auto mouse = g_glfw_input->m_mouse; @@ -169,7 +169,7 @@ namespace wmoge { } void GlfwInput::keyboard_keys_callback(GLFWwindow*, int key, int scancode, int action, int mods) { - WG_AUTO_PROFILE_GLFW("GlfwInput::keyboard_keys_callback"); + WG_PROFILE_CPU_GLFW("GlfwInput::keyboard_keys_callback"); auto keyboard = g_glfw_input->m_keyboard; @@ -189,7 +189,7 @@ namespace wmoge { } void GlfwInput::keyboard_text_callback(GLFWwindow*, unsigned int code_point) { - WG_AUTO_PROFILE_GLFW("GlfwInput::keyboard_text_callback"); + WG_PROFILE_CPU_GLFW("GlfwInput::keyboard_text_callback"); auto keyboard = g_glfw_input->m_keyboard; @@ -204,7 +204,7 @@ namespace wmoge { } void GlfwInput::joystick_callback(int jid, int state) { - WG_AUTO_PROFILE_GLFW("GlfwInput::joystick_callback"); + WG_PROFILE_CPU_GLFW("GlfwInput::joystick_callback"); auto joystick = g_glfw_input->get_joystick_by_hnd(jid); auto deviceState = state == GLFW_CONNECTED ? InputDeviceState::Connected : InputDeviceState::Disconnected; diff --git a/engine/runtime/platform/glfw/glfw_window.cpp b/engine/runtime/platform/glfw/glfw_window.cpp index 5b4db7b9d..3f7b6d8ea 100644 --- a/engine/runtime/platform/glfw/glfw_window.cpp +++ b/engine/runtime/platform/glfw/glfw_window.cpp @@ -29,12 +29,12 @@ #include "core/log.hpp" #include "platform/glfw/glfw_window_manager.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" namespace wmoge { GlfwWindow::GlfwWindow(const WindowInfo& window_info, class GlfwWindowManager& manager) : m_manager(manager) { - WG_AUTO_PROFILE_GLFW("GlfwWindow::GlfwWindow"); + WG_PROFILE_CPU_GLFW("GlfwWindow::GlfwWindow"); m_id = window_info.id; m_hnd = glfwCreateWindow(window_info.width, window_info.height, window_info.title.c_str(), nullptr, nullptr); @@ -59,7 +59,7 @@ namespace wmoge { } GlfwWindow::~GlfwWindow() { - WG_AUTO_PROFILE_GLFW("GlfwWindow::~GlfwWindow"); + WG_PROFILE_CPU_GLFW("GlfwWindow::~GlfwWindow"); if (m_hnd) { close(); @@ -67,7 +67,7 @@ namespace wmoge { } void GlfwWindow::close() { - WG_AUTO_PROFILE_GLFW("GlfwWindow::close"); + WG_PROFILE_CPU_GLFW("GlfwWindow::close"); if (!m_hnd) { WG_LOG_WARNING("window id=" << id() << " closed"); diff --git a/engine/runtime/platform/glfw/glfw_window_manager.cpp b/engine/runtime/platform/glfw/glfw_window_manager.cpp index 5fa7ee4e1..bd7cd625c 100644 --- a/engine/runtime/platform/glfw/glfw_window_manager.cpp +++ b/engine/runtime/platform/glfw/glfw_window_manager.cpp @@ -28,7 +28,7 @@ #include "glfw_window_manager.hpp" #include "core/log.hpp" -#include "profiler/profiler.hpp" +#include "profiler/profiler_cpu.hpp" #include #include @@ -38,7 +38,7 @@ namespace wmoge { static GlfwWindowManager* g_glwl_manager = nullptr; GlfwWindowManager::GlfwWindowManager(bool vsync, bool client_api) { - WG_AUTO_PROFILE_GLFW("GlfwWindowManager::GlfwWindowManager"); + WG_PROFILE_CPU_GLFW("GlfwWindowManager::GlfwWindowManager"); g_glwl_manager = this; m_vsync = vsync; @@ -78,7 +78,7 @@ namespace wmoge { } GlfwWindowManager::~GlfwWindowManager() { - WG_AUTO_PROFILE_GLFW("GlfwWindowManager::~GlfwWindowManager"); + WG_PROFILE_CPU_GLFW("GlfwWindowManager::~GlfwWindowManager"); m_primary.reset(); m_windows_by_hnd.clear(); @@ -89,7 +89,7 @@ namespace wmoge { } void GlfwWindowManager::poll_events() { - WG_AUTO_PROFILE_GLFW("GlfwWindowManager::poll_events"); + WG_PROFILE_CPU_GLFW("GlfwWindowManager::poll_events"); clear_events(); m_input->clear_events(); @@ -113,7 +113,7 @@ namespace wmoge { } Ref GlfwWindowManager::create_window(const WindowInfo& window_info) { - WG_AUTO_PROFILE_GLFW("GlfwWindowManager::create"); + WG_PROFILE_CPU_GLFW("GlfwWindowManager::create"); if (get_window(window_info.id)) { WG_LOG_ERROR("an attempt to recreate window with the same id=" << window_info.id); @@ -179,7 +179,7 @@ namespace wmoge { } std::vector GlfwWindowManager::extensions() { - WG_AUTO_PROFILE_GLFW("GlfwWindowManager::extensions"); + WG_PROFILE_CPU_GLFW("GlfwWindowManager::extensions"); const char** glfw_ext; uint32_t glfw_ext_count; @@ -195,7 +195,7 @@ namespace wmoge { std::function, VkSurfaceKHR&)> GlfwWindowManager::factory() { auto func = [this](VkInstance instance, Ref window, VkSurfaceKHR& surface_khr) { - WG_AUTO_PROFILE_GLFW("GlfwWindowManager::glfwCreateWindowSurface"); + WG_PROFILE_CPU_GLFW("GlfwWindowManager::glfwCreateWindowSurface"); assert(instance); assert(window); auto glfw_window = dynamic_cast(window.get()); diff --git a/engine/runtime/profiler/profiler.cpp b/engine/runtime/profiler/profiler.cpp deleted file mode 100644 index c31479c46..000000000 --- a/engine/runtime/profiler/profiler.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/**********************************************************************************/ -/* Wmoge game engine */ -/* Available at github https://github.com/EgorOrachyov/wmoge */ -/**********************************************************************************/ -/* MIT License */ -/* */ -/* Copyright (c) 2023 Egor Orachyov */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining a copy */ -/* of this software and associated documentation files (the "Software"), to deal */ -/* in the Software without restriction, including without limitation the rights */ -/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */ -/* copies of the Software, and to permit persons to whom the Software is */ -/* furnished to do so, subject to the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be included in all */ -/* copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ -/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ -/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */ -/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */ -/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */ -/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ -/* SOFTWARE. */ -/**********************************************************************************/ - -#include "profiler.hpp" - -#include "core/ioc_container.hpp" -#include "core/log.hpp" -#include "platform/file_system.hpp" -#include "platform/time.hpp" - -namespace wmoge { - - ProfilerMark::ProfilerMark(Strid label, - Strid in_function, - Strid in_function_sig, - Strid in_file, - Strid in_category, - std::size_t in_line) - : label(label), - function(in_function), - function_sig(in_function_sig), - file(in_file), - category(in_category), - line(in_line), - profiler(Profiler::instance()) { - - pretty_name = label.str(); - - if (pretty_name.empty()) { - std::string to_replace = "__cdecl "; - - pretty_name = function_sig.str(); - auto pos = pretty_name.find(to_replace); - if (pos != std::string::npos) { - pretty_name.replace(pos, to_replace.length(), ""); - } - } - } - - ProfilerTimeEvent::ProfilerTimeEvent(ProfilerMark* mark, std::string desc) - : m_mark(mark), m_desc(std::move(desc)) { - m_timer.start(); - } - - ProfilerTimeEvent::~ProfilerTimeEvent() { - m_timer.stop(); - - if (m_mark->profiler && m_mark->profiler->is_collecting()) { - ProfilerEntry entry; - entry.tid = std::this_thread::get_id(); - entry.start = m_timer.get_start(); - entry.stop = m_timer.get_end(); - entry.mark = m_mark; - entry.desc = std::move(m_desc); - m_mark->profiler->add_entry(std::move(entry)); - } - } - - void ProfilerCapture::set_name(Strid name) { - m_name = name; - } - - void ProfilerCapture::set_file(std::string file) { - m_file = std::move(file); - } - - void ProfilerCapture::add_entry(ProfilerEntry&& entry) { - m_entries.push_back(std::move(entry)); - } - - Profiler g_profiler_default; - Profiler* Profiler::g_profiler = &g_profiler_default; - - void Profiler::configure(IocContainer* ioc) { - m_file_system = ioc->resolve_value(); - m_time = ioc->resolve_value