Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/auto-load-e…
Browse files Browse the repository at this point in the history
…xtra-files
  • Loading branch information
J-Swift committed Sep 7, 2024
2 parents 401e60e + ca59c3f commit ecbea21
Show file tree
Hide file tree
Showing 39 changed files with 642 additions and 140 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>
24 changes: 22 additions & 2 deletions src/Ryujinx.Common/GraphicsDriver/DriverUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
using Ryujinx.Common.Utilities;
using System;

namespace Ryujinx.Common.GraphicsDriver
{
public static class DriverUtilities
{
private static void AddMesaFlags(string envVar, string newFlags)
{
string existingFlags = Environment.GetEnvironmentVariable(envVar);

string flags = existingFlags == null ? newFlags : $"{existingFlags},{newFlags}";

OsUtils.SetEnvironmentVariableNoCaching(envVar, flags);
}

public static void InitDriverConfig(bool oglThreading)
{
if (OperatingSystem.IsLinux())
{
AddMesaFlags("RADV_DEBUG", "nodcc");
}

ToggleOGLThreading(oglThreading);
}

public static void ToggleOGLThreading(bool enabled)
{
Environment.SetEnvironmentVariable("mesa_glthread", enabled.ToString().ToLower());
Environment.SetEnvironmentVariable("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");
OsUtils.SetEnvironmentVariableNoCaching("mesa_glthread", enabled.ToString().ToLower());
OsUtils.SetEnvironmentVariableNoCaching("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");

try
{
Expand Down
24 changes: 24 additions & 0 deletions src/Ryujinx.Common/Utilities/OsUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Ryujinx.Common.Utilities
{
public partial class OsUtils
{
[LibraryImport("libc", SetLastError = true)]
private static partial int setenv([MarshalAs(UnmanagedType.LPStr)] string name, [MarshalAs(UnmanagedType.LPStr)] string value, int overwrite);

public static void SetEnvironmentVariableNoCaching(string key, string value)
{
// Set the value in the cached environment variables, too.
Environment.SetEnvironmentVariable(key, value);

if (!OperatingSystem.IsWindows())
{
int res = setenv(key, value, 1);
Debug.Assert(res != -1);
}
}
}
}
8 changes: 7 additions & 1 deletion src/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClassState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,13 @@ struct Size3D
#pragma warning disable CS0649 // Field is never assigned to
public int Width;
public int Height;
public int Depth;
public ushort Depth;
public ushort Flags;

public readonly bool UnpackIsLayered()
{
return (Flags & 1) == 0;
}
#pragma warning restore CS0649
}

Expand Down
8 changes: 3 additions & 5 deletions src/Ryujinx.Graphics.Gpu/Image/TextureCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,11 @@ public Texture FindOrCreateTexture(
int gobBlocksInY = dsState.MemoryLayout.UnpackGobBlocksInY();
int gobBlocksInZ = dsState.MemoryLayout.UnpackGobBlocksInZ();

layered &= size.UnpackIsLayered();

Target target;

if (dsState.MemoryLayout.UnpackIsTarget3D())
{
target = Target.Texture3D;
}
else if ((samplesInX | samplesInY) != 1)
if ((samplesInX | samplesInY) != 1)
{
target = size.Depth > 1 && layered
? Target.Texture2DMultisampleArray
Expand Down
39 changes: 26 additions & 13 deletions src/Ryujinx.Graphics.Vulkan/BarrierBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ private enum IncoherentBarrierType
CommandBuffer
}

private bool _feedbackLoopActive;
private PipelineStageFlags _incoherentBufferWriteStages;
private PipelineStageFlags _incoherentTextureWriteStages;
private PipelineStageFlags _extraStages;
private IncoherentBarrierType _queuedIncoherentBarrier;
private bool _queuedFeedbackLoopBarrier;

public BarrierBatch(VulkanRenderer gd)
{
Expand All @@ -53,17 +55,6 @@ public static (AccessFlags Access, PipelineStageFlags Stages) GetSubpassAccessSu
stages |= PipelineStageFlags.TransformFeedbackBitExt;
}

if (!gd.IsTBDR)
{
// Desktop GPUs can transform image barriers into memory barriers.

access |= AccessFlags.DepthStencilAttachmentWriteBit | AccessFlags.ColorAttachmentWriteBit;
access |= AccessFlags.DepthStencilAttachmentReadBit | AccessFlags.ColorAttachmentReadBit;

stages |= PipelineStageFlags.EarlyFragmentTestsBit | PipelineStageFlags.LateFragmentTestsBit;
stages |= PipelineStageFlags.ColorAttachmentOutputBit;
}

return (access, stages);
}

Expand Down Expand Up @@ -178,23 +169,43 @@ public unsafe void FlushMemoryBarrier(ShaderCollection program, bool inRenderPas
}

_queuedIncoherentBarrier = IncoherentBarrierType.None;
_queuedFeedbackLoopBarrier = false;
}
else if (_feedbackLoopActive && _queuedFeedbackLoopBarrier)
{
// Feedback loop barrier.

MemoryBarrier barrier = new MemoryBarrier()
{
SType = StructureType.MemoryBarrier,
SrcAccessMask = AccessFlags.ShaderWriteBit,
DstAccessMask = AccessFlags.ShaderReadBit
};

QueueBarrier(barrier, PipelineStageFlags.FragmentShaderBit, PipelineStageFlags.AllGraphicsBit);

_queuedFeedbackLoopBarrier = false;
}

_feedbackLoopActive = false;
}
}

public unsafe void Flush(CommandBufferScoped cbs, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
{
Flush(cbs, null, inRenderPass, rpHolder, endRenderPass);
Flush(cbs, null, false, inRenderPass, rpHolder, endRenderPass);
}

public unsafe void Flush(CommandBufferScoped cbs, ShaderCollection program, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
public unsafe void Flush(CommandBufferScoped cbs, ShaderCollection program, bool feedbackLoopActive, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
{
if (program != null)
{
_incoherentBufferWriteStages |= program.IncoherentBufferWriteStages | _extraStages;
_incoherentTextureWriteStages |= program.IncoherentTextureWriteStages;
}

_feedbackLoopActive |= feedbackLoopActive;

FlushMemoryBarrier(program, inRenderPass);

if (!inRenderPass && rpHolder != null)
Expand Down Expand Up @@ -406,6 +417,8 @@ private void QueueIncoherentBarrier(IncoherentBarrierType type)
{
_queuedIncoherentBarrier = type;
}

_queuedFeedbackLoopBarrier = true;
}

public void QueueTextureBarrier()
Expand Down
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
Loading

0 comments on commit ecbea21

Please sign in to comment.