From 2545c6c3914e296e5b30971960625634349b8cb8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 15 Oct 2023 21:09:53 +0200 Subject: [PATCH] Refactor D3D12 generator files and helper types --- ...iptorGenerator.NumericProperties.Syntax.cs | 2 +- ...orGenerator.DispatchDataLoading.Syntax.cs} | 2 +- ...escriptorGenerator.DispatchDataLoading.cs} | 4 +- ...escriptorGenerator.HlslBytecode.Syntax.cs} | 2 +- ...ShaderDescriptorGenerator.HlslBytecode.cs} | 89 +-------------- ...rDescriptorGenerator.HlslSource.Syntax.cs} | 4 +- ...teShaderDescriptorGenerator.HlslSource.cs} | 4 +- ...ptorGenerator.MetadataProperties.Syntax.cs | 39 +++++++ ...erDescriptorGenerator.NumThreads.Syntax.cs | 49 +++++++++ ...uteShaderDescriptorGenerator.NumThreads.cs | 103 ++++++++++++++++++ ...erator.ResourceDescriptorRanges.Syntax.cs} | 26 +---- ...ptorGenerator.ResourceDescriptorRanges.cs} | 4 +- .../ComputeShaderDescriptorGenerator.cs | 44 ++++---- 13 files changed, 227 insertions(+), 145 deletions(-) rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.Syntax.cs => ComputeShaderDescriptorGenerator.DispatchDataLoading.Syntax.cs} (99%) rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.cs => ComputeShaderDescriptorGenerator.DispatchDataLoading.cs} (98%) rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.Syntax.cs => ComputeShaderDescriptorGenerator.HlslBytecode.Syntax.cs} (99%) rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.cs => ComputeShaderDescriptorGenerator.HlslBytecode.cs} (68%) rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.Syntax.cs => ComputeShaderDescriptorGenerator.HlslSource.Syntax.cs} (92%) rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.cs => ComputeShaderDescriptorGenerator.HlslSource.cs} (99%) create mode 100644 src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.MetadataProperties.Syntax.cs create mode 100644 src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.Syntax.cs create mode 100644 src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs => ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.Syntax.cs} (73%) rename src/ComputeSharp.SourceGenerators/{ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.cs => ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.cs} (93%) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs index a4896594..0efc43fd 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs @@ -10,7 +10,7 @@ partial class D2DPixelShaderDescriptorGenerator /// /// A helper with all logic to generate the available numeric properties. /// - private static partial class NumericProperties + private static class NumericProperties { /// /// Writes the ConstantBufferSize property. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.Syntax.cs similarity index 99% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.Syntax.cs index 04c15cd8..9deae88d 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.Syntax.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - partial class LoadDispatchData + partial class DispatchDataLoading { /// /// Writes the LoadConstantBuffer method. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.cs similarity index 98% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.cs index d9cb4c6a..e95b012a 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.cs @@ -18,9 +18,9 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the LoadDispatchData method. + /// A helper with all logic to generate the dispatch data loading methods. /// - private static partial class LoadDispatchData + private static partial class DispatchDataLoading { /// /// Explores a given type hierarchy and generates statements to load fields. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.Syntax.cs similarity index 99% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.Syntax.cs index fca6095e..dcee6b1c 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.Syntax.cs @@ -9,7 +9,7 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - partial class LoadBytecode + partial class HlslBytecode { /// /// Writes the HlslBytecode property. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs similarity index 68% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs index 9652aefd..adcd069d 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs @@ -25,9 +25,9 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the LoadBytecode method. + /// A helper with all logic to generate the HlslBytecode property. /// - private static partial class LoadBytecode + private static partial class HlslBytecode { /// /// The shared cache of values. @@ -39,91 +39,6 @@ partial class ComputeShaderDescriptorGenerator /// private static volatile bool areDxcLibrariesLoaded; - /// - /// Gets the thread ids values for a given shader type, if available. - /// - /// The collection of produced instances. - /// The input instance to process. - /// The thread ids value for the X axis. - /// The thread ids value for the Y axis. - /// The thread ids value for the Z axis. - /// Whether compilation should be attempted for the current info. - public static void GetInfo( - ImmutableArrayBuilder diagnostics, - INamedTypeSymbol structDeclarationSymbol, - out int threadsX, - out int threadsY, - out int threadsZ, - out bool isCompilationEnabled) - { - // Try to get the attribute that controls shader precompilation (has to be present when ComputeSharp.Dynamic is not referenced) - if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName(typeof(EmbeddedBytecodeAttribute).FullName, out AttributeData? attribute)) - { - // Emit the diagnostics if dynamic shaders are not supported - diagnostics.Add(MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported, structDeclarationSymbol, structDeclarationSymbol); - - threadsX = threadsY = threadsZ = 0; - isCompilationEnabled = false; - - return; - } - - // Check for a dispatch axis argument first - if (attribute.ConstructorArguments.Length == 1) - { - int dispatchAxis = (int)attribute.ConstructorArguments[0].Value!; - - (threadsX, threadsY, threadsZ) = (DispatchAxis)dispatchAxis switch - { - DispatchAxis.X => (64, 1, 1), - DispatchAxis.Y => (1, 64, 1), - DispatchAxis.Z => (1, 1, 64), - DispatchAxis.XY => (8, 8, 1), - DispatchAxis.XZ => (8, 1, 8), - DispatchAxis.YZ => (1, 8, 8), - DispatchAxis.XYZ => (4, 4, 4), - _ => (0, 0, 0) - }; - - // Validate the dispatch axis argument - if ((threadsX, threadsY, threadsZ) is (0, 0, 0)) - { - diagnostics.Add(InvalidEmbeddedBytecodeDispatchAxis, structDeclarationSymbol, structDeclarationSymbol); - - threadsX = threadsY = threadsZ = 0; - isCompilationEnabled = false; - - return; - } - - isCompilationEnabled = true; - } - else if ( - attribute.ConstructorArguments.Length != 3 || - attribute.ConstructorArguments[0].Value is not int explicitThreadsX || - attribute.ConstructorArguments[1].Value is not int explicitThreadsY || - attribute.ConstructorArguments[2].Value is not int explicitThreadsZ || - explicitThreadsX is < 1 or > 1024 || - explicitThreadsY is < 1 or > 1024 || - explicitThreadsZ is < 1 or > 64) - { - // Failed to validate the thread number arguments - diagnostics.Add(InvalidEmbeddedBytecodeThreadIds, structDeclarationSymbol, structDeclarationSymbol); - - threadsX = threadsY = threadsZ = 0; - isCompilationEnabled = false; - - return; - } - else - { - threadsX = explicitThreadsX; - threadsY = explicitThreadsY; - threadsZ = explicitThreadsZ; - isCompilationEnabled = true; - } - } - /// /// Gets the instance for the input shader info. /// diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.Syntax.cs similarity index 92% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.Syntax.cs index d2f3b50c..fdb68dae 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.Syntax.cs @@ -8,10 +8,10 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - partial class BuildHlslSource + partial class HlslSource { /// - /// Writes the BuildHlslSource method. + /// Writes the HlslSource property. /// /// The input instance with gathered shader info. /// The instance to write into. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs similarity index 99% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs index 8bf96c78..7d6dd476 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs @@ -20,9 +20,9 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the BuildHlslSource method. + /// A helper with all logic to generate the HlslSource property. /// - internal static partial class BuildHlslSource + internal static partial class HlslSource { /// /// Gathers all necessary information on a transpiled HLSL source for a given shader type. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.MetadataProperties.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.MetadataProperties.Syntax.cs new file mode 100644 index 00000000..c13050d1 --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.MetadataProperties.Syntax.cs @@ -0,0 +1,39 @@ +using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.SourceGeneration.Helpers; +using ComputeSharp.SourceGenerators.Models; + +namespace ComputeSharp.SourceGenerators; + +/// +partial class ComputeShaderDescriptorGenerator +{ + /// + /// A helper with all logic to generate additional metadata properties + /// + private static class MetadataProperties + { + /// + /// Writes the ConstantBufferSize property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteConstantBufferSizeSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); + } + + /// + /// Writes the IsStaticSamplerRequired property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteIsStaticSamplerRequiredSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};"); + } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.Syntax.cs new file mode 100644 index 00000000..deafb48c --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.Syntax.cs @@ -0,0 +1,49 @@ +using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.SourceGeneration.Helpers; +using ComputeSharp.SourceGenerators.Models; + +namespace ComputeSharp.SourceGenerators; + +/// +partial class ComputeShaderDescriptorGenerator +{ + /// + partial class NumThreads + { + /// + /// Writes the ThreadsX property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteThreadsXSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsX => {info.ThreadsX};"); + } + + /// + /// Writes the ThreadsY property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteThreadsYSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsY => {info.ThreadsY};"); + } + + /// + /// Writes the ThreadsZ property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteThreadsZSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsZ => {info.ThreadsZ};"); + } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs new file mode 100644 index 00000000..0efd19fb --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs @@ -0,0 +1,103 @@ +using System; +using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.SourceGeneration.Helpers; +using ComputeSharp.SourceGeneration.Models; +using Microsoft.CodeAnalysis; +using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; + +namespace ComputeSharp.SourceGenerators; + +/// +partial class ComputeShaderDescriptorGenerator +{ + /// + /// A helper with all logic to generate the [numthreads] properties. + /// + private static partial class NumThreads + { + /// + /// Gets the thread ids values for a given shader type, if available. + /// + /// The collection of produced instances. + /// The input instance to process. + /// The thread ids value for the X axis. + /// The thread ids value for the Y axis. + /// The thread ids value for the Z axis. + /// Whether compilation should be attempted for the current info. + public static void GetInfo( + ImmutableArrayBuilder diagnostics, + INamedTypeSymbol structDeclarationSymbol, + out int threadsX, + out int threadsY, + out int threadsZ, + out bool isCompilationEnabled) + { + // Try to get the attribute that controls shader precompilation (has to be present when ComputeSharp.Dynamic is not referenced) + if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName(typeof(EmbeddedBytecodeAttribute).FullName, out AttributeData? attribute)) + { + // Emit the diagnostics if dynamic shaders are not supported + diagnostics.Add(MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported, structDeclarationSymbol, structDeclarationSymbol); + + threadsX = threadsY = threadsZ = 0; + isCompilationEnabled = false; + + return; + } + + // Check for a dispatch axis argument first + if (attribute.ConstructorArguments.Length == 1) + { + int dispatchAxis = (int)attribute.ConstructorArguments[0].Value!; + + (threadsX, threadsY, threadsZ) = (DispatchAxis)dispatchAxis switch + { + DispatchAxis.X => (64, 1, 1), + DispatchAxis.Y => (1, 64, 1), + DispatchAxis.Z => (1, 1, 64), + DispatchAxis.XY => (8, 8, 1), + DispatchAxis.XZ => (8, 1, 8), + DispatchAxis.YZ => (1, 8, 8), + DispatchAxis.XYZ => (4, 4, 4), + _ => (0, 0, 0) + }; + + // Validate the dispatch axis argument + if ((threadsX, threadsY, threadsZ) is (0, 0, 0)) + { + diagnostics.Add(InvalidEmbeddedBytecodeDispatchAxis, structDeclarationSymbol, structDeclarationSymbol); + + threadsX = threadsY = threadsZ = 0; + isCompilationEnabled = false; + + return; + } + + isCompilationEnabled = true; + } + else if ( + attribute.ConstructorArguments.Length != 3 || + attribute.ConstructorArguments[0].Value is not int explicitThreadsX || + attribute.ConstructorArguments[1].Value is not int explicitThreadsY || + attribute.ConstructorArguments[2].Value is not int explicitThreadsZ || + explicitThreadsX is < 1 or > 1024 || + explicitThreadsY is < 1 or > 1024 || + explicitThreadsZ is < 1 or > 64) + { + // Failed to validate the thread number arguments + diagnostics.Add(InvalidEmbeddedBytecodeThreadIds, structDeclarationSymbol, structDeclarationSymbol); + + threadsX = threadsY = threadsZ = 0; + isCompilationEnabled = false; + + return; + } + else + { + threadsX = explicitThreadsX; + threadsY = explicitThreadsY; + threadsZ = explicitThreadsZ; + isCompilationEnabled = true; + } + } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.Syntax.cs similarity index 73% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.Syntax.cs index 90eb885e..4a86db94 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.Syntax.cs @@ -8,32 +8,8 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - partial class LoadDispatchMetadata + partial class ResourceDescriptorRanges { - /// - /// Writes the ConstantBufferSize property. - /// - /// The input instance with gathered shader info. - /// The instance to write into. - public static void WriteConstantBufferSizeSyntax(ShaderInfo info, IndentedTextWriter writer) - { - writer.WriteLine("/// "); - writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); - } - - /// - /// Writes the IsStaticSamplerRequired property. - /// - /// The input instance with gathered shader info. - /// The instance to write into. - public static void WriteIsStaticSamplerRequiredSyntax(ShaderInfo info, IndentedTextWriter writer) - { - writer.WriteLine("/// "); - writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};"); - } - /// /// Writes the ResourceDescriptorRanges property. /// diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.cs similarity index 93% rename from src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.cs index b84b4c43..2adf9096 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.CreateLoadDispatchMetadataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.cs @@ -9,9 +9,9 @@ namespace ComputeSharp.SourceGenerators; partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the LoadDispatchMetadata method. + /// A helper with all logic to generate the ResourceDescriptorRanges property. /// - private static partial class LoadDispatchMetadata + private static partial class ResourceDescriptorRanges { /// /// Gets the data related to the shader metadata for a given shader type. diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs index 93abd83d..50d63776 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs @@ -53,8 +53,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener using ImmutableArrayBuilder diagnostics = new(); - // LoadDispatchData() info - ImmutableArray fieldInfos = LoadDispatchData.GetInfo( + // Dispatch data loading info + ImmutableArray fieldInfos = DispatchDataLoading.GetInfo( diagnostics, typeSymbol, isPixelShaderLike, @@ -63,8 +63,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener token.ThrowIfCancellationRequested(); - // TryGetBytecode() info - LoadBytecode.GetInfo( + // Thread group size info + NumThreads.GetInfo( diagnostics, typeSymbol, out int threadsX, @@ -74,8 +74,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener token.ThrowIfCancellationRequested(); - // BuildHlslSource() info - BuildHlslSource.GetInfo( + // Transpiled HLSL source info + HlslSource.GetInfo( diagnostics, context.SemanticModel.Compilation, typeDeclaration, @@ -89,8 +89,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener token.ThrowIfCancellationRequested(); - // GetDispatchMetadata() info - ImmutableArray resourceDescriptors = LoadDispatchMetadata.GetInfo( + // Resource descriptor ranges info + ImmutableArray resourceDescriptors = ResourceDescriptorRanges.GetInfo( isImplicitTextureUsed, isSamplerUsed, fieldInfos); @@ -101,11 +101,11 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener HlslBytecodeInfoKey hlslInfoKey = new(hlslSource, isCompilationEnabled); // Try to get the HLSL bytecode - HlslBytecodeInfo hlslInfo = LoadBytecode.GetBytecode(ref hlslInfoKey, token); + HlslBytecodeInfo hlslInfo = HlslBytecode.GetBytecode(ref hlslInfoKey, token); token.ThrowIfCancellationRequested(); - LoadBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics); + HlslBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics); token.ThrowIfCancellationRequested(); @@ -143,22 +143,22 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener { using ImmutableArrayBuilder> declaredMembers = new(); - declaredMembers.Add(LoadBytecode.WriteThreadsXSyntax); - declaredMembers.Add(LoadBytecode.WriteThreadsYSyntax); - declaredMembers.Add(LoadBytecode.WriteThreadsZSyntax); - declaredMembers.Add(LoadDispatchMetadata.WriteConstantBufferSizeSyntax); - declaredMembers.Add(LoadDispatchMetadata.WriteIsStaticSamplerRequiredSyntax); - declaredMembers.Add(LoadDispatchMetadata.WriteSyntax); - declaredMembers.Add(BuildHlslSource.WriteSyntax); - declaredMembers.Add(LoadBytecode.WriteHlslBytecodeSyntax); - declaredMembers.Add(LoadDispatchData.WriteLoadConstantBufferSyntax); - declaredMembers.Add(LoadDispatchData.WriteLoadGraphicsResourcesSyntax); + declaredMembers.Add(HlslBytecode.WriteThreadsXSyntax); + declaredMembers.Add(HlslBytecode.WriteThreadsYSyntax); + declaredMembers.Add(HlslBytecode.WriteThreadsZSyntax); + declaredMembers.Add(MetadataProperties.WriteConstantBufferSizeSyntax); + declaredMembers.Add(MetadataProperties.WriteIsStaticSamplerRequiredSyntax); + declaredMembers.Add(ResourceDescriptorRanges.WriteSyntax); + declaredMembers.Add(HlslSource.WriteSyntax); + declaredMembers.Add(HlslBytecode.WriteHlslBytecodeSyntax); + declaredMembers.Add(DispatchDataLoading.WriteLoadConstantBufferSyntax); + declaredMembers.Add(DispatchDataLoading.WriteLoadGraphicsResourcesSyntax); using ImmutableArrayBuilder> additionalTypes = new(); using ImmutableHashSetBuilder usingDirectives = new(); - LoadDispatchMetadata.RegisterAdditionalDataMemberSyntax(item, additionalTypes, usingDirectives); - LoadBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); + ResourceDescriptorRanges.RegisterAdditionalDataMemberSyntax(item, additionalTypes, usingDirectives); + HlslBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); using IndentedTextWriter writer = new();