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 576b567b..57addcbc 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs @@ -54,6 +54,16 @@ internal unsafe partial struct PixelShaderEffect /// private static D2D1PixelShaderInputType* inputTypes; + /// + /// The number of available input descriptions. + /// + private static int inputDescriptionCount; + + /// + /// The buffer with the available input descriptions for the shader. + /// + private static D2D1InputDescription* inputDescriptions; + /// /// The shader bytecode. /// @@ -104,8 +114,8 @@ internal unsafe partial struct PixelShaderEffect { // Load all shader properties Guid shaderId = typeof(T).GUID; - ReadOnlyMemory buffer = D2D1PixelShader.LoadBytecode(); - int bytecodeSize = buffer.Length; + ReadOnlyMemory bytecodeInfo = D2D1PixelShader.LoadBytecode(); + int bytecodeSize = bytecodeInfo.Length; byte* bytecode = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For), bytecodeSize); D2D1BufferPrecision bufferPrecision = D2D1PixelShader.GetOutputBufferPrecision(); D2D1ChannelDepth channelDepth = D2D1PixelShader.GetOutputBufferChannelDepth(); @@ -119,13 +129,22 @@ internal unsafe partial struct PixelShaderEffect inputTypes[i] = D2D1PixelShader.GetInputType(i); } + // Prepare the input descriptions + ReadOnlyMemory inputDescriptionsInfo = D2D1PixelShader.GetInputDescriptions(); + int inputDescriptionCount = inputDescriptionsInfo.Length; + D2D1InputDescription* inputDescriptions = (D2D1InputDescription*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For), inputDescriptionCount); + + inputDescriptionsInfo.Span.CopyTo(new Span(inputDescriptions, inputDescriptionCount)); + // Copy the bytecode to the target buffer - buffer.Span.CopyTo(new Span(bytecode, bytecodeSize)); + bytecodeInfo.Span.CopyTo(new Span(bytecode, bytecodeSize)); // Set the shared state and mark the type as initialized For.shaderId = shaderId; For.inputCount = inputCount; For.inputTypes = inputTypes; + For.inputDescriptionCount = inputDescriptionCount; + For.inputDescriptions = inputDescriptions; For.bytecode = bytecode; For.bytecodeSize = bytecodeSize; For.bufferPrecision = bufferPrecision; @@ -207,6 +226,8 @@ internal unsafe partial struct PixelShaderEffect shaderId, inputCount, inputTypes, + inputDescriptionCount, + inputDescriptions, 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 fbfbb0c5..9af7e953 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs @@ -331,13 +331,38 @@ partial struct PixelShaderEffect return hresult; } + // If any input descriptions are present, set them + if (@this->inputDescriptionCount > 0) + { + for (int i = 0; i < @this->inputDescriptionCount; i++) + { + ref D2D1InputDescription inputDescription = ref @this->inputDescriptions[i]; + + D2D1_INPUT_DESCRIPTION d2D1InputDescription; + d2D1InputDescription.filter = (D2D1_FILTER)inputDescription.Filter; + d2D1InputDescription.levelOfDetailCount = (uint)inputDescription.LevelOfDetail; + + hresult = drawInfo->SetInputDescription((uint)inputDescription.Index, d2D1InputDescription); + + 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( + hresult = drawInfo->SetOutputBuffer( (D2D1_BUFFER_PRECISION)@this->bufferPrecision, (D2D1_CHANNEL_DEPTH)@this->channelDepth); + + if (hresult != S.S_OK) + { + return hresult; + } } return S.S_OK; diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index af5e1537..e330ab71 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -161,6 +161,20 @@ internal unsafe partial struct PixelShaderEffect /// private D2D1PixelShaderInputType* inputTypes; + /// + /// The number of available input descriptions. + /// + private int inputDescriptionCount; + + /// + /// The buffer with the available input descriptions for the shader. + /// + /// + /// This buffer is also shared among effect instances, so it should not be released. It is + /// owned by , which will release it when the target type is unloaded. + /// + private D2D1InputDescription* inputDescriptions; + /// /// The shader bytecode. /// @@ -197,6 +211,8 @@ internal unsafe partial struct PixelShaderEffect /// The for the shader. /// The number of inputs for the shader. /// 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 shader bytecode. /// The size of . /// The buffer precision for the resulting output buffer. @@ -208,6 +224,8 @@ internal unsafe partial struct PixelShaderEffect Guid shaderId, int inputCount, D2D1PixelShaderInputType* inputTypes, + int inputDescriptionCount, + D2D1InputDescription* inputDescriptions, byte* bytecode, int bytecodeSize, D2D1BufferPrecision bufferPrecision, @@ -225,6 +243,8 @@ internal unsafe partial struct PixelShaderEffect @this->shaderId = shaderId; @this->inputCount = inputCount; @this->inputTypes = inputTypes; + @this->inputDescriptionCount = inputDescriptionCount; + @this->inputDescriptions = inputDescriptions; @this->bytecode = bytecode; @this->bytecodeSize = bytecodeSize; @this->bufferPrecision = bufferPrecision; diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_INPUT_DESCRIPTION.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_INPUT_DESCRIPTION.cs new file mode 100644 index 00000000..0da17fd0 --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_INPUT_DESCRIPTION.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/d2d1effectauthor.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +namespace TerraFX.Interop.DirectX +{ + internal partial struct D2D1_INPUT_DESCRIPTION + { + public D2D1_FILTER filter; + + [NativeTypeName("UINT32")] + public uint levelOfDetailCount; + } +} \ 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 76105584..bd4d7036 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(3)] + public HRESULT SetInputDescription([NativeTypeName("UINT32")] uint inputIndex, D2D1_INPUT_DESCRIPTION inputDescription) + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((ID2D1DrawInfo*)Unsafe.AsPointer(ref this), inputIndex, inputDescription); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(4)] public HRESULT SetOutputBuffer(D2D1_BUFFER_PRECISION bufferPrecision, D2D1_CHANNEL_DEPTH channelDepth) 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 da6f98fe..9668e5d7 100644 --- a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems +++ b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems @@ -14,6 +14,7 @@ +