Skip to content

Commit

Permalink
Vulkan: Update Silk.NET to 2.21 (#7266)
Browse files Browse the repository at this point in the history
* Update Silk.NET version

* fix: add MoltenVK resolver workaround

fix: add MoltenVK resolver workaround

* Cleanup

* Readonly ref warnings

* Remove driver id todo
  • Loading branch information
riperiperi authored Sep 1, 2024
1 parent 2c5c039 commit 398fa1c
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 60 deletions.
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
<PackageVersion Include="shaderc.net" Version="0.1.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Silk.NET.Vulkan" Version="2.16.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.16.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.16.0" />
<PackageVersion Include="Silk.NET.Vulkan" Version="2.21.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.21.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.21.0" />
<PackageVersion Include="SkiaSharp" Version="2.88.7" />
<PackageVersion Include="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
<PackageVersion Include="SPB" Version="0.0.4-build32" />
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
</ItemGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions src/Ryujinx.Graphics.Vulkan/BufferHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public unsafe Auto<DisposableBufferView> CreateView(VkFormat format, int offset,
Range = (uint)size,
};

_gd.Api.CreateBufferView(_device, bufferViewCreateInfo, null, out var bufferView).ThrowOnError();
_gd.Api.CreateBufferView(_device, in bufferViewCreateInfo, null, out var bufferView).ThrowOnError();

return new Auto<DisposableBufferView>(new DisposableBufferView(_gd.Api, _device, bufferView), this, _waitable, _buffer);
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public unsafe void InsertBarrier(CommandBuffer commandBuffer, bool isWrite)
PipelineStageFlags.AllCommandsBit,
DependencyFlags.DeviceGroupBit,
1,
memoryBarrier,
in memoryBarrier,
0,
null,
0,
Expand Down Expand Up @@ -770,7 +770,7 @@ public static unsafe void InsertBufferBarrier(
0,
null,
1,
memoryBarrier,
in memoryBarrier,
0,
null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/BufferManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public unsafe BufferHandle CreateSparse(VulkanRenderer gd, ReadOnlySpan<BufferRa
PBufferBinds = &bufferBind
};

gd.Api.QueueBindSparse(gd.Queue, 1, bindSparseInfo, default).ThrowOnError();
gd.Api.QueueBindSparse(gd.Queue, 1, in bindSparseInfo, default).ThrowOnError();
}

var holder = new BufferHolder(gd, _device, buffer, (int)size, storageAllocations);
Expand Down
5 changes: 4 additions & 1 deletion src/Ryujinx.Graphics.Vulkan/BufferState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public readonly void BindTransformFeedbackBuffer(VulkanRenderer gd, CommandBuffe
{
var buffer = _buffer.Get(cbs, _offset, _size, true).Value;

gd.TransformFeedbackApi.CmdBindTransformFeedbackBuffers(cbs.CommandBuffer, binding, 1, buffer, (ulong)_offset, (ulong)_size);
ulong offset = (ulong)_offset;
ulong size = (ulong)_size;

gd.TransformFeedbackApi.CmdBindTransformFeedbackBuffers(cbs.CommandBuffer, binding, 1, in buffer, in offset, in size);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Vulkan/CommandBufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Initialize(Vk api, Device device, CommandPool pool)
Level = CommandBufferLevel.Primary,
};

api.AllocateCommandBuffers(device, allocateInfo, out CommandBuffer);
api.AllocateCommandBuffers(device, in allocateInfo, out CommandBuffer);

Dependants = new List<IAuto>();
Waitables = new List<MultiFenceHolder>();
Expand Down Expand Up @@ -83,7 +83,7 @@ public unsafe CommandBufferPool(
CommandPoolCreateFlags.ResetCommandBufferBit,
};

api.CreateCommandPool(device, commandPoolCreateInfo, null, out _pool).ThrowOnError();
api.CreateCommandPool(device, in commandPoolCreateInfo, null, out _pool).ThrowOnError();

// We need at least 2 command buffers to get texture data in some cases.
_totalCommandBuffers = isLight ? 2 : MaxCommandBuffers;
Expand Down Expand Up @@ -253,7 +253,7 @@ public CommandBufferScoped Rent()
SType = StructureType.CommandBufferBeginInfo,
};

_api.BeginCommandBuffer(entry.CommandBuffer, commandBufferBeginInfo).ThrowOnError();
_api.BeginCommandBuffer(entry.CommandBuffer, in commandBufferBeginInfo).ThrowOnError();

return new CommandBufferScoped(this, entry.CommandBuffer, cursor);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ public unsafe void Return(

lock (_queueLock)
{
_api.QueueSubmit(_queue, 1, sInfo, entry.Fence.GetUnsafe()).ThrowOnError();
_api.QueueSubmit(_queue, 1, in sInfo, entry.Fence.GetUnsafe()).ThrowOnError();
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Ryujinx.Graphics.Vulkan/DescriptorSetCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public unsafe void UpdateBuffer(int setIndex, int bindingIndex, DescriptorBuffer
PBufferInfo = &bufferInfo,
};

_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, in writeDescriptorSet, 0, null);
}
}

