diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index 1fef76ce..c35cc2ca 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -45,5 +45,41 @@ partial class IShaderGenerator } } } + + /// + /// 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.__Internals.IShader.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.__Internals.IShader.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.__Internals.IShader.ThreadsZ => {info.ThreadsZ};"); + } } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index f7b11ec2..d62dee1b 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -145,6 +145,9 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator { using ImmutableArrayBuilder> declaredMembers = new(); + declaredMembers.Add(LoadBytecode.WriteThreadsXSyntax); + declaredMembers.Add(LoadBytecode.WriteThreadsYSyntax); + declaredMembers.Add(LoadBytecode.WriteThreadsZSyntax); declaredMembers.Add(LoadDispatchData.WriteSyntax); declaredMembers.Add(LoadDispatchMetadata.WriteSyntax); declaredMembers.Add(BuildHlslSource.WriteSyntax); diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs index d39d9234..77e80df5 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs @@ -10,6 +10,21 @@ namespace ComputeSharp.__Internals; [Obsolete("This interface is not intended to be used directly by user code")] public interface IShader { + /// + /// The number of threads in each thread group for the X axis. + /// + int ThreadsX { get; } + + /// + /// The number of threads in each thread group for the Y axis. + /// + int ThreadsY { get; } + + /// + /// The number of threads in each thread group for the Z axis. + /// + int ThreadsZ { get; } + /// /// Loads the dispatch data for the shader. ///