Update ID2D1Shader interface and generator
このコミットが含まれているのは:
1 親
01b32fd0ad
コミット
8edc54748f
8ファイル変更
+28
-22
検索条件に一致するファイルはありません
+12
-5
@@ -16,18 +16,25 @@ partial class ID2D1ShaderGenerator
|
||||
/// <summary>
|
||||
/// Creates a <see cref="PropertyDeclarationSyntax"/> instance for the <c>EffectDisplayName</c> property.
|
||||
/// </summary>
|
||||
/// <param name="effectDisplayName">The input effect display name value.</param>
|
||||
/// <param name="effectDisplayName">The input effect display name value, if available.</param>
|
||||
/// <returns>The resulting <see cref="PropertyDeclarationSyntax"/> instance for the <c>EffectDisplayName</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetSyntax(string effectDisplayName)
|
||||
public static PropertyDeclarationSyntax GetSyntax(string? effectDisplayName)
|
||||
{
|
||||
// Get the expression: either a string literal, or just null
|
||||
ExpressionSyntax displayNameExpression = effectDisplayName switch
|
||||
{
|
||||
{ } => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(effectDisplayName)),
|
||||
_ => LiteralExpression(SyntaxKind.NullLiteralExpression)
|
||||
};
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly string global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectDisplayName => "<EFFECT_DISPLAY_NAME>";
|
||||
// readonly string? global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectDisplayName => <EFFECT_DISPLAY_NAME>;
|
||||
return
|
||||
PropertyDeclaration(PredefinedType(Token(SyntaxKind.StringKeyword)), Identifier(nameof(EffectDisplayName)))
|
||||
PropertyDeclaration(NullableType(PredefinedType(Token(SyntaxKind.StringKeyword))), Identifier(nameof(EffectDisplayName)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithExpressionBody(ArrowExpressionClause(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(effectDisplayName))))
|
||||
.WithExpressionBody(ArrowExpressionClause(displayNameExpression))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
@@ -18,15 +17,15 @@ partial class ID2D1ShaderGenerator
|
||||
/// </summary>
|
||||
/// <param name="compilation">The input <see cref="Compilation"/> object currently in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for the shader type in use.</param>
|
||||
/// <returns>The resulting effect display name.</returns>
|
||||
public static string GetInfo(Compilation compilation, INamedTypeSymbol structDeclarationSymbol)
|
||||
/// <returns>The resulting effect display name, if available.</returns>
|
||||
public static string? GetInfo(Compilation compilation, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
if (TryGetDefinedEffectDisplayName(compilation, structDeclarationSymbol, out string? effectDisplayName))
|
||||
{
|
||||
return effectDisplayName;
|
||||
}
|
||||
|
||||
return structDeclarationSymbol.GetFullyQualifiedMetadataName();
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -58,7 +58,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// EffectDisplayName info
|
||||
string effectDisplayName = EffectDisplayName.GetInfo(context.SemanticModel.Compilation, typeSymbol);
|
||||
string? effectDisplayName = EffectDisplayName.GetInfo(context.SemanticModel.Compilation, typeSymbol);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -149,7 +149,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
.Select(static (item, _) => item.Diagnostcs));
|
||||
|
||||
// Get the EffectDisplayName info (hierarchy and effect display name)
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, string EffectDisplayName)> effectDisplayNameInfo =
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, string? EffectDisplayName)> effectDisplayNameInfo =
|
||||
shaderInfoWithErrors
|
||||
.Select(static (item, _) => (item.Hierarchy, item.EffectDisplayName));
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// </summary>
|
||||
/// <param name="Hierarchy">The hierarchy info for the shader type.</param>
|
||||
/// <param name="EffectId">The effect id info for the shader type.</param>
|
||||
/// <param name="EffectDisplayName">The effect display name for the shader type.</param>
|
||||
/// <param name="EffectDisplayName">The effect display name for the shader type, if available.</param>
|
||||
/// <param name="DispatchData">The gathered shader dispatch data.</param>
|
||||
/// <param name="InputTypes">The gathered input types for the shader.</param>
|
||||
/// <param name="ResourceTextureDescriptions">The gathered resource texture descriptions for the shader.</param>
|
||||
@@ -20,7 +20,7 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
internal sealed record D2D1ShaderInfo(
|
||||
HierarchyInfo Hierarchy,
|
||||
EffectIdInfo EffectId,
|
||||
string EffectDisplayName,
|
||||
string? EffectDisplayName,
|
||||
DispatchDataInfo DispatchData,
|
||||
InputTypesInfo InputTypes,
|
||||
ResourceTextureDescriptionsInfo ResourceTextureDescriptions,
|
||||
|
||||
@@ -20,12 +20,12 @@ public interface ID2D1Shader
|
||||
ref readonly Guid EffectId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display name of the D2D effect using this shader.
|
||||
/// Gets the display name of the D2D effect using this shader, if specified.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
|
||||
/// </remarks>
|
||||
string EffectDisplayName { get; }
|
||||
string? EffectDisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the current shader from a buffer with the serialized dispatch data.
|
||||
|
||||
@@ -32,11 +32,11 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the effect display name of the D2D effect using this shader.
|
||||
/// Gets the effect display name of the D2D effect using this shader, if available.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader to get the effect id for.</typeparam>
|
||||
/// <returns>The effect display name of the D2D effect using <typeparamref name="T"/> shaders.</returns>
|
||||
public static string GetEffectDisplayName<T>()
|
||||
/// <returns>The effect display name of the D2D effect using <typeparamref name="T"/> shaders, if available.</returns>
|
||||
public static string? GetEffectDisplayName<T>()
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
@@ -71,7 +71,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
<Effect>
|
||||
<Property name='DisplayName' type='string' value='
|
||||
""");
|
||||
writer.WriteRaw(GetEffectDisplayName<T>());
|
||||
writer.WriteRaw(GetEffectDisplayName<T>().AsSpan());
|
||||
writer.WriteRaw("""
|
||||
'/>
|
||||
<Property name='Author' type='string' value='ComputeSharp.D2D1'/>
|
||||
@@ -311,7 +311,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
<Effect>
|
||||
<Property name='DisplayName' type='string' value='
|
||||
"""u8);
|
||||
writer.WriteAsUtf8(GetEffectDisplayName<T>());
|
||||
writer.WriteAsUtf8(GetEffectDisplayName<T>() ?? "");
|
||||
writer.WriteRaw("""
|
||||
'/>
|
||||
<Property name='Author' type='string' value='ComputeSharp.D2D1'/>
|
||||
|
||||
@@ -46,7 +46,7 @@ public partial class D2D1EffectRegistrationDataTests
|
||||
Assert.AreEqual("""
|
||||
<?xml version='1.0'?>
|
||||
<Effect>
|
||||
<Property name='DisplayName' type='string' value='ComputeSharp.D2D1.Tests.D2D1EffectRegistrationDataTests+TestRegistrationBlobShader'/>
|
||||
<Property name='DisplayName' type='string' value=''/>
|
||||
<Property name='Author' type='string' value='ComputeSharp.D2D1'/>
|
||||
<Property name='Category' type='string' value='Stylize'/>
|
||||
<Property name='Description' type='string' value='A custom D2D1 effect using a pixel shader'/>
|
||||
|
||||
@@ -228,7 +228,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
[TestMethod]
|
||||
public unsafe void DefaultEffectDisplayName_MatchesValue()
|
||||
{
|
||||
Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName<ShaderWithDefaultEffectDisplayName>(), typeof(ShaderWithDefaultEffectDisplayName).FullName);
|
||||
Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName<ShaderWithDefaultEffectDisplayName>(), null);
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする