Move ShaderCompiler to D3D12 generator

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-17 01:55:16 +02:00
1 親 27596e26f5
コミット 976e40268c
4ファイル変更
+15 -23

検索条件に一致するファイルはありません

+2 -2
ファイルの表示
@@ -7,10 +7,10 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using ComputeSharp.Shaders.Translation;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
using ComputeSharp.SourceGenerators.Dxc;
using ComputeSharp.SourceGenerators.Models;
using Microsoft.CodeAnalysis;
using TerraFX.Interop.DirectX;
@@ -63,7 +63,7 @@ partial class ComputeShaderDescriptorGenerator
token.ThrowIfCancellationRequested();
// Compile the shader bytecode
using ComPtr<IDxcBlob> dxcBlobBytecode = ShaderCompiler.Instance.Compile(key.HlslSource.AsSpan());
using ComPtr<IDxcBlob> dxcBlobBytecode = DxcShaderCompiler.Instance.Compile(key.HlslSource.AsSpan());
token.ThrowIfCancellationRequested();
-2
ファイルの表示
@@ -68,8 +68,6 @@
<Compile Include="..\ComputeSharp\Core\Interfaces\IComputeShader.cs" Link="ComputeSharp\Core\Interfaces\IComputeShader.cs" />
<Compile Include="..\ComputeSharp\Core\Interfaces\IComputeShader{TPixel}.cs" Link="ComputeSharp\Core\Interfaces\IComputeShader{TPixel}.cs" />
<Compile Include="..\ComputeSharp\Graphics\Extensions\Interop\ComPtrExtensions.cs" Link="ComputeSharp\Graphics\Extensions\Interop\ComPtrExtensions.cs" />
<Compile Include="..\ComputeSharp.Dynamic\Shaders\Exceptions\DxcCompilationException.cs" Link="ComputeSharp\Shaders\Exceptions\DxcCompilationException.cs" />
<Compile Include="..\ComputeSharp.Dynamic\Shaders\Translation\ShaderCompiler.cs" Link="ComputeSharp\Shaders\Translation\ShaderCompiler.cs" />
</ItemGroup>
<ItemGroup>
@@ -1,11 +1,11 @@
using System;
namespace ComputeSharp;
namespace ComputeSharp.SourceGenerators.Dxc;
/// <summary>
/// A custom <see cref="Exception"/> type that indicates when a shader compilation with the DXC compiler has failed.
/// </summary>
public sealed class DxcCompilationException : Exception
internal sealed class DxcCompilationException : Exception
{
/// <summary>
/// Creates a new <see cref="DxcCompilationException"/> instance.
@@ -23,14 +23,8 @@ public sealed class DxcCompilationException : Exception
/// <returns>A formatted error message for a new <see cref="DxcCompilationException"/> instance.</returns>
private static string GetExceptionMessage(string error)
{
#if NET6_0_OR_GREATER
ReadOnlySpan<char> message = error.AsSpan().Trim();
#else
string message = error.Trim();
#endif
return
$"""The DXC compiler encountered one or more errors while trying to compile the shader: "{message}". """ +
$"""The DXC compiler encountered one or more errors while trying to compile the shader: "{error.Trim()}". """ +
$"""Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp. """ +
$"""If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.""";
}
@@ -5,19 +5,19 @@ using ComputeSharp.Core.Extensions;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
namespace ComputeSharp.Shaders.Translation;
namespace ComputeSharp.SourceGenerators.Dxc;
/// <summary>
/// A <see langword="class"/> that uses the DXC APIs to compile compute shaders.
/// </summary>
internal sealed unsafe class ShaderCompiler
internal sealed unsafe class DxcShaderCompiler
{
/// <summary>
/// The thread local <see cref="ShaderCompiler"/> instance.
/// The thread local <see cref="DxcShaderCompiler"/> instance.
/// This is necessary because the DXC library is strictly single-threaded.
/// </summary>
[ThreadStatic]
private static ShaderCompiler? instance;
private static DxcShaderCompiler? instance;
/// <summary>
/// The <see cref="IDxcCompiler"/> instance to use to create the bytecode for HLSL sources.
@@ -35,9 +35,9 @@ internal sealed unsafe class ShaderCompiler
private readonly ComPtr<IDxcIncludeHandler> dxcIncludeHandler;
/// <summary>
/// Creates a new <see cref="ShaderCompiler"/> instance.
/// Creates a new <see cref="DxcShaderCompiler"/> instance.
/// </summary>
private ShaderCompiler()
private DxcShaderCompiler()
{
using ComPtr<IDxcCompiler> dxcCompiler = default;
using ComPtr<IDxcLibrary> dxcLibrary = default;
@@ -61,9 +61,9 @@ internal sealed unsafe class ShaderCompiler
}
/// <summary>
/// Destroys the current <see cref="ShaderCompiler"/> instance.
/// Destroys the current <see cref="DxcShaderCompiler"/> instance.
/// </summary>
~ShaderCompiler()
~DxcShaderCompiler()
{
this.dxcCompiler.Dispose();
this.dxcLibrary.Dispose();
@@ -71,9 +71,9 @@ internal sealed unsafe class ShaderCompiler
}
/// <summary>
/// Gets a <see cref="ShaderCompiler"/> instance to use.
/// Gets a <see cref="DxcShaderCompiler"/> instance to use.
/// </summary>
public static ShaderCompiler Instance => instance ??= new();
public static DxcShaderCompiler Instance => instance ??= new();
/// <summary>
/// Compiles a new HLSL shader from the input source code.