Skip to content

Commit

Permalink
[Direct3D12] First round to provide wrapper around RootParameter/Root…
Browse files Browse the repository at this point in the history
…SignatureDescription (sharpdx#609)
  • Loading branch information
xoofx committed Aug 18, 2015
1 parent 2a174b0 commit 8a81952
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 211 deletions.
26 changes: 26 additions & 0 deletions Source/SharpDX.Direct3D12/CommandSignatureDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace SharpDX.Direct3D12
{
public partial class CommandSignatureDescription
{
public IndirectArgumentDescription[] IndirectArguments { get; set; }
}
}
16 changes: 13 additions & 3 deletions Source/SharpDX.Direct3D12/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,21 @@ public GraphicsCommandList CreateCommandList(int nodeMask,
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12Device::CreateCommandSignature']/*"/>
/// <unmanaged>HRESULT ID3D12Device::CreateCommandSignature([In] const D3D12_COMMAND_SIGNATURE* pDesc,[In, Optional] ID3D12RootSignature* pRootSignature,[In] const GUID&amp; riid,[Out] ID3D12CommandSignature** ppvCommandSignature)</unmanaged>
/// <unmanaged-short>ID3D12Device::CreateCommandSignature</unmanaged-short>
public CommandSignature CreateCommandSignature(SharpDX.Direct3D12.CommandSignatureDescription descRef, SharpDX.Direct3D12.RootSignature rootSignatureRef)
public unsafe CommandSignature CreateCommandSignature(SharpDX.Direct3D12.CommandSignatureDescription descRef, SharpDX.Direct3D12.RootSignature rootSignatureRef)
{
return CreateCommandSignature(descRef, rootSignatureRef, Utilities.GetGuidFromType(typeof(CommandSignature)));
}
var nativeDesc = new CommandSignatureDescription.__Native();
descRef.__MarshalTo(ref nativeDesc);
fixed(void* pIndirectArguments = descRef.IndirectArguments)
{
if(descRef.IndirectArguments != null)
{
nativeDesc.ArgumentDescCount = descRef.IndirectArguments.Length;
nativeDesc.ArgumentDescsPointer = new IntPtr(pIndirectArguments);
}

return CreateCommandSignature(new IntPtr(&nativeDesc), rootSignatureRef, Utilities.GetGuidFromType(typeof(CommandSignature)));
}
}

/// <summary>
/// No documentation for Direct3D12
Expand Down
12 changes: 11 additions & 1 deletion Source/SharpDX.Direct3D12/Mapping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,16 @@
// D3D12 Struct
// *****************************************************************
-->

<map field="D3D12_.*::p([A-Z].*)" name="$1Pointer" visibility="public"/>

<map field="D3D12_MESSAGE::pDescription" name="Description" visibility="public"/>

<map struct="D3D12_.*_PIPELINE_STATE_DESC" struct-to-class="true" marshalto="true"/>
<map struct="D3D12_COMMAND_SIGNATURE_DESC" struct-to-class="true" marshalto="true"/>
<map field="D3D12_COMMAND_SIGNATURE_DESC::NumArgumentDescs" visibility="internal"/>
<map field="D3D12_COMMAND_SIGNATURE_DESC::pArgumentDescs" visibility="internal"/>

<map field="D3D12_.*_PIPELINE_STATE_DESC::p([A-Z].*)" name="$1Pointer" visibility="private"/>
<map field="D3D12_GRAPHICS_PIPELINE_STATE_DESC::RTVFormats" name="RenderTargetFormats"/>
<map field="D3D12_GRAPHICS_PIPELINE_STATE_DESC::DSVFormat" name="DepthStencilFormat"/>
Expand Down Expand Up @@ -173,6 +181,7 @@
<map struct="D3D12_CACHED_PIPELINE_STATE::pCachedBlob" name="CachedBlobPointer"/>

<map interface="ID3D12Debug" name="DebugInterface"/>
<remove struct="D3D12_MEMCPY_DEST"/>

<!--
// *****************************************************************
Expand Down Expand Up @@ -250,6 +259,7 @@

<map method="ID3D12Device::CreateCommandSignature" visibility="private"/>
<map param="ID3D12Device::CreateCommandSignature::ppvCommandSignature" attribute="out" type="ID3D12CommandSignature" return="true"/>
<map param="ID3D12Device::CreateCommandSignature::pDesc" type="void"/>

<map method="ID3D12Device::CreateHeap" visibility="private"/>
<map param="ID3D12Device::CreateHeap::ppvHeap" attribute="out" type="ID3D12Heap" return="true"/>
Expand Down Expand Up @@ -286,7 +296,7 @@
<map param="ID3D12Resource::Map::pReadRange" default="null"/>
<map param="ID3D12Resource::Unmap::pWrittenRange" default="null"/>
<map param="ID3D12Resource::Map::ppData" attribute="out" return="true"/>

<!--
// *****************************************************************
// D3D12 Functions
Expand Down
14 changes: 5 additions & 9 deletions Source/SharpDX.Direct3D12/Message.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SharpDX.Direct3D12
{
Expand All @@ -13,11 +9,11 @@ public partial struct Message
[StructLayout(LayoutKind.Sequential, Pack = 0)]
internal partial struct __Native
{
public SharpDX.Direct3D12.MessageCategory Category;
public SharpDX.Direct3D12.MessageSeverity Severity;
public SharpDX.Direct3D12.MessageId Id;
public System.IntPtr PDescription;
public SharpDX.PointerSize DescriptionByteLength;
public MessageCategory Category;
public MessageSeverity Severity;
public MessageId Id;
public IntPtr PDescription;
public PointerSize DescriptionByteLength;
}

// Method to marshal from native to managed struct
Expand Down
81 changes: 70 additions & 11 deletions Source/SharpDX.Direct3D12/RootParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,100 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.Runtime.InteropServices;

namespace SharpDX.Direct3D12
{
public partial struct RootParameter
{
public RootParameterType ParameterType;
internal __Native native;
private DescriptorRange[] descriptorTable;

private Union union;
public RootParameter(DescriptorRange[] descriptorTable) : this()
{
DescriptorTable = descriptorTable;
}

public RootParameter(RootConstants rootConstants)
: this()
{
Constants = rootConstants;
}

public RootParameter(RootDescriptor rootDescriptor, RootParameterType type)
: this()
{
if(type == RootParameterType.Constant32Bits || type == RootParameterType.DescriptorTable)
{
throw new ArgumentException(string.Format("Cannot this type [{0}] for a RootDescriptor", type), "type");
}

native.ParameterType = type;
Descriptor = rootDescriptor;
}

public static implicit operator RootParameter(DescriptorRange[] descriptorTable)
{
return new RootParameter(descriptorTable);
}

public RootDescriptorTable DescriptorTable
public static implicit operator RootParameter(RootConstants rootConstants)
{
get { return union.DescriptorTable; }
set { union.DescriptorTable = value; }
return new RootParameter(rootConstants);
}

public DescriptorRange[] DescriptorTable
{
get { return descriptorTable; }
private set
{
native.ParameterType = RootParameterType.DescriptorTable;
descriptorTable = value;
}
}

public RootConstants Constants
{
get { return union.Constants; }
set { union.Constants = value; }
get { return native.Union.Constants; }
private set
{
native.ParameterType = RootParameterType.Constant32Bits;
native.Union.Constants = value;
}
}

public RootDescriptor Descriptor
{
get { return union.Descriptor; }
set { union.Descriptor = value; }
get { return native.Union.Descriptor; }
private set
{
native.Union.Descriptor = value;
}
}

public ShaderVisibility ShaderVisibility;
public ShaderVisibility ShaderVisibility
{
get { return native.ShaderVisibility; }
set { native.ShaderVisibility = value; }
}

[StructLayout(LayoutKind.Sequential)]
internal partial struct __Native
{
public RootParameterType ParameterType;

public __Union Union;

public ShaderVisibility ShaderVisibility;
}

/// <summary>
/// Because this union contains pointers, it is aligned on 8 bytes boundary, making the field ResourceBarrierDescription.Type
/// to be aligned on 8 bytes instead of 4 bytes, so we can't use directly Explicit layout on ResourceBarrierDescription
/// </summary>
[StructLayout(LayoutKind.Explicit, Pack = 0)]
private partial struct Union
internal partial struct __Union
{
[FieldOffset(0)]
public RootDescriptorTable DescriptorTable;
Expand All @@ -64,5 +122,6 @@ private partial struct Union
[FieldOffset(0)]
public RootDescriptor Descriptor;
}

}
}
Loading

0 comments on commit 8a81952

Please sign in to comment.