diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs index adcd069d..e6aed98c 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs @@ -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 dxcBlobBytecode = ShaderCompiler.Instance.Compile(key.HlslSource.AsSpan()); + using ComPtr dxcBlobBytecode = DxcShaderCompiler.Instance.Compile(key.HlslSource.AsSpan()); token.ThrowIfCancellationRequested(); diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 35b85d5a..4ab06edc 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -68,8 +68,6 @@ - - diff --git a/src/ComputeSharp.Dynamic/Shaders/Exceptions/DxcCompilationException.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcCompilationException.cs similarity index 82% rename from src/ComputeSharp.Dynamic/Shaders/Exceptions/DxcCompilationException.cs rename to src/ComputeSharp.SourceGenerators/Dxc/DxcCompilationException.cs index 7aa7ee72..7b690b9e 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Exceptions/DxcCompilationException.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcCompilationException.cs @@ -1,11 +1,11 @@ using System; -namespace ComputeSharp; +namespace ComputeSharp.SourceGenerators.Dxc; /// /// A custom type that indicates when a shader compilation with the DXC compiler has failed. /// -public sealed class DxcCompilationException : Exception +internal sealed class DxcCompilationException : Exception { /// /// Creates a new instance. @@ -23,14 +23,8 @@ public sealed class DxcCompilationException : Exception /// A formatted error message for a new instance. private static string GetExceptionMessage(string error) { -#if NET6_0_OR_GREATER - ReadOnlySpan 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."""; } diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs similarity index 91% rename from src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs rename to src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs index 7376f484..1bad772f 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs @@ -5,19 +5,19 @@ using ComputeSharp.Core.Extensions; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; -namespace ComputeSharp.Shaders.Translation; +namespace ComputeSharp.SourceGenerators.Dxc; /// /// A that uses the DXC APIs to compile compute shaders. /// -internal sealed unsafe class ShaderCompiler +internal sealed unsafe class DxcShaderCompiler { /// - /// The thread local instance. + /// The thread local instance. /// This is necessary because the DXC library is strictly single-threaded. /// [ThreadStatic] - private static ShaderCompiler? instance; + private static DxcShaderCompiler? instance; /// /// The instance to use to create the bytecode for HLSL sources. @@ -35,9 +35,9 @@ internal sealed unsafe class ShaderCompiler private readonly ComPtr dxcIncludeHandler; /// - /// Creates a new instance. + /// Creates a new instance. /// - private ShaderCompiler() + private DxcShaderCompiler() { using ComPtr dxcCompiler = default; using ComPtr dxcLibrary = default; @@ -61,9 +61,9 @@ internal sealed unsafe class ShaderCompiler } /// - /// Destroys the current instance. + /// Destroys the current instance. /// - ~ShaderCompiler() + ~DxcShaderCompiler() { this.dxcCompiler.Dispose(); this.dxcLibrary.Dispose(); @@ -71,9 +71,9 @@ internal sealed unsafe class ShaderCompiler } /// - /// Gets a instance to use. + /// Gets a instance to use. /// - public static ShaderCompiler Instance => instance ??= new(); + public static DxcShaderCompiler Instance => instance ??= new(); /// /// Compiles a new HLSL shader from the input source code.