Skip to content

Commit

Permalink
Merge pull request #400 from tannergooding/main
Browse files Browse the repository at this point in the history
Fix the alignment of the CD3DX12_PIPELINE_STATE_STREAM_* structs and add support for .NET 9
  • Loading branch information
tannergooding authored Nov 12, 2024
2 parents e263f55 + 2f78f13 commit 0a2996e
Show file tree
Hide file tree
Showing 42 changed files with 624 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<PackageOutputPath>$(BaseArtifactsPath)pkg/$(Configuration)/</PackageOutputPath>
<Product>TerraFX.Interop.Windows</Product>
<RootNamespace>TerraFX.Interop</RootNamespace>
<VersionPrefix>10.0.26100.0</VersionPrefix>
<VersionPrefix>10.0.26100.1</VersionPrefix>
<VersionSuffix Condition="'$(EXCLUDE_SUFFIX_FROM_VERSION)' != 'true'">rc1</VersionSuffix>
<VersionSuffix Condition="'$(GITHUB_EVENT_NAME)' == 'pull_request'">pr</VersionSuffix>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100-preview",
"version": "9.0.100",
"allowPrerelease": true,
"rollForward": "latestFeature"
}
Expand Down
16 changes: 12 additions & 4 deletions samples/DirectX/D3D12/HelloConstBuffer12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using static TerraFX.Interop.DirectX.D3D12_HEAP_FLAGS;
using static TerraFX.Interop.DirectX.D3D12_HEAP_TYPE;
using static TerraFX.Interop.DirectX.D3D12_INPUT_CLASSIFICATION;
using static TerraFX.Interop.DirectX.D3D12_PIPELINE_STATE_SUBOBJECT_TYPE;
using static TerraFX.Interop.DirectX.D3D12_PRIMITIVE_TOPOLOGY_TYPE;
using static TerraFX.Interop.DirectX.D3D12_RESOURCE_STATES;
using static TerraFX.Interop.DirectX.D3D12_ROOT_SIGNATURE_FLAGS;
Expand Down Expand Up @@ -158,7 +159,7 @@ protected override void CreateDescriptorHeaps()
};

