From 5b8113c2ce18d13bc1172e546cfb13005447cadc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 14 Oct 2023 09:58:16 +0200 Subject: [PATCH] Switch IShader.BuildHlslSource to a property --- .../Shaders/Interop/ReflectionServices.cs | 2 +- ...erator.CreateBuildHlslSourceMethod.Syntax.cs | 17 ++++++----------- .../Core/Interfaces/__Internals/IShader.cs | 13 +++++-------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs index b31d8c38..7ebb877f 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs @@ -104,7 +104,7 @@ public static class ReflectionServices private static unsafe ShaderInfo GetNonGenericShaderInfo(in T shader) where T : struct, IShader { - Unsafe.AsRef(in shader).BuildHlslSource(out string hlslSource); + string hlslSource = Unsafe.AsRef(in shader).HlslSource; using ComPtr dxcBlobBytecode = Shaders.Translation.ShaderCompiler.Instance.Compile(hlslSource); diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs index 1f86db7d..555652a0 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs @@ -19,17 +19,12 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.BuildHlslSource(out string hlslSource)"); - - using (writer.WriteBlock()) - { - writer.WriteLine("hlslSource ="); - writer.IncreaseIndent(); - writer.WriteLine("\"\"\""); - writer.Write(info.HlslInfoKey.HlslSource, isMultiline: true); - writer.WriteLine("\"\"\";"); - writer.DecreaseIndent(); - } + writer.WriteLine($"readonly string global::ComputeSharp.__Internals.IShader.HlslSource =>"); + writer.IncreaseIndent(); + writer.WriteLine("\"\"\""); + writer.Write(info.HlslInfoKey.HlslSource, isMultiline: true); + writer.WriteLine("\"\"\";"); + writer.DecreaseIndent(); } } } \ No newline at end of file diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs index 2a0e128c..dc110632 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs @@ -25,6 +25,11 @@ public interface IShader /// int ThreadsZ { get; } + /// + /// Gets the HLSL source code for the current shader instance. + /// + string HlslSource { get; } + /// /// Gets the HLSL bytecode for the current shader. /// @@ -54,12 +59,4 @@ public interface IShader [Obsolete("This method is not intended to be called directly by user code")] void LoadDispatchMetadata(ref TLoader loader, out IntPtr result) where TLoader : struct, IDispatchMetadataLoader; - - /// - /// Builds the HLSL source code for the current shader instance. - /// - /// The resulting HLSL source. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be called directly by user code")] - void BuildHlslSource(out string hlslSource); } \ No newline at end of file