From a926a1211fcb489e5bd0695e8f082fada409e37d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 18 Dec 2023 20:01:07 +0100 Subject: [PATCH] Move and rename the HlslSourceHelper type --- ...xelShaderDescriptorGenerator.HlslSource.cs | 20 +++++++++---------- ...mputeSharp.SourceGeneration.Hlsl.projitems | 2 +- .../HlslSourceSyntaxProcessor.cs} | 7 ++++--- ...uteShaderDescriptorGenerator.HlslSource.cs | 20 +++++++++---------- 4 files changed, 25 insertions(+), 24 deletions(-) rename src/ComputeSharp.SourceGeneration.Hlsl/{Helpers/HlslSourceHelper.cs => SyntaxProcessors/HlslSourceSyntaxProcessor.cs} (95%) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs index 3b4a1f00..831bcb05 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs @@ -451,13 +451,13 @@ partial class D2DPixelShaderDescriptorGenerator /// /// Produces the series of statements to build the current HLSL source. /// - /// - /// + /// + /// /// The sequence of captured resource textures for the current shader. - /// - /// - /// - /// + /// + /// + /// + /// /// The body of the entry point of the shader. /// The number of shader inputs to declare. /// The indicess of the simple shader inputs. @@ -480,7 +480,7 @@ partial class D2DPixelShaderDescriptorGenerator { using IndentedTextWriter writer = new(); - HlslSourceHelper.WriteHeader(writer); + HlslSourceSyntaxProcessor.WriteHeader(writer); // Shader metadata writer.WriteLine($"#define D2D_INPUT_COUNT {inputCount}"); @@ -503,7 +503,7 @@ partial class D2DPixelShaderDescriptorGenerator writer.WriteLine(); // The FXC compiler does not support type forward declarations - HlslSourceHelper.WriteTopDeclarations( + HlslSourceSyntaxProcessor.WriteTopDeclarations( writer, definedConstants, staticFields, @@ -511,7 +511,7 @@ partial class D2DPixelShaderDescriptorGenerator typeDeclarations, includeTypeForwardDeclarations: false); - HlslSourceHelper.WriteCapturedFields(writer, valueFields); + HlslSourceSyntaxProcessor.WriteCapturedFields(writer, valueFields); // Resource textures foreach (HlslResourceTextureField field in resourceTextureFields) @@ -521,7 +521,7 @@ partial class D2DPixelShaderDescriptorGenerator writer.WriteLine($"SamplerState __sampler__{field.Name} : register(s{field.Index});"); } - HlslSourceHelper.WriteMethodDeclarations(writer, processedMethods, typeMethodDeclarations); + HlslSourceSyntaxProcessor.WriteMethodDeclarations(writer, processedMethods, typeMethodDeclarations); // Entry point writer.WriteLine(executeMethod); diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems b/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems index ac737e05..5b6c9f91 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems +++ b/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems @@ -31,7 +31,7 @@ - + diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/HlslSourceHelper.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/HlslSourceSyntaxProcessor.cs similarity index 95% rename from src/ComputeSharp.SourceGeneration.Hlsl/Helpers/HlslSourceHelper.cs rename to src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/HlslSourceSyntaxProcessor.cs index 8aff4c3e..9d2ee587 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/HlslSourceHelper.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/HlslSourceSyntaxProcessor.cs @@ -1,11 +1,12 @@ using System.Collections.Immutable; +using ComputeSharp.SourceGeneration.Helpers; -namespace ComputeSharp.SourceGeneration.Helpers; +namespace ComputeSharp.SourceGeneration.SyntaxProcessors; /// -/// A helper type to write HLSL source. +/// A processor responsible for formatting shared HLSL source for all shader types. /// -internal static class HlslSourceHelper +internal static class HlslSourceSyntaxProcessor { /// /// Writes the header included at the top of each generated HLSL shader. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs index fbd70b2c..48d351d6 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs @@ -489,14 +489,14 @@ partial class ComputeShaderDescriptorGenerator /// The thread ids value for the X axis. /// The thread ids value for the Y axis. /// The thread ids value for the Z axis. - /// + /// /// The sequence of resource instance fields for the current shader. - /// - /// + /// + /// /// The sequence of shared buffers declared by the shader. - /// - /// - /// + /// + /// + /// /// Whether or not the current shader type is a compute shader. /// The type of the implicit target texture, if present. /// Whether the static sampler is used by the shader. @@ -521,14 +521,14 @@ partial class ComputeShaderDescriptorGenerator { using IndentedTextWriter writer = new(); - HlslSourceHelper.WriteHeader(writer); + HlslSourceSyntaxProcessor.WriteHeader(writer); // Group size constants writer.WriteLine($"#define __GroupSize__get_X {threadsX}"); writer.WriteLine($"#define __GroupSize__get_Y {threadsY}"); writer.WriteLine($"#define __GroupSize__get_Z {threadsZ}"); - HlslSourceHelper.WriteTopDeclarations( + HlslSourceSyntaxProcessor.WriteTopDeclarations( writer, definedConstants, staticFields, @@ -545,7 +545,7 @@ partial class ComputeShaderDescriptorGenerator writer.WriteLine("uint __y;"); writer.WriteLineIf(isComputeShader, "uint __z;"); - HlslSourceHelper.WriteCapturedFields(writer, valueFields); + HlslSourceSyntaxProcessor.WriteCapturedFields(writer, valueFields); } int constantBuffersCount = 1; @@ -593,7 +593,7 @@ partial class ComputeShaderDescriptorGenerator writer.WriteLine($"groupshared {buffer.Type} {buffer.Name} [{count}];"); } - HlslSourceHelper.WriteMethodDeclarations(writer, processedMethods, typeMethodDeclarations); + HlslSourceSyntaxProcessor.WriteMethodDeclarations(writer, processedMethods, typeMethodDeclarations); // Entry point writer.WriteLine("[NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)]");