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

Commit 1b22d9e

Browse files
committed
GraphicsCommandList improvements and add better BeginEvent and SetMarker methods.
1 parent 55abe14 commit 1b22d9e

File tree

1 file changed

+69
-25
lines changed

1 file changed

+69
-25
lines changed

Source/SharpDX.Direct3D12/GraphicsCommandList.cs

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// THE SOFTWARE.
2020

2121
using System;
22+
using System.Runtime.InteropServices;
2223

2324
namespace SharpDX.Direct3D12
2425
{
@@ -142,7 +143,7 @@ public unsafe void ResourceBarrier(SharpDX.Direct3D12.ResourceBarrier barrier)
142143
/// <unmanaged-short>ID3D12GraphicsCommandList::ResourceBarrier</unmanaged-short>
143144
public unsafe void ResourceBarrier(params SharpDX.Direct3D12.ResourceBarrier[] barriers)
144145
{
145-
if(barriers == null) throw new ArgumentNullException("barriers");
146+
if (barriers == null) throw new ArgumentNullException("barriers");
146147

147148
fixed (void* pBarriers = barriers)
148149
ResourceBarrier(barriers.Length, new IntPtr(pBarriers));
@@ -197,7 +198,7 @@ public unsafe void SetRenderTargets(CpuDescriptorHandle[] renderTargetDescriptor
197198
public unsafe void SetRenderTargets(CpuDescriptorHandle? renderTargetDescriptor, SharpDX.Direct3D12.CpuDescriptorHandle? depthStencilDescriptorRef)
198199
{
199200
var renderTargetDesc = new CpuDescriptorHandle();
200-
if(renderTargetDescriptor.HasValue)
201+
if (renderTargetDescriptor.HasValue)
201202
{
202203
renderTargetDesc = renderTargetDescriptor.Value;
203204
}
@@ -208,17 +209,16 @@ public unsafe void SetRenderTargets(CpuDescriptorHandle? renderTargetDescriptor,
208209
/// <p>Sets a CPU descriptor handle for the vertex buffers.</p>
209210
/// </summary>
210211
/// <param name="startSlot"><dd> <p> Index into the device's zero-based array to begin setting vertex buffers. </p> </dd></param>
211-
/// <param name="numViews"><dd> <p> The number of views in the <em>pViews</em> array. </p> </dd></param>
212-
/// <param name="viewsRef"><dd> <p> Specifies the vertex buffer views in an array of <strong><see cref="SharpDX.Direct3D12.VertexBufferView"/></strong> structures. </p> </dd></param>
213-
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::IASetVertexBuffers']/*"/>
212+
/// <param name="vertexBufferViews"><dd> <p> Specifies the vertex buffer views in an array of <strong><see cref="SharpDX.Direct3D12.VertexBufferView"/></strong> structures. </p> </dd></param>
213+
/// <param name="numBuffers"><dd> <p> The number of views in the <em>pViews</em> array. </p> </dd></param>
214214
/// <msdn-id>dn986883</msdn-id>
215215
/// <unmanaged>void ID3D12GraphicsCommandList::IASetVertexBuffers([In] unsigned int StartSlot,[In] unsigned int NumViews,[In] const void* pViews)</unmanaged>
216216
/// <unmanaged-short>ID3D12GraphicsCommandList::IASetVertexBuffers</unmanaged-short>
217-
public void SetVertexBuffers(int startSlot, SharpDX.Direct3D12.VertexBufferView[] descRef, int numBuffers)
217+
public void SetVertexBuffers(int startSlot, SharpDX.Direct3D12.VertexBufferView[] vertexBufferViews, int numBuffers)
218218
{
219219
unsafe
220220
{
221-
fixed (void* descPtr = descRef)
221+
fixed (void* descPtr = vertexBufferViews)
222222
SetVertexBuffers(startSlot, numBuffers, new IntPtr(descPtr));
223223
}
224224
}
@@ -227,35 +227,31 @@ public void SetVertexBuffers(int startSlot, SharpDX.Direct3D12.VertexBufferView[
227227
/// <p>Sets a CPU descriptor handle for the vertex buffers.</p>
228228
/// </summary>
229229
/// <param name="startSlot"><dd> <p> Index into the device's zero-based array to begin setting vertex buffers. </p> </dd></param>
230-
/// <param name="numViews"><dd> <p> The number of views in the <em>pViews</em> array. </p> </dd></param>
231-
/// <param name="viewsRef"><dd> <p> Specifies the vertex buffer views in an array of <strong><see cref="SharpDX.Direct3D12.VertexBufferView"/></strong> structures. </p> </dd></param>
232-
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::IASetVertexBuffers']/*"/>
230+
/// <param name="vertexBufferView"><dd> <p> Specifies the vertex buffer view of <strong><see cref="SharpDX.Direct3D12.VertexBufferView"/></strong> structures. </p> </dd></param>
233231
/// <msdn-id>dn986883</msdn-id>
234232
/// <unmanaged>void ID3D12GraphicsCommandList::IASetVertexBuffers([In] unsigned int StartSlot,[In] unsigned int NumViews,[In] const void* pViews)</unmanaged>
235233
/// <unmanaged-short>ID3D12GraphicsCommandList::IASetVertexBuffers</unmanaged-short>
236-
public void SetVertexBuffer(int startSlot, SharpDX.Direct3D12.VertexBufferView descRef)
234+
public void SetVertexBuffer(int startSlot, SharpDX.Direct3D12.VertexBufferView vertexBufferView)
237235
{
238236
unsafe
239237
{
240-
SetVertexBuffers(startSlot, 1, (IntPtr)(&descRef));
238+
SetVertexBuffers(startSlot, 1, (IntPtr)(&vertexBufferView));
241239
}
242240
}
243241

244242
/// <summary>
245243
/// <p> Bind an array of viewports to the rasterizer stage of the pipeline. </p>
246244
/// </summary>
247-
/// <param name="numViewports"><dd> <p> Number of viewports to bind. The range of valid values is (0, D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE). </p> </dd></param>
248-
/// <param name="viewportsRef"><dd> <p> An array of <strong><see cref="SharpDX.Direct3D12.Viewport"/></strong> structures to bind to the device. </p> </dd></param>
245+
/// <param name="viewports"><dd> <p> Number of viewports to bind. The range of valid values is (0, D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE). </p> </dd></param>
249246
/// <remarks>
250247
/// <p> All viewports must be set atomically as one operation. Any viewports not defined by the call are disabled. </p><p> Which viewport to use is determined by the SV_ViewportArrayIndex semantic output by a geometry shader; if a geometry shader does not specify the semantic, Direct3D will use the first viewport in the array. </p><strong>Note</strong> Even though you specify float values to the members of the <strong><see cref="SharpDX.Direct3D12.Viewport"/></strong> structure for the <em>pViewports</em> array in a call to <strong>RSSetViewports</strong> for feature levels 9_x, <strong>RSSetViewports</strong> uses DWORDs internally. Because of this behavior, when you use a negative top left corner for the viewport, the call to <strong>RSSetViewports</strong> for feature levels 9_x fails. This failure occurs because <strong>RSSetViewports</strong> for 9_x casts the floating point values into unsigned integers without validation, which results in integer overflow.
251248
/// </remarks>
252-
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::RSSetViewports']/*"/>
253249
/// <msdn-id>dn903900</msdn-id>
254250
/// <unmanaged>void ID3D12GraphicsCommandList::RSSetViewports([In] unsigned int NumViewports,[In, Buffer] const D3D12_VIEWPORT* pViewports)</unmanaged>
255251
/// <unmanaged-short>ID3D12GraphicsCommandList::RSSetViewports</unmanaged-short>
256252
public void SetViewports(params SharpDX.Mathematics.Interop.RawViewportF[] viewports)
257253
{
258-
if(viewports == null) throw new ArgumentNullException("viewports");
254+
if (viewports == null) throw new ArgumentNullException("viewports");
259255
unsafe
260256
{
261257
fixed (void* pViewPorts = viewports)
@@ -266,12 +262,10 @@ public void SetViewports(params SharpDX.Mathematics.Interop.RawViewportF[] viewp
266262
/// <summary>
267263
/// <p> Bind an array of viewports to the rasterizer stage of the pipeline. </p>
268264
/// </summary>
269-
/// <param name="numViewports"><dd> <p> Number of viewports to bind. The range of valid values is (0, D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE). </p> </dd></param>
270-
/// <param name="viewportsRef"><dd> <p> An array of <strong><see cref="SharpDX.Direct3D12.Viewport"/></strong> structures to bind to the device. </p> </dd></param>
265+
/// <param name="viewport"><dd> <p> Number of viewports to bind. The range of valid values is (0, D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE). </p> </dd></param>
271266
/// <remarks>
272267
/// <p> All viewports must be set atomically as one operation. Any viewports not defined by the call are disabled. </p><p> Which viewport to use is determined by the SV_ViewportArrayIndex semantic output by a geometry shader; if a geometry shader does not specify the semantic, Direct3D will use the first viewport in the array. </p><strong>Note</strong> Even though you specify float values to the members of the <strong><see cref="SharpDX.Direct3D12.Viewport"/></strong> structure for the <em>pViewports</em> array in a call to <strong>RSSetViewports</strong> for feature levels 9_x, <strong>RSSetViewports</strong> uses DWORDs internally. Because of this behavior, when you use a negative top left corner for the viewport, the call to <strong>RSSetViewports</strong> for feature levels 9_x fails. This failure occurs because <strong>RSSetViewports</strong> for 9_x casts the floating point values into unsigned integers without validation, which results in integer overflow.
273268
/// </remarks>
274-
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::RSSetViewports']/*"/>
275269
/// <msdn-id>dn903900</msdn-id>
276270
/// <unmanaged>void ID3D12GraphicsCommandList::RSSetViewports([In] unsigned int NumViewports,[In, Buffer] const D3D12_VIEWPORT* pViewports)</unmanaged>
277271
/// <unmanaged-short>ID3D12GraphicsCommandList::RSSetViewports</unmanaged-short>
@@ -283,9 +277,7 @@ public unsafe void SetViewport(SharpDX.Mathematics.Interop.RawViewportF viewport
283277
/// <summary>
284278
/// Binds an array of scissor rectangles to the rasterizer stage.
285279
/// </summary>
286-
/// <param name="numRects">No documentation.</param>
287-
/// <param name="rectsRef">No documentation.</param>
288-
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::RSSetScissorRects']/*"/>
280+
/// <param name="rectangles">No documentation.</param>
289281
/// <msdn-id>dn903899</msdn-id>
290282
/// <unmanaged>void ID3D12GraphicsCommandList::RSSetScissorRects([In] unsigned int NumRects,[In, Buffer] const RECT* pRects)</unmanaged>
291283
/// <unmanaged-short>ID3D12GraphicsCommandList::RSSetScissorRects</unmanaged-short>
@@ -298,15 +290,67 @@ public void SetScissorRectangles(params SharpDX.Mathematics.Interop.RawRectangle
298290
/// <summary>
299291
/// Binds an array of scissor rectangles to the rasterizer stage.
300292
/// </summary>
301-
/// <param name="numRects">No documentation.</param>
302-
/// <param name="rectsRef">No documentation.</param>
303-
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::RSSetScissorRects']/*"/>
293+
/// <param name="rectangle">No documentation.</param>
304294
/// <msdn-id>dn903899</msdn-id>
305295
/// <unmanaged>void ID3D12GraphicsCommandList::RSSetScissorRects([In] unsigned int NumRects,[In, Buffer] const RECT* pRects)</unmanaged>
306296
/// <unmanaged-short>ID3D12GraphicsCommandList::RSSetScissorRects</unmanaged-short>
307297
public unsafe void SetScissorRectangles(SharpDX.Mathematics.Interop.RawRectangle rectangle)
308298
{
309299
SetScissorRectangles(1, new IntPtr(&rectangle));
310300
}
301+
302+
/// <summary>
303+
/// <p> For internal use only. </p>
304+
/// </summary>
305+
/// <param name="name"><dd> <p> Internal. </p> </dd></param>
306+
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::BeginEvent']/*"/>
307+
/// <msdn-id>dn986879</msdn-id>
308+
/// <unmanaged>void ID3D12GraphicsCommandList::BeginEvent([In] unsigned int Metadata,[In, Buffer, Optional] const void* pData,[In] unsigned int Size)</unmanaged>
309+
/// <unmanaged-short>ID3D12GraphicsCommandList::BeginEvent</unmanaged-short>
310+
public void BeginEvent(string name)
311+
{
312+
if (name == null) throw new ArgumentNullException("name");
313+
IntPtr hMessage = IntPtr.Zero;
314+
try
315+
{
316+
hMessage = Marshal.StringToHGlobalUni(name);
317+
BeginEvent(1, hMessage, name.Length);
318+
}
319+
finally
320+
{
321+
if (hMessage != IntPtr.Zero)
322+
{
323+
Marshal.FreeHGlobal(hMessage);
324+
hMessage = IntPtr.Zero;
325+
}
326+
}
327+
}
328+
329+
/// <summary>
330+
/// <p> For internal use only.</p>
331+
/// </summary>
332+
/// <param name="name"><dd> <p> Internal. </p> </dd></param>
333+
/// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12GraphicsCommandList::SetMarker']/*"/>
334+
/// <msdn-id>dn986885</msdn-id>
335+
/// <unmanaged>void ID3D12GraphicsCommandList::SetMarker([In] unsigned int Metadata,[In, Buffer, Optional] const void* pData,[In] unsigned int Size)</unmanaged>
336+
/// <unmanaged-short>ID3D12GraphicsCommandList::SetMarker</unmanaged-short>
337+
public void SetMarker(string name)
338+
{
339+
if (name == null) throw new ArgumentNullException("name");
340+
IntPtr hMessage = IntPtr.Zero;
341+
try
342+
{
343+
hMessage = Marshal.StringToHGlobalUni(name);
344+
SetMarker(1, hMessage, name.Length);
345+
}
346+
finally
347+
{
348+
if (hMessage != IntPtr.Zero)
349+
{
350+
Marshal.FreeHGlobal(hMessage);
351+
hMessage = IntPtr.Zero;
352+
}
353+
}
354+
}
311355
}
312356
}

0 commit comments

Comments
 (0)