// Describe and create the graphics pipeline state object (PSO).
var psoDesc = new D3D12_GRAPHICS_PIPELINE_STATE_DESC {
var gpsoDesc = new D3D12_GRAPHICS_PIPELINE_STATE_DESC {
InputLayout = new D3D12_INPUT_LAYOUT_DESC {
pInputElementDescs = inputElementDescs,
NumElements = InputElementDescsCount,
Expand All @@ -174,11 +175,18 @@ protected override void CreateDescriptorHeaps()
NumRenderTargets = 1,
SampleDesc = new DXGI_SAMPLE_DESC(count: 1, quality: 0),
};
psoDesc.DepthStencilState.DepthEnable = FALSE;
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
gpsoDesc.DepthStencilState.DepthEnable = FALSE;
gpsoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;

var pssDesc = new CD3DX12_PIPELINE_STATE_STREAM(gpsoDesc);

var psoDesc = new D3D12_PIPELINE_STATE_STREAM_DESC {
SizeInBytes = (uint)sizeof(CD3DX12_PIPELINE_STATE_STREAM),
pPipelineStateSubobjectStream = &pssDesc
};

ID3D12PipelineState* pipelineState;
ThrowIfFailed(D3DDevice->CreateGraphicsPipelineState(&psoDesc, __uuidof<ID3D12PipelineState>(), (void**)&pipelineState));
ThrowIfFailed(D3DDevice->CreatePipelineState(&psoDesc, __uuidof<ID3D12PipelineState>(), (void**)&pipelineState));

return pipelineState;
}
Expand Down
10 changes: 5 additions & 5 deletions samples/DirectX/D3D12/Shared/DX12Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract unsafe class DX12Sample : DXSample
{
private readonly ID3D12CommandAllocator*[] _commandAllocators;

private ID3D12Device* _d3dDevice;
private ID3D12Device2* _d3dDevice;
private IDXGIAdapter1* _dxgiAdapter;
private IDXGIFactory4* _dxgiFactory;
private IDXGISwapChain3* _swapChain;
Expand Down Expand Up @@ -62,7 +62,7 @@ protected DX12Sample(string name) : base(name)

public ID3D12CommandQueue* CommandQueue => _commandQueue;

public ID3D12Device* D3DDevice => _d3dDevice;
public ID3D12Device2* D3DDevice => _d3dDevice;

public ID3D12Resource* DepthStencil => _depthStencil;

Expand Down Expand Up @@ -243,10 +243,10 @@ protected override void CreateDeviceDependentResources()
return commandQueue;
}

ID3D12Device* CreateD3DDevice()
ID3D12Device2* CreateD3DDevice()
{
ID3D12Device* d3dDevice;
ThrowIfFailed(D3D12CreateDevice((IUnknown*)_dxgiAdapter, D3D_FEATURE_LEVEL_11_0, __uuidof<ID3D12Device>(), (void**)&d3dDevice));
ID3D12Device2* d3dDevice;
ThrowIfFailed(D3D12CreateDevice((IUnknown*)_dxgiAdapter, D3D_FEATURE_LEVEL_11_0, __uuidof<ID3D12Device2>(), (void**)&d3dDevice));
return d3dDevice;
}

Expand Down
16 changes: 8 additions & 8 deletions samples/DirectX/Shared/DXSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ private static TimeSpan GetCurrentTimestamp()
private static DXSample[] GetSamples()
{
var samples = new List<DXSample>(8) {
new HelloWindow11("D3D11.HelloWindow")
};
// new HelloWindow11("D3D11.HelloWindow")
};

if (OperatingSystem.IsWindowsVersionAtLeast(10))
{
samples.Add(new HelloTriangle11("D3D11.HelloTriangle"));
samples.Add(new HelloWindow12("D3D12.HelloWindow"));
samples.Add(new HelloTriangle12("D3D12.HelloTriangle"));
// samples.Add(new HelloTriangle11("D3D11.HelloTriangle"));
// samples.Add(new HelloWindow12("D3D12.HelloWindow"));
// samples.Add(new HelloTriangle12("D3D12.HelloTriangle"));
samples.Add(new HelloConstBuffer12("D3D12.HelloConstBuffer"));
samples.Add(new HelloTexture12("D3D12.HelloTexture"));
samples.Add(new HelloBundles12("D3D12.HelloBundles"));
samples.Add(new HelloMultiSampling12("D3D12.HelloMultiSampling"));
// samples.Add(new HelloTexture12("D3D12.HelloTexture"));
// samples.Add(new HelloBundles12("D3D12.HelloBundles"));
// samples.Add(new HelloMultiSampling12("D3D12.HelloMultiSampling"));
}

return samples.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion samples/DirectX/TerraFX.Samples.DirectX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 3 additions & 0 deletions samples/WinForms/DXPanel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.ComponentModel;
using System.Numerics;
using System.Windows.Forms;
using TerraFX.Interop.Windows;
Expand All @@ -19,6 +20,7 @@ public DXPanel()
InitializeComponent();
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DXSample? DXSample
{
get
Expand Down Expand Up @@ -46,6 +48,7 @@ public DXSample? DXSample
}
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public bool UseWarpDevice
{
get
Expand Down
2 changes: 1 addition & 1 deletion samples/WinForms/TerraFX.Samples.WinForms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<TargetFrameworks>net8.0-windows;net9.0-windows</TargetFrameworks>
<OutputType>WinExe</OutputType>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ try {
Create-Directory -Path $DotNetInstallDirectory

& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
& $DotNetInstallScript -Channel 9.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture

$env:PATH="$DotNetInstallDirectory;$env:PATH"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public HRESULT Init(ID3D12Device* pDevice)

// Special procedure to initialize local protected resource session types structs
// Must wait until session type count initialized
QueryProtectedResourceSessionTypes(NodeIndex, m_dProtectedResourceSessionTypeCount[NodeIndex].Count);
_ = QueryProtectedResourceSessionTypes(NodeIndex, m_dProtectedResourceSessionTypeCount[NodeIndex].Count);
}

// Initialize features that requires highest version check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public unsafe struct CD3DX12_PIPELINE_MESH_STATE_STREAM

public CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING ViewInstancingDesc;


public CD3DX12_PIPELINE_MESH_STATE_STREAM([NativeTypeName("const D3DX12_MESH_SHADER_PIPELINE_STATE_DESC &")] in D3DX12_MESH_SHADER_PIPELINE_STATE_DESC Desc)
{
Flags = Desc.Flags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
// Ported from d3dx12_pipeline_state_stream.h in microsoft/DirectX-Headers tag v1.614.0
// Original source is Copyright © Microsoft. Licensed under the MIT license

using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using static TerraFX.Interop.DirectX.D3D12_PIPELINE_STATE_SUBOBJECT_TYPE;

namespace TerraFX.Interop.DirectX;

[StructLayout(LayoutKind.Explicit)]
public struct CD3DX12_PIPELINE_STATE_STREAM_AS
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;
[FieldOffset(0)]
private readonly unsafe void* _Anonymous_e__Alignment;

public D3D12_SHADER_BYTECODE pssInner;
[FieldOffset(0)]
public _Anonymous_e__Struct Anonymous;

[UnscopedRef]
public ref D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType => ref Anonymous.pssType;

[UnscopedRef]
public ref D3D12_SHADER_BYTECODE pssInner => ref Anonymous.pssInner;

public CD3DX12_PIPELINE_STATE_STREAM_AS()
{
Expand All @@ -28,4 +39,11 @@ public CD3DX12_PIPELINE_STATE_STREAM_AS([NativeTypeName("D3D12_SHADER_BYTECODE c
public static implicit operator CD3DX12_PIPELINE_STATE_STREAM_AS(in D3D12_SHADER_BYTECODE value) => new CD3DX12_PIPELINE_STATE_STREAM_AS(value);

public static implicit operator D3D12_SHADER_BYTECODE(in CD3DX12_PIPELINE_STATE_STREAM_AS value) => value.pssInner;

public struct _Anonymous_e__Struct
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;

public D3D12_SHADER_BYTECODE pssInner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
// Ported from d3dx12_pipeline_state_stream.h in microsoft/DirectX-Headers tag v1.614.0
// Original source is Copyright © Microsoft. Licensed under the MIT license

using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using static TerraFX.Interop.DirectX.D3D12_PIPELINE_STATE_SUBOBJECT_TYPE;

namespace TerraFX.Interop.DirectX;

[StructLayout(LayoutKind.Explicit)]
public struct CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;
[FieldOffset(0)]
private readonly unsafe void* _Anonymous_e__Alignment;

public D3D12_BLEND_DESC pssInner;
[FieldOffset(0)]
public _Anonymous_e__Struct Anonymous;

[UnscopedRef]
public ref D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType => ref Anonymous.pssType;

[UnscopedRef]
public ref D3D12_BLEND_DESC pssInner => ref Anonymous.pssInner;

public CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC()
{
Expand All @@ -28,4 +39,11 @@ public CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC([NativeTypeName("D3D12_BLEND_DES
public static implicit operator CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC(in D3D12_BLEND_DESC value) => new CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC(value);

public static implicit operator D3D12_BLEND_DESC(in CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC value) => value.pssInner;

public struct _Anonymous_e__Struct
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;

public D3D12_BLEND_DESC pssInner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
// Ported from d3dx12_pipeline_state_stream.h in microsoft/DirectX-Headers tag v1.614.0
// Original source is Copyright © Microsoft. Licensed under the MIT license

using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using static TerraFX.Interop.DirectX.D3D12_PIPELINE_STATE_SUBOBJECT_TYPE;

namespace TerraFX.Interop.DirectX;

[StructLayout(LayoutKind.Explicit)]
public struct CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;
[FieldOffset(0)]
private readonly unsafe void* _Anonymous_e__Alignment;

public D3D12_CACHED_PIPELINE_STATE pssInner;
[FieldOffset(0)]
public _Anonymous_e__Struct Anonymous;

[UnscopedRef]
public ref D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType => ref Anonymous.pssType;

[UnscopedRef]
public ref D3D12_CACHED_PIPELINE_STATE pssInner => ref Anonymous.pssInner;

public CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO()
{
Expand All @@ -28,4 +39,11 @@ public CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO([NativeTypeName("D3D12_CACHED_PI
public static implicit operator CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO(in D3D12_CACHED_PIPELINE_STATE value) => new CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO(value);

public static implicit operator D3D12_CACHED_PIPELINE_STATE(in CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO value) => value.pssInner;

public struct _Anonymous_e__Struct
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;

public D3D12_CACHED_PIPELINE_STATE pssInner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
// Ported from d3dx12_pipeline_state_stream.h in microsoft/DirectX-Headers tag v1.614.0
// Original source is Copyright © Microsoft. Licensed under the MIT license

using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using static TerraFX.Interop.DirectX.D3D12_PIPELINE_STATE_SUBOBJECT_TYPE;

namespace TerraFX.Interop.DirectX;

[StructLayout(LayoutKind.Explicit)]
public struct CD3DX12_PIPELINE_STATE_STREAM_CS
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;
[FieldOffset(0)]
private readonly unsafe void* _Anonymous_e__Alignment;

public D3D12_SHADER_BYTECODE pssInner;
[FieldOffset(0)]
public _Anonymous_e__Struct Anonymous;

[UnscopedRef]
public ref D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType => ref Anonymous.pssType;

[UnscopedRef]
public ref D3D12_SHADER_BYTECODE pssInner => ref Anonymous.pssInner;

public CD3DX12_PIPELINE_STATE_STREAM_CS()
{
Expand All @@ -28,4 +39,11 @@ public CD3DX12_PIPELINE_STATE_STREAM_CS([NativeTypeName("D3D12_SHADER_BYTECODE c
public static implicit operator CD3DX12_PIPELINE_STATE_STREAM_CS(in D3D12_SHADER_BYTECODE value) => new CD3DX12_PIPELINE_STATE_STREAM_CS(value);

public static implicit operator D3D12_SHADER_BYTECODE(in CD3DX12_PIPELINE_STATE_STREAM_CS value) => value.pssInner;

public struct _Anonymous_e__Struct
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;

public D3D12_SHADER_BYTECODE pssInner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
// Ported from d3dx12_pipeline_state_stream.h in microsoft/DirectX-Headers tag v1.614.0
// Original source is Copyright © Microsoft. Licensed under the MIT license

using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using static TerraFX.Interop.DirectX.D3D12_PIPELINE_STATE_SUBOBJECT_TYPE;

namespace TerraFX.Interop.DirectX;

[StructLayout(LayoutKind.Explicit)]
public struct CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;
[FieldOffset(0)]
private readonly unsafe void* _Anonymous_e__Alignment;

public D3D12_DEPTH_STENCIL_DESC pssInner;
[FieldOffset(0)]
public _Anonymous_e__Struct Anonymous;

[UnscopedRef]
public ref D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType => ref Anonymous.pssType;

[UnscopedRef]
public ref D3D12_DEPTH_STENCIL_DESC pssInner => ref Anonymous.pssInner;

public CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL()
{
Expand All @@ -28,4 +39,11 @@ public CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL([NativeTypeName("D3D12_DEPTH_
public static implicit operator CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL(in D3D12_DEPTH_STENCIL_DESC value) => new CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL(value);

public static implicit operator D3D12_DEPTH_STENCIL_DESC(in CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL value) => value.pssInner;

public struct _Anonymous_e__Struct
{
public D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;

public D3D12_DEPTH_STENCIL_DESC pssInner;
}
}
Loading

0 comments on commit 0a2996e

Please sign in to comment.