diff options
author | riperiperi <rhy3756547@hotmail.com> | 2024-01-20 14:07:33 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 11:07:33 -0300 |
commit | 331c07807fd0db5d4452d6ef02962a6d19a56d7f (patch) | |
tree | a306b0b43f50c58abb649e45057008f60b5da656 /src/Ryujinx.Graphics.Vulkan/DescriptorSetTemplateUpdater.cs | |
parent | a772b073ecb5c753acbddbf5861051d878f5153b (diff) |
Vulkan: Use templates for descriptor updates (#6014)1.1.1116
* WIP: Descriptor template update
* Make configurable
* Wording
* Simplify template creation
* Whitespace
* UTF-8 whatever
* Leave only templated path, better template updater
Diffstat (limited to 'src/Ryujinx.Graphics.Vulkan/DescriptorSetTemplateUpdater.cs')
-rw-r--r-- | src/Ryujinx.Graphics.Vulkan/DescriptorSetTemplateUpdater.cs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/Ryujinx.Graphics.Vulkan/DescriptorSetTemplateUpdater.cs b/src/Ryujinx.Graphics.Vulkan/DescriptorSetTemplateUpdater.cs new file mode 100644 index 00000000..1eb9dce7 --- /dev/null +++ b/src/Ryujinx.Graphics.Vulkan/DescriptorSetTemplateUpdater.cs @@ -0,0 +1,65 @@ +using Ryujinx.Common; +using Silk.NET.Vulkan; +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Ryujinx.Graphics.Vulkan +{ + ref struct DescriptorSetTemplateWriter + { + private Span<byte> _data; + + public DescriptorSetTemplateWriter(Span<byte> data) + { + _data = data; + } + + public void Push<T>(ReadOnlySpan<T> values) where T : unmanaged + { + Span<T> target = MemoryMarshal.Cast<byte, T>(_data); + + values.CopyTo(target); + + _data = _data[(Unsafe.SizeOf<T>() * values.Length)..]; + } + } + + unsafe class DescriptorSetTemplateUpdater : IDisposable + { + private const int SizeGranularity = 512; + + private DescriptorSetTemplate _activeTemplate; + private NativeArray<byte> _data; + + private void EnsureSize(int size) + { + if (_data == null || _data.Length < size) + { + _data?.Dispose(); + + int dataSize = BitUtils.AlignUp(size, SizeGranularity); + _data = new NativeArray<byte>(dataSize); + } + } + + public DescriptorSetTemplateWriter Begin(DescriptorSetTemplate template) + { + _activeTemplate = template; + + EnsureSize(template.Size); + + return new DescriptorSetTemplateWriter(new Span<byte>(_data.Pointer, template.Size)); + } + + public void Commit(VulkanRenderer gd, Device device, DescriptorSet set) + { + gd.Api.UpdateDescriptorSetWithTemplate(device, set, _activeTemplate.Template, _data.Pointer); + } + + public void Dispose() + { + _data?.Dispose(); + } + } +} |