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

Commit 672e484

Browse files
committed
Add ExecuteCommandLists with params to CommandQueue.
Cleanup Device CreateCommandList documentation. Some better logic for CommandQueueDescription and HeapProperties.
1 parent 5a73369 commit 672e484

4 files changed

Lines changed: 101 additions & 33 deletions

File tree

Source/SharpDX.Direct3D12/CommandQueue.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,43 @@ public partial class CommandQueue
2828
/// <summary>
2929
/// <p>Submits a command list for execution.</p>
3030
/// </summary>
31-
/// <param name="numCommandLists"><dd> <p> The number of command lists to be executed. </p> </dd></param>
32-
/// <param name="commandListsOut"><dd> <p> The array of <strong><see cref="SharpDX.Direct3D12.CommandList"/></strong> command lists to be executed. </p> </dd></param>
31+
/// <param name="commandList"><dd> <p> The <strong><see cref="SharpDX.Direct3D12.CommandList"/></strong> command list to be executed. </p> </dd></param>
3332
/// <remarks>
3433
/// <p> The driver is free to patch the submitted command lists. It is the calling application?s responsibility to ensure that the graphics processing unit (GPU) is not currently reading the any of the submitted command lists from a previous execution. </p><p> Applications are encouraged to batch together command list executions to reduce fixed costs associated with submitted commands to the GPU. </p>
3534
/// </remarks>
36-
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12CommandQueue::ExecuteCommandLists']/*"/>
37-
/// <msdn-id>dn788631</msdn-id>
38-
/// <unmanaged>void ID3D12CommandQueue::ExecuteCommandLists([In] unsigned int NumCommandLists,[In, Buffer] const ID3D12CommandList** ppCommandLists)</unmanaged>
39-
/// <unmanaged-short>ID3D12CommandQueue::ExecuteCommandLists</unmanaged-short>
4035
public unsafe void ExecuteCommandList(CommandList commandList)
4136
{
4237
if(commandList == null) throw new ArgumentNullException("commandList");
4338
var ptr = commandList.NativePointer;
4439
this.ExecuteCommandLists(1, new IntPtr(&ptr));
4540
}
41+
42+
/// <summary>
43+
/// Submits an array of command lists for execution.
44+
/// </summary>
45+
/// <param name="commandLists">
46+
/// The array of <see cref="SharpDX.Direct3D12.CommandList"/> command lists to be executed.
47+
/// </param>
48+
/// <remarks>
49+
/// The driver is free to patch the submitted command lists.
50+
/// It is the calling application's responsibility to ensure that the graphics processing unit (GPU) is not currently reading the any of the submitted command lists from a previous execution.
51+
/// Applications are encouraged to batch together command list executions to reduce fixed costs associated with submitted commands to the GPU.
52+
/// </remarks>
53+
public unsafe void ExecuteCommandLists(params SharpDX.Direct3D12.CommandList[] commandLists)
54+
{
55+
var commandListsPtr = (IntPtr*)0;
56+
57+
int count = 0;
58+
if (commandLists != null)
59+
{
60+
count = commandLists.Length;
61+
IntPtr* tempPtr = stackalloc IntPtr[count];
62+
commandListsPtr = tempPtr;
63+
for (int i = 0; i < count; i++)
64+
commandListsPtr[i] = (commandLists[i] == null) ? IntPtr.Zero : commandLists[i].NativePointer;
65+
}
66+
67+
ExecuteCommandLists(count, new IntPtr(commandListsPtr));
68+
}
4669
}
4770
}

Source/SharpDX.Direct3D12/CommandQueueDescription.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ namespace SharpDX.Direct3D12
2121
{
2222
public partial struct CommandQueueDescription
2323
{
24-
public CommandQueueDescription(CommandListType type, CommandQueueFlags flags = CommandQueueFlags.None) : this()
24+
public CommandQueueDescription(CommandListType type, CommandQueueFlags flags = CommandQueueFlags.None)
2525
{
2626
Type = type;
27+
Priority = 0;
2728
Flags = flags;
29+
NodeMask = 0;
30+
}
31+
32+
public CommandQueueDescription(
33+
CommandListType type,
34+
int nodeMask)
35+
{
36+
Type = type;
37+
Priority = 0;
38+
Flags = CommandQueueFlags.None;
39+
NodeMask = nodeMask;
2840
}
2941
}
3042
}

