From 30414faf405cc0440fd07c3dba71706191f0fe4e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 14 Oct 2023 10:28:57 +0200 Subject: [PATCH] Add and generate IShader.IsStaticSamplerRequired API --- ...erator.CreateLoadDispatchMetadataMethod.Syntax.cs | 12 ++++++++++++ .../IShaderGenerator.cs | 3 ++- .../Core/Interfaces/__Internals/IShader.cs | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs index 22881355..0f1117e2 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs @@ -23,6 +23,18 @@ partial class IShaderGenerator writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.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.__Internals.IShader.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};"); + } + /// /// Writes the LoadDispatchMetadata method. /// diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 49144cbd..511845f3 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -149,10 +149,11 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator declaredMembers.Add(LoadBytecode.WriteThreadsYSyntax); declaredMembers.Add(LoadBytecode.WriteThreadsZSyntax); declaredMembers.Add(LoadDispatchMetadata.WriteConstantBufferSizeSyntax); + declaredMembers.Add(LoadDispatchMetadata.WriteIsStaticSamplerRequiredSyntax); + declaredMembers.Add(BuildHlslSource.WriteSyntax); declaredMembers.Add(LoadBytecode.WriteHlslBytecodeSyntax); declaredMembers.Add(LoadDispatchData.WriteSyntax); declaredMembers.Add(LoadDispatchMetadata.WriteSyntax); - declaredMembers.Add(BuildHlslSource.WriteSyntax); using ImmutableArrayBuilder> additionalTypes = new(); using ImmutableHashSetBuilder usingDirectives = new(); diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs index b1fa6a4e..089c3e94 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs @@ -35,6 +35,14 @@ public interface IShader /// int ConstantBufferSize { get; } + /// + /// Gets whether the shader requires a static sampler being declared and initialized. + /// + /// + /// When requested, a static sampler with linear sampling and mirror addressing will be bound to register(s). + /// + bool IsStaticSamplerRequired { get; } + /// /// Gets the HLSL source code for the current shader instance. ///