Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
Disable code generation for ID3D12RootSignatureDeserializer and RootS…
Browse files Browse the repository at this point in the history
…ignatureDescription. Rely on manual marshaling instead.
  • Loading branch information
Yi Zhang committed Jul 6, 2016
1 parent 9673433 commit db3fba1
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Source/SharpDX.Direct3D12/Mapping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@
</context-set>

<!-- D3D12 extensions -->
<extension>
<extension>
<context id="d3d12-all"/>

<const from-macro="D3D12_SDK_VERSION" class="SharpDX.Direct3D12.D3D12" type="int" name="SdkVersion" />
<create class="D3D12" />

<context-clear />
</extension>

<!-- D3D12 bindings -->
<bindings>
<bindings>

</bindings>

<!-- D3D12 mapping -->
Expand Down Expand Up @@ -145,9 +145,9 @@

<map field="D3D12_ROOT_SIGNATURE::pParameters" name="ParametersPointer"/>

<map struct="D3D12_ROOT_SIGNATURE_DESC" struct-to-class="true"/>
<map struct="D3D12_ROOT_SIGNATURE_DESC" struct-to-class="true" marshal="true"/>
<remove field="D3D12_ROOT_SIGNATURE_DESC::.*"/>

<map struct="D3D12_INPUT_LAYOUT_DESC" struct-to-class="true" marshalto="true"/>
<map field="D3D12_INPUT_LAYOUT_DESC::pInputElementDescs" name="InputElementsPointer" visibility="private"/>
<map field="D3D12_INPUT_LAYOUT_DESC::NumElements" visibility="private"/>
Expand Down Expand Up @@ -296,7 +296,6 @@
<map param="ID3D12Device::CreateComputePipelineState::pDesc" attribute="in" type="void"/>

<map method="ID3D12RootSignatureDeserializer::GetRootSignature" type="void" property="false" visibility="private"/>

<map param="ID3D12Resource::Map::pReadRange" default="null"/>
<map param="ID3D12Resource::Unmap::pWrittenRange" default="null"/>
<map param="ID3D12Resource::Map::ppData" attribute="out" return="true"/>
Expand All @@ -315,6 +314,7 @@

<remove function=".*_Stub"/>
<remove function=".*_Proxy"/>
<remove method="ID3D12RootSignatureDeserializer::GetRootSignatureDesc"/>
<map function="D3D12(.+)" name-tmp="$1" />
<map function="D3D12.*" dll='"d3d12.dll"' group="SharpDX.Direct3D12.D3D12" />
<map param="D3D12CreateDevice::ppDevice" type="ID3D12Device" attribute="out fast" />
Expand Down
71 changes: 70 additions & 1 deletion Source/SharpDX.Direct3D12/RootSignatureDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public RootSignatureDescription(RootSignatureFlags flags, RootParameter[] parame
Flags = flags;
}

public RootSignatureDescription(IntPtr pNativePtr)
{
Deserialize(pNativePtr);
}

/// <summary>
/// The parameters
/// </summary>
Expand Down Expand Up @@ -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
{
/// <unmanaged-short>unsigned int NumParameters</unmanaged-short>
Expand All @@ -174,5 +243,5 @@ internal partial struct __Native
/// <unmanaged-short>unsigned int Flags</unmanaged-short>
public RootSignatureFlags Flags;
}
}
}
}
47 changes: 47 additions & 0 deletions Source/SharpDX.Direct3D12/RootSignatureDeserializer.cs
Original file line number Diff line number Diff line change
@@ -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
{
// <summary>
/// <p> Gets the layout of the root signature. </p>
/// </summary>
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12RootSignatureDeserializer::GetRootSignatureDesc']/*"/>
/// <msdn-id>dn986887</msdn-id>
/// <unmanaged>GetRootSignatureDesc</unmanaged>
/// <unmanaged-short>GetRootSignatureDesc</unmanaged-short>
/// <unmanaged>const D3D12_ROOT_SIGNATURE_DESC* ID3D12RootSignatureDeserializer::GetRootSignatureDesc()</unmanaged>
public SharpDX.Direct3D12.RootSignatureDescription RootSignatureDescription
{
get { return GetRootSignatureDescription(); }
}

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
internal delegate IntPtr GetRootSignatureDescDelegate(IntPtr pThis);

/// <summary>
/// <p> Gets the layout of the root signature. </p>
/// </summary>
/// <returns><p> Returns a reference to a <strong><see cref="SharpDX.Direct3D12.RootSignatureDescription"/></strong> structure that describes the layout of the root signature. </p></returns>
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12RootSignatureDeserializer::GetRootSignatureDesc']/*"/>
/// <msdn-id>dn986887</msdn-id>
/// <unmanaged>const D3D12_ROOT_SIGNATURE_DESC* ID3D12RootSignatureDeserializer::GetRootSignatureDesc()</unmanaged>
/// <unmanaged-short>ID3D12RootSignatureDeserializer::GetRootSignatureDesc</unmanaged-short>
internal SharpDX.Direct3D12.RootSignatureDescription GetRootSignatureDescription()
{
unsafe
{
void* target = ((void**)(*(void**)_nativePointer))[3];
GetRootSignatureDescDelegate getRootSignatureDescMethod = Marshal.GetDelegateForFunctionPointer<GetRootSignatureDescDelegate>(new IntPtr(target));
IntPtr pDesc = getRootSignatureDescMethod(new IntPtr(_nativePointer));
return new RootSignatureDescription(pDesc);
}
}
}
}
1 change: 1 addition & 0 deletions Source/SharpDX.Direct3D12/SharpDX.Direct3D12.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Compile Include="ResourceDescription.cs" />
<Compile Include="ResourceTransitionBarrier.cs" />
<Compile Include="RootConstants.cs" />
<Compile Include="RootSignatureDeserializer.cs" />
<Compile Include="RootDescriptor.cs" />
<Compile Include="RootParameter.cs" />
<Compile Include="RootSignatureDescription.cs" />
Expand Down

0 comments on commit db3fba1

Please sign in to comment.