Skip to content

Commit

Permalink
Added shader reload button to the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
adepke committed Apr 21, 2022
1 parent 735371c commit f5d8078
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions VanguardEngine/Source/Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void Editor::Render(RenderGraph& graph, RenderDevice& device, Renderer& renderer
ui->DrawLayout();
ui->DrawDemoWindow();
ui->DrawScene(&device, registry, resources.GetTexture(outputLDR));
ui->DrawControls(&device);
ui->DrawEntityHierarchy(registry);
ui->DrawEntityPropertyViewer(registry);
ui->DrawMetrics(&device, renderer.lastFrameTime);
Expand Down
17 changes: 17 additions & 0 deletions VanguardEngine/Source/Editor/EditorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void EditorUI::DrawMenu()
{
if (ImGui::BeginMenu("View"))
{
ImGui::MenuItem("Controls", nullptr, &controlsOpen);
ImGui::MenuItem("Entity Hierarchy", nullptr, &entityHierarchyOpen);
ImGui::MenuItem("Entity Properties", nullptr, &entityPropertyViewerOpen);
ImGui::MenuItem("Metrics", nullptr, &metricsOpen);
Expand Down Expand Up @@ -206,6 +207,22 @@ void EditorUI::DrawScene(RenderDevice* device, entt::registry& registry, Texture
ImGui::PopStyleVar();
}

void EditorUI::DrawControls(RenderDevice* device)
{
if (controlsOpen)
{
if (ImGui::Begin("Controls", &controlsOpen))
{
if (ImGui::Button("Reload Shaders"))
{
Renderer::Get().ReloadShaderPipelines();
}
}

ImGui::End();
}
}

void EditorUI::DrawEntityHierarchy(entt::registry& registry)
{
if (entityHierarchyOpen)
Expand Down
2 changes: 2 additions & 0 deletions VanguardEngine/Source/Editor/EditorUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class EditorUI
bool fullscreen = false;

// Window states.
bool controlsOpen = true;
bool entityHierarchyOpen = true;
bool entityPropertyViewerOpen = true;
bool metricsOpen = true;
Expand Down Expand Up @@ -67,6 +68,7 @@ class EditorUI
void DrawLayout();
void DrawDemoWindow();
void DrawScene(RenderDevice* device, entt::registry& registry, TextureHandle sceneTexture);
void DrawControls(RenderDevice* device);
void DrawEntityHierarchy(entt::registry& registry);
void DrawEntityPropertyViewer(entt::registry& registry);
void DrawMetrics(RenderDevice* device, float frameTimeMs);
Expand Down
11 changes: 9 additions & 2 deletions VanguardEngine/Source/Rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ void Renderer::Render(entt::registry& registry)
{
VGScopedCPUStat("Render");

// Check if shaders need to be reloaded here since we might be requested at anytime during the frame.
if (shouldReloadShaders)
{
device->Synchronize();
renderGraphResources.DiscardPipelines();
shouldReloadShaders = false;
}

// Only run once for now since this becomes the bottleneck running every frame with 100k+ objects.
static bool objectsUpdated = false;
if (!objectsUpdated)
Expand Down Expand Up @@ -567,6 +575,5 @@ void Renderer::SetResolution(uint32_t width, uint32_t height, bool fullscreen)

void Renderer::ReloadShaderPipelines()
{
device->Synchronize();
renderGraphResources.DiscardPipelines();
shouldReloadShaders = true;
}
2 changes: 2 additions & 0 deletions VanguardEngine/Source/Rendering/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Renderer : public Singleton<Renderer>

BufferHandle meshIndirectRenderArgs;

bool shouldReloadShaders = false;

private:
void CreateRootSignature();
std::vector<MeshRenderable> UpdateObjects(const entt::registry& registry);
Expand Down

0 comments on commit f5d8078

Please sign in to comment.