mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-24 14:34:16 +00:00
2989c163a8
* editorconfig: Add default charset * Change file encoding from UTF-8-BOM to UTF-8
60 lines
1.4 KiB
C#
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;
|
|
private 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;
|
|
}
|
|
}
|
|
}
|
|
}
|