diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs index 210e2ee1..57183541 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs @@ -205,7 +205,8 @@ partial class D2DPixelShaderDescriptorGenerator using ComPtr d3DBlob = D3DCompiler.Compile( key.HlslSource.AsSpan(), key.ShaderProfile, - key.CompileOptions); + key.CompileOptions, + token); token.ThrowIfCancellationRequested(); diff --git a/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs b/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs index f1ab48c0..873a1990 100644 --- a/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs +++ b/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs @@ -5,6 +5,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; #if SOURCE_GENERATOR +using System.Threading; using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.Graphics.Direct3D; @@ -34,7 +35,17 @@ internal static unsafe partial class D3DCompiler /// The shader profile to use to compile the shader. /// The options to use to compile the shader. /// The bytecode for the compiled shader. - public static ComPtr Compile(ReadOnlySpan source, D2D1ShaderProfile shaderProfile, D2D1CompileOptions options) + public static ComPtr Compile( + ReadOnlySpan source, + D2D1ShaderProfile shaderProfile, +#if SOURCE_GENERATOR +#pragma warning disable CS1573 + D2D1CompileOptions options, + CancellationToken token) // The cancellation token used to cancel the operation. +#pragma warning restore CS1573 +#else + D2D1CompileOptions options) +#endif { int maxLength = Encoding.ASCII.GetMaxByteCount(source.Length); byte[] buffer = ArrayPool.Shared.Rent(maxLength); @@ -58,6 +69,10 @@ internal static unsafe partial class D3DCompiler try { +#if SOURCE_GENERATOR + token.ThrowIfCancellationRequested(); +#endif + // Compile the standalone D2D1 full shader using ComPtr d3DBlobFullShader = Compile( source: buffer.AsSpan(0, writtenBytes), @@ -73,6 +88,10 @@ internal static unsafe partial class D3DCompiler return d3DBlobFullShader.Move(); } +#if SOURCE_GENERATOR + token.ThrowIfCancellationRequested(); +#endif + // Compile the export function using ComPtr d3DBlobFunction = Compile( source: buffer.AsSpan(0, writtenBytes),