From 85fd44d863d948ad95c0e077e730c333ea30f365 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 14:28:30 +0200 Subject: [PATCH 1/5] Rename internal interfaces and update all signatures --- .../ComputeSharp.D2D1.SourceGenerators.csproj | 4 +- .../Descriptors/ID2D1ConstantBufferLoader.cs | 15 +++ .../ID2D1PixelShaderDescriptor{T}.cs} | 104 +++++++----------- .../Interfaces/ID2D1PixelShader.cs | 6 +- .../__Internals/ID2D1DispatchDataLoader.cs | 18 --- .../Interop/D2D1DrawInfoUpdateContext{T}.cs | 11 +- .../Shaders/Interop/D2D1PixelShader.cs | 59 +++++----- .../Shaders/Interop/D2D1PixelShaderEffect.cs | 27 +++-- .../Shaders/Interop/D2D1ReflectionServices.cs | 5 +- .../Interop/D2D1TransformMapperFactory{T}.cs | 3 +- .../Shaders/Interop/D2D1TransformMapper{T}.cs | 3 +- .../Effects/PixelShaderEffect.For{T}.cs | 3 +- ... => D2D1TransformMapper{T,TParameters}.cs} | 3 +- .../Factories/D2D1AffineTransformMapper{T}.cs | 3 +- .../D2D1InflateTransformMapper{T}.cs | 3 +- ...s => D2D1ByteArrayConstantBufferLoader.cs} | 8 +- ... => D2D1ByteBufferConstantBufferLoader.cs} | 12 +- ...cs => D2D1DrawInfoConstantBufferLoader.cs} | 12 +- ...wInfoUpdateContextConstantBufferLoader.cs} | 12 +- ...r.cs => D2D1EffectConstantBufferLoader.cs} | 12 +- 20 files changed, 140 insertions(+), 183 deletions(-) create mode 100644 src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1ConstantBufferLoader.cs rename src/ComputeSharp.D2D1/Interfaces/{__Internals/ID2D1Shader.cs => Descriptors/ID2D1PixelShaderDescriptor{T}.cs} (53%) delete mode 100644 src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1DispatchDataLoader.cs rename src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/{D2D1TransformMapper{T, TParameters}.cs => D2D1TransformMapper{T,TParameters}.cs} (97%) rename src/ComputeSharp.D2D1/Shaders/Loaders/{D2D1ByteArrayDispatchDataLoader.cs => D2D1ByteArrayConstantBufferLoader.cs} (78%) rename src/ComputeSharp.D2D1/Shaders/Loaders/{D2D1ByteBufferDispatchDataLoader.cs => D2D1ByteBufferConstantBufferLoader.cs} (84%) rename src/ComputeSharp.D2D1/Shaders/Loaders/{D2D1DrawInfoDispatchDataLoader.cs => D2D1DrawInfoConstantBufferLoader.cs} (70%) rename src/ComputeSharp.D2D1/Shaders/Loaders/{D2D1DrawInfoUpdateContextDispatchDataLoader.cs => D2D1DrawInfoUpdateContextConstantBufferLoader.cs} (70%) rename src/ComputeSharp.D2D1/Shaders/Loaders/{D2D1EffectDispatchDataLoader.cs => D2D1EffectConstantBufferLoader.cs} (73%) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 9f52daa2..8240a9ff 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -78,8 +78,8 @@ - - + + diff --git a/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1ConstantBufferLoader.cs b/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1ConstantBufferLoader.cs new file mode 100644 index 00000000..1f318330 --- /dev/null +++ b/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1ConstantBufferLoader.cs @@ -0,0 +1,15 @@ +using System; + +namespace ComputeSharp.D2D1.Descriptors; + +/// +/// A type representing a data loader for the constant buffer of a D2D1 shader. +/// +public interface ID2D1ConstantBufferLoader +{ + /// + /// Loads the constant buffer of a D2D1 shader. + /// + /// The constant buffer for the D2D1 shader. + void LoadConstantBuffer(ReadOnlySpan data); +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1PixelShaderDescriptor{T}.cs similarity index 53% rename from src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs rename to src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1PixelShaderDescriptor{T}.cs index 4fb00ab4..ac06889c 100644 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1PixelShaderDescriptor{T}.cs @@ -1,21 +1,22 @@ using System; -using System.ComponentModel; using ComputeSharp.D2D1.Interop; -namespace ComputeSharp.D2D1.__Internals; +namespace ComputeSharp.D2D1.Descriptors; /// -/// A base representing a given shader that can be dispatched. +/// An interface for a descriptor for a given D2D1 pixel shader. +/// Descriptors contain metadata associated to D2D1 pixel shaders, +/// with all information needed to run them and create effects. /// -[EditorBrowsable(EditorBrowsableState.Never)] -[Obsolete("This interface is not intended to be used directly by user code")] -public interface ID2D1Shader +/// The type of D2D1 pixel shader being described. +public interface ID2D1PixelShaderDescriptor + where T : unmanaged, ID2D1PixelShader { /// /// Gets the effect id of the D2D effect using this shader. /// /// - /// This only applies to effects created from . + /// This only applies to effects created from . /// ref readonly Guid EffectId { get; } @@ -23,7 +24,7 @@ public interface ID2D1Shader /// Gets the display name of the D2D effect using this shader, if specified. /// /// - /// This only applies to effects created from . + /// This only applies to effects created from . /// string? EffectDisplayName { get; } @@ -31,7 +32,7 @@ public interface ID2D1Shader /// Gets the description of the D2D effect using this shader, if specified. /// /// - /// This only applies to effects created from . + /// This only applies to effects created from . /// string? EffectDescription { get; } @@ -39,7 +40,7 @@ public interface ID2D1Shader /// Gets the category of the D2D effect using this shader, if specified. /// /// - /// This only applies to effects created from . + /// This only applies to effects created from . /// string? EffectCategory { get; } @@ -47,107 +48,61 @@ public interface ID2D1Shader /// Gets the author of the D2D effect using this shader, if specified. /// /// - /// This only applies to effects created from . + /// This only applies to effects created from . /// string? EffectAuthor { get; } - /// - /// Initializes the current shader from a buffer with the serialized dispatch data. - /// - /// The input buffer with the serialized dispatch data. - /// The input buffer must be retrieved from . - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be called directly by user code")] - void InitializeFromDispatchData(ReadOnlySpan data); - - /// - /// Gets the pixel options for the current shader. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [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. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] int InputCount { get; } /// /// Gets the number of resource textures for the current shader. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] int ResourceTextureCount { get; } /// /// Gets the input types for the current shader. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] ReadOnlyMemory InputTypes { get; } /// /// Gets the input descriptions for the current shader. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] ReadOnlyMemory InputDescriptions { get; } /// /// Gets the resource texture descriptions for the shader. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] ReadOnlyMemory ResourceTextureDescriptions { get; } + /// + /// Gets the pixel options for the current shader. + /// + D2D1PixelOptions PixelOptions { get; } + /// /// Gets the buffer precision for the shader. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] D2D1BufferPrecision BufferPrecision { get; } /// /// Gets the channel depth for the shader. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] D2D1ChannelDepth ChannelDepth { get; } - /// - /// Loads the dispatch data for the shader. - /// - /// The type of data loader being used. - /// The instance to use to load the data. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be called directly by user code")] - void LoadDispatchData(ref TLoader loader) - where TLoader : struct, ID2D1DispatchDataLoader; - - /// - /// Gets the HLSL source code for the current shader instance. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be called directly by user code")] - string HlslSource { get; } - /// /// Gets the shader profile for the current shader. /// /// /// This shader profile is either explicitly set by users, or the default one for D2D1 shaders. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] D2D1ShaderProfile ShaderProfile { get; } /// @@ -156,17 +111,34 @@ public interface ID2D1Shader /// /// This compile options are either explicitly set by users, or the default one for D2D1 shaders. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] D2D1CompileOptions CompileOptions { get; } + /// + /// Gets the HLSL source code for the current shader instance. + /// + string HlslSource { get; } + /// /// Gets the HLSL bytecode for the current shader, if available. /// /// /// If no precompiled HLSL bytecode is available, the returned instance will be empty. /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be used directly by user code")] ReadOnlyMemory HlslBytecode { get; } + + /// + /// Creates a new shader instance from a constant buffer. + /// + /// The input constant buffer to read. + /// The input buffer must be retrieved from . + T CreateFromConstantBuffer(ReadOnlySpan buffer); + + /// + /// Loads the constant buffer of a given input shader. + /// + /// The type of data loader being used. + /// The input shader to load the constant buffer for. + /// The instance to use to load the constant buffer. + void LoadConstantBuffer(in T shader, ref TLoader loader) + where TLoader : struct, ID2D1ConstantBufferLoader; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Interfaces/ID2D1PixelShader.cs b/src/ComputeSharp.D2D1/Interfaces/ID2D1PixelShader.cs index c327733f..1a6e91a0 100644 --- a/src/ComputeSharp.D2D1/Interfaces/ID2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/ID2D1PixelShader.cs @@ -1,13 +1,9 @@ -using ComputeSharp.D2D1.__Internals; - -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1; /// /// An representing a D2D1 pixel shader. /// -public interface ID2D1PixelShader : ID2D1Shader +public interface ID2D1PixelShader { /// /// Executes the current pixel shader. diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1DispatchDataLoader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1DispatchDataLoader.cs deleted file mode 100644 index d380bf7d..00000000 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1DispatchDataLoader.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.ComponentModel; - -namespace ComputeSharp.D2D1.__Internals; - -/// -/// A base representing a data loader for a D2D1 shader being dispatched. -/// -[EditorBrowsable(EditorBrowsableState.Never)] -[Obsolete("This interface is not intended to be used directly by user code")] -public interface ID2D1DispatchDataLoader -{ - /// - /// Loads the captured values used by the D2D1 shader to be dispatched. - /// - /// The sequence of serialized captured values. - void LoadConstantBuffer(ReadOnlySpan data); -} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1DrawInfoUpdateContext{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1DrawInfoUpdateContext{T}.cs index e725eaa1..a0064dae 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1DrawInfoUpdateContext{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1DrawInfoUpdateContext{T}.cs @@ -1,11 +1,10 @@ using System.Buffers; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers; using ComputeSharp.D2D1.Shaders.Loaders; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Interop; /// @@ -13,7 +12,7 @@ namespace ComputeSharp.D2D1.Interop; /// /// The type of shader the transform will interact with. public readonly unsafe ref struct D2D1DrawInfoUpdateContext - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The instance associated with the current object. @@ -48,7 +47,7 @@ public readonly unsafe ref struct D2D1DrawInfoUpdateContext Unsafe.SkipInit(out T shader); - shader.InitializeFromDispatchData(buffer); + shader = shader.CreateFromConstantBuffer(buffer); ArrayPool.Shared.Return(buffer); @@ -61,8 +60,8 @@ public readonly unsafe ref struct D2D1DrawInfoUpdateContext /// The instance to be used in the associated effect. public void SetConstantBuffer(in T shader) { - D2D1DrawInfoUpdateContextDispatchDataLoader dataLoader = new(this.d2D1DrawInfoUpdateContext); + D2D1DrawInfoUpdateContextConstantBufferLoader dataLoader = new(this.d2D1DrawInfoUpdateContext); - Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader); + Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader); } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index 20cbbcce..2122a91d 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -1,12 +1,11 @@ using System; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Shaders.Loaders; using ComputeSharp.D2D1.Shaders.Translation; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Interop; /// @@ -27,7 +26,7 @@ public static class D2D1PixelShader /// /// public static ReadOnlyMemory LoadBytecode() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -58,7 +57,7 @@ public static class D2D1PixelShader /// /// public static ReadOnlyMemory LoadBytecode(out D2D1ShaderProfile shaderProfile, out D2D1CompileOptions compileOptions) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { return LoadOrCompileBytecode(null, null, out shaderProfile, out compileOptions); } @@ -84,7 +83,7 @@ public static class D2D1PixelShader /// /// public static ReadOnlyMemory LoadBytecode(D2D1ShaderProfile shaderProfile) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { return LoadOrCompileBytecode(shaderProfile, null, out _, out _); } @@ -111,7 +110,7 @@ public static class D2D1PixelShader /// /// public static ReadOnlyMemory LoadBytecode(D2D1ShaderProfile shaderProfile, out D2D1CompileOptions compileOptions) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { return LoadOrCompileBytecode(shaderProfile, null, out _, out compileOptions); } @@ -140,7 +139,7 @@ public static class D2D1PixelShader /// /// public static ReadOnlyMemory LoadBytecode(D2D1CompileOptions compileOptions) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions)); @@ -172,7 +171,7 @@ public static class D2D1PixelShader /// /// public static ReadOnlyMemory LoadBytecode(D2D1CompileOptions compileOptions, out D2D1ShaderProfile shaderProfile) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions)); @@ -195,7 +194,7 @@ public static class D2D1PixelShader /// If the shader was compiled at runtime, the returned instance will wrap a array with the bytecode. /// public static ReadOnlyMemory LoadBytecode(D2D1ShaderProfile shaderProfile, D2D1CompileOptions compileOptions) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions)); @@ -217,7 +216,7 @@ public static class D2D1PixelShader D2D1CompileOptions? requestedCompileOptions, out D2D1ShaderProfile effectiveShaderProfile, out D2D1CompileOptions effectiveCompileOptions) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -250,7 +249,7 @@ public static class D2D1PixelShader D2D1CompileOptions? requestedCompileOptions, out D2D1ShaderProfile effectiveShaderProfile, out D2D1CompileOptions effectiveCompileOptions) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -275,7 +274,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the pixel options for. /// The pixel options for the D2D1 pixel shader of type . public static D2D1PixelOptions GetPixelOptions() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -288,7 +287,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the input count for. /// The number of inputs for the D2D1 pixel shader of type . public static int GetInputCount() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -301,7 +300,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the resource texture count for. /// The number of resource texture for the D2D1 pixel shader of type . public static int GetResourceTextureCount() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -314,7 +313,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the input types for. /// The input types of the target D2D1 pixel shader. public static ReadOnlyMemory GetInputTypes() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -327,7 +326,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the input descriptions for. /// A with the available input descriptions for the shader. public static ReadOnlyMemory GetInputDescriptions() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -340,7 +339,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the resource texture descriptions for. /// A with the available resource texture descriptions for the shader. public static ReadOnlyMemory GetResourceTextureDescriptions() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -353,7 +352,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the output buffer precision for. /// The output buffer precision for the D2D1 pixel shader of type . public static D2D1BufferPrecision GetOutputBufferPrecision() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -366,7 +365,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to get the output buffer channel depth for. /// The output buffer channel depth for the D2D1 pixel shader of type . public static D2D1ChannelDepth GetOutputBufferChannelDepth() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -383,11 +382,11 @@ public static class D2D1PixelShader /// This method will allocate a buffer every time it is invoked. /// For a zero-allocation alternative, use . public static ReadOnlyMemory GetConstantBuffer(in T shader) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { - D2D1ByteArrayDispatchDataLoader dataLoader = default; + D2D1ByteArrayConstantBufferLoader dataLoader = default; - Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader); + Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader); return dataLoader.GetResultingDispatchData(); } @@ -398,7 +397,7 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader to retrieve info for. /// The size of the constant buffer for a D2D1 pixel shader of type . public static int GetConstantBufferSize() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -414,7 +413,7 @@ public static class D2D1PixelShader /// The number of bytes written into . /// Thrown if is not large enough to contain the constant buffer. public static int GetConstantBuffer(in T shader, Span span) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { if (!TryGetConstantBuffer(in shader, span, out int writtenBytes)) { @@ -433,13 +432,13 @@ public static class D2D1PixelShader /// The number of bytes written into . /// Whether or not the constant buffer was retrieved successfully. public static unsafe bool TryGetConstantBuffer(in T shader, Span span, out int bytesWritten) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { fixed (byte* buffer = span) { - D2D1ByteBufferDispatchDataLoader dataLoader = new(buffer, span.Length); + D2D1ByteBufferConstantBufferLoader dataLoader = new(buffer, span.Length); - Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader); + Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader); return dataLoader.TryGetWrittenBytes(out bytesWritten); } @@ -454,12 +453,12 @@ public static class D2D1PixelShader /// Thrown if is . /// For more info, see . public static unsafe void SetConstantBufferForD2D1DrawInfo(void* d2D1DrawInfo, in T shader) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentNullException).ThrowIfNull(d2D1DrawInfo); - D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo); + D2D1DrawInfoConstantBufferLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo); - Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader); + Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader); } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs index add62e86..71ac7af4 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Interop.Effects; using ComputeSharp.D2D1.Shaders.Interop.Buffers; @@ -9,8 +10,6 @@ using ComputeSharp.D2D1.Shaders.Loaders; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Interop; /// @@ -24,7 +23,7 @@ public static unsafe class D2D1PixelShaderEffect /// The type of D2D1 pixel shader to get the effect id for. /// The effect id of the D2D effect using shaders. public static ref readonly Guid GetEffectId() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -37,7 +36,7 @@ public static unsafe class D2D1PixelShaderEffect /// The type of D2D1 pixel shader to get the effect display name for. /// The effect display name of the D2D effect using shaders, if available. public static string? GetEffectDisplayName() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -50,7 +49,7 @@ public static unsafe class D2D1PixelShaderEffect /// The type of D2D1 pixel shader to get the effect description for. /// The effect description of the D2D effect using shaders, if available. public static string? GetEffectDescription() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -63,7 +62,7 @@ public static unsafe class D2D1PixelShaderEffect /// The type of D2D1 pixel shader to get the effect category for. /// The effect category of the D2D effect using shaders, if available. public static string? GetEffectCategory() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -76,7 +75,7 @@ public static unsafe class D2D1PixelShaderEffect /// The type of D2D1 pixel shader to get the effect author for. /// The effect author of the D2D effect using shaders, if available. public static string? GetEffectAuthor() - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); @@ -96,7 +95,7 @@ public static unsafe class D2D1PixelShaderEffect /// For more info, see . /// public static void RegisterForD2D1Factory1(void* d2D1Factory1, out Guid effectId) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentNullException).ThrowIfNull(d2D1Factory1); @@ -345,7 +344,7 @@ public static unsafe class D2D1PixelShaderEffect /// For more info, see . /// public static ReadOnlyMemory GetRegistrationBlob(out Guid effectId) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { ArrayPoolBufferWriter writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize); @@ -560,7 +559,7 @@ public static unsafe class D2D1PixelShaderEffect /// /// For more info, see . public static void CreateFromD2D1DeviceContext(void* d2D1DeviceContext, void** d2D1Effect) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentNullException).ThrowIfNull(d2D1DeviceContext); default(ArgumentNullException).ThrowIfNull(d2D1Effect); @@ -582,13 +581,13 @@ public static unsafe class D2D1PixelShaderEffect /// Thrown if is . /// For more info, see . public static void SetConstantBufferForD2D1Effect(void* d2D1Effect, in T shader) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentNullException).ThrowIfNull(d2D1Effect); - D2D1EffectDispatchDataLoader dataLoader = new((ID2D1Effect*)d2D1Effect); + D2D1EffectConstantBufferLoader dataLoader = new((ID2D1Effect*)d2D1Effect); - Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader); + Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader); } /// @@ -662,7 +661,7 @@ public static unsafe class D2D1PixelShaderEffect /// Thrown if or are . /// For more info, see . public static void SetTransformMapperForD2D1Effect(void* d2D1Effect, D2D1TransformMapper transformMapper) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { default(ArgumentNullException).ThrowIfNull(d2D1Effect); default(ArgumentNullException).ThrowIfNull(transformMapper); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs index 8be0483b..2141af17 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs @@ -1,12 +1,11 @@ using System; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Shaders.Translation; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Interop; /// @@ -28,7 +27,7 @@ public static class D2D1ReflectionServices /// /// public static unsafe D2D1ShaderInfo GetShaderInfo() - where T : struct, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { Unsafe.SkipInit(out T shader); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs index 1e065117..aeef84c0 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs @@ -1,5 +1,6 @@ using System; using System.Numerics; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Shaders.Interop.Factories; namespace ComputeSharp.D2D1.Interop; @@ -9,7 +10,7 @@ namespace ComputeSharp.D2D1.Interop; /// /// The type of D2D1 pixel shader associated to the transform mapper. public static class D2D1TransformMapperFactory - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// Creates an instance for an inflate transform. diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapper{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapper{T}.cs index 21db7412..524fcda4 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapper{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapper{T}.cs @@ -2,6 +2,7 @@ using System; using System.Drawing; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop.Effects; using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers; using TerraFX.Interop.Windows; @@ -94,7 +95,7 @@ namespace ComputeSharp.D2D1.Interop; /// /// public abstract unsafe class D2D1TransformMapper : ICustomQueryInterface, ID2D1TransformMapperInterop - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The object wrapped by the current instance. diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs index 133025da..d9eba121 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using ComputeSharp.D2D1.Descriptors; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; #if !NET6_0_OR_GREATER @@ -27,7 +28,7 @@ internal unsafe partial struct PixelShaderEffect /// /// The type of shader. public sealed class For - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The wrapper for the shader factory. diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T, TParameters}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T,TParameters}.cs similarity index 97% rename from src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T, TParameters}.cs rename to src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T,TParameters}.cs index 774f063c..34fcf9ba 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T, TParameters}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T,TParameters}.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Interop.Helpers; @@ -12,7 +13,7 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract; /// The type of D2D1 pixel shader associated to the transform mapper. /// The type of parameters that the transform mapper will use. internal abstract class D2D1TransformMapper : D2D1TransformMapper - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor where TParameters : unmanaged { /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1AffineTransformMapper{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1AffineTransformMapper{T}.cs index a87f958d..33c15902 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1AffineTransformMapper{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1AffineTransformMapper{T}.cs @@ -1,6 +1,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract; using ComputeSharp.D2D1.Shaders.Interop.Helpers; @@ -80,7 +81,7 @@ file static class D2D1AffineTransformMapper /// /// The type of D2D1 pixel shader associated to the transform mapper. internal abstract class D2D1AffineTransformMapper : D2D1TransformMapper - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// protected sealed override void TransformInputToOutput(in Matrix3x2 parameters, ref Rectangle64 rectangle) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1InflateTransformMapper{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1InflateTransformMapper{T}.cs index c01e4591..ba955962 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1InflateTransformMapper{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1InflateTransformMapper{T}.cs @@ -1,3 +1,4 @@ +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract; using ComputeSharp.D2D1.Shaders.Interop.Helpers; @@ -9,7 +10,7 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Factories; /// /// The type of D2D1 pixel shader associated to the transform mapper. internal abstract class D2D1InflateTransformMapper : D2D1TransformMapper - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// protected sealed override void TransformInputToOutput(in (int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle) diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayConstantBufferLoader.cs similarity index 78% rename from src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayConstantBufferLoader.cs index b3cc46f4..95f820c4 100644 --- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayConstantBufferLoader.cs @@ -1,16 +1,14 @@ using System; using System.Runtime.CompilerServices; -using ComputeSharp.D2D1.__Internals; +using ComputeSharp.D2D1.Descriptors; using TerraFX.Interop.DirectX; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders dispatched via . /// -internal struct D2D1ByteArrayDispatchDataLoader : ID2D1DispatchDataLoader +internal struct D2D1ByteArrayConstantBufferLoader : ID2D1ConstantBufferLoader { /// /// The resulting array with the constant buffer to use. @@ -28,7 +26,7 @@ internal struct D2D1ByteArrayDispatchDataLoader : ID2D1DispatchDataLoader } /// - void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) + void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan data) { this.data = data.ToArray(); } diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteBufferDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteBufferConstantBufferLoader.cs similarity index 84% rename from src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteBufferDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteBufferConstantBufferLoader.cs index 087ac7da..0225b6cd 100644 --- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteBufferDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteBufferConstantBufferLoader.cs @@ -1,16 +1,14 @@ using System; using System.Runtime.CompilerServices; -using ComputeSharp.D2D1.__Internals; +using ComputeSharp.D2D1.Descriptors; using TerraFX.Interop.DirectX; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders dispatched via . /// -internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoader +internal unsafe struct D2D1ByteBufferConstantBufferLoader : ID2D1ConstantBufferLoader { /// /// The target buffer to write data to. @@ -28,12 +26,12 @@ internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoade private int writtenBytes; /// - /// Creates a new instance. + /// Creates a new instance. /// /// The target buffer to write data to. /// The length of the buffer pointed to by . [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal D2D1ByteBufferDispatchDataLoader(byte* buffer, int length) + internal D2D1ByteBufferConstantBufferLoader(byte* buffer, int length) { this.buffer = buffer; this.length = length; @@ -65,7 +63,7 @@ internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoade } /// - void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) + void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan data) { if (data.TryCopyTo(new Span(this.buffer, this.length))) { diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoConstantBufferLoader.cs similarity index 70% rename from src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoConstantBufferLoader.cs index 88bf71d0..49fc96d1 100644 --- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoConstantBufferLoader.cs @@ -1,18 +1,16 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using ComputeSharp.D2D1.__Internals; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.DirectX; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders dispatched via . /// -internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDataLoader +internal readonly unsafe struct D2D1DrawInfoConstantBufferLoader : ID2D1ConstantBufferLoader { /// /// The object in use. @@ -20,17 +18,17 @@ internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDa private readonly ID2D1DrawInfo* d2D1DrawInfo; /// - /// Creates a new instance. + /// Creates a new instance. /// /// The object to use. [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal D2D1DrawInfoDispatchDataLoader(ID2D1DrawInfo* d2D1DrawInfo) + internal D2D1DrawInfoConstantBufferLoader(ID2D1DrawInfo* d2D1DrawInfo) { this.d2D1DrawInfo = d2D1DrawInfo; } /// - void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) + void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan data) { this.d2D1DrawInfo->SetPixelShaderConstantBuffer( buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)), diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoUpdateContextDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoUpdateContextConstantBufferLoader.cs similarity index 70% rename from src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoUpdateContextDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoUpdateContextConstantBufferLoader.cs index 74a3690d..7a746016 100644 --- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoUpdateContextDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoUpdateContextConstantBufferLoader.cs @@ -1,18 +1,16 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using ComputeSharp.D2D1.__Internals; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders to be passed onto an object. /// -internal readonly unsafe struct D2D1DrawInfoUpdateContextDispatchDataLoader : ID2D1DispatchDataLoader +internal readonly unsafe struct D2D1DrawInfoUpdateContextConstantBufferLoader : ID2D1ConstantBufferLoader { /// /// The object in use. @@ -20,17 +18,17 @@ internal readonly unsafe struct D2D1DrawInfoUpdateContextDispatchDataLoader : ID private readonly ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext; /// - /// Creates a new instance. + /// Creates a new instance. /// /// The object to use. [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal D2D1DrawInfoUpdateContextDispatchDataLoader(ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext) + internal D2D1DrawInfoUpdateContextConstantBufferLoader(ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext) { this.d2D1DrawInfoUpdateContext = d2D1DrawInfoUpdateContext; } /// - void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) + void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan data) { this.d2D1DrawInfoUpdateContext->SetConstantBuffer( buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)), diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectConstantBufferLoader.cs similarity index 73% rename from src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectConstantBufferLoader.cs index 0f8c809f..267c4747 100644 --- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectConstantBufferLoader.cs @@ -1,18 +1,16 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using ComputeSharp.D2D1.__Internals; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.DirectX; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders dispatched via . /// -internal readonly unsafe struct D2D1EffectDispatchDataLoader : ID2D1DispatchDataLoader +internal readonly unsafe struct D2D1EffectConstantBufferLoader : ID2D1ConstantBufferLoader { /// /// The object in use. @@ -20,17 +18,17 @@ internal readonly unsafe struct D2D1EffectDispatchDataLoader : ID2D1DispatchData private readonly ID2D1Effect* d2D1Effect; /// - /// Creates a new instance. + /// Creates a new instance. /// /// The object to use. [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal D2D1EffectDispatchDataLoader(ID2D1Effect* d2D1Effect) + internal D2D1EffectConstantBufferLoader(ID2D1Effect* d2D1Effect) { this.d2D1Effect = d2D1Effect; } /// - void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) + void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan data) { if (data.IsEmpty) { From 1a94d017bb7baea1c5b3c74d2d97c10ccb7b2816 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 16:47:16 +0200 Subject: [PATCH 2/5] Update generator to implement ID2D1PixelShaderDescriptor --- ...Generator.CreateEffectIdProperty.Syntax.cs | 2 +- ...r.CreateEffectMetadataProperties.Syntax.cs | 13 ++++++----- ...nerator.CreateHlslSourceProperty.Syntax.cs | 2 +- ...InitializeFromDispatchDataMethod.Syntax.cs | 6 +++-- ....CreateInputDescriptionsProperty.Syntax.cs | 2 +- ...nerator.CreateInputTypesProperty.Syntax.cs | 2 +- ...nerator.CreateLoadBytecodeMethod.Syntax.cs | 6 ++--- ...tor.CreateLoadDispatchDataMethod.Syntax.cs | 4 +++- ...enerator.CreateNumericProperties.Syntax.cs | 6 ++--- ...tor.CreateOutputBufferProperties.Syntax.cs | 4 ++-- ...rator.CreatePixelOptionsProperty.Syntax.cs | 2 +- ...ourceTextureDescriptionsProperty.Syntax.cs | 2 +- .../ID2D1ShaderGenerator.cs | 6 ++++- .../Models/HierarchyInfo.cs | 22 +++++++++++++++++-- 14 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs index b9bdcc22..1a783458 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectIdProperty.Syntax.cs @@ -19,7 +19,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine("readonly ref readonly global::System.Guid global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectId"); + writer.WriteLine($"readonly ref readonly global::System.Guid global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.EffectId"); using (writer.WriteBlock()) { diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectMetadataProperties.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectMetadataProperties.Syntax.cs index a5cc487a..860de917 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectMetadataProperties.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateEffectMetadataProperties.Syntax.cs @@ -17,7 +17,7 @@ partial class ID2D1ShaderGenerator /// The instance to write into. public static void WriteEffectDisplayNameSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) { - WriteEffectMetadataSyntax("EffectDisplayName", info.EffectDisplayName, writer); + WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectDisplayName", info.EffectDisplayName, writer); } /// @@ -27,7 +27,7 @@ partial class ID2D1ShaderGenerator /// The instance to write into. public static void WriteEffectDescriptionSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) { - WriteEffectMetadataSyntax("EffectDescription", info.EffectDescription, writer); + WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectDescription", info.EffectDescription, writer); } /// @@ -37,7 +37,7 @@ partial class ID2D1ShaderGenerator /// The instance to write into. public static void WriteEffectCategorySyntax(D2D1ShaderInfo info, IndentedTextWriter writer) { - WriteEffectMetadataSyntax("EffectCategory", info.EffectCategory, writer); + WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectCategory", info.EffectCategory, writer); } /// @@ -47,20 +47,21 @@ partial class ID2D1ShaderGenerator /// The instance to write into. public static void WriteEffectAuthorSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) { - WriteEffectMetadataSyntax("EffectAuthor", info.EffectAuthor, writer); + WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectAuthor", info.EffectAuthor, writer); } /// /// Writes a specified metadata property. /// + /// The qualified name of the shader type. /// The property name to generate. /// The input effect metadata value, if available. /// The instance to write into. - private static void WriteEffectMetadataSyntax(string propertyName, string? metadataValue, IndentedTextWriter writer) + private static void WriteEffectMetadataSyntax(string qualifiedName, string propertyName, string? metadataValue, IndentedTextWriter writer) { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.Write($"readonly string? global::ComputeSharp.D2D1.__Internals.ID2D1Shader.{propertyName} => "); + writer.Write($"readonly string? global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{qualifiedName}>.{propertyName} => "); // Append null or the metadata value as a string literal if (metadataValue is null) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs index e0b0f645..b065bca3 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs @@ -19,7 +19,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine("readonly string global::ComputeSharp.D2D1.__Internals.ID2D1Shader.HlslSource =>"); + writer.WriteLine($"readonly string global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslSource =>"); writer.IncreaseIndent(); writer.WriteLine("\"\"\""); writer.Write(info.HlslInfoKey.HlslSource, isMultiline: true); diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs index e51cbcd2..67398f84 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs @@ -11,15 +11,17 @@ partial class ID2D1ShaderGenerator partial class InitializeFromDispatchData { /// - /// Writes the InitializeFromDispatchData method. + /// Writes the CreateFromConstantBuffer method. /// /// The input instance with gathered shader info. /// The instance to write into. public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) { + string typeName = info.Hierarchy.Hierarchy[0].QualifiedName; + writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine("readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InitializeFromDispatchData(global::System.ReadOnlySpan data)"); + writer.WriteLine($"readonly {typeName} global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.CreateFromConstantBuffer(global::System.ReadOnlySpan data)"); using (writer.WriteBlock()) { diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs index f3dbb302..f7bde651 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs @@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.Write("readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputDescriptions => "); + writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputDescriptions => "); // If there are no input descriptions, just return a default expression. // Otherwise, return the shared array with cached input descriptions. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs index 3f556167..4774ef8f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputTypesProperty.Syntax.cs @@ -19,7 +19,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.Write("readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputTypes => "); + writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputTypes => "); // If there are no inputs, simply return a default expression. Otherwise, create // a ReadOnlyMemory instance from the memory manager. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index 76f2b105..9f6d3708 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.EffectiveShaderProfile};"); + writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.EffectiveShaderProfile};"); } /// @@ -41,7 +41,7 @@ partial class ID2D1ShaderGenerator writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.__Internals.ID2D1Shader.CompileOptions => {compileOptionsExpression};"); + writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.CompileOptions => {compileOptionsExpression};"); } /// @@ -53,7 +53,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.Write("readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.__Internals.ID2D1Shader.HlslBytecode => "); + writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslBytecode => "); // If there is no bytecode, just return a default expression. // Otherwise, return the memory manager backed memory instance. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index 7ec8edb3..f4301f36 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -18,9 +18,11 @@ partial class ID2D1ShaderGenerator /// The instance to write into. public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer) { + string typeName = info.Hierarchy.Hierarchy[0].QualifiedName; + writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine("readonly unsafe void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadDispatchData(ref TLoader loader)"); + writer.WriteLine($"readonly unsafe void global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.LoadConstantBuffer(in {typeName} shader, ref TLoader loader)"); using (writer.WriteBlock()) { diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs index 1bb81881..4c9ca529 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs @@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); + writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); } /// @@ -33,7 +33,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputCount => {info.InputTypes.Length};"); + writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputCount => {info.InputTypes.Length};"); } /// @@ -45,7 +45,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ResourceTextureCount => {info.ResourceTextureDescriptions.Length};"); + writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceTextureCount => {info.ResourceTextureDescriptions.Length};"); } } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateOutputBufferProperties.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateOutputBufferProperties.Syntax.cs index ca889f0e..6d536f8c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateOutputBufferProperties.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateOutputBufferProperties.Syntax.cs @@ -28,7 +28,7 @@ partial class ID2D1ShaderGenerator writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1BufferPrecision global::ComputeSharp.D2D1.__Internals.ID2D1Shader.BufferPrecision => {bufferPrecisionExpression};"); + writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1BufferPrecision global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.BufferPrecision => {bufferPrecisionExpression};"); } /// @@ -47,7 +47,7 @@ partial class ID2D1ShaderGenerator writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ChannelDepth global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ChannelDepth => {channelDepthExpression};"); + writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ChannelDepth global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ChannelDepth => {channelDepthExpression};"); } } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreatePixelOptionsProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreatePixelOptionsProperty.Syntax.cs index f5207ece..a87afa5a 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreatePixelOptionsProperty.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreatePixelOptionsProperty.Syntax.cs @@ -26,7 +26,7 @@ partial class ID2D1ShaderGenerator writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.__Internals.ID2D1Shader.PixelOptions => {pixelOptionsExpression};"); + writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.PixelOptions => {pixelOptionsExpression};"); } } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.Syntax.cs index d24e6673..94d202a3 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.Syntax.cs @@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.Write("readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ResourceTextureDescriptions => "); + writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceTextureDescriptions => "); // If there are no resource texture descriptions, just return a default expression. // Otherwise, return a memory instance from the generated static readonly array. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index ec56e55b..317238a5 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -227,7 +227,11 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator using IndentedTextWriter writer = IndentedTextWriter.Rent(); - item.Hierarchy.WriteSyntax(item, writer, declaredMembers.WrittenSpan); + item.Hierarchy.WriteSyntax( + state: item, + writer: writer, + baseTypes: new[] { $"global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{item.Hierarchy.Hierarchy[0].QualifiedName}>" }, + memberCallbacks: declaredMembers.WrittenSpan); // If any generated types are needed, they go into a separate namespace // This allows the code to use using directives without any conflicts. diff --git a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs index 7ab7f352..1ce487c3 100644 --- a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs @@ -48,8 +48,13 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName, /// The type of state to pass to callbacks. /// The input state to pass to callbacks. /// The target instance to write text to. + /// A list of base types to add to the generated type, if any. /// The callbacks to use to write members into the declared type. - public void WriteSyntax(T state, IndentedTextWriter writer, ReadOnlySpan> memberCallbacks) + public void WriteSyntax( + T state, + IndentedTextWriter writer, + ReadOnlySpan baseTypes, + ReadOnlySpan> memberCallbacks) { // Write the generated file header writer.WriteLine("// "); @@ -68,7 +73,20 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName, for (int i = Hierarchy.Length - 1; i >= 0; i--) { writer.WriteLine($$"""/// """); - writer.WriteLine($$"""partial {{Hierarchy[i].GetTypeKeyword()}} {{Hierarchy[i].QualifiedName}}"""); + writer.Write($$"""partial {{Hierarchy[i].GetTypeKeyword()}} {{Hierarchy[i].QualifiedName}}"""); + + // Add any base types, if needed + if (i == 0 && !baseTypes.IsEmpty) + { + writer.Write(" : "); + writer.WriteInitializationExpressions(baseTypes, static (item, writer) => writer.Write(item)); + writer.WriteLine(); + } + else + { + writer.WriteLine(); + } + writer.WriteLine($$"""{"""); writer.IncreaseIndent(); } From 76df248427edd49bc30a5b3e1462dd6039c99556 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 17:10:51 +0200 Subject: [PATCH 3/5] Update constant buffer marshalling methods in generator --- ...InitializeFromDispatchDataMethod.Syntax.cs | 35 ++++++++++--------- ...tor.CreateLoadDispatchDataMethod.Syntax.cs | 2 ++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs index 67398f84..ec970a6e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs @@ -21,27 +21,24 @@ partial class ID2D1ShaderGenerator writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); - writer.WriteLine($"readonly {typeName} global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.CreateFromConstantBuffer(global::System.ReadOnlySpan data)"); + writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]"); + writer.WriteLine($"readonly unsafe {typeName} global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.CreateFromConstantBuffer(global::System.ReadOnlySpan data)"); using (writer.WriteBlock()) { - // If there are no fields, the method body is just empty + // If there are no fields, just return an empty shader (TODO: add length check on .NET 8) if (info.Fields.IsEmpty) { + writer.WriteLine("return default;"); + return; } - // Insert the fallback for empty shaders. This will generate the following code: - writer.WriteLine("if (data.IsEmpty)"); - - using (writer.WriteBlock()) - { - writer.WriteLine("return;"); - } - - // Get a reference to the data through the generated native layout type + // Get a reference to the data through the generated native layout type and define the shader + writer.WriteLine($"ref readonly global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer = ref global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));"); + writer.WriteLine(); + writer.WriteLine($"{typeName} shader;"); writer.WriteLine(); - writer.WriteLine("ref readonly global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer = ref global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));"); // Generate loading statements for each captured field foreach (FieldInfo fieldInfo in info.Fields) @@ -51,7 +48,7 @@ partial class ID2D1ShaderGenerator case FieldInfo.Primitive primitive: // Read a primitive value - writer.WriteLine($"global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.{string.Join(".", primitive.FieldPath)}) = buffer.{string.Join("_", primitive.FieldPath)};"); + writer.WriteLine($"*&shader.{string.Join(".", primitive.FieldPath)} = buffer.{string.Join("_", primitive.FieldPath)};"); break; case FieldInfo.NonLinearMatrix matrix: @@ -60,18 +57,22 @@ partial class ID2D1ShaderGenerator // Read all rows of a given matrix type: // - // global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.)[0] = buffer.; - // global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.)[1] = buffer.; + // (*&shader.)[0] = buffer.; + // (*&shader.)[1] = buffer.; // ... - // global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.)[N] = buffer.; + // (*&shader.)[N] = buffer.; for (int j = 0; j < matrix.Rows; j++) { - writer.WriteLine($"global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.{fieldPath})[{j}] = buffer.{fieldNamePrefix}_{j};"); + writer.WriteLine($"(*&shader.{fieldPath})[{j}] = buffer.{fieldNamePrefix}_{j};"); } break; } } + + // Return the populated shader + writer.WriteLine(); + writer.WriteLine("return shader;"); } } } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index f4301f36..f327dded 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -22,6 +22,7 @@ partial class ID2D1ShaderGenerator writer.WriteLine("/// "); writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator)); + writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]"); writer.WriteLine($"readonly unsafe void global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.LoadConstantBuffer(in {typeName} shader, ref TLoader loader)"); using (writer.WriteBlock()) @@ -34,6 +35,7 @@ partial class ID2D1ShaderGenerator else { writer.WriteLine("global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer;"); + writer.WriteLine(); // Generate loading statements for each captured field foreach (FieldInfo fieldInfo in info.Fields) From 0fb876fde0e5c8a3e9e38285e183dfb301a260bf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 17:18:10 +0200 Subject: [PATCH 4/5] Update Win2D method signatures in all projects --- .../Shaders/PixelShaderEffect.cs | 3 ++- .../Backend/PixelShaderEffect.cs | 3 ++- .../Extensions/ID2D1EffectExtensions.cs | 11 +++++------ ...{T}.Properties.ResourceTextureManagerCollection.cs | 2 +- src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs | 3 ++- .../ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs | 9 +++++---- tests/ComputeSharp.D2D1.Tests/ShadersTests.cs | 3 ++- tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs | 5 +++-- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs index 125c6e68..ddee56ac 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs @@ -1,5 +1,6 @@ using System; using ComputeSharp.D2D1; +using ComputeSharp.D2D1.Descriptors; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp; #else @@ -62,7 +63,7 @@ public abstract class PixelShaderEffect : CanvasEffect /// /// The type of pixel shader to render. public sealed class For : PixelShaderEffect - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The node in use. diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs index b6ccd257..c31a4a82 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs @@ -1,5 +1,6 @@ using System; using ComputeSharp.D2D1; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.WinUI; namespace ComputeSharp.SwapChain.D2D1.Backend; @@ -56,7 +57,7 @@ internal abstract class PixelShaderEffect : CanvasEffect /// /// The type of pixel shader to render. public sealed class For : PixelShaderEffect - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The node in use. diff --git a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs index d4d40ebb..86133bab 100644 --- a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs @@ -2,6 +2,7 @@ using System; using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; @@ -9,8 +10,6 @@ using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; -#pragma warning disable CS0618 - #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; #else @@ -29,7 +28,7 @@ internal static unsafe class ID2D1EffectExtensions /// The input instance. /// The constant buffer of type for . public static T GetConstantBuffer(this ref ID2D1Effect d2D1Effect) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { int constantBufferSize = D2D1PixelShader.GetConstantBufferSize(); @@ -55,7 +54,7 @@ internal static unsafe class ID2D1EffectExtensions Unsafe.SkipInit(out T shader); - shader.InitializeFromDispatchData(buffer.AsSpan(0, constantBufferSize)); + shader = shader.CreateFromConstantBuffer(buffer.AsSpan(0, constantBufferSize)); ArrayPool.Shared.Return(buffer); @@ -69,7 +68,7 @@ internal static unsafe class ID2D1EffectExtensions /// The input instance. /// The constant buffer value to set. public static void SetConstantBuffer(this ref ID2D1Effect d2D1Effect, in T value) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { // Same as above, simply do nothing for empty types. This case is still handled to // avoid crashing when someone's just setting an empty constant buffer, which is @@ -90,7 +89,7 @@ internal static unsafe class ID2D1EffectExtensions /// The input instance. /// The instance for . public static D2D1TransformMapper? GetTransformMapper(this ref ID2D1Effect d2D1Effect) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { using ComPtr d2D1TransformMapper = default; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index 8a7cd163..5b47ee1d 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -13,7 +13,7 @@ using ComputeSharp.D2D1.WinUI.Buffers; using ComputeSharp.D2D1.WinUI.Collections; #endif -#pragma warning disable CS0618, CS8767 +#pragma warning disable CS8767 #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs index b9700090..863d7176 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; #endif using ABI.Microsoft.Graphics.Canvas; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.Interop; using Microsoft.Graphics.Canvas; @@ -20,7 +21,7 @@ namespace ComputeSharp.D2D1.WinUI; /// /// The type of shader to use to render frames. public sealed partial class PixelShaderEffect : IReferenceTrackedObject, ICanvasEffect, ICanvasImageInterop.Interface - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The value for the current instance. diff --git a/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs b/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs index 919a763f..fd1de7f8 100644 --- a/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs +++ b/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.Tests.Helpers; using Win32; @@ -32,7 +33,7 @@ internal static class D2D1TestRunner string expectedFileName, [CallerMemberName] string destinationFileName = "", float threshold = 0.00001f) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets"); string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp"); @@ -73,7 +74,7 @@ internal static class D2D1TestRunner [CallerMemberName] string destinationFileName = "", float threshold = 0.00001f, params (int Index, D2D1ResourceTextureManager ResourceTextureManager)[] resourceTextures) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets"); string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp"); @@ -109,7 +110,7 @@ internal static class D2D1TestRunner D2D1TransformMapper? transformMapper, string sourcePath, string destinationPath) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { using ComPtr d2D1Factory2 = D2D1Helper.CreateD2D1Factory2(); using ComPtr d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get()); @@ -158,7 +159,7 @@ internal static class D2D1TestRunner int height, string destinationPath, params (int Index, D2D1ResourceTextureManager ResourceTextureManager)[] resourceTextures) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { using ComPtr d2D1Factory2 = D2D1Helper.CreateD2D1Factory2(); using ComPtr d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get()); diff --git a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs index 2c05cc1c..c171a6fb 100644 --- a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Tests.Helpers; using ComputeSharp.SwapChain.Shaders.D2D1; @@ -114,7 +115,7 @@ public class ShadersTests } private static void RunTest(float threshold = 0.00001f) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs index 9a4a8b86..bcc474da 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.UI.Tests.Helpers; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp; @@ -79,7 +80,7 @@ public class ShadersTests } private static async Task RunTestAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(WrapperType wrapperType, float threshold = 0.00001f) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; @@ -118,7 +119,7 @@ public class ShadersTests } private sealed class TestCanvasEffect : CanvasEffect - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { private static readonly EffectNode> Effect = new(); From c9cb83724a85948db32b247aeb58fa6501b68fcd Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 17:21:09 +0200 Subject: [PATCH 5/5] Rename and update D2D1 generator files --- ...eCreateFromConstantBufferMethod.Syntax.cs} | 2 +- ...or.CreateHlslBytecodeProperties.Syntax.cs} | 2 +- ...Generator.CreateHlslBytecodeProperties.cs} | 4 +-- ....CreateLoadConstantBufferMethod.Syntax.cs} | 4 +-- ...nerator.CreateLoadConstantBufferMethod.cs} | 4 +-- .../ID2D1ShaderGenerator.cs | 30 +++++++++---------- 6 files changed, 23 insertions(+), 23 deletions(-) rename src/ComputeSharp.D2D1.SourceGenerators/{ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs => ID2D1ShaderGenerator.CreateCreateFromConstantBufferMethod.Syntax.cs} (98%) rename src/ComputeSharp.D2D1.SourceGenerators/{ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs => ID2D1ShaderGenerator.CreateHlslBytecodeProperties.Syntax.cs} (99%) rename src/ComputeSharp.D2D1.SourceGenerators/{ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs => ID2D1ShaderGenerator.CreateHlslBytecodeProperties.cs} (98%) rename src/ComputeSharp.D2D1.SourceGenerators/{ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs => ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.Syntax.cs} (98%) rename src/ComputeSharp.D2D1.SourceGenerators/{ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs => ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.cs} (98%) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateCreateFromConstantBufferMethod.Syntax.cs similarity index 98% rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateCreateFromConstantBufferMethod.Syntax.cs index ec970a6e..66084b04 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateCreateFromConstantBufferMethod.Syntax.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.D2D1.SourceGenerators; partial class ID2D1ShaderGenerator { /// - partial class InitializeFromDispatchData + partial class CreateFromConstantBuffer { /// /// Writes the CreateFromConstantBuffer method. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslBytecodeProperties.Syntax.cs similarity index 99% rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslBytecodeProperties.Syntax.cs index 9f6d3708..6c2b84c7 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslBytecodeProperties.Syntax.cs @@ -10,7 +10,7 @@ namespace ComputeSharp.D2D1.SourceGenerators; partial class ID2D1ShaderGenerator { /// - partial class LoadBytecode + partial class HlslBytecode { /// /// Writes the ShaderProfile property. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslBytecodeProperties.cs similarity index 98% rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslBytecodeProperties.cs index 876be56c..fcf764fa 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslBytecodeProperties.cs @@ -21,9 +21,9 @@ namespace ComputeSharp.D2D1.SourceGenerators; partial class ID2D1ShaderGenerator { /// - /// A helper with all logic to generate the LoadBytecode method. + /// A helper with all logic to generate the HLSL bytecode properties. /// - internal static partial class LoadBytecode + internal static partial class HlslBytecode { /// /// The shared cache of values. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.Syntax.cs similarity index 98% rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.Syntax.cs index f327dded..f5e58d3e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.Syntax.cs @@ -9,10 +9,10 @@ namespace ComputeSharp.D2D1.SourceGenerators; partial class ID2D1ShaderGenerator { /// - partial class LoadDispatchData + partial class LoadConstantBuffer { /// - /// Writes the LoadDispatchData method. + /// Writes the LoadConstantBuffer method. /// /// The input instance with gathered shader info. /// The instance to write into. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.cs similarity index 98% rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.cs index 46c83eb2..dc12107f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadConstantBufferMethod.cs @@ -18,9 +18,9 @@ namespace ComputeSharp.D2D1.SourceGenerators; partial class ID2D1ShaderGenerator { /// - /// A helper with all logic to generate the LoadDispatchData method. + /// A helper with all logic to generate the LoadConstantBuffer method. /// - private static partial class LoadDispatchData + private static partial class LoadConstantBuffer { /// /// Explores a given type hierarchy and generates statements to load fields. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 317238a5..810264f2 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -74,7 +74,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator using ImmutableArrayBuilder diagnostics = ImmutableArrayBuilder.Rent(); // LoadDispatchData() info - ImmutableArray fieldInfos = LoadDispatchData.GetInfo( + ImmutableArray fieldInfos = LoadConstantBuffer.GetInfo( diagnostics, typeSymbol, out int constantBufferSizeInBytes); @@ -132,11 +132,11 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator token.ThrowIfCancellationRequested(); // Get the shader profile and linking info for LoadBytecode() - bool isLinkingSupported = LoadBytecode.IsSimpleInputShader(typeSymbol, inputCount); - D2D1ShaderProfile? requestedShaderProfile = LoadBytecode.GetRequestedShaderProfile(typeSymbol); - D2D1CompileOptions? requestedCompileOptions = LoadBytecode.GetRequestedCompileOptions(diagnostics, typeSymbol); - D2D1ShaderProfile effectiveShaderProfile = LoadBytecode.GetEffectiveShaderProfile(requestedShaderProfile); - D2D1CompileOptions effectiveCompileOptions = LoadBytecode.GetEffectiveCompileOptions(requestedCompileOptions, isLinkingSupported); + bool isLinkingSupported = HlslBytecode.IsSimpleInputShader(typeSymbol, inputCount); + D2D1ShaderProfile? requestedShaderProfile = HlslBytecode.GetRequestedShaderProfile(typeSymbol); + D2D1CompileOptions? requestedCompileOptions = HlslBytecode.GetRequestedCompileOptions(diagnostics, typeSymbol); + D2D1ShaderProfile effectiveShaderProfile = HlslBytecode.GetEffectiveShaderProfile(requestedShaderProfile); + D2D1CompileOptions effectiveCompileOptions = HlslBytecode.GetEffectiveCompileOptions(requestedCompileOptions, isLinkingSupported); bool hasErrors = diagnostics.Count > 0; token.ThrowIfCancellationRequested(); @@ -152,12 +152,12 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator hasErrors); // TODO: cache this across transform runs - HlslBytecodeInfo hlslInfo = LoadBytecode.GetInfo(ref hlslInfoKey, token); + HlslBytecodeInfo hlslInfo = HlslBytecode.GetInfo(ref hlslInfoKey, token); token.ThrowIfCancellationRequested(); // Append any diagnostic for the shader compilation - LoadBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics); + HlslBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics); token.ThrowIfCancellationRequested(); @@ -210,20 +210,20 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator declaredMembers.Add(PixelOptions.WriteSyntax); declaredMembers.Add(OutputBuffer.WriteBufferPrecisionSyntax); declaredMembers.Add(OutputBuffer.WriteChannelDepthSyntax); - declaredMembers.Add(LoadBytecode.WriteShaderProfileSyntax); - declaredMembers.Add(LoadBytecode.WriteCompileOptionsSyntax); + declaredMembers.Add(HlslBytecode.WriteShaderProfileSyntax); + declaredMembers.Add(HlslBytecode.WriteCompileOptionsSyntax); declaredMembers.Add(HlslSource.WriteSyntax); - declaredMembers.Add(LoadBytecode.WriteHlslBytecodeSyntax); - declaredMembers.Add(InitializeFromDispatchData.WriteSyntax); - declaredMembers.Add(LoadDispatchData.WriteSyntax); + declaredMembers.Add(HlslBytecode.WriteHlslBytecodeSyntax); + declaredMembers.Add(CreateFromConstantBuffer.WriteSyntax); + declaredMembers.Add(LoadConstantBuffer.WriteSyntax); using ImmutableArrayBuilder> additionalTypes = ImmutableArrayBuilder>.Rent(); using ImmutableHashSetBuilder usingDirectives = ImmutableHashSetBuilder.Rent(); - LoadDispatchData.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); + LoadConstantBuffer.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); InputDescriptions.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); InputTypes.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); - LoadBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); + HlslBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); using IndentedTextWriter writer = IndentedTextWriter.Rent();