Skip to content

Commit

Permalink
Pipeline configs moved to mesh data + more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Aug 10, 2024
1 parent a9e7d08 commit 7c458c9
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 48 deletions.
Binary file added data/editor/icons/environment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/editor/icons/environment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/editor/icons/environment_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/editor/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace Atlas::Editor {
ContentDiscovery::Update();
Singletons::imguiWrapper->Update(&window, deltaTime);

Singletons::blockingOperation->Update();

if (Singletons::blockingOperation->block)
return;

Expand Down
16 changes: 13 additions & 3 deletions src/editor/BlockingOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <future>
#include <string>
#include <optional>

namespace Atlas::Editor {

Expand All @@ -11,15 +12,24 @@ namespace Atlas::Editor {
void Block(const std::string& text, std::function<void()> blocker) {
if (future.valid())
future.get();
block = true;
this->blocker = blocker;
blockText = text;
future = std::async(std::launch::async, [blocker, &block = block] {
blocker();
}

void Update() {
if (!blocker.has_value())
return;

block = true;
future = std::async(std::launch::async, [blocker = blocker, &block = block] {
blocker.value()();
block = false;
});
blocker = {};
}

std::future<void> future;
std::optional<std::function<void()>> blocker;
std::string blockText;
bool block = false;

Expand Down
3 changes: 3 additions & 0 deletions src/editor/Content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace Atlas::Editor {
{ "lua", ContentType::Script },
{ "ttf", ContentType::Font },
{ "aeprefab", ContentType::Prefab },
{ "jpg", ContentType::Texture },
{ "png", ContentType::Texture },
{ "hdr", ContentType::EnvironmentTexture },
};

}
2 changes: 2 additions & 0 deletions src/editor/Content.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Atlas::Editor {
Script,
Font,
Prefab,
Texture,
EnvironmentTexture,
None
};

Expand Down
5 changes: 5 additions & 0 deletions src/editor/ContentDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace Atlas::Editor {

Ref<ContentDiscovery::DiscoveredContent> ContentDiscovery::PerformContentDiscovery() {

auto start = Clock::Get();

auto assetDirectory = Loader::AssetLoader::GetAssetDirectory();

auto rootDirectory = CreateRef<ContentDirectory>({
Expand All @@ -81,6 +83,9 @@ namespace Atlas::Editor {

DiscoverDirectory(rootDirectory, result);

auto end = Clock::Get();
Log::Warning("Discovery took " + std::to_string(end - start) + "s");

return result;

}
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace Atlas::Editor {
{ IconType::MoreHorizontal, Texture::Texture2D("editor/icons/more_horiz.png") },
{ IconType::Material, Texture::Texture2D("editor/icons/material.png") },
{ IconType::MeshSource, Texture::Texture2D("editor/icons/meshSource.png") },
{ IconType::EnvironmentImage, Texture::Texture2D("editor/icons/environment.png") },
};
}
else {
Expand Down Expand Up @@ -79,6 +80,7 @@ namespace Atlas::Editor {
{ IconType::MoreHorizontal, Texture::Texture2D("editor/icons/more_horiz_light.png") },
{ IconType::Material, Texture::Texture2D("editor/icons/material_light.png") },
{ IconType::MeshSource, Texture::Texture2D("editor/icons/meshSource_light.png") },
{ IconType::EnvironmentImage, Texture::Texture2D("editor/icons/environment_light.png") },
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/editor/Icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace Atlas::Editor {
Rotate,
MoreHorizontal,
Material,
MeshSource
MeshSource,
EnvironmentImage
};

class Icons {
Expand Down
13 changes: 11 additions & 2 deletions src/editor/Notifications.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Notifications.h"
#include "Singletons.h"

#include "common/Hash.h"
#include "Log.h"
Expand Down Expand Up @@ -27,6 +28,8 @@ namespace Atlas::Editor {
auto viewport = ImGui::GetMainViewport();
auto viewportSize = viewport->Size;

auto config = Singletons::config;

std::scoped_lock lock(mutex);

std::vector<uint32_t> toBeRemoved;
Expand Down Expand Up @@ -58,8 +61,14 @@ namespace Atlas::Editor {
HashCombine(hash, notification.message);
HashCombine(hash, notification.creationTime);

ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.5f, 0.5f, 0.5f, alpha * 0.9f));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.1f, 0.1f, 0.1f, alpha * 0.9f));
if (config->darkMode) {
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.5f, 0.5f, 0.5f, alpha * 0.9f));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.1f, 0.1f, 0.1f, alpha * 0.9f));
}
else {
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.1f, 0.1f, 0.1f, alpha * 0.9f));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.7f, 0.7f, 0.7f, alpha * 0.9f));
}

auto windowName = "Notification##" + std::to_string(hash);
ImGui::Begin(windowName.c_str(), nullptr, notificationWindowFlags);
Expand Down
12 changes: 10 additions & 2 deletions src/editor/ui/panels/PopupPanels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,16 @@ namespace Atlas::Editor::UI {
ImGui::OpenPopup("Blocking popup");
}

