2024-06-03 03:40:28 +02:00
|
|
|
using Silk.NET.Vulkan;
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Vulkan
|
|
|
|
{
|
|
|
|
class ResourceArray : IDisposable
|
|
|
|
{
|
|
|
|
private DescriptorSet[] _cachedDescriptorSets;
|
|
|
|
|
|
|
|
private ShaderCollection _cachedDscProgram;
|
|
|
|
private int _cachedDscSetIndex;
|
|
|
|
private int _cachedDscIndex;
|
|
|
|
|
|
|
|
private int _bindCount;
|
|
|
|
|
2024-08-21 01:49:17 +02:00
|
|
|
protected void SetDirty(VulkanRenderer gd, bool isImage)
|
2024-06-03 03:40:28 +02:00
|
|
|
{
|
|
|
|
ReleaseDescriptorSet();
|
|
|
|
|
|
|
|
if (_bindCount != 0)
|
|
|
|
{
|
2024-08-21 01:49:17 +02:00
|
|
|
if (isImage)
|
|
|
|
{
|
|
|
|
gd.PipelineInternal.ForceImageDirty();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gd.PipelineInternal.ForceTextureDirty();
|
|
|
|
}
|
2024-06-03 03:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool TryGetCachedDescriptorSets(CommandBufferScoped cbs, ShaderCollection program, int setIndex, out DescriptorSet[] sets)
|
|
|
|
{
|
|
|
|
if (_cachedDescriptorSets != null)
|
|
|
|
{
|
|
|
|
_cachedDscProgram.UpdateManualDescriptorSetCollectionOwnership(cbs, _cachedDscSetIndex, _cachedDscIndex);
|
|
|
|
|
|
|
|
sets = _cachedDescriptorSets;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dsc = program.GetNewManualDescriptorSetCollection(cbs, setIndex, out _cachedDscIndex).Get(cbs);
|
|
|
|
|
|
|
|
sets = dsc.GetSets();
|
|
|
|
|
|
|
|
_cachedDescriptorSets = sets;
|
|
|
|
_cachedDscProgram = program;
|
|
|
|
_cachedDscSetIndex = setIndex;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void IncrementBindCount()
|
|
|
|
{
|
|
|
|
_bindCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DecrementBindCount()
|
|
|
|
{
|
|
|
|
int newBindCount = --_bindCount;
|
|
|
|
Debug.Assert(newBindCount >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ReleaseDescriptorSet()
|
|
|
|
{
|
|
|
|
if (_cachedDescriptorSets != null)
|
|
|
|
{
|
|
|
|
_cachedDscProgram.ReleaseManualDescriptorSetCollection(_cachedDscSetIndex, _cachedDscIndex);
|
|
|
|
_cachedDescriptorSets = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
ReleaseDescriptorSet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|