Compare commits

...

3 Commits

Author SHA1 Message Date
gdkchan 8afdade37a
Merge 9003549de1 into ef81658fbd 2024-09-18 23:55:53 +03:00
gdkchan ef81658fbd
Implement support for shader ATOM.EXCH instruction (#7320)
* Implement support for shader ATOM.EXCH instruction

* Shader cache version bump

* Check type
2024-09-18 15:48:55 -03:00
gdkchan 9003549de1 Replace shaderc.net with Silk.NET.Shaderc 2024-09-01 17:43:29 -03:00
5 changed files with 64 additions and 60 deletions

View File

@ -37,8 +37,8 @@
<PackageVersion Include="Ryujinx.GtkSharp" Version="3.24.24.59-ryujinx" /> <PackageVersion Include="Ryujinx.GtkSharp" Version="3.24.24.59-ryujinx" />
<PackageVersion Include="Ryujinx.SDL2-CS" Version="2.30.0-build32" /> <PackageVersion Include="Ryujinx.SDL2-CS" Version="2.30.0-build32" />
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" /> <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="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Silk.NET.Shaderc" Version="2.21.0" />
<PackageVersion Include="Silk.NET.Vulkan" Version="2.21.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.EXT" Version="2.21.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.21.0" /> <PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.21.0" />

View File

@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMajor = 1;
private const ushort FileFormatVersionMinor = 2; private const ushort FileFormatVersionMinor = 2;
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
private const uint CodeGenVersion = 7131; private const uint CodeGenVersion = 7320;
private const string SharedTocFileName = "shared.toc"; private const string SharedTocFileName = "shared.toc";
private const string SharedDataFileName = "shared.data"; private const string SharedDataFileName = "shared.data";

View File

@ -222,30 +222,14 @@ namespace Ryujinx.Graphics.Shader.Instructions
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}."); context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}.");
} }
break; break;
case AtomOp.And: case AtomOp.Min:
if (type == AtomSize.S32 || type == AtomSize.U32) if (type == AtomSize.S32)
{ {
res = context.AtomicAnd(storageKind, e0, e1, value); res = context.AtomicMinS32(storageKind, e0, e1, value);
} }
else else if (type == AtomSize.U32)
{ {
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}."); res = context.AtomicMinU32(storageKind, e0, e1, value);
}
break;
case AtomOp.Xor:
if (type == AtomSize.S32 || type == AtomSize.U32)
{
res = context.AtomicXor(storageKind, e0, e1, value);
}
else
{
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}.");
}
break;
case AtomOp.Or:
if (type == AtomSize.S32 || type == AtomSize.U32)
{
res = context.AtomicOr(storageKind, e0, e1, value);
} }
else else
{ {
@ -266,20 +250,49 @@ namespace Ryujinx.Graphics.Shader.Instructions
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}."); context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}.");
} }
break; break;
case AtomOp.Min: case AtomOp.And:
if (type == AtomSize.S32) if (type == AtomSize.S32 || type == AtomSize.U32)
{ {
res = context.AtomicMinS32(storageKind, e0, e1, value); res = context.AtomicAnd(storageKind, e0, e1, value);
}
else if (type == AtomSize.U32)
{
res = context.AtomicMinU32(storageKind, e0, e1, value);
} }
else else
{ {
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}."); context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}.");
} }
break; break;
case AtomOp.Or:
if (type == AtomSize.S32 || type == AtomSize.U32)
{
res = context.AtomicOr(storageKind, e0, e1, value);
}
else
{
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}.");
}
break;
case AtomOp.Xor:
if (type == AtomSize.S32 || type == AtomSize.U32)
{
res = context.AtomicXor(storageKind, e0, e1, value);
}
else
{
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}.");
}
break;
case AtomOp.Exch:
if (type == AtomSize.S32 || type == AtomSize.U32)
{
res = context.AtomicSwap(storageKind, e0, e1, value);
}
else
{
context.TranslatorContext.GpuAccessor.Log($"Invalid reduction type: {type}.");
}
break;
default:
context.TranslatorContext.GpuAccessor.Log($"Invalid atomic operation: {op}.");
break;
} }
return res; return res;

