Fixing destruction

This commit is contained in:
Dynamitos
2024-07-18 11:45:56 +02:00
parent 67c4ce2f7a
commit 3b6eb3ebcc
31 changed files with 173 additions and 82 deletions
+2 -2
View File
@@ -32,8 +32,8 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
} }
result += brdf.evaluateAmbient(); result += brdf.evaluateAmbient();
// gamma correction // gamma correction
result = result / (result + float3(1.0)); //result = result / (result + float3(1.0));
result = pow(result, float3(1.0/2.2)); //result = pow(result, float3(1.0/2.2));
return float4(result, brdf.getAlpha()); return float4(result, brdf.getAlpha());
} }
+1
View File
@@ -54,6 +54,7 @@ int main(int argc, char** argv) {
while (windowManager->isActive()) { while (windowManager->isActive()) {
windowManager->render(); windowManager->render();
} }
graphics->waitDeviceIdle();
vd->destroy(); vd->destroy();
return 0; return 0;
+2 -4
View File
@@ -533,8 +533,6 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
globalMeshes[meshIndex]->vertexData = vertexData; globalMeshes[meshIndex]->vertexData = vertexData;
globalMeshes[meshIndex]->id = id; globalMeshes[meshIndex]->id = id;
globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex]; globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex];
globalMeshes[meshIndex]->meshlets = std::move(meshlets);
globalMeshes[meshIndex]->indices = std::move(indices);
globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices; globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices;
globalMeshes[meshIndex]->blas = graphics->createBottomLevelAccelerationStructure(Gfx::BottomLevelASCreateInfo{ globalMeshes[meshIndex]->blas = graphics->createBottomLevelAccelerationStructure(Gfx::BottomLevelASCreateInfo{
.mesh = globalMeshes[meshIndex], .mesh = globalMeshes[meshIndex],
@@ -563,8 +561,8 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset) {
meshAsset->setStatus(Asset::Status::Loading); meshAsset->setStatus(Asset::Status::Loading);
Assimp::Importer importer; Assimp::Importer importer;
importer.ReadFile(args.filePath.string().c_str(), importer.ReadFile(args.filePath.string().c_str(),
(uint32)(aiProcess_JoinIdenticalVertices | aiProcess_FlipUVs | aiProcess_Triangulate | aiProcess_SortByPType | (uint32)(aiProcess_FlipUVs | aiProcess_Triangulate | aiProcess_SortByPType |
aiProcess_GenBoundingBoxes | aiProcess_GenSmoothNormals | aiProcess_ImproveCacheLocality | aiProcess_GenBoundingBoxes | aiProcess_GenSmoothNormals |
aiProcess_GenUVCoords | aiProcess_FindDegenerates)); aiProcess_GenUVCoords | aiProcess_FindDegenerates));
const aiScene* scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace); const aiScene* scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
std::cout << importer.GetErrorString() << std::endl; std::cout << importer.GetErrorString() << std::endl;
+8 -6
View File
@@ -14,6 +14,7 @@
#include <stb_image_write.h> #include <stb_image_write.h>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include "ktx.h" #include "ktx.h"
#include <ThreadPool.h>
#include <fstream> #include <fstream>
using namespace Seele; using namespace Seele;
@@ -110,13 +111,12 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
ktxBasisParams basisParams = { ktxBasisParams basisParams = {
.structSize = sizeof(ktxBasisParams), .structSize = sizeof(ktxBasisParams),
.uastc = true, .uastc = true,
.threadCount = std::thread::hardware_concurrency() - 2, .threadCount = std::thread::hardware_concurrency(),
.uastcFlags = KTX_PACK_UASTC_LEVEL_DEFAULT, .uastcFlags = KTX_PACK_UASTC_LEVEL_DEFAULT,
.uastcRDO = true, .uastcRDO = true,
}; };
//KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams)); //KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
// //KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 20));
//KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 15));
char writer[100]; char writer[100];
snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1"); snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
@@ -126,7 +126,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
size_t texSize; size_t texSize;
KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize)); KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize));
//ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.filename().replace_extension(".ktx").generic_string().c_str()); // ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.filename().replace_extension(".ktx").generic_string().c_str());
Array<uint8> serialized(texSize); Array<uint8> serialized(texSize);
std::memcpy(serialized.data(), texData, texSize); std::memcpy(serialized.data(), texData, texSize);
@@ -138,7 +138,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
return; return;
} }
textureAsset->setTexture(std::move(serialized)); //textureAsset->setTexture(std::move(serialized));
std::string path = (std::filesystem::path(args.importPath) / textureAsset->getName()).string().append(".asset"); std::string path = (std::filesystem::path(args.importPath) / textureAsset->getName()).string().append(".asset");
auto assetStream = AssetRegistry::createWriteStream(std::move(path), std::ios::binary); auto assetStream = AssetRegistry::createWriteStream(std::move(path), std::ios::binary);
@@ -150,11 +150,13 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
// write folder // write folder
Serialization::save(buffer, textureAsset->getFolderPath()); Serialization::save(buffer, textureAsset->getFolderPath());
// write asset data // write asset data
textureAsset->save(buffer); //textureAsset->save(buffer);
Serialization::save(buffer, serialized);
buffer.writeToStream(assetStream); buffer.writeToStream(assetStream);
buffer.rewind(); buffer.rewind();
std::unique_lock l(AssetRegistry::get().assetLock);
AssetRegistry::get().loadAsset(buffer); AssetRegistry::get().loadAsset(buffer);
} }
+2
View File
@@ -93,6 +93,8 @@ int main() {
while (windowManager->isActive() && getGlobals().running) { while (windowManager->isActive() && getGlobals().running) {
windowManager->render(); windowManager->render();
} }
graphics->waitDeviceIdle();
Material::destroy();
vd->destroy(); vd->destroy();
// export game // export game
+6
View File
@@ -100,6 +100,7 @@ AssetRegistry::AssetFolder* AssetRegistry::getOrCreateFolder(std::string_view fu
} }
void AssetRegistry::initialize(const std::filesystem::path& _rootFolder, Gfx::PGraphics _graphics) { void AssetRegistry::initialize(const std::filesystem::path& _rootFolder, Gfx::PGraphics _graphics) {
std::unique_lock l(get().assetLock);
this->graphics = _graphics; this->graphics = _graphics;
this->rootFolder = _rootFolder; this->rootFolder = _rootFolder;
this->assetRoot = new AssetFolder(""); this->assetRoot = new AssetFolder("");
@@ -279,26 +280,31 @@ void AssetRegistry::saveAsset(PAsset asset, uint64 identifier, const std::filesy
std::filesystem::path AssetRegistry::getRootFolder() { return get().rootFolder; } std::filesystem::path AssetRegistry::getRootFolder() { return get().rootFolder; }
void AssetRegistry::registerMesh(OMeshAsset mesh) { void AssetRegistry::registerMesh(OMeshAsset mesh) {
std::unique_lock l(assetLock);
AssetFolder* folder = getOrCreateFolder(mesh->getFolderPath()); AssetFolder* folder = getOrCreateFolder(mesh->getFolderPath());
folder->meshes[mesh->getName()] = std::move(mesh); folder->meshes[mesh->getName()] = std::move(mesh);
} }
void AssetRegistry::registerTexture(OTextureAsset texture) { void AssetRegistry::registerTexture(OTextureAsset texture) {
std::unique_lock l(assetLock);
AssetFolder* folder = getOrCreateFolder(texture->getFolderPath()); AssetFolder* folder = getOrCreateFolder(texture->getFolderPath());
folder->textures[texture->getName()] = std::move(texture); folder->textures[texture->getName()] = std::move(texture);
} }
void AssetRegistry::registerFont(OFontAsset font) { void AssetRegistry::registerFont(OFontAsset font) {
std::unique_lock l(assetLock);
AssetFolder* folder = getOrCreateFolder(font->getFolderPath()); AssetFolder* folder = getOrCreateFolder(font->getFolderPath());
folder->fonts[font->getName()] = std::move(font); folder->fonts[font->getName()] = std::move(font);
} }
void AssetRegistry::registerMaterial(OMaterialAsset material) { void AssetRegistry::registerMaterial(OMaterialAsset material) {
std::unique_lock l(assetLock);
AssetFolder* folder = getOrCreateFolder(material->getFolderPath()); AssetFolder* folder = getOrCreateFolder(material->getFolderPath());
folder->materials[material->getName()] = std::move(material); folder->materials[material->getName()] = std::move(material);
} }
void AssetRegistry::registerMaterialInstance(OMaterialInstanceAsset material) { void AssetRegistry::registerMaterialInstance(OMaterialInstanceAsset material) {
std::unique_lock l(assetLock);
AssetFolder* folder = getOrCreateFolder(material->getFolderPath()); AssetFolder* folder = getOrCreateFolder(material->getFolderPath());
folder->instances[material->getName()] = std::move(material); folder->instances[material->getName()] = std::move(material);
} }
+1
View File
@@ -71,6 +71,7 @@ class AssetRegistry {
std::ifstream internalCreateReadStream(const std::filesystem::path& relaitvePath, std::ios_base::openmode openmode = std::ios::in); std::ifstream internalCreateReadStream(const std::filesystem::path& relaitvePath, std::ios_base::openmode openmode = std::ios::in);
std::filesystem::path rootFolder; std::filesystem::path rootFolder;
std::mutex assetLock;
AssetFolder* assetRoot; AssetFolder* assetRoot;
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
bool release = false; bool release = false;
+4 -1
View File
@@ -22,10 +22,13 @@ TextureAsset::TextureAsset(std::string_view folderPath, std::string_view name) :
TextureAsset::~TextureAsset() {} TextureAsset::~TextureAsset() {}
void TextureAsset::save(ArchiveBuffer& buffer) const { Serialization::save(buffer, ktxData); } void TextureAsset::save(ArchiveBuffer& buffer) const { /*
Serialization::save(buffer, ktxData);*/
}
void TextureAsset::load(ArchiveBuffer& buffer) { void TextureAsset::load(ArchiveBuffer& buffer) {
ktxTexture2* ktxHandle; ktxTexture2* ktxHandle;
Array<uint8> ktxData;
Serialization::load(buffer, ktxData); Serialization::load(buffer, ktxData);
KTX_ASSERT( KTX_ASSERT(
ktxTexture_CreateFromMemory(ktxData.data(), ktxData.size(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, (ktxTexture**)&ktxHandle)); ktxTexture_CreateFromMemory(ktxData.data(), ktxData.size(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, (ktxTexture**)&ktxHandle));
+1 -2
View File
@@ -13,13 +13,12 @@ class TextureAsset : public Asset {
virtual void save(ArchiveBuffer& buffer) const override; virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
Gfx::PTexture getTexture() { return texture; } Gfx::PTexture getTexture() { return texture; }
void setTexture(Array<uint8> data) { ktxData = std::move(data); } void setTexture(Array<uint8> data) { }
uint32 getWidth(); uint32 getWidth();
uint32 getHeight(); uint32 getHeight();
private: private:
Gfx::OTexture texture; Gfx::OTexture texture;
Array<uint8> ktxData;
friend class TextureLoader; friend class TextureLoader;
}; };
DEFINE_REF(TextureAsset) DEFINE_REF(TextureAsset)
+1 -1
View File
@@ -182,7 +182,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> c
_size = 0; _size = 0;
} }
// Insert at the end // Insert at the end
constexpr iterator add(const T& value) { return addInternal(value); } constexpr iterator add(const T& value = T()) { return addInternal(value); }
constexpr iterator add(T&& value) { return addInternal(std::move(value)); } constexpr iterator add(T&& value) { return addInternal(std::move(value)); }
template <typename... args> constexpr reference emplace(args... arguments) { template <typename... args> constexpr reference emplace(args... arguments) {
std::allocator_traits<NodeAllocator>::construct(allocator, tail, tail->prev, tail->next, arguments...); std::allocator_traits<NodeAllocator>::construct(allocator, tail, tail->prev, tail->next, arguments...);
+2
View File
@@ -1,4 +1,5 @@
#include "Command.h" #include "Command.h"
#include "Command.h"
using namespace Seele; using namespace Seele;
using namespace Seele::Gfx; using namespace Seele::Gfx;
@@ -10,3 +11,4 @@ RenderCommand::~RenderCommand() {}
ComputeCommand::ComputeCommand() {} ComputeCommand::ComputeCommand() {}
ComputeCommand::~ComputeCommand() {} ComputeCommand::~ComputeCommand() {}
-5
View File
@@ -12,8 +12,6 @@ void Mesh::save(ArchiveBuffer& buffer) const {
Serialization::save(buffer, transform); Serialization::save(buffer, transform);
Serialization::save(buffer, vertexData->getTypeName()); Serialization::save(buffer, vertexData->getTypeName());
Serialization::save(buffer, vertexCount); Serialization::save(buffer, vertexCount);
Serialization::save(buffer, indices);
Serialization::save(buffer, meshlets);
Serialization::save(buffer, referencedMaterial->getFolderPath()); Serialization::save(buffer, referencedMaterial->getFolderPath());
Serialization::save(buffer, referencedMaterial->getName()); Serialization::save(buffer, referencedMaterial->getName());
vertexData->serializeMesh(id, vertexCount, buffer); vertexData->serializeMesh(id, vertexCount, buffer);
@@ -25,15 +23,12 @@ void Mesh::load(ArchiveBuffer& buffer) {
Serialization::load(buffer, typeName); Serialization::load(buffer, typeName);
Serialization::load(buffer, vertexCount); Serialization::load(buffer, vertexCount);
vertexData = VertexData::findByTypeName(typeName); vertexData = VertexData::findByTypeName(typeName);
Serialization::load(buffer, indices);
Serialization::load(buffer, meshlets);
std::string refFolder; std::string refFolder;
Serialization::load(buffer, refFolder); Serialization::load(buffer, refFolder);
std::string refId; std::string refId;
Serialization::load(buffer, refId); Serialization::load(buffer, refId);
referencedMaterial = AssetRegistry::findMaterialInstance(refFolder, refId); referencedMaterial = AssetRegistry::findMaterialInstance(refFolder, refId);
id = vertexData->allocateVertexData(vertexCount); id = vertexData->allocateVertexData(vertexCount);
vertexData->loadMesh(id, indices, meshlets);
vertexData->deserializeMesh(id, buffer); vertexData->deserializeMesh(id, buffer);
blas = buffer.getGraphics()->createBottomLevelAccelerationStructure(Gfx::BottomLevelASCreateInfo{ blas = buffer.getGraphics()->createBottomLevelAccelerationStructure(Gfx::BottomLevelASCreateInfo{
.mesh = this, .mesh = this,
-2
View File
@@ -16,8 +16,6 @@ class Mesh {
MeshId id; MeshId id;
uint64 vertexCount; uint64 vertexCount;
PMaterialInstanceAsset referencedMaterial; PMaterialInstanceAsset referencedMaterial;
Array<uint32> indices;
Array<Meshlet> meshlets;
Gfx::OBottomLevelAS blas; Gfx::OBottomLevelAS blas;
void save(ArchiveBuffer& buffer) const; void save(ArchiveBuffer& buffer) const;
void load(ArchiveBuffer& buffer); void load(ArchiveBuffer& buffer);
@@ -53,6 +53,7 @@ void Seele::StaticMeshVertexData::loadColors(uint64 offset, const Array<Vector4>
} }
void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) { void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) {
VertexData::serializeMesh(id, numVertices, buffer);
uint64 offset; uint64 offset;
{ {
std::unique_lock l(vertexDataLock); std::unique_lock l(vertexDataLock);
@@ -82,6 +83,7 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
} }
void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) { void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
VertexData::deserializeMesh(id, buffer);
uint64 offset; uint64 offset;
{ {
std::unique_lock l(vertexDataLock); std::unique_lock l(vertexDataLock);
+31 -2
View File
@@ -147,8 +147,7 @@ void VertexData::createDescriptors() {
} }
} }
} }
for (uint32 i = 0; i < transparentData.size(); ++i) for (uint32 i = 0; i < transparentData.size(); ++i) {
{
transparentData[i].offsets.instanceOffset = instanceData.size(); transparentData[i].offsets.instanceOffset = instanceData.size();
instanceData.add(transparentData[i].instanceData); instanceData.add(transparentData[i].instanceData);
instanceMeshData.add(transparentData[i].meshData); instanceMeshData.add(transparentData[i].meshData);
@@ -299,6 +298,35 @@ MeshId VertexData::allocateVertexData(uint64 numVertices) {
return res; return res;
} }
void VertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) {
std::unique_lock l(vertexDataLock);
Array<Meshlet> out;
MeshData data = meshData[id];
for (size_t i = 0; i < data.numMeshlets; ++i)
{
MeshletDescription& desc = meshlets[i + data.meshletOffset];
Meshlet m;
std::memcpy(m.uniqueVertices, &vertexIndices[desc.vertexOffset], desc.vertexCount * sizeof(uint32));
std::memcpy(m.primitiveLayout, &primitiveIndices[desc.primitiveOffset], desc.primitiveCount * 3 * sizeof(uint8));
m.numPrimitives = desc.primitiveCount;
m.numVertices = desc.vertexCount;
m.boundingBox = desc.bounding;
out.add(std::move(m));
}
Array<uint32> ind(data.numIndices);
std::memcpy(ind.data(), &indices[data.firstIndex], data.numIndices * sizeof(uint32));
Serialization::save(buffer, out);
Serialization::save(buffer, ind);
}
void VertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
Array<Meshlet> in;
Array<uint32> ind;
Serialization::load(buffer, in);
Serialization::load(buffer, ind);
loadMesh(id, ind, in);
}
List<VertexData*> vertexDataList; List<VertexData*> vertexDataList;
List<VertexData*> VertexData::getList() { return vertexDataList; } List<VertexData*> VertexData::getList() { return vertexDataList; }
@@ -362,6 +390,7 @@ void VertexData::init(Gfx::PGraphics _graphics) {
} }
void VertexData::destroy() { void VertexData::destroy() {
cullingOffsetBuffer = nullptr;
instanceBuffer = nullptr; instanceBuffer = nullptr;
instanceMeshDataBuffer = nullptr; instanceMeshDataBuffer = nullptr;
instanceDataLayout = nullptr; instanceDataLayout = nullptr;
+2 -2
View File
@@ -61,8 +61,8 @@ class VertexData {
MeshId allocateVertexData(uint64 numVertices); MeshId allocateVertexData(uint64 numVertices);
uint64 getMeshOffset(MeshId id) const { return meshOffsets[id]; } uint64 getMeshOffset(MeshId id) const { return meshOffsets[id]; }
uint64 getMeshVertexCount(MeshId id) { return meshVertexCounts[id]; } uint64 getMeshVertexCount(MeshId id) { return meshVertexCounts[id]; }
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) = 0; virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer);
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) = 0; virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer);
virtual void bindBuffers(Gfx::PRenderCommand command) = 0; virtual void bindBuffers(Gfx::PRenderCommand command) = 0;
virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0; virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0;
virtual Gfx::PDescriptorSet getVertexDataSet() = 0; virtual Gfx::PDescriptorSet getVertexDataSet() = 0;
+15 -6
View File
@@ -54,6 +54,7 @@ void BufferAllocation::pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageF
.offset = 0, .offset = 0,
.size = size, .size = size,
}; };
commandBuffer->bindResource(this);
vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0, nullptr, 1, &barrier, 0, nullptr); vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0, nullptr, 1, &barrier, 0, nullptr);
} }
@@ -77,6 +78,8 @@ void BufferAllocation::transferOwnership(Gfx::QueueType newOwner) {
PCommandPool sourcePool = graphics->getQueueCommands(owner); PCommandPool sourcePool = graphics->getQueueCommands(owner);
PCommandPool dstPool = graphics->getQueueCommands(newOwner); PCommandPool dstPool = graphics->getQueueCommands(newOwner);
assert(barrier.srcQueueFamilyIndex != barrier.dstQueueFamilyIndex); assert(barrier.srcQueueFamilyIndex != barrier.dstQueueFamilyIndex);
sourcePool->getCommands()->bindResource(this);
dstPool->getCommands()->bindResource(this);
vkCmdPipelineBarrier(sourcePool->getCommands()->getHandle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, vkCmdPipelineBarrier(sourcePool->getCommands()->getHandle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0,
0, nullptr, 1, &barrier, 0, nullptr); 0, nullptr, 1, &barrier, 0, nullptr);
vkCmdPipelineBarrier(dstPool->getCommands()->getHandle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, vkCmdPipelineBarrier(dstPool->getCommands()->getHandle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0,
@@ -110,17 +113,15 @@ void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, vo
Gfx::QueueType prevOwner = owner; Gfx::QueueType prevOwner = owner;
// transferOwnership(Gfx::QueueType::TRANSFER); // transferOwnership(Gfx::QueueType::TRANSFER);
PCommand cmd = graphics->getQueueCommands(Gfx::QueueType::TRANSFER)->getCommands(); PCommand cmd = graphics->getQueueCommands(Gfx::QueueType::GRAPHICS)->getCommands();
VkBufferCopy copy = { VkBufferCopy copy = {
.srcOffset = 0, .srcOffset = 0,
.dstOffset = regionOffset, .dstOffset = regionOffset,
.size = regionSize, .size = regionSize,
}; };
vkCmdCopyBuffer(cmd->getHandle(), staging->buffer, buffer, 1, &copy);
pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);
cmd->bindResource(PBufferAllocation(this)); cmd->bindResource(PBufferAllocation(this));
cmd->bindResource(PBufferAllocation(staging)); cmd->bindResource(PBufferAllocation(staging));
vkCmdCopyBuffer(cmd->getHandle(), staging->buffer, buffer, 1, &copy);
// transferOwnership(prevOwner); // transferOwnership(prevOwner);
graphics->getDestructionManager()->queueResourceForDestruction(std::move(staging)); graphics->getDestructionManager()->queueResourceForDestruction(std::move(staging));
@@ -153,9 +154,9 @@ void BufferAllocation::readContents(uint64 regionOffset, uint64 regionSize, void
.dstOffset = 0, .dstOffset = 0,
.size = regionSize, .size = regionSize,
}; };
vkCmdCopyBuffer(cmd->getHandle(), buffer, staging->buffer, 1, &copy);
cmd->bindResource(PBufferAllocation(this)); cmd->bindResource(PBufferAllocation(this));
cmd->bindResource(PBufferAllocation(staging)); cmd->bindResource(PBufferAllocation(staging));
vkCmdCopyBuffer(cmd->getHandle(), buffer, staging->buffer, 1, &copy);
pool->submitCommands(); pool->submitCommands();
cmd->getFence()->wait(1000000); cmd->getFence()->wait(1000000);
@@ -250,6 +251,7 @@ void Buffer::createBuffer(uint64 size, uint32 destIndex) {
buffers[destIndex] = new BufferAllocation(graphics, name, info, allocInfo, initialOwner); buffers[destIndex] = new BufferAllocation(graphics, name, info, allocInfo, initialOwner);
if (createCleared) { if (createCleared) {
PCommand command = graphics->getQueueCommands(initialOwner)->getCommands(); PCommand command = graphics->getQueueCommands(initialOwner)->getCommands();
command->bindResource(PBufferAllocation(buffers[destIndex]));
vkCmdFillBuffer(command->getHandle(), buffers[destIndex]->buffer, 0, VK_WHOLE_SIZE, clearValue); vkCmdFillBuffer(command->getHandle(), buffers[destIndex]->buffer, 0, VK_WHOLE_SIZE, clearValue);
pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
@@ -284,6 +286,8 @@ void Buffer::copyBuffer(uint64 src, uint64 dst) {
.size = buffers[dst]->size, .size = buffers[dst]->size,
}; };
VkBufferMemoryBarrier srcBarriers[] = {srcBarrier, clearBarrier}; VkBufferMemoryBarrier srcBarriers[] = {srcBarrier, clearBarrier};
command->bindResource(PBufferAllocation(buffers[src]));
command->bindResource(PBufferAllocation(buffers[dst]));
vkCmdPipelineBarrier(command->getHandle(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 2, vkCmdPipelineBarrier(command->getHandle(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 2,
srcBarriers, 0, nullptr); srcBarriers, 0, nullptr);
VkBufferCopy region = { VkBufferCopy region = {
@@ -291,6 +295,8 @@ void Buffer::copyBuffer(uint64 src, uint64 dst) {
.dstOffset = 0, .dstOffset = 0,
.size = buffers[src]->size, .size = buffers[src]->size,
}; };
command->bindResource(PBufferAllocation(buffers[src]));
command->bindResource(PBufferAllocation(buffers[dst]));
vkCmdCopyBuffer(command->getHandle(), buffers[src]->buffer, buffers[dst]->buffer, 1, &region); vkCmdCopyBuffer(command->getHandle(), buffers[src]->buffer, buffers[dst]->buffer, 1, &region);
VkBufferMemoryBarrier dstBarrier = { VkBufferMemoryBarrier dstBarrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
@@ -303,6 +309,7 @@ void Buffer::copyBuffer(uint64 src, uint64 dst) {
.offset = 0, .offset = 0,
.size = buffers[dst]->size, .size = buffers[dst]->size,
}; };
command->bindResource(PBufferAllocation(buffers[dst]));
vkCmdPipelineBarrier(command->getHandle(), VK_PIPELINE_STAGE_TRANSFER_BIT, vkCmdPipelineBarrier(command->getHandle(), VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &dstBarrier, 0, nullptr); VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &dstBarrier, 0, nullptr);
} }
@@ -383,7 +390,9 @@ void ShaderBuffer::rotateBuffer(uint64 size, bool preserveContents) {
} }
void ShaderBuffer::clear() { void ShaderBuffer::clear() {
vkCmdFillBuffer(graphics->getQueueCommands(getAlloc()->owner)->getCommands()->getHandle(), Vulkan::Buffer::getHandle(), 0, PCommand command = graphics->getQueueCommands(getAlloc()->owner)->getCommands();
command->bindResource(PBufferAllocation(getAlloc()));
vkCmdFillBuffer(command->getHandle(), Vulkan::Buffer::getHandle(), 0,
VK_WHOLE_SIZE, 0); VK_WHOLE_SIZE, 0);
} }
+9 -2
View File
@@ -245,7 +245,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint
auto descriptor = descriptorSet.cast<DescriptorSet>(); auto descriptor = descriptorSet.cast<DescriptorSet>();
assert(descriptor->writeDescriptors.size() == 0); assert(descriptor->writeDescriptors.size() == 0);
descriptor->bind(); descriptor->bind();
boundResources.add(descriptor.getHandle()); boundResources.add(descriptor);
for (auto binding : descriptor->boundResources) { for (auto binding : descriptor->boundResources) {
for (auto res : binding) { for (auto res : binding) {
res->bind(); res->bind();
@@ -269,7 +269,7 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0); assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind(); descriptorSet->bind();
boundResources.add(descriptorSet.getHandle()); boundResources.add(descriptorSet);
for (auto binding : descriptorSet->boundResources) { for (auto binding : descriptorSet->boundResources) {
for (auto res : binding) { for (auto res : binding) {
@@ -550,3 +550,10 @@ void CommandPool::submitCommands(PSemaphore signalSemaphore) {
command->begin(); command->begin();
command->waitForSemaphore(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, waitSemaphore); command->waitForSemaphore(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, waitSemaphore);
} }
void CommandPool::refreshCommands() {
for (uint32 i = 0; i < allocatedBuffers.size(); ++i)
{
allocatedBuffers[i]->checkFence();
}
}
+1
View File
@@ -144,6 +144,7 @@ class CommandPool {
OComputeCommand createComputeCommand(const std::string& name); OComputeCommand createComputeCommand(const std::string& name);
constexpr VkCommandPool getHandle() const { return commandPool; } constexpr VkCommandPool getHandle() const { return commandPool; }
void submitCommands(PSemaphore signalSemaphore = nullptr); void submitCommands(PSemaphore signalSemaphore = nullptr);
void refreshCommands();
private: private:
PGraphics graphics; PGraphics graphics;
+2 -5
View File
@@ -125,7 +125,7 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
if (cachedHandles[setIndex] == nullptr) { if (cachedHandles[setIndex] == nullptr) {
cachedHandles[setIndex] = new DescriptorSet(graphics, this); cachedHandles[setIndex] = new DescriptorSet(graphics, this);
} }
if (cachedHandles[setIndex]->isCurrentlyBound() || cachedHandles[setIndex]->isCurrentlyInUse()) { if (cachedHandles[setIndex]->isCurrentlyBound()) {
// Currently in use, skip // Currently in use, skip
continue; continue;
} }
@@ -133,7 +133,6 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
// If it hasnt been initialized, allocate it // If it hasnt been initialized, allocate it
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle)); VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
} }
cachedHandles[setIndex]->allocate();
PDescriptorSet vulkanSet = cachedHandles[setIndex]; PDescriptorSet vulkanSet = cachedHandles[setIndex];
@@ -153,7 +152,6 @@ void DescriptorPool::reset() {
if (cachedHandles[i] == nullptr) { if (cachedHandles[i] == nullptr) {
return; return;
} }
cachedHandles[i]->free();
} }
if (nextAlloc != nullptr) { if (nextAlloc != nullptr) {
nextAlloc->reset(); nextAlloc->reset();
@@ -161,8 +159,7 @@ void DescriptorPool::reset() {
} }
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), setHandle(VK_NULL_HANDLE), graphics(graphics), owner(owner), : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), setHandle(VK_NULL_HANDLE), graphics(graphics), owner(owner){
bindCount(0), currentlyInUse(false) {
boundResources.resize(owner->getLayout()->getBindings().size()); boundResources.resize(owner->getLayout()->getBindings().size());
for (uint32 i = 0; i < boundResources.size(); ++i) for (uint32 i = 0; i < boundResources.size(); ++i)
{ {
-5
View File
@@ -60,9 +60,6 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override; virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override;
virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override;
constexpr bool isCurrentlyInUse() const { return currentlyInUse; }
constexpr void allocate() { currentlyInUse = true; }
constexpr void free() { currentlyInUse = false; }
constexpr VkDescriptorSet getHandle() const { return setHandle; } constexpr VkDescriptorSet getHandle() const { return setHandle; }
private: private:
@@ -78,8 +75,6 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
VkDescriptorSet setHandle; VkDescriptorSet setHandle;
PGraphics graphics; PGraphics graphics;
PDescriptorPool owner; PDescriptorPool owner;
uint32 bindCount;
bool currentlyInUse;
friend class DescriptorPool; friend class DescriptorPool;
friend class Command; friend class Command;
friend class RenderCommand; friend class RenderCommand;
+5 -5
View File
@@ -100,7 +100,6 @@ VkDeviceAddress vkGetAccelerationStructureDeviceAddressKHR(VkDevice device, cons
Graphics::Graphics() : instance(VK_NULL_HANDLE), handle(VK_NULL_HANDLE), physicalDevice(VK_NULL_HANDLE), callback(VK_NULL_HANDLE) {} Graphics::Graphics() : instance(VK_NULL_HANDLE), handle(VK_NULL_HANDLE), physicalDevice(VK_NULL_HANDLE), callback(VK_NULL_HANDLE) {}
Graphics::~Graphics() { Graphics::~Graphics() {
vkDeviceWaitIdle(handle);
pipelineCache = nullptr; pipelineCache = nullptr;
allocatedFramebuffers.clear(); allocatedFramebuffers.clear();
shaderCompiler = nullptr; shaderCompiler = nullptr;
@@ -166,7 +165,10 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
void Graphics::endRenderPass() { getGraphicsCommands()->getCommands()->endRenderPass(); } void Graphics::endRenderPass() { getGraphicsCommands()->getCommands()->endRenderPass(); }
void Graphics::waitDeviceIdle() { vkDeviceWaitIdle(handle); } void Graphics::waitDeviceIdle() {
vkDeviceWaitIdle(handle);
getGraphicsCommands()->refreshCommands();
}
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) { void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) {
getGraphicsCommands()->getCommands()->executeCommands(std::move(commands)); getGraphicsCommands()->getCommands()->executeCommands(std::move(commands));
@@ -527,11 +529,9 @@ void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>
PCommand cmd = graphicsCommands->getCommands(); PCommand cmd = graphicsCommands->getCommands();
vkCmdBuildAccelerationStructuresKHR(cmd->getHandle(), buildGeometries.size(), buildGeometries.data(), buildRangePointers.data()); vkCmdBuildAccelerationStructuresKHR(cmd->getHandle(), buildGeometries.size(), buildGeometries.data(), buildRangePointers.data());
transformBuffer->bind();
cmd->bindResource(PBufferAllocation(transformBuffer)); cmd->bindResource(PBufferAllocation(transformBuffer));
destructionManager->queueResourceForDestruction(std::move(transformBuffer)); destructionManager->queueResourceForDestruction(std::move(transformBuffer));
for (auto& scratchAlloc : scratchBuffers) { for (auto& scratchAlloc : scratchBuffers) {
scratchAlloc->bind();
cmd->bindResource(PBufferAllocation(scratchAlloc)); cmd->bindResource(PBufferAllocation(scratchAlloc));
destructionManager->queueResourceForDestruction(std::move(scratchAlloc)); destructionManager->queueResourceForDestruction(std::move(scratchAlloc));
} }
@@ -655,7 +655,7 @@ void Graphics::initInstance(GraphicsInitializer initInfo) {
extensions.add("VK_KHR_portability_enumeration"); extensions.add("VK_KHR_portability_enumeration");
#endif #endif
Array<const char*> layers = initInfo.layers; Array<const char*> layers = initInfo.layers;
layers.add("VK_LAYER_KHRONOS_validation"); //layers.add("VK_LAYER_KHRONOS_validation");
VkInstanceCreateInfo info = { VkInstanceCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
+1 -3
View File
@@ -190,14 +190,12 @@ TopLevelAS::TopLevelAS(PGraphics graphics, const Gfx::TopLevelASCreateInfo& crea
}; };
vkCmdPipelineBarrier(cmd->getHandle(), VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, 0, 0, vkCmdPipelineBarrier(cmd->getHandle(), VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, 0, 0,
nullptr, 1, &barrier, 0, nullptr); nullptr, 1, &barrier, 0, nullptr);
scratchBuffer->bind();
cmd->bindResource(PBufferAllocation(scratchBuffer)); cmd->bindResource(PBufferAllocation(scratchBuffer));
graphics->getDestructionManager()->queueResourceForDestruction(std::move(scratchBuffer)); graphics->getDestructionManager()->queueResourceForDestruction(std::move(scratchBuffer));
buffer->bind();
cmd->bindResource(PBufferAllocation(buffer)); cmd->bindResource(PBufferAllocation(buffer));
instanceAllocation->bind();
cmd->bindResource(PBufferAllocation(instanceAllocation)); cmd->bindResource(PBufferAllocation(instanceAllocation));
} }
+6
View File
@@ -63,6 +63,12 @@ void Material::init(Gfx::PGraphics graphics) {
}); });
} }
void Material::destroy() {
floatBuffer = nullptr;
set = nullptr;
layout = nullptr;
}
void Material::updateDescriptor() { void Material::updateDescriptor() {
floatBuffer->rotateBuffer(floatData.size() * sizeof(float)); floatBuffer->rotateBuffer(floatData.size() * sizeof(float));
floatBuffer->updateContents(ShaderBufferCreateInfo{ floatBuffer->updateContents(ShaderBufferCreateInfo{
+1
View File
@@ -14,6 +14,7 @@ class Material {
std::string materialName, Array<OShaderExpression> expressions, Array<std::string> parameter, MaterialNode brdf); std::string materialName, Array<OShaderExpression> expressions, Array<std::string> parameter, MaterialNode brdf);
~Material(); ~Material();
static void init(Gfx::PGraphics graphics); static void init(Gfx::PGraphics graphics);
static void destroy();
static Gfx::PDescriptorLayout getDescriptorLayout() { return layout; } static Gfx::PDescriptorLayout getDescriptorLayout() { return layout; }
static Gfx::PDescriptorSet getDescriptorSet() { return set; } static Gfx::PDescriptorSet getDescriptorSet() { return set; }
static void updateDescriptor(); static void updateDescriptor();
+9 -1
View File
@@ -9,7 +9,7 @@
#include "Component/Transform.h" #include "Component/Transform.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/Mesh.h" #include "Graphics/Mesh.h"
#include "Graphics/StaticMeshVertexData.h"
using namespace Seele; using namespace Seele;
@@ -17,4 +17,12 @@ Scene::Scene(Gfx::PGraphics graphics) : graphics(graphics), lightEnv(new LightEn
Scene::~Scene() {} Scene::~Scene() {}
void Scene::bakeLighting() {
const auto& matData = StaticMeshVertexData::getInstance()->getMaterialData();
for (const auto& mat : matData)
{
}
}
void Scene::update(float deltaTime) { physics.update(deltaTime); } void Scene::update(float deltaTime) { physics.update(deltaTime); }
+2
View File
@@ -15,6 +15,7 @@ class Scene {
public: public:
Scene(Gfx::PGraphics graphics); Scene(Gfx::PGraphics graphics);
~Scene(); ~Scene();
void bakeLighting();
void update(float deltaTime); void update(float deltaTime);
entt::entity createEntity() { return registry.create(); } entt::entity createEntity() { return registry.create(); }
void destroyEntity(entt::entity identifier) { registry.destroy(identifier); } void destroyEntity(entt::entity identifier) { registry.destroy(identifier); }
@@ -39,6 +40,7 @@ class Scene {
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
OLightEnvironment lightEnv; OLightEnvironment lightEnv;
PhysicsSystem physics; PhysicsSystem physics;
Array<Gfx::OTexture2D> lightMaps;
}; };
DEFINE_REF(Scene) DEFINE_REF(Scene)
} // namespace Seele } // namespace Seele
+37 -16
View File
@@ -15,9 +15,9 @@ ThreadPool::ThreadPool(uint32 numWorkers) {
ThreadPool::~ThreadPool() { ThreadPool::~ThreadPool() {
{ {
std::unique_lock l(taskLock); std::unique_lock l(queueLock);
running = false; running = false;
taskCV.notify_all(); queueCV.notify_all();
} }
for (auto& worker : workers) { for (auto& worker : workers) {
worker.join(); worker.join();
@@ -26,35 +26,56 @@ ThreadPool::~ThreadPool() {
void ThreadPool::runAndWait(List<std::function<void()>> functions) { void ThreadPool::runAndWait(List<std::function<void()>> functions) {
std::unique_lock l(taskLock); std::unique_lock l(taskLock);
currentTask.numRemaining = functions.size(); auto newTask = runningTasks.add();
currentTask.functions = std::move(functions); newTask->numRemaining = functions.size();
taskCV.notify_all(); {
std::unique_lock q(queueLock);
while (currentTask.numRemaining > 0) { while (!functions.empty()) {
queue.add(QueueEntry{
.func = std::move(functions.back()),
.task = &*newTask,
});
functions.popBack();
}
queueCV.notify_all();
}
while (newTask->numRemaining > 0) {
completedCV.wait(l); completedCV.wait(l);
} }
runningTasks.remove(newTask);
}
void ThreadPool::runAsync(std::function<void()> func) {
std::unique_lock l(queueLock);
queue.add(QueueEntry{
.func = std::move(func),
.task = nullptr,
});
queueCV.notify_one();
} }
void ThreadPool::work() { void ThreadPool::work() {
while (running) { while (running) {
std::unique_lock l(taskLock); std::unique_lock l(queueLock);
while (currentTask.functions.empty()) { while (queue.empty()) {
taskCV.wait(l); queueCV.wait(l);
if (!running) { if (!running) {
return; return;
} }
} }
auto func = std::move(currentTask.functions.front()); auto entry = std::move(queue.front());
currentTask.functions.popFront(); queue.popFront();
l.unlock(); l.unlock();
func(); entry.func();
l.lock(); l.lock();
currentTask.numRemaining--; if (entry.task != nullptr) {
if (currentTask.numRemaining == 0) { std::unique_lock t(taskLock);
currentTask.functions.clear(); entry.task->numRemaining--;
if (entry.task->numRemaining == 0) {
completedCV.notify_one(); completedCV.notify_one();
} }
} }
}
} }
static ThreadPool threadPool; static ThreadPool threadPool;
+12 -4
View File
@@ -12,16 +12,24 @@ class ThreadPool {
void runAndWait(List<std::function<void()>> functions); void runAndWait(List<std::function<void()>> functions);
void runAsync(std::function<void()> func); void runAsync(std::function<void()> func);
private: private:
struct Task { struct TaskGroup {
uint64 numRemaining = 0; uint64 numRemaining = 0;
List<std::function<void()>> functions;
}; };
struct QueueEntry {
std::function<void()> func;
TaskGroup* task = nullptr;
};
std::mutex queueLock;
std::condition_variable queueCV;
List<QueueEntry> queue;
void work(); void work();
Array<std::thread> workers; Array<std::thread> workers;
std::mutex taskLock; std::mutex taskLock;
std::condition_variable taskCV;
std::condition_variable completedCV; std::condition_variable completedCV;
Task currentTask; List<TaskGroup> runningTasks;
bool running = true; bool running = true;
}; };
ThreadPool& getThreadPool(); ThreadPool& getThreadPool();
+6 -6
View File
@@ -23,12 +23,12 @@ using namespace Seele;
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath) GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath)
: View(graphics, window, createInfo, "Game"), scene(new Scene(graphics)), gameInterface(dllPath) { : View(graphics, window, createInfo, "Game"), scene(new Scene(graphics)), gameInterface(dllPath) {
reloadGame(); reloadGame();
//renderGraph.addPass(new CachedDepthPass(graphics, scene)); renderGraph.addPass(new CachedDepthPass(graphics, scene));
//renderGraph.addPass(new DepthCullingPass(graphics, scene)); renderGraph.addPass(new DepthCullingPass(graphics, scene));
//renderGraph.addPass(new VisibilityPass(graphics, scene)); renderGraph.addPass(new VisibilityPass(graphics, scene));
//renderGraph.addPass(new LightCullingPass(graphics, scene)); renderGraph.addPass(new LightCullingPass(graphics, scene));
//renderGraph.addPass(new BasePass(graphics, scene)); renderGraph.addPass(new BasePass(graphics, scene));
renderGraph.addPass(new RayTracingPass(graphics, scene)); //renderGraph.addPass(new RayTracingPass(graphics, scene));
renderGraph.setViewport(viewport); renderGraph.setViewport(viewport);
renderGraph.createRenderPass(); renderGraph.createRenderPass();
} }
+1 -1
View File
@@ -11,7 +11,7 @@ class WindowManager {
OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo); OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo);
void render(); void render();
void notifyWindowClosed(PWindow window); void notifyWindowClosed(PWindow window);
bool isActive() const { return windows.size(); } bool isActive() const { return getGlobals().running && windows.size(); }
private: private:
Array<PWindow> windows; Array<PWindow> windows;