Skip to content

Commit

Permalink
[Direct3D12] - Lot of raytracing bindings and improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkoleci committed Sep 11, 2019
1 parent 0b63f0b commit ea17b58
Show file tree
Hide file tree
Showing 32 changed files with 446 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ KEY CHANGES:
- Multiplatform support: targets netstandard2.0 and uap10.0.16299.
- Improvements in Direct3D12 raytracing API, StateObject and StateSubObject.
- Fixes #22 - Load dxil.dll first before dxcompiler.dll.
- Improvements in Direct3D12 raytracing API and structures.
- Fix UINT16 to System.UInt16 and UINT64 to System.UInt64 (to avoid interop issues).

-----------------------------------------------
Release: 1.2.0 (September 2019)
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.DXGI/IDXGIInfoQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Vortice.DXGI
{
public partial class IDXGIInfoQueue
{
public unsafe InfoQueueMessage GetMessage(Guid producer, long messageIndex)
public unsafe InfoQueueMessage GetMessage(Guid producer, ulong messageIndex)
{
PointerSize messageSize = 0;
GetMessage(producer, messageIndex, IntPtr.Zero, ref messageSize);
Expand Down
2 changes: 0 additions & 2 deletions src/Vortice.DXGI/Mappings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
</extension>

<bindings>
<bind from="UINT16" to="System.Int16" />
<bind from="UINT32" to="System.Int32" />
<bind from="UINT64" to="System.Int64" />
<bind from="LUID" to="System.Int64"/>
<bind from="DXGI_RGB" to="Vortice.Mathematics.Color3" />
<bind from="DXGI_RGBA" to="Vortice.Mathematics.Color4" />
Expand Down
2 changes: 0 additions & 2 deletions src/Vortice.Direct2D1/Mappings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
</extension>

<bindings>
<bind from="UINT16" to="System.Int16" />
<bind from="UINT32" to="System.Int32" />
<bind from="UINT64" to="System.Int64" />
<bind from="DWORD" to="System.UInt32" />

<bind from="D2D_SIZE_U" to="System.Drawing.Size" />
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.Direct3D11/Debug/ID3D11InfoQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Vortice.Direct3D11.Debug
{
public partial class ID3D11InfoQueue
{
public unsafe Message GetMessage(long messageIndex)
public unsafe Message GetMessage(ulong messageIndex)
{
PointerSize messageSize = 0;
GetMessage(messageIndex, IntPtr.Zero, ref messageSize);
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.Direct3D11/ID3D11Device5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Vortice.Direct3D11
{
public partial class ID3D11Device5
{
public ID3D11Fence CreateFence(long initialValue, FenceFlags flags = FenceFlags.None)
public ID3D11Fence CreateFence(ulong initialValue, FenceFlags flags = FenceFlags.None)
{
return CreateFence(initialValue, flags, typeof(ID3D11Fence).GUID);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.Direct3D11/ID3D11Fence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public IntPtr CreateSharedHandle(SecurityAttributes? attributes, string name)
return CreateSharedHandle(attributes, GENERIC_ALL, name);
}

public void SetEventOnCompletion(long value, EventWaitHandle waitHandle)
public void SetEventOnCompletion(ulong value, EventWaitHandle waitHandle)
{
SetEventOnCompletion(value, waitHandle.SafeWaitHandle.DangerousGetHandle());
}
Expand Down
2 changes: 0 additions & 2 deletions src/Vortice.Direct3D11/Mappings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@
</extension>

<bindings>
<bind from="UINT16" to="System.Int16" />
<bind from="UINT32" to="System.Int32" />
<bind from="UINT64" to="System.Int64" />
<bind from="LUID" to="System.Int64"/>
<bind from="VORTICE_VECTOR4" to="System.Numerics.Vector4" />
<bind from="VORTICE_COLOR4" to="Vortice.Mathematics.Color4" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Amer Koleci and contributors.
// Distributed under the MIT license. See the LICENSE file in the project root for more information.

namespace Vortice.Direct3D12
{
/// <summary>
/// Describes a raytracing acceleration structure. Pass this structure into <see cref="ID3D12GraphicsCommandList4.BuildRaytracingAccelerationStructure(BuildRaytracingAccelerationStructureDescription)"/> to describe the acceleration structure to be built.
/// </summary>
public partial struct BuildRaytracingAccelerationStructureDescription
{
/// <summary>
/// Initializes a new instance of the <see cref="BuildRaytracingAccelerationStructureDescription"/> struct.
/// </summary>
/// <param name="destinationAccelerationStructureData">
/// Location to store resulting acceleration structure. <see cref="ID3D12Device5.GetRaytracingAccelerationStructurePrebuildInfo(BuildRaytracingAccelerationStructureInputs)"/> reports the amount of memory required for the result here given a set of acceleration structure build parameters.
/// The address must be aligned to 256 bytes, defined as <see cref="RaytracingAccelerationStructureByteAlignment"/>.
/// The memory pointed to must be in state <see cref="ResourceStates.RaytracingAccelerationStructure"/>.
/// </param>
/// <param name="inputs">Description of the input data for the acceleration structure build. This is data is stored in a separate structure because it is also used with <see cref="ID3D12Device5.GetRaytracingAccelerationStructurePrebuildInfo(BuildRaytracingAccelerationStructureInputs)"/>.</param>
/// <param name="sourceAccelerationStructureData">Address of an existing acceleration structure if an acceleration structure update (an incremental build) is being requested, by setting <see cref="RaytracingAccelerationStructureBuildFlags.PerformUpdate"/> in the Flags parameter. Otherwise this address must be 0.</param>
/// <param name="scratchAccelerationStructureData">Location where the build will store temporary data. <see cref="ID3D12Device5.GetRaytracingAccelerationStructurePrebuildInfo(BuildRaytracingAccelerationStructureInputs)"/> reports the amount of scratch memory the implementation will need for a given set of acceleration structure build parameters.</param>
public BuildRaytracingAccelerationStructureDescription(
ulong destinationAccelerationStructureData,
BuildRaytracingAccelerationStructureInputs inputs,
ulong sourceAccelerationStructureData,
ulong scratchAccelerationStructureData)
{
DestinationAccelerationStructureData = destinationAccelerationStructureData;
Inputs = inputs;
SourceAccelerationStructureData = sourceAccelerationStructureData;
ScratchAccelerationStructureData = scratchAccelerationStructureData;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

namespace Vortice.Direct3D12
{
/// <summary>
/// Defines the inputs for a raytracing acceleration structure build operation.
/// This is used by <see cref="ID3D12GraphicsCommandList4.BuildRaytracingAccelerationStructure(BuildRaytracingAccelerationStructureDescription)"/> and <see cref="ID3D12Device5.GetRaytracingAccelerationStructurePrebuildInfo(BuildRaytracingAccelerationStructureInputs)"/>.
/// </summary>
public partial class BuildRaytracingAccelerationStructureInputs
{
public RaytracingAccelerationStructureType Type { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.Direct3D12/ConstantBufferViewDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial struct ConstantBufferViewDescription
/// </summary>
/// <param name="bufferLocation">The gpu virtual address of the constant buffer.</param>
/// <param name="sizeInBytes">The size in bytes of the constant buffer.</param>
public ConstantBufferViewDescription(long bufferLocation, int sizeInBytes, Format format)
public ConstantBufferViewDescription(ulong bufferLocation, int sizeInBytes)
{
BufferLocation = bufferLocation;
SizeInBytes = sizeInBytes;
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.Direct3D12/Debug/ID3D12InfoQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Vortice.Direct3D12.Debug
{
public partial class ID3D12InfoQueue
{
public unsafe Message GetMessage(long messageIndex)
public unsafe Message GetMessage(ulong messageIndex)
{
PointerSize messageSize = 0;
GetMessage(messageIndex, IntPtr.Zero, ref messageSize);
Expand Down
20 changes: 17 additions & 3 deletions src/Vortice.Direct3D12/GpuDescriptorHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Vortice.Direct3D12
public partial struct GpuDescriptorHandle : IEquatable<GpuDescriptorHandle>
{
/// <summary>
/// Adds an offset to a descriptor handle
/// Adds an offset to a descriptor handle.
/// </summary>
/// <param name = "left">Initial descriptor handle</param>
/// <param name = "right">Offset to apply, use <see cref="ID3D12Device.GetDescriptorHandleIncrementSize(DescriptorHeapType)"/> with the relevant heap type.</param>
Expand All @@ -18,7 +18,21 @@ public partial struct GpuDescriptorHandle : IEquatable<GpuDescriptorHandle>
{
return new GpuDescriptorHandle()
{
Ptr = left.Ptr + (long)right
Ptr = left.Ptr + (ulong)right
};
}

/// <summary>
/// Adds an offset to a descriptor handle.
/// </summary>
/// <param name = "left">Initial descriptor handle</param>
/// <param name = "right">Offset to apply, use <see cref="ID3D12Device.GetDescriptorHandleIncrementSize(DescriptorHeapType)"/> with the relevant heap type.</param>
/// <returns>Offsetted descriptor handle</returns>
public static GpuDescriptorHandle operator +(GpuDescriptorHandle left, uint right)
{
return new GpuDescriptorHandle()
{
Ptr = left.Ptr + right
};
}

Expand All @@ -28,7 +42,7 @@ public partial struct GpuDescriptorHandle : IEquatable<GpuDescriptorHandle>
/// <param name = "left">Initial descriptor handle</param>
/// <param name = "right">Offset to apply, use <see cref="ID3D12Device.GetDescriptorHandleIncrementSize(DescriptorHeapType)"/> with the relevant heap type.</param>
/// <returns>Offsetted descriptor handle</returns>
public static GpuDescriptorHandle operator +(GpuDescriptorHandle left, long right)
public static GpuDescriptorHandle operator +(GpuDescriptorHandle left, ulong right)
{
return new GpuDescriptorHandle()
{
Expand Down
22 changes: 22 additions & 0 deletions src/Vortice.Direct3D12/GpuVirtualAddressAndStride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Amer Koleci and contributors.
// Distributed under the MIT license. See the LICENSE file in the project root for more information.

namespace Vortice.Direct3D12
{
/// <summary>
/// Describes a GPU virtual address and indexing stride.
/// </summary>
public partial struct GpuVirtualAddressAndStride
{
/// <summary>
/// Initializes a new instance of the <see cref="GpuVirtualAddressAndStride"/> struct.
/// </summary>
/// <param name="startAddress">The beginning of the virtual address range.</param>
/// <param name="strideInBytes">Defines indexing stride, such as for vertices. Only the bottom 32 bits are used. The field is 64 bits to make alignment of containing structures consistent everywhere.</param>
public GpuVirtualAddressAndStride(ulong startAddress, ulong strideInBytes)
{
StartAddress = startAddress;
StrideInBytes = strideInBytes;
}
}
}
22 changes: 22 additions & 0 deletions src/Vortice.Direct3D12/GpuVirtualAddressRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Amer Koleci and contributors.
// Distributed under the MIT license. See the LICENSE file in the project root for more information.

namespace Vortice.Direct3D12
{
/// <summary>
/// Describes a GPU virtual address range.
/// </summary>
public partial struct GpuVirtualAddressRange
{
/// <summary>
/// Initializes a new instance of the <see cref="GpuVirtualAddressRange"/> struct.
/// </summary>
/// <param name="startAddress">The beginning of the virtual address range.</param>
/// <param name="sizeInBytes">The size of the virtual address range, in bytes.</param>
public GpuVirtualAddressRange(ulong startAddress, ulong sizeInBytes)
{
StartAddress = startAddress;
SizeInBytes = sizeInBytes;
}
}
}
24 changes: 24 additions & 0 deletions src/Vortice.Direct3D12/GpuVirtualAddressRangeAndStride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Amer Koleci and contributors.
// Distributed under the MIT license. See the LICENSE file in the project root for more information.

namespace Vortice.Direct3D12
{
/// <summary>
/// Describes a GPU virtual address range and stride.
/// </summary>
public partial struct GpuVirtualAddressRangeAndStride
{
/// <summary>
/// Initializes a new instance of the <see cref="GpuVirtualAddressRangeAndStride"/> struct.
/// </summary>
/// <param name="startAddress">The beginning of the virtual address range.</param>
/// <param name="sizeInBytes">The size of the virtual address range, in bytes.</param>
/// <param name="strideInBytes">Defines the record-indexing stride within the memory range.</param>
public GpuVirtualAddressRangeAndStride(ulong startAddress, ulong sizeInBytes, ulong strideInBytes)
{
StartAddress = startAddress;
SizeInBytes = sizeInBytes;
StrideInBytes = strideInBytes;
}
}
}
4 changes: 2 additions & 2 deletions src/Vortice.Direct3D12/ID3D12Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public ID3D12GraphicsCommandList CreateCommandList(int nodeMask, CommandListType
return new ID3D12GraphicsCommandList(nativePtr);
}

public ID3D12Fence CreateFence(long initialValue, FenceFlags flags = FenceFlags.None)
public ID3D12Fence CreateFence(ulong initialValue, FenceFlags flags = FenceFlags.None)
{
return CreateFence(initialValue, flags, typeof(ID3D12Fence).GUID);
}
Expand Down Expand Up @@ -407,7 +407,7 @@ public ID3D12QueryHeap CreateQueryHeap(QueryHeapDescription description)

public ID3D12Resource CreatePlacedResource(
ID3D12Heap heap,
long heapOffset,
ulong heapOffset,
ResourceDescription resourceDescription,
ResourceStates initialState,
ClearValue? clearValue = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.Direct3D12/ID3D12Device3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class ID3D12Device3
/// <summary>
/// Asynchronously makes objects resident for the device.
/// </summary>
public Result EnqueueMakeResident(ResidencyFlags flags, ID3D12Pageable[] objects, ID3D12Fence fenceToSignal, long fenceValueToSignal)
public Result EnqueueMakeResident(ResidencyFlags flags, ID3D12Pageable[] objects, ID3D12Fence fenceToSignal, ulong fenceValueToSignal)
{
return EnqueueMakeResident(flags, objects?.Length ?? 0, objects, fenceToSignal, fenceValueToSignal);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vortice.Direct3D12/ID3D12Fence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Vortice.Direct3D12
{
public partial class ID3D12Fence
{
public void SetEventOnCompletion(long value, EventWaitHandle waitHandle)
public void SetEventOnCompletion(ulong value, EventWaitHandle waitHandle)
{
SetEventOnCompletion(value, waitHandle.SafeWaitHandle.DangerousGetHandle());
}
Expand Down
11 changes: 10 additions & 1 deletion src/Vortice.Direct3D12/ID3D12GraphicsCommandList4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ public void BeginRenderPass(RenderPassRenderTargetDescription[] renderTargets, R
BeginRenderPass(renderTargets.Length, renderTargets, depthStencil, flags);
}

/// <summary>
/// Performs a raytracing acceleration structure build on the GPU and optionally outputs post-build information immediately after the build.
/// </summary>
/// <param name="description">Description of the acceleration structure to build.</param>
public void BuildRaytracingAccelerationStructure(BuildRaytracingAccelerationStructureDescription description)
{
BuildRaytracingAccelerationStructure(ref description, 0, null);
}

/// <summary>
/// Performs a raytracing acceleration structure build on the GPU and optionally outputs post-build information immediately after the build.
/// </summary>
/// <param name="description">Description of the acceleration structure to build.</param>
/// <param name="postbuildInfoDescriptions">Array of descriptions for post-build info to generate describing properties of the acceleration structure that was built.</param>
public void BuildRaytracingAccelerationStructure(BuildRaytracingAccelerationStructureDescription description, RaytracingAccelerationStructurePostbuildInfoDescription[] postbuildInfoDescriptions)
{
BuildRaytracingAccelerationStructure(ref description, postbuildInfoDescriptions.Length, postbuildInfoDescriptions);
Expand Down Expand Up @@ -46,7 +55,7 @@ public void ExecuteMetaCommand(ID3D12MetaCommand metaCommand, Blob executionPara

public void EmitRaytracingAccelerationStructurePostbuildInfo(
RaytracingAccelerationStructurePostbuildInfoDescription description,
long[] sourceAccelerationStructureData)
ulong[] sourceAccelerationStructureData)
{
EmitRaytracingAccelerationStructurePostbuildInfo(description, sourceAccelerationStructureData.Length, sourceAccelerationStructureData);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Vortice.Direct3D12/IndexBufferView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial struct IndexBufferView
/// <param name="bufferLocation">Specifies a gpu virtual address that identifies the address of the buffer.</param>
/// <param name="sizeInBytes">Specifies the size in bytes of the index buffer.</param>
/// <param name="format">Specifies the <see cref="DXGI.Format"/> for the index-buffer format.</param>
public IndexBufferView(long bufferLocation, int sizeInBytes, Format format)
public IndexBufferView(ulong bufferLocation, int sizeInBytes, Format format)
{
BufferLocation = bufferLocation;
SizeInBytes = sizeInBytes;
Expand All @@ -29,7 +29,7 @@ public IndexBufferView(long bufferLocation, int sizeInBytes, Format format)
/// <param name="bufferLocation">Specifies a gpu virtual address that identifies the address of the buffer.</param>
/// <param name="sizeInBytes">Specifies the size in bytes of the index buffer.</param>
/// <param name="is32Bit">Specifies if index buffer is 32 bit or 16 bit sized.</param>
public IndexBufferView(long bufferLocation, int sizeInBytes, bool is32Bit = false)
public IndexBufferView(ulong bufferLocation, int sizeInBytes, bool is32Bit = false)
: this(bufferLocation, sizeInBytes, is32Bit ? Format.R32_UInt : Format.R16_UInt)
{
}
Expand Down
11 changes: 7 additions & 4 deletions src/Vortice.Direct3D12/Mappings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
<const from-macro="D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES" class="Vortice.Direct3D12.ResourceBarrier" type="int" name="AllSubResources" />

<const from-macro="D3D12_RAYTRACING_MAX_ATTRIBUTE_SIZE_IN_BYTES" class="Vortice.Direct3D12.RaytracingShaderConfig" type="int" name="RaytracingMaxAttributeSizeInBytes" />

<const from-macro="D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BYTE_ALIGNMENT" class="Vortice.Direct3D12.BuildRaytracingAccelerationStructureDescription" type="int" name="RaytracingAccelerationStructureByteAlignment" />
<const from-macro="D3D12_RAYTRACING_TRANSFORM3X4_BYTE_ALIGNMENT" class="Vortice.Direct3D12.RaytracingGeometryTrianglesDescription" type="int" name="RaytracingTransform3x4ByteAlignment" />
<const from-macro="D3D12_RAYTRACING_AABB_BYTE_ALIGNMENT" class="Vortice.Direct3D12.RaytracingGeometryAabbsDescription" type="int" name="RaytracingAABBByteAlignment" />

<define enum="Vortice.Direct3D12.Shader" sizeof="1" />
</extension>

<bindings>
<bind from="UINT16" to="System.Int16" />
<bind from="UINT32" to="System.Int32" />
<bind from="UINT64" to="System.Int64" />
<bind from="LUID" to="System.Int64"/>
<bind from="VORTICE_INT4" to="Vortice.Mathematics.Int4" />
<bind from="VORTICE_COLOR4" to="Vortice.Mathematics.Color4" />
Expand All @@ -67,6 +68,7 @@
<short name="POINT">Point</short>
<short name="POINTS">Points</short>
<short name="TRIANGLE">Triangle</short>
<short name="TRIANGLES">Triangles</short>
<short name="LIST">List</short>
<short name="ADJACENCY">Adjacency</short>
<short name="ADJ">Adjacency</short>
Expand Down Expand Up @@ -470,7 +472,8 @@
<remove field="D3D12_VERSIONED_ROOT_SIGNATURE_DESC::.*"/>

<map struct="D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS" struct-to-class="true" marshal="true" />

<map field="D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC::DestAccelerationStructureData" name="DestinationAccelerationStructureData" />

<map field="D3D12_CLEAR_VALUE::Color" type="VORTICE_COLOR4" array="" override-native-type="true" />

<map struct="D3D12_DEPTH_STENCILOP_DESC" name="DepthStencilOperationDescription" />
Expand Down
Loading

0 comments on commit ea17b58

Please sign in to comment.