View File

@ -52,7 +52,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="OpenTK.Windowing.GraphicsLibraryFramework" /> <PackageReference Include="OpenTK.Windowing.GraphicsLibraryFramework" />
<PackageReference Include="shaderc.net" /> <PackageReference Include="Silk.NET.Shaderc" />
<PackageReference Include="Silk.NET.Vulkan" /> <PackageReference Include="Silk.NET.Vulkan" />
<PackageReference Include="Silk.NET.Vulkan.Extensions.EXT" /> <PackageReference Include="Silk.NET.Vulkan.Extensions.EXT" />
<PackageReference Include="Silk.NET.Vulkan.Extensions.KHR" /> <PackageReference Include="Silk.NET.Vulkan.Extensions.KHR" />

View File

@ -1,7 +1,7 @@
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader; using Ryujinx.Graphics.Shader;
using shaderc; using Silk.NET.Shaderc;
using Silk.NET.Vulkan; using Silk.NET.Vulkan;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -11,10 +11,6 @@ namespace Ryujinx.Graphics.Vulkan
{ {
class Shader : IDisposable class Shader : IDisposable
{ {
// The shaderc.net dependency's Options constructor and dispose are not thread safe.
// Take this lock when using them.
private static readonly object _shaderOptionsLock = new();
private static readonly IntPtr _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main"); private static readonly IntPtr _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main");
private readonly Vk _api; private readonly Vk _api;
@ -73,38 +69,33 @@ namespace Ryujinx.Graphics.Vulkan
private unsafe static byte[] GlslToSpirv(string glsl, ShaderStage stage) private unsafe static byte[] GlslToSpirv(string glsl, ShaderStage stage)
{ {
Options options; var api = Shaderc.GetApi();
var compiler = api.CompilerInitialize();
var options = api.CompileOptionsInitialize();
lock (_shaderOptionsLock) api.CompileOptionsSetSourceLanguage(options, SourceLanguage.Glsl);
api.CompileOptionsSetTargetSpirv(options, SpirvVersion.Shaderc15);
api.CompileOptionsSetTargetEnv(options, TargetEnv.Vulkan, Vk.Version12);
var scr = api.CompileIntoSpv(compiler, glsl, (nuint)glsl.Length, GetShaderCShaderStage(stage), "Ryu", "main", options);
var status = api.ResultGetCompilationStatus(scr);
if (status != CompilationStatus.Success)
{ {
options = new Options(false) Logger.Error?.Print(LogClass.Gpu, $"Shader compilation error: {status} {api.ResultGetErrorMessageS(scr)}");
{
SourceLanguage = SourceLanguage.Glsl,
TargetSpirVVersion = new SpirVVersion(1, 5),
};
}
options.SetTargetEnvironment(TargetEnvironment.Vulkan, EnvironmentVersion.Vulkan_1_2);
Compiler compiler = new(options);
var scr = compiler.Compile(glsl, "Ryu", GetShaderCShaderStage(stage));
lock (_shaderOptionsLock)
{
options.Dispose();
}
if (scr.Status != Status.Success)
{
Logger.Error?.Print(LogClass.Gpu, $"Shader compilation error: {scr.Status} {scr.ErrorMessage}");
return null; return null;
} }
var spirvBytes = new Span<byte>((void*)scr.CodePointer, (int)scr.CodeLength); var spirvBytes = new Span<byte>(api.ResultGetBytes(scr), (int)api.ResultGetLength(scr));
byte[] code = new byte[(scr.CodeLength + 3) & ~3]; byte[] code = new byte[(spirvBytes.Length + 3) & ~3];
spirvBytes.CopyTo(code.AsSpan()[..(int)scr.CodeLength]); spirvBytes.CopyTo(code.AsSpan()[..spirvBytes.Length]);
api.CompilerRelease(compiler);
api.CompileOptionsRelease(options);
return code; return code;
} }