diff --git a/src/ComputeSharp.D2D1/Attributes/Enums/D2D1ChannelDepth.cs b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1ChannelDepth.cs index 73abb928..e712cce0 100644 --- a/src/ComputeSharp.D2D1/Attributes/Enums/D2D1ChannelDepth.cs +++ b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1ChannelDepth.cs @@ -12,15 +12,15 @@ public enum D2D1ChannelDepth /// /// The channel depth is the default, and it will be inherited by the inputs. /// - Default, + Default = 0, /// /// The channel depth is 1. /// - One, + One = 1, /// /// The channel depth is 4. /// - Four + Four = 4 } 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 1afb2a41..576b567b 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,16 @@ internal unsafe partial struct PixelShaderEffect /// private static int bytecodeSize; + /// + /// The buffer precision for the resulting output buffer. + /// + private static D2D1BufferPrecision bufferPrecision; + + /// + /// The channel depth for the resulting output buffer. + /// + private static D2D1ChannelDepth channelDepth; + /// /// The factory of instances to use for each created effect. /// @@ -97,6 +107,8 @@ internal unsafe partial struct PixelShaderEffect ReadOnlyMemory buffer = D2D1PixelShader.LoadBytecode(); int bytecodeSize = buffer.Length; byte* bytecode = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For), bytecodeSize); + D2D1BufferPrecision bufferPrecision = D2D1PixelShader.GetOutputBufferPrecision(); + D2D1ChannelDepth channelDepth = D2D1PixelShader.GetOutputBufferChannelDepth(); // Prepare the inputs info int inputCount = D2D1PixelShader.GetInputCount(); @@ -116,6 +128,8 @@ internal unsafe partial struct PixelShaderEffect For.inputTypes = inputTypes; For.bytecode = bytecode; For.bytecodeSize = bytecodeSize; + For.bufferPrecision = bufferPrecision; + For.channelDepth = channelDepth; For.d2D1DrawTransformMapperFactory = d2D1DrawTransformMapperFactory; isInitialized = true; @@ -195,6 +209,8 @@ internal unsafe partial struct PixelShaderEffect inputTypes, bytecode, bytecodeSize, + bufferPrecision, + channelDepth, d2D1TransformMapper, effectImpl); } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs index 211cefcd..fbfbb0c5 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs @@ -323,7 +323,24 @@ partial struct PixelShaderEffect @this->d2D1DrawInfo = drawInfo; - return drawInfo->SetPixelShader(&@this->shaderId); + // Set the pixel shader for the effect + HRESULT hresult = drawInfo->SetPixelShader(&@this->shaderId); + + if (hresult != S.S_OK) + { + return hresult; + } + + // If a custom buffer precision or channel depth is requested, set it + if (@this->bufferPrecision != D2D1BufferPrecision.Unknown || + @this->channelDepth != D2D1ChannelDepth.Default) + { + return drawInfo->SetOutputBuffer( + (D2D1_BUFFER_PRECISION)@this->bufferPrecision, + (D2D1_CHANNEL_DEPTH)@this->channelDepth); + } + + return S.S_OK; } } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index 8cbf824e..af5e1537 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -171,6 +171,16 @@ internal unsafe partial struct PixelShaderEffect /// private int bytecodeSize; + /// + /// The buffer precision for the resulting output buffer. + /// + private D2D1BufferPrecision bufferPrecision; + + /// + /// The channel depth for the resulting output buffer. + /// + private D2D1ChannelDepth channelDepth; + /// /// The handle for the instance in use, if any. /// @@ -189,6 +199,8 @@ internal unsafe partial struct PixelShaderEffect /// The buffer with the types of inputs for the shader. /// The shader bytecode. /// The size of . + /// The buffer precision for the resulting output buffer. + /// The channel depth for the resulting output buffer. /// The instance to use for the effect. /// The resulting effect instance. /// This always returns 0. @@ -198,6 +210,8 @@ internal unsafe partial struct PixelShaderEffect D2D1PixelShaderInputType* inputTypes, byte* bytecode, int bytecodeSize, + D2D1BufferPrecision bufferPrecision, + D2D1ChannelDepth channelDepth, D2D1TransformMapper? d2D1TransformMapper, IUnknown** effectImpl) { @@ -213,6 +227,8 @@ internal unsafe partial struct PixelShaderEffect @this->inputTypes = inputTypes; @this->bytecode = bytecode; @this->bytecodeSize = bytecodeSize; + @this->bufferPrecision = bufferPrecision; + @this->channelDepth = channelDepth; @this->d2D1TransformMapperHandle = GCHandle.Alloc(d2D1TransformMapper); *effectImpl = (IUnknown*)@this; diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_BUFFER_PRECISION.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_BUFFER_PRECISION.cs new file mode 100644 index 00000000..f8aab853 --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_BUFFER_PRECISION.cs @@ -0,0 +1,18 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/d2d1_1.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +namespace TerraFX.Interop.DirectX +{ + internal enum D2D1_BUFFER_PRECISION : uint + { + D2D1_BUFFER_PRECISION_UNKNOWN = 0, + D2D1_BUFFER_PRECISION_8BPC_UNORM = 1, + D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB = 2, + D2D1_BUFFER_PRECISION_16BPC_UNORM = 3, + D2D1_BUFFER_PRECISION_16BPC_FLOAT = 4, + D2D1_BUFFER_PRECISION_32BPC_FLOAT = 5, + D2D1_BUFFER_PRECISION_FORCE_DWORD = 0xffffffff + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_CHANNEL_DEPTH.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_CHANNEL_DEPTH.cs new file mode 100644 index 00000000..3189cb39 --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_CHANNEL_DEPTH.cs @@ -0,0 +1,15 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/d2d1_1.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +namespace TerraFX.Interop.DirectX +{ + internal enum D2D1_CHANNEL_DEPTH : uint + { + D2D1_CHANNEL_DEPTH_DEFAULT = 0, + D2D1_CHANNEL_DEPTH_1 = 1, + D2D1_CHANNEL_DEPTH_4 = 4, + D2D1_CHANNEL_DEPTH_FORCE_DWORD = 0xffffffff + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs index 2c94d473..76105584 100644 --- a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs @@ -20,6 +20,13 @@ namespace TerraFX.Interop.DirectX { public void** lpVtbl; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(4)] + public HRESULT SetOutputBuffer(D2D1_BUFFER_PRECISION bufferPrecision, D2D1_CHANNEL_DEPTH channelDepth) + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((ID2D1DrawInfo*)Unsafe.AsPointer(ref this), bufferPrecision, channelDepth); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(7)] public HRESULT SetPixelShaderConstantBuffer([NativeTypeName("const BYTE *")] byte* buffer, [NativeTypeName("UINT32")] uint bufferCount) diff --git a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems index 942865b5..70a7135d 100644 --- a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems +++ b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems @@ -19,6 +19,8 @@ + +