Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework asset system to use binary serializing instead of text format #51

Merged
merged 19 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Volt/Launcher/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ project "Launcher"
"%{IncludeDir.fastlz}",

"%{IncludeDir.VulkanSDK}",
"%{IncludeDir.vma}"
"%{IncludeDir.vma}",
"%{IncludeDir.zlib}"
}

links
Expand Down Expand Up @@ -123,7 +124,8 @@ project "Launcher"
"%{Library.discord}",

"%{Library.Vulkan}",
"%{Library.dxc}"
"%{Library.dxc}",
"%{Library.zlib}"
}

debugargs
Expand Down
6 changes: 4 additions & 2 deletions Volt/Sandbox/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ project "Sandbox"
"%{IncludeDir.VulkanSDK}",
"%{IncludeDir.vma}",

"%{IncludeDir.TGAFbx}"
"%{IncludeDir.TGAFbx}",
"%{IncludeDir.zlib}"
}

links
Expand Down Expand Up @@ -163,7 +164,8 @@ project "Sandbox"
"%{Library.discord}",

"%{Library.Vulkan}",
"%{Library.dxc}"
"%{Library.dxc}",
"%{Library.zlib}"
}

debugargs
Expand Down
26 changes: 13 additions & 13 deletions Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <Volt/Asset/Prefab.h>

#include <Volt/Utility/UIUtility.h>
#include <Volt/Utility/FileIO/YAMLStreamReader.h>
#include <Volt/Utility/FileIO/YAMLFileStreamReader.h>

#include <Volt/Asset/Asset.h>
#include <Volt/Asset/Animation/AnimatedCharacter.h>
Expand Down Expand Up @@ -58,15 +58,15 @@ struct TypeIndexContainer
};

static std::unordered_map<PreV113PropertyType, TypeIndexContainer> s_preV113PropTypeToTypeIndexMap;
static std::unordered_map<std::type_index, std::function<void(Volt::YAMLStreamReader&, uint8_t*, const size_t)>> s_arrayDeserializers;
static std::unordered_map<std::type_index, std::function<void(Volt::YAMLFileStreamReader&, uint8_t*, const size_t)>> s_arrayDeserializers;
static std::unordered_map<VoltGUID, std::unordered_map<std::string, std::string>> s_componentMemberRemap;

static bool s_initialize = false;

