Merge branch 'shaderc' into 'master'

Replace shaderc.net with Silk.NET.Shaderc

See merge request [ryubing/ryujinx!225](https://git.ryujinx.app/ryubing/ryujinx/-/merge_requests/225)
This commit is contained in:
V380-Ori 2025-12-12 15:30:22 -06:00
commit 8e666a2133
3 changed files with 23 additions and 33 deletions

View File

@ -47,8 +47,8 @@
<PackageVersion Include="Gommon" Version="2.8.0.1" />
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
<PackageVersion Include="Sep" Version="0.11.1" />
<PackageVersion Include="shaderc.net" Version="0.1.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Silk.NET.Shaderc" Version="2.22.0" />
<PackageVersion Include="Silk.NET.Vulkan" Version="2.22.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.22.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.22.0" />
@ -59,4 +59,4 @@
<PackageVersion Include="System.Management" Version="9.0.2" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
</ItemGroup>
</Project>
</Project>

View File

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

View File

@ -1,22 +1,17 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader;
using shaderc;
using Silk.NET.Shaderc;
using Silk.NET.Vulkan;
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Result = shaderc.Result;
namespace Ryujinx.Graphics.Vulkan
{
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 Lock _shaderOptionsLock = new();
private static readonly nint _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main");
private readonly Vk _api;
@ -75,38 +70,33 @@ namespace Ryujinx.Graphics.Vulkan
private unsafe static byte[] GlslToSpirv(string glsl, ShaderStage stage)
{
Options options;
Shaderc api = Shaderc.GetApi();
Compiler* compiler = api.CompilerInitialize();
CompileOptions* options = api.CompileOptionsInitialize();
lock (_shaderOptionsLock)
api.CompileOptionsSetSourceLanguage(options, SourceLanguage.Glsl);
api.CompileOptionsSetTargetSpirv(options, SpirvVersion.Shaderc15);
api.CompileOptionsSetTargetEnv(options, TargetEnv.Vulkan, Vk.Version12);
CompilationResult* scr = api.CompileIntoSpv(compiler, glsl, (nuint)glsl.Length, GetShaderCShaderStage(stage), "Ryu", "main", options);
CompilationStatus status = api.ResultGetCompilationStatus(scr);
if (status != CompilationStatus.Success)
{
options = new Options(false)
{
SourceLanguage = SourceLanguage.Glsl,
TargetSpirVVersion = new SpirVVersion(1, 5),
};
}
options.SetTargetEnvironment(TargetEnvironment.Vulkan, EnvironmentVersion.Vulkan_1_2);
Compiler compiler = new(options);
Result 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}");
Logger.Error?.Print(LogClass.Gpu, $"Shader compilation error: {status} {api.ResultGetErrorMessageS(scr)}");
return null;
}
Span<byte> spirvBytes = new((void*)scr.CodePointer, (int)scr.CodeLength);
Span<byte> spirvBytes = new(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;
}