ImGui::PushStyleColor(ImGuiCol_PopupBg, ImVec4(0.0f, 0.0f, 0.0f, 0.7f));
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
auto config = Singletons::config;

if (config->darkMode) {
ImGui::PushStyleColor(ImGuiCol_PopupBg, ImVec4(0.0f, 0.0f, 0.0f, 0.7f));
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
}
else {
ImGui::PushStyleColor(ImGuiCol_PopupBg, ImVec4(1.0f, 1.0f, 1.0f, 0.7f));
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
}
ImGui::PushStyleVar(ImGuiStyleVar_PopupBorderSize, 2.0f);

SetupPopupSize(0.2f, 0.05f);
Expand Down
2 changes: 1 addition & 1 deletion src/editor/ui/panels/components/MeshComponentPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Atlas::Editor::UI {
materialsPanel.Render(Singletons::imguiWrapper, mesh->data.materials);

// Just update materials regardless of any change
mesh->UpdateMaterials();
mesh->UpdatePipelines();
}

return resourceChanged;
Expand Down
7 changes: 5 additions & 2 deletions src/editor/ui/windows/ContentBrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ namespace Atlas::Editor::UI {

ImGui::Separator();

const char *items[] = {"Audio", "Mesh", "Mesh source", "Material", "Terrain", "Scene", "Script", "Font", "Prefab"};
const char *items[] = {"Audio", "Mesh", "Mesh source", "Material", "Terrain", "Scene",
"Script", "Font", "Prefab", "Texture", "Environment texture"};
for (int i = 0; i < IM_ARRAYSIZE(items); i++) {
bool isSelected = selectedFilter == i;
ImGui::Selectable(items[i], &isSelected, ImGuiSelectableFlags_SpanAvailWidth);
Expand Down Expand Up @@ -292,7 +293,7 @@ namespace Atlas::Editor::UI {

if (ImGui::BeginPopupContextItem()) {
// Do a direct import here without relying on the file importer
if (type == ContentType::Mesh && ImGui::MenuItem("Import as scene")) {
if (type == ContentType::MeshSource && ImGui::MenuItem("Import as scene")) {
PopupPanels::filename = assetRelativePath;
PopupPanels::isImportScenePopupVisible = true;
}
Expand Down Expand Up @@ -355,6 +356,8 @@ namespace Atlas::Editor::UI {
case ContentType::Scene: return icons->Get(IconType::Scene);
case ContentType::Font: return icons->Get(IconType::Font);
case ContentType::Prefab: return icons->Get(IconType::Prefab);
case ContentType::Texture: return icons->Get(IconType::Image);
case ContentType::EnvironmentTexture: return icons->Get(IconType::EnvironmentImage);
default: return icons->Get(IconType::Document);
}

Expand Down
7 changes: 0 additions & 7 deletions src/engine/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,4 @@ namespace Atlas {

}

void Material::SetChanged() {

mainConfig = PipelineConfig{};
shadowConfig = PipelineConfig{};

}

}
6 changes: 0 additions & 6 deletions src/engine/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "texture/Texture.h"
#include "texture/Texture2DArray.h"
#include "loader/ImageLoader.h"
#include "pipeline/PipelineConfig.h"
#include "resource/Resource.h"
#include "common/Ref.h"

Expand All @@ -26,8 +25,6 @@ namespace Atlas {
bool HasAoMap() const;
bool HasDisplacementMap() const;

void SetChanged();

std::string name;

ResourceHandle<Texture::Texture2D> baseColorMap;
Expand Down Expand Up @@ -62,9 +59,6 @@ namespace Atlas {

uint32_t uvChannel = 0;

PipelineConfig mainConfig;
PipelineConfig shadowConfig;

};


Expand Down
4 changes: 4 additions & 0 deletions src/engine/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ namespace Atlas {
auto meshes = scene->GetMeshes();
std::map<Hash, ResourceHandle<Material>> materials;

std::sort(meshes.begin(), meshes.end(), [](const auto& mesh0, const auto& mesh1) {
return mesh0->data.GetVertexCount() > mesh1->data.GetVertexCount();
});

if (multithreaded) {
std::atomic_int32_t counter = 0;

Expand Down
7 changes: 4 additions & 3 deletions src/engine/mesh/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ namespace Atlas {

}

void Mesh::UpdateMaterials() {
void Mesh::UpdatePipelines() {

for (const auto& material : data.materials) {
material->SetChanged();
for (auto& subData : data.subData) {
subData.mainConfig = PipelineConfig();
subData.shadowConfig = PipelineConfig();
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/mesh/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Atlas {
/*
* Resets material pipeline configs
*/
void UpdateMaterials();
void UpdatePipelines();

/**
* Updates the vertex array based on the state of the vertex buffers.
Expand Down
4 changes: 4 additions & 0 deletions src/engine/mesh/MeshData.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "resource/Resource.h"
#include "DataComponent.h"
#include "Material.h"
#include "pipeline/PipelineConfig.h"

#include <vector>

Expand All @@ -28,6 +29,9 @@ namespace Atlas {
int32_t materialIdx;

Volume::AABB aabb;

PipelineConfig mainConfig;
PipelineConfig shadowConfig;

};

Expand Down
18 changes: 9 additions & 9 deletions src/engine/renderer/OpaqueRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ namespace Atlas {
for (int32_t i = 0; i < subDataCount; i++) {
auto& [subData, _, mesh] = subDatas[i];
const auto& material = subData->material;
if (material->mainConfig.IsValid()) continue;
if (subData->mainConfig.IsValid()) continue;

material->mainConfig = GetPipelineConfigForSubData(subData, mesh, target);
subData->mainConfig = GetPipelineConfigForSubData(subData, mesh, target);
}

// Sort materials by hash
std::sort(subDatas.begin(), subDatas.begin() + size_t(subDataCount),
[](auto& subData0, auto& subData1) {
return std::get<0>(subData0)->material->mainConfig.variantHash <
std::get<0>(subData1)->material->mainConfig.variantHash;
return std::get<0>(subData0)->mainConfig.variantHash <
std::get<0>(subData1)->mainConfig.variantHash;
});

Hash prevMesh = 0;
Expand All @@ -72,12 +72,12 @@ namespace Atlas {
const auto material = subData->material;

// Overwrite material config frame buffer (and assume these have the same format)
material->mainConfig.graphicsPipelineDesc.frameBuffer = target->gBufferFrameBuffer;
subData->mainConfig.graphicsPipelineDesc.frameBuffer = target->gBufferFrameBuffer;

if (material->mainConfig.variantHash != prevHash) {
currentPipeline = PipelineManager::GetPipeline(material->mainConfig);
if (subData->mainConfig.variantHash != prevHash) {
currentPipeline = PipelineManager::GetPipeline(subData->mainConfig);
commandList->BindPipeline(currentPipeline);
prevHash = material->mainConfig.variantHash;
prevHash = subData->mainConfig.variantHash;
}

if (meshID != prevMesh) {
Expand Down Expand Up @@ -127,7 +127,7 @@ namespace Atlas {
0, instances.offset);

// Reset the frame buffer here to let it be able to be deleted
material->mainConfig.graphicsPipelineDesc.frameBuffer = nullptr;
subData->mainConfig.graphicsPipelineDesc.frameBuffer = nullptr;

}

Expand Down
18 changes: 9 additions & 9 deletions src/engine/renderer/ShadowRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ namespace Atlas {
for (int32_t i = 0; i < subDataCount; i++) {
auto& [subData, _, mesh] = subDatas[i];
const auto& material = subData->material;
if (material->shadowConfig.IsValid()) continue;
if (subData->shadowConfig.IsValid()) continue;

material->shadowConfig = GetPipelineConfigForSubData(subData, mesh, frameBuffer);
subData->shadowConfig = GetPipelineConfigForSubData(subData, mesh, frameBuffer);
}

// Sort materials by hash
std::sort(subDatas.begin(), subDatas.begin() + size_t(subDataCount),
[](auto& subData0, auto& subData1) {
return std::get<0>(subData0)->material->shadowConfig.variantHash <
std::get<0>(subData1)->material->shadowConfig.variantHash;
return std::get<0>(subData0)->shadowConfig.variantHash <
std::get<0>(subData1)->shadowConfig.variantHash;
});

Hash prevHash = 0;
Expand All @@ -143,12 +143,12 @@ namespace Atlas {
auto material = subData->material;

// Overwrite material config frame buffer (and assume these have the same format)
material->shadowConfig.graphicsPipelineDesc.frameBuffer = frameBuffer;
subData->shadowConfig.graphicsPipelineDesc.frameBuffer = frameBuffer;

if (material->shadowConfig.variantHash != prevHash) {
currentPipeline = PipelineManager::GetPipeline(material->shadowConfig);
if (subData->shadowConfig.variantHash != prevHash) {
currentPipeline = PipelineManager::GetPipeline(subData->shadowConfig);
commandList->BindPipeline(currentPipeline);
prevHash = material->shadowConfig.variantHash;
prevHash = subData->shadowConfig.variantHash;
}

if (meshID != prevMesh) {
Expand Down Expand Up @@ -176,7 +176,7 @@ namespace Atlas {
0, instances.offset);

// Reset the frame buffer here to let it be able to be deleted
material->shadowConfig.graphicsPipelineDesc.frameBuffer = nullptr;
subData->shadowConfig.graphicsPipelineDesc.frameBuffer = nullptr;

}

Expand Down
Loading

0 comments on commit 7c458c9

Please sign in to comment.