Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some remaining static readonly with unmanaged constants + tests #196

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions samples/DirectX/D3D11/HelloTriangle11.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Numerics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D_DRIVER_TYPE;
using static TerraFX.Interop.D3D_FEATURE_LEVEL;
using static TerraFX.Interop.D3D_PRIMITIVE_TOPOLOGY;
using static TerraFX.Interop.D3D11_BIND_FLAG;
using static TerraFX.Interop.D3D11_INPUT_CLASSIFICATION;
using static TerraFX.Interop.D3D11_USAGE;
using static TerraFX.Interop.DXGI_FORMAT;
using static TerraFX.Interop.DXGI_SWAP_EFFECT;
using static TerraFX.Interop.Windows;
using static TerraFX.Samples.DirectX.DXSampleHelper;

Expand Down
1 change: 0 additions & 1 deletion samples/WinForms/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Windows.Forms;
using TerraFX.Samples.WinForms;

namespace TerraFX.Samples.WinForms
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Ported from DirectXHelpers.h in the microsoft/DirectXTK12 tag jan2021
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License.

using System;
using static TerraFX.Interop.D3D_ROOT_SIGNATURE_VERSION;

namespace TerraFX.Interop
Expand Down
111 changes: 97 additions & 14 deletions sources/Interop/Windows/other/d3dx12/D3D12_BLEND_DESC.Manual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,108 @@
// Ported from d3dx12.h in DirectX-Graphics-Samples commit a7a87f1853b5540f10920518021d91ae641033fb
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using static TerraFX.Interop.Windows;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace TerraFX.Interop
{
public unsafe partial struct D3D12_BLEND_DESC
{
public static readonly D3D12_BLEND_DESC DEFAULT = new D3D12_BLEND_DESC {
AlphaToCoverageEnable = FALSE,
IndependentBlendEnable = FALSE,
RenderTarget = new _RenderTarget_e__FixedBuffer() {
e0 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT,
e1 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT,
e2 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT,
e3 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT,
e4 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT,
e5 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT,
e6 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT,
e7 = D3D12_RENDER_TARGET_BLEND_DESC.DEFAULT
public static ref readonly D3D12_BLEND_DESC DEFAULT
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data = new byte[] {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00
};

Debug.Assert(data.Length == Unsafe.SizeOf<D3D12_BLEND_DESC>());
return ref Unsafe.As<byte, D3D12_BLEND_DESC>(ref MemoryMarshal.GetReference(data));
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace TerraFX.Interop
{
public unsafe partial struct D3D12_CPU_DESCRIPTOR_HANDLE : IEquatable<D3D12_CPU_DESCRIPTOR_HANDLE>
{
public static readonly D3D12_CPU_DESCRIPTOR_HANDLE DEFAULT = new D3D12_CPU_DESCRIPTOR_HANDLE {
ptr = 0
};
public static D3D12_CPU_DESCRIPTOR_HANDLE DEFAULT => default;

public D3D12_CPU_DESCRIPTOR_HANDLE([NativeTypeName("const D3D12_CPU_DESCRIPTOR_HANDLE &")] in D3D12_CPU_DESCRIPTOR_HANDLE other, [NativeTypeName("INT")] int offsetScaledByIncrementSize)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
// Ported from d3dx12.h in DirectX-Graphics-Samples commit a7a87f1853b5540f10920518021d91ae641033fb
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using static TerraFX.Interop.D3D12_COMPARISON_FUNC;
using static TerraFX.Interop.D3D12_STENCIL_OP;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace TerraFX.Interop
{
public partial struct D3D12_DEPTH_STENCILOP_DESC
{
public static readonly D3D12_DEPTH_STENCILOP_DESC DEFAULT = new D3D12_DEPTH_STENCILOP_DESC {
StencilFailOp = D3D12_STENCIL_OP_KEEP,
StencilDepthFailOp = D3D12_STENCIL_OP_KEEP,
StencilPassOp = D3D12_STENCIL_OP_KEEP,
StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS
};
public static ref readonly D3D12_DEPTH_STENCILOP_DESC DEFAULT
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data = new byte[] {
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00
};

Debug.Assert(data.Length == Unsafe.SizeOf<D3D12_DEPTH_STENCILOP_DESC>());
return ref Unsafe.As<byte, D3D12_DEPTH_STENCILOP_DESC>(ref MemoryMarshal.GetReference(data));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,42 @@
// Ported from d3dx12.h in DirectX-Graphics-Samples commit a7a87f1853b5540f10920518021d91ae641033fb
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using static TerraFX.Interop.D3D12_COMPARISON_FUNC;
using static TerraFX.Interop.D3D12_DEPTH_WRITE_MASK;
using static TerraFX.Interop.Windows;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace TerraFX.Interop
{
public partial struct D3D12_DEPTH_STENCIL_DESC
{
public static readonly D3D12_DEPTH_STENCIL_DESC DEFAULT = new D3D12_DEPTH_STENCIL_DESC {
DepthEnable = TRUE,
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL,
DepthFunc = D3D12_COMPARISON_FUNC_LESS,
StencilEnable = FALSE,
StencilReadMask = (byte)D3D12_DEFAULT_STENCIL_READ_MASK,
StencilWriteMask = (byte)D3D12_DEFAULT_STENCIL_WRITE_MASK,
FrontFace = D3D12_DEPTH_STENCILOP_DESC.DEFAULT,
BackFace = D3D12_DEPTH_STENCILOP_DESC.DEFAULT
};
public static ref readonly D3D12_DEPTH_STENCIL_DESC DEFAULT
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data = new byte[] {
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xFF,
0xFF,
0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00
};

Debug.Assert(data.Length == Unsafe.SizeOf<D3D12_DEPTH_STENCIL_DESC>());
return ref Unsafe.As<byte, D3D12_DEPTH_STENCIL_DESC>(ref MemoryMarshal.GetReference(data));
}
}

public D3D12_DEPTH_STENCIL_DESC([NativeTypeName("BOOL")] int depthEnable, D3D12_DEPTH_WRITE_MASK depthWriteMask, D3D12_COMPARISON_FUNC depthFunc, [NativeTypeName("BOOL")] int stencilEnable, [NativeTypeName("UINT8")] byte stencilReadMask, [NativeTypeName("UINT8")] byte stencilWriteMask, D3D12_STENCIL_OP frontStencilFailOp, D3D12_STENCIL_OP frontStencilDepthFailOp, D3D12_STENCIL_OP frontStencilPassOp, D3D12_COMPARISON_FUNC frontStencilFunc, D3D12_STENCIL_OP backStencilFailOp, D3D12_STENCIL_OP backStencilDepthFailOp, D3D12_STENCIL_OP backStencilPassOp, D3D12_COMPARISON_FUNC backStencilFunc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// Ported from d3dx12.h in DirectX-Graphics-Samples commit a7a87f1853b5540f10920518021d91ae641033fb
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using static TerraFX.Interop.D3D12_COMPARISON_FUNC;
using static TerraFX.Interop.D3D12_DEPTH_WRITE_MASK;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static TerraFX.Interop.Windows;

namespace TerraFX.Interop
Expand All @@ -30,17 +32,32 @@ public D3D12_DEPTH_STENCIL_DESC1([NativeTypeName("const D3D12_DEPTH_STENCIL_DESC
DepthBoundsTestEnable = FALSE;
}

public static readonly D3D12_DEPTH_STENCIL_DESC1 DEFAULT = new D3D12_DEPTH_STENCIL_DESC1 {
DepthEnable = TRUE,
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL,
DepthFunc = D3D12_COMPARISON_FUNC_LESS,
StencilEnable = FALSE,
StencilReadMask = (byte)D3D12_DEFAULT_STENCIL_READ_MASK,
StencilWriteMask = (byte)D3D12_DEFAULT_STENCIL_WRITE_MASK,
FrontFace = D3D12_DEPTH_STENCILOP_DESC.DEFAULT,
BackFace = D3D12_DEPTH_STENCILOP_DESC.DEFAULT,
DepthBoundsTestEnable = FALSE
};
public static ref readonly D3D12_DEPTH_STENCIL_DESC1 DEFAULT
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data = new byte[] {
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};

Debug.Assert(data.Length == Unsafe.SizeOf<D3D12_DEPTH_STENCIL_DESC1>());
return ref Unsafe.As<byte, D3D12_DEPTH_STENCIL_DESC1>(ref MemoryMarshal.GetReference(data));
}
}

public D3D12_DEPTH_STENCIL_DESC1([NativeTypeName("BOOL")] int depthEnable, D3D12_DEPTH_WRITE_MASK depthWriteMask, D3D12_COMPARISON_FUNC depthFunc, [NativeTypeName("BOOL")] int stencilEnable, [NativeTypeName("UINT8")] byte stencilReadMask, [NativeTypeName("UINT8")] byte stencilWriteMask, D3D12_STENCIL_OP frontStencilFailOp, D3D12_STENCIL_OP frontStencilDepthFailOp, D3D12_STENCIL_OP frontStencilPassOp, D3D12_COMPARISON_FUNC frontStencilFunc, D3D12_STENCIL_OP backStencilFailOp, D3D12_STENCIL_OP backStencilDepthFailOp, D3D12_STENCIL_OP backStencilPassOp, D3D12_COMPARISON_FUNC backStencilFunc, [NativeTypeName("BOOL")] int depthBoundsTestEnable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace TerraFX.Interop
{
public unsafe partial struct D3D12_GPU_DESCRIPTOR_HANDLE : IEquatable<D3D12_GPU_DESCRIPTOR_HANDLE>
{
public static readonly D3D12_GPU_DESCRIPTOR_HANDLE DEFAULT = new D3D12_GPU_DESCRIPTOR_HANDLE {
ptr = 0
};
public static D3D12_GPU_DESCRIPTOR_HANDLE DEFAULT => default;

public D3D12_GPU_DESCRIPTOR_HANDLE([NativeTypeName("const D3D12_GPU_DESCRIPTOR_HANDLE &")] in D3D12_GPU_DESCRIPTOR_HANDLE other, [NativeTypeName("INT")] int offsetScaledByIncrementSize)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@
// Ported from d3dx12.h in DirectX-Graphics-Samples commit a7a87f1853b5540f10920518021d91ae641033fb
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using static TerraFX.Interop.D3D12_CULL_MODE;
using static TerraFX.Interop.D3D12_FILL_MODE;
using static TerraFX.Interop.D3D12_CONSERVATIVE_RASTERIZATION_MODE;
using static TerraFX.Interop.Windows;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace TerraFX.Interop
{
public partial struct D3D12_RASTERIZER_DESC
{
public static readonly D3D12_RASTERIZER_DESC DEFAULT = new D3D12_RASTERIZER_DESC {
FillMode = D3D12_FILL_MODE_SOLID,
CullMode = D3D12_CULL_MODE_BACK,
FrontCounterClockwise = FALSE,
DepthBias = D3D12_DEFAULT_DEPTH_BIAS,
DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP,
SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS,
DepthClipEnable = TRUE,
MultisampleEnable = FALSE,
AntialiasedLineEnable = FALSE,
ForcedSampleCount = 0,
ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF,
};
public static ref readonly D3D12_RASTERIZER_DESC DEFAULT
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data = new byte[] {
0x03, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};

Debug.Assert(data.Length == Unsafe.SizeOf<D3D12_RASTERIZER_DESC>());
return ref Unsafe.As<byte, D3D12_RASTERIZER_DESC>(ref MemoryMarshal.GetReference(data));
}
}

public D3D12_RASTERIZER_DESC(D3D12_FILL_MODE fillMode, D3D12_CULL_MODE cullMode, [NativeTypeName("BOOL")] int frontCounterClockwise, [NativeTypeName("INT")] int depthBias, [NativeTypeName("FLOAT")] float depthBiasClamp, [NativeTypeName("FLOAT")] float slopeScaledDepthBias, [NativeTypeName("BOOL")] int depthClipEnable, [NativeTypeName("BOOL")] int multisampleEnable, [NativeTypeName("BOOL")] int antialiasedLineEnable, [NativeTypeName("UINT")] uint forcedSampleCount, D3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster)
{
Expand Down
Loading