Skip to content

Commit baa9bd4

Browse files
fixed excessive call of vkUpdateDescriptorSet (#417)
* fixed excessive call of vkUpdateDescriptorSet * fixed compile issue on macos * fixed formatted
1 parent 09456d4 commit baa9bd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3308
-3437
lines changed

Resources/Shaders/fragment_common.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ layout(std140, set = 0, binding = 5) readonly buffer MatSB
6060
MaterialData Data[];
6161
}
6262
MaterialDataBuffer;
63+
6364
layout(set = 0, binding = 9) uniform sampler2D TextureArray[];
6465

6566
MaterialData FetchMaterial(uint dataIndex)

Tetragrama/Components/AboutUIComponent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Tetragrama::Components
1010
AboutUIComponent(std::string_view name = "AboutUIComponent", bool visibility = true) : UIComponent(name, visibility, true) {}
1111
virtual ~AboutUIComponent() = default;
1212

13-
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override
13+
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override
1414
{
1515
ImGui::ShowAboutWindow(&m_is_open);
1616
}

Tetragrama/Components/DemoUIComponent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace Tetragrama::Components
77
class DemoUIComponent : public UIComponent
88
{
99
public:
10-
DemoUIComponent(std::string_view name = "DemoUIComponent", bool visibility = true) : UIComponent(name, visibility, true) {}
10+
DemoUIComponent(Layers::ImguiLayer* parent = nullptr, std::string_view name = "DemoUIComponent", bool visibility = true) : UIComponent(parent, name, visibility, true) {}
1111
virtual ~DemoUIComponent() = default;
1212

13-
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override
13+
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override
1414
{
1515
ImGui::ShowDemoWindow(&m_is_open);
1616
}

Tetragrama/Components/DockspaceUIComponent.cpp

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ namespace Tetragrama::Components
2121
std::string DockspaceUIComponent::s_asset_importer_report_msg = "";
2222
float DockspaceUIComponent::s_editor_scene_serializer_progress = 0.0f;
2323

24-
DockspaceUIComponent::DockspaceUIComponent(std::string_view name, bool visibility) : UIComponent(name, visibility, false), m_asset_importer(CreateScope<Importers::AssimpImporter>()), m_editor_serializer(CreateScope<Serializers::EditorSceneSerializer>())
24+
DockspaceUIComponent::DockspaceUIComponent(Layers::ImguiLayer* parent, std::string_view name, bool visibility) : UIComponent(parent, name, visibility, false), m_asset_importer(CreateScope<Importers::AssimpImporter>()), m_editor_serializer(CreateScope<Serializers::EditorSceneSerializer>())
2525
{
2626
m_dockspace_node_flag = ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_PassthruCentralNode;
2727
m_window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
2828

29-
const auto& editor_config = Editor::GetCurrentEditorConfiguration();
29+
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
30+
m_editor_serializer->Context = context;
31+
m_asset_importer->Context = context;
32+
33+
const auto& editor_config = *context->ConfigurationPtr;
3034

3135
m_default_import_configuration = {.OutputModelFilePath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath), .OutputMeshFilePath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath), .OutputTextureFilesPath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.DefaultImportTexturePath), .OutputMaterialsPath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath)};
3236

@@ -52,21 +56,13 @@ namespace Tetragrama::Components
5256
m_asset_importer->SetOnProgressCallback(OnAssetImporterProgress);
5357
m_asset_importer->SetOnLogCallback(OnAssetImporterLog);
5458
m_asset_importer->SetOnErrorCallback(OnAssetImporterError);
55-
56-
auto scene_fullname = fmt::format("{0}/{1}/{2}.zescene", editor_config.WorkingSpacePath, editor_config.ScenePath, editor_config.ActiveSceneName);
57-
58-
#ifdef _WIN32
59-
std::replace(scene_fullname.begin(), scene_fullname.end(), '/', '\\'); // Todo : Move this replace into an helper function....
60-
#endif // _WIN32
61-
62-
m_editor_serializer->Deserialize(scene_fullname);
6359
}
6460

6561
DockspaceUIComponent::~DockspaceUIComponent() {}
6662

6763
void DockspaceUIComponent::Update(ZEngine::Core::TimeStep dt) {}
6864

