aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Vulkan/TextureArray.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Graphics.Vulkan/TextureArray.cs')
-rw-r--r--src/Ryujinx.Graphics.Vulkan/TextureArray.cs76
1 files changed, 74 insertions, 2 deletions
diff --git a/src/Ryujinx.Graphics.Vulkan/TextureArray.cs b/src/Ryujinx.Graphics.Vulkan/TextureArray.cs
index 6ef9087b..fe834225 100644
--- a/src/Ryujinx.Graphics.Vulkan/TextureArray.cs
+++ b/src/Ryujinx.Graphics.Vulkan/TextureArray.cs
@@ -2,6 +2,7 @@ using Ryujinx.Graphics.GAL;
using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
namespace Ryujinx.Graphics.Vulkan
{
@@ -24,12 +25,18 @@ namespace Ryujinx.Graphics.Vulkan
private HashSet<TextureStorage> _storages;
+ private DescriptorSet[] _cachedDescriptorSets;
+
private int _cachedCommandBufferIndex;
private int _cachedSubmissionCount;
+ private ShaderCollection _cachedDscProgram;
+ private int _cachedDscSetIndex;
+ private int _cachedDscIndex;
+
private readonly bool _isBuffer;
- public bool Bound;
+ private int _bindCount;
public TextureArray(VulkanRenderer gd, int size, bool isBuffer)
{
@@ -106,8 +113,12 @@ namespace Ryujinx.Graphics.Vulkan
{
_cachedCommandBufferIndex = -1;
_storages = null;
+ _cachedDescriptorSets = null;
- _gd.PipelineInternal.ForceTextureDirty();
+ if (_bindCount != 0)
+ {
+ _gd.PipelineInternal.ForceTextureDirty();
+ }
}
public void QueueWriteToReadBarriers(CommandBufferScoped cbs, PipelineStageFlags stageFlags)
@@ -190,5 +201,66 @@ namespace Ryujinx.Graphics.Vulkan
return bufferTextures;
}
+
+ public DescriptorSet[] GetDescriptorSets(
+ Device device,
+ CommandBufferScoped cbs,
+ DescriptorSetTemplateUpdater templateUpdater,
+ ShaderCollection program,
+ int setIndex,
+ TextureView dummyTexture,
+ SamplerHolder dummySampler)
+ {
+ if (_cachedDescriptorSets != null)
+ {
+ // We still need to ensure the current command buffer holds a reference to all used textures.
+
+ if (!_isBuffer)
+ {
+ GetImageInfos(_gd, cbs, dummyTexture, dummySampler);
+ }
+ else
+ {
+ GetBufferViews(cbs);
+ }
+
+ return _cachedDescriptorSets;
+ }
+
+ _cachedDscProgram?.ReleaseManualDescriptorSetCollection(_cachedDscSetIndex, _cachedDscIndex);
+ var dsc = program.GetNewManualDescriptorSetCollection(cbs.CommandBufferIndex, setIndex, out _cachedDscIndex).Get(cbs);
+
+ DescriptorSetTemplate template = program.Templates[setIndex];
+
+ DescriptorSetTemplateWriter tu = templateUpdater.Begin(template);
+
+ if (!_isBuffer)
+ {
+ tu.Push(GetImageInfos(_gd, cbs, dummyTexture, dummySampler));
+ }
+ else
+ {
+ tu.Push(GetBufferViews(cbs));
+ }
+
+ var sets = dsc.GetSets();
+ templateUpdater.Commit(_gd, device, sets[0]);
+ _cachedDescriptorSets = sets;
+ _cachedDscProgram = program;
+ _cachedDscSetIndex = setIndex;
+
+ return sets;
+ }
+
+ public void IncrementBindCount()
+ {
+ _bindCount++;
+ }
+
+ public void DecrementBindCount()
+ {
+ int newBindCount = --_bindCount;
+ Debug.Assert(newBindCount >= 0);
+ }
}
}