From 6fbdef8ce4b20ebe82008349ae2846189f2b7a9d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 8 May 2022 19:10:11 +0200 Subject: [PATCH 1/4] Add D2D1 pixel option types and APIs --- .../ComputeSharp.D2D1.SourceGenerators.csproj | 1 + .../Attributes/D2DPixelOptions.cs | 28 +++++++++++++++++++ .../Attributes/Enums/D2D1PixelOption.cs | 22 +++++++++++++++ .../Interfaces/__Internals/ID2D1Shader.cs | 8 ++++++ .../Shaders/Interop/D2D1PixelShader.cs | 13 +++++++++ 5 files changed, 72 insertions(+) create mode 100644 src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs create mode 100644 src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOption.cs diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 878c9c54..1709d243 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -68,6 +68,7 @@ + diff --git a/src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs b/src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs new file mode 100644 index 00000000..d4b9ad29 --- /dev/null +++ b/src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs @@ -0,0 +1,28 @@ +using System; + +namespace ComputeSharp.D2D1; + +/// +/// An attribute for a D2D1 shader indicating the pixel options to use. +/// Using this attribute is optional when defining a D2D1 shader. +/// +/// +/// For more info, see . +/// +[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] +public sealed class D2DPixelOptionsAttribute : Attribute +{ + /// + /// Creates a new instance of the type with the specified arguments. + /// + /// The options to specify for the shader. + public D2DPixelOptionsAttribute(D2D1PixelOption options) + { + Options = options; + } + + /// + /// Gets the options to specify for the shader. + /// + public D2D1PixelOption Options { get; } +} diff --git a/src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOption.cs b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOption.cs new file mode 100644 index 00000000..d0b52dcb --- /dev/null +++ b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOption.cs @@ -0,0 +1,22 @@ +namespace ComputeSharp.D2D1; + +/// +/// Indicates how the sampling of a D2D1 pixel shader will be restricted. This indicates whether the vertex buffer +/// is large and tends to change infrequently or smaller and changes frequently (typically frame over frame). +/// +/// +/// This type exposes the available values in . +/// +public enum D2D1PixelOption +{ + /// + /// The pixel shader is not restricted in its sampling. + /// + None, + + /// + /// The pixel shader samples inputs only at the same scene coordinate as the output pixel + /// and returns transparent black whenever the input pixels are also transparent black. + /// + TrivialSampling +} diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs index 11cd5ae3..0c4fe02c 100644 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs @@ -19,6 +19,14 @@ public interface ID2D1Shader [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. + /// + /// The pixel options for the current shader. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + uint GetPixelOptions(); + /// /// Gets the number of inputs for the current shader. /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index b0ec5b48..49ab6d7b 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -80,6 +80,19 @@ public static class D2D1PixelShader return new ReadOnlySpan(bytecodePtr, bytecodeSize).ToArray(); } + /// + /// Gets the pixel options from an input D2D1 pixel shader. + /// + /// The type of D2D1 pixel shader to get the pixel options for. + /// The pixel options for the D2D1 pixel shader of type . + public static D2D1PixelOption GetPixelOptions() + where T : unmanaged, ID2D1PixelShader + { + Unsafe.SkipInit(out T shader); + + return (D2D1PixelOption)shader.GetPixelOptions(); + } + /// /// Gets the number of inputs from an input D2D1 pixel shader. /// From b21193288195686ff2126c9e43abd65507f03e6e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 8 May 2022 19:24:11 +0200 Subject: [PATCH 2/4] Enable generation for ID2D1Shader.GetPixelOptions API --- ...ator.CreateGetPixelOptionsMethod.Syntax.cs | 36 +++++++++++++++++++ ...erGenerator.CreateGetPixelOptionsMethod.cs | 31 ++++++++++++++++ .../ID2D1ShaderGenerator.cs | 24 +++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs create mode 100644 src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs new file mode 100644 index 00000000..499462da --- /dev/null +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs @@ -0,0 +1,36 @@ +using ComputeSharp.D2D1.__Internals; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +#pragma warning disable CS0618 + +namespace ComputeSharp.D2D1.SourceGenerators; + +/// +partial class ID2D1ShaderGenerator +{ + /// + partial class GetPixelOptions + { + /// + /// Creates a instance for the GetPixelOptions method. + /// + /// The pixel options for the shader. + /// The resulting instance for the GetPixelOptions method. + public static MethodDeclarationSyntax GetSyntax(D2D1PixelOption pixelOptions) + { + // This code produces a method declaration as follows: + // + // readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetPixelOptions() + // { + // return ; + // } + return + MethodDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)), Identifier(nameof(GetPixelOptions))) + .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}"))) + .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) + .WithBody(Block(ReturnStatement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)pixelOptions))))); + } + } +} diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs new file mode 100644 index 00000000..c4787c3d --- /dev/null +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs @@ -0,0 +1,31 @@ +using ComputeSharp.SourceGeneration.Extensions; +using Microsoft.CodeAnalysis; + +namespace ComputeSharp.D2D1.SourceGenerators; + +/// +partial class ID2D1ShaderGenerator +{ + /// + /// A helper with all logic to generate the GetPixelOptions method. + /// + private static partial class GetPixelOptions + { + /// + /// Extracts the pixel options for the current shader. + /// + /// The input instance to process. + /// The pixel options for the shader. + public static void GetInfo(INamedTypeSymbol structDeclarationSymbol, out D2D1PixelOption pixelOptions) + { + if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute", out AttributeData? attributeData)) + { + pixelOptions = (D2D1PixelOption)attributeData!.ConstructorArguments[0].Value!; + } + else + { + pixelOptions = D2D1PixelOption.None; + } + } + } +} diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index b3314ae2..73b8ac3f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -305,5 +305,29 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadInputDescriptions)}", compilationUnit.ToFullString()); }); + + // Get the pixel options, again independently from other generation steps. + // This can also be immediately cached at a fine grained level. + IncrementalValuesProvider<(HierarchyInfo Hierarchy, D2D1PixelOption Options)> pixelOptionsInfo = + shaderDeclarations + .Select(static (item, token) => + { + // GetPixelOptions() info + GetPixelOptions.GetInfo(item.Symbol, out D2D1PixelOption pixelOptions); + + token.ThrowIfCancellationRequested(); + + return (item.Hierarchy, pixelOptions); + }) + .WithComparers(HierarchyInfo.Comparer.Default, EqualityComparer.Default); + + // Generate the GetPixelOptions() methods + context.RegisterSourceOutput(pixelOptionsInfo, static (context, item) => + { + MethodDeclarationSyntax getPixelOptionsMethod = GetPixelOptions.GetSyntax(item.Options); + CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, getPixelOptionsMethod, false); + + context.AddSource($"{item.Hierarchy.FilenameHint}.{nameof(GetPixelOptions)}", compilationUnit.ToFullString()); + }); } } From a70ae6af3856b85684e5fb2eec3eaf91409e35f5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 8 May 2022 19:45:47 +0200 Subject: [PATCH 3/4] Enable pixel options info in D2D1PixelShaderEffect --- .../Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs | 8 ++++++++ .../PixelShaderEffect.ID2D1DrawTransformMethods.cs | 2 +- .../Shaders/Interop/Effects/PixelShaderEffect.cs | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) 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 57addcbc..575eb61d 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs @@ -64,6 +64,11 @@ internal unsafe partial struct PixelShaderEffect /// private static D2D1InputDescription* inputDescriptions; + /// + /// The pixel options for the shader. + /// + private static D2D1PixelOption pixelOptions; + /// /// The shader bytecode. /// @@ -119,6 +124,7 @@ internal unsafe partial struct PixelShaderEffect byte* bytecode = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For), bytecodeSize); D2D1BufferPrecision bufferPrecision = D2D1PixelShader.GetOutputBufferPrecision(); D2D1ChannelDepth channelDepth = D2D1PixelShader.GetOutputBufferChannelDepth(); + D2D1PixelOption pixelOptions = D2D1PixelShader.GetPixelOptions(); // Prepare the inputs info int inputCount = D2D1PixelShader.GetInputCount(); @@ -145,6 +151,7 @@ internal unsafe partial struct PixelShaderEffect For.inputTypes = inputTypes; For.inputDescriptionCount = inputDescriptionCount; For.inputDescriptions = inputDescriptions; + For.pixelOptions = pixelOptions; For.bytecode = bytecode; For.bytecodeSize = bytecodeSize; For.bufferPrecision = bufferPrecision; @@ -228,6 +235,7 @@ internal unsafe partial struct PixelShaderEffect inputTypes, inputDescriptionCount, inputDescriptions, + pixelOptions, bytecode, bytecodeSize, bufferPrecision, diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs index 89b281e5..f5d73715 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs @@ -324,7 +324,7 @@ partial struct PixelShaderEffect @this->d2D1DrawInfo = drawInfo; // Set the pixel shader for the effect - HRESULT hresult = drawInfo->SetPixelShader(&@this->shaderId); + HRESULT hresult = drawInfo->SetPixelShader(&@this->shaderId, (D2D1_PIXEL_OPTIONS)@this->pixelOptions); if (hresult != S.S_OK) { diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index e330ab71..ae1a8732 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -175,6 +175,11 @@ internal unsafe partial struct PixelShaderEffect /// private D2D1InputDescription* inputDescriptions; + /// + /// The pixel options for the shader. + /// + private D2D1PixelOption pixelOptions; + /// /// The shader bytecode. /// @@ -213,6 +218,7 @@ internal unsafe partial struct PixelShaderEffect /// The buffer with the types of inputs for the shader. /// The number of available input descriptions. /// The buffer with the available input descriptions for the shader. + /// The pixel options for the shader. /// The shader bytecode. /// The size of . /// The buffer precision for the resulting output buffer. @@ -226,6 +232,7 @@ internal unsafe partial struct PixelShaderEffect D2D1PixelShaderInputType* inputTypes, int inputDescriptionCount, D2D1InputDescription* inputDescriptions, + D2D1PixelOption pixelOptions, byte* bytecode, int bytecodeSize, D2D1BufferPrecision bufferPrecision, @@ -245,6 +252,7 @@ internal unsafe partial struct PixelShaderEffect @this->inputTypes = inputTypes; @this->inputDescriptionCount = inputDescriptionCount; @this->inputDescriptions = inputDescriptions; + @this->pixelOptions = pixelOptions; @this->bytecode = bytecode; @this->bytecodeSize = bytecodeSize; @this->bufferPrecision = bufferPrecision; From ec1798cbe3bd7eb718a5fd8f41ae51339055a313 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 8 May 2022 21:33:59 +0200 Subject: [PATCH 4/4] Rename and tweak D2D1PixelOptions type --- .../ComputeSharp.D2D1.SourceGenerators.csproj | 2 +- ...enerator.CreateGetPixelOptionsMethod.Syntax.cs | 2 +- ...ShaderGenerator.CreateGetPixelOptionsMethod.cs | 6 +++--- .../ID2D1ShaderGenerator.cs | 6 +++--- .../Attributes/D2DPixelOptions.cs | 4 ++-- .../{D2D1PixelOption.cs => D2D1PixelOptions.cs} | 15 +++++++++------ .../Shaders/Interop/D2D1PixelShader.cs | 4 ++-- .../Interop/Effects/PixelShaderEffect.For{T}.cs | 4 ++-- .../Shaders/Interop/Effects/PixelShaderEffect.cs | 4 ++-- 9 files changed, 25 insertions(+), 22 deletions(-) rename src/ComputeSharp.D2D1/Attributes/Enums/{D2D1PixelOption.cs => D2D1PixelOptions.cs} (70%) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 1709d243..a430c4ca 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -68,7 +68,7 @@ - + diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs index 499462da..b583ae38 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.Syntax.cs @@ -18,7 +18,7 @@ partial class ID2D1ShaderGenerator /// /// The pixel options for the shader. /// The resulting instance for the GetPixelOptions method. - public static MethodDeclarationSyntax GetSyntax(D2D1PixelOption pixelOptions) + public static MethodDeclarationSyntax GetSyntax(D2D1PixelOptions pixelOptions) { // This code produces a method declaration as follows: // diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs index c4787c3d..d1f52c2c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs @@ -16,15 +16,15 @@ partial class ID2D1ShaderGenerator /// /// The input instance to process. /// The pixel options for the shader. - public static void GetInfo(INamedTypeSymbol structDeclarationSymbol, out D2D1PixelOption pixelOptions) + public static void GetInfo(INamedTypeSymbol structDeclarationSymbol, out D2D1PixelOptions pixelOptions) { if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute", out AttributeData? attributeData)) { - pixelOptions = (D2D1PixelOption)attributeData!.ConstructorArguments[0].Value!; + pixelOptions = (D2D1PixelOptions)attributeData!.ConstructorArguments[0].Value!; } else { - pixelOptions = D2D1PixelOption.None; + pixelOptions = D2D1PixelOptions.None; } } } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 73b8ac3f..41f8e262 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -308,18 +308,18 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator // Get the pixel options, again independently from other generation steps. // This can also be immediately cached at a fine grained level. - IncrementalValuesProvider<(HierarchyInfo Hierarchy, D2D1PixelOption Options)> pixelOptionsInfo = + IncrementalValuesProvider<(HierarchyInfo Hierarchy, D2D1PixelOptions Options)> pixelOptionsInfo = shaderDeclarations .Select(static (item, token) => { // GetPixelOptions() info - GetPixelOptions.GetInfo(item.Symbol, out D2D1PixelOption pixelOptions); + GetPixelOptions.GetInfo(item.Symbol, out D2D1PixelOptions pixelOptions); token.ThrowIfCancellationRequested(); return (item.Hierarchy, pixelOptions); }) - .WithComparers(HierarchyInfo.Comparer.Default, EqualityComparer.Default); + .WithComparers(HierarchyInfo.Comparer.Default, EqualityComparer.Default); // Generate the GetPixelOptions() methods context.RegisterSourceOutput(pixelOptionsInfo, static (context, item) => diff --git a/src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs b/src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs index d4b9ad29..11bc6de2 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DPixelOptions.cs @@ -16,7 +16,7 @@ public sealed class D2DPixelOptionsAttribute : Attribute /// Creates a new instance of the type with the specified arguments. /// /// The options to specify for the shader. - public D2DPixelOptionsAttribute(D2D1PixelOption options) + public D2DPixelOptionsAttribute(D2D1PixelOptions options) { Options = options; } @@ -24,5 +24,5 @@ public sealed class D2DPixelOptionsAttribute : Attribute /// /// Gets the options to specify for the shader. /// - public D2D1PixelOption Options { get; } + public D2D1PixelOptions Options { get; } } diff --git a/src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOption.cs b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOptions.cs similarity index 70% rename from src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOption.cs rename to src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOptions.cs index d0b52dcb..d6c0fbd9 100644 --- a/src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOption.cs +++ b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1PixelOptions.cs @@ -1,22 +1,25 @@ -namespace ComputeSharp.D2D1; +using System; +using static TerraFX.Interop.DirectX.D2D1_PIXEL_OPTIONS; + +namespace ComputeSharp.D2D1; /// -/// Indicates how the sampling of a D2D1 pixel shader will be restricted. This indicates whether the vertex buffer -/// is large and tends to change infrequently or smaller and changes frequently (typically frame over frame). +/// Indicates how the sampling of a D2D1 pixel shader will be restricted. /// /// /// This type exposes the available values in . /// -public enum D2D1PixelOption +[Flags] +public enum D2D1PixelOptions { /// /// The pixel shader is not restricted in its sampling. /// - None, + None = (int)D2D1_PIXEL_OPTIONS_NONE, /// /// The pixel shader samples inputs only at the same scene coordinate as the output pixel /// and returns transparent black whenever the input pixels are also transparent black. /// - TrivialSampling + TrivialSampling = (int)D2D1_PIXEL_OPTIONS_TRIVIAL_SAMPLING } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index 49ab6d7b..afcb0287 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -85,12 +85,12 @@ 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 D2D1PixelOption GetPixelOptions() + public static D2D1PixelOptions GetPixelOptions() where T : unmanaged, ID2D1PixelShader { Unsafe.SkipInit(out T shader); - return (D2D1PixelOption)shader.GetPixelOptions(); + return (D2D1PixelOptions)shader.GetPixelOptions(); } /// 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 575eb61d..26d86426 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs @@ -67,7 +67,7 @@ internal unsafe partial struct PixelShaderEffect /// /// The pixel options for the shader. /// - private static D2D1PixelOption pixelOptions; + private static D2D1PixelOptions pixelOptions; /// /// The shader bytecode. @@ -124,7 +124,7 @@ internal unsafe partial struct PixelShaderEffect byte* bytecode = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For), bytecodeSize); D2D1BufferPrecision bufferPrecision = D2D1PixelShader.GetOutputBufferPrecision(); D2D1ChannelDepth channelDepth = D2D1PixelShader.GetOutputBufferChannelDepth(); - D2D1PixelOption pixelOptions = D2D1PixelShader.GetPixelOptions(); + D2D1PixelOptions pixelOptions = D2D1PixelShader.GetPixelOptions(); // Prepare the inputs info int inputCount = D2D1PixelShader.GetInputCount(); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index ae1a8732..f9edc7af 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -178,7 +178,7 @@ internal unsafe partial struct PixelShaderEffect /// /// The pixel options for the shader. /// - private D2D1PixelOption pixelOptions; + private D2D1PixelOptions pixelOptions; /// /// The shader bytecode. @@ -232,7 +232,7 @@ internal unsafe partial struct PixelShaderEffect D2D1PixelShaderInputType* inputTypes, int inputDescriptionCount, D2D1InputDescription* inputDescriptions, - D2D1PixelOption pixelOptions, + D2D1PixelOptions pixelOptions, byte* bytecode, int bytecodeSize, D2D1BufferPrecision bufferPrecision,