It finally imports somewhat

This commit is contained in:
Dynamitos
2024-05-01 19:05:48 +02:00
parent 2c1669aab4
commit dfcfc2bb1e
19 changed files with 108 additions and 84 deletions
+4 -4
View File
@@ -632,13 +632,14 @@ private:
}
else
{
allocated = calculateGrowth(newSize);
// The array is not big enough, so we make a new one
T *newData = allocateArray(newSize);
T *newData = allocateArray(allocated);
if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>)
{
std::memcpy(newData, _data, sizeof(T) * arraySize);
std::memset(&newData[arraySize], 0, sizeof(T) * (newSize - arraySize));
std::memset(&newData[arraySize], 0, sizeof(T) * (allocated - arraySize));
}
else
{
@@ -648,14 +649,13 @@ private:
newData[i] = std::forward<Type>(_data[i]);
}
// As well as default initialize the others
for (size_type i = arraySize; i < newSize; ++i)
for (size_type i = arraySize; i < allocated; ++i)
{
std::allocator_traits<allocator_type>::construct(allocator, &newData[i], value);
}
}
deallocateArray(_data, allocated);
arraySize = newSize;
allocated = newSize;
_data = newData;
}
}
+62 -32
View File
@@ -1,4 +1,5 @@
#include "Shader.h"
#include "ThreadPool.h"
#include "Graphics/Initializer.h"
#include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/BasePass.h"
@@ -51,57 +52,83 @@ void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout, std::string
void ShaderCompiler::compile()
{
List<std::function<void()>> work;
for (const auto& [name, pass] : passes)
{
ShaderPermutation permutation;
if (pass.useMeshShading)
{
permutation.setMeshFile(pass.mainFile);
}
else
{
permutation.setVertexFile(pass.mainFile);
}
if (pass.hasFragmentShader)
{
permutation.setFragmentFile(pass.fragmentFile);
}
if (pass.hasTaskShader)
{
permutation.setTaskFile(pass.taskFile);
}
for (const auto& [vdName, vd] : vertexData)
{
permutation.setVertexData(vd->getTypeName());
if (pass.useMaterial)
{
for (const auto& [matName, mat] : materials)
{
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
layout->addDescriptorLayout(mat->getDescriptorLayout());
permutation.setMaterial(mat->getName());
createShaders(permutation, std::move(layout));
work.add([=]() {
ShaderPermutation permutation;
if (pass.useMeshShading)
{
permutation.setMeshFile(pass.mainFile);
}
else
{
permutation.setVertexFile(pass.mainFile);
}
if (pass.hasFragmentShader)
{
permutation.setFragmentFile(pass.fragmentFile);
}
if (pass.hasTaskShader)
{
permutation.setTaskFile(pass.taskFile);
}
permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
layout->addDescriptorLayout(mat->getDescriptorLayout());
permutation.setMaterial(mat->getName());
createShaders(permutation, std::move(layout));
});
}
}
else
{
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
createShaders(permutation, std::move(layout));
work.add([=]() {
ShaderPermutation permutation;
if (pass.useMeshShading)
{
permutation.setMeshFile(pass.mainFile);
}
else
{
permutation.setVertexFile(pass.mainFile);
}
if (pass.hasFragmentShader)
{
permutation.setFragmentFile(pass.fragmentFile);
}
if (pass.hasTaskShader)
{
permutation.setTaskFile(pass.taskFile);
}
permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
createShaders(permutation, std::move(layout));
});
}
}
}
getThreadPool().runAndWait(std::move(work));
}
void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout)
{
std::scoped_lock lock(shadersLock);
PermutationId perm = PermutationId(permutation);
if (shaders.contains(perm))
return;
{
std::scoped_lock lock(shadersLock);
if (shaders.contains(perm))
return;
}
ShaderCollection collection;
collection.pipelineLayout = std::move(layout);
@@ -142,5 +169,8 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
collection.fragmentShader = graphics->createFragmentShader(createInfo);
}
collection.pipelineLayout->create();
shaders[perm] = std::move(collection);
{
std::scoped_lock lock(shadersLock);
shaders[perm] = std::move(collection);
}
}
+4 -4
View File
@@ -58,10 +58,10 @@ struct ShaderPermutation
char fragmentFile[32];
char vertexDataName[32];
char materialName[64];
uint8 hasFragment : 1;
uint8 useMeshShading : 1;
uint8 hasTaskShader : 1;
uint8 useMaterial : 1;
uint8 hasFragment;
uint8 useMeshShading;
uint8 hasTaskShader;
uint8 useMaterial;
//TODO: lightmapping etc
ShaderPermutation()
{
+6 -6
View File
@@ -105,12 +105,12 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
Array<Vector> tan(numVertices);
Array<Vector> bit(numVertices);
Array<Vector> col(numVertices);
std::memcpy(positionData.data() + offset, pos.data(), numVertices * sizeof(Vector));
std::memcpy(texCoordsData.data() + offset, tex.data(), numVertices * sizeof(Vector2));
std::memcpy(normalData.data() + offset, nor.data(), numVertices * sizeof(Vector));
std::memcpy(tangentData.data() + offset, tan.data(), numVertices * sizeof(Vector));
std::memcpy(biTangentData.data() + offset, bit.data(), numVertices * sizeof(Vector));
std::memcpy(colorData.data() + offset, col.data(), numVertices * sizeof(Vector));
std::memcpy(pos.data(), positionData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(tex.data(), texCoordsData.data() + offset, numVertices * sizeof(Vector2));
std::memcpy(nor.data(), normalData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(tan.data(), tangentData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(bit.data(), biTangentData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(col.data(), colorData.data() + offset, numVertices * sizeof(Vector));
Serialization::save(buffer, pos);
Serialization::save(buffer, tex);
Serialization::save(buffer, nor);
+5 -5
View File
@@ -24,7 +24,7 @@ public:
return Dependencies<>();
}
template<typename... Deps>
void setupView(Dependencies<Deps...>, ThreadPool& pool)
void setupView(Dependencies<Deps...>)
{
List<std::function<void()>> work;
registry.view<Components..., Deps...>().each([&](Components&... comp, Deps&... deps){
@@ -33,12 +33,12 @@ public:
update(comp...);
});
});
pool.runAndWait(std::move(work));
getThreadPool().runAndWait(std::move(work));
}
virtual void run(ThreadPool& pool, double delta) override
virtual void run(double delta) override
{
SystemBase::run(pool, delta);
setupView((getDependencies<Components>() | ...), pool);
SystemBase::run(delta);
setupView((getDependencies<Components>() | ...));
}
virtual void update() override {}
virtual void update(Components&... components) = 0;
-2
View File
@@ -11,8 +11,6 @@ class Executor
public:
Executor();
~Executor();
private:
ThreadPool pool;
};
} // namespace System
} // namespace Seele
+1 -1
View File
@@ -12,7 +12,7 @@ class SystemBase
public:
SystemBase(PScene scene) : registry(scene->registry), scene(scene) {}
virtual ~SystemBase() {}
virtual void run(ThreadPool&, double delta)
virtual void run(double delta)
{
deltaTime = delta;
update();
+2 -2
View File
@@ -7,9 +7,9 @@ void SystemGraph::addSystem(System::OSystemBase system)
systems.add(std::move(system));
}
void SystemGraph::run(ThreadPool& threadPool, float deltaTime)
void SystemGraph::run(float deltaTime)
{
for(auto& system : systems) {
system->run(threadPool, deltaTime);
system->run(deltaTime);
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ class SystemGraph
{
public:
void addSystem(System::OSystemBase system);
void run(ThreadPool& threadPool, float deltaTime);
void run(float deltaTime);
private:
Array<System::OSystemBase> systems;
};
+7
View File
@@ -61,3 +61,10 @@ void ThreadPool::work()
}
}
}
static ThreadPool threadPool;
ThreadPool& Seele::getThreadPool()
{
return threadPool;
}
+1
View File
@@ -26,4 +26,5 @@ private:
Task currentTask;
bool running = true;
};
ThreadPool& getThreadPool();
}
+1 -1
View File
@@ -43,7 +43,7 @@ void GameView::update()
{
vd->resetMeshData();
}
systemGraph->run(threadPool, updateTime);
systemGraph->run(updateTime);
scene->update(updateTime);
for (VertexData* vd : VertexData::getList())
{
-1
View File
@@ -36,7 +36,6 @@ protected:
PSystemGraph systemGraph;
System::PKeyboardInput keyboardSystem;
ThreadPool threadPool;
float updateTime = 0;
virtual void keyCallback(Seele::KeyCode code, Seele::InputAction action, Seele::KeyModifier modifier) override;