Switched from DotNetDxc to Vortice.Dxc
このコミットが含まれているのは:
1 親
20166ff27e
コミット
c63c11366a
2ファイル変更
+7
-63
検索条件に一致するファイルはありません
@@ -8,24 +8,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetDxc" Version="1.2.0-alpha">
|
||||
<ExcludeAssets>native</ExcludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="ICSharpCode.Decompiler" Version="5.0.0.5066-preview4" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.0-beta2-final" />
|
||||
<PackageReference Include="Stubble.Core" Version="1.4.12" />
|
||||
<PackageReference Include="Vortice.Dxc" Version="1.0.0-gcdd75d017a" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputeSharp.Graphics\ComputeSharp.Graphics.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\..\lib\win-x64\*.*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Renderer\Templates\ShaderTemplate.mustache">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using DotNetDxc;
|
||||
using Vortice.DirectX.Direct3D12;
|
||||
using Vortice.Dxc;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that uses the <see cref="HlslDxcLib"/> APIs to compile compute shaders
|
||||
/// A <see langword="class"/> that uses the <see cref="DxcCompiler"/> APIs to compile compute shaders
|
||||
/// </summary>
|
||||
internal sealed class ShaderCompiler
|
||||
{
|
||||
@@ -15,25 +15,10 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
public static ShaderCompiler Instance { get; } = new ShaderCompiler();
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IDxcCompiler"/> instance to use to create new HLSL shaders
|
||||
/// </summary>
|
||||
private readonly IDxcCompiler Compiler;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IDxcLibrary"/> instance to use to create the bytecode for HLSL sources
|
||||
/// </summary>
|
||||
private readonly IDxcLibrary Library;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderCompiler"/> instance
|
||||
/// </summary>
|
||||
private ShaderCompiler()
|
||||
{
|
||||
HlslDxcLib.DxcCreateInstanceFn = DefaultDxcLib.GetDxcCreateInstanceFn();
|
||||
Compiler = HlslDxcLib.CreateDxcCompiler();
|
||||
Library = HlslDxcLib.CreateDxcLibrary();
|
||||
}
|
||||
private readonly IDxcLibrary Library = Dxc.CreateDxcLibrary();
|
||||
|
||||
/// <summary>
|
||||
/// Compiles a new HLSL shader from the input source code
|
||||
@@ -43,53 +28,20 @@ namespace ComputeSharp.Shaders.Translation
|
||||
[Pure]
|
||||
public ShaderBytecode CompileShader(string source)
|
||||
{
|
||||
const uint CP_UTF16 = 1200;
|
||||
|
||||
IDxcBlobEncoding sourceBlob = Library.CreateBlobWithEncodingOnHeapCopy(source, (uint)(source.Length * 2), CP_UTF16);
|
||||
IDxcOperationResult result = Compiler.Compile(sourceBlob, "", "CSMain", "cs_6_1", new[] { "-Zpr" }, 1, null, 0, Library.CreateIncludeHandler());
|
||||
var result = DxcCompiler.Compile(DxcShaderStage.ComputeShader, source, "Main", string.Empty, new DxcCompilerOptions { ShaderModel = DxcShaderModel.Model6_1 });
|
||||
|
||||
// Get the compiled bytecode in case of success
|
||||
if (result.GetStatus() == 0)
|
||||
{
|
||||
IDxcBlob blob = result.GetResult();
|
||||
byte[] bytecode = GetBytesFromBlob(blob);
|
||||
byte[] bytecode = Dxc.GetBytesFromBlob(blob);
|
||||
|
||||
return bytecode;
|
||||
}
|
||||
|
||||
// Compile error
|
||||
string resultText = GetStringFromBlob(Library, result.GetErrors());
|
||||
string resultText = Dxc.GetStringFromBlob(Library, result.GetErrors());
|
||||
throw new Exception(resultText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the buffer content from an input <see cref="IDxcBlob"/> instance
|
||||
/// </summary>
|
||||
/// <param name="blob">The input <see cref="IDxcBlob"/> instance to read data from</param>
|
||||
/// <returns>The read bytes buffer, as an array</returns>
|
||||
[Pure]
|
||||
private static unsafe byte[] GetBytesFromBlob(IDxcBlob blob)
|
||||
{
|
||||
byte* pMem = (byte*)blob.GetBufferPointer();
|
||||
uint size = blob.GetBufferSize();
|
||||
byte[] result = new byte[size];
|
||||
|
||||
new Span<byte>(pMem, (int)size).CopyTo(result.AsSpan());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a <see cref="string"/> value from an input <see cref="IDxcBlob"/> instance
|
||||
/// </summary>
|
||||
/// <param name="library">The source <see cref="IDxcLibrary"/> to use to load the data</param>
|
||||
/// <param name="blob">The input <see cref="IDxcBlob"/> instance to read data from</param>
|
||||
/// <returns>The resulting <see cref="string"/> read from the input data buffer</returns>
|
||||
[Pure]
|
||||
private static unsafe string GetStringFromBlob(IDxcLibrary library, IDxcBlob blob)
|
||||
{
|
||||
blob = library.GetBlobAstUf16(blob);
|
||||
return new string(blob.GetBufferPointer(), 0, (int)(blob.GetBufferSize() / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする