Skip to content

Commit

Permalink
Implemented VulkanDevice.Dispose. (#15936)
Browse files Browse the repository at this point in the history
  • Loading branch information
jp2masa authored Jun 7, 2024
1 parent f140033 commit 5d2ba6d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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

0 comments on commit 5d2ba6d

Please sign in to comment.