Source/SharpDX.Direct3D12/Device.cs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,33 +111,48 @@ public SharpDX.Direct3D12.CommandAllocator CreateCommandAllocator(SharpDX.Direct
111111
return CreateCommandAllocator(type, Utilities.GetGuidFromType(typeof(CommandAllocator)));
112112
}
113113

114+
/// <summary>
115+
/// <p>Creates a new graphics command list object.</p>
116+
/// </summary>
117+
/// <param name="type">A <see cref="SharpDX.Direct3D12.CommandListType"/> value that specifies the type of command list to create.</param>
118+
/// <param name="commandAllocator">A <see cref="CommandAllocator"/> object that the device creates command lists from.</param>
119+
/// <param name="initialState">A <see cref="PipelineState"/> object that contains the initial pipeline state for the command list.</param>
120+
/// <returns>A new instance of <see cref="GraphicsCommandList"/>.</returns>
114121
public GraphicsCommandList CreateCommandList(
115-
SharpDX.Direct3D12.CommandListType type,
116-
SharpDX.Direct3D12.CommandAllocator commandAllocatorRef,
117-
SharpDX.Direct3D12.PipelineState initialStateRef)
122+
SharpDX.Direct3D12.CommandListType type,
123+
SharpDX.Direct3D12.CommandAllocator commandAllocator,
124+
SharpDX.Direct3D12.PipelineState initialState)
118125
{
119-
return CreateCommandList(0, type, commandAllocatorRef, initialStateRef);
126+
return CreateCommandList(0, type, commandAllocator, initialState);
120127
}
121128

122129
/// <summary>
123-
/// No documentation for Direct3D12
130+
/// <p>Creates a new graphics command list object.</p>
124131
/// </summary>
125-
/// <param name="nodeMask">No documentation.</param>
126-
/// <param name="type">No documentation.</param>
127-
/// <param name="commandAllocatorRef">No documentation.</param>
128-
/// <param name="initialStateRef">No documentation.</param>
129-
/// <param name="riid">No documentation.</param>
130-
/// <returns>No documentation.</returns>
132+
/// <param name="nodeMask">
133+
/// For single GPU operation, set this to zero.
134+
/// If there are multiple GPU nodes, set a bit to identify the node (the device's physical adapter) for which to create the command list.
135+
/// Each bit in the mask corresponds to a single node. Only 1 bit must be set.
136+
/// </param>
137+
/// <param name="type">A <see cref="SharpDX.Direct3D12.CommandListType"/> value that specifies the type of command list to create.</param>
138+
/// <param name="commandAllocator">A <see cref="CommandAllocator"/> object that the device creates command lists from.</param>
139+
/// <param name="initialState">A <see cref="PipelineState"/> object that contains the initial pipeline state for the command list.</param>
140+
/// <returns>A new instance of <see cref="GraphicsCommandList"/>.</returns>
131141
/// <msdn-id>dn788656</msdn-id>
132142
/// <include file='Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12Device::CreateCommandList']/*"/>
133143
/// <unmanaged>HRESULT ID3D12Device::CreateCommandList([In] unsigned int nodeMask,[In] D3D12_COMMAND_LIST_TYPE type,[In] ID3D12CommandAllocator* pCommandAllocator,[In, Optional] ID3D12PipelineState* pInitialState,[In] const GUID&amp; riid,[Out] void** ppCommandList)</unmanaged>
134144
/// <unmanaged-short>ID3D12Device::CreateCommandList</unmanaged-short>
135145
public GraphicsCommandList CreateCommandList(int nodeMask,
136146
SharpDX.Direct3D12.CommandListType type,
137-
SharpDX.Direct3D12.CommandAllocator commandAllocatorRef,
138-
SharpDX.Direct3D12.PipelineState initialStateRef)
147+
SharpDX.Direct3D12.CommandAllocator commandAllocator,
148+
SharpDX.Direct3D12.PipelineState initialState)
139149
{
140-
var nativePointer = CreateCommandList(nodeMask, type, commandAllocatorRef, initialStateRef, Utilities.GetGuidFromType(typeof(GraphicsCommandList)));
150+
var nativePointer = CreateCommandList(
151+
nodeMask,
152+
type,
153+
commandAllocator,
154+
initialState,
155+
Utilities.GetGuidFromType(typeof(GraphicsCommandList)));
141156
return new GraphicsCommandList(nativePointer);
142157
}
143158

