phr00t / FocusEngine

Focus Game Engine. This is Stride/Xenko fast-tracked for Phr00t's Software games. Improvements over the original Focus on Vulkan support, PC platforms, VR, performance & ease. Cherry-picks commits from other forks as needed.
MIT License
97 stars 11 forks source link

Resizing window in Vulkan causes crash #53

Closed phr00t closed 5 years ago

phr00t commented 5 years ago

SharpVulkan exception "Error Device Lost" happens on submission after resizing the game window. Likely due to an event where buffers are trying to be resized.

SharpVulkan.dll!SharpVulkan.Queue.Submit(uint submitCount, SharpVulkan.SubmitInfo* submits, SharpVulkan.Fence fence) Line 1608 C# Xenko.Graphics.dll!Xenko.Graphics.GraphicsDevice.ExecuteCommandLists(int count, Xenko.Graphics.CompiledCommandList[] commandLists) Line 242 C# Xenko.Rendering.dll!Xenko.Rendering.RenderSystem.Draw(Xenko.Rendering.RenderDrawContext renderDrawContext, Xenko.Rendering.RenderView renderView, Xenko.Rendering.RenderStage renderStage) Line 402 C# Xenko.Rendering.dll!Xenko.Rendering.Shadows.ShadowMapRenderer.Draw(Xenko.Rendering.RenderDrawContext drawContext) Line 175 C# Xenko.Engine.dll!Xenko.Rendering.Compositing.ForwardRenderer.DrawCore(Xenko.Rendering.RenderContext context, Xenko.Rendering.RenderDrawContext drawContext) Line 620 C# Xenko.Rendering.dll!Xenko.Rendering.Compositing.SceneRendererBase.Draw(Xenko.Rendering.RenderDrawContext context) Line 39 C# Xenko.Rendering.dll!Xenko.Rendering.Compositing.SceneRendererCollection.DrawCore(Xenko.Rendering.RenderContext context, Xenko.Rendering.RenderDrawContext drawContext) Line 28 C# Xenko.Rendering.dll!Xenko.Rendering.Compositing.SceneRendererBase.Draw(Xenko.Rendering.RenderDrawContext context) Line 39 C#

phr00t commented 5 years ago

This is likely the validation line where the problem is occurring:

Error: [ VUID-VkFramebufferCreateInfo-pAttachments-00882 ] Object: VK_NULL_HANDLE (Type = 0) | vkCreateFramebuffer(): VkFramebufferCreateInfo attachment #1 mip level 0 has dimensions smaller than the corresponding framebuffer dimensions. Here are the respective dimensions for attachment #1, framebuffer: width: 1280, 1398 height: 720, 825 layerCount: 1, 1 The Vulkan spec states: Each element of pAttachments must have dimensions at least as large as the corresponding framebuffer dimension (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkFramebufferCreateInfo-pAttachments-00882) ([0] Validation)

phr00t commented 5 years ago

In CommandList.cs, I don't think the new resized backbuffers are getting passed in ClearState().. I think the old backbuffers are being passed, which causes Vulkan to get lost. When newly resized buffers are created in ResizeBackBuffers() in Vulkan Swapchain, it needs to report back to CommandList or GraphicsDevice.Presenter the new backbuffer(s)... (theory)

phr00t commented 5 years ago

Vulkan Swapchain needs a " public override Texture BackBuffer => backBuffer;" kinda thing?

phr00t commented 5 years ago

BackBuffer is already implemented. Backbuffers are getting passed to ClearState(). Still unsure of the root cause of this problem. Device is still "getting lost" shortly after buffers are resized.

phr00t commented 5 years ago

Fixed with https://github.com/phr00t/xenko/commit/a8e750a9c89247ef9c0dd9dd43b2e7eb9caa602b