Fixing staging buffers not getting deleted
remove vgcore
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
using namespace Seele;
|
||||
|
||||
Entity::Entity(PScene scene)
|
||||
: identifier(scene->createEntity())
|
||||
, scene(scene)
|
||||
: scene(scene)
|
||||
, identifier(scene->createEntity())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ Asset::Asset()
|
||||
{
|
||||
}
|
||||
Asset::Asset(std::string_view _folderPath, std::string_view _name)
|
||||
: status(Status::Uninitialized)
|
||||
, folderPath(_folderPath)
|
||||
: folderPath(_folderPath)
|
||||
, name(_name)
|
||||
, status(Status::Uninitialized)
|
||||
{
|
||||
if (folderPath.empty())
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ PMeshAsset AssetRegistry::findMesh(const std::string &filePath)
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
std::string fileName = filePath;
|
||||
size_t slashLoc = filePath.rfind("/");
|
||||
if(slashLoc != -1)
|
||||
if(slashLoc != std::string::npos)
|
||||
{
|
||||
folder = get().getOrCreateFolder(filePath.substr(0, slashLoc));
|
||||
fileName = filePath.substr(slashLoc+1, filePath.size());
|
||||
@@ -44,7 +44,7 @@ PTextureAsset AssetRegistry::findTexture(const std::string &filePath)
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
std::string fileName = filePath;
|
||||
size_t slashLoc = filePath.rfind("/");
|
||||
if (slashLoc != -1)
|
||||
if (slashLoc != std::string::npos)
|
||||
{
|
||||
folder = get().getOrCreateFolder(filePath.substr(0, slashLoc));
|
||||
fileName = filePath.substr(slashLoc + 1, filePath.size());
|
||||
@@ -57,7 +57,7 @@ PFontAsset AssetRegistry::findFont(const std::string& filePath)
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
std::string fileName = filePath;
|
||||
size_t slashLoc = filePath.rfind("/");
|
||||
if(slashLoc != -1)
|
||||
if(slashLoc != std::string::npos)
|
||||
{
|
||||
folder = get().getOrCreateFolder(filePath.substr(0, slashLoc));
|
||||
fileName = filePath.substr(slashLoc+1, filePath.size());
|
||||
@@ -70,7 +70,7 @@ PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath)
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
std::string fileName = filePath;
|
||||
size_t slashLoc = filePath.rfind("/");
|
||||
if (slashLoc != -1)
|
||||
if (slashLoc != std::string::npos)
|
||||
{
|
||||
folder = get().getOrCreateFolder(filePath.substr(0, slashLoc));
|
||||
fileName = filePath.substr(slashLoc + 1, filePath.size());
|
||||
@@ -78,6 +78,19 @@ PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath)
|
||||
return folder->materials.at(fileName);
|
||||
}
|
||||
|
||||
PMaterialInstanceAsset AssetRegistry::findMaterialInstance(const std::string &filePath)
|
||||
{
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
std::string fileName = filePath;
|
||||
size_t slashLoc = filePath.rfind("/");
|
||||
if (slashLoc != std::string::npos)
|
||||
{
|
||||
folder = get().getOrCreateFolder(filePath.substr(0, slashLoc));
|
||||
fileName = filePath.substr(slashLoc + 1, filePath.size());
|
||||
}
|
||||
return folder->instances.at(fileName);
|
||||
}
|
||||
|
||||
std::ofstream AssetRegistry::createWriteStream(const std::filesystem::path& relativePath, std::ios_base::openmode openmode)
|
||||
{
|
||||
return get().internalCreateWriteStream(relativePath, openmode);
|
||||
@@ -356,7 +369,7 @@ AssetRegistry::AssetFolder* AssetRegistry::getOrCreateFolder(std::string fullPat
|
||||
while(!fullPath.empty())
|
||||
{
|
||||
size_t slashLoc = fullPath.find("/");
|
||||
if(slashLoc == -1)
|
||||
if(slashLoc == std::string::npos)
|
||||
{
|
||||
if (!result->children.contains(fullPath))
|
||||
{
|
||||
|
||||
@@ -75,6 +75,7 @@ private:
|
||||
Gfx::PGraphics graphics;
|
||||
ArchiveBuffer assetBuffer;
|
||||
bool release = false;
|
||||
friend class MaterialAsset;
|
||||
friend class TextureLoader;
|
||||
friend class FontLoader;
|
||||
friend class MaterialLoader;
|
||||
|
||||
@@ -30,7 +30,9 @@ void FontAsset::save(ArchiveBuffer& buffer) const
|
||||
Array<uint8> textureData;
|
||||
ktxTexture2* kTexture;
|
||||
ktxTextureCreateInfo createInfo = {
|
||||
.glInternalformat = 0,
|
||||
.vkFormat = (uint32_t)glyph.texture->getFormat(),
|
||||
.pDfd = nullptr,
|
||||
.baseWidth = glyph.texture->getSizeX(),
|
||||
.baseHeight = glyph.texture->getSizeY(),
|
||||
.baseDepth = glyph.texture->getSizeZ(),
|
||||
|
||||
@@ -18,12 +18,12 @@ LevelAsset::~LevelAsset()
|
||||
|
||||
}
|
||||
|
||||
void LevelAsset::save(ArchiveBuffer& buffer) const
|
||||
void LevelAsset::save(ArchiveBuffer&) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LevelAsset::load(ArchiveBuffer& buffer)
|
||||
void LevelAsset::load(ArchiveBuffer&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Material/Material.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "MaterialInstanceAsset.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -30,13 +31,15 @@ void MaterialAsset::load(ArchiveBuffer& buffer)
|
||||
material->compile();
|
||||
}
|
||||
|
||||
OMaterialInstanceAsset Seele::MaterialAsset::instantiate(const InstantiationParameter& params)
|
||||
PMaterialInstanceAsset MaterialAsset::instantiate(const InstantiationParameter& params)
|
||||
{
|
||||
OMaterialInstance instance = material->instantiate();
|
||||
instance->setBaseMaterial(this);
|
||||
OMaterialInstanceAsset asset = new MaterialInstanceAsset(params.folderPath, params.name);
|
||||
asset->setHandle(std::move(instance));
|
||||
return asset;
|
||||
asset->setBase(this);
|
||||
PMaterialInstanceAsset ref = asset;
|
||||
AssetRegistry::get().saveAsset(ref, MaterialInstanceAsset::IDENTIFIER, ref->getFolderPath(), ref->getName());
|
||||
AssetRegistry::get().registerMaterialInstance(std::move(asset));
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
PMaterial getMaterial() const { return material; }
|
||||
OMaterialInstanceAsset instantiate(const InstantiationParameter& params);
|
||||
PMaterialInstanceAsset instantiate(const InstantiationParameter& params);
|
||||
private:
|
||||
OMaterial material;
|
||||
friend class MaterialLoader;
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
void setHandle(OMaterialInstance handle) { material = std::move(handle); }
|
||||
void setBase(PMaterialAsset base) { baseMaterial = base; }
|
||||
PMaterialInstance getHandle() const { return material; }
|
||||
private:
|
||||
OMaterialInstance material;
|
||||
PMaterialAsset baseMaterial;
|
||||
|
||||
@@ -21,7 +21,6 @@ MeshAsset::~MeshAsset()
|
||||
void MeshAsset::save(ArchiveBuffer& buffer) const
|
||||
{
|
||||
Serialization::save(buffer, meshes);
|
||||
|
||||
}
|
||||
|
||||
void MeshAsset::load(ArchiveBuffer& buffer)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Graphics/Vulkan/Enums.h"
|
||||
#include "Graphics/Texture.h"
|
||||
#include "ktx.h"
|
||||
|
||||
using namespace Seele;
|
||||
@@ -22,7 +23,7 @@ TextureAsset::~TextureAsset()
|
||||
|
||||
}
|
||||
|
||||
void TextureAsset::save(ArchiveBuffer& buffer) const
|
||||
void TextureAsset::save(ArchiveBuffer&) const
|
||||
{
|
||||
/*ktxTexture2* kTexture;
|
||||
ktxTextureCreateInfo createInfo = {
|
||||
@@ -113,3 +114,8 @@ void TextureAsset::load(ArchiveBuffer& buffer)
|
||||
texture->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
ktxTexture_Destroy(ktxTexture(kTexture));
|
||||
}
|
||||
|
||||
void TextureAsset::setTexture(Gfx::OTexture _texture)
|
||||
{
|
||||
texture = std::move(_texture);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ public:
|
||||
virtual ~TextureAsset();
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
void setTexture(Gfx::OTexture _texture)
|
||||
{
|
||||
texture = std::move(_texture);
|
||||
}
|
||||
void setTexture(Gfx::OTexture _texture);
|
||||
Gfx::PTexture getTexture()
|
||||
{
|
||||
return texture;
|
||||
|
||||
@@ -8,8 +8,8 @@ using namespace Seele::Component;
|
||||
using namespace Seele::Math;
|
||||
|
||||
Camera::Camera()
|
||||
: bNeedsViewBuild(false)
|
||||
, viewMatrix(Matrix4())
|
||||
: viewMatrix(Matrix4())
|
||||
, bNeedsViewBuild(false)
|
||||
{
|
||||
yaw = 0;
|
||||
pitch = 0;
|
||||
|
||||
@@ -21,7 +21,6 @@ struct Dependencies<This, Rest...> : public Dependencies<Rest...>
|
||||
|
||||
namespace Component
|
||||
{
|
||||
#pragma warning(disable: 4505)
|
||||
template<typename Comp>
|
||||
static int accessComponent(Comp& comp);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Graphics/VertexData.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -9,9 +10,9 @@ namespace Component
|
||||
{
|
||||
struct Mesh
|
||||
{
|
||||
VertexData* vertexData;
|
||||
MeshId id;
|
||||
PMaterialInstance instance;
|
||||
PMeshAsset asset;
|
||||
Mesh() {}
|
||||
Mesh(PMeshAsset asset) : asset(asset) {}
|
||||
};
|
||||
} // namespace Component
|
||||
} // namespace Seele
|
||||
|
||||
@@ -56,6 +56,11 @@ public:
|
||||
{
|
||||
return (int)(p - other.p);
|
||||
}
|
||||
constexpr IteratorBase& operator+=(difference_type other)
|
||||
{
|
||||
p+=other;
|
||||
return *this;
|
||||
}
|
||||
constexpr bool operator<(const IteratorBase& other) const
|
||||
{
|
||||
return p < other.p;
|
||||
@@ -725,7 +730,7 @@ public:
|
||||
}
|
||||
StaticArray(T value)
|
||||
{
|
||||
for (int i = 0; i < N; ++i)
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
{
|
||||
_data[i] = value;
|
||||
}
|
||||
@@ -736,7 +741,7 @@ public:
|
||||
{
|
||||
assert(init.size() == N);
|
||||
auto beg = init.begin();
|
||||
for (int i = 0; i < N; ++i)
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
{
|
||||
_data[i] = *beg;
|
||||
beg++;
|
||||
|
||||
@@ -209,17 +209,17 @@ public:
|
||||
constexpr Map(const Map& other)
|
||||
: nodeContainer(other.nodeContainer)
|
||||
, root(other.root)
|
||||
, iteratorsDirty(true)
|
||||
, _size(other._size)
|
||||
, comp(other.comp)
|
||||
, iteratorsDirty(true)
|
||||
{
|
||||
}
|
||||
constexpr Map(Map&& other) noexcept
|
||||
: nodeContainer(std::move(other.nodeContainer))
|
||||
, root(std::move(other.root))
|
||||
, iteratorsDirty(true)
|
||||
, _size(std::move(other._size))
|
||||
, comp(std::move(other.comp))
|
||||
, iteratorsDirty(true)
|
||||
{
|
||||
}
|
||||
constexpr ~Map() noexcept
|
||||
@@ -502,7 +502,7 @@ private:
|
||||
endIt = calcEndIterator();
|
||||
iteratorsDirty = false;
|
||||
}
|
||||
inline Iterator calcBeginIterator() const
|
||||
constexpr Iterator calcBeginIterator() const
|
||||
{
|
||||
size_t beginIndex = root;
|
||||
Array<size_t> beginTraversal;
|
||||
@@ -518,7 +518,7 @@ private:
|
||||
}
|
||||
return Iterator(beginIndex, &nodeContainer, std::move(beginTraversal));
|
||||
}
|
||||
inline Iterator calcEndIterator() const
|
||||
constexpr Iterator calcEndIterator() const
|
||||
{
|
||||
size_t endIndex = root;
|
||||
Array<size_t> endTraversal;
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ namespace Seele
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
Game(AssetRegistry* registry) {}
|
||||
Game(AssetRegistry*) {}
|
||||
virtual ~Game() {}
|
||||
virtual void setupScene(PScene scene, PSystemGraph graph) = 0;
|
||||
};
|
||||
|
||||
@@ -32,6 +32,7 @@ target_sources(Engine
|
||||
Buffer.h
|
||||
DebugVertex.h
|
||||
Descriptor.h
|
||||
Enums.h
|
||||
Graphics.h
|
||||
Initializer.h
|
||||
Mesh.h
|
||||
|
||||
@@ -110,6 +110,7 @@ FormatCompatibilityInfo Gfx::getFormatInfo(SeFormat format)
|
||||
.blockExtent = Vector(1, 1, 1),
|
||||
.texelsPerBlock = 1,
|
||||
};
|
||||
default:
|
||||
throw new std::logic_error("not yet implemented");
|
||||
}
|
||||
throw new std::logic_error("not yet implemented");
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace Gfx
|
||||
static constexpr bool useAsyncCompute = true;
|
||||
static constexpr bool waitIdleOnSubmit = true;
|
||||
static constexpr bool useMeshShading = true;
|
||||
static constexpr uint32 numFramesBuffered = 8;
|
||||
static constexpr uint32 numFramesBuffered = 3;
|
||||
|
||||
// meshlet dimensions curated by NVIDIA
|
||||
static constexpr uint32 numVerticesPerMeshlet = 64;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "Mesh.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -16,6 +17,7 @@ void Mesh::save(ArchiveBuffer& buffer) const
|
||||
Serialization::save(buffer, vertexData->getTypeName());
|
||||
Serialization::save(buffer, vertexCount);
|
||||
Serialization::save(buffer, meshlets);
|
||||
Serialization::save(buffer, referencedMaterial->getAssetIdentifier());
|
||||
vertexData->serializeMesh(id, vertexCount, buffer);
|
||||
}
|
||||
|
||||
@@ -26,6 +28,9 @@ void Mesh::load(ArchiveBuffer& buffer)
|
||||
Serialization::load(buffer, vertexCount);
|
||||
vertexData = VertexData::findByTypeName(typeName);
|
||||
Serialization::load(buffer, meshlets);
|
||||
std::string refId;
|
||||
Serialization::load(buffer, refId);
|
||||
referencedMaterial = AssetRegistry::findMaterialInstance(refId);
|
||||
id = vertexData->allocateVertexData(vertexCount);
|
||||
vertexData->loadMesh(id, meshlets);
|
||||
vertexData->deserializeMesh(id, buffer);
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
VertexData* vertexData;
|
||||
MeshId id;
|
||||
uint64 vertexCount;
|
||||
PMaterialInstance referencedMaterial;
|
||||
PMaterialInstanceAsset referencedMaterial;
|
||||
Array<Meshlet> meshlets;
|
||||
void save(ArchiveBuffer& buffer) const;
|
||||
void load(ArchiveBuffer& buffer);
|
||||
@@ -23,12 +23,12 @@ DEFINE_REF(Mesh)
|
||||
namespace Serialization
|
||||
{
|
||||
template<>
|
||||
static void save(ArchiveBuffer& buffer, const OMesh& ptr)
|
||||
void save(ArchiveBuffer& buffer, const OMesh& ptr)
|
||||
{
|
||||
ptr->save(buffer);
|
||||
}
|
||||
template<>
|
||||
static void load(ArchiveBuffer& buffer, OMesh& ptr)
|
||||
void load(ArchiveBuffer& buffer, OMesh& ptr)
|
||||
{
|
||||
ptr = new Mesh();
|
||||
ptr->load(buffer);
|
||||
|
||||
@@ -152,6 +152,6 @@ void BasePass::createRenderPass()
|
||||
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
|
||||
}
|
||||
|
||||
void BasePass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
|
||||
void BasePass::modifyRenderPassMacros(Map<const char*, const char*>&)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ LightCullingPass::~LightCullingPass()
|
||||
void LightCullingPass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
RenderPass::beginFrame(cam);
|
||||
uint32_t viewportWidth = viewport->getSizeX();
|
||||
uint32_t viewportHeight = viewport->getSizeY();
|
||||
|
||||
uint32 reset = 0;
|
||||
DataSource counterReset = {
|
||||
|
||||
@@ -30,6 +30,7 @@ void RenderPass::beginFrame(const Component::Camera& cam)
|
||||
.projectionMatrix = viewport->getProjectionMatrix(),
|
||||
.cameraPosition = Vector4(cam.getCameraPosition(), 1),
|
||||
.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY())),
|
||||
.pad0 = Vector2(0),
|
||||
};
|
||||
DataSource uniformUpdate = {
|
||||
.size = sizeof(ViewParameter),
|
||||
|
||||
@@ -75,13 +75,13 @@ public:
|
||||
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
|
||||
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
|
||||
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE)
|
||||
: loadOp(loadOp)
|
||||
: clear()
|
||||
, componentFlags(0)
|
||||
, loadOp(loadOp)
|
||||
, storeOp(storeOp)
|
||||
, stencilLoadOp(stencilLoadOp)
|
||||
, stencilStoreOp(stencilStoreOp)
|
||||
, texture(texture)
|
||||
, clear()
|
||||
, componentFlags(0)
|
||||
{
|
||||
}
|
||||
virtual ~RenderTargetAttachment()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Shader.h"
|
||||
#include "Graphics/RenderPass/DepthPrepass.h"
|
||||
#include "Graphics/RenderPass/BasePass.h"
|
||||
#include <format>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Gfx;
|
||||
@@ -52,11 +53,9 @@ void ShaderCompiler::compile()
|
||||
for (const auto& [name, pass] : passes)
|
||||
{
|
||||
std::memset(&permutation, 0, sizeof(ShaderPermutation));
|
||||
permutation = {
|
||||
.hasFragment = pass.hasFragmentShader,
|
||||
.useMeshShading = pass.useMeshShading,
|
||||
.hasTaskShader = pass.hasTaskShader,
|
||||
};
|
||||
permutation.hasFragment = pass.hasFragmentShader;
|
||||
permutation.useMeshShading = pass.useMeshShading;
|
||||
permutation.hasTaskShader = pass.hasTaskShader;
|
||||
std::memcpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile));
|
||||
if (pass.hasFragmentShader)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024;
|
||||
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024;
|
||||
|
||||
void VertexData::resetMeshData()
|
||||
{
|
||||
@@ -19,13 +19,13 @@ void VertexData::resetMeshData()
|
||||
}
|
||||
}
|
||||
|
||||
void VertexData::updateMesh(const Component::Transform& transform, const Component::Mesh& mesh)
|
||||
void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh)
|
||||
{
|
||||
PMaterial mat = mesh.instance->getBaseMaterial();
|
||||
PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial();
|
||||
MaterialData& matData = materialData[mat->getName()];
|
||||
MaterialInstanceData& matInstanceData = matData.instances[mesh.instance->getId()];
|
||||
MaterialInstanceData& matInstanceData = matData.instances[mesh->referencedMaterial->getHandle()->getId()];
|
||||
matInstanceData.meshes.add(MeshInstanceData{
|
||||
.id = mesh.id,
|
||||
.id = mesh->id,
|
||||
.instance = InstanceData {
|
||||
.transformMatrix = transform.toMatrix(),
|
||||
}
|
||||
@@ -45,10 +45,10 @@ void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
|
||||
Meshlet& m = loadedMeshlets[currentMesh + i];
|
||||
uint32 vertexOffset = vertexIndices.size();
|
||||
vertexIndices.resize(vertexOffset + m.numVertices);
|
||||
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices.data(), sizeof(m.uniqueVertices));
|
||||
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices.data(), m.numVertices * sizeof(uint32));
|
||||
uint32 primitiveOffset = primitiveIndices.size();
|
||||
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
||||
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout.data(), sizeof(m.primitiveLayout));
|
||||
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout.data(), m.numPrimitives * 3 * sizeof(uint8));
|
||||
meshlets.add(MeshletDescription{
|
||||
.boundingBox = MeshletAABB(),
|
||||
.vertexCount = m.numVertices,
|
||||
@@ -193,9 +193,9 @@ void Seele::VertexData::init(Gfx::PGraphics graphics)
|
||||
|
||||
VertexData::VertexData()
|
||||
: idCounter(0)
|
||||
, dirty(false)
|
||||
, head(0)
|
||||
, verticesAllocated(0)
|
||||
, dirty(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,7 @@
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Component
|
||||
{
|
||||
struct Mesh;
|
||||
}
|
||||
DECLARE_REF(Mesh)
|
||||
struct MeshId
|
||||
{
|
||||
uint64 id;
|
||||
@@ -60,7 +57,7 @@ public:
|
||||
uint32 indicesOffset;
|
||||
};
|
||||
void resetMeshData();
|
||||
void updateMesh(const Component::Transform& transform, const Component::Mesh& mesh);
|
||||
void updateMesh(const Component::Transform& transform, PMesh mesh);
|
||||
void loadMesh(MeshId id, Array<Meshlet> meshlets);
|
||||
void createDescriptors();
|
||||
MeshId allocateVertexData(uint64 numVertices);
|
||||
|
||||
@@ -18,22 +18,12 @@ SubAllocation::~SubAllocation()
|
||||
owner->markFree(this);
|
||||
}
|
||||
|
||||
constexpr VkDeviceMemory SubAllocation::getHandle() const
|
||||
VkDeviceMemory SubAllocation::getHandle() const
|
||||
{
|
||||
return owner->getHandle();
|
||||
}
|
||||
|
||||
constexpr VkDeviceSize SubAllocation::getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
constexpr VkDeviceSize SubAllocation::getOffset() const
|
||||
{
|
||||
return alignedOffset;
|
||||
}
|
||||
|
||||
constexpr bool SubAllocation::isReadable() const
|
||||
bool SubAllocation::isReadable() const
|
||||
{
|
||||
return owner->isReadable();
|
||||
}
|
||||
@@ -203,30 +193,6 @@ void Allocation::markFree(PSubAllocation allocation)
|
||||
}
|
||||
}
|
||||
|
||||
constexpr VkDeviceMemory Allocation::getHandle() const
|
||||
{
|
||||
return allocatedMemory;
|
||||
}
|
||||
|
||||
constexpr void* Allocation::getMappedPointer()
|
||||
{
|
||||
if (!canMap)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if (!isMapped)
|
||||
{
|
||||
vkMapMemory(device, allocatedMemory, 0, bytesAllocated, 0, &mappedPointer);
|
||||
isMapped = true;
|
||||
}
|
||||
return mappedPointer;
|
||||
}
|
||||
|
||||
constexpr bool Allocation::isReadable() const
|
||||
{
|
||||
return readable;
|
||||
}
|
||||
|
||||
void Allocation::flushMemory()
|
||||
{
|
||||
VkMappedMemoryRange range = {
|
||||
@@ -260,6 +226,7 @@ Allocator::Allocator(PGraphics graphics)
|
||||
VkMemoryHeap memoryHeap = memProperties.memoryHeaps[i];
|
||||
HeapInfo heapInfo;
|
||||
heapInfo.maxSize = memoryHeap.size;
|
||||
std::cout << "Creating heap " << i << " with properties " << memoryHeap.flags << " size " << memoryHeap.size << std::endl;
|
||||
heaps.add(std::move(heapInfo));
|
||||
}
|
||||
}
|
||||
@@ -293,6 +260,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
|
||||
{
|
||||
OAllocation newAllocation = new Allocation(graphics, this, requirements.size, memoryTypeIndex, properties, dedicatedInfo);
|
||||
heaps[heapIndex].inUse += newAllocation->bytesAllocated;
|
||||
std::cout << "Heap " << heapIndex << " +" <<newAllocation->bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
|
||||
heaps[heapIndex].allocations.add(std::move(newAllocation));
|
||||
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
|
||||
}
|
||||
@@ -312,7 +280,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
|
||||
// no suitable allocations found, allocate new block
|
||||
OAllocation newAllocation = new Allocation(graphics, this, (requirements.size > MemoryBlockSize) ? requirements.size : (VkDeviceSize)MemoryBlockSize, memoryTypeIndex, properties, nullptr);
|
||||
heaps[heapIndex].inUse += newAllocation->bytesAllocated;
|
||||
heaps[heapIndex].allocations.add(std::move(newAllocation));
|
||||
std::cout << "Heap " << heapIndex << " +" <<newAllocation->bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; heaps[heapIndex].allocations.add(std::move(newAllocation));
|
||||
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
|
||||
}
|
||||
|
||||
@@ -321,12 +289,13 @@ void Allocator::free(Allocation *allocation)
|
||||
std::scoped_lock lck(lock);
|
||||
for (auto& heap : heaps)
|
||||
{
|
||||
for (uint32 i = 0; i < heap.allocations.size(); ++i)
|
||||
for (uint32 heapIndex = 0; heapIndex < heap.allocations.size(); ++heapIndex)
|
||||
{
|
||||
if (heap.allocations[i] == allocation)
|
||||
if (heap.allocations[heapIndex] == allocation)
|
||||
{
|
||||
heap.inUse -= allocation->bytesAllocated;
|
||||
heap.allocations.removeAt(i, false);
|
||||
std::cout << "Heap " << heapIndex << " -" <<allocation->bytesAllocated << ":" << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
|
||||
heap.allocations.removeAt(heapIndex, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -374,31 +343,21 @@ void StagingBuffer::invalidateMemory()
|
||||
allocation->invalidateMemory();
|
||||
}
|
||||
|
||||
constexpr VkDeviceMemory StagingBuffer::getMemoryHandle() const
|
||||
VkDeviceMemory StagingBuffer::getMemoryHandle() const
|
||||
{
|
||||
return allocation->getHandle();
|
||||
}
|
||||
|
||||
constexpr VkDeviceSize StagingBuffer::getOffset() const
|
||||
VkDeviceSize StagingBuffer::getOffset() const
|
||||
{
|
||||
return allocation->getOffset();
|
||||
}
|
||||
|
||||
constexpr uint64 StagingBuffer::getSize() const
|
||||
uint64 StagingBuffer::getSize() const
|
||||
{
|
||||
return allocation->getSize();
|
||||
}
|
||||
|
||||
constexpr bool StagingBuffer::isReadable() const
|
||||
{
|
||||
return readable;
|
||||
}
|
||||
|
||||
constexpr VkBufferUsageFlags StagingBuffer::getUsage() const
|
||||
{
|
||||
return usage;
|
||||
}
|
||||
|
||||
StagingManager::StagingManager(PGraphics graphics, PAllocator allocator)
|
||||
: graphics(graphics), allocator(allocator)
|
||||
{
|
||||
@@ -422,8 +381,9 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
|
||||
{
|
||||
//std::cout << "Reusing staging buffer" << std::endl;
|
||||
activeBuffers.add(freeBuffer);
|
||||
OStagingBuffer owner = std::move(freeBuffer);
|
||||
freeBuffers.remove(it, false);
|
||||
return std::move(freeBuffer);
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
//std::cout << "Creating new stagingbuffer" << std::endl;
|
||||
@@ -463,6 +423,8 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
|
||||
);
|
||||
vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemoryHandle(), stagingBuffer->getOffset());
|
||||
|
||||
std::cout << "Creating new stagingbuffer size " << stagingBuffer->getSize() << std::endl;
|
||||
|
||||
activeBuffers.add(stagingBuffer);
|
||||
|
||||
return stagingBuffer;
|
||||
@@ -471,6 +433,11 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
|
||||
void StagingManager::releaseStagingBuffer(OStagingBuffer buffer)
|
||||
{
|
||||
std::scoped_lock l(lock);
|
||||
if(activeBuffers.find(buffer) == activeBuffers.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
activeBuffers.remove(buffer);
|
||||
std::cout << "Releasing stagingbuffer size " << buffer->getSize() << std::endl;
|
||||
freeBuffers.add(std::move(buffer));
|
||||
}
|
||||
@@ -17,10 +17,20 @@ class SubAllocation
|
||||
public:
|
||||
SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize);
|
||||
~SubAllocation();
|
||||
constexpr VkDeviceMemory getHandle() const;
|
||||
constexpr VkDeviceSize getSize() const;
|
||||
constexpr VkDeviceSize getOffset() const;
|
||||
constexpr bool isReadable() const;
|
||||
VkDeviceMemory getHandle() const;
|
||||
|
||||
constexpr VkDeviceSize getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
constexpr VkDeviceSize getOffset() const
|
||||
{
|
||||
return alignedOffset;
|
||||
}
|
||||
|
||||
bool isReadable() const;
|
||||
|
||||
void *getMappedPointer();
|
||||
void flushMemory();
|
||||
void invalidateMemory();
|
||||
@@ -43,9 +53,30 @@ public:
|
||||
~Allocation();
|
||||
OSubAllocation getSuballocation(VkDeviceSize size, VkDeviceSize alignment);
|
||||
void markFree(PSubAllocation alloc);
|
||||
constexpr VkDeviceMemory getHandle() const;
|
||||
constexpr void* getMappedPointer();
|
||||
constexpr bool isReadable() const;
|
||||
constexpr VkDeviceMemory getHandle() const
|
||||
{
|
||||
return allocatedMemory;
|
||||
}
|
||||
|
||||
constexpr void* getMappedPointer()
|
||||
{
|
||||
if (!canMap)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if (!isMapped)
|
||||
{
|
||||
vkMapMemory(device, allocatedMemory, 0, bytesAllocated, 0, &mappedPointer);
|
||||
isMapped = true;
|
||||
}
|
||||
return mappedPointer;
|
||||
}
|
||||
|
||||
constexpr bool isReadable() const
|
||||
{
|
||||
return readable;
|
||||
}
|
||||
|
||||
void flushMemory();
|
||||
void invalidateMemory();
|
||||
|
||||
@@ -134,11 +165,19 @@ public:
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
constexpr VkDeviceMemory getMemoryHandle() const;
|
||||
constexpr VkDeviceSize getOffset() const;
|
||||
constexpr uint64 getSize() const;
|
||||
constexpr bool isReadable() const;
|
||||
constexpr VkBufferUsageFlags getUsage() const;
|
||||
VkDeviceMemory getMemoryHandle() const;
|
||||
VkDeviceSize getOffset() const;
|
||||
uint64 getSize() const;
|
||||
constexpr bool isReadable() const
|
||||
{
|
||||
return readable;
|
||||
}
|
||||
|
||||
constexpr VkBufferUsageFlags getUsage() const
|
||||
{
|
||||
return usage;
|
||||
}
|
||||
|
||||
private:
|
||||
OSubAllocation allocation;
|
||||
VkBuffer buffer;
|
||||
|
||||
@@ -291,6 +291,7 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &
|
||||
|
||||
UniformBuffer::~UniformBuffer()
|
||||
{
|
||||
graphics->getStagingManager()->releaseStagingBuffer(std::move(dedicatedStagingBuffer));
|
||||
}
|
||||
|
||||
bool UniformBuffer::updateContents(const DataSource &sourceData)
|
||||
@@ -363,7 +364,12 @@ VkAccessFlags UniformBuffer::getDestAccessMask()
|
||||
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sourceData)
|
||||
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.stride, sourceData.sourceData.size / sourceData.stride, sourceData.sourceData)
|
||||
, Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, sourceData.dynamic)
|
||||
, dedicatedStagingBuffer(nullptr)
|
||||
{
|
||||
if(sourceData.dynamic)
|
||||
{
|
||||
dedicatedStagingBuffer = graphics->getStagingManager()->allocateStagingBuffer(sourceData.sourceData.size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||
}
|
||||
if (sourceData.sourceData.data != nullptr)
|
||||
{
|
||||
void *data = lock();
|
||||
@@ -374,6 +380,7 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sou
|
||||
|
||||
ShaderBuffer::~ShaderBuffer()
|
||||
{
|
||||
graphics->getStagingManager()->releaseStagingBuffer(std::move(dedicatedStagingBuffer));
|
||||
}
|
||||
|
||||
bool ShaderBuffer::updateContents(const DataSource &sourceData)
|
||||
@@ -422,13 +429,13 @@ void ShaderBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner)
|
||||
|
||||
void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
|
||||
{
|
||||
Vulkan::ShaderBuffer::executeOwnershipBarrier(newOwner);
|
||||
Vulkan::Buffer::executeOwnershipBarrier(newOwner);
|
||||
}
|
||||
|
||||
void ShaderBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
|
||||
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
|
||||
{
|
||||
Vulkan::ShaderBuffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
|
||||
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
|
||||
}
|
||||
|
||||
VkAccessFlags ShaderBuffer::getSourceAccessMask()
|
||||
|
||||
@@ -34,7 +34,7 @@ protected:
|
||||
struct BufferAllocation
|
||||
{
|
||||
VkBuffer buffer;
|
||||
PSubAllocation allocation;
|
||||
OSubAllocation allocation;
|
||||
};
|
||||
PGraphics graphics;
|
||||
uint32 currentBuffer;
|
||||
@@ -140,6 +140,5 @@ protected:
|
||||
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
|
||||
};
|
||||
DEFINE_REF(IndexBuffer)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -172,6 +172,8 @@ VkDeviceCreateInfo init::DeviceCreateInfo(VkDeviceQueueCreateInfo *queueInfos, u
|
||||
createInfo.enabledLayerCount = layerCount;
|
||||
createInfo.ppEnabledLayerNames = layers;
|
||||
#else
|
||||
(void)layers;
|
||||
(void)layerCount;
|
||||
createInfo.enabledLayerCount = 0;
|
||||
layerCount = 0;
|
||||
layers = nullptr;
|
||||
|
||||
@@ -217,7 +217,7 @@ void TextureHandle::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Ar
|
||||
auto prevlayout = layout;
|
||||
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
|
||||
Gfx::FormatCompatibilityInfo formatInfo = Gfx::getFormatInfo(format);
|
||||
//Gfx::FormatCompatibilityInfo formatInfo = Gfx::getFormatInfo(format);
|
||||
VkBufferImageCopy region = {
|
||||
.bufferOffset = 0,
|
||||
.bufferRowLength = 0,
|
||||
|
||||
@@ -14,21 +14,24 @@ MaterialInstance::MaterialInstance(uint64 id,
|
||||
Array<std::string> params,
|
||||
uint32 uniformBinding,
|
||||
uint32 uniformSize)
|
||||
: id(id)
|
||||
, graphics(graphics)
|
||||
: graphics(graphics)
|
||||
, uniformBinding(uniformBinding)
|
||||
, id(id)
|
||||
{
|
||||
uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = uniformSize,
|
||||
},
|
||||
.dynamic = true,
|
||||
}
|
||||
);
|
||||
if(uniformSize > 0)
|
||||
{
|
||||
uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = uniformSize,
|
||||
},
|
||||
.dynamic = true,
|
||||
}
|
||||
);
|
||||
}
|
||||
uniformData.resize(uniformSize);
|
||||
ArchiveBuffer buffer(graphics);
|
||||
parameters.reserve(params.size());
|
||||
for (int i = 0; i < params.size(); ++i)
|
||||
for (size_t i = 0; i < params.size(); ++i)
|
||||
{
|
||||
Serialization::save(buffer, expressions[params[i]]);
|
||||
buffer.rewind();
|
||||
@@ -52,6 +55,14 @@ void MaterialInstance::updateDescriptor()
|
||||
{
|
||||
param->updateDescriptorSet(descriptor, uniformData.data());
|
||||
}
|
||||
if(uniformData.size() > 0)
|
||||
{
|
||||
uniformBuffer->updateContents(DataSource{
|
||||
.size = uniformData.size(),
|
||||
.data = uniformData.data(),
|
||||
});
|
||||
descriptor->updateBuffer(uniformBinding, uniformBuffer);
|
||||
}
|
||||
descriptor->writeChanges();
|
||||
}
|
||||
|
||||
@@ -62,13 +73,16 @@ Gfx::PDescriptorSet MaterialInstance::getDescriptorSet() const
|
||||
|
||||
void MaterialInstance::setBaseMaterial(PMaterialAsset asset)
|
||||
{
|
||||
uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = uniformData.size(),
|
||||
},
|
||||
.dynamic = true,
|
||||
}
|
||||
);
|
||||
if(uniformData.size() > 0)
|
||||
{
|
||||
uniformBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = uniformData.size(),
|
||||
},
|
||||
.dynamic = true,
|
||||
}
|
||||
);
|
||||
}
|
||||
baseMaterial = asset;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
#include <format>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -40,6 +41,10 @@ ShaderExpression::ShaderExpression(std::string key)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderExpression::~ShaderExpression()
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderExpression::save(ArchiveBuffer& buffer) const
|
||||
{
|
||||
Serialization::save(buffer, inputs);
|
||||
|
||||
@@ -38,6 +38,7 @@ struct ShaderExpression
|
||||
std::string key;
|
||||
ShaderExpression();
|
||||
ShaderExpression(std::string key);
|
||||
virtual ~ShaderExpression();
|
||||
virtual uint64 getIdentifier() const = 0;
|
||||
virtual std::string evaluate(Map<std::string, std::string>& varState) const = 0;
|
||||
virtual void save(ArchiveBuffer& buffer) const;
|
||||
@@ -216,14 +217,14 @@ struct MaterialNode
|
||||
void load(ArchiveBuffer& buffer);
|
||||
};
|
||||
template<>
|
||||
static void Serialization::save(ArchiveBuffer& buffer, const OShaderExpression& parameter)
|
||||
void Serialization::save(ArchiveBuffer& buffer, const OShaderExpression& parameter)
|
||||
{
|
||||
Serialization::save(buffer, parameter->getIdentifier());
|
||||
parameter->save(buffer);
|
||||
}
|
||||
|
||||
template<>
|
||||
static void Serialization::load(ArchiveBuffer& buffer, OShaderExpression& parameter)
|
||||
void Serialization::load(ArchiveBuffer& buffer, OShaderExpression& parameter)
|
||||
{
|
||||
uint64 identifier = 0;
|
||||
Serialization::load(buffer, identifier);
|
||||
@@ -269,14 +270,14 @@ static void Serialization::load(ArchiveBuffer& buffer, OShaderExpression& parame
|
||||
}
|
||||
|
||||
template<>
|
||||
static void Serialization::save(ArchiveBuffer& buffer, const OShaderParameter& parameter)
|
||||
void Serialization::save(ArchiveBuffer& buffer, const OShaderParameter& parameter)
|
||||
{
|
||||
Serialization::save(buffer, parameter->getIdentifier());
|
||||
parameter->save(buffer);
|
||||
}
|
||||
|
||||
template<>
|
||||
static void Serialization::load(ArchiveBuffer& buffer, OShaderParameter& parameter)
|
||||
void Serialization::load(ArchiveBuffer& buffer, OShaderParameter& parameter)
|
||||
{
|
||||
uint64 identifier = 0;
|
||||
Serialization::load(buffer, identifier);
|
||||
|
||||
@@ -157,6 +157,10 @@ public:
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if(pointer != nullptr)
|
||||
{
|
||||
Deleter()(pointer);
|
||||
}
|
||||
pointer = other.pointer;
|
||||
}
|
||||
return *this;
|
||||
|
||||
@@ -109,7 +109,7 @@ void BVH::reinsertCollider(entt::entity entity, AABB aabb)
|
||||
void BVH::removeCollider(entt::entity entity)
|
||||
{
|
||||
int32 nodeIndex = -1;
|
||||
for (int32 i = 0; i < dynamicNodes.size(); i++)
|
||||
for (size_t i = 0; i < dynamicNodes.size(); i++)
|
||||
{
|
||||
if(dynamicNodes[i].isLeaf && dynamicNodes[i].owner == entity)
|
||||
{
|
||||
@@ -119,7 +119,6 @@ void BVH::removeCollider(entt::entity entity)
|
||||
}
|
||||
if(nodeIndex == -1)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
int32 parentIndex = dynamicNodes[nodeIndex].parentIndex;
|
||||
@@ -354,7 +353,7 @@ int32 BVH::splitNode(Array<AABBCenter> aabbs)
|
||||
}
|
||||
int32 BVH::allocateNode()
|
||||
{
|
||||
for (int32 i = 0; i < dynamicNodes.size(); i++)
|
||||
for (size_t i = 0; i < dynamicNodes.size(); i++)
|
||||
{
|
||||
if(!dynamicNodes[i].isValid)
|
||||
{
|
||||
@@ -377,7 +376,7 @@ void BVH::validateBVH() const
|
||||
{
|
||||
assert(dynamicNodes[dynamicRoot].parentIndex == -1);
|
||||
}
|
||||
for(int32 i = 0; i < dynamicNodes.size(); ++i)
|
||||
for(size_t i = 0; i < dynamicNodes.size(); ++i)
|
||||
{
|
||||
int32 nodeIdx = i;
|
||||
size_t counter = dynamicNodes.size();
|
||||
|
||||
@@ -91,7 +91,7 @@ bool CollisionSystem::createWitness(Witness& result, const ShapeBase& source, co
|
||||
}
|
||||
for (size_t i = 0; i < source.indices.size(); i += 3)
|
||||
{
|
||||
auto findEdgePlane = [=, &result](uint32_t point1Index, uint32_t point2Index)
|
||||
auto findEdgePlane = [this, &source, &other, &result](uint32_t point1Index, uint32_t point2Index)
|
||||
{
|
||||
const glm::vec3 point1 = source.vertices[point1Index];
|
||||
const glm::vec3 point2 = source.vertices[point2Index];
|
||||
|
||||
@@ -346,19 +346,19 @@ void PhysicsSystem::calculateContacts(entt::entity id1, const ShapeBase& shape1,
|
||||
&& tx >= 0.f
|
||||
&& tx <= 1.f)
|
||||
{
|
||||
Vector p = p1 + tx * (p2 - p1);
|
||||
Vector ea = p2 - p1;
|
||||
Vector eb = p4 - p3;
|
||||
Vector n = glm::normalize(glm::cross(eb, ea));
|
||||
Contact contact = {
|
||||
.a = id1,
|
||||
.b = id2,
|
||||
.p = p,
|
||||
.n = n,
|
||||
.ea = ea,
|
||||
.eb = eb,
|
||||
.vf = false
|
||||
};
|
||||
// Vector p = p1 + tx * (p2 - p1);
|
||||
// Vector ea = p2 - p1;
|
||||
// Vector eb = p4 - p3;
|
||||
// Vector n = glm::normalize(glm::cross(eb, ea));
|
||||
// Contact contact = {
|
||||
// .a = id1,
|
||||
// .b = id2,
|
||||
// .p = p,
|
||||
// .n = n,
|
||||
// .ea = ea,
|
||||
// .eb = eb,
|
||||
// .vf = false
|
||||
// };
|
||||
}
|
||||
};
|
||||
for(size_t j = 0; j < shape2.indices.size(); j+=3)
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
add_subdirectory(Windows/)
|
||||
if(WIN32)
|
||||
add_subdirectory(Windows/)
|
||||
else()
|
||||
add_subdirectory(Linux/)
|
||||
endif()
|
||||
@@ -0,0 +1,10 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
GameInterface.h
|
||||
GameInterface.cpp)
|
||||
|
||||
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
FILES
|
||||
GameInterface.h)
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "GameInterface.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
GameInterface::GameInterface(std::string soPath)
|
||||
: lib(NULL)
|
||||
, soPath(soPath)
|
||||
{
|
||||
}
|
||||
|
||||
GameInterface::~GameInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Game* GameInterface::getGame()
|
||||
{
|
||||
return game;
|
||||
}
|
||||
|
||||
void GameInterface::reload(AssetRegistry* registry)
|
||||
{
|
||||
if(lib != NULL)
|
||||
{
|
||||
destroyInstance(game);
|
||||
dlclose(lib);
|
||||
}
|
||||
lib = dlopen(soPath.c_str(), RTLD_NOW);
|
||||
createInstance = (decltype(createInstance))dlsym(lib, "createInstance");
|
||||
destroyInstance = (decltype(destroyInstance))dlsym(lib, "destroyInstance");
|
||||
game = createInstance(registry);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Game.h"
|
||||
#include "dlfcn.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class GameInterface
|
||||
{
|
||||
public:
|
||||
GameInterface(std::string soPath);
|
||||
~GameInterface();
|
||||
Game* getGame();
|
||||
void reload(AssetRegistry* registry);
|
||||
private:
|
||||
void* lib;
|
||||
std::string soPath;
|
||||
Game* game;
|
||||
Game* (*createInstance)(AssetRegistry*) = nullptr;
|
||||
void (*destroyInstance)(Game*) = nullptr;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -14,8 +14,8 @@ using namespace Seele;
|
||||
|
||||
Scene::Scene(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
, physics(registry)
|
||||
, lightEnv(new LightEnvironment(graphics))
|
||||
, physics(registry)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ public:
|
||||
Gfx::PGraphics getGraphics() const { return graphics; }
|
||||
entt::registry registry;
|
||||
private:
|
||||
Gfx::PGraphics graphics;
|
||||
OLightEnvironment lightEnv;
|
||||
PhysicsSystem physics;
|
||||
Gfx::PGraphics graphics;
|
||||
};
|
||||
DEFINE_REF(Scene)
|
||||
} // namespace Seele
|
||||
@@ -59,7 +59,7 @@ void ArchiveBuffer::seek(int64 s, SeekOp op)
|
||||
newPos = position + s;
|
||||
break;
|
||||
}
|
||||
assert(newPos >= 0 && newPos < memory.size());
|
||||
assert(newPos >= 0 && size_t(newPos) < memory.size());
|
||||
newPos = position;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,14 @@ public:
|
||||
{
|
||||
return (deps | ...);
|
||||
}
|
||||
void setupView(Dependencies<>, dp::thread_pool<>&)
|
||||
{
|
||||
registry.view<Components...>().each([&](Components&... comp){
|
||||
//pool.enqueue_detach([&](){
|
||||
update(comp...);
|
||||
//});
|
||||
});
|
||||
}
|
||||
template<typename... Deps>
|
||||
void setupView(Dependencies<Deps...>, dp::thread_pool<>&)
|
||||
{
|
||||
@@ -37,20 +45,12 @@ public:
|
||||
//});
|
||||
});
|
||||
}
|
||||
template<>
|
||||
void setupView(Dependencies<>, dp::thread_pool<>&)
|
||||
{
|
||||
registry.view<Components...>().each([&](Components&... comp){
|
||||
//pool.enqueue_detach([&](){
|
||||
update(comp...);
|
||||
//});
|
||||
});
|
||||
}
|
||||
virtual void run(dp::thread_pool<>& pool, double delta) override
|
||||
{
|
||||
SystemBase::run(pool, delta);
|
||||
setupView(mergeDependencies((getDependencies<Components>(),...)), pool);
|
||||
}
|
||||
virtual void update() {}
|
||||
virtual void update(Components&... components) = 0;
|
||||
};
|
||||
} // namespace System
|
||||
|
||||
@@ -12,7 +12,10 @@ MeshUpdater::~MeshUpdater()
|
||||
{
|
||||
}
|
||||
|
||||
void MeshUpdater::update(Component::Transform& transform, Component::Mesh& mesh)
|
||||
void MeshUpdater::update(Component::Transform& transform, Component::Mesh& meshComp)
|
||||
{
|
||||
mesh.vertexData->updateMesh(transform, mesh);
|
||||
for(const auto& mesh : meshComp.asset->meshes)
|
||||
{
|
||||
mesh->vertexData->updateMesh(transform, mesh);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class SystemBase
|
||||
public:
|
||||
SystemBase(PScene scene) : registry(scene->registry), scene(scene) {}
|
||||
virtual ~SystemBase() {}
|
||||
virtual void run(dp::thread_pool<>& pool, double delta)
|
||||
virtual void run(dp::thread_pool<>&, double delta)
|
||||
{
|
||||
deltaTime = delta;
|
||||
update();
|
||||
|
||||
@@ -22,7 +22,7 @@ void System::update()
|
||||
|
||||
}
|
||||
|
||||
void System::updateViewport(Gfx::PViewport viewport)
|
||||
void System::updateViewport(Gfx::PViewport)
|
||||
{
|
||||
//TODO set viewport FoV to 0
|
||||
}
|
||||
|
||||
@@ -9,12 +9,13 @@ using namespace Seele;
|
||||
|
||||
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string dllPath)
|
||||
: View(graphics, window, createInfo, "Game")
|
||||
, scene(new Scene(graphics))
|
||||
, gameInterface(dllPath)
|
||||
, renderGraph(RenderGraphBuilder::build(
|
||||
std::move(DepthPrepass(graphics, scene)),
|
||||
std::move(LightCullingPass(graphics, scene)),
|
||||
std::move(BasePass(graphics, scene)),
|
||||
std::move(SkyboxRenderPass(graphics, scene))
|
||||
DepthPrepass(graphics, scene),
|
||||
LightCullingPass(graphics, scene),
|
||||
BasePass(graphics, scene),
|
||||
SkyboxRenderPass(graphics, scene)
|
||||
))
|
||||
{
|
||||
reloadGame();
|
||||
@@ -75,7 +76,7 @@ void GameView::reloadGame()
|
||||
|
||||
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier)
|
||||
{
|
||||
scene->view<Component::KeyboardInput>([=](Component::KeyboardInput& input)
|
||||
scene->view<Component::KeyboardInput>([=, this](Component::KeyboardInput& input)
|
||||
{
|
||||
//if(code == KeyCode::KEY_R && action == InputAction::PRESS)
|
||||
//{
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
#include "Graphics/RenderPass/LightCullingPass.h"
|
||||
#include "Graphics/RenderPass/BasePass.h"
|
||||
#include "Graphics/RenderPass/SkyboxRenderPass.h"
|
||||
#ifdef WIN32
|
||||
#include "Platform/Windows/GameInterface.h" // TODO
|
||||
#else
|
||||
#include "Platform/Linux/GameInterface.h"
|
||||
#endif
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -23,6 +27,8 @@ public:
|
||||
|
||||
void reloadGame();
|
||||
private:
|
||||
OScene scene;
|
||||
PEntity camera;
|
||||
GameInterface gameInterface;
|
||||
RenderGraph<
|
||||
DepthPrepass,
|
||||
@@ -31,8 +37,6 @@ private:
|
||||
SkyboxRenderPass
|
||||
> renderGraph;
|
||||
|
||||
PEntity camera;
|
||||
OScene scene;
|
||||
PSystemGraph systemGraph;
|
||||
dp::thread_pool<> threadPool;
|
||||
float updateTime = 0;
|
||||
|
||||
Reference in New Issue
Block a user