diff --git a/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs b/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs
new file mode 100644
index 00000000..13a95b6d
--- /dev/null
+++ b/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Diagnostics.Contracts;
+using System.Text;
+
+namespace ComputeSharp.Exceptions
+{
+ ///
+ /// A custom that indicates when mismatched devices are being used
+ ///
+ public sealed class HlslCompilationException : Exception
+ {
+ ///
+ /// Creates a new instance
+ ///
+ /// The error message produced by the Dxc compiler
+ internal HlslCompilationException(string error) : base(GetExceptionMessage(error)) { }
+
+ // Gets a proper exception message for a given compilation error
+ [Pure]
+ private static string GetExceptionMessage(string error)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.Append("The Dxc compiler encountered an error while trying to compile the shader.");
+ builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
+ builder.AppendLine("If you're sure that your C# shader code is valid, please open an issue an include a working repro and the following error message:");
+ builder.AppendLine(error.TrimEnd());
+
+ return builder.ToString();
+ }
+ }
+}
diff --git a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs
index 0cedbcaf..ec7b9c0c 100644
--- a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs
+++ b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs
@@ -1,5 +1,5 @@
-using System;
-using System.Diagnostics.Contracts;
+using System.Diagnostics.Contracts;
+using ComputeSharp.Exceptions;
using Vortice.Direct3D12;
using Vortice.Dxc;
@@ -43,7 +43,7 @@ namespace ComputeSharp.Shaders.Translation
// Compile error
string resultText = Dxc.GetStringFromBlob(Library, result.GetErrors());
- throw new Exception(resultText);
+ throw new HlslCompilationException(resultText);
}
}
}