Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates of Avalonia.Vulkan and SilkNetDemo projects #9885

Closed
wants to merge 12 commits into from

Conversation

abenedik
Copy link

@abenedik abenedik commented Jan 5, 2023

The PR improves using VulkanControlBase. See comments in the commits for more information.

…n VulkanPlatformGraphics.TryCreate (VulkanDevice is created later from VulkanPlatformGraphics.CreateContext)
…vent rendering too small texture and then scaling it up
…Vulkan resources when the control is hidden (for example in TabControl)
…property dispose the control when the window is unloaded
…sed to wait in BeginRecording until the previous operation has finished. Also there should not be an option to use another Fence in Submit because this could leave _fence in unsignalled state and could wait forever (for example in WaitForFences that is called Dispose method)
@@ -15,13 +15,18 @@

namespace Avalonia.Vulkan;

public abstract class VulkanControlBase : Control
public abstract class VulkanControlBase : Control, IDisposable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure that making a control to be disposable is a good idea. Any cleanup logic should happen in OnDetachedFromVisualTree

Copy link
Author

@abenedik abenedik Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnDetachedFromVisualTree is also called when VulkanControlBase is inside a TabControl and when user changes Tabs. Also, if user decides to move the control from one parent to another, this should not dispose all Vulkan resources. Ok, the VulkanBitmapChain that is used by the VulkanControlBase could be disposed in OnDetachedFromVisualTree. But calling OnVulkanDeInit is too "heavy" - if user would be showing a complex 3D scene we should not dispose all Vulkan resources because the control was hidden or moved. The user of VulkanControlBase should be aware that this control creates a lot of unmanaged resources and that it is his responsibility to clear that (for example, when the MainWindow is closed - as in the updated SilkNetDemo). When using only a single VulkanControlBase, then there is actually no need to clean anything because the OS will clean all resources; but when using multiple VulkanControlBase objects, user will need to manually dispose the resources when he knows they will no longer be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VulkanControlBase is responsible for managing a swapchain and associated resources. When it's detached the swapchain becomes invalid and any associated resources like framebuffers should be disposed as well.

I'm currently working on something like SwapChainPanel and generic non-primary context creation APIs that would allow to manually manage resources that are shared between different vulkan-powered controls.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will remove the IDisposable from VulkanControlBase and will update the code so that in OnDetachedFromVisualTree the resources created by the VulkanControlBase will be disposed: VulkanBitmapChain and VulkanCommandBufferPool. But I would not call OnVulkanDeInit because OnDetachedFromVisualTree does not mean that all Vulkan resources should be disposed (actually I think OnVulkanDeInit should be removed because the VulkanControlBase cannot know when the Vulkan resources should be disposed). I would preserve the manual disposal of the Vulkan resource that are created in the VulkanDemoControl (they are disposed when the MainWindow is Unloaded). Is this ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still needs to inform the user code that swapchain images are no longer valid and that corresponding framebuffers should be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ok, I will update the PR with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#9925 - see external memory interop spec.

…ges and frame buffers when control is detached. Renamed OnVulkanDeInit to OnSwapchainDisposing. Adding TabControl to VulkanDemo.axaml to test removing and adding the control to visual tree.
…ed between calling StartPresentation and EndPresentation
@jmacato
Copy link
Member

jmacato commented Nov 17, 2023

Closing this PR temporarily due to inactivity. Please ping me if this needs to be reopened.

@jmacato jmacato closed this Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants