Skip to content

Commit

Permalink
fixed excessive call of vkUpdateDescriptorSet (JeanPhilippeKernel#417)
Browse files Browse the repository at this point in the history
* fixed excessive call of vkUpdateDescriptorSet

* fixed compile issue on macos

* fixed formatted
  • Loading branch information
JeanPhilippeKernel authored Jan 20, 2025
1 parent 09456d4 commit baa9bd4
Show file tree
Hide file tree
Showing 72 changed files with 3,308 additions and 3,437 deletions.
1 change: 1 addition & 0 deletions Resources/Shaders/fragment_common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ layout(std140, set = 0, binding = 5) readonly buffer MatSB
MaterialData Data[];
}
MaterialDataBuffer;

layout(set = 0, binding = 9) uniform sampler2D TextureArray[];

MaterialData FetchMaterial(uint dataIndex)
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/AboutUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Tetragrama::Components
AboutUIComponent(std::string_view name = "AboutUIComponent", bool visibility = true) : UIComponent(name, visibility, true) {}
virtual ~AboutUIComponent() = default;

virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override
{
ImGui::ShowAboutWindow(&m_is_open);
}
Expand Down
4 changes: 2 additions & 2 deletions Tetragrama/Components/DemoUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Tetragrama::Components
class DemoUIComponent : public UIComponent
{
public:
DemoUIComponent(std::string_view name = "DemoUIComponent", bool visibility = true) : UIComponent(name, visibility, true) {}
DemoUIComponent(Layers::ImguiLayer* parent = nullptr, std::string_view name = "DemoUIComponent", bool visibility = true) : UIComponent(parent, name, visibility, true) {}
virtual ~DemoUIComponent() = default;

virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override
{
ImGui::ShowDemoWindow(&m_is_open);
}
Expand Down
111 changes: 52 additions & 59 deletions Tetragrama/Components/DockspaceUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ namespace Tetragrama::Components
std::string DockspaceUIComponent::s_asset_importer_report_msg = "";
float DockspaceUIComponent::s_editor_scene_serializer_progress = 0.0f;

DockspaceUIComponent::DockspaceUIComponent(std::string_view name, bool visibility) : UIComponent(name, visibility, false), m_asset_importer(CreateScope<Importers::AssimpImporter>()), m_editor_serializer(CreateScope<Serializers::EditorSceneSerializer>())
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>())
{
m_dockspace_node_flag = ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_PassthruCentralNode;
m_window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;

const auto& editor_config = Editor::GetCurrentEditorConfiguration();
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
m_editor_serializer->Context = context;
m_asset_importer->Context = context;

const auto& editor_config = *context->ConfigurationPtr;

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)};

Expand All @@ -52,21 +56,13 @@ namespace Tetragrama::Components
m_asset_importer->SetOnProgressCallback(OnAssetImporterProgress);
m_asset_importer->SetOnLogCallback(OnAssetImporterLog);
m_asset_importer->SetOnErrorCallback(OnAssetImporterError);

auto scene_fullname = fmt::format("{0}/{1}/{2}.zescene", editor_config.WorkingSpacePath, editor_config.ScenePath, editor_config.ActiveSceneName);

#ifdef _WIN32
std::replace(scene_fullname.begin(), scene_fullname.end(), '/', '\\'); // Todo : Move this replace into an helper function....
#endif // _WIN32

m_editor_serializer->Deserialize(scene_fullname);
}

DockspaceUIComponent::~DockspaceUIComponent() {}

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

void DockspaceUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
void DockspaceUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer)
{
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
Expand Down Expand Up @@ -123,6 +119,12 @@ namespace Tetragrama::Components
RenderSaveSceneAs();

ImGui::End();

auto ctx = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
if (ctx->CurrentScenePtr && ctx->CurrentScenePtr->RenderScene->IsDrawDataDirty)
{
ctx->CurrentScenePtr->RenderScene->InitOrResetDrawBuffer(renderer->Device, renderer->RenderGraph.get(), renderer->AsyncLoader.get());
}
}

void DockspaceUIComponent::RenderImporter()
Expand Down Expand Up @@ -299,9 +301,9 @@ namespace Tetragrama::Components

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

m_open_save_scene_as = false;
m_open_save_scene = true;
Expand Down Expand Up @@ -334,7 +336,8 @@ namespace Tetragrama::Components

