VulkanDevice.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using Silk.NET.Vulkan;
  3. namespace Ryujinx.Ava.Ui.Vulkan
  4. {
  5. internal class VulkanDevice : IDisposable
  6. {
  7. private static object _lock = new object();
  8. public VulkanDevice(Device apiHandle, VulkanPhysicalDevice physicalDevice, Vk api)
  9. {
  10. InternalHandle = apiHandle;
  11. Api = api;
  12. api.GetDeviceQueue(apiHandle, physicalDevice.QueueFamilyIndex, 0, out var queue);
  13. var vulkanQueue = new VulkanQueue(this, queue);
  14. Queue = vulkanQueue;
  15. PresentQueue = vulkanQueue;
  16. CommandBufferPool = new VulkanCommandBufferPool(this, physicalDevice);
  17. }
  18. public IntPtr Handle => InternalHandle.Handle;
  19. internal Device InternalHandle { get; }
  20. public Vk Api { get; }
  21. public VulkanQueue Queue { get; private set; }
  22. public VulkanQueue PresentQueue { get; }
  23. public VulkanCommandBufferPool CommandBufferPool { get; }
  24. public void Dispose()
  25. {
  26. WaitIdle();
  27. CommandBufferPool?.Dispose();
  28. Queue = null;
  29. }
  30. internal void Submit(SubmitInfo submitInfo, Fence fence = default)
  31. {
  32. lock (_lock)
  33. {
  34. Api.QueueSubmit(Queue.InternalHandle, 1, submitInfo, fence).ThrowOnError();
  35. }
  36. }
  37. public void WaitIdle()
  38. {
  39. lock (_lock)
  40. {
  41. Api.DeviceWaitIdle(InternalHandle);
  42. }
  43. }
  44. public void QueueWaitIdle()
  45. {
  46. lock (_lock)
  47. {
  48. Api.QueueWaitIdle(Queue.InternalHandle);
  49. }
  50. }
  51. public object Lock => _lock;
  52. }
  53. }