1+ using ComputeSharp . D2D1 . SourceGenerators . Models ;
2+ using ComputeSharp . SourceGeneration . Extensions ;
3+ using ComputeSharp . SourceGeneration . Helpers ;
4+
5+ namespace ComputeSharp . D2D1 . SourceGenerators ;
6+
7+ /// <inheritdoc/>
8+ partial class D2DPixelShaderDescriptorGenerator
9+ {
10+ /// <summary>
11+ /// A helper with all logic to generate the <c>EffectFactory</c> property.
12+ /// </summary>
13+ private static class EffectFactory
14+ {
15+ /// <summary>
16+ /// Writes the <c>EffectFactory</c> property.
17+ /// </summary>
18+ /// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
19+ /// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
20+ public static void WriteSyntax ( D2D1ShaderInfo info , IndentedTextWriter writer )
21+ {
22+ writer . WriteLine ( "/// <inheritdoc/>" ) ;
23+ writer . WriteGeneratedAttributes ( GeneratorName ) ;
24+ writer . WriteLine ( $ "static unsafe nint global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{ info . Hierarchy . Hierarchy [ 0 ] . QualifiedName } >.EffectFactory") ;
25+
26+ using ( writer . WriteBlock ( ) )
27+ {
28+ writer . WriteLine ( "[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]" ) ;
29+ writer . WriteLine ( "get" ) ;
30+
31+ using ( writer . WriteBlock ( ) )
32+ {
33+ writer . WriteLine ( $$ """
34+ [global::System.Runtime.InteropServices.UnmanagedCallersOnly(CallConvs = [typeof(global::System.Runtime.CompilerServices.CallConvStdcall)])]
35+ static int FactoryDelegate(void** effectImpl)
36+ {
37+ return global::ComputeSharp.D2D1.Interop.D2D1PixelShaderEffect.CreateEffectUnsafe<{{ info . Hierarchy . Hierarchy [ 0 ] . QualifiedName }} >(effectImpl);
38+ }
39+
40+ return (nint)(delegate* unmanaged[Stdcall]<void**, int>)&FactoryDelegate;
41+ """ , isMultiline : true ) ;
42+ }
43+ }
44+ }
45+ }
46+ }
0 commit comments