From 06e5a61af73ec6339567cd05cfed9a2c7a48caf1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 10 Aug 2022 12:20:26 +0200 Subject: [PATCH] Add D2DPixelShaderSourceAttribute type --- .../Attributes/D2DCompileOptionsAttribute.cs | 2 +- .../D2DEmbeddedBytecodeAttribute.cs | 2 +- .../D2DPixelShaderSourceAttribute.cs | 50 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs diff --git a/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs index 232ad1bd..8f02de62 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs @@ -26,7 +26,7 @@ namespace ComputeSharp.D2D1; /// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type. /// /// -[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)] +[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)] public sealed class D2DCompileOptionsAttribute : Attribute { /// diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs index 1a8cf87d..aad92ca2 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs @@ -24,7 +24,7 @@ namespace ComputeSharp.D2D1; /// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type. /// /// -[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)] +[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)] public sealed class D2DEmbeddedBytecodeAttribute : Attribute { /// diff --git a/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs new file mode 100644 index 00000000..80a26c4b --- /dev/null +++ b/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs @@ -0,0 +1,50 @@ +using System; + +namespace ComputeSharp.D2D1; + +/// +/// An attribute that indicates that a given D2D1 shader should be precompiled at build time and embedded +/// directly into the containing assembly as static bytecode, to be retrieved as a . +/// +/// This attribute can be used to annotate methods as follows: +/// +/// [D2DPixelShaderSource(""" +/// #define D2D_INPUT_COUNT 1 +/// #define D2D_INPUT0_SIMPLE +/// +/// #include ""d2d1effecthelpers.hlsli"" +/// +/// D2D_PS_ENTRY(PSMain) +/// { +/// float4 color = D2DGetInput(0); +/// float3 rgb = saturate(1.0 - color.rgb); +/// return float4(rgb, 1); +/// } +/// """")] +/// static partial ReadOnlySpan<byte> GetBytecode(); +/// +/// +/// +/// +/// +/// Methods can also be annotated with and +/// to further customize the shader profile to use when compiling the HLSL source, and the compile options to use. +/// +/// +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public sealed class D2DPixelShaderSourceAttribute : Attribute +{ + /// + /// Creates a new instance of the type with the specified arguments. + /// + /// The number of texture inputs for the shader. + public D2DPixelShaderSourceAttribute(string hlslSource) + { + HlslSource = hlslSource; + } + + /// + /// Gets the number of texture inputs for the shader. + /// + public string HlslSource { get; } +}