0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/src/Ryujinx.Graphics.Vulkan/SemaphoreHolder.cs
2023-04-27 23:51:14 +02:00

60 lines
1.4 KiB
C#

using Silk.NET.Vulkan;
using System;
using System.Threading;
using VkSemaphore = Silk.NET.Vulkan.Semaphore;
namespace Ryujinx.Graphics.Vulkan
{
class SemaphoreHolder : IDisposable
{
private readonly Vk _api;
private readonly Device _device;
private VkSemaphore _semaphore;
private int _referenceCount;
public bool _disposed;
public unsafe SemaphoreHolder(Vk api, Device device)
{
_api = api;
_device = device;
var semaphoreCreateInfo = new SemaphoreCreateInfo()
{
SType = StructureType.SemaphoreCreateInfo
};
api.CreateSemaphore(device, in semaphoreCreateInfo, null, out _semaphore).ThrowOnError();
_referenceCount = 1;
}
public VkSemaphore GetUnsafe()
{
return _semaphore;
}
public VkSemaphore Get()
{
Interlocked.Increment(ref _referenceCount);
return _semaphore;
}
public unsafe void Put()
{
if (Interlocked.Decrement(ref _referenceCount) == 0)
{
_api.DestroySemaphore(_device, _semaphore, null);
_semaphore = default;
}
}
public void Dispose()
{
if (!_disposed)
{
Put();
_disposed = true;
}
}
}
}