Capture D2D1CompileOptions in source generator

このコミットが含まれているのは:
Sergio Pedri committed 2022-05-22 01:40:09 +02:00
1 親 77c43a819e
コミット 0bfe836a4e
5ファイル変更
+52 -1

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

+1
ファイルの表示
@@ -50,3 +50,4 @@ CMPSD2D0040 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
CMPSD2D0041 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0042 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0043 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0044 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+16
ファイルの表示
@@ -618,4 +618,20 @@ internal static class DiagnosticDescriptors
isEnabledByDefault: true,
description: "A D2D1 shader must only have unique indices for all of its [D2DInputDescription] attributes.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for the PackMatrixColumnMajor option being used.
/// <para>
/// Format: <c>"The D2D1 shader of type {0} is using the PackMatrixColumnMajor option in its [D2DCompileOptions] attribute"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor InvalidPackMatrixColumnMajorOption = new DiagnosticDescriptor(
id: "CMPSD2D0044",
title: "Invalid PackMatrixColumnMajor compile option",
messageFormat: "The D2D1 shader of type {0} is using the PackMatrixColumnMajor option in its [D2DCompileOptions] attribute",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A D2D1 shader generated with ComputeSharp.D2D1 cannot use the PackMatrixColumnMajor option, as that is not compatible with the generated code used to load shader constant buffers.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
@@ -41,6 +41,32 @@ partial class ID2D1ShaderGenerator
return null;
}
/// <summary>
/// Extracts the compile options for the current shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> 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, INamedTypeSymbol structDeclarationSymbol)
{
if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
D2D1CompileOptions options = (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!;
if ((options & D2D1CompileOptions.PackMatrixColumnMajor) != 0)
{
diagnostics.Add(
InvalidPackMatrixColumnMajorOption,
structDeclarationSymbol,
structDeclarationSymbol);
}
return options;
}
return null;
}
/// <summary>
/// Extracts the metadata definition for the current shader.
/// </summary>
+2
ファイルの表示
@@ -93,11 +93,13 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
// Get the shader profile and linking info for LoadBytecode()
D2D1ShaderProfile? shaderProfile = LoadBytecode.GetShaderProfile(item.Left.Symbol);
D2D1CompileOptions? compileOptions = LoadBytecode.GetCompileOptions(diagnostics, item.Left.Symbol);
bool isLinkingSupported = diagnostics.Count == 0 && LoadBytecode.IsSimpleInputShader(item.Left.Symbol, inputCount);
HlslShaderSourceInfo sourceInfo = new(
hlslSource,
shaderProfile,
compileOptions,
isLinkingSupported,
diagnostics.Count > 0);
+7 -1
ファイルの表示
@@ -5,6 +5,12 @@
/// </summary>
/// <param name="HlslSource">The HLSL source.</param>
/// <param name="ShaderProfile">The shader profile to use to compile the shader, if requested.</param>
/// <param name="CompileOptions">The compile options to use to compile the shader.</param>
/// <param name="IsLinkingSupported">Whether the shader supports linking.</param>
/// <param name="HasErrors">Whether any errors have been detected, and therefore the shader compilation should be skipped.</param>
internal sealed record HlslShaderSourceInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, bool IsLinkingSupported, bool HasErrors);
internal sealed record HlslShaderSourceInfo(
string HlslSource,
D2D1ShaderProfile? ShaderProfile,
D2D1CompileOptions? CompileOptions,
bool IsLinkingSupported,
bool HasErrors);