Added custom DXC/DXIL libraries resolver
このコミットが含まれているのは:
1 親
41e9af11e7
コミット
604ca2fea7
2ファイル変更
+24
-1
検索条件に一致するファイルはありません
@@ -7,7 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Toolkit" Version="7.0.0-preview4" />
|
||||
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.19041-beta2-379749354" />
|
||||
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.19041-beta2-449553204" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Exceptions;
|
||||
using TerraFX.Interop;
|
||||
@@ -34,6 +37,8 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
static ShaderCompiler()
|
||||
{
|
||||
FX.ResolveLibrary += ResolveLibrary;
|
||||
|
||||
using ComPtr<IDxcCompiler> dxcCompiler = default;
|
||||
using ComPtr<IDxcLibrary> dxcLibrary = default;
|
||||
using ComPtr<IDxcIncludeHandler> dxcIncludeHandler = default;
|
||||
@@ -51,6 +56,24 @@ namespace ComputeSharp.Shaders.Translation
|
||||
DxcIncludeHandler = dxcIncludeHandler.Move();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom resolver to override the default library resolution behavior for the DXC and DXIL libraries.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="DllImportResolver"/>
|
||||
private static IntPtr ResolveLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
||||
{
|
||||
if (libraryName != "dxcompiler" && libraryName != "dxil") return IntPtr.Zero;
|
||||
|
||||
string libraryPath = Path.GetFullPath(@$"runtimes\win-x64\native\{libraryName}.dll");
|
||||
|
||||
if (NativeLibrary.TryLoad(libraryPath, out IntPtr handle))
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compiles a new HLSL shader from the input source code.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする