diff --git a/src/lightmapper/gpuraytracer.cpp b/src/lightmapper/gpuraytracer.cpp index 57d4c35..4639847 100644 --- a/src/lightmapper/gpuraytracer.cpp +++ b/src/lightmapper/gpuraytracer.cpp @@ -49,8 +49,28 @@ void GPURaytracer::Raytrace(DoomLevelMesh* mesh) raytrace->BeginFrame(); lightmap->BeginFrame(); - printf("."); - //lightmap->Raytrace(surfaces); + // Keep baking until all surfaces have been processed + while (true) + { + printf("."); + + TArray surfaces; + for (int i = 0, count = submesh->GetSurfaceCount(); i < count; i++) + { + LevelMeshSurface* surface = submesh->GetSurface(i); + if (surface->needsUpdate) + { + surfaces.Push(surface); + } + } + + if (surfaces.Size() == 0) + break; + + lightmap->Raytrace(surfaces); + + mDevice->GetCommands()->SubmitAndWait(); + } printf("."); diff --git a/src/lightmapper/vk_renderdevice.cpp b/src/lightmapper/vk_renderdevice.cpp index 75cf3ee..5c0714d 100644 --- a/src/lightmapper/vk_renderdevice.cpp +++ b/src/lightmapper/vk_renderdevice.cpp @@ -66,6 +66,8 @@ void VkCommandBufferManager::SubmitAndWait() .AddCommandBuffer(mTransferCommands.get()) .Execute(fb->GetDevice(), fb->GetDevice()->GraphicsQueue); + TransferDeleteList->Add(std::move(mTransferCommands)); + vkDeviceWaitIdle(fb->GetDevice()->device); } @@ -113,7 +115,7 @@ void VkTextureManager::CreateLightmap(int newLMTextureSize, int newLMTextureCoun PipelineBarrier() .AddImage(Lightmap.Image.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, LMTextureCount) - .Execute(fb->GetCommands()->GetTransferCommands(), 0, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); + .Execute(fb->GetCommands()->GetTransferCommands(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); } void VkTextureManager::DownloadLightmap(int arrayIndex, uint16_t* buffer)