It finally imports somewhat
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user