From db3fba1c7d172344bd58bb43d723f62fff325137 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Tue, 5 Jul 2016 21:48:18 -0700 Subject: [PATCH] Disable code generation for ID3D12RootSignatureDeserializer and RootSignatureDescription. Rely on manual marshaling instead. --- Source/SharpDX.Direct3D12/Mapping.xml | 14 ++-- .../RootSignatureDescription.cs | 71 ++++++++++++++++++- .../RootSignatureDeserializer.cs | 47 ++++++++++++ .../SharpDX.Direct3D12.csproj | 1 + 4 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 Source/SharpDX.Direct3D12/RootSignatureDeserializer.cs diff --git a/Source/SharpDX.Direct3D12/Mapping.xml b/Source/SharpDX.Direct3D12/Mapping.xml index 527bbad25..3551ffa56 100644 --- a/Source/SharpDX.Direct3D12/Mapping.xml +++ b/Source/SharpDX.Direct3D12/Mapping.xml @@ -48,18 +48,18 @@ - + - + - - + + @@ -145,9 +145,9 @@ - + - + @@ -296,7 +296,6 @@ - @@ -315,6 +314,7 @@ + diff --git a/Source/SharpDX.Direct3D12/RootSignatureDescription.cs b/Source/SharpDX.Direct3D12/RootSignatureDescription.cs index 08e013b48..efe0f6011 100644 --- a/Source/SharpDX.Direct3D12/RootSignatureDescription.cs +++ b/Source/SharpDX.Direct3D12/RootSignatureDescription.cs @@ -56,6 +56,11 @@ public RootSignatureDescription(RootSignatureFlags flags, RootParameter[] parame Flags = flags; } + public RootSignatureDescription(IntPtr pNativePtr) + { + Deserialize(pNativePtr); + } + /// /// The parameters /// @@ -159,6 +164,70 @@ private unsafe Result Serialize(out Blob result, out string errorText) } } + private unsafe void Deserialize(IntPtr pNativePtr) + { + __Native* pNative = (__Native*)pNativePtr; + + if (pNative->ParameterCount > 0) + { + Parameters = new RootParameter[pNative->ParameterCount]; + RootParameter.__Native* rpn = (RootParameter.__Native * ) pNative->ParametersPointer; + for (int i = 0; i < Parameters.Length; ++i) + { + Parameters[i] = new RootParameter(); + if (rpn[i].ParameterType == RootParameterType.DescriptorTable) + { + // Marshal descriptor table + DescriptorRange[] ranges = null; + + int rangeCount = rpn[i].Union.DescriptorTable.DescriptorRangeCount; + if (rangeCount > 0) + { + ranges = new DescriptorRange[rangeCount]; + fixed (DescriptorRange* pCurRange = ranges) + { + DescriptorRange* pSourceDescRange = (DescriptorRange*)rpn[i].Union.DescriptorTable.DescriptorRangesPointer; + DescriptorRange* pSourceDescRangeEnd = pSourceDescRange + rpn[i].Union.DescriptorTable.DescriptorRangeCount; + DescriptorRange* pTargetDescRange = pCurRange; + while (pTargetDescRange < pSourceDescRangeEnd) + { + *pTargetDescRange = *pSourceDescRange; + pTargetDescRange++; + pSourceDescRange++; + } + + } + } + + Parameters[i] = new RootParameter(rpn[i].ShaderVisibility, ranges); + } + else + { + // No need to marshal them when RootParameter don't contain DescriptorTable - simple copy as-is + Parameters[i] = new RootParameter(); + Parameters[i].native = *rpn; + } + } + } + + if (pNative->StaticSamplerCount > 0) + { + StaticSamplers = new StaticSamplerDescription[pNative->StaticSamplerCount]; + fixed (StaticSamplerDescription *pSamplerDesc = StaticSamplers) + { + StaticSamplerDescription* pTargetSamplerDesc = pSamplerDesc; + StaticSamplerDescription* pSourceSamplerDesc = (StaticSamplerDescription*) pNative->StaticSamplerPointer; + StaticSamplerDescription* pSourceSamplerDescEnd = pSourceSamplerDesc + pNative->StaticSamplerCount; + while (pSamplerDesc < pSourceSamplerDescEnd) + { + *pTargetSamplerDesc = *pSourceSamplerDesc; + pTargetSamplerDesc++; + pSourceSamplerDesc++; + } + } + } + } + internal partial struct __Native { /// unsigned int NumParameters @@ -174,5 +243,5 @@ internal partial struct __Native /// unsigned int Flags public RootSignatureFlags Flags; } - } + } } \ No newline at end of file diff --git a/Source/SharpDX.Direct3D12/RootSignatureDeserializer.cs b/Source/SharpDX.Direct3D12/RootSignatureDeserializer.cs new file mode 100644 index 000000000..30c33ecb1 --- /dev/null +++ b/Source/SharpDX.Direct3D12/RootSignatureDeserializer.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace SharpDX.Direct3D12 +{ + public partial class RootSignatureDeserializer + { + // + ///

Gets the layout of the root signature.

+ ///
+ /// + /// dn986887 + /// GetRootSignatureDesc + /// GetRootSignatureDesc + /// const D3D12_ROOT_SIGNATURE_DESC* ID3D12RootSignatureDeserializer::GetRootSignatureDesc() + public SharpDX.Direct3D12.RootSignatureDescription RootSignatureDescription + { + get { return GetRootSignatureDescription(); } + } + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + internal delegate IntPtr GetRootSignatureDescDelegate(IntPtr pThis); + + /// + ///

Gets the layout of the root signature.

+ ///
+ ///

Returns a reference to a structure that describes the layout of the root signature.

+ /// + /// dn986887 + /// const D3D12_ROOT_SIGNATURE_DESC* ID3D12RootSignatureDeserializer::GetRootSignatureDesc() + /// ID3D12RootSignatureDeserializer::GetRootSignatureDesc + internal SharpDX.Direct3D12.RootSignatureDescription GetRootSignatureDescription() + { + unsafe + { + void* target = ((void**)(*(void**)_nativePointer))[3]; + GetRootSignatureDescDelegate getRootSignatureDescMethod = Marshal.GetDelegateForFunctionPointer(new IntPtr(target)); + IntPtr pDesc = getRootSignatureDescMethod(new IntPtr(_nativePointer)); + return new RootSignatureDescription(pDesc); + } + } + } +} diff --git a/Source/SharpDX.Direct3D12/SharpDX.Direct3D12.csproj b/Source/SharpDX.Direct3D12/SharpDX.Direct3D12.csproj index c8fcf3cc0..ab4c31bc7 100644 --- a/Source/SharpDX.Direct3D12/SharpDX.Direct3D12.csproj +++ b/Source/SharpDX.Direct3D12/SharpDX.Direct3D12.csproj @@ -44,6 +44,7 @@ +