44using ComputeSharp . __Internals ;
55using ComputeSharp . SourceGeneration . Helpers ;
66using ComputeSharp . SourceGenerators . Models ;
7+ using Microsoft . CodeAnalysis ;
78using Microsoft . CodeAnalysis . CSharp ;
89using Microsoft . CodeAnalysis . CSharp . Syntax ;
910using static Microsoft . CodeAnalysis . CSharp . SyntaxFactory ;
@@ -24,12 +25,13 @@ partial class BuildHlslSource
2425 /// <param name="hlslSourceInfo">The input <see cref="HlslShaderSourceInfo"/> instance to use.</param>
2526 /// <param name="supportsDynamicShaders">Indicates whether or not dynamic shaders are supported.</param>
2627 /// <param name="hierarchyDepth">The depth of the hierarchy for this type (used to calculate the right indentation).</param>
28+ /// <param name="useRawMultiLineStringLiteralExpression">Whether to use a raw multiline string literal expression</param>
2729 /// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslSource</c> method.</returns>
28- public static MethodDeclarationSyntax GetSyntax ( HlslShaderSourceInfo hlslSourceInfo , bool supportsDynamicShaders , int hierarchyDepth )
30+ public static MethodDeclarationSyntax GetSyntax ( HlslShaderSourceInfo hlslSourceInfo , bool supportsDynamicShaders , int hierarchyDepth , bool useRawMultiLineStringLiteralExpression )
2931 {
3032 // Generate the necessary body statements depending on whether dynamic shaders are supported
3133 ImmutableArray < StatementSyntax > bodyStatements = supportsDynamicShaders
32- ? GenerateRenderMethodBody ( hlslSourceInfo , hierarchyDepth )
34+ ? GenerateRenderMethodBody ( hlslSourceInfo , hierarchyDepth , useRawMultiLineStringLiteralExpression )
3335 : GenerateEmptyMethodBody ( ) ;
3436
3537 // This code produces a method declaration as follows:
@@ -81,8 +83,9 @@ private static ImmutableArray<StatementSyntax> GenerateEmptyMethodBody()
8183 /// </summary>
8284 /// <param name="hlslSourceInfo">The input <see cref="HlslShaderSourceInfo"/> instance to use.</param>
8385 /// <param name="hierarchyDepth">The depth of the hierarchy for this type (used to calculate the right indentation).</param>
86+ /// <param name="useRawMultiLineStringLiteralExpression">Whether to use a raw multiline string literal expression</param>
8487 /// <returns>The series of statements to build the HLSL source to compile to execute the current shader.</returns>
85- private static ImmutableArray < StatementSyntax > GenerateRenderMethodBody ( HlslShaderSourceInfo hlslSourceInfo , int hierarchyDepth )
88+ private static ImmutableArray < StatementSyntax > GenerateRenderMethodBody ( HlslShaderSourceInfo hlslSourceInfo , int hierarchyDepth , bool useRawMultiLineStringLiteralExpression )
8689 {
8790 using ImmutableArrayBuilder < StatementSyntax > statements = ImmutableArrayBuilder < StatementSyntax > . Rent ( ) ;
8891
@@ -112,19 +115,23 @@ void FlushText()
112115 {
113116 if ( textBuilder . Length > 0 )
114117 {
115- string text = textBuilder . ToString ( ) ;
118+ string hlslSource = textBuilder . ToString ( ) ;
116119
117- textBuilder . Append ( text ) ;
120+ textBuilder . Append ( hlslSource ) ;
118121
119122 sizeHint += textBuilder . Length ;
120123
124+ SyntaxToken hlslSourceLiteralExpression = useRawMultiLineStringLiteralExpression switch
125+ {
126+ true => SyntaxTokenHelper . CreateRawMultilineStringLiteral ( hlslSource , hierarchyDepth ) ,
127+ false => Literal ( hlslSource )
128+ } ;
129+
121130 statements . Add (
122131 ExpressionStatement (
123132 InvocationExpression (
124133 MemberAccessExpression ( SyntaxKind . SimpleMemberAccessExpression , IdentifierName ( "builder" ) , IdentifierName ( "Append" ) ) )
125- . AddArgumentListArguments ( Argument ( LiteralExpression (
126- SyntaxKind . StringLiteralExpression ,
127- SyntaxTokenHelper . CreateRawMultilineStringLiteral ( text , hierarchyDepth ) ) ) ) ) ) ;
134+ . AddArgumentListArguments ( Argument ( LiteralExpression ( SyntaxKind . StringLiteralExpression , hlslSourceLiteralExpression ) ) ) ) ) ;
128135
129136 textBuilder . Clear ( ) ;
130137 }
0 commit comments