Expand All @@ -66,7 +66,7 @@ public unsafe void UpdateBuffers(int setIndex, int baseBinding, ReadOnlySpan<Des
PBufferInfo = pBufferInfo,
};

_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, in writeDescriptorSet, 0, null);
}
}

Expand All @@ -84,7 +84,7 @@ public unsafe void UpdateImage(int setIndex, int bindingIndex, DescriptorImageIn
PImageInfo = &imageInfo,
};

_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, in writeDescriptorSet, 0, null);
}
}

Expand All @@ -107,7 +107,7 @@ public unsafe void UpdateImages(int setIndex, int baseBinding, ReadOnlySpan<Desc
PImageInfo = pImageInfo,
};

_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, in writeDescriptorSet, 0, null);
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ public unsafe void UpdateImagesCombined(int setIndex, int baseBinding, ReadOnlyS
PImageInfo = pImageInfo,
};

_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, in writeDescriptorSet, 0, null);

i += count - 1;
}
Expand All @@ -166,7 +166,7 @@ public unsafe void UpdateBufferImage(int setIndex, int bindingIndex, BufferView
PTexelBufferView = &texelBufferView,
};

_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, in writeDescriptorSet, 0, null);
}
}

Expand Down Expand Up @@ -200,7 +200,7 @@ public unsafe void UpdateBufferImages(int setIndex, int baseBinding, ReadOnlySpa
PTexelBufferView = pTexelBufferView + i,
};

_holder.Api.UpdateDescriptorSets(_holder.Device, 1, writeDescriptorSet, 0, null);
_holder.Api.UpdateDescriptorSets(_holder.Device, 1, in writeDescriptorSet, 0, null);
}

i += count;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/DescriptorSetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public unsafe DescriptorPoolHolder(Vk api, Device device, ReadOnlySpan<Descripto
PPoolSizes = pPoolsSize,
};

Api.CreateDescriptorPool(device, descriptorPoolCreateInfo, null, out _pool).ThrowOnError();
Api.CreateDescriptorPool(device, in descriptorPoolCreateInfo, null, out _pool).ThrowOnError();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/FramebufferParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public unsafe Auto<DisposableFramebuffer> Create(Vk api, CommandBufferScoped cbs
Layers = Layers,
};

api.CreateFramebuffer(_device, framebufferCreateInfo, null, out var framebuffer).ThrowOnError();
api.CreateFramebuffer(_device, in framebufferCreateInfo, null, out var framebuffer).ThrowOnError();
return new Auto<DisposableFramebuffer>(new DisposableFramebuffer(api, _device, framebuffer), null, _attachments);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public unsafe bool TryImport(
PNext = &importInfo,
};

Result result = _api.AllocateMemory(_device, memoryAllocateInfo, null, out var deviceMemory);
Result result = _api.AllocateMemory(_device, in memoryAllocateInfo, null, out var deviceMemory);

if (result < Result.Success)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public unsafe MemoryAllocation Allocate(ulong size, ulong alignment, bool map)
MemoryTypeIndex = (uint)MemoryTypeIndex,
};

_api.AllocateMemory(_device, memoryAllocateInfo, null, out var deviceMemory).ThrowOnError();
_api.AllocateMemory(_device, in memoryAllocateInfo, null, out var deviceMemory).ThrowOnError();

IntPtr hostPointer = IntPtr.Zero;

Expand Down
18 changes: 18 additions & 0 deletions src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKInitialization.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Silk.NET.Core.Loader;
using Silk.NET.Vulkan;
using System;
using System.Runtime.InteropServices;
Expand All @@ -8,6 +9,8 @@ namespace Ryujinx.Graphics.Vulkan.MoltenVK
[SupportedOSPlatform("macos")]
public static partial class MVKInitialization
{
private const string VulkanLib = "libvulkan.dylib";

[LibraryImport("libMoltenVK.dylib")]
private static partial Result vkGetMoltenVKConfigurationMVK(IntPtr unusedInstance, out MVKConfiguration config, in IntPtr configSize);

Expand All @@ -29,5 +32,20 @@ public static void Initialize()

vkSetMoltenVKConfigurationMVK(IntPtr.Zero, config, configSize);
}

