Skip to content

Commit

Permalink
Merge branch 'Ryujinx:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zandm7 authored Apr 10, 2022
2 parents 4ba4e4f + 247d26b commit d64360b
Show file tree
Hide file tree
Showing 82 changed files with 6,411 additions and 2,358 deletions.
42 changes: 40 additions & 2 deletions Ryujinx.Common/System/ForceDpiAware.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Ryujinx.Common.Logging;
using System;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

Expand All @@ -11,6 +12,23 @@ public static class ForceDpiAware
[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();

private const string X11LibraryName = "libX11.so.6";

[DllImport(X11LibraryName)]
private static extern IntPtr XOpenDisplay(string display);

[DllImport(X11LibraryName)]
private static extern IntPtr XGetDefault(IntPtr display, string program, string option);

[DllImport(X11LibraryName)]
private static extern int XDisplayWidth(IntPtr display, int screenNumber);

[DllImport(X11LibraryName)]
private static extern int XDisplayWidthMM(IntPtr display, int screenNumber);

[DllImport(X11LibraryName)]
private static extern int XCloseDisplay(IntPtr display);

private static readonly double _standardDpiScale = 96.0;
private static readonly double _maxScaleFactor = 1.25;

Expand All @@ -36,9 +54,29 @@ public static double GetWindowScaleFactor()
{
userDpiScale = Graphics.FromHwnd(IntPtr.Zero).DpiX;
}
else
else if (OperatingSystem.IsLinux())
{
// TODO: Linux support
string xdgSessionType = Environment.GetEnvironmentVariable("XDG_SESSION_TYPE")?.ToLower();

if (xdgSessionType == null || xdgSessionType == "x11")
{
IntPtr display = XOpenDisplay(null);
string dpiString = Marshal.PtrToStringAnsi(XGetDefault(display, "Xft", "dpi"));
if (dpiString == null || !double.TryParse(dpiString, NumberStyles.Any, CultureInfo.InvariantCulture, out userDpiScale))
{
userDpiScale = (double)XDisplayWidth(display, 0) * 25.4 / (double)XDisplayWidthMM(display, 0);
}
XCloseDisplay(display);
}
else if (xdgSessionType == "wayland")
{
// TODO
Logger.Warning?.Print(LogClass.Application, $"Couldn't determine monitor DPI: Wayland not yet supported");
}
else
{
Logger.Warning?.Print(LogClass.Application, $"Couldn't determine monitor DPI: Unrecognised XDG_SESSION_TYPE: {xdgSessionType}");
}
}
}
catch (Exception e)
Expand Down
9 changes: 9 additions & 0 deletions Ryujinx.Graphics.GAL/Capabilities.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using Ryujinx.Graphics.Shader.Translation;