69-
void DockspaceUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
65+
void DockspaceUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer)
7066
{
7167
const ImGuiViewport* viewport = ImGui::GetMainViewport();
7268
ImGui::SetNextWindowPos(viewport->Pos);
@@ -123,6 +119,12 @@ namespace Tetragrama::Components
123119
RenderSaveSceneAs();
124120

125121
ImGui::End();
122+
123+
auto ctx = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
124+
if (ctx->CurrentScenePtr && ctx->CurrentScenePtr->RenderScene->IsDrawDataDirty)
125+
{
126+
ctx->CurrentScenePtr->RenderScene->InitOrResetDrawBuffer(renderer->Device, renderer->RenderGraph.get(), renderer->AsyncLoader.get());
127+
}
126128
}
127129

128130
void DockspaceUIComponent::RenderImporter()
@@ -299,9 +301,9 @@ namespace Tetragrama::Components
299301

300302
if (ImGui::Button("Save", ImVec2(80, 0)) && is_save_button_enabled)
301303
{
302-
auto active_scene = Editor::GetCurrentEditorScene();
303-
active_scene->SetName(s_save_as_input_buffer);
304-
m_editor_serializer->Serialize(active_scene);
304+
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
305+
context->CurrentScenePtr->Name = s_save_as_input_buffer;
306+
m_editor_serializer->Serialize(context->CurrentScenePtr);
305307

306308
m_open_save_scene_as = false;
307309
m_open_save_scene = true;
@@ -334,7 +336,8 @@ namespace Tetragrama::Components
334336

335337
m_pending_shutdown = true;
336338

337-
auto current_scene = Editor::GetCurrentEditorScene();
339+
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
340+
auto current_scene = context->CurrentScenePtr;
338341
if (!current_scene->HasPendingChange())
339342
{
340343
Helpers::UIDispatcher::RunAsync([this] { OnExitAsync(); });
@@ -348,7 +351,7 @@ namespace Tetragrama::Components
348351

349352
if (ImGui::BeginPopupModal(str_id, NULL, ImGuiWindowFlags_AlwaysAutoResize))
350353
{
351-
ImGui::Text(fmt::format("You have unsaved changes for your current scene : {}", current_scene->GetName()).c_str());
354+
ImGui::Text(fmt::format("You have unsaved changes for your current scene : {}", current_scene->Name).c_str());
352355
ImGui::Separator();
353356

354357
if (ImGui::Button("Save", ImVec2(120, 0)))
@@ -357,7 +360,7 @@ namespace Tetragrama::Components
357360
m_open_exit = false;
358361
ImGui::CloseCurrentPopup();
359362

360-
m_editor_serializer->Serialize(Editor::GetCurrentEditorScene());
363+
m_editor_serializer->Serialize(current_scene);
361364
}
362365
ImGui::SetItemDefaultFocus();
363366
ImGui::SameLine();
@@ -391,17 +394,16 @@ namespace Tetragrama::Components
391394
ZEngine::Helpers::secure_memset(s_save_as_input_buffer, 0, IM_ARRAYSIZE(s_save_as_input_buffer), IM_ARRAYSIZE(s_save_as_input_buffer));
392395
}
393396

394-
void DockspaceUIComponent::OnAssetImporterComplete(Importers::ImporterData&& data)
397+
void DockspaceUIComponent::OnAssetImporterComplete(void* const context, Importers::ImporterData&& data)
395398
{
396399
s_asset_importer_report_msg_color = {0.0f, 1.0f, 0.0f, 1.0f};
397400
s_asset_importer_report_msg = "Completed";
398401

399-
auto editor_scene = Editor::GetCurrentEditorScene();
400-
auto editor_config = Editor::GetCurrentEditorConfiguration();
402+
auto context_ptr = reinterpret_cast<EditorContext*>(context);
401403
/*
402404
* Removing the WorkingSpace Path
403405
*/
404-
auto ws = editor_config.WorkingSpacePath + "\\";
406+
auto ws = context_ptr->ConfigurationPtr->WorkingSpacePath + "\\";
405407
if (data.SerializedMeshesPath.find(ws) != std::string::npos)
406408
{
407409
data.SerializedMeshesPath.replace(data.SerializedMeshesPath.find(ws), ws.size(), "");
@@ -416,27 +418,28 @@ namespace Tetragrama::Components
416418
{
417419
data.SerializedModelPath.replace(data.SerializedModelPath.find(ws), ws.size(), "");
418420
}
419-
editor_scene->AddModel({.Name = data.Name, .MeshesPath = data.SerializedMeshesPath, .MaterialsPath = data.SerializedMaterialsPath, .ModelPath = data.SerializedModelPath});
421+
422+
context_ptr->CurrentScenePtr->Push(data.SerializedMeshesPath, data.SerializedModelPath, data.SerializedMaterialsPath);
420423
}
421424

422-
void DockspaceUIComponent::OnAssetImporterProgress(float value)
425+
void DockspaceUIComponent::OnAssetImporterProgress(void* const context, float value)
423426
{
424427
s_asset_importer_report_msg_color = {1.0f, 1.0f, 1.0f, 1.0f};
425428
s_asset_importer_report_msg = fmt::format("Reading file: {:.1f} %%", (value * 100.f));
426429
}
427430

428-
void DockspaceUIComponent::OnAssetImporterError(std::string_view msg)
431+
void DockspaceUIComponent::OnAssetImporterError(void* const, std::string_view msg)
429432
{
430433
s_asset_importer_report_msg_color = {1.0f, 0.0f, 0.0f, 1.0f};
431434
s_asset_importer_report_msg = msg;
432435
}
433436

434-
void DockspaceUIComponent::OnEditorSceneSerializerError(std::string_view msg)
437+
void DockspaceUIComponent::OnEditorSceneSerializerError(void* const, std::string_view msg)
435438
{
436439
ZENGINE_CORE_ERROR("{}", msg)
437440
}
438441

439-
void DockspaceUIComponent::OnAssetImporterLog(std::string_view msg)
442+
void DockspaceUIComponent::OnAssetImporterLog(void* const, std::string_view msg)
440443
{
441444
s_asset_importer_report_msg_color = {1.0f, 1.0f, 1.0f, 1.0f};
442445
s_asset_importer_report_msg = msg;
@@ -465,7 +468,13 @@ namespace Tetragrama::Components
465468
{
466469
m_open_save_scene = true;
467470
m_request_save_scene_ui_close = true;
468-
Helpers::UIDispatcher::RunAsync([this] { m_editor_serializer->Serialize(Editor::GetCurrentEditorScene()); });
471+
Helpers::UIDispatcher::RunAsync([this] {
472+
if (ParentLayer->ParentContext)
473+
{
474+
auto ctx = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
475+
m_editor_serializer->Serialize(ctx->CurrentScenePtr);
476+
}
477+
});
469478
}
470479

471480
ImGui::MenuItem("Save As...", NULL, &m_open_save_scene_as);
@@ -488,45 +497,26 @@ namespace Tetragrama::Components
488497
}
489498
}
490499

491-
void DockspaceUIComponent::OnEditorSceneSerializerProgress(float value)
500+
void DockspaceUIComponent::OnEditorSceneSerializerProgress(void* const, float value)
492501
{
493502
s_editor_scene_serializer_progress = value;
494503
}
495504

496-
void DockspaceUIComponent::OnEditorSceneSerializerComplete() {}
505+
void DockspaceUIComponent::OnEditorSceneSerializerComplete(void* const) {}
497506

498-
void DockspaceUIComponent::OnEditorSceneSerializerDeserializeComplete(EditorScene&& scene)
507+
void DockspaceUIComponent::OnEditorSceneSerializerDeserializeComplete(void* const context, EditorScene&& scene)
499508
{
500-
ZENGINE_CORE_INFO("Scene {} loaded successfully", scene.GetName())
509+
auto ctx = reinterpret_cast<EditorContext*>(context);
501510

502-
ZEngine::Rendering::Scenes::GraphicScene::SetRootNodeName(scene.GetName());
511+
// Todo : Ensure no data race on CurrentScenePtr
512+
ctx->CurrentScenePtr->Name = scene.Name;
513+
ctx->CurrentScenePtr->Data = scene.Data;
514+
ctx->CurrentScenePtr->MeshFiles = scene.MeshFiles;
515+
ctx->CurrentScenePtr->ModelFiles = scene.ModelFiles;
516+
ctx->CurrentScenePtr->MaterialFiles = scene.MaterialFiles;
517+
ctx->CurrentScenePtr->RenderScene = scene.RenderScene;
503518

504-
const auto& config = Editor::GetCurrentEditorConfiguration();
505-
const auto& scene_models = scene.GetModels();
506-
507-
std::vector<ZEngine::Rendering::Scenes::SceneRawData> scene_data;
508-
for (auto& [_, model] : scene_models)
509-
{
510-
auto model_path = fmt::format("{0}/{1}", config.WorkingSpacePath, model.ModelPath);
511-
auto mesh_path = fmt::format("{0}/{1}", config.WorkingSpacePath, model.MeshesPath);
512-
auto material_path = fmt::format("{0}/{1}", config.WorkingSpacePath, model.MaterialsPath);
513-
514-
#ifdef _WIN32
515-
std::replace(model_path.begin(), model_path.end(), '/', '\\');
516-
std::replace(mesh_path.begin(), mesh_path.end(), '/', '\\');
517-
std::replace(material_path.begin(), material_path.end(), '/', '\\');
518-
#endif // _WIN32
519-
520-
auto import_data = Importers::IAssetImporter::DeserializeImporterData(model_path, mesh_path, material_path);
521-
scene_data.push_back(import_data.Scene);
522-
}
523-
524-
if (!scene_data.empty())
525-
{
526-
ZEngine::Rendering::Scenes::GraphicScene::Merge(scene_data);
527-
}
528-
529-
Editor::SetCurrentEditorScene(std::move(scene));
519+
ZENGINE_CORE_INFO("Scene {} deserialized successfully", ctx->CurrentScenePtr->Name)
530520
}
531521

532522
std::future<void> DockspaceUIComponent::OnNewSceneAsync()
@@ -539,11 +529,14 @@ namespace Tetragrama::Components
539529
if (ParentLayer)
540530
{
541531
auto window = ParentLayer->GetAttachedWindow();
542-
std::vector<std::string_view> filters = {"."};
532+
std::vector<std::string_view> filters = {".zescene"};
543533
std::string scene_filename = co_await window->OpenFileDialogAsync(filters);
544534

545535
if (!scene_filename.empty())
546536
{
537+
#ifdef _WIN32
538+
std::replace(scene_filename.begin(), scene_filename.end(), '/', '\\'); // Todo : Move this replace into an helper function....
539+
#endif
547540
m_editor_serializer->Deserialize(scene_filename);
548541
}
549542
}

Tetragrama/Components/DockspaceUIComponent.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace Tetragrama::Components
1010
class DockspaceUIComponent : public UIComponent
1111
{
1212
public:
13-
DockspaceUIComponent(std::string_view name = "Dockspace", bool visibility = true);
13+
DockspaceUIComponent(Layers::ImguiLayer* parent = nullptr, std::string_view name = "Dockspace", bool visibility = true);
1414
virtual ~DockspaceUIComponent();
1515

1616
void Update(ZEngine::Core::TimeStep dt) override;
17-
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override;
17+
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override;
1818

1919
void RenderMenuBar();
2020
void RenderSaveScene();
@@ -27,18 +27,18 @@ namespace Tetragrama::Components
2727
*/
2828
void RenderImporter();
2929
void ResetImporterBuffers();
30-
static void OnAssetImporterComplete(Importers::ImporterData&&);
31-
static void OnAssetImporterProgress(float value);
32-
static void OnAssetImporterError(std::string_view);
33-
static void OnAssetImporterLog(std::string_view);
30+
static void OnAssetImporterComplete(void* const, Importers::ImporterData&&);
31+
static void OnAssetImporterProgress(void* const, float value);
32+
static void OnAssetImporterError(void* const, std::string_view);
33+
static void OnAssetImporterLog(void* const, std::string_view);
3434

3535
/*
3636
* Editor Scene Funcs
3737
*/
38-
static void OnEditorSceneSerializerProgress(float value);
39-
static void OnEditorSceneSerializerComplete();
40-
static void OnEditorSceneSerializerDeserializeComplete(EditorScene&&);
41-
static void OnEditorSceneSerializerError(std::string_view);
38+
static void OnEditorSceneSerializerProgress(void* const, float value);
39+
static void OnEditorSceneSerializerComplete(void* const);
40+
static void OnEditorSceneSerializerDeserializeComplete(void* const, EditorScene&&);
41+
static void OnEditorSceneSerializerError(void* const, std::string_view);
4242

4343
std::future<void> OnNewSceneAsync();
4444
std::future<void> OnOpenSceneAsync();

0 commit comments

Comments
 (0)