mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-12-23 12:36:25 +00:00
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:
commit
8e666a2133
@ -47,8 +47,8 @@
|
|||||||
<PackageVersion Include="Gommon" Version="2.8.0.1" />
|
<PackageVersion Include="Gommon" Version="2.8.0.1" />
|
||||||
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
|
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
|
||||||
<PackageVersion Include="Sep" Version="0.11.1" />
|
<PackageVersion Include="Sep" Version="0.11.1" />
|
||||||
<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.22.0" />
|
||||||
<PackageVersion Include="Silk.NET.Vulkan" 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.EXT" Version="2.22.0" />
|
||||||
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.22.0" />
|
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.22.0" />
|
||||||
|
|||||||
@ -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" ExcludeAssets="native" />
|
||||||
<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" />
|
||||||
|
|||||||
@ -1,22 +1,17 @@
|
|||||||
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;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Result = shaderc.Result;
|
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Vulkan
|
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 Lock _shaderOptionsLock = new();
|
|
||||||
|
|
||||||
private static readonly nint _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main");
|
private static readonly nint _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main");
|
||||||
|
|
||||||
private readonly Vk _api;
|
private readonly Vk _api;
|
||||||
@ -75,38 +70,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;
|
Shaderc api = Shaderc.GetApi();
|
||||||
|
Compiler* compiler = api.CompilerInitialize();
|
||||||
|
CompileOptions* options = api.CompileOptionsInitialize();
|
||||||
|
|
||||||
lock (_shaderOptionsLock)
|
api.CompileOptionsSetSourceLanguage(options, SourceLanguage.Glsl);
|
||||||
{
|
api.CompileOptionsSetTargetSpirv(options, SpirvVersion.Shaderc15);
|
||||||
options = new Options(false)
|
api.CompileOptionsSetTargetEnv(options, TargetEnv.Vulkan, Vk.Version12);
|
||||||
{
|
|
||||||
SourceLanguage = SourceLanguage.Glsl,
|
|
||||||
TargetSpirVVersion = new SpirVVersion(1, 5),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
options.SetTargetEnvironment(TargetEnvironment.Vulkan, EnvironmentVersion.Vulkan_1_2);
|
CompilationResult* scr = api.CompileIntoSpv(compiler, glsl, (nuint)glsl.Length, GetShaderCShaderStage(stage), "Ryu", "main", options);
|
||||||
Compiler compiler = new(options);
|
|
||||||
Result scr = compiler.Compile(glsl, "Ryu", GetShaderCShaderStage(stage));
|
|
||||||
|
|
||||||
lock (_shaderOptionsLock)
|
CompilationStatus status = api.ResultGetCompilationStatus(scr);
|
||||||
{
|
|
||||||
options.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scr.Status != Status.Success)
|
if (status != CompilationStatus.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;
|
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;
|
return code;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user