Skip to content

Commit

Permalink
Merge branch 'master' into feature/input-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneIsWorking authored Dec 24, 2024
2 parents 1d4e578 + b05eab2 commit a381607
Show file tree
Hide file tree
Showing 135 changed files with 15,318 additions and 374 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ kernel:

infra:
- changed-files:
- any-glob-to-any-file: ['.github/**', 'distribution/**', 'Directory.Packages.props']
- any-glob-to-any-file: ['.github/**', 'distribution/**', 'Directory.Packages.props', 'src/Ryujinx.BuildValidationTasks/**']

documentation:
- changed-files:
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PackageVersion Include="Gommon" Version="2.6.8" />
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
<PackageVersion Include="shaderc.net" Version="0.1.0" />
<PackageVersion Include="SharpMetal" Version="1.0.0-preview20" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Silk.NET.Vulkan" Version="2.21.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.21.0" />
Expand Down
8 changes: 8 additions & 0 deletions Ryujinx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Horizon.Kernel.Generators", "src\Ryujinx.Horizon.Kernel.Generators\Ryujinx.Horizon.Kernel.Generators.csproj", "{7F55A45D-4E1D-4A36-ADD3-87F29A285AA2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.HLE.Generators", "src\Ryujinx.HLE.Generators\Ryujinx.HLE.Generators.csproj", "{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ryujinx.Graphics.Metal", "src\Ryujinx.Graphics.Metal\Ryujinx.Graphics.Metal.csproj", "{C08931FA-1191-417A-864F-3882D93E683B}"
ProjectSection(ProjectDependencies) = postProject
{A602AE97-91A5-4608-8DF1-EBF4ED7A0B9E} = {A602AE97-91A5-4608-8DF1-EBF4ED7A0B9E}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{36F870C1-3E5F-485F-B426-F0645AF78751}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -257,6 +261,10 @@ Global
{4A89A234-4F19-497D-A576-DDE8CDFC5B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A89A234-4F19-497D-A576-DDE8CDFC5B22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A89A234-4F19-497D-A576-DDE8CDFC5B22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C08931FA-1191-417A-864F-3882D93E683B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C08931FA-1191-417A-864F-3882D93E683B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C08931FA-1191-417A-864F-3882D93E683B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C08931FA-1191-417A-864F-3882D93E683B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions src/Ryujinx.Common/Configuration/GraphicsBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace Ryujinx.Common.Configuration
[JsonConverter(typeof(TypedStringEnumConverter<GraphicsBackend>))]
public enum GraphicsBackend
{
Auto,
Vulkan,
OpenGl,
Metal
}
}
18 changes: 18 additions & 0 deletions src/Ryujinx.Graphics.GAL/ComputeSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Ryujinx.Graphics.GAL
{
public readonly struct ComputeSize
{
public readonly static ComputeSize VtgAsCompute = new ComputeSize(32, 32, 1);

public readonly int X;
public readonly int Y;
public readonly int Z;

public ComputeSize(int x, int y, int z)
{
X = x;
Y = y;
Z = z;
}
}
}
78 changes: 78 additions & 0 deletions src/Ryujinx.Graphics.GAL/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,84 @@ public static int GetScalarSize(this Format format)
return 1;
}

/// <summary>
/// Get bytes per element for this format.
/// </summary>
/// <param name="format">Texture format</param>
/// <returns>Byte size for an element of this format (pixel, vertex attribute, etc)</returns>
public static int GetBytesPerElement(this Format format)
{
int scalarSize = format.GetScalarSize();

switch (format)
{
case Format.R8G8Unorm:
case Format.R8G8Snorm:
case Format.R8G8Uint:
case Format.R8G8Sint:
case Format.R8G8Uscaled:
case Format.R8G8Sscaled:
case Format.R16G16Float:
case Format.R16G16Unorm:
case Format.R16G16Snorm:
case Format.R16G16Uint:
case Format.R16G16Sint:
case Format.R16G16Uscaled:
case Format.R16G16Sscaled:
case Format.R32G32Float:
case Format.R32G32Uint:
case Format.R32G32Sint:
case Format.R32G32Uscaled:
case Format.R32G32Sscaled:
return 2 * scalarSize;

case Format.R8G8B8Unorm:
case Format.R8G8B8Snorm:
case Format.R8G8B8Uint:
case Format.R8G8B8Sint:
case Format.R8G8B8Uscaled:
case Format.R8G8B8Sscaled:
case Format.R16G16B16Float:
case Format.R16G16B16Unorm:
case Format.R16G16B16Snorm:
case Format.R16G16B16Uint:
case Format.R16G16B16Sint:
case Format.R16G16B16Uscaled:
case Format.R16G16B16Sscaled:
case Format.R32G32B32Float:
case Format.R32G32B32Uint:
case Format.R32G32B32Sint:
case Format.R32G32B32Uscaled:
case Format.R32G32B32Sscaled:
return 3 * scalarSize;

case Format.R8G8B8A8Unorm:
case Format.R8G8B8A8Snorm:
case Format.R8G8B8A8Uint:
case Format.R8G8B8A8Sint:
case Format.R8G8B8A8Srgb:
case Format.R8G8B8A8Uscaled:
case Format.R8G8B8A8Sscaled:
case Format.B8G8R8A8Unorm:
case Format.B8G8R8A8Srgb:
case Format.R16G16B16A16Float:
case Format.R16G16B16A16Unorm:
case Format.R16G16B16A16Snorm:
case Format.R16G16B16A16Uint:
case Format.R16G16B16A16Sint:
case Format.R16G16B16A16Uscaled:
case Format.R16G16B16A16Sscaled:
case Format.R32G32B32A32Float:
case Format.R32G32B32A32Uint:
case Format.R32G32B32A32Sint:
case Format.R32G32B32A32Uscaled:
case Format.R32G32B32A32Sscaled:
return 4 * scalarSize;
}

return scalarSize;
}

/// <summary>
/// Checks if the texture format is a depth or depth-stencil format.
/// </summary>
Expand Down
17 changes: 8 additions & 9 deletions src/Ryujinx.Graphics.GAL/ShaderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ public struct ShaderInfo
{
public int FragmentOutputMap { get; }
public ResourceLayout ResourceLayout { get; }
public ComputeSize ComputeLocalSize { get; }
public ProgramPipelineState? State { get; }
public bool FromCache { get; set; }

public ShaderInfo(int fragmentOutputMap, ResourceLayout resourceLayout, ProgramPipelineState state, bool fromCache = false)
public ShaderInfo(
int fragmentOutputMap,
ResourceLayout resourceLayout,
ComputeSize computeLocalSize,
ProgramPipelineState? state,
bool fromCache = false)
{
FragmentOutputMap = fragmentOutputMap;
ResourceLayout = resourceLayout;
ComputeLocalSize = computeLocalSize;
State = state;
FromCache = fromCache;
}

public ShaderInfo(int fragmentOutputMap, ResourceLayout resourceLayout, bool fromCache = false)
{
FragmentOutputMap = fragmentOutputMap;
ResourceLayout = resourceLayout;
State = null;
FromCache = fromCache;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw
/// </summary>
class VtgAsComputeContext : IDisposable
{
private const int DummyBufferSize = 16;

private readonly GpuContext _context;

/// <summary>
Expand Down Expand Up @@ -48,7 +46,7 @@ public ITexture Get(IRenderer renderer, Format format)
1,
1,
1,
1,
format.GetBytesPerElement(),
format,
DepthStencilMode.Depth,
Target.TextureBuffer,
Expand Down Expand Up @@ -521,21 +519,6 @@ public BufferRange GetGeometryIndexDataBufferRange(int offset, int size, bool wr
return new BufferRange(_geometryIndexDataBuffer.Handle, offset, size, write);
}

/// <summary>
/// Gets the range for a dummy 16 bytes buffer, filled with zeros.
/// </summary>
/// <returns>Dummy buffer range</returns>
public BufferRange GetDummyBufferRange()
{
if (_dummyBuffer == BufferHandle.Null)
{
_dummyBuffer = _context.Renderer.CreateBuffer(DummyBufferSize, BufferAccess.DeviceMemory);
_context.Renderer.Pipeline.ClearBuffer(_dummyBuffer, 0, DummyBufferSize, 0);
}

return new BufferRange(_dummyBuffer, 0, DummyBufferSize);
}

/// <summary>
/// Gets the range for a sequential index buffer, with ever incrementing index values.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public readonly void RunVertex()
{
_vacContext.VertexInfoBufferUpdater.SetVertexStride(index, 0, componentsCount);
_vacContext.VertexInfoBufferUpdater.SetVertexOffset(index, 0, 0);
SetDummyBufferTexture(_vertexAsCompute.Reservations, index, format);
continue;
}

Expand All @@ -163,15 +162,12 @@ public readonly void RunVertex()
{
_vacContext.VertexInfoBufferUpdater.SetVertexStride(index, 0, componentsCount);
_vacContext.VertexInfoBufferUpdater.SetVertexOffset(index, 0, 0);
SetDummyBufferTexture(_vertexAsCompute.Reservations, index, format);
continue;
}

int vbStride = vertexBuffer.UnpackStride();
ulong vbSize = GetVertexBufferSize(address, endAddress.Pack(), vbStride, _indexed, instanced, _firstVertex, _count);

ulong oldVbSize = vbSize;

ulong attributeOffset = (ulong)vertexAttrib.UnpackOffset();
int componentSize = format.GetScalarSize();

Expand Down Expand Up @@ -345,20 +341,6 @@ private static int GetMaxCompleteStrips(int verticesPerPrimitive, int maxOutputV
return maxOutputVertices / verticesPerPrimitive;
}

/// <summary>
/// Binds a dummy buffer as vertex buffer into a buffer texture.
/// </summary>
/// <param name="reservations">Shader resource binding reservations</param>
/// <param name="index">Buffer texture index</param>
/// <param name="format">Buffer texture format</param>
private readonly void SetDummyBufferTexture(ResourceReservations reservations, int index, Format format)
{
ITexture bufferTexture = _vacContext.EnsureBufferTexture(index + 2, format);
bufferTexture.SetStorage(_vacContext.GetDummyBufferRange());

_context.Renderer.Pipeline.SetTextureAndSampler(ShaderStage.Compute, reservations.GetVertexBufferTextureBinding(index), bufferTexture, null);
}

/// <summary>
/// Binds a vertex buffer into a buffer texture.
/// </summary>
Expand Down
13 changes: 11 additions & 2 deletions src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ public void LoadShaders(GpuContext context, ParallelDiskCacheLoader loader)

bool loadHostCache = header.CodeGenVersion == CodeGenVersion;

if (context.Capabilities.Api == TargetApi.Metal)
{
loadHostCache = false;
}

int programIndex = 0;

DataEntry entry = new();
Expand Down Expand Up @@ -392,7 +397,8 @@ public void LoadShaders(GpuContext context, ParallelDiskCacheLoader loader)
context,
shaders,
specState.PipelineState,
specState.TransformFeedbackDescriptors != null);
specState.TransformFeedbackDescriptors != null,
specState.ComputeState.GetLocalSize());

IProgram hostProgram;

Expand Down Expand Up @@ -629,7 +635,10 @@ public void AddShader(GpuContext context, CachedShaderProgram program, ReadOnlyS
return;
}

WriteHostCode(context, hostCode, program.Shaders, streams, timestamp);
if (context.Capabilities.Api != TargetApi.Metal)
{
WriteHostCode(context, hostCode, program.Shaders, streams, timestamp);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,12 @@ private void ProcessCompilationQueue()
{
ShaderSource[] shaderSources = new ShaderSource[compilation.TranslatedStages.Length];

ShaderInfoBuilder shaderInfoBuilder = new(_context, compilation.SpecializationState.TransformFeedbackDescriptors != null);
ref GpuChannelComputeState computeState = ref compilation.SpecializationState.ComputeState;

ShaderInfoBuilder shaderInfoBuilder = new(
_context,
compilation.SpecializationState.TransformFeedbackDescriptors != null,
computeLocalSize: computeState.GetLocalSize());

for (int index = 0; index < compilation.TranslatedStages.Length; index++)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GpuAccessor : GpuAccessorBase, IGpuAccessor
private readonly GpuAccessorState _state;
private readonly int _stageIndex;
private readonly bool _compute;
private readonly bool _isVulkan;
private readonly bool _isOpenGL;
private readonly bool _hasGeometryShader;
private readonly bool _supportsQuads;

Expand All @@ -38,7 +38,7 @@ public GpuAccessor(
_channel = channel;
_state = state;
_stageIndex = stageIndex;
_isVulkan = context.Capabilities.Api == TargetApi.Vulkan;
_isOpenGL = context.Capabilities.Api == TargetApi.OpenGL;
_hasGeometryShader = hasGeometryShader;
_supportsQuads = context.Capabilities.SupportsQuads;

Expand Down Expand Up @@ -116,10 +116,10 @@ public uint QueryConstantBufferUse()
public GpuGraphicsState QueryGraphicsState()
{
return _state.GraphicsState.CreateShaderGraphicsState(
!_isVulkan,
_isOpenGL,
_supportsQuads,
_hasGeometryShader,
_isVulkan || _state.GraphicsState.YNegateEnabled);
!_isOpenGL || _state.GraphicsState.YNegateEnabled);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Gpu/Shader/GpuAccessorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SetBindingPair CreateConstantBufferBinding(int index)
{
int binding;

if (_context.Capabilities.Api == TargetApi.Vulkan)
if (_context.Capabilities.Api != TargetApi.OpenGL)
{
binding = GetBindingFromIndex(index, _context.Capabilities.MaximumUniformBuffersPerStage, "Uniform buffer");
}
Expand All @@ -71,7 +71,7 @@ public SetBindingPair CreateImageBinding(int count, bool isBuffer)
{
int binding;

if (_context.Capabilities.Api == TargetApi.Vulkan)
if (_context.Capabilities.Api != TargetApi.OpenGL)
{
if (count == 1)
{
Expand Down Expand Up @@ -103,7 +103,7 @@ public SetBindingPair CreateStorageBufferBinding(int index)
{
int binding;

if (_context.Capabilities.Api == TargetApi.Vulkan)
if (_context.Capabilities.Api != TargetApi.OpenGL)
{
binding = GetBindingFromIndex(index, _context.Capabilities.MaximumStorageBuffersPerStage, "Storage buffer");
}
Expand All @@ -119,7 +119,7 @@ public SetBindingPair CreateTextureBinding(int count, bool isBuffer)
{
int binding;

if (_context.Capabilities.Api == TargetApi.Vulkan)
if (_context.Capabilities.Api != TargetApi.OpenGL)
{
if (count == 1)
{
Expand Down
Loading

0 comments on commit a381607

Please sign in to comment.