801b71a128
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0059 warnings * Address dotnet format CA1816 warnings * Fix new dotnet-format issues after rebase * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Another rebase, another dotnet format run * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format style after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Run dotnet format after rebase * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Fix naming rule violations * Remove redundant code * Rename generics * Address review feedback * Remove SetOrigin
222 lines
8.1 KiB
C#
222 lines
8.1 KiB
C#
using Silk.NET.Vulkan;
|
|
using System;
|
|
using VkBuffer = Silk.NET.Vulkan.Buffer;
|
|
|
|
namespace Ryujinx.Graphics.Vulkan
|
|
{
|
|
struct DescriptorSetCollection : IDisposable
|
|
{
|
|
private DescriptorSetManager.DescriptorPoolHolder _holder;
|
|
private readonly DescriptorSet[] _descriptorSets;
|
|
public readonly int SetsCount => _descriptorSets.Length;
|
|
|
|
public DescriptorSetCollection(DescriptorSetManager.DescriptorPoolHolder holder, DescriptorSet[] descriptorSets)
|
|
{
|
|
_holder = holder;
|
|
_descriptorSets = descriptorSets;
|
|
}
|
|
|
|
public void InitializeBuffers(int setIndex, int baseBinding, int count, DescriptorType type, VkBuffer dummyBuffer)
|
|
{
|
|
Span<DescriptorBufferInfo> infos = stackalloc DescriptorBufferInfo[count];
|
|
|
|
infos.Fill(new DescriptorBufferInfo
|
|
{
|
|
Buffer = dummyBuffer,
|
|
Range = Vk.WholeSize,
|
|
});
|
|
|
|
UpdateBuffers(setIndex, baseBinding, infos, type);
|
|
}
|
|
|
|
public unsafe void UpdateBuffer(int setIndex, int bindingIndex, DescriptorBufferInfo bufferInfo, DescriptorType type)
|
|
{
|
|
if (bufferInfo.Buffer.Handle != 0UL)
|
|
{
|
|
var writeDescriptorSet = new WriteDescriptorSet
|
|
{
|
|
SType = StructureType.WriteDescriptorSet,
|
|
DstSet = _descriptorSets[setIndex],
|
|
DstBinding = (uint)bindingIndex,
|
|
DescriptorType = type,
|
|
DescriptorCount = 1,
|
|
PBufferInfo = &bufferInfo,
|
|
};
|
|
|
|
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
|
|
}
|
|
}
|
|
|
|
public unsafe void UpdateBuffers(int setIndex, int baseBinding, ReadOnlySpan<DescriptorBufferInfo> bufferInfo, DescriptorType type)
|
|
{
|
|
if (bufferInfo.Length == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
fixed (DescriptorBufferInfo* pBufferInfo = bufferInfo)
|
|
{
|
|
var writeDescriptorSet = new WriteDescriptorSet
|
|
{
|
|
SType = StructureType.WriteDescriptorSet,
|
|
DstSet = _descriptorSets[setIndex],
|
|
DstBinding = (uint)baseBinding,
|
|
DescriptorType = type,
|
|
DescriptorCount = (uint)bufferInfo.Length,
|
|
PBufferInfo = pBufferInfo,
|
|
};
|
|
|
|
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
|
|
}
|
|
}
|
|
|
|
public unsafe void UpdateImage(int setIndex, int bindingIndex, DescriptorImageInfo imageInfo, DescriptorType type)
|
|
{
|
|
if (imageInfo.ImageView.Handle != 0UL)
|
|
{
|
|
var writeDescriptorSet = new WriteDescriptorSet
|
|
{
|
|
SType = StructureType.WriteDescriptorSet,
|
|
DstSet = _descriptorSets[setIndex],
|
|
DstBinding = (uint)bindingIndex,
|
|
DescriptorType = type,
|
|
DescriptorCount = 1,
|
|
PImageInfo = &imageInfo,
|
|
};
|
|
|
|
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
|
|
}
|
|
}
|
|
|
|
public unsafe void UpdateImages(int setIndex, int baseBinding, ReadOnlySpan<DescriptorImageInfo> imageInfo, DescriptorType type)
|
|
{
|
|
if (imageInfo.Length == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
fixed (DescriptorImageInfo* pImageInfo = imageInfo)
|
|
{
|
|
var writeDescriptorSet = new WriteDescriptorSet
|
|
{
|
|
SType = StructureType.WriteDescriptorSet,
|
|
DstSet = _descriptorSets[setIndex],
|
|
DstBinding = (uint)baseBinding,
|
|
DescriptorType = type,
|
|
DescriptorCount = (uint)imageInfo.Length,
|
|
PImageInfo = pImageInfo,
|
|
};
|
|
|
|
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
|
|
}
|
|
}
|
|
|
|
public unsafe void UpdateImagesCombined(int setIndex, int baseBinding, ReadOnlySpan<DescriptorImageInfo> imageInfo, DescriptorType type)
|
|
{
|
|
if (imageInfo.Length == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
fixed (DescriptorImageInfo* pImageInfo = imageInfo)
|
|
{
|
|
for (int i = 0; i < imageInfo.Length; i++)
|
|
{
|
|
bool nonNull = imageInfo[i].ImageView.Handle != 0 && imageInfo[i].Sampler.Handle != 0;
|
|
if (nonNull)
|
|
{
|
|
int count = 1;
|
|
|
|
while (i + count < imageInfo.Length &&
|
|
imageInfo[i + count].ImageView.Handle != 0 &&
|
|
imageInfo[i + count].Sampler.Handle != 0)
|
|
{
|
|
count++;
|
|
}
|
|
|
|
var writeDescriptorSet = new WriteDescriptorSet
|
|
{
|
|
SType = StructureType.WriteDescriptorSet,
|
|
DstSet = _descriptorSets[setIndex],
|
|
DstBinding = (uint)(baseBinding + i),
|
|
DescriptorType = DescriptorType.CombinedImageSampler,
|
|
DescriptorCount = (uint)count,
|
|
PImageInfo = pImageInfo,
|
|
};
|
|
|
|
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
|
|
|
|
i += count - 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public unsafe void UpdateBufferImage(int setIndex, int bindingIndex, BufferView texelBufferView, DescriptorType type)
|
|
{
|
|
if (texelBufferView.Handle != 0UL)
|
|
{
|
|
var writeDescriptorSet = new WriteDescriptorSet
|
|
{
|
|
SType = StructureType.WriteDescriptorSet,
|
|
DstSet = _descriptorSets[setIndex],
|
|
DstBinding = (uint)bindingIndex,
|
|
DescriptorType = type,
|
|
DescriptorCount = 1,
|
|
PTexelBufferView = &texelBufferView,
|
|
};
|
|
|
|
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
|
|
}
|
|
}
|
|
|
|
public unsafe void UpdateBufferImages(int setIndex, int baseBinding, ReadOnlySpan<BufferView> texelBufferView, DescriptorType type)
|
|
{
|
|
if (texelBufferView.Length == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
fixed (BufferView* pTexelBufferView = texelBufferView)
|
|
{
|
|
for (uint i = 0; i < texelBufferView.Length;)
|
|
{
|
|
uint count = 1;
|
|
|
|
if (texelBufferView[(int)i].Handle != 0UL)
|
|
{
|
|
while (i + count < texelBufferView.Length && texelBufferView[(int)(i + count)].Handle != 0UL)
|
|
{
|
|
count++;
|
|
}
|
|
|
|
var writeDescriptorSet = new WriteDescriptorSet
|
|
{
|
|
SType = StructureType.WriteDescriptorSet,
|
|
DstSet = _descriptorSets[setIndex],
|
|
DstBinding = (uint)baseBinding + i,
|
|
DescriptorType = type,
|
|
DescriptorCount = count,
|
|
PTexelBufferView = pTexelBufferView + i,
|
|
};
|
|
|
|
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
|
|
}
|
|
|
|
i += count;
|
|
}
|
|
}
|
|
}
|
|
|
|
public readonly DescriptorSet[] GetSets()
|
|
{
|
|
return _descriptorSets;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_holder?.FreeDescriptorSets(this);
|
|
_holder = null;
|
|
}
|
|
}
|
|
}
|