Graceful exit
This commit is contained in:
+5
-2
@@ -17,6 +17,9 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::Editor;
|
||||
|
||||
// make it global so it gets deleted last and automatically
|
||||
static Gfx::OGraphics graphics;
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef WIN32
|
||||
@@ -31,7 +34,7 @@ int main()
|
||||
std::string gameName = "TrackClear";
|
||||
std::filesystem::path cmakePath = outputPath / "cmake";
|
||||
|
||||
Gfx::OGraphics graphics = new Vulkan::Graphics();
|
||||
graphics = new Vulkan::Graphics();
|
||||
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
@@ -246,7 +249,7 @@ int main()
|
||||
{
|
||||
windowManager->render();
|
||||
}
|
||||
vd->~StaticMeshVertexData();
|
||||
vd->destroy();
|
||||
//export game
|
||||
if (false)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ using namespace Seele;
|
||||
|
||||
extern List<VertexData*> vertexDataList;
|
||||
|
||||
|
||||
StaticMeshVertexData::StaticMeshVertexData()
|
||||
{
|
||||
vertexDataList.add(this);
|
||||
@@ -128,6 +127,18 @@ void StaticMeshVertexData::init(Gfx::PGraphics graphics)
|
||||
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::destroy()
|
||||
{
|
||||
VertexData::destroy();
|
||||
positions = nullptr;
|
||||
texCoords = nullptr;
|
||||
normals = nullptr;
|
||||
tangents = nullptr;
|
||||
biTangents = nullptr;
|
||||
colors = nullptr;
|
||||
descriptorLayout = nullptr;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::bindBuffers(Gfx::PRenderCommand)
|
||||
{
|
||||
// TODO: for legacy vertex buffer binding
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override;
|
||||
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
||||
virtual void init(Gfx::PGraphics graphics) override;
|
||||
virtual void destroy() override;
|
||||
virtual void bindBuffers(Gfx::PRenderCommand command) override;
|
||||
virtual Gfx::PDescriptorLayout getVertexDataLayout() override;
|
||||
virtual Gfx::PDescriptorSet getVertexDataSet() override;
|
||||
|
||||
@@ -97,11 +97,11 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
||||
{
|
||||
uint32 numMeshlets = std::min<uint32>(512, loadedMeshlets.size() - currentMesh);
|
||||
uint32 meshletOffset = meshlets.size();
|
||||
AABB meshAABB;
|
||||
//AABB meshAABB;
|
||||
for (uint32 i = 0; i < numMeshlets; ++i)
|
||||
{
|
||||
Meshlet& m = loadedMeshlets[currentMesh + i];
|
||||
meshAABB = meshAABB.combine(m.boundingBox);
|
||||
//meshAABB = meshAABB.combine(m.boundingBox);
|
||||
uint32 vertexOffset = vertexIndices.size();
|
||||
vertexIndices.resize(vertexOffset + m.numVertices);
|
||||
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
|
||||
@@ -109,7 +109,6 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
||||
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
||||
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
||||
meshlets.add(MeshletDescription{
|
||||
.boundingBox = m.boundingBox,
|
||||
.vertexCount = m.numVertices,
|
||||
.primitiveCount = m.numPrimitives,
|
||||
.vertexOffset = vertexOffset,
|
||||
@@ -117,10 +116,9 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
||||
});
|
||||
}
|
||||
meshData[id].add(MeshData{
|
||||
.boundingBox = meshAABB,
|
||||
.numMeshlets = numMeshlets,
|
||||
.meshletOffset = meshletOffset,
|
||||
.indicesOffset = static_cast<uint32>(meshOffsets[id]),
|
||||
.numMeshlets = (uint16)numMeshlets,
|
||||
.indicesOffset = (uint16)meshOffsets[id],
|
||||
});
|
||||
currentMesh += numMeshlets;
|
||||
}
|
||||
@@ -225,6 +223,17 @@ void Seele::VertexData::init(Gfx::PGraphics _graphics)
|
||||
graphics->getShaderCompiler()->registerVertexData(this);
|
||||
}
|
||||
|
||||
void VertexData::destroy()
|
||||
{
|
||||
instanceDataLayout = nullptr;
|
||||
meshletBuffer = nullptr;
|
||||
vertexIndicesBuffer = nullptr;
|
||||
primitiveIndicesBuffer = nullptr;
|
||||
indexBuffer = nullptr;
|
||||
meshData.clear();
|
||||
materialData.clear();
|
||||
}
|
||||
|
||||
VertexData::VertexData()
|
||||
: idCounter(0)
|
||||
, head(0)
|
||||
|
||||
@@ -41,13 +41,13 @@ public:
|
||||
};
|
||||
struct MeshData
|
||||
{
|
||||
AABB boundingBox;
|
||||
uint32 numMeshlets = 0;
|
||||
uint32 meshletOffset = 0;
|
||||
uint16 numMeshlets = 0;
|
||||
uint16 indicesOffset = 0;
|
||||
uint32 firstIndex = 0;
|
||||
uint32 numIndices = 0;
|
||||
uint32 indicesOffset = 0;
|
||||
};
|
||||
static_assert(sizeof(MeshData) == 16);
|
||||
struct MeshInstanceData
|
||||
{
|
||||
InstanceData instance;
|
||||
@@ -86,13 +86,13 @@ public:
|
||||
static List<VertexData*> getList();
|
||||
static VertexData* findByTypeName(std::string name);
|
||||
virtual void init(Gfx::PGraphics graphics);
|
||||
virtual void destroy();
|
||||
protected:
|
||||
virtual void resizeBuffers() = 0;
|
||||
virtual void updateBuffers() = 0;
|
||||
VertexData();
|
||||
struct MeshletDescription
|
||||
{
|
||||
AABB boundingBox;
|
||||
uint32_t vertexCount;
|
||||
uint32_t primitiveCount;
|
||||
uint32_t vertexOffset;
|
||||
|
||||
@@ -267,7 +267,6 @@ void Buffer::unmap()
|
||||
.size = pending.size,
|
||||
};
|
||||
vkCmdCopyBuffer(cmdHandle, stagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, ®ion);
|
||||
graphics->getQueueCommands(owner)->submitCommands();
|
||||
}
|
||||
//requestOwnershipTransfer(pending.prevQueue);
|
||||
pendingBuffers.erase(this);
|
||||
@@ -328,7 +327,6 @@ void UniformBuffer::unmap()
|
||||
std::memset(®ion, 0, sizeof(VkBufferCopy));
|
||||
region.size = Vulkan::Buffer::size;
|
||||
vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, ®ion);
|
||||
graphics->getQueueCommands(currentOwner)->submitCommands();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -416,7 +414,6 @@ void ShaderBuffer::unmap()
|
||||
.size = Vulkan::Buffer::size,
|
||||
};
|
||||
vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, ®ion);
|
||||
graphics->getQueueCommands(currentOwner)->submitCommands();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -407,7 +407,9 @@ void Graphics::pickPhysicalDevice()
|
||||
VkPhysicalDevice bestDevice = VK_NULL_HANDLE;
|
||||
uint32 deviceRating = 0;
|
||||
features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
||||
features.pNext = &features12;
|
||||
features.pNext = &features11;
|
||||
features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
|
||||
features11.pNext = &features12;
|
||||
features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
|
||||
features12.pNext = nullptr;
|
||||
for (auto dev : physicalDevices)
|
||||
@@ -446,7 +448,7 @@ void Graphics::pickPhysicalDevice()
|
||||
{
|
||||
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
||||
{
|
||||
meshShadingEnabled = true;
|
||||
//meshShadingEnabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -565,7 +567,7 @@ void Graphics::createDevice(GraphicsInitializer initializer)
|
||||
}
|
||||
VkDeviceCreateInfo deviceInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||
.pNext = &features12,
|
||||
.pNext = &features11,
|
||||
.queueCreateInfoCount = (uint32)queueInfos.size(),
|
||||
.pQueueCreateInfos = queueInfos.data(),
|
||||
.enabledExtensionCount = (uint32)initializer.deviceExtensions.size(),
|
||||
|
||||
@@ -93,6 +93,7 @@ protected:
|
||||
thread_local static OCommandPool dedicatedTransferCommands;
|
||||
VkPhysicalDeviceProperties props;
|
||||
VkPhysicalDeviceFeatures2 features;
|
||||
VkPhysicalDeviceVulkan11Features features11;
|
||||
VkPhysicalDeviceVulkan12Features features12;
|
||||
VkDebugReportCallbackEXT callback;
|
||||
Map<uint32, OFramebuffer> allocatedFramebuffers;
|
||||
|
||||
Reference in New Issue
Block a user