3700 FPS here we go

This commit is contained in:
Dynamitos
2021-04-13 23:09:16 +02:00
parent d5f0fe644f
commit 312ae2af9a
36 changed files with 401 additions and 231 deletions
+17 -2
View File
@@ -28,16 +28,31 @@ public:
std::string getExtension() const;
inline Status getStatus()
{
std::scoped_lock lck(lock);
std::unique_lock lck(lock);
return status;
}
inline void setStatus(Status status)
{
std::scoped_lock lck(lock);
std::unique_lock lck(lock);
this->status = status;
if(status == Status::Ready)
{
readyCV.notify_all();
}
}
protected:
inline void waitReady()
{
std::unique_lock lck(lock);
if(status != Status::Ready)
{
std::cout << "Asset " << name.generic_string() << " not ready yet, waiting" << std::endl;
readyCV.wait(lck);
std::cout << "Asset " << name.generic_string() << " now ready, continuing" << std::endl;
}
}
std::mutex lock;
std::condition_variable readyCV;
std::ifstream& getReadStream();
std::ofstream& getWriteStream();
private:
+3 -1
View File
@@ -43,7 +43,9 @@ void AssetRegistry::importFile(const std::string &filePath)
PMeshAsset AssetRegistry::findMesh(const std::string &filePath)
{
return get().meshes[filePath];
auto it = get().meshes.find(filePath);
assert(it != get().meshes.end());
return it->value;
}
PTextureAsset AssetRegistry::findTexture(const std::string &filePath)
+3 -1
View File
@@ -1,5 +1,6 @@
#include "MeshAsset.h"
#include "Graphics/Mesh.h"
#include "Graphics/VertexShaderInput.h"
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
@@ -40,7 +41,8 @@ void MeshAsset::addMesh(PMesh mesh)
referencedMaterials.add(mesh->referencedMaterial);
}
const Array<PMesh> MeshAsset::getMeshes() const
const Array<PMesh> MeshAsset::getMeshes()
{
waitReady();
return meshes;
}
+1 -1
View File
@@ -15,7 +15,7 @@ public:
virtual void save() override;
virtual void load() override;
void addMesh(PMesh mesh);
const Array<PMesh> getMeshes() const;
const Array<PMesh> getMeshes();
private:
Array<PMesh> meshes;
Array<PMaterialAsset> referencedMaterials;
+9 -6
View File
@@ -29,7 +29,11 @@ MeshLoader::~MeshLoader()
void MeshLoader::importAsset(const std::filesystem::path &path)
{
futures.add(std::async(std::launch::async, &MeshLoader::import, this, path));
std::filesystem::path assetPath = path.filename();
assetPath.replace_extension("asset");
PMeshAsset meshAsset = new MeshAsset(assetPath.generic_string());
AssetRegistry::get().registerMesh(meshAsset);
futures.add(std::async(std::launch::async, &MeshLoader::import, this, meshAsset, path));
}
void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics)
@@ -224,8 +228,9 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
AssetRegistry::importFile(texPngPath.string());
}
}
void MeshLoader::import(const std::filesystem::path &path)
void MeshLoader::import(PMeshAsset meshAsset, const std::filesystem::path &path)
{
meshAsset->setStatus(Asset::Status::Loading);
Assimp::Importer importer;
importer.ReadFile(path.string().c_str(),
aiProcess_FlipUVs |
@@ -246,9 +251,7 @@ void MeshLoader::import(const std::filesystem::path &path)
List<aiNode *> meshNodes;
findMeshRoots(scene->mRootNode, meshNodes);
std::filesystem::path filePath = path.filename();
filePath.replace_extension("asset");
PMeshAsset meshAsset = new MeshAsset(filePath.generic_string());
for (auto meshNode : meshNodes)
{
for(uint32 i = 0; i < meshNode->mNumMeshes; ++i)
@@ -256,6 +259,6 @@ void MeshLoader::import(const std::filesystem::path &path)
meshAsset->addMesh(globalMeshes[meshNode->mMeshes[i]]);
}
}
meshAsset->setStatus(Asset::Status::Ready);
meshAsset->save();
AssetRegistry::get().registerMesh(meshAsset);
}
+1 -1
View File
@@ -25,7 +25,7 @@ private:
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics);
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
void import(const std::filesystem::path& path);
void import(PMeshAsset meshAsset, const std::filesystem::path& path);
List<std::future<void>> futures;
Gfx::PGraphics graphics;
};
+4 -2
View File
@@ -28,12 +28,14 @@ void TextureLoader::importAsset(const std::filesystem::path& filePath)
PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string());
asset->setStatus(Asset::Status::Loading);
asset->setTexture(placeholderTexture);
std::cout << "Loading texture, placeholder" << std::endl;
AssetRegistry::get().textures[asset->getFileName()] = asset;
//futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
Gfx::PTexture2D texture = import(filePath);
asset->setTexture(texture);
asset->setStatus(Asset::Status::Ready);
//}));
std::cout << "Finished loading texture" << std::endl;
}));
}
PTextureAsset TextureLoader::getPlaceholderTexture()