fix shutdown

This commit is contained in:
2026-06-20 01:20:14 +02:00
parent 1479ad468d
commit b1dad89214
8 changed files with 209 additions and 158 deletions

View File

@@ -33,7 +33,7 @@ public:
void endDrawing();
void draw(VkCommandBuffer cmd, GfxDevice& gfxDevice, const Camera& camera, const SceneData& sceneData);
void cleanup(VkDevice device);
void cleanup(GfxDevice& gfxDevice);
void drawMesh(MeshID id, const glm::mat4& transform, MaterialID materialId);
void drawSkinnedMesh(MeshID id,

View File

@@ -126,5 +126,6 @@ void App::run() {
}
void App::cleanup() {
spdlog::info("Cleaning up");
customCleanup();
}

View File

@@ -104,18 +104,7 @@ void GfxDevice::init(SDL_Window* window, const std::string& appName, bool vSync)
VkPhysicalDeviceProperties props{};
vkGetPhysicalDeviceProperties(physicalDevice, &props);
imageCache.bindlessSetManager.init(device, props.limits.maxSamplerAnisotropy); {
// create white texture
std::uint32_t pixel = 0xFFFFFFFF;
whiteImageId = createImage(
{
.format = VK_FORMAT_R8G8B8A8_UNORM,
.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
.extent = VkExtent3D{1, 1, 1},
},
"white texture",
&pixel);
}
imageCache.bindlessSetManager.init(device, props.limits.maxSamplerAnisotropy);
swapchain.initSync(device);

View File

@@ -38,12 +38,20 @@ ImageID ImageCache::addImage(GPUImage image) {
ImageID ImageCache::addImage(ImageID id, GPUImage image) {
image.setBindlessId(static_cast<std::uint32_t>(id));
if (id != images.size()) {
images[id] = std::move(image); // replacing existing image
if (id < images.size()) {
gfxDevice.destroyImage(images[id]);
images[id] = std::move(image);
} else {
assert(id == images.size());
images.push_back(std::move(image));
}
bindlessSetManager.addImage(gfxDevice.getDevice(), id, image.imageView);
bindlessSetManager.addImage(
gfxDevice.getDevice(),
id,
images[id].imageView
);
return id;
}

View File

@@ -112,8 +112,30 @@ void GameRenderer::draw(VkCommandBuffer cmd, GfxDevice& gfxDevice, const Camera&
}
void GameRenderer::cleanup(VkDevice device) {
meshPipeline->cleanup(device);
void GameRenderer::cleanup(GfxDevice& gfxDevice) {
VkDevice device = gfxDevice.getDevice().device;
vkDeviceWaitIdle(device);
if (skinningPipeline)
skinningPipeline->cleanup(gfxDevice);
if (skyboxPipeline)
skyboxPipeline->cleanup(device);
if (meshPipeline)
meshPipeline->cleanup(device);
sceneDataBuffer.cleanup(gfxDevice);
// if (drawImageId != NULL_IMAGE_ID)
// gfxDevice.destroyImage();
// if (depthImageId != NULL_IMAGE_ID)
// gfxDevice.destroyImage(depthImageId);
drawImageId = NULL_IMAGE_ID;
depthImageId = NULL_IMAGE_ID;
}
void GameRenderer::drawMesh(MeshID id, const glm::mat4& transform, MaterialID materialId) {