Add diagnostics for [D2DPixelShaderSource]

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-18 14:26:09 +02:00
1 親 51f2642e80
コミット c998002f90
6ファイル変更
+121 -27

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

+5
ファイルの表示
@@ -58,3 +58,8 @@ CMPSD2D0048 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
CMPSD2D0049 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0050 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0051 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0052 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0053 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0054 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0055 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0056 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+28 -19
ファイルの表示
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using ComputeSharp.D2D1.Exceptions;
using ComputeSharp.D2D1.Shaders.Translation;
@@ -12,11 +9,9 @@ using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
namespace ComputeSharp.D2D1.SourceGenerators;
@@ -34,16 +29,20 @@ partial class D2DPixelShaderSourceGenerator
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="methodSymbol">The input <see cref="IMethodSymbol"/> instance to process.</param>
/// <returns>The HLSL source to compile, if present.</returns>
public static string? GetHlslSource(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
public static string GetHlslSource(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
{
_ = methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DPixelShaderSourceAttribute", out AttributeData? attributeData);
if (!attributeData!.TryGetConstructorArgument(0, out string? hlslSource))
{
// TODO: no string diagnostic
diagnostics.Add(
InvalidD2DPixelShaderSource,
methodSymbol,
methodSymbol.Name,
methodSymbol.ContainingType);
}
return hlslSource;
return hlslSource ?? "";
}
/// <summary>
@@ -52,7 +51,7 @@ partial class D2DPixelShaderSourceGenerator
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="methodSymbol">The input <see cref="IMethodSymbol"/> instance to process.</param>
/// <returns>The shader profile to use to compile the shader, if present.</returns>
public static D2D1ShaderProfile? GetShaderProfile(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
public static D2D1ShaderProfile GetShaderProfile(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
{
if (methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DEmbeddedBytecodeAttribute", out AttributeData? attributeData))
{
@@ -64,9 +63,13 @@ partial class D2DPixelShaderSourceGenerator
return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!;
}
// TODO: diagnostics
diagnostics.Add(
MissingShaderProfileForD2DPixelShaderSource,
methodSymbol,
methodSymbol.Name,
methodSymbol.ContainingType);
return null;
return D2D1ShaderProfile.PixelShader50;
}
/// <summary>
@@ -75,7 +78,7 @@ partial class D2DPixelShaderSourceGenerator
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="methodSymbol">The input <see cref="IMethodSymbol"/> instance to process.</param>
/// <returns>The compile options to use to compile the shader, if present.</returns>
public static D2D1CompileOptions? GetCompileOptions(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
public static D2D1CompileOptions GetCompileOptions(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
{
if (methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
@@ -87,9 +90,13 @@ partial class D2DPixelShaderSourceGenerator
return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!;
}
// TODO: diagnostics
diagnostics.Add(
MissingCompileOptionsForD2DPixelShaderSource,
methodSymbol,
methodSymbol.Name,
methodSymbol.ContainingType);
return null;
return D2D1CompileOptions.Default;
}
/// <summary>
@@ -118,8 +125,8 @@ partial class D2DPixelShaderSourceGenerator
// Compile the shader bytecode using the requested parameters
using ComPtr<ID3DBlob> dxcBlobBytecode = D3DCompiler.Compile(
sourceInfo.HlslSource.AsSpan(),
sourceInfo.ShaderProfile!.Value,
sourceInfo.CompileOptions!.Value);
sourceInfo.ShaderProfile,
sourceInfo.CompileOptions);
token.ThrowIfCancellationRequested();
@@ -134,14 +141,16 @@ partial class D2DPixelShaderSourceGenerator
catch (Win32Exception e)
{
diagnostic = new DiagnosticInfo(
null!, // TODO
D2DPixelShaderSourceCompilationFailedWithWin32Exception,
sourceInfo.MethodName,
e.HResult,
ID2D1ShaderGenerator.LoadBytecode.FixupExceptionMessage(e.Message));
}
catch (FxcCompilationException e)
{
diagnostic = new DiagnosticInfo(
null!, // TODO
D2DPixelShaderSourceCompilationFailedWithFxcCompilationException,
sourceInfo.MethodName,
ID2D1ShaderGenerator.LoadBytecode.FixupExceptionMessage(e.Message));
}
+3 -3
ファイルの表示
@@ -41,9 +41,9 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
// Get all necessary info for the current shader
ImmutableArray<SyntaxKind> modifiers = item.Syntax.Modifiers.Select(token => token.Kind()).ToImmutableArray();
string methodName = item.Symbol.Name;
string? hlslSource = Execute.GetHlslSource(diagnostics, item.Symbol) ?? "";
D2D1ShaderProfile? shaderProfile = Execute.GetShaderProfile(diagnostics, item.Symbol);
D2D1CompileOptions? compileOptions = Execute.GetCompileOptions(diagnostics, item.Symbol);
string hlslSource = Execute.GetHlslSource(diagnostics, item.Symbol);
D2D1ShaderProfile shaderProfile = Execute.GetShaderProfile(diagnostics, item.Symbol);
D2D1CompileOptions compileOptions = Execute.GetCompileOptions(diagnostics, item.Symbol);
HlslShaderMethodSourceInfo sourceInfo = new(
modifiers,
+81 -1
ファイルの表示
@@ -463,7 +463,7 @@ partial class DiagnosticDescriptors
/// Format: <c>"The shader of type {0} failed to compile due to an HLSL compiler error (Message: "{1}")"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithDxcCompilationException = new DiagnosticDescriptor(
public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithFxcCompilationException = new DiagnosticDescriptor(
id: "CMPSD2D0034",
title: "Embedded bytecode compilation failed due to an HLSL compiler error",
messageFormat: "The shader of type {0} failed to compile due to an HLSL compiler error (Message: \"{1}\")",
@@ -744,4 +744,84 @@ partial class DiagnosticDescriptors
isEnabledByDefault: true,
description: "The element type of D2D1 resource texture fields in a D2D1 shader must be either float or float4.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid HLSL source in <c>[D2DPixelShaderSource]</c>.
/// <para>
/// Format: <c>"The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor InvalidD2DPixelShaderSource = new DiagnosticDescriptor(
id: "CMPSD2D0052",
title: "Invalid [D2DPixelShaderSource] HLSL source argument",
messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Methods using [D2DPixelShaderSource] must pass a valid string as the HLSL source argument.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an embedded bytecode D2D shader failed due to a Win32 exception.
/// <para>
/// Format: <c>"Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: \"{3}\")"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor D2DPixelShaderSourceCompilationFailedWithWin32Exception = new DiagnosticDescriptor(
id: "CMPSD2D0053",
title: "D2D shader compilation failed due to Win32 exception",
messageFormat: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: \"{3}\")",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "The embedded bytecode for an input HLSl source failed to be compiled due to a Win32 exception.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an embedded bytecode D2D shader failed due to an HLSL compilation exception.
/// <para>
/// Format: <c>"Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to an HLSL compiler error (Message: \"{2}\")"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor D2DPixelShaderSourceCompilationFailedWithFxcCompilationException = new DiagnosticDescriptor(
id: "CMPSD2D0054",
title: "D2D shader compilation failed due to an HLSL compiler error",
messageFormat: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to an HLSL compiler error (Message: \"{2}\")",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "The embedded bytecode for an input HLSl source failed to be compiled due to an HLSL compiler error.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an embedded bytecode D2D shader with no shader profile set.
/// <para>
/// Format: <c>"The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor MissingShaderProfileForD2DPixelShaderSource = new DiagnosticDescriptor(
id: "CMPSD2D0055",
title: "Missing shader profile for D2D pixel shader source",
messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Precompiled shaders using [D2DPixelShaderSource] must explicitly indicate the shader profile to use.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an embedded bytecode D2D shader with no compile options set.
/// <para>
/// Format: <c>"The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor MissingCompileOptionsForD2DPixelShaderSource = new DiagnosticDescriptor(
id: "CMPSD2D0056",
title: "Missing compile options for D2D pixel shader source",
messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Precompiled shaders using [D2DPixelShaderSource] must explicitly indicate the compile options.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
@@ -198,7 +198,7 @@ partial class ID2D1ShaderGenerator
catch (FxcCompilationException e)
{
options = default;
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithDxcCompilationException, FixupExceptionMessage(e.Message));
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithFxcCompilationException, FixupExceptionMessage(e.Message));
}
End:
+3 -3
ファイルの表示
@@ -13,15 +13,15 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// <param name="Modifiers">The modifiers for the annotated method.</param>
/// <param name="MethodName">The name of the annotated method.</param>
/// <param name="HlslSource">The HLSL source.</param>
/// <param name="ShaderProfile">The shader profile to use to compile the shader, if requested.</param>
/// <param name="ShaderProfile">The shader profile to use to compile the shader.</param>
/// <param name="CompileOptions">The compile options to use to compile the shader.</param>
/// <param name="HasErrors">Whether any errors have been detected, and therefore the shader compilation should be skipped.</param>
internal sealed record HlslShaderMethodSourceInfo(
ImmutableArray<SyntaxKind> Modifiers,
string MethodName,
string HlslSource,
D2D1ShaderProfile? ShaderProfile,
D2D1CompileOptions? CompileOptions,
D2D1ShaderProfile ShaderProfile,
D2D1CompileOptions CompileOptions,
bool HasErrors)
{
/// <summary>