Somewhat working version
This commit is contained in:
@@ -72,7 +72,7 @@ ExternalProject_Add(slang-build
|
|||||||
SOURCE_DIR ${SLANG_ROOT}
|
SOURCE_DIR ${SLANG_ROOT}
|
||||||
BINARY_DIR ${SLANG_ROOT}
|
BINARY_DIR ${SLANG_ROOT}
|
||||||
CONFIGURE_COMMAND ${SLANG_ROOT}/premake.bat vs2019 --file=${SLANG_ROOT}/premake5.lua gmake --arch=x64 --deps=true
|
CONFIGURE_COMMAND ${SLANG_ROOT}/premake.bat vs2019 --file=${SLANG_ROOT}/premake5.lua gmake --arch=x64 --deps=true
|
||||||
BUILD_COMMAND msbuild slang.sln -p:PlatformToolset=v143 -p:Configuration=Release -p:Platform=x64
|
BUILD_COMMAND msbuild -p:PlatformToolset=v143 -p:Configuration=Release -p:Platform=x64 build/visual-studio/slang/slang.vcxproj
|
||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
)
|
)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
|
|||||||
Vendored
+1
-1
Submodule external/slang updated: 79677b8387...5af36cf4ca
@@ -1,18 +1,7 @@
|
|||||||
import Common;
|
import Common;
|
||||||
import VertexData;
|
import VertexData;
|
||||||
import MaterialParameter;
|
import MaterialParameter;
|
||||||
|
import Scene;
|
||||||
struct InstanceData
|
|
||||||
{
|
|
||||||
float4x4 transformMatrix;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Scene
|
|
||||||
{
|
|
||||||
StructuredBuffer<InstanceData> instances;
|
|
||||||
}
|
|
||||||
layout(set=2)
|
|
||||||
ParameterBlock<Scene> pScene;
|
|
||||||
|
|
||||||
struct VertexShaderOutput
|
struct VertexShaderOutput
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Common;
|
import Common;
|
||||||
import BRDF;
|
import BRDF;
|
||||||
import Meshlet;
|
import Scene;
|
||||||
import VertexData;
|
import VertexData;
|
||||||
import MaterialParameter;
|
import MaterialParameter;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ struct MeshData
|
|||||||
|
|
||||||
static const uint MAX_VERTICES = 64;
|
static const uint MAX_VERTICES = 64;
|
||||||
static const uint MAX_PRIMITIVES = 126;
|
static const uint MAX_PRIMITIVES = 126;
|
||||||
static const uint TASK_GROUP_SIZE = 128;
|
static const uint TASK_GROUP_SIZE = 1;
|
||||||
static const uint MESH_GROUP_SIZE = 32;
|
static const uint MESH_GROUP_SIZE = 32;
|
||||||
static const uint MAX_MESHLETS_PER_MESH = 512;
|
static const uint MAX_MESHLETS_PER_MESH = 512;
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ void VertexData::resetMeshData()
|
|||||||
{
|
{
|
||||||
mat.material->getDescriptorLayout()->reset();
|
mat.material->getDescriptorLayout()->reset();
|
||||||
}
|
}
|
||||||
|
materialData.clear();
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
updateBuffers();
|
updateBuffers();
|
||||||
@@ -25,7 +26,7 @@ void VertexData::resetMeshData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexData::addMesh(PMesh mesh)
|
void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
||||||
{
|
{
|
||||||
PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial();
|
PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial();
|
||||||
MaterialData& matData = materialData[mat->getName()];
|
MaterialData& matData = materialData[mat->getName()];
|
||||||
@@ -34,7 +35,7 @@ void VertexData::addMesh(PMesh mesh)
|
|||||||
matInstanceData.meshes.add(MeshInstanceData{
|
matInstanceData.meshes.add(MeshInstanceData{
|
||||||
.id = mesh->id,
|
.id = mesh->id,
|
||||||
.instance = InstanceData {
|
.instance = InstanceData {
|
||||||
.transformMatrix = Matrix4(),
|
.transformMatrix = transform.toMatrix(),
|
||||||
},
|
},
|
||||||
.indexBuffer = mesh->indexBuffer,
|
.indexBuffer = mesh->indexBuffer,
|
||||||
});
|
});
|
||||||
@@ -42,20 +43,7 @@ void VertexData::addMesh(PMesh mesh)
|
|||||||
matInstanceData.numMeshes += meshData[mesh->id].size();
|
matInstanceData.numMeshes += meshData[mesh->id].size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexData::removeMesh(PMesh mesh)
|
void VertexData::createDescriptors()
|
||||||
{
|
|
||||||
PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial();
|
|
||||||
MaterialData& matData = materialData[mat->getName()];
|
|
||||||
matData.material = mat;
|
|
||||||
MaterialInstanceData& matInstanceData = matData.instances[mesh->referencedMaterial->getHandle()->getId()];
|
|
||||||
matInstanceData.meshes.remove_if([&mesh](const MeshInstanceData& data) {
|
|
||||||
return data.id == mesh->id;
|
|
||||||
});
|
|
||||||
matInstanceData.materialInstance = mesh->referencedMaterial->getHandle();
|
|
||||||
matInstanceData.numMeshes -= meshData[mesh->id].size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VertexData::updateInstances()
|
|
||||||
{
|
{
|
||||||
instanceDataLayout->reset();
|
instanceDataLayout->reset();
|
||||||
for (const auto& [_, mat] : materialData)
|
for (const auto& [_, mat] : materialData)
|
||||||
@@ -63,11 +51,13 @@ void VertexData::updateInstances()
|
|||||||
for (auto& [_, matInst] : mat.instances)
|
for (auto& [_, matInst] : mat.instances)
|
||||||
{
|
{
|
||||||
Array<InstanceData> instanceData;
|
Array<InstanceData> instanceData;
|
||||||
|
Array<MeshData> meshes;
|
||||||
for (auto& inst : matInst.meshes)
|
for (auto& inst : matInst.meshes)
|
||||||
{
|
{
|
||||||
inst.meshes = 0;
|
inst.meshes = 0;
|
||||||
for (const auto& mesh : meshData[inst.id])
|
for (const auto& mesh : meshData[inst.id])
|
||||||
{
|
{
|
||||||
|
meshes.add(mesh);
|
||||||
instanceData.add(inst.instance);
|
instanceData.add(inst.instance);
|
||||||
inst.meshes++;
|
inst.meshes++;
|
||||||
}
|
}
|
||||||
@@ -82,47 +72,7 @@ void VertexData::updateInstances()
|
|||||||
});
|
});
|
||||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
||||||
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
|
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
|
||||||
if (graphics->supportMeshShading())
|
|
||||||
{
|
|
||||||
matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer);
|
|
||||||
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
|
||||||
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
|
|
||||||
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
|
|
||||||
}
|
|
||||||
matInst.descriptorSet->writeChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VertexData::createDescriptors()
|
|
||||||
{
|
|
||||||
instanceDataLayout->reset();
|
|
||||||
for (const auto& [_, mat] : materialData)
|
|
||||||
{
|
|
||||||
for (auto& [_, matInst] : mat.instances)
|
|
||||||
{
|
|
||||||
Array<MeshData> meshes;
|
|
||||||
for (auto& inst : matInst.meshes)
|
|
||||||
{
|
|
||||||
inst.meshes = 0;
|
|
||||||
for (const auto& mesh : meshData[inst.id])
|
|
||||||
{
|
|
||||||
meshes.add(mesh);
|
|
||||||
inst.meshes++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
matInst.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
|
||||||
.sourceData = {
|
|
||||||
.size = sizeof(InstanceData) * instanceData.size(),
|
|
||||||
.data = (uint8*)instanceData.data(),
|
|
||||||
},
|
|
||||||
.numElements = instanceData.size(),
|
|
||||||
.dynamic = false,
|
|
||||||
});
|
|
||||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
|
||||||
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
|
|
||||||
if (graphics->supportMeshShading())
|
|
||||||
{
|
|
||||||
matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData = {
|
.sourceData = {
|
||||||
.size = sizeof(MeshData) * meshes.size(),
|
.size = sizeof(MeshData) * meshes.size(),
|
||||||
@@ -135,7 +85,7 @@ void VertexData::createDescriptors()
|
|||||||
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
||||||
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
|
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
|
||||||
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
|
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
|
||||||
}
|
|
||||||
matInst.descriptorSet->writeChanges();
|
matInst.descriptorSet->writeChanges();
|
||||||
matInst.numMeshes = meshes.size();
|
matInst.numMeshes = meshes.size();
|
||||||
}
|
}
|
||||||
@@ -252,8 +202,7 @@ void Seele::VertexData::init(Gfx::PGraphics graphics)
|
|||||||
verticesAllocated = NUM_DEFAULT_ELEMENTS;
|
verticesAllocated = NUM_DEFAULT_ELEMENTS;
|
||||||
instanceDataLayout = graphics->createDescriptorLayout("VertexDataInstanceLayout");
|
instanceDataLayout = graphics->createDescriptorLayout("VertexDataInstanceLayout");
|
||||||
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
if (graphics->supportMeshShading())
|
|
||||||
{
|
|
||||||
// meshData
|
// meshData
|
||||||
instanceDataLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
instanceDataLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
// meshletData
|
// meshletData
|
||||||
@@ -262,7 +211,7 @@ void Seele::VertexData::init(Gfx::PGraphics graphics)
|
|||||||
instanceDataLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
instanceDataLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
// vetexIndices
|
// vetexIndices
|
||||||
instanceDataLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
instanceDataLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
}
|
|
||||||
instanceDataLayout->create();
|
instanceDataLayout->create();
|
||||||
resizeBuffers();
|
resizeBuffers();
|
||||||
graphics->getShaderCompiler()->registerVertexData(this);
|
graphics->getShaderCompiler()->registerVertexData(this);
|
||||||
|
|||||||
@@ -67,9 +67,7 @@ public:
|
|||||||
uint32 indicesOffset;
|
uint32 indicesOffset;
|
||||||
};
|
};
|
||||||
void resetMeshData();
|
void resetMeshData();
|
||||||
void addMesh(PMesh mesh);
|
void updateMesh(PMesh mesh, Component::Transform& transform);
|
||||||
void removeMesh(PMesh mesh);
|
|
||||||
void updateInstances();
|
|
||||||
void createDescriptors();
|
void createDescriptors();
|
||||||
void loadMesh(MeshId id, Array<Meshlet> meshlets);
|
void loadMesh(MeshId id, Array<Meshlet> meshlets);
|
||||||
MeshId allocateVertexData(uint64 numVertices);
|
MeshId allocateVertexData(uint64 numVertices);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using namespace Seele::System;
|
|||||||
KeyboardInput::KeyboardInput(PScene scene)
|
KeyboardInput::KeyboardInput(PScene scene)
|
||||||
: ComponentSystem<Component::KeyboardInput>(scene)
|
: ComponentSystem<Component::KeyboardInput>(scene)
|
||||||
{
|
{
|
||||||
|
std::memset(keys.data(), 0, sizeof(keys));
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardInput::~KeyboardInput()
|
KeyboardInput::~KeyboardInput()
|
||||||
|
|||||||
@@ -1,32 +1,22 @@
|
|||||||
#include "MeshUpdater.h"
|
#include "MeshUpdater.h"
|
||||||
|
#include "Component/Mesh.h"
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::System;
|
using namespace Seele::System;
|
||||||
|
|
||||||
MeshUpdater::MeshUpdater(PScene scene)
|
MeshUpdater::MeshUpdater(PScene scene)
|
||||||
: SystemBase(scene)
|
: ComponentSystem<Component::Transform, Component::Mesh>(scene)
|
||||||
{
|
{
|
||||||
scene->view<Component::Mesh>([&](entt::entity id, Component::Mesh& mesh) {
|
|
||||||
meshEntities.add(id);
|
|
||||||
});
|
|
||||||
scene->constructCallback<Component::Mesh>().connect<&MeshUpdater::on_construct>(this);
|
|
||||||
scene->destroyCallback<Component::Mesh>().connect<&MeshUpdater::on_destroy>(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshUpdater::~MeshUpdater()
|
MeshUpdater::~MeshUpdater()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshUpdater::update()
|
void MeshUpdater::update(Component::Transform& transform, Component::Mesh& comp)
|
||||||
{
|
{
|
||||||
}
|
for (auto& mesh : comp.asset->meshes)
|
||||||
|
|
||||||
void MeshUpdater::on_construct(entt::registry& reg, entt::entity id)
|
|
||||||
{
|
{
|
||||||
meshEntities.add(id);
|
mesh->vertexData->updateMesh(mesh, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshUpdater::on_destroy(entt::registry& reg, entt::entity id)
|
|
||||||
{
|
|
||||||
meshEntities.remove(id, false);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "SystemBase.h"
|
#include "ComponentSystem.h"
|
||||||
#include "Component/Transform.h"
|
#include "Component/Transform.h"
|
||||||
#include "Component/Mesh.h"
|
#include "Component/Mesh.h"
|
||||||
|
|
||||||
@@ -7,16 +7,13 @@ namespace Seele
|
|||||||
{
|
{
|
||||||
namespace System
|
namespace System
|
||||||
{
|
{
|
||||||
class MeshUpdater : public SystemBase
|
class MeshUpdater : public ComponentSystem<Component::Transform, Component::Mesh>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MeshUpdater(PScene scene);
|
MeshUpdater(PScene scene);
|
||||||
virtual ~MeshUpdater();
|
virtual ~MeshUpdater();
|
||||||
virtual void update() override;
|
virtual void update(Component::Transform& transform, Component::Mesh& mesh) override;
|
||||||
private:
|
private:
|
||||||
Array<entt::entity> meshEntities;
|
|
||||||
void on_construct(entt::registry& reg, entt::entity id);
|
|
||||||
void on_destroy(entt::registry& reg, entt::entity id);
|
|
||||||
};
|
};
|
||||||
} // namespace System
|
} // namespace System
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
Reference in New Issue
Block a user