template<typename T>
void RegisterArrayDeserializationFunction()
{
s_arrayDeserializers[std::type_index{ typeid(T) }] = [](Volt::YAMLStreamReader& streamReader, uint8_t* data, const size_t offset)
s_arrayDeserializers[std::type_index{ typeid(T) }] = [](Volt::YAMLFileStreamReader& streamReader, uint8_t* data, const size_t offset)
{
*reinterpret_cast<T*>(&data[offset]) = streamReader.ReadKey("value", T());
};
Expand Down Expand Up @@ -291,7 +291,7 @@ void ProjectUpgradeModal::ConvertAnimationGraphsToV0_1_2()
{
for (const auto& characterPath : characterAssets)
{
Volt::YAMLStreamReader metaStreamReader{};
Volt::YAMLFileStreamReader metaStreamReader{};

if (!metaStreamReader.OpenFile(characterPath.string() + ".vtmeta"))
{
Expand All @@ -306,7 +306,7 @@ void ProjectUpgradeModal::ConvertAnimationGraphsToV0_1_2()

if (characterAssetHandle == handle)
{
Volt::YAMLStreamReader charStreamReader{};
Volt::YAMLFileStreamReader charStreamReader{};

if (!charStreamReader.OpenFile(characterPath))
{
Expand Down Expand Up @@ -337,7 +337,7 @@ void ProjectUpgradeModal::ConvertAnimationGraphsToV0_1_2()
AnimGraphDescriptor& descriptor = animGraphDescriptors.emplace_back();
{ // convert the animgraph
{// parse meta
Volt::YAMLStreamReader metaStreamReader{};
Volt::YAMLFileStreamReader metaStreamReader{};

if (!metaStreamReader.OpenFile(animGraphPath.string() + ".vtmeta"))
{
Expand Down Expand Up @@ -677,7 +677,7 @@ void ProjectUpgradeModal::ConvertScenesToV113()

// Load scene name
{
Volt::YAMLStreamReader streamReader{};
Volt::YAMLFileStreamReader streamReader{};
if (!streamReader.OpenFile(sceneFilePath))
{
VT_CORE_ERROR("[Project Upgrade]: Unable to open scene file! Skipping!");
Expand Down Expand Up @@ -717,7 +717,7 @@ void ProjectUpgradeModal::ConvertScenesToV113()

void ProjectUpgradeModal::ConvertPreV113Prefab(const std::filesystem::path& filePath)
{
Volt::YAMLStreamReader streamReader{};
Volt::YAMLFileStreamReader streamReader{};
if (!streamReader.OpenFile(filePath))
{
return;
Expand Down Expand Up @@ -768,7 +768,7 @@ void ProjectUpgradeModal::ConvertPreV113Prefab(const std::filesystem::path& file

void ProjectUpgradeModal::DeserializePreV113SceneLayer(Ref<Volt::Scene> scene, Volt::SceneLayer& sceneLayer, const std::filesystem::path& layerPath, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping)
{
Volt::YAMLStreamReader streamReader{};
Volt::YAMLFileStreamReader streamReader{};

if (!streamReader.OpenFile(layerPath))
{
Expand All @@ -790,7 +790,7 @@ void ProjectUpgradeModal::DeserializePreV113SceneLayer(Ref<Volt::Scene> scene, V
streamReader.ExitScope();
}

void ProjectUpgradeModal::DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt::YAMLStreamReader& streamReader, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping, bool isPrefabEntity)
void ProjectUpgradeModal::DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt::YAMLFileStreamReader& streamReader, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping, bool isPrefabEntity)
{
if (!isPrefabEntity)
{
Expand Down Expand Up @@ -927,7 +927,7 @@ void ProjectUpgradeModal::DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt:
}
}

void ProjectUpgradeModal::DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLStreamReader& streamReader)
void ProjectUpgradeModal::DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLFileStreamReader& streamReader)
{
const auto& typeDeserializers = Volt::SceneImporter::GetTypeDeserializers();

Expand Down Expand Up @@ -1009,7 +1009,7 @@ void ProjectUpgradeModal::DeserializePreV113Component(uint8_t* componentData, co
});
}

void ProjectUpgradeModal::DeserializePreV113MonoScripts(Ref<Volt::Scene> scene, const Volt::EntityID entityId, Volt::YAMLStreamReader& streamReader)
void ProjectUpgradeModal::DeserializePreV113MonoScripts(Ref<Volt::Scene> scene, const Volt::EntityID entityId, Volt::YAMLFileStreamReader& streamReader)
{
Volt::Entity entity = scene->GetEntityFromUUID(entityId);
const auto& typeDeserializers = Volt::SceneImporter::GetTypeDeserializers();
Expand Down Expand Up @@ -1288,7 +1288,7 @@ const Volt::ComponentMember* ProjectUpgradeModal::TryGetComponentMemberFromName(

std::pair<std::filesystem::path, Volt::AssetHandle> ProjectUpgradeModal::DeserializeV0MetaFile(const std::filesystem::path& metaPath)
{
Volt::YAMLStreamReader streamReader{};
Volt::YAMLFileStreamReader streamReader{};

if (!streamReader.OpenFile(metaPath))
{
Expand Down
8 changes: 4 additions & 4 deletions Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Volt

class Scene;
struct SceneLayer;
class YAMLStreamReader;
class YAMLFileStreamReader;
}

class ProjectUpgradeModal : public Modal
Expand All @@ -40,9 +40,9 @@ class ProjectUpgradeModal : public Modal
void ConvertPreV113Prefab(const std::filesystem::path& filePath);

void DeserializePreV113SceneLayer(Ref<Volt::Scene> scene, Volt::SceneLayer& sceneLayer, const std::filesystem::path& layerPath, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping);
void DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt::YAMLStreamReader& streamReader, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping, bool isPrefabEntity);
void DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLStreamReader& streamReader);
void DeserializePreV113MonoScripts(Ref<Volt::Scene> scene, const Volt::EntityID entityId, Volt::YAMLStreamReader& streamReader);
void DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt::YAMLFileStreamReader& streamReader, std::map<Volt::EntityID, Volt::EntityID>& entityRemapping, bool isPrefabEntity);
void DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLFileStreamReader& streamReader);
void DeserializePreV113MonoScripts(Ref<Volt::Scene> scene, const Volt::EntityID entityId, Volt::YAMLFileStreamReader& streamReader);

void HandleEntityRemapping(Ref<Volt::Scene> scene, const std::map<Volt::EntityID, Volt::EntityID>& entityRemapping);
void HandleEntityArrayRemapping(Ref<Volt::Scene> scene, const std::map<Volt::EntityID, Volt::EntityID>& entityRemapping, const Volt::ComponentMember& componentMember, uint8_t* componentData);
Expand Down
3 changes: 2 additions & 1 deletion Volt/Sandbox/src/Sandbox/NodeGraph/IONodeGraphEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ inline IONodeGraphEditor<graphType, EditorBackend>::IONodeGraphEditor(const std:
SetGraphTypeText("GRAPHKEY");
}

myHeaderTexture = Volt::TextureImporter::ImportTexture("Editor/Textures/Graph/Translucency.dds");
myHeaderTexture = CreateRef<Volt::Texture2D>();
Volt::TextureImporter::ImportTexture("Editor/Textures/Graph/Translucency.dds", *myHeaderTexture);

{
Ref<NodeGraph::EditorContext> editorContext = CreateRef<NodeGraph::EditorContext>();
Expand Down
4 changes: 3 additions & 1 deletion Volt/Sandbox/src/Sandbox/Utility/AnimatedIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ AnimatedIcon::AnimatedIcon(const std::filesystem::path& firstFrame, uint32_t fra
for (uint32_t frame = 1; frame <= frameCount; frame++)
{
const std::filesystem::path path = dirPath / (filename + std::to_string(frame) + firstFrame.extension().string());
myTextures.emplace_back(Volt::TextureImporter::ImportTexture(path));

myTextures.emplace_back() = CreateRef<Volt::Texture2D>();
Volt::TextureImporter::ImportTexture(path, *myTextures.back());
}

VT_CORE_ASSERT(!myTextures.empty(), "No frames found!");
Expand Down
11 changes: 7 additions & 4 deletions Volt/Sandbox/src/Sandbox/Utility/EditorResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Volt/Asset/Importers/TextureImporter.h>
#include <Volt/Asset/Importers/MeshTypeImporter.h>

#include <Volt/Asset/Mesh/Mesh.h>

#include <Volt/Rendering/Shape.h>
#include <Volt/Rendering/Renderer.h>
#include <Volt/Rendering/Texture/Texture2D.h>
Expand Down Expand Up @@ -140,9 +142,10 @@ Ref<Volt::Mesh> EditorResources::GetEditorMesh(EditorMesh mesh)

Ref<Volt::Texture2D> EditorResources::TryLoadIcon(const std::filesystem::path& path)
{
Ref<Volt::Texture2D> texture = Volt::TextureImporter::ImportTexture(path);
Ref<Volt::Texture2D> texture = CreateRef<Volt::Texture2D>();
Volt::TextureImporter::ImportTexture(path, *texture);

if (!texture)
if (!texture->IsValid())
{
texture = Volt::Renderer::GetDefaultData().whiteTexture;
}
Expand All @@ -152,8 +155,8 @@ Ref<Volt::Texture2D> EditorResources::TryLoadIcon(const std::filesystem::path& p

Ref<Volt::Mesh> EditorResources::TryLoadMesh(const std::filesystem::path& path)
{
Ref<Volt::Mesh> mesh = Volt::MeshTypeImporter::ImportMesh(path);
if (!mesh)
Ref<Volt::Mesh> mesh = CreateRef<Volt::Mesh>();
if (!Volt::MeshTypeImporter::ImportMesh(path, *mesh))
{
mesh = Volt::Shape::CreateUnitCube();
}
Expand Down
20 changes: 10 additions & 10 deletions Volt/Sandbox/src/Sandbox/Utility/EditorUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ bool EditorUtils::ReimportSourceMesh(Volt::AssetHandle assetHandle, Ref<Volt::Sk
{
case Volt::AssetType::Animation:
{
Ref<Volt::Animation> newAnim = Volt::MeshTypeImporter::ImportAnimation(Volt::ProjectManager::GetDirectory() / sourcePath, targetSkeleton);
if (!newAnim)
Ref<Volt::Animation> newAnim = CreateRef<Volt::Animation>();
if (!Volt::MeshTypeImporter::ImportAnimation(Volt::ProjectManager::GetDirectory() / sourcePath, targetSkeleton, *newAnim))
{
UI::Notify(NotificationType::Error, "Unable to re import animation!", std::format("Failed to import animation from {0}!", sourcePath.string()));
break;
Expand All @@ -253,8 +253,8 @@ bool EditorUtils::ReimportSourceMesh(Volt::AssetHandle assetHandle, Ref<Volt::Sk

case Volt::AssetType::Skeleton:
{
Ref<Volt::Skeleton> newSkel = Volt::MeshTypeImporter::ImportSkeleton(Volt::ProjectManager::GetDirectory() / sourcePath);
if (!newSkel)
Ref<Volt::Skeleton> newSkel = CreateRef<Volt::Skeleton>();
if (!Volt::MeshTypeImporter::ImportSkeleton(Volt::ProjectManager::GetDirectory() / sourcePath, *newSkel))
{
UI::Notify(NotificationType::Error, "Unable to re import skeleton!", std::format("Failed to import skeleton from {0}!", sourcePath.string()));
break;
Expand All @@ -274,8 +274,8 @@ bool EditorUtils::ReimportSourceMesh(Volt::AssetHandle assetHandle, Ref<Volt::Sk
{
Ref<Volt::Mesh> originalMesh = std::reinterpret_pointer_cast<Volt::Mesh>(originalAsset);

Ref<Volt::Mesh> newMesh = Volt::MeshTypeImporter::ImportMesh(Volt::ProjectManager::GetDirectory() / sourcePath);
if (!newMesh || !newMesh->IsValid())
Ref<Volt::Mesh> newMesh = CreateRef<Volt::Mesh>();
if (!Volt::MeshTypeImporter::ImportMesh(Volt::ProjectManager::GetDirectory() / sourcePath, *newMesh))
{
UI::Notify(NotificationType::Error, "Unable to re import mesh!", std::format("Failed to import mesh from {0}!", sourcePath.string()));
break;
Expand Down Expand Up @@ -503,8 +503,8 @@ ImportState EditorUtils::MeshImportModal(const std::string& aId, MeshImportData&

if (aImportData.importSkeleton)
{
Ref<Volt::Skeleton> skeleton = Volt::MeshTypeImporter::ImportSkeleton(Volt::ProjectManager::GetDirectory() / aMeshToImport);
if (!skeleton)
Ref<Volt::Skeleton> skeleton = CreateRef<Volt::Skeleton>();
if (!Volt::MeshTypeImporter::ImportSkeleton(Volt::ProjectManager::GetDirectory() / aMeshToImport, *skeleton))
{
UI::Notify(NotificationType::Error, "Failed to import skeleton!", std::format("Failed to import skeleton from {}!", aMeshToImport.string()));
}
Expand All @@ -527,8 +527,8 @@ ImportState EditorUtils::MeshImportModal(const std::string& aId, MeshImportData&
}
else
{
Ref<Volt::Animation> animation = Volt::MeshTypeImporter::ImportAnimation(Volt::ProjectManager::GetDirectory() / aMeshToImport, targetSkeleton);
if (!animation)
Ref<Volt::Animation> animation = CreateRef<Volt::Animation>();
if (!Volt::MeshTypeImporter::ImportAnimation(Volt::ProjectManager::GetDirectory() / aMeshToImport, targetSkeleton, *animation))
{
UI::Notify(NotificationType::Error, "Failed to import animation!", std::format("Failed to import animaition from {}!", aMeshToImport.string()));
}
Expand Down
4 changes: 3 additions & 1 deletion Volt/Volt/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ project "Volt"
"%{IncludeDir.vma}",
"%{IncludeDir.VulkanSDK}",
"%{IncludeDir.shaderc_glslc}",
"%{IncludeDir.shaderc_utils}"
"%{IncludeDir.shaderc_utils}",

"%{IncludeDir.zlib}"
}

links
Expand Down
1 change: 1 addition & 0 deletions Volt/Volt/src/Volt/Asset/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace Volt
PostProcessingMaterial = BIT(25),
PostProcessingStack = BIT(26),
MotionWeave = BIT(27),
TextureSource = BIT(28)
};

inline AssetType operator|(AssetType aLhs, AssetType aRhs)
Expand Down
2 changes: 1 addition & 1 deletion Volt/Volt/src/Volt/Asset/AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ namespace Volt
{
Unload(handle);

Ref<Asset> asset;
Ref<Asset> asset = CreateRef<Asset>();
LoadAsset(handle, asset);
}

Expand Down
2 changes: 1 addition & 1 deletion Volt/Volt/src/Volt/Asset/AssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace Volt
return nullptr;
}

Ref<Asset> asset;
Ref<Asset> asset = CreateRef<T>();
Get().LoadAsset(assetHandle, asset);

if (asset)
Expand Down
10 changes: 4 additions & 6 deletions Volt/Volt/src/Volt/Asset/Importers/AssetImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Volt
{
bool TextureSourceImporter::Load(const AssetMetadata& metadata, Ref<Asset>& asset) const
{
asset = CreateRef<Texture2D>();
Ref<Texture2D> texture = std::reinterpret_pointer_cast<Texture2D>(asset);

const auto filePath = AssetManager::GetFilesystemPath(metadata.filePath);

if (!std::filesystem::exists(filePath))
Expand All @@ -41,17 +42,14 @@ namespace Volt
asset->SetFlag(AssetFlag::Missing, true);
return false;
}
auto mesh = TextureImporter::ImportTexture(filePath);

if (!mesh)
if (!TextureImporter::ImportTexture(filePath, *texture))
{
asset->SetFlag(AssetFlag::Invalid, true);
return false;
}

asset = mesh;

Renderer::AddTexture(std::reinterpret_pointer_cast<Texture2D>(asset)->GetImage());
Renderer::AddTexture(texture->GetImage());
return true;
}

Expand Down
12 changes: 7 additions & 5 deletions Volt/Volt/src/Volt/Asset/Importers/DDSTextureImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ namespace Volt

case tdl::DDSFile::DXGIFormat::BC5_UNorm: return ImageFormat::BC5;

case tdl::DDSFile::DXGIFormat::BC6H_SF16: return ImageFormat::BC6H_SF16;
case tdl::DDSFile::DXGIFormat::BC6H_UF16: return ImageFormat::BC6H_UF16;

case tdl::DDSFile::DXGIFormat::BC7_UNorm: return ImageFormat::BC7;
case tdl::DDSFile::DXGIFormat::BC7_UNorm_SRGB: return ImageFormat::BC7SRGB;
}
Expand All @@ -67,7 +70,7 @@ namespace Volt
}
}

Ref<Texture2D> DDSTextureImporter::ImportTextureImpl(const std::filesystem::path& path)
bool DDSTextureImporter::ImportTextureImpl(const std::filesystem::path& path, Texture2D& outTexture)
{
tdl::DDSFile dds;
auto returnCode = dds.Load(path.string().c_str());
Expand All @@ -79,7 +82,7 @@ namespace Volt
if (dds.GetTextureDimension() != tdl::DDSFile::TextureDimension::Texture2D)
{
VT_CORE_ERROR("Texture {0} is not 2D!", path.string().c_str());
return nullptr;
return false;
}

auto imageData = dds.GetImageData();
Expand Down Expand Up @@ -171,9 +174,8 @@ namespace Volt
Utility::TransitionImageLayout(image->GetHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
image->OverrideLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

Ref<Texture2D> texture = CreateRef<Texture2D>();
texture->myImage = image;
outTexture.myImage = image;

return texture;
return true;
}
}
Loading