m_pending_shutdown = true;

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

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

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

m_editor_serializer->Serialize(Editor::GetCurrentEditorScene());
m_editor_serializer->Serialize(current_scene);
}
ImGui::SetItemDefaultFocus();
ImGui::SameLine();
Expand Down Expand Up @@ -391,17 +394,16 @@ namespace Tetragrama::Components
ZEngine::Helpers::secure_memset(s_save_as_input_buffer, 0, IM_ARRAYSIZE(s_save_as_input_buffer), IM_ARRAYSIZE(s_save_as_input_buffer));
}

void DockspaceUIComponent::OnAssetImporterComplete(Importers::ImporterData&& data)
void DockspaceUIComponent::OnAssetImporterComplete(void* const context, Importers::ImporterData&& data)
{
s_asset_importer_report_msg_color = {0.0f, 1.0f, 0.0f, 1.0f};
s_asset_importer_report_msg = "Completed";

auto editor_scene = Editor::GetCurrentEditorScene();
auto editor_config = Editor::GetCurrentEditorConfiguration();
auto context_ptr = reinterpret_cast<EditorContext*>(context);
/*
* Removing the WorkingSpace Path
*/
auto ws = editor_config.WorkingSpacePath + "\\";
auto ws = context_ptr->ConfigurationPtr->WorkingSpacePath + "\\";
if (data.SerializedMeshesPath.find(ws) != std::string::npos)
{
data.SerializedMeshesPath.replace(data.SerializedMeshesPath.find(ws), ws.size(), "");
Expand All @@ -416,27 +418,28 @@ namespace Tetragrama::Components
{
data.SerializedModelPath.replace(data.SerializedModelPath.find(ws), ws.size(), "");
}
editor_scene->AddModel({.Name = data.Name, .MeshesPath = data.SerializedMeshesPath, .MaterialsPath = data.SerializedMaterialsPath, .ModelPath = data.SerializedModelPath});

context_ptr->CurrentScenePtr->Push(data.SerializedMeshesPath, data.SerializedModelPath, data.SerializedMaterialsPath);
}

void DockspaceUIComponent::OnAssetImporterProgress(float value)
void DockspaceUIComponent::OnAssetImporterProgress(void* const context, float value)
{
s_asset_importer_report_msg_color = {1.0f, 1.0f, 1.0f, 1.0f};
s_asset_importer_report_msg = fmt::format("Reading file: {:.1f} %%", (value * 100.f));
}

void DockspaceUIComponent::OnAssetImporterError(std::string_view msg)
void DockspaceUIComponent::OnAssetImporterError(void* const, std::string_view msg)
{
s_asset_importer_report_msg_color = {1.0f, 0.0f, 0.0f, 1.0f};
s_asset_importer_report_msg = msg;
}

void DockspaceUIComponent::OnEditorSceneSerializerError(std::string_view msg)
void DockspaceUIComponent::OnEditorSceneSerializerError(void* const, std::string_view msg)
{
ZENGINE_CORE_ERROR("{}", msg)
}

void DockspaceUIComponent::OnAssetImporterLog(std::string_view msg)
void DockspaceUIComponent::OnAssetImporterLog(void* const, std::string_view msg)
{
s_asset_importer_report_msg_color = {1.0f, 1.0f, 1.0f, 1.0f};
s_asset_importer_report_msg = msg;
Expand Down Expand Up @@ -465,7 +468,13 @@ namespace Tetragrama::Components
{
m_open_save_scene = true;
m_request_save_scene_ui_close = true;
Helpers::UIDispatcher::RunAsync([this] { m_editor_serializer->Serialize(Editor::GetCurrentEditorScene()); });
Helpers::UIDispatcher::RunAsync([this] {
if (ParentLayer->ParentContext)
{
auto ctx = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
m_editor_serializer->Serialize(ctx->CurrentScenePtr);
}
});
}

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

void DockspaceUIComponent::OnEditorSceneSerializerProgress(float value)
void DockspaceUIComponent::OnEditorSceneSerializerProgress(void* const, float value)
{
s_editor_scene_serializer_progress = value;
}

void DockspaceUIComponent::OnEditorSceneSerializerComplete() {}
void DockspaceUIComponent::OnEditorSceneSerializerComplete(void* const) {}

void DockspaceUIComponent::OnEditorSceneSerializerDeserializeComplete(EditorScene&& scene)
void DockspaceUIComponent::OnEditorSceneSerializerDeserializeComplete(void* const context, EditorScene&& scene)
{
ZENGINE_CORE_INFO("Scene {} loaded successfully", scene.GetName())
auto ctx = reinterpret_cast<EditorContext*>(context);

ZEngine::Rendering::Scenes::GraphicScene::SetRootNodeName(scene.GetName());
// Todo : Ensure no data race on CurrentScenePtr
ctx->CurrentScenePtr->Name = scene.Name;
ctx->CurrentScenePtr->Data = scene.Data;
ctx->CurrentScenePtr->MeshFiles = scene.MeshFiles;
ctx->CurrentScenePtr->ModelFiles = scene.ModelFiles;
ctx->CurrentScenePtr->MaterialFiles = scene.MaterialFiles;
ctx->CurrentScenePtr->RenderScene = scene.RenderScene;

const auto& config = Editor::GetCurrentEditorConfiguration();
const auto& scene_models = scene.GetModels();

std::vector<ZEngine::Rendering::Scenes::SceneRawData> scene_data;
for (auto& [_, model] : scene_models)
{
auto model_path = fmt::format("{0}/{1}", config.WorkingSpacePath, model.ModelPath);
auto mesh_path = fmt::format("{0}/{1}", config.WorkingSpacePath, model.MeshesPath);
auto material_path = fmt::format("{0}/{1}", config.WorkingSpacePath, model.MaterialsPath);

#ifdef _WIN32
std::replace(model_path.begin(), model_path.end(), '/', '\\');
std::replace(mesh_path.begin(), mesh_path.end(), '/', '\\');
std::replace(material_path.begin(), material_path.end(), '/', '\\');
#endif // _WIN32

auto import_data = Importers::IAssetImporter::DeserializeImporterData(model_path, mesh_path, material_path);
scene_data.push_back(import_data.Scene);
}

if (!scene_data.empty())
{
ZEngine::Rendering::Scenes::GraphicScene::Merge(scene_data);
}

Editor::SetCurrentEditorScene(std::move(scene));
ZENGINE_CORE_INFO("Scene {} deserialized successfully", ctx->CurrentScenePtr->Name)
}

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

if (!scene_filename.empty())
{
#ifdef _WIN32
std::replace(scene_filename.begin(), scene_filename.end(), '/', '\\'); // Todo : Move this replace into an helper function....
#endif
m_editor_serializer->Deserialize(scene_filename);
}
}
Expand Down
20 changes: 10 additions & 10 deletions Tetragrama/Components/DockspaceUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Tetragrama::Components
class DockspaceUIComponent : public UIComponent
{
public:
DockspaceUIComponent(std::string_view name = "Dockspace", bool visibility = true);
DockspaceUIComponent(Layers::ImguiLayer* parent = nullptr, std::string_view name = "Dockspace", bool visibility = true);
virtual ~DockspaceUIComponent();

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

void RenderMenuBar();
void RenderSaveScene();
Expand All @@ -27,18 +27,18 @@ namespace Tetragrama::Components
*/
void RenderImporter();
void ResetImporterBuffers();
static void OnAssetImporterComplete(Importers::ImporterData&&);
static void OnAssetImporterProgress(float value);
static void OnAssetImporterError(std::string_view);
static void OnAssetImporterLog(std::string_view);
static void OnAssetImporterComplete(void* const, Importers::ImporterData&&);
static void OnAssetImporterProgress(void* const, float value);
static void OnAssetImporterError(void* const, std::string_view);
static void OnAssetImporterLog(void* const, std::string_view);

/*
* Editor Scene Funcs
*/
static void OnEditorSceneSerializerProgress(float value);
static void OnEditorSceneSerializerComplete();
static void OnEditorSceneSerializerDeserializeComplete(EditorScene&&);
static void OnEditorSceneSerializerError(std::string_view);
static void OnEditorSceneSerializerProgress(void* const, float value);
static void OnEditorSceneSerializerComplete(void* const);
static void OnEditorSceneSerializerDeserializeComplete(void* const, EditorScene&&);
static void OnEditorSceneSerializerError(void* const, std::string_view);

std::future<void> OnNewSceneAsync();
std::future<void> OnOpenSceneAsync();
Expand Down
Loading

0 comments on commit baa9bd4

Please sign in to comment.