namespace Ryujinx.Graphics.GAL
{
public struct Capabilities
{
public readonly TargetApi Api;
public readonly string VendorName;

public readonly bool HasFrontFacingBug;
public readonly bool HasVectorIndexingBug;

Expand All @@ -24,6 +29,8 @@ public struct Capabilities
public readonly int StorageBufferOffsetAlignment;

public Capabilities(
TargetApi api,
string vendorName,
bool hasFrontFacingBug,
bool hasVectorIndexingBug,
bool supportsAstcCompression,
Expand All @@ -43,6 +50,8 @@ public Capabilities(
float maximumSupportedAnisotropy,
int storageBufferOffsetAlignment)
{
Api = api;
VendorName = vendorName;
HasFrontFacingBug = hasFrontFacingBug;
HasVectorIndexingBug = hasVectorIndexingBug;
SupportsAstcCompression = supportsAstcCompression;
Expand Down
4 changes: 1 addition & 3 deletions Ryujinx.Graphics.GAL/IRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ public interface IRenderer : IDisposable

void BackgroundContextAction(Action action, bool alwaysBackground = false);

IShader CompileShader(ShaderStage stage, string code);

BufferHandle CreateBuffer(int size);

IProgram CreateProgram(IShader[] shaders, ShaderInfo info);
IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info);

ISampler CreateSampler(SamplerCreateInfo info);
ITexture CreateTexture(TextureCreateInfo info, float scale);
Expand Down
6 changes: 0 additions & 6 deletions Ryujinx.Graphics.GAL/Multithreading/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Ryujinx.Graphics.GAL.Multithreading.Commands.Program;
using Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer;
using Ryujinx.Graphics.GAL.Multithreading.Commands.Sampler;
using Ryujinx.Graphics.GAL.Multithreading.Commands.Shader;
using Ryujinx.Graphics.GAL.Multithreading.Commands.Texture;
using Ryujinx.Graphics.GAL.Multithreading.Commands.Window;
using System;
Expand Down Expand Up @@ -53,8 +52,6 @@ private static void InitLookup()
{
_lookup[(int)CommandType.Action] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
ActionCommand.Run(ref GetCommand<ActionCommand>(memory), threaded, renderer);
_lookup[(int)CommandType.CompileShader] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
CompileShaderCommand.Run(ref GetCommand<CompileShaderCommand>(memory), threaded, renderer);
_lookup[(int)CommandType.CreateBuffer] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
CreateBufferCommand.Run(ref GetCommand<CreateBufferCommand>(memory), threaded, renderer);
_lookup[(int)CommandType.CreateProgram] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
Expand Down Expand Up @@ -98,9 +95,6 @@ private static void InitLookup()
_lookup[(int)CommandType.SamplerDispose] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
SamplerDisposeCommand.Run(ref GetCommand<SamplerDisposeCommand>(memory), threaded, renderer);

_lookup[(int)CommandType.ShaderDispose] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
ShaderDisposeCommand.Run(ref GetCommand<ShaderDisposeCommand>(memory), threaded, renderer);

_lookup[(int)CommandType.TextureCopyTo] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
TextureCopyToCommand.Run(ref GetCommand<TextureCopyToCommand>(memory), threaded, renderer);
_lookup[(int)CommandType.TextureCopyToScaled] = (Span<byte> memory, ThreadedRenderer threaded, IRenderer renderer) =>
Expand Down
3 changes: 0 additions & 3 deletions Ryujinx.Graphics.GAL/Multithreading/CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
enum CommandType : byte
{
Action,
CompileShader,
CreateBuffer,
CreateProgram,
CreateSampler,
Expand All @@ -29,8 +28,6 @@ enum CommandType : byte

SamplerDispose,

ShaderDispose,

TextureCopyTo,
TextureCopyToScaled,
TextureCopyToSlice,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Ryujinx.Graphics.GAL.Multithreading.Resources;
using Ryujinx.Graphics.Shader;

namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer
namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer
{
struct CreateBufferCommand : IGALCommand
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer
namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer
{
struct PreFrameCommand : IGALCommand
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class SourceProgramRequest : IProgramRequest
{
public ThreadedProgram Threaded { get; set; }

private IShader[] _shaders;
private ShaderSource[] _shaders;
private ShaderInfo _info;

public SourceProgramRequest(ThreadedProgram program, IShader[] shaders, ShaderInfo info)
public SourceProgramRequest(ThreadedProgram program, ShaderSource[] shaders, ShaderInfo info)
{
Threaded = program;

Expand All @@ -19,14 +19,7 @@ public SourceProgramRequest(ThreadedProgram program, IShader[] shaders, ShaderIn

public IProgram Create(IRenderer renderer)
{
IShader[] shaders = _shaders.Select(shader =>
{
var threaded = (ThreadedShader)shader;
threaded?.EnsureCreated();
return threaded?.Base;
}).ToArray();

return renderer.CreateProgram(shaders, _info);
return renderer.CreateProgram(_shaders, _info);
}
}
}
38 changes: 0 additions & 38 deletions Ryujinx.Graphics.GAL/Multithreading/Resources/ThreadedShader.cs

This file was deleted.

1 change: 0 additions & 1 deletion Ryujinx.Graphics.GAL/Multithreading/ThreadedPipeline.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Ryujinx.Graphics.GAL.Multithreading.Commands;
using Ryujinx.Graphics.GAL.Multithreading.Model;
using Ryujinx.Graphics.GAL.Multithreading.Resources;
using Ryujinx.Graphics.Shader;
using System;
using System.Linq;

Expand Down
11 changes: 1 addition & 10 deletions Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,6 @@ public void BackgroundContextAction(Action action, bool alwaysBackground = false
}
}

public IShader CompileShader(ShaderStage stage, string code)
{
var shader = new ThreadedShader(this, stage, code);
New<CompileShaderCommand>().Set(Ref(shader));
QueueCommand();

return shader;
}

public BufferHandle CreateBuffer(int size)
{
BufferHandle handle = Buffers.CreateBufferHandle();
Expand All @@ -268,7 +259,7 @@ public BufferHandle CreateBuffer(int size)
return handle;
}

public IProgram CreateProgram(IShader[] shaders, ShaderInfo info)
public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info)
{
var program = new ThreadedProgram(this);
SourceProgramRequest request = new SourceProgramRequest(program, shaders, info);
Expand Down
29 changes: 29 additions & 0 deletions Ryujinx.Graphics.GAL/ShaderSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Ryujinx.Graphics.Shader;
using Ryujinx.Graphics.Shader.Translation;

namespace Ryujinx.Graphics.GAL
{
public struct ShaderSource
{
public string Code { get; }
public byte[] BinaryCode { get; }
public ShaderStage Stage { get; }
public TargetLanguage Language { get; }

public ShaderSource(string code, byte[] binaryCode, ShaderStage stage, TargetLanguage language)
{
Code = code;
BinaryCode = binaryCode;
Stage = stage;
Language = language;
}

public ShaderSource(string code, ShaderStage stage, TargetLanguage language) : this(code, null, stage, language)
{
}

public ShaderSource(byte[] binaryCode, ShaderStage stage, TargetLanguage language) : this(null, binaryCode, stage, language)
{
}
}
}
16 changes: 6 additions & 10 deletions Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,20 @@ private void SendSignalingPcasB(int argument)
ulong samplerPoolGpuVa = ((ulong)_state.State.SetTexSamplerPoolAOffsetUpper << 32) | _state.State.SetTexSamplerPoolB;
ulong texturePoolGpuVa = ((ulong)_state.State.SetTexHeaderPoolAOffsetUpper << 32) | _state.State.SetTexHeaderPoolB;

GpuAccessorState gas = new GpuAccessorState(
GpuChannelPoolState poolState = new GpuChannelPoolState(
texturePoolGpuVa,
_state.State.SetTexHeaderPoolCMaximumIndex,
_state.State.SetBindlessTextureConstantBufferSlotSelect,
false,
PrimitiveTopology.Points,
default);

ShaderBundle cs = memoryManager.Physical.ShaderCache.GetComputeShader(
_channel,
gas,
shaderGpuVa,
_state.State.SetBindlessTextureConstantBufferSlotSelect);

GpuChannelComputeState computeState = new GpuChannelComputeState(
qmd.CtaThreadDimension0,
qmd.CtaThreadDimension1,
qmd.CtaThreadDimension2,
localMemorySize,
sharedMemorySize);

CachedShaderProgram cs = memoryManager.Physical.ShaderCache.GetComputeShader(_channel, poolState, computeState, shaderGpuVa);

_context.Renderer.Pipeline.SetProgram(cs.HostProgram);

_channel.TextureManager.SetComputeSamplerPool(samplerPoolGpuVa, _state.State.SetTexSamplerPoolCMaximumIndex, qmd.SamplerIndex);
Expand Down
Loading

0 comments on commit d64360b

Please sign in to comment.