private static string[] Resolver(string path)
{
if (path.EndsWith(VulkanLib))
{
path = path[..^VulkanLib.Length] + "libMoltenVK.dylib";
return [path];
}
return Array.Empty<string>();
}

public static void InitializeResolver()
{
((DefaultPathResolver)PathResolver.Default).Resolvers.Insert(0, Resolver);
}
}
}
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Vulkan/PipelineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public unsafe PipelineBase(VulkanRenderer gd, Device device)
SType = StructureType.PipelineCacheCreateInfo,
};

gd.Api.CreatePipelineCache(device, pipelineCacheCreateInfo, null, out PipelineCache).ThrowOnError();
gd.Api.CreatePipelineCache(device, in pipelineCacheCreateInfo, null, out PipelineCache).ThrowOnError();

_descriptorSetUpdater = new DescriptorSetUpdater(gd, device);
_vertexBufferUpdater = new VertexBufferUpdater(gd);
Expand Down Expand Up @@ -1628,7 +1628,7 @@ private unsafe void BeginRenderPass()
ClearValueCount = 1,
};

Gd.Api.CmdBeginRenderPass(CommandBuffer, renderPassBeginInfo, SubpassContents.Inline);
Gd.Api.CmdBeginRenderPass(CommandBuffer, in renderPassBeginInfo, SubpassContents.Inline);
RenderPassActive = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static unsafe DisposableRenderPass ToRenderPass(this ProgramPipelineState
DependencyCount = 1,
};

gd.Api.CreateRenderPass(device, renderPassCreateInfo, null, out var renderPass).ThrowOnError();
gd.Api.CreateRenderPass(device, in renderPassCreateInfo, null, out var renderPass).ThrowOnError();

return new DisposableRenderPass(gd.Api, device, renderPass);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/PipelineLayoutFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static unsafe ResourceLayouts Create(
Flags = flags,
};

gd.Api.CreateDescriptorSetLayout(device, descriptorSetLayoutCreateInfo, null, out layouts[setIndex]).ThrowOnError();
gd.Api.CreateDescriptorSetLayout(device, in descriptorSetLayoutCreateInfo, null, out layouts[setIndex]).ThrowOnError();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/Queries/BufferedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public unsafe BufferedQuery(VulkanRenderer gd, Device device, PipelineFull pipel
PipelineStatistics = flags,
};

gd.Api.CreateQueryPool(device, queryPoolCreateInfo, null, out _queryPool).ThrowOnError();
gd.Api.CreateQueryPool(device, in queryPoolCreateInfo, null, out _queryPool).ThrowOnError();
}

var buffer = gd.BufferManager.Create(gd, sizeof(long), forConditionalRendering: true);
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/RenderPassHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public unsafe RenderPassHolder(VulkanRenderer gd, Device device, RenderPassCache
DependencyCount = 1,
};

gd.Api.CreateRenderPass(device, renderPassCreateInfo, null, out var renderPass).ThrowOnError();
gd.Api.CreateRenderPass(device, in renderPassCreateInfo, null, out var renderPass).ThrowOnError();

_renderPass = new Auto<DisposableRenderPass>(new DisposableRenderPass(gd.Api, device, renderPass));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/SamplerHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public unsafe SamplerHolder(VulkanRenderer gd, Device device, SamplerCreateInfo
samplerCreateInfo.BorderColor = BorderColor.FloatCustomExt;
}

gd.Api.CreateSampler(device, samplerCreateInfo, null, out var sampler).ThrowOnError();
gd.Api.CreateSampler(device, in samplerCreateInfo, null, out var sampler).ThrowOnError();

_sampler = new Auto<DisposableSampler>(new DisposableSampler(gd.Api, device, sampler));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Vulkan/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public unsafe Shader(Vk api, Device device, ShaderSource shaderSource)
PCode = (uint*)pCode,
};

api.CreateShaderModule(device, shaderModuleCreateInfo, null, out _module).ThrowOnError();
api.CreateShaderModule(device, in shaderModuleCreateInfo, null, out _module).ThrowOnError();
}

