diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index ac0ca80d..a7fc292c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -39,7 +39,34 @@ partial class ID2D1ShaderGenerator MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile"), - IdentifierName(bytecodeInfo.ShaderProfile.ToString())))) + IdentifierName(bytecodeInfo.ShaderProfile.ToString(CultureInfo.InvariantCulture))))) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); + } + + /// + /// Creates a instance for the CompileOptions property. + /// + /// The input bytecode info. + /// The resulting instance for the CompileOptions property. + public static PropertyDeclarationSyntax GetCompileOptionsSyntax(EmbeddedBytecodeInfo bytecodeInfo) + { + // Get a formatted representation of the compile options being used + ExpressionSyntax compileOptionsExpression = + ParseExpression( + bytecodeInfo.CompileOptions + .ToString(CultureInfo.InvariantCulture) + .Split(',') + .Select(static name => $"global::ComputeSharp.D2D1.D2D1CompileOptions.{name.Trim()}") + .Aggregate("", static (left, right) => left.Length > 0 ? $"{left} | {right}" : right)); + + // This code produces a method declaration as follows: + // + // readonly ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.__Internals.ID2D1Shader.CompileOptions => ; + return + PropertyDeclaration(IdentifierName("ComputeSharp.D2D1.D2D1CompileOptions"), Identifier(nameof(ID2D1Shader.CompileOptions))) + .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}"))) + .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) + .WithExpressionBody(ArrowExpressionClause(compileOptionsExpression)) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 3368e1d1..f557ce17 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -372,6 +372,11 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator CompilationUnitSyntax shaderProfileCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, shaderProfileProperty, skipLocalsInit: false); context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.ShaderProfile.g.cs", shaderProfileCompilationUnit.GetText(Encoding.UTF8)); + + PropertyDeclarationSyntax compileOptionsProperty = LoadBytecode.GetCompileOptionsSyntax(item.BytecodeInfo); + CompilationUnitSyntax compileOptionsCompilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, compileOptionsProperty, canUseSkipLocalsInit: false); + + context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.CompileOptions.g.cs", compileOptionsCompilationUnit.GetText(Encoding.UTF8)); }); // Get the output buffer info (hierarchy and output buffers) diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs index be881457..60b542fc 100644 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs @@ -137,6 +137,16 @@ public interface ID2D1Shader [Obsolete("This method is not intended to be used directly by user code")] D2D1ShaderProfile ShaderProfile { get; } + /// + /// Gets the compile options for the current shader. + /// + /// + /// This compile options are either explicitly set by users, or the default one for D2D1 shaders. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + D2D1CompileOptions CompileOptions { get; } + /// /// Loads the bytecode for the current shader. ///