diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs
index e5d9b082..e6338f55 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs
@@ -14,23 +14,38 @@ partial class ID2D1ShaderGenerator
partial class GetPixelOptions
{
///
- /// Creates a instance for the GetPixelOptions method.
+ /// Creates a instance for the PixelOptions property.
///
/// The pixel options for the shader.
- /// The resulting instance for the GetPixelOptions method.
- public static MethodDeclarationSyntax GetSyntax(D2D1PixelOptions pixelOptions)
+ /// The resulting instance for the PixelOptions property.
+ public static PropertyDeclarationSyntax GetSyntax(D2D1PixelOptions pixelOptions)
{
- // This code produces a method declaration as follows:
+ ExpressionSyntax pixelOptionsExpression;
+
+ // Set the right expression if the pixel options are valid
+ if (pixelOptions is D2D1PixelOptions.None or D2D1PixelOptions.TrivialSampling)
+ {
+ pixelOptionsExpression =
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("ComputeSharp.D2D1.D2D1PixelOptions"),
+ IdentifierName(pixelOptions.ToString()));
+ }
+ else
+ {
+ // Otherwise just return default (the analyzer will emit a diagnostic)
+ pixelOptionsExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
+ }
+
+ // This code produces a property declaration as follows:
//
- // readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetPixelOptions()
- // {
- // return ;
- // }
+ // readonly ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.__Internals.ID2D1Shader.PixelOptions => ;
return
- MethodDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)), Identifier(nameof(GetPixelOptions)))
+ PropertyDeclaration(IdentifierName("ComputeSharp.D2D1.D2D1PixelOptions"), Identifier("PixelOptions"))
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
- .WithBody(Block(ReturnStatement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)pixelOptions)))));
+ .WithExpressionBody(ArrowExpressionClause(pixelOptionsExpression))
+ .WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
}
}
}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
index a9b53915..5f779817 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
@@ -423,8 +423,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
// Generate the GetPixelOptions() methods
context.RegisterSourceOutput(pixelOptionsInfo, static (context, item) =>
{
- MethodDeclarationSyntax getPixelOptionsMethod = GetPixelOptions.GetSyntax(item.PixelOptions);
- CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, getPixelOptionsMethod, canUseSkipLocalsInit: false);
+ PropertyDeclarationSyntax pixelOptionsProperty = GetPixelOptions.GetSyntax(item.PixelOptions);
+ CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, pixelOptionsProperty, canUseSkipLocalsInit: false);
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetPixelOptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
});
diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
index ef33bcde..0dc9676b 100644
--- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
+++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
@@ -64,10 +64,9 @@ public interface ID2D1Shader
///
/// Gets the pixel options for the current shader.
///
- /// The pixel options for the current shader.
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
- uint GetPixelOptions();
+ D2D1PixelOptions PixelOptions { get; }
///
/// Gets the number of inputs for the current shader.
diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs
index c10cb2b1..5bd65dff 100644
--- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs
+++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs
@@ -242,7 +242,7 @@ public static class D2D1PixelShader
{
Unsafe.SkipInit(out T shader);
- return (D2D1PixelOptions)shader.GetPixelOptions();
+ return shader.PixelOptions;
}
///