vulkan fixed destructor and some crashes

This commit is contained in:
KojoZero 2026-06-03 08:48:31 -07:00
parent 1914583b35
commit 8d10a81ba4

View file

@ -159,6 +159,8 @@ RendererVulkan::RendererVulkan(Core::System& system, Pica::PicaCore& pica_,
BuildLayouts(); BuildLayouts();
CreateTextureRenderPass(); CreateTextureRenderPass();
AllocateSMAATextures(); AllocateSMAATextures();
AllocatePPTextures();
CreatePPTextureFramebuffers();
BuildPipelines(); BuildPipelines();
if (secondary_window) { if (secondary_window) {
secondary_present_window_ptr = std::make_unique<PresentWindow>( secondary_present_window_ptr = std::make_unique<PresentWindow>(
@ -172,6 +174,13 @@ RendererVulkan::~RendererVulkan() {
main_present_window.WaitPresent(); main_present_window.WaitPresent();
device.waitIdle(); device.waitIdle();
vmaDestroyBuffer(instance.GetAllocator(), areaTexInfo.buffer, areaTexInfo.bufferAllocation);
vmaDestroyBuffer(instance.GetAllocator(), searchTexInfo.buffer, searchTexInfo.bufferAllocation);
device.destroyImageView(areaTexInfo.image_view);
vmaDestroyImage(instance.GetAllocator(), areaTexInfo.image, areaTexInfo.imageAllocation);
device.destroyImageView(searchTexInfo.image_view);
vmaDestroyImage(instance.GetAllocator(), searchTexInfo.image, searchTexInfo.imageAllocation);
device.destroyShaderModule(present_vertex_shader); device.destroyShaderModule(present_vertex_shader);
for (u32 i = 0; i < PRESENT_PIPELINES; i++) { for (u32 i = 0; i < PRESENT_PIPELINES; i++) {
device.destroyPipeline(present_pipelines[i]); device.destroyPipeline(present_pipelines[i]);
@ -216,6 +225,16 @@ RendererVulkan::~RendererVulkan() {
device.destroyImageView(antialiasTextures[j].image_view); device.destroyImageView(antialiasTextures[j].image_view);
vmaDestroyImage(instance.GetAllocator(), antialiasTextures[j].image, antialiasTextures[j].allocation); vmaDestroyImage(instance.GetAllocator(), antialiasTextures[j].image, antialiasTextures[j].allocation);
} }
for (int i = 0; i < intermediateOutputSizeTextures.size(); i++) {
for (int j = 0; j < intermediateOutputSizeTextures[0].size(); j++){
for (int k = 0; k < intermediateOutputSizeTextures[0][0].size(); k++){
device.destroyFramebuffer(intermediateOutputSizeTextureFBOs[i][j][k]);
device.destroyImageView(intermediateOutputSizeTextures[i][j][k].image_view);
vmaDestroyImage(instance.GetAllocator(), intermediateOutputSizeTextures[i][j][k].image, intermediateOutputSizeTextures[i][j][k].allocation);
}
}
}
device.destroyRenderPass(textureRenderpass); device.destroyRenderPass(textureRenderpass);
device.destroyPipeline(cursor_pipeline); device.destroyPipeline(cursor_pipeline);
device.destroyShaderModule(cursor_vertex_shader); device.destroyShaderModule(cursor_vertex_shader);
@ -612,6 +631,10 @@ void RendererVulkan::CreateTextureFramebuffer(TextureInfo& texture, vk::Framebuf
if (texture.width == 0 || texture.height == 0){ if (texture.width == 0 || texture.height == 0){
return; return;
} }
vk::Device device = instance.GetDevice();
if (framebuffer){
device.destroyFramebuffer(framebuffer);
}
const vk::FramebufferCreateInfo framebuffer_info = { const vk::FramebufferCreateInfo framebuffer_info = {
.renderPass = textureRenderpass, .renderPass = textureRenderpass,
.attachmentCount = 1, .attachmentCount = 1,
@ -1607,9 +1630,6 @@ void RendererVulkan::DrawSingleScreen(u32 screen_id, float screenLeft, float scr
std::vector<u32> screen_ids; std::vector<u32> screen_ids;
std::vector<TextureInfo> texturesToSample; std::vector<TextureInfo> texturesToSample;
currentPass = 0; currentPass = 0;
if (antialiasingMode == 1){ if (antialiasingMode == 1){
screen_ids.assign({screen_id}); screen_ids.assign({screen_id});