Skip to content

Commit

Permalink
Introducing Async Resources Loader (JeanPhilippeKernel#404)
Browse files Browse the repository at this point in the history
* Introduce Async Resource Loader

* clang formatted code

* adjusted queue selection

* updated swapchain

* fixed frame sync

* updated externals deps

* added mutex and tests to handlemanager

* vulkan 1.3.296

* vulkan 1.3.290

* include thread

* attemps to temp fix rendering crash

* Rethinking Rendering (JeanPhilippeKernel#406)

* rendering idea

* fixed rendering crash

* fixed crash imgui crash on integrated GPU

* fixed image view deletion

* render graph is back

* fixed rendering crash on integrated GPU

* moved render target storage into global texture

* make async resource loading a reality

* checked device available transfer queue

* async loading res works! 🎉

* reset the depth clear to 1

* migrated buffers to use handle as ref

* removed commented codes

* fixed macOS build

* fixed renderer deps cycle

* removed swapchain definition files

* updated environment map

* fixed textures deletion bug

* Fixed resource deletion process (JeanPhilippeKernel#407)

* rendering idea

* fixed rendering crash

* fixed crash imgui crash on integrated GPU

* fixed image view deletion

* render graph is back

* fixed rendering crash on integrated GPU

* moved render target storage into global texture

* make async resource loading a reality

* checked device available transfer queue

* async loading res works! 🎉

* reset the depth clear to 1

* migrated buffers to use handle as ref

* removed commented codes

* fixed macOS build

* fixed renderer deps cycle

* removed swapchain definition files

* updated environment map

* fixed textures deletion bug

* fixed handling resource deletion proc

* Simplifying Graphic Renderer definition (JeanPhilippeKernel#408)

* rendering idea

* fixed rendering crash

* fixed crash imgui crash on integrated GPU

* fixed image view deletion

* render graph is back

* fixed rendering crash on integrated GPU

* moved render target storage into global texture

* make async resource loading a reality

* checked device available transfer queue

* async loading res works! 🎉

* reset the depth clear to 1

* migrated buffers to use handle as ref

* removed commented codes

* fixed macOS build

* fixed renderer deps cycle

* removed swapchain definition files

* updated environment map

* fixed textures deletion bug

* fixed handling resource deletion proc

* simplify renderer impl

* added back support of bindless textures

* reworking on skybox pass

* fixed skybox pass to use drawindexed

* simplified skybox shader code

* improved grid pass and render graph

* added support of enable - disable render node

---------

Co-authored-by: jnyfah <[email protected]>
  • Loading branch information
JeanPhilippeKernel and jnyfah authored Jan 4, 2025
1 parent 1e5e35b commit c327fb0
Show file tree
Hide file tree
Showing 96 changed files with 4,143 additions and 3,425 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 9 additions & 6 deletions Resources/Shaders/infinite_grid.vert
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#version 460
#extension GL_GOOGLE_include_directive : require
#include "vertex_common.glsl"

layout (location = 0) in vec3 pos;
layout (location = 0) out vec2 uv;
layout (location = 1) out float scaleFactor;

layout(set = 0, binding = 0) uniform UBCamera
{
mat4 View;
mat4 Projection;
vec4 Position;
} Camera;

void main()
{
scaleFactor = 80.0;

DrawDataView dataView = GetDrawDataView();
vec3 posScale = vec3((dataView.Vertex * scaleFactor).xyz);
vec3 posScale = pos * scaleFactor;
uv = posScale.xz;
gl_Position = Camera.Projection * Camera.View * vec4(posScale, 1.0);
gl_Position = Camera.Projection * Camera.View * vec4(posScale, 1.0);
}
8 changes: 8 additions & 0 deletions Resources/Shaders/initial.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 460

layout (location = 0) out vec4 outColor;

void main()
{
outColor = vec4(vec3(0.0f), 1.0f);
}
15 changes: 15 additions & 0 deletions Resources/Shaders/initial.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 460

layout (location = 0) in vec3 pos;

layout(set = 0, binding = 0) uniform UBCamera
{
mat4 View;
mat4 Projection;
vec4 Position;
} Camera;

void main()
{
gl_Position = vec4(pos, 1.0f);
}
6 changes: 2 additions & 4 deletions Resources/Shaders/skybox.frag
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#version 460

layout (location = 0) in vec3 dir;

layout (location = 0) out vec4 outColor;

layout(set = 0, binding = 5) uniform samplerCube CubemapTexture;
layout(set = 0, binding = 1) uniform samplerCube EnvMap;

void main()
{
outColor = texture(CubemapTexture, dir);
outColor = texture(EnvMap, dir);
}
20 changes: 12 additions & 8 deletions Resources/Shaders/skybox.vert
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#version 460
#extension GL_GOOGLE_include_directive : require
#include "vertex_common.glsl"

layout (location = 0) in vec3 pos;
layout (location = 0) out vec3 dir;

layout(set = 0, binding = 0) uniform UBCamera
{
mat4 View;
mat4 Projection;
vec4 Position;
} Camera;

void main()
{
DrawVertex v = FetchVertexData();

dir = vec3(v.x, -v.y, v.z);
vec4 position = Camera.Projection * Camera.RotScaleView * vec4(v.x, v.y, v.z, 1.0f);
gl_Position = position.xyww;
dir = normalize(vec3(pos.x, -pos.y, pos.z));
mat4 rotScaleView = mat4(mat3(Camera.View));
vec4 position = Camera.Projection * rotScaleView * vec4(pos, 1.0f);
gl_Position = position.xyww;
}
1 change: 0 additions & 1 deletion Resources/Shaders/vertex_common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct DrawDataView
layout(set = 0, binding = 0) uniform UBCamera
{
mat4 View;
mat4 RotScaleView;
mat4 Projection;
vec4 Position;
} Camera;
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() override
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override
{
ImGui::ShowAboutWindow(&m_is_open);
}
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/DemoUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Tetragrama::Components
DemoUIComponent(std::string_view name = "DemoUIComponent", bool visibility = true) : UIComponent(name, visibility, true) {}
virtual ~DemoUIComponent() = default;

virtual void Render() override
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override
{
ImGui::ShowDemoWindow(&m_is_open);
}
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/DockspaceUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Tetragrama::Components

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

void DockspaceUIComponent::Render()
void DockspaceUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
{
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/DockspaceUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Tetragrama::Components
virtual ~DockspaceUIComponent();

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

void RenderMenuBar();
void RenderSaveScene();
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/HierarchyViewUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Tetragrama::Components
co_return;
}

void HierarchyViewUIComponent::Render()
void HierarchyViewUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
{
ImGui::Begin(m_name.c_str(), (m_can_be_closed ? &m_can_be_closed : NULL), ImGuiWindowFlags_NoCollapse);
if (ImGui::BeginPopupContextWindow(m_name.c_str()))
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/HierarchyViewUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Tetragrama::Components
virtual ~HierarchyViewUIComponent();

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

void RenderTreeNodes();
void RenderGuizmo();
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/InspectorViewUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace Tetragrama::Components
co_return;
}

void InspectorViewUIComponent::Render()
void InspectorViewUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
{
if (m_recieved_deleted_request || m_recieved_unselected_request)
{
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/InspectorViewUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Tetragrama::Components

void Update(ZEngine::Core::TimeStep dt) override;

virtual void Render() override;
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override;

public:
std::future<void> SceneAvailableMessageHandlerAsync(Messengers::GenericMessage<ZEngine::Helpers::Ref<ZEngine::Rendering::Scenes::GraphicScene>>&);
Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/LogUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Tetragrama::Components
}
}

void LogUIComponent::Render()
void LogUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
{
ImGui::Begin(m_name.c_str(), (m_can_be_closed ? &m_can_be_closed : NULL), ImGuiWindowFlags_NoCollapse);

Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/LogUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Tetragrama::Components
virtual ~LogUIComponent();

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

void OnLog(ZEngine::Logging::LogMessage);

Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/ProjectViewUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Tetragrama::Components

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

void ProjectViewUIComponent::Render()
void ProjectViewUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
{
ImGui::Begin(m_name.c_str(), (m_can_be_closed ? &m_can_be_closed : NULL), ImGuiWindowFlags_NoCollapse);

Expand Down
2 changes: 1 addition & 1 deletion Tetragrama/Components/ProjectViewUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ namespace Tetragrama::Components

void Update(ZEngine::Core::TimeStep dt) override;

virtual void Render() override;
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer) override;
};
} // namespace Tetragrama::Components
43 changes: 28 additions & 15 deletions Tetragrama/Components/SceneViewportUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ namespace Tetragrama::Components
{
if ((m_viewport_size.x != m_content_region_available_size.x) || (m_viewport_size.y != m_content_region_available_size.y))
{
m_viewport_size = m_content_region_available_size;
m_request_renderer_resize = true;
}
if (!m_is_resizing)
{
m_is_resizing = true;
}

if (m_request_renderer_resize)
m_viewport_size = m_content_region_available_size;
m_idle_frame_count = 0;
}
else if (m_is_resizing)
{
GraphicRenderer::SetViewportSize(m_viewport_size.x, m_viewport_size.y);
m_refresh_texture_handle = true;

Messengers::IMessenger::SendAsync<Windows::Layers::Layer, Messengers::GenericMessage<std::pair<float, float>>>(
EDITOR_RENDER_LAYER_SCENE_REQUEST_RESIZE, Messengers::GenericMessage<std::pair<float, float>>{{m_viewport_size.x, m_viewport_size.y}});

m_request_renderer_resize = false;
m_idle_frame_count++;
if (m_idle_frame_count >= m_idle_frame_threshold)
{
m_is_resizing = false;
m_request_renderer_resize = true;
}
}

if (m_is_window_hovered && m_is_window_focused)
Expand Down Expand Up @@ -70,13 +73,12 @@ namespace Tetragrama::Components
}
}

void SceneViewportUIComponent::Render()
void SceneViewportUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
{
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin(m_name.c_str(), (m_can_be_closed ? &m_can_be_closed : NULL), ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove);

auto viewport_offset = ImGui::GetCursorPos();

auto viewport_offset = ImGui::GetCursorPos();
m_content_region_available_size = ImGui::GetContentRegionAvail();
m_is_window_focused = ImGui::IsWindowFocused();
m_is_window_hovered = ImGui::IsWindowHovered();
Expand All @@ -85,7 +87,7 @@ namespace Tetragrama::Components
// Scene texture representation
if (!m_scene_texture || m_refresh_texture_handle)
{
m_scene_texture = GraphicRenderer::GetImguiFrameOutput();
m_scene_texture = renderer->GetImguiFrameOutput();
m_refresh_texture_handle = false;
}

Expand All @@ -109,6 +111,17 @@ namespace Tetragrama::Components
ImGui::End();

ImGui::PopStyleVar();

if (m_request_renderer_resize)
{
renderer->EnqueuedResizeRequests.Emplace({.Width = (uint32_t) m_viewport_size.x, .Height = (uint32_t) m_viewport_size.y});
m_refresh_texture_handle = true;

Messengers::IMessenger::SendAsync<Windows::Layers::Layer, Messengers::GenericMessage<std::pair<float, float>>>(
EDITOR_RENDER_LAYER_SCENE_REQUEST_RESIZE, Messengers::GenericMessage<std::pair<float, float>>{{m_viewport_size.x, m_viewport_size.y}});

m_request_renderer_resize = false;
}
}

std::future<void> SceneViewportUIComponent::SceneViewportClickedMessageHandlerAsync(Messengers::ArrayValueMessage<int, 2>& e)
Expand Down
5 changes: 4 additions & 1 deletion Tetragrama/Components/SceneViewportUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Tetragrama::Components
virtual ~SceneViewportUIComponent();

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

public:
std::future<void> SceneViewportClickedMessageHandlerAsync(Messengers::ArrayValueMessage<int, 2>&);
Expand All @@ -29,6 +29,9 @@ namespace Tetragrama::Components
bool m_is_window_clicked{false};
bool m_refresh_texture_handle{false};
bool m_request_renderer_resize{false};
bool m_is_resizing{false};
int m_idle_frame_count = 0;
int m_idle_frame_threshold = 9; // SwapchainImageCount * 3
ImVec2 m_viewport_size{0.f, 0.f};
ImVec2 m_content_region_available_size{0.f, 0.f};
std::array<ImVec2, 2> m_viewport_bounds;
Expand Down
33 changes: 15 additions & 18 deletions Tetragrama/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ using namespace ZEngine::Windows::Events;
using namespace ZEngine::Windows;
using namespace ZEngine::Rendering;
using namespace ZEngine::Helpers;
using namespace ZEngine::Hardwares;
using namespace ZEngine::Rendering::Renderers;

namespace Tetragrama
{
EditorWindow::EditorWindow(const WindowConfiguration& configuration) : CoreWindow()
EditorWindow::EditorWindow(const WindowConfiguration& configuration) : CoreWindow(configuration)
{
m_property.Height = configuration.Height;
m_property.Width = configuration.Width;
Expand Down Expand Up @@ -136,7 +138,16 @@ namespace Tetragrama

void EditorWindow::Initialize()
{
m_swapchain = CreateRef<Rendering::Swapchain>();
for (const auto& layer : m_configuration.RenderingLayerCollection)
{
PushLayer(layer);
}

for (const auto& layer : m_configuration.OverlayLayerCollection)
{
PushOverlayLayer(layer);
}
InitializeLayer();

glfwSetWindowUserPointer(m_native_window, &m_property);

Expand Down Expand Up @@ -179,8 +190,6 @@ namespace Tetragrama
{
(*rlayer_it)->Deinitialize();
}

m_swapchain.reset();
}

void EditorWindow::PollEvent()
Expand Down Expand Up @@ -362,14 +371,12 @@ namespace Tetragrama
}
}

void EditorWindow::Render()
void EditorWindow::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers::CommandBuffer* const command_buffer)
{
for (const Ref<Layers::Layer>& layer : *m_layer_stack_ptr)
{
layer->Render();
layer->Render(renderer, command_buffer);
}

m_swapchain->Present();
}

std::future<std::string> EditorWindow::OpenFileDialogAsync(std::span<std::string_view> type_filters)
Expand Down Expand Up @@ -430,11 +437,6 @@ namespace Tetragrama
return outputs;
}

Ref<Rendering::Swapchain> EditorWindow::GetSwapchain() const
{
return m_swapchain;
}

EditorWindow::~EditorWindow()
{
glfwSetErrorCallback(NULL);
Expand All @@ -460,11 +462,6 @@ namespace Tetragrama

bool EditorWindow::OnWindowResized(WindowResizedEvent& event)
{
if (event.GetWidth() > 0 && event.GetHeight() > 0)
{
m_swapchain->Resize();
}

ZENGINE_CORE_INFO("Window has been resized")

Core::EventDispatcher event_dispatcher(event);
Expand Down
Loading

0 comments on commit c327fb0

Please sign in to comment.