More D3D12 goodies.

This commit is contained in:
Amer Koleci
2022-11-21 11:21:28 +01:00
parent cf55322a11
commit cee7905599
14 changed files with 484 additions and 2 deletions

View File

@@ -15,7 +15,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<RestoreConfigFile>$(MSBuildThisFileDirectory)NuGet.config</RestoreConfigFile>
<VersionPrefix>1.8.7</VersionPrefix>
<VersionPrefix>1.8.8</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@@ -0,0 +1,28 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D12.Apis;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct DescriptorRange
{
public DescriptorRange(DescriptorRangeType rangeType, uint numDescriptors, uint baseShaderRegister, uint registerSpace = 0, uint offsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
Init(out this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
}
public void Init(DescriptorRangeType rangeType, uint numDescriptors, uint baseShaderRegister, uint registerSpace = 0, uint offsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
Init(out this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
}
public static void Init(out DescriptorRange range, DescriptorRangeType rangeType, uint numDescriptors, uint baseShaderRegister, uint registerSpace = 0, uint offsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
range.RangeType = rangeType;
range.NumDescriptors = numDescriptors;
range.BaseShaderRegister = baseShaderRegister;
range.RegisterSpace = registerSpace;
range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
}
}

View File

@@ -0,0 +1,29 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D12.Apis;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct DescriptorRange1
{
public DescriptorRange1(DescriptorRangeType rangeType, uint numDescriptors, uint baseShaderRegister, uint registerSpace = 0, DescriptorRangeFlags flags = DescriptorRangeFlags.None, uint offsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
Init(out this, rangeType, numDescriptors, baseShaderRegister, registerSpace, flags, offsetInDescriptorsFromTableStart);
}
public void Init(DescriptorRangeType rangeType, uint numDescriptors, uint baseShaderRegister, uint registerSpace = 0, DescriptorRangeFlags flags = DescriptorRangeFlags.None, uint offsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
Init(out this, rangeType, numDescriptors, baseShaderRegister, registerSpace, flags, offsetInDescriptorsFromTableStart);
}
public static void Init(out DescriptorRange1 range, DescriptorRangeType rangeType, uint numDescriptors, uint baseShaderRegister, uint registerSpace = 0, DescriptorRangeFlags flags = DescriptorRangeFlags.None, uint offsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)
{
range.RangeType = rangeType;
range.NumDescriptors = numDescriptors;
range.BaseShaderRegister = baseShaderRegister;
range.RegisterSpace = registerSpace;
range.Flags = flags;
range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
}
}

View File

@@ -0,0 +1,15 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
namespace Win32.Graphics.Direct3D12;
public partial struct RangeUInt64
{
public RangeUInt64(ulong begin, ulong end)
{
Begin = begin;
End = end;
}
}

View File

@@ -0,0 +1,45 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
namespace Win32.Graphics.Direct3D12;
public partial struct RenderPassBeginningAccess : IEquatable<RenderPassBeginningAccess>
{
public static bool operator ==(in RenderPassBeginningAccess left, in RenderPassBeginningAccess right)
{
if (left.Type != right.Type)
{
return false;
}
if (left.Type == RenderPassBeginningAccessType.Clear && !(left.Anonymous.Clear == right.Anonymous.Clear))
{
return false;
}
return true;
}
public static bool operator !=(in RenderPassBeginningAccess left, in RenderPassBeginningAccess right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is RenderPassBeginningAccess other) && Equals(other);
public bool Equals(RenderPassBeginningAccess other) => this == other;
public override int GetHashCode()
{
var hashCode = new HashCode();
{
hashCode.Add(Type);
if (Type == RenderPassBeginningAccessType.Clear)
{
hashCode.Add(Anonymous.Clear);
}
}
return hashCode.ToHashCode();
}
}

View File

@@ -0,0 +1,23 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
namespace Win32.Graphics.Direct3D12;
public partial struct RenderPassBeginningAccessClearParameters : IEquatable<RenderPassBeginningAccessClearParameters>
{
public static bool operator ==(in RenderPassBeginningAccessClearParameters left, in RenderPassBeginningAccessClearParameters right)
{
return left.ClearValue == right.ClearValue;
}
public static bool operator !=(in RenderPassBeginningAccessClearParameters left, in RenderPassBeginningAccessClearParameters right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is RenderPassBeginningAccessClearParameters other) && Equals(other);
public bool Equals(RenderPassBeginningAccessClearParameters other) => this == other;
public override int GetHashCode() => ClearValue.GetHashCode();
}

View File

@@ -0,0 +1,51 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
namespace Win32.Graphics.Direct3D12;
public partial struct RenderPassDepthStencilDescription : IEquatable<RenderPassDepthStencilDescription>
{
public static bool operator ==(in RenderPassDepthStencilDescription left, in RenderPassDepthStencilDescription right)
{
if (left.cpuDescriptor.ptr != right.cpuDescriptor.ptr)
{
return false;
}
if (!(left.DepthBeginningAccess == right.DepthBeginningAccess))
{
return false;
}
if (!(left.StencilBeginningAccess == right.StencilBeginningAccess))
{
return false;
}
if (!(left.DepthEndingAccess == right.DepthEndingAccess))
{
return false;
}
if (!(left.StencilEndingAccess == right.StencilEndingAccess))
{
return false;
}
return true;
}
public static bool operator !=(in RenderPassDepthStencilDescription left, in RenderPassDepthStencilDescription right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is RenderPassDepthStencilDescription other) && Equals(other);
public bool Equals(RenderPassDepthStencilDescription other) => this == other;
public override int GetHashCode()
{
return HashCode.Combine(cpuDescriptor, DepthBeginningAccess, StencilBeginningAccess, DepthEndingAccess, StencilEndingAccess);
}
}

View File

@@ -0,0 +1,45 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
namespace Win32.Graphics.Direct3D12;
public partial struct RenderPassEndingAccess : IEquatable<RenderPassEndingAccess>
{
public static bool operator ==(in RenderPassEndingAccess left, in RenderPassEndingAccess right)
{
if (left.Type != right.Type)
{
return false;
}
if (left.Type == RenderPassEndingAccessType.Resolve && !(left.Anonymous.Resolve == right.Anonymous.Resolve))
{
return false;
}
return true;
}
public static bool operator !=(in RenderPassEndingAccess left, in RenderPassEndingAccess right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is RenderPassEndingAccess other) && Equals(other);
public bool Equals(RenderPassEndingAccess other) => this == other;
public override int GetHashCode()
{
var hashCode = new HashCode();
{
hashCode.Add(Type);
if (Type == RenderPassEndingAccessType.Resolve)
{
hashCode.Add(Anonymous.Resolve);
}
}
return hashCode.ToHashCode();
}
}

View File

@@ -0,0 +1,61 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct RenderPassEndingAccessResolveParameters : IEquatable<RenderPassEndingAccessResolveParameters>
{
public static bool operator ==(in RenderPassEndingAccessResolveParameters left, in RenderPassEndingAccessResolveParameters right)
{
if (left.pSrcResource != right.pSrcResource)
{
return false;
}
if (left.pDstResource != right.pDstResource)
{
return false;
}
if (left.SubresourceCount != right.SubresourceCount)
{
return false;
}
if (left.Format != right.Format)
{
return false;
}
if (left.ResolveMode != right.ResolveMode)
{
return false;
}
if (left.PreserveResolveSource != right.PreserveResolveSource)
{
return false;
}
return true;
}
public static bool operator !=(in RenderPassEndingAccessResolveParameters left, in RenderPassEndingAccessResolveParameters right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is RenderPassEndingAccessResolveParameters other) && Equals(other);
public bool Equals(RenderPassEndingAccessResolveParameters other) => this == other;
public override int GetHashCode()
{
return HashCode.Combine(
(nuint)pSrcResource,
(nuint)pDstResource,
SubresourceCount,
(nuint)pSubresourceParameters,
Format,
ResolveMode,
PreserveResolveSource);
}
}

View File

@@ -0,0 +1,39 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct RenderPassRenderTargetDescription : IEquatable<RenderPassRenderTargetDescription>
{
public static bool operator ==(in RenderPassRenderTargetDescription left, in RenderPassRenderTargetDescription right)
{
if (left.cpuDescriptor.ptr != right.cpuDescriptor.ptr)
{
return false;
}
if (!(left.BeginningAccess == right.BeginningAccess))
{
return false;
}
if (!(left.EndingAccess == right.EndingAccess))
{
return false;
}
return true;
}
public static bool operator !=(in RenderPassRenderTargetDescription left, in RenderPassRenderTargetDescription right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is RenderPassRenderTargetDescription other) && Equals(other);
public bool Equals(RenderPassRenderTargetDescription other) => this == other;
public override int GetHashCode()
{
return HashCode.Combine(cpuDescriptor, BeginningAccess, EndingAccess);
}
}

View File

@@ -0,0 +1,43 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D12.Apis;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct ResourceBarrier
{
public static ResourceBarrier InitTransition(
ID3D12Resource* pResource,
ResourceStates stateBefore,
ResourceStates stateAfter,
uint subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
ResourceBarrierFlags flags = ResourceBarrierFlags.None)
{
ResourceBarrier result = default;
result.Type = ResourceBarrierType.Transition;
result.Flags = flags;
result.Anonymous.Transition.pResource = pResource;
result.Anonymous.Transition.StateBefore = stateBefore;
result.Anonymous.Transition.StateAfter = stateAfter;
result.Anonymous.Transition.Subresource = subresource;
return result;
}
public static ResourceBarrier InitAliasing(ID3D12Resource* pResourceBefore, ID3D12Resource* pResourceAfter)
{
ResourceBarrier result = default;
result.Type = ResourceBarrierType.Aliasing;
result.Anonymous.Aliasing.pResourceBefore = pResourceBefore;
result.Anonymous.Aliasing.pResourceAfter = pResourceAfter;
return result;
}
public static ResourceBarrier InitUAV(ID3D12Resource* pResource)
{
ResourceBarrier result = default;
result.Type = ResourceBarrierType.Uav;
result.Anonymous.UAV.pResource = pResource;
return result;
}
}

View File

@@ -0,0 +1,20 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct SubresourceRangeUInt64
{
public SubresourceRangeUInt64(uint subresource, RangeUInt64* range)
{
Subresource = subresource;
Range = *range;
}
public SubresourceRangeUInt64(uint subresource, ulong begin, ulong end)
{
Subresource = subresource;
Range.Begin = begin;
Range.End = end;
}
}

View File

@@ -0,0 +1,83 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
using static Win32.Graphics.Direct3D12.Apis;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct VersionedRootSignatureDescription
{
public VersionedRootSignatureDescription(in RootSignatureDescription other)
{
Unsafe.SkipInit(out this);
Version = RootSignatureVersion.V1_0;
Anonymous.Desc_1_0 = other;
}
public VersionedRootSignatureDescription(in RootSignatureDescription1 other)
{
Unsafe.SkipInit(out this);
Version = RootSignatureVersion.V1_1;
Anonymous.Desc_1_1 = other;
}
public VersionedRootSignatureDescription(uint numParameters, RootParameter* _pParameters, uint numStaticSamplers = 0, StaticSamplerDescription* _pStaticSamplers = null, RootSignatureFlags flags = RootSignatureFlags.None)
{
Init_1_0(out this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
public VersionedRootSignatureDescription(uint numParameters, RootParameter1* _pParameters, uint numStaticSamplers = 0, StaticSamplerDescription* _pStaticSamplers = null, RootSignatureFlags flags = RootSignatureFlags.None)
{
Init_1_1(out this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
public void Init_1_0(
uint numParameters, RootParameter* parameters,
uint numStaticSamplers = 0, StaticSamplerDescription* staticSamplers = null,
RootSignatureFlags flags = RootSignatureFlags.None)
{
Init_1_0(out this, numParameters, parameters, numStaticSamplers, staticSamplers, flags);
}
public static void Init_1_0(out VersionedRootSignatureDescription desc,
uint numParameters, RootParameter* parameters,
uint numStaticSamplers = 0, StaticSamplerDescription* staticSamplers = null,
RootSignatureFlags flags = RootSignatureFlags.None)
{
desc = default;
desc.Version = RootSignatureVersion.V1_0;
desc.Anonymous.Desc_1_0.NumParameters = numParameters;
desc.Anonymous.Desc_1_0.pParameters = parameters;
desc.Anonymous.Desc_1_0.NumStaticSamplers = numStaticSamplers;
desc.Anonymous.Desc_1_0.pStaticSamplers = staticSamplers;
desc.Anonymous.Desc_1_0.Flags = flags;
}
public void Init_1_1(
uint numParameters, RootParameter1* parameters,
uint numStaticSamplers = 0, StaticSamplerDescription* staticSamplers = null,
RootSignatureFlags flags = RootSignatureFlags.None)
{
Init_1_1(out this, numParameters, parameters, numStaticSamplers, staticSamplers, flags);
}
public static void Init_1_1(
out VersionedRootSignatureDescription desc,
uint numParameters, RootParameter1* parameters,
uint numStaticSamplers = 0, StaticSamplerDescription* staticSamplers = null,
RootSignatureFlags flags = RootSignatureFlags.None)
{
desc = default;
desc.Version = RootSignatureVersion.V1_1;
desc.Anonymous.Desc_1_1.NumParameters = numParameters;
desc.Anonymous.Desc_1_1.pParameters = parameters;
desc.Anonymous.Desc_1_1.NumStaticSamplers = numStaticSamplers;
desc.Anonymous.Desc_1_1.pStaticSamplers = staticSamplers;
desc.Anonymous.Desc_1_1.Flags = flags;
}
}

View File

@@ -93,7 +93,7 @@ public static unsafe class Program
d2d1Factory2.GetVoidAddressOf()).ThrowIfFailed();
using ComPtr<IDWriteFactory> dwriteFactory = default;
DWriteCreateFactory(DWriteFactoryType.Shared, __uuidof<IDWriteFactory>(), dwriteFactory.GetIUnknownAddressOf()).ThrowIfFailed();
DWriteCreateFactory(DWriteFactoryType.Shared, __uuidof<IDWriteFactory>(), dwriteFactory.GetVoidAddressOf()).ThrowIfFailed();
using ComPtr<IDWriteTextFormat> textFormat =
dwriteFactory.Get()->CreateTextFormat(