Skip to content

Commit

Permalink
gh-82: minor polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Oct 12, 2024
1 parent e94d178 commit 867a1b0
Show file tree
Hide file tree
Showing 23 changed files with 451 additions and 256 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# IDE files
/.idea
/.vscode

# python cache files
/**/__pycache__
Expand Down
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
"cwd": "${workspaceRoot}/build-Release/template",
"environment": [],
"console": "integratedTerminal"
},
{
"name": "template-debug (help)",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/build-Debug/template/template.exe",
"args": [
"-h"
],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/build-Debug/template",
"environment": [],
"console": "integratedTerminal"
}
]
}
114 changes: 114 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"cmake.configureOnOpen": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"files.associations": {
"vector": "cpp",
"cinttypes": "cpp",
"algorithm": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"filesystem": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"valarray": "cpp",
"variant": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"cassert": "cpp",
"debug": "cpp",
"typeindex": "cpp",
"**/*.asset": "yaml",
"**/*.shader": "yaml",
"*.moc": "cpp",
"coroutine": "cpp",
"resumable": "cpp"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none",
"cmake.generator": "Ninja",
"cmake.buildArgs": [
"-j 8"
]
}
4 changes: 4 additions & 0 deletions engine/runtime/core/task_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ namespace wmoge {
void TaskManager::shutdown() {
WG_PROFILE_CPU_CORE("TaskManager::shutdown");

if (m_finished.load()) {
return;
}

WG_LOG_INFO("shutdown manager=" << m_worker_prefix << " and join already started tasks");

m_finished.store(true);
Expand Down
1 change: 1 addition & 0 deletions engine/runtime/core/task_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "core/string_id.hpp"
#include "core/synchronization.hpp"

#include <atomic>
#include <condition_variable>
#include <deque>
#include <functional>
Expand Down
34 changes: 20 additions & 14 deletions engine/runtime/grc/texture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ namespace wmoge {
if (!m_need_upload_default) {
return;
}
m_need_upload_default = false;

const std::array<std::uint8_t, 4> tex_colors[int(DefaultTexture::Total)] = {
{0xff, 0xff, 0xff, 0xff},
Expand All @@ -172,15 +173,18 @@ namespace wmoge {
};

auto cmd = m_gfx_driver->acquire_cmd_list(GfxQueueType::Graphics);

for (int i = 0; i < int(DefaultTexture::Total); i++) {
cmd->barrier_image(m_default_textures[i], GfxTexBarrierType::Undefined, GfxTexBarrierType::CopyDestination);
cmd->update_texture_2d(m_default_textures[i], 0, Rect2i(0, 0, 1, 1), array_view<const std::uint8_t>(tex_colors[i].data(), sizeof(std::uint8_t[4])));
cmd->barrier_image(m_default_textures[i], GfxTexBarrierType::CopyDestination, GfxTexBarrierType::Sampling);
WG_PROFILE_GPU_BEGIN(cmd);
{
WG_PROFILE_GPU_SCOPE(cmd, "TextureManager::upload_default_textures");

for (int i = 0; i < int(DefaultTexture::Total); i++) {
cmd->barrier_image(m_default_textures[i], GfxTexBarrierType::Undefined, GfxTexBarrierType::CopyDestination);
cmd->update_texture_2d(m_default_textures[i], 0, Rect2i(0, 0, 1, 1), array_view<const std::uint8_t>(tex_colors[i].data(), sizeof(std::uint8_t[4])));
cmd->barrier_image(m_default_textures[i], GfxTexBarrierType::CopyDestination, GfxTexBarrierType::Sampling);
}
}

WG_PROFILE_GPU_END(cmd);
m_gfx_driver->submit_cmd_list(cmd);
m_need_upload_default = false;
}

void TextureManager::init_textures() {
Expand Down Expand Up @@ -213,16 +217,18 @@ namespace wmoge {
}

auto cmd = m_gfx_driver->acquire_cmd_list(GfxQueueType::Graphics);
WG_PROFILE_GPU_BEGIN(cmd.get());
WG_PROFILE_GPU_BEGIN(cmd);
{
WG_PROFILE_GPU_SCOPE(cmd, "TextureManager::init_textures");

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::Undefined, GfxTexBarrierType::CopyDestination);
for (Texture* texture : for_upload) {
texture->upload_gfx_data(cmd);
}
cmd->barrier_images(for_barrier, GfxTexBarrierType::CopyDestination, GfxTexBarrierType::Sampling);
}
cmd->barrier_images(for_barrier, GfxTexBarrierType::CopyDestination, GfxTexBarrierType::Sampling);

WG_PROFILE_GPU_END(cmd);
m_gfx_driver->submit_cmd_list(cmd);
WG_PROFILE_GPU_END(cmd.get());

WG_LOG_INFO("uploaded " << for_upload.size() << " textures to gpu");
}
Expand Down
3 changes: 1 addition & 2 deletions engine/runtime/io/async_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace wmoge {
}

AsyncResult<IoAsyncFileSystem::BufferView> IoAsyncFileSystem::read_file(const std::string& filepath, BufferView buffer_view) {
WG_PROFILE_CPU_IO("IoAsyncFileSystem::read_file");

AsyncOp<BufferView> async_result = make_async_op<BufferView>();

Task task(SID(filepath), [=](TaskContext&) -> int {
Expand All @@ -49,6 +47,7 @@ namespace wmoge {
WG_LOG_ERROR("failed open file " << filepath);
return 1;
}
WG_PROFILE_CPU_SCOPE_WITH_DESC(io, "IoAsyncFileSystem::read_file", filepath);
if (!file->nread(buffer_view.data(), buffer_view.size())) {
WG_LOG_ERROR("failed read file " << filepath);
return 1;
Expand Down
1 change: 1 addition & 0 deletions engine/runtime/profiler/profiler_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace wmoge {
m_session_name = session_name;
m_session_path = filepath;
m_events_cpu.clear();
m_events_gpu.clear();

m_is_collecting.store(true);
}
Expand Down
4 changes: 4 additions & 0 deletions engine/runtime/profiler/profiler_capture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

namespace wmoge {

/**
* @class ProfilerCapture
* @brief Allows to caprute cpu and gpu time profiling events and dump to a file
*/
class ProfilerCapture {
public:
ProfilerCapture(class IocContainer* ioc);
Expand Down
8 changes: 8 additions & 0 deletions engine/runtime/profiler/profiler_cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

namespace wmoge {

/** @brief Cpu profiling mark */
struct ProfilerCpuMark {
std::string name;
Strid category;
Expand All @@ -50,6 +51,7 @@ namespace wmoge {
std::size_t line;
};

/** @brief Cpu profiling time event */
struct ProfilerCpuEvent {
ProfilerCpuMark* mark = nullptr;
std::string data;
Expand All @@ -58,6 +60,10 @@ namespace wmoge {
int thread_id = -1;
};

/**
* @class ProfilerCpu
* @brief Collects cpu time events for application from different threads
*/
class ProfilerCpu {
public:
Signal<const ProfilerCpuEvent&> on_event;
Expand All @@ -82,6 +88,7 @@ namespace wmoge {
static ProfilerCpu* g_profiler_cpu;
};

/** @brief Cpu profiling scope for single event */
struct ProfilerCpuScope {
ProfilerCpuScope(ProfilerCpuMark& mark, const std::string& data) { ProfilerCpu::instance()->begin_event(&mark, data); }
~ProfilerCpuScope() { ProfilerCpu::instance()->end_event(); }
Expand Down Expand Up @@ -126,3 +133,4 @@ namespace wmoge {
#define WG_PROFILE_CPU_OPENAL(label) WG_PROFILE_CPU_SCOPE(openal, label)
#define WG_PROFILE_CPU_SYSTEM(label) WG_PROFILE_CPU_SCOPE(system, label)
#define WG_PROFILE_CPU_PLUGIN(label) WG_PROFILE_CPU_SCOPE(plugin, label)
#define WG_PROFILE_CPU_GPU(label) WG_PROFILE_CPU_SCOPE(gpu, label)
Loading

0 comments on commit 867a1b0

Please sign in to comment.