CompileStatus = ProgramLinkStatus.Success;
Expand Down
12 changes: 6 additions & 6 deletions src/Ryujinx.Graphics.Vulkan/TextureCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static int Clamp(int value, int max)
DstOffsets = dstOffsets,
};

api.CmdBlitImage(commandBuffer, srcImage, ImageLayout.General, dstImage, ImageLayout.General, 1, region, filter);
api.CmdBlitImage(commandBuffer, srcImage, ImageLayout.General, dstImage, ImageLayout.General, 1, in region, filter);

copySrcLevel++;
copyDstLevel++;
Expand Down Expand Up @@ -320,13 +320,13 @@ public static void Copy(
{
var region = new ImageResolve(srcSl, new Offset3D(0, 0, srcZ), dstSl, new Offset3D(0, 0, dstZ), extent);

api.CmdResolveImage(commandBuffer, srcImage, ImageLayout.General, dstImage, ImageLayout.General, 1, region);
api.CmdResolveImage(commandBuffer, srcImage, ImageLayout.General, dstImage, ImageLayout.General, 1, in region);
}
else
{
var region = new ImageCopy(srcSl, new Offset3D(0, 0, srcZ), dstSl, new Offset3D(0, 0, dstZ), extent);

api.CmdCopyImage(commandBuffer, srcImage, ImageLayout.General, dstImage, ImageLayout.General, 1, region);
api.CmdCopyImage(commandBuffer, srcImage, ImageLayout.General, dstImage, ImageLayout.General, 1, in region);
}

width = Math.Max(1, width >> 1);
Expand Down Expand Up @@ -422,7 +422,7 @@ public unsafe static void ResolveDepthStencil(
DependencyCount = 1,
};

gd.Api.CreateRenderPass2(device, renderPassCreateInfo, null, out var renderPass).ThrowOnError();
gd.Api.CreateRenderPass2(device, in renderPassCreateInfo, null, out var renderPass).ThrowOnError();

using var rp = new Auto<DisposableRenderPass>(new DisposableRenderPass(gd.Api, device, renderPass));

Expand All @@ -445,7 +445,7 @@ public unsafe static void ResolveDepthStencil(
Layers = (uint)src.Layers,
};

gd.Api.CreateFramebuffer(device, framebufferCreateInfo, null, out var framebuffer).ThrowOnError();
gd.Api.CreateFramebuffer(device, in framebufferCreateInfo, null, out var framebuffer).ThrowOnError();
using var fb = new Auto<DisposableFramebuffer>(new DisposableFramebuffer(gd.Api, device, framebuffer), null, srcView, dstView);

var renderArea = new Rect2D(null, new Extent2D((uint)src.Info.Width, (uint)src.Info.Height));
Expand All @@ -465,7 +465,7 @@ public unsafe static void ResolveDepthStencil(
// to resolve the depth-stencil texture.
// TODO: Do speculative resolve and part of the same render pass as the draw to avoid
// ending the current render pass?
gd.Api.CmdBeginRenderPass(cbs.CommandBuffer, renderPassBeginInfo, SubpassContents.Inline);
gd.Api.CmdBeginRenderPass(cbs.CommandBuffer, in renderPassBeginInfo, SubpassContents.Inline);
gd.Api.CmdEndRenderPass(cbs.CommandBuffer);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Vulkan/TextureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public unsafe TextureStorage(
Flags = flags,
};

gd.Api.CreateImage(device, imageCreateInfo, null, out _image).ThrowOnError();
gd.Api.CreateImage(device, in imageCreateInfo, null, out _image).ThrowOnError();

if (foreignAllocation == null)
{
Expand Down Expand Up @@ -284,7 +284,7 @@ private unsafe void InitialTransition(ImageLayout srcLayout, ImageLayout dstLayo
0,
null,
1,
barrier);
in barrier);

if (useTempCbs)
{
Expand Down Expand Up @@ -401,11 +401,11 @@ public void CopyFromOrToBuffer(

if (to)
{
_gd.Api.CmdCopyImageToBuffer(commandBuffer, image, ImageLayout.General, buffer, 1, region);
_gd.Api.CmdCopyImageToBuffer(commandBuffer, image, ImageLayout.General, buffer, 1, in region);
}
else
{
_gd.Api.CmdCopyBufferToImage(commandBuffer, buffer, image, ImageLayout.General, 1, region);
_gd.Api.CmdCopyBufferToImage(commandBuffer, buffer, image, ImageLayout.General, 1, in region);
}

offset += mipSize;
Expand Down
Loading

0 comments on commit 398fa1c

Please sign in to comment.