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

Commit

Permalink
Browse files Browse the repository at this point in the history
[Direct3D12] Simplify marshaling for PR #773 (issue #667)
  • Loading branch information
xoofx committed Jul 6, 2016
1 parent 54d0f17 commit 9d7b926
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Source/SharpDX.Direct3D12/Mapping.xml
Expand Up @@ -314,7 +314,7 @@

<remove function=".*_Stub"/>
<remove function=".*_Proxy"/>
<remove method="ID3D12RootSignatureDeserializer::GetRootSignatureDesc"/>
<map method="ID3D12RootSignatureDeserializer::GetRootSignatureDesc" type="void" property="false" visibility="private"/>
<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
35 changes: 8 additions & 27 deletions Source/SharpDX.Direct3D12/RootSignatureDescription.cs
Expand Up @@ -166,6 +166,11 @@ private unsafe Result Serialize(out Blob result, out string errorText)

private unsafe void Deserialize(IntPtr pNativePtr)
{
if(pNativePtr == IntPtr.Zero)
{
return;
}

__Native* pNative = (__Native*)pNativePtr;

if (pNative->ParameterCount > 0)
Expand All @@ -184,47 +189,23 @@ private unsafe void Deserialize(IntPtr pNativePtr)
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++;
}

}
Utilities.Read(rpn[i].Union.DescriptorTable.DescriptorRangesPointer, ranges, 0, ranges.Length);
}

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;
Parameters[i] = new RootParameter {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++;
}
}
Utilities.Read(pNative->StaticSamplerPointer, StaticSamplers, 0, StaticSamplers.Length);
}
}

Expand Down
19 changes: 4 additions & 15 deletions Source/SharpDX.Direct3D12/RootSignatureDeserializer.cs
Expand Up @@ -17,13 +17,7 @@ public partial class RootSignatureDeserializer
/// <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);
public SharpDX.Direct3D12.RootSignatureDescription RootSignatureDescription => GetRootSignatureDescription2();

/// <summary>
/// <p> Gets the layout of the root signature. </p>
Expand All @@ -33,15 +27,10 @@ public SharpDX.Direct3D12.RootSignatureDescription RootSignatureDescription
/// <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()
internal SharpDX.Direct3D12.RootSignatureDescription GetRootSignatureDescription2()
{
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);
}
var pDesc = this.GetRootSignatureDescription();
return new RootSignatureDescription(pDesc);
}
}
}

0 comments on commit 9d7b926

Please sign in to comment.