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

Implemented VulkanDevice.Dispose #15936

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Avalonia.Vulkan/Interop/VulkanDevice.Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static IVulkanDevice Create(IVulkanInstance instance,

api.GetDeviceQueue(createdDevice, dev.QueueFamilyIndex, 0, out var createdQueue);

return new VulkanDevice(api.Instance, createdDevice, dev.PhysicalDevice, createdQueue,
return new VulkanDevice(api, createdDevice, dev.PhysicalDevice, createdQueue,
dev.QueueFamilyIndex, enabledExtensions);

}
Expand Down
14 changes: 10 additions & 4 deletions src/Avalonia.Vulkan/Interop/VulkanDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ namespace Avalonia.Vulkan.Interop;

internal partial class VulkanDevice : IVulkanDevice
{
private readonly VkDevice _handle;
private readonly VulkanInstanceApi _instanceApi;
private VkDevice _handle;
private readonly VkPhysicalDevice _physicalDeviceHandle;
private readonly VkQueue _mainQueue;
private readonly uint _graphicsQueueIndex;
private readonly object _lock = new();
private Thread? _lockedByThread;
private int _lockCount;

private VulkanDevice(IVulkanInstance instance, VkDevice handle, VkPhysicalDevice physicalDeviceHandle,
private VulkanDevice(VulkanInstanceApi instanceApi, VkDevice handle, VkPhysicalDevice physicalDeviceHandle,
VkQueue mainQueue, uint graphicsQueueIndex, string[] enabledExtensions)
{
_instanceApi = instanceApi;
_handle = handle;
_physicalDeviceHandle = physicalDeviceHandle;
_mainQueue = mainQueue;
_graphicsQueueIndex = graphicsQueueIndex;
Instance = instance;
Instance = _instanceApi.Instance;
EnabledExtensions = enabledExtensions;
}

Expand Down Expand Up @@ -59,7 +61,11 @@ public IDisposable Lock()
public IVulkanInstance Instance { get; }
public void Dispose()
{
// TODO
if (_handle.Handle != IntPtr.Zero)
{
_instanceApi.DestroyDevice(_handle, IntPtr.Zero);
_handle = default;
}
}

public object? TryGetFeature(Type featureType) => null;
Expand Down
3 changes: 3 additions & 0 deletions src/Avalonia.Vulkan/UnmanagedInterop/VulkanInstanceApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public partial void GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice phys
public partial VkResult CreateDevice(VkPhysicalDevice physicalDevice, ref VkDeviceCreateInfo pCreateInfo,
IntPtr pAllocator, out VkDevice pDevice);

[GetProcAddress("vkDestroyDevice")]
public partial VkResult DestroyDevice(VkDevice device, IntPtr pAllocator);

[GetProcAddress("vkGetDeviceQueue")]
public partial void GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
out VkQueue pQueue);
Expand Down
Loading