From f9a73d9b095895db76df6e700e0d9697a2384aaa Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 03:30:18 +0200 Subject: [PATCH] Add ID2D1Shader.ConstantBufferSize property --- ...nerator.CreateInputCountProperty.Syntax.cs | 27 ------------- ...enerator.CreateNumericProperties.Syntax.cs | 39 +++++++++++++++++++ .../ID2D1ShaderGenerator.cs | 3 +- .../Interfaces/__Internals/ID2D1Shader.cs | 7 ++++ 4 files changed, 48 insertions(+), 28 deletions(-) delete mode 100644 src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputCountProperty.Syntax.cs create mode 100644 src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputCountProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputCountProperty.Syntax.cs deleted file mode 100644 index bbde29e1..00000000 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputCountProperty.Syntax.cs +++ /dev/null @@ -1,27 +0,0 @@ -using ComputeSharp.D2D1.SourceGenerators.Models; -using ComputeSharp.SourceGeneration.Extensions; -using ComputeSharp.SourceGeneration.Helpers; - -namespace ComputeSharp.D2D1.SourceGenerators; - -/// -partial class ID2D1ShaderGenerator -{ - /// - /// A helper with all logic to generate the InputCount property. - /// - private static partial class InputCount - { - /// - /// Writes the InputCount property. - /// - /// The input instance with gathered shader info. - /// The instance to write into. - public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) - { - writer.WriteLine("/// "); - writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputCount => {info.InputTypes.Length};"); - } - } -} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs new file mode 100644 index 00000000..1a45c069 --- /dev/null +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs @@ -0,0 +1,39 @@ +using ComputeSharp.D2D1.SourceGenerators.Models; +using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.SourceGeneration.Helpers; + +namespace ComputeSharp.D2D1.SourceGenerators; + +/// +partial class ID2D1ShaderGenerator +{ + /// + /// A helper with all logic to generate the available numeric properties. + /// + private static partial class NumericProperties + { + /// + /// Writes the ConstantBufferSize property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteConstantBufferSizeSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); + writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); + } + + /// + /// Writes the InputCount property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteInputCountSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); + writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputCount => {info.InputTypes.Length};"); + } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index c1a0eb76..5561deae 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -201,7 +201,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator declaredMembers.Add(EffectMetadata.WriteEffectDescriptionSyntax); declaredMembers.Add(EffectMetadata.WriteEffectCategorySyntax); declaredMembers.Add(EffectMetadata.WriteEffectAuthorSyntax); - declaredMembers.Add(InputCount.WriteSyntax); + declaredMembers.Add(NumericProperties.WriteConstantBufferSizeSyntax); + declaredMembers.Add(NumericProperties.WriteInputCountSyntax); declaredMembers.Add(InputTypes.WriteSyntax); declaredMembers.Add(InputDescriptions.WriteSyntax); declaredMembers.Add(ResourceTextureDescriptions.WriteSyntax); diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs index 3da044d0..0cff2231 100644 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs @@ -67,6 +67,13 @@ public interface ID2D1Shader [Obsolete("This method is not intended to be used directly by user code")] D2D1PixelOptions PixelOptions { get; } + /// + /// Gets the size in bytes of the constant buffer for the current shader. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + int ConstantBufferSize { get; } + /// /// Gets the number of inputs for the current shader. ///