Source/SharpDX.Direct3D12/HeapProperties.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,57 @@ public partial struct HeapProperties
2727
/// <param name="type">The type.</param>
2828
/// <param name="cpuPageProperty">The cpu page properties.</param>
2929
/// <param name="memoryPoolPreference">The memory pool preference.</param>
30-
public HeapProperties(HeapType type, CpuPageProperty cpuPageProperty, MemoryPool memoryPoolPreference)
30+
/// <param name="creationNodeMask"></param>
31+
/// <param name="visibleNodeMask"></param>
32+
public HeapProperties(
33+
HeapType type,
34+
CpuPageProperty cpuPageProperty,
35+
MemoryPool memoryPoolPreference,
36+
int creationNodeMask = 1,
37+
int visibleNodeMask = 1)
3138
{
3239
Type = type;
3340
CPUPageProperty = cpuPageProperty;
3441
MemoryPoolPreference = memoryPoolPreference;
35-
this.CreationNodeMask = 1;
36-
this.VisibleNodeMask = 1;
42+
CreationNodeMask = creationNodeMask;
43+
VisibleNodeMask = visibleNodeMask;
3744
}
3845

3946
/// <summary>
4047
/// Initializes a new instance of the <see cref="HeapProperties"/> struct with <see cref="HeapType.Custom"/>
4148
/// </summary>
4249
/// <param name="cpuPageProperty">The cpu page properties.</param>
4350
/// <param name="memoryPoolPreference">The memory pool preference.</param>
44-
public HeapProperties(CpuPageProperty cpuPageProperty, MemoryPool memoryPoolPreference)
51+
/// <param name="creationNodeMask"></param>
52+
/// <param name="visibleNodeMask"></param>
53+
public HeapProperties(
54+
CpuPageProperty cpuPageProperty,
55+
MemoryPool memoryPoolPreference,
56+
int creationNodeMask = 1,
57+
int visibleNodeMask = 1)
4558
{
4659
Type = HeapType.Custom;
4760
CPUPageProperty = cpuPageProperty;
4861
MemoryPoolPreference = memoryPoolPreference;
49-
this.CreationNodeMask = 1;
50-
this.VisibleNodeMask = 1;
62+
CreationNodeMask = creationNodeMask;
63+
VisibleNodeMask = visibleNodeMask;
5164
}
5265

5366
/// <summary>
5467
/// Initializes a new instance of the <see cref="HeapProperties"/> struct.
5568
/// </summary>
5669
/// <param name="type">The type.</param>
57-
public HeapProperties(HeapType type)
70+
/// <param name="creationNodeMask"></param>
71+
/// <param name="visibleNodeMask"></param>
72+
public HeapProperties(HeapType type,
73+
int creationNodeMask = 1,
74+
int visibleNodeMask = 1)
5875
{
5976
Type = type;
6077
CPUPageProperty = CpuPageProperty.Unknown;
6178
MemoryPoolPreference = MemoryPool.Unknown;
62-
this.CreationNodeMask = 1;
63-
this.VisibleNodeMask = 1;
79+
CreationNodeMask = creationNodeMask;
80+
VisibleNodeMask = visibleNodeMask;
6481
}
6582

6683
/// <summary>
@@ -71,9 +88,10 @@ public bool IsCpuAccessible
7188
{
7289
get
7390
{
74-
return Type == HeapType.Upload || (Type == HeapType.Custom &&
75-
(CPUPageProperty == CpuPageProperty.WriteCombine
76-
|| CPUPageProperty == CpuPageProperty.WriteBack));
91+
return
92+
Type == HeapType.Upload ||
93+
Type == HeapType.Readback ||
94+
(Type == HeapType.Custom && (CPUPageProperty == CpuPageProperty.WriteCombine || CPUPageProperty == CpuPageProperty.WriteBack));
7795
}
7896
}
7997
}

0 commit comments

Comments
 (0)