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

Commit 7dcca8b

Browse files
committed
Refactoring Direct3D12 to use constructor logic instead of Factory Create logic.
1 parent 19df37e commit 7dcca8b

9 files changed

Lines changed: 323 additions & 184 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
using System;
22+
using System.Threading;
23+
24+
namespace SharpDX.Direct3D12
25+
{
26+
public partial class CommandAllocator
27+
{
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="CommandAllocator"/> class.
30+
/// </summary>
31+
/// <param name="device">The device with which to associate the command allocator.</param>
32+
/// <param name="type"><see cref="SharpDX.Direct3D12.CommandListType "/> value that specifies the type of command allocator to create.</param>
33+
public CommandAllocator(Device device, SharpDX.Direct3D12.CommandListType type)
34+
: base(IntPtr.Zero)
35+
{
36+
device.CreateCommandAllocator(
37+
type,
38+
Utilities.GetGuidFromType(typeof(CommandAllocator)),
39+
this);
40+
}
41+
}
42+
}

Source/SharpDX.Direct3D12/CommandQueue.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,59 @@ namespace SharpDX.Direct3D12
2525
{
2626
public partial class CommandQueue
2727
{
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="CommandQueue"/> class.
30+
/// </summary>
31+
/// <param name="device">The device with which to associate the command queue.</param>
32+
/// <param name="description"><see cref="CommandQueueDescription"/> structure that describes the queue.</param>
33+
public CommandQueue(Device device, CommandQueueDescription description)
34+
: base(IntPtr.Zero)
35+
{
36+
device.CreateCommandQueue(
37+
ref description,
38+
Utilities.GetGuidFromType(typeof(CommandQueue)),
39+
this);
40+
}
41+
2842
/// <summary>
2943
/// <p>Submits a command list for execution.</p>
3044
/// </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>
45+
/// <param name="commandList">The <see cref="SharpDX.Direct3D12.CommandList"/> be executed.</param>
3346
/// <remarks>
3447
/// <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>
3548
/// </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>
4049
public unsafe void ExecuteCommandList(CommandList commandList)
4150
{
42-
if(commandList == null) throw new ArgumentNullException("commandList");
4351
var ptr = commandList.NativePointer;
44-
this.ExecuteCommandLists(1, new IntPtr(&ptr));
52+
ExecuteCommandLists(1, new IntPtr(&ptr));
53+
}
54+
55+
/// <summary>
56+
/// Submits an array of command lists for execution.
57+
/// </summary>
58+
/// <param name="commandLists">
59+
/// The array of <see cref="SharpDX.Direct3D12.CommandList"/> command lists to be executed.
60+
/// </param>
61+
/// <remarks>
62+
/// The driver is free to patch the submitted command lists.
63+
/// 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.
64+
/// Applications are encouraged to batch together command list executions to reduce fixed costs associated with submitted commands to the GPU.
65+
/// </remarks>
66+
public unsafe void ExecuteCommandLists(params SharpDX.Direct3D12.CommandList[] commandLists)
67+
{
68+
var commandListsPtr = (IntPtr*)0;
69+
70+
int count = 0;
71+
if (commandLists != null)
72+
{
73+
count = commandLists.Length;
74+
IntPtr* tempPtr = stackalloc IntPtr[count];
75+
commandListsPtr = tempPtr;
76+
for (int i = 0; i < count; i++)
77+
commandListsPtr[i] = (commandLists[i] == null) ? IntPtr.Zero : commandLists[i].NativePointer;
78+
}
79+
80+
ExecuteCommandLists(count, new IntPtr(commandListsPtr));
4581
}
4682
}
4783
}

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
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
using System;
22+
using System.Threading;
23+
24+
namespace SharpDX.Direct3D12
25+
{
26+
public partial class DescriptorHeap
27+
{
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="DescriptorHeap"/> class.
30+
/// </summary>
31+
/// <param name="device">The device with which to associate the command allocator.</param>
32+
/// <param name="description"><see cref="DescriptorHeapDescription"/> structure that describes the heap.</param>
33+
public DescriptorHeap(Device device, DescriptorHeapDescription description)
34+
: base(IntPtr.Zero)
35+
{
36+
device.CreateDescriptorHeap(
37+
ref description,
38+
Utilities.GetGuidFromType(typeof(DescriptorHeap)),
39+
this);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)