diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 16a104e..0c5272e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup .NET 8 SDK + - name: Setup .NET SDK uses: actions/setup-dotnet@v4 with: global-json-file: ./global.json diff --git a/Directory.Build.props b/Directory.Build.props index 0b1bf0a..49bd7cc 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -11,13 +11,13 @@ - 2.2.6 + 2.2.7 true - latest + 13.0 enable enable true diff --git a/Directory.Packages.props b/Directory.Packages.props index 5db0057..c7f9edf 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,12 +7,12 @@ - - - + + + - + diff --git a/README.md b/README.md index c0efc26..68bdca8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build status](https://github.com/amerkoleci/Vortice.Win32/workflows/Build/badge.svg)](https://github.com/amerkoleci/Vortice.Win32/actions) [![NuGet](https://img.shields.io/nuget/v/Vortice.Win32.svg)](https://www.nuget.org/packages/Vortice.Win32) -**Vortice.Win32** is **.net8.0** low-level bindings for Win32, generation is based on json files from [win32json](https://github.com/marlersoft/win32json), follows naming conventions of Vortice.Windows but small GC allocation and using unsafe struct for COM objects. +**Vortice.Win32** is **.net8.0** and **.net9.0** low-level bindings for Win32, generation is based on json files from [win32json](https://github.com/marlersoft/win32json), follows naming conventions of Vortice.Windows but small GC allocation and using unsafe struct for COM objects. ## Sponsors To further help development of these bindings library or other projects, please consider [SPONSOR](https://github.com/sponsors/amerkoleci) my profile in order to allow faster issue triaging and new features to be implemented. diff --git a/Vortice.Win32.sln b/Vortice.Win32.sln index 52c53c7..90a180d 100644 --- a/Vortice.Win32.sln +++ b/Vortice.Win32.sln @@ -11,7 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{08F6 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01-ClearScreen", "samples\01-ClearScreen\01-ClearScreen.csproj", "{5A10816D-90A4-4AEA-B06E-6A463DA4A891}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{065268A8-16E6-4CFF-8F67-3FD99155877F}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".root", ".root", "{065268A8-16E6-4CFF-8F67-3FD99155877F}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitignore = .gitignore @@ -50,6 +50,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vortice.Dxc.Native", "src\V EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vortice.Pix.Native", "src\Vortice.Pix.Native\Vortice.Pix.Native.csproj", "{E75BA02B-0788-4065-8534-BC3FCF06CC9D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Native", "Native", "{2B88F597-01D2-4843-BE1E-858855688A4A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vortice.D3D12MA.Native", "src\Vortice.D3D12MA.Native\Vortice.D3D12MA.Native.csproj", "{28E78497-FD58-4C79-A3A2-9FA9509B55F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vortice.Win32.Graphics.D3D12MemoryAllocator", "src\Vortice.Win32.Graphics.D3D12MemoryAllocator\Vortice.Win32.Graphics.D3D12MemoryAllocator.csproj", "{AC2594D8-0538-4E3B-AC7E-3F40CC07623C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -120,12 +126,23 @@ Global {E75BA02B-0788-4065-8534-BC3FCF06CC9D}.Debug|Any CPU.Build.0 = Debug|Any CPU {E75BA02B-0788-4065-8534-BC3FCF06CC9D}.Release|Any CPU.ActiveCfg = Release|Any CPU {E75BA02B-0788-4065-8534-BC3FCF06CC9D}.Release|Any CPU.Build.0 = Release|Any CPU + {28E78497-FD58-4C79-A3A2-9FA9509B55F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28E78497-FD58-4C79-A3A2-9FA9509B55F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28E78497-FD58-4C79-A3A2-9FA9509B55F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28E78497-FD58-4C79-A3A2-9FA9509B55F2}.Release|Any CPU.Build.0 = Release|Any CPU + {AC2594D8-0538-4E3B-AC7E-3F40CC07623C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC2594D8-0538-4E3B-AC7E-3F40CC07623C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC2594D8-0538-4E3B-AC7E-3F40CC07623C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC2594D8-0538-4E3B-AC7E-3F40CC07623C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {5A10816D-90A4-4AEA-B06E-6A463DA4A891} = {08F6AF96-809B-45C5-BE6C-5BAB7D9AFB60} + {3C579D3B-8239-4707-B906-253181EF52B4} = {2B88F597-01D2-4843-BE1E-858855688A4A} + {E75BA02B-0788-4065-8534-BC3FCF06CC9D} = {2B88F597-01D2-4843-BE1E-858855688A4A} + {28E78497-FD58-4C79-A3A2-9FA9509B55F2} = {2B88F597-01D2-4843-BE1E-858855688A4A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DF0375B3-E304-4A53-8E5F-FC9D23743647} diff --git a/global.json b/global.json index fee645a..60af8e2 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.100", + "version": "9.0.100", "rollForward": "latestFeature", "allowPrerelease": false } diff --git a/samples/01-ClearScreen/01-ClearScreen.csproj b/samples/01-ClearScreen/01-ClearScreen.csproj index 21d51da..c998bc2 100644 --- a/samples/01-ClearScreen/01-ClearScreen.csproj +++ b/samples/01-ClearScreen/01-ClearScreen.csproj @@ -1,7 +1,7 @@ Exe - net8.0 + net9.0 true false ClearScreen @@ -9,6 +9,7 @@ + @@ -24,12 +25,14 @@ + + diff --git a/samples/01-ClearScreen/Program.cs b/samples/01-ClearScreen/Program.cs index 3efcdec..852862c 100644 --- a/samples/01-ClearScreen/Program.cs +++ b/samples/01-ClearScreen/Program.cs @@ -16,17 +16,22 @@ using Win32.Media.Audio.XAudio2; using static Win32.Apis; using static Win32.Graphics.Direct2D.Apis; using static Win32.Graphics.Direct3D.Dxc.Apis; +using static Win32.Graphics.Direct3D12.Apis; using static Win32.Graphics.Direct3D11.Apis; using static Win32.Graphics.DirectWrite.Apis; using static Win32.Graphics.Dxgi.Apis; using static Win32.Graphics.Imaging.D2D.Apis; using static Win32.Media.Audio.XAudio2.Apis; +using static Win32.Graphics.D3D12MemoryAllocator.Apis; using DWriteFactoryType = Win32.Graphics.DirectWrite.FactoryType; using FactoryType = Win32.Graphics.Direct2D.FactoryType; using FeatureLevel = Win32.Graphics.Direct3D.FeatureLevel; using InfoQueueFilter = Win32.Graphics.Direct3D11.InfoQueueFilter; using MessageId = Win32.Graphics.Direct3D11.MessageId; +using D3D11MessageSeverity = Win32.Graphics.Direct3D11.MessageSeverity; +using Win32.Graphics.Direct3D12; +using Win32.Graphics.D3D12MemoryAllocator; namespace ClearScreen; @@ -147,6 +152,7 @@ public static unsafe class Program } using ComPtr adapter = default; + bool supportD3D12 = false; using ComPtr factory6 = default; if (factory.CopyTo(&factory6).Success) @@ -165,6 +171,13 @@ public static unsafe class Program if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None) continue; + // Check to see if the adapter supports Direct3D 12, but don't create the actual device yet. + if (D3D12CreateDevice((IUnknown*)adapter.Get(), FeatureLevel.Level_11_0, __uuidof(), null).Success) + { + supportD3D12 = true; + break; + } + break; //string name = desc.DescriptionStr; } @@ -182,85 +195,129 @@ public static unsafe class Program if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None) continue; + // Check to see if the adapter supports Direct3D 12, but don't create the actual device yet. + if (D3D12CreateDevice((IUnknown*)adapter.Get(), FeatureLevel.Level_11_0, __uuidof(), null).Success) + { + supportD3D12 = true; + break; + } + //string name = desc.DescriptionStr; break; } } - ReadOnlySpan featureLevels = stackalloc FeatureLevel[1] + if (supportD3D12) { - FeatureLevel.Level_11_0 - }; + using ComPtr device = default; - CreateDeviceFlags creationFlags = CreateDeviceFlags.BgraSupport; -#if DEBUG - if (SdkLayersAvailable()) - { - // If the project is in a debug build, enable debugging via SDK Layers with this flag. - creationFlags |= CreateDeviceFlags.Debug; + // Create the DX12 API device object. + hr = D3D12CreateDevice( + (IUnknown*)adapter.Get(), + FeatureLevel.Level_11_0, + __uuidof(), + device.GetVoidAddressOf() + ); + ThrowIfFailed(hr); + + AllocatorDesc allocatorDesc = new() + { + pDevice = device.Get(), + pAdapter = (IDXGIAdapter*)adapter.Get() + }; + hr = CreateAllocator(in allocatorDesc, out Allocator allocator); + + AllocationDesc allocationDesc = new(); + allocationDesc.HeapType = HeapType.Default; + + using ComPtr buffer = default; + ResourceDescription bufferDesc = ResourceDescription.Buffer(256u); + + Allocation allocation = default; + hr = allocator.CreateResource(&allocationDesc, in bufferDesc, ResourceStates.Common, + null, &allocation, buffer.GetAddressOf()); + //var test = allocator.IsUMA; + ThrowIfFailed(hr); + uint cnt = allocation.Release(); } + else + { + + ReadOnlySpan featureLevels = + [ + FeatureLevel.Level_11_0 + ]; + + CreateDeviceFlags creationFlags = CreateDeviceFlags.BgraSupport; +#if DEBUG + if (SdkLayersAvailable()) + { + // If the project is in a debug build, enable debugging via SDK Layers with this flag. + creationFlags |= CreateDeviceFlags.Debug; + } #endif - using ComPtr tempDevice = default; - FeatureLevel featureLevel; - using ComPtr tempImmediateContext = default; + using ComPtr tempDevice = default; + FeatureLevel featureLevel; + using ComPtr tempImmediateContext = default; - ThrowIfFailed(D3D11CreateDevice( - (IDXGIAdapter*)adapter.Get(), - DriverType.Unknown, - creationFlags, - featureLevels, - tempDevice.GetAddressOf(), - &featureLevel, - tempImmediateContext.GetAddressOf())); + ThrowIfFailed(D3D11CreateDevice( + (IDXGIAdapter*)adapter.Get(), + DriverType.Unknown, + creationFlags, + featureLevels, + tempDevice.GetAddressOf(), + &featureLevel, + tempImmediateContext.GetAddressOf())); #if DEBUG - using ComPtr d3dDebug = default; - if (tempDevice.CopyTo(&d3dDebug).Success) - { - using ComPtr d3dInfoQueue = default; - if (d3dDebug.CopyTo(&d3dInfoQueue).Success) + using ComPtr d3dDebug = default; + if (tempDevice.CopyTo(&d3dDebug).Success) { - d3dInfoQueue.Get()->SetBreakOnSeverity(MessageSeverity.Corruption, true); - d3dInfoQueue.Get()->SetBreakOnSeverity(MessageSeverity.Error, true); - - MessageId* hide = stackalloc MessageId[1] + using ComPtr d3dInfoQueue = default; + if (d3dDebug.CopyTo(&d3dInfoQueue).Success) { + d3dInfoQueue.Get()->SetBreakOnSeverity(D3D11MessageSeverity.Corruption, true); + d3dInfoQueue.Get()->SetBreakOnSeverity(D3D11MessageSeverity.Error, true); + + MessageId* hide = stackalloc MessageId[1] + { MessageId.SetPrivateDataChangingParams, }; - InfoQueueFilter filter = new(); - filter.DenyList.NumIDs = 1u; - filter.DenyList.pIDList = hide; - d3dInfoQueue.Get()->AddStorageFilterEntries(&filter); + InfoQueueFilter filter = new(); + filter.DenyList.NumIDs = 1u; + filter.DenyList.pIDList = hide; + d3dInfoQueue.Get()->AddStorageFilterEntries(&filter); + } } - } #endif - using ComPtr d3dDevice = default; - using ComPtr immediateContext = default; + using ComPtr d3dDevice = default; + using ComPtr immediateContext = default; - ThrowIfFailed(tempDevice.CopyTo(&d3dDevice)); - ThrowIfFailed(tempImmediateContext.CopyTo(&immediateContext)); + ThrowIfFailed(tempDevice.CopyTo(&d3dDevice)); + ThrowIfFailed(tempImmediateContext.CopyTo(&immediateContext)); - ReadOnlySpan triangleVertices = stackalloc VertexPositionColor[] - { + ReadOnlySpan triangleVertices = stackalloc VertexPositionColor[] + { new VertexPositionColor(new Vector3(0f, 0.5f, 0.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f)), new VertexPositionColor(new Vector3(0.5f, -0.5f, 0.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f)), new VertexPositionColor(new Vector3(-0.5f, -0.5f, 0.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)) }; - using ComPtr vertexBuffer = ((ID3D11Device*)d3dDevice.Get())->CreateBuffer(triangleVertices, BindFlags.VertexBuffer); + using ComPtr vertexBuffer = ((ID3D11Device*)d3dDevice.Get())->CreateBuffer(triangleVertices, BindFlags.VertexBuffer); - using ComPtr depthStencilTexture = default; - using ComPtr depthStencilTextureView = default; + using ComPtr depthStencilTexture = default; + using ComPtr depthStencilTextureView = default; - Texture2DDescription texture2DDesc = new(Format.D32Float, 256, 256, 1, 1, BindFlags.DepthStencil); - ThrowIfFailed(tempDevice.Get()->CreateTexture2D(&texture2DDesc, null, depthStencilTexture.GetAddressOf())); - depthStencilTexture.Get()->GetDesc(&texture2DDesc); - depthStencilTexture.Get()->SetDebugName("CIAO"); + Texture2DDescription texture2DDesc = new(Format.D32Float, 256, 256, 1, 1, BindFlags.DepthStencil); + ThrowIfFailed(tempDevice.Get()->CreateTexture2D(&texture2DDesc, null, depthStencilTexture.GetAddressOf())); + depthStencilTexture.Get()->GetDesc(&texture2DDesc); + depthStencilTexture.Get()->SetDebugName("CIAO"); - ThrowIfFailed(tempDevice.Get()->CreateDepthStencilView( - (ID3D11Resource*)depthStencilTexture.Get(), null, depthStencilTextureView.GetAddressOf())); + ThrowIfFailed(tempDevice.Get()->CreateDepthStencilView( + (ID3D11Resource*)depthStencilTexture.Get(), null, depthStencilTextureView.GetAddressOf())); + } } } diff --git a/src/Generator/DocGenerator.cs b/src/Generator/DocGenerator.cs index 9738291..02303f3 100644 --- a/src/Generator/DocGenerator.cs +++ b/src/Generator/DocGenerator.cs @@ -21,8 +21,8 @@ public static class DocGenerator public static void Generate(string repoRoot, string[] prefixes, string outputPath) { using FileStream docsStream = File.OpenRead(Path.Combine(repoRoot, "docs", "apidocs.msgpack")); - var data = MessagePackSerializer.Deserialize>(docsStream); - var documentationData = new Dictionary(); + Dictionary data = MessagePackSerializer.Deserialize>(docsStream); + Dictionary documentationData = new(); foreach (string key in data.Keys) { @@ -70,7 +70,7 @@ public static class DocGenerator if (!string.IsNullOrEmpty(doc.Description) || doc.Parameters.Count > 0) { string memberName = item.Replace(".", "::"); - + writer.WriteStartElement(null, "member", null); writer.WriteAttributeString("name", memberName); { @@ -174,7 +174,7 @@ public static class DocGenerator string memberName = $"{item.Replace(".", "::")}::{fieldName}"; writer.WriteStartElement(null, "member", null); - + writer.WriteAttributeString("name", memberName); { diff --git a/src/Generator/Generator.csproj b/src/Generator/Generator.csproj index 56e6ec3..141794b 100644 --- a/src/Generator/Generator.csproj +++ b/src/Generator/Generator.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 Exe true false diff --git a/src/Generator/win32json/api/Graphics.CompositionSwapchain.json b/src/Generator/win32json/api/Graphics.CompositionSwapchain.json index edfe78e..254b279 100644 --- a/src/Generator/win32json/api/Graphics.CompositionSwapchain.json +++ b/src/Generator/win32json/api/Graphics.CompositionSwapchain.json @@ -351,7 +351,7 @@ ,"Attrs":[] ,"Params":[ {"Name":"riid","Type":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Guid"}},"Attrs":["In","Const"]} - ,{"Name":"fence","Type":{"Kind":"PointerTo","Child":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Void"}}},"Attrs":["Out","RetVal"]} + ,{"Name":"fence","Type":{"Kind":"PointerTo","Child":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Void"}}},"Attrs":["Out","RetVal","ComOutPtr"]} ] } ,{ @@ -667,7 +667,7 @@ ,"Params":[ {"Name":"d3dDevice","Type":{"Kind":"ApiRef","Name":"IUnknown","TargetKind":"Com","Api":"System.Com","Parents":[]},"Attrs":["In"]} ,{"Name":"riid","Type":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Guid"}},"Attrs":["In","Const"]} - ,{"Name":"presentationFactory","Type":{"Kind":"PointerTo","Child":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Void"}}},"Attrs":["Out"]} + ,{"Name":"presentationFactory","Type":{"Kind":"PointerTo","Child":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Void"}}},"Attrs":["Out","ComOutPtr"]} ] } ] diff --git a/src/Generator/win32json/api/Graphics.Direct3D12.json b/src/Generator/win32json/api/Graphics.Direct3D12.json index 2d16d64..f7c1fa5 100644 --- a/src/Generator/win32json/api/Graphics.Direct3D12.json +++ b/src/Generator/win32json/api/Graphics.Direct3D12.json @@ -9103,7 +9103,7 @@ ,{"Name":"Depth","Type":{"Kind":"Native","Name":"Single"},"Attrs":["In"]} ,{"Name":"Stencil","Type":{"Kind":"Native","Name":"Byte"},"Attrs":["In"]} ,{"Name":"NumRects","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"pRects","Type":{"Kind":"LPArray","NullNullTerm":false,"CountConst":-1,"CountParamIndex":4,"Child":{"Kind":"ApiRef","Name":"RECT","TargetKind":"Default","Api":"Foundation","Parents":[]}},"Attrs":["In","Const"]} + ,{"Name":"pRects","Type":{"Kind":"LPArray","NullNullTerm":false,"CountConst":-1,"CountParamIndex":4,"Child":{"Kind":"ApiRef","Name":"RECT","TargetKind":"Default","Api":"Foundation","Parents":[]}},"Attrs":["In","Optional","Const"]} ] } ,{ diff --git a/src/Generator/win32json/api/Graphics.DirectComposition.json b/src/Generator/win32json/api/Graphics.DirectComposition.json index f265d03..89440e9 100644 --- a/src/Generator/win32json/api/Graphics.DirectComposition.json +++ b/src/Generator/win32json/api/Graphics.DirectComposition.json @@ -349,7 +349,7 @@ ,"Platform":null ,"Attrs":[] ,"Params":[ - {"Name":"statistics","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"DCOMPOSITION_FRAME_STATISTICS","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out"]} + {"Name":"statistics","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"DCOMPOSITION_FRAME_STATISTICS","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out","RetVal"]} ] } ,{ @@ -2257,7 +2257,7 @@ ,"Platform":null ,"Attrs":[] ,"Params":[ - {"Name":"statistics","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"DCOMPOSITION_FRAME_STATISTICS","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out"]} + {"Name":"statistics","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"DCOMPOSITION_FRAME_STATISTICS","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out","RetVal"]} ] } ,{ @@ -4484,7 +4484,7 @@ ,"Params":[ {"Name":"fenceValue","Type":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"UInt64"}},"Attrs":["Out"]} ,{"Name":"iid","Type":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Guid"}},"Attrs":["In","Const"]} - ,{"Name":"availableFence","Type":{"Kind":"PointerTo","Child":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Void"}}},"Attrs":["Out"]} + ,{"Name":"availableFence","Type":{"Kind":"PointerTo","Child":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"Void"}}},"Attrs":["Out","ComOutPtr"]} ] } ] @@ -4645,7 +4645,7 @@ {"Name":"frameId","Type":{"Kind":"Native","Name":"UInt64"},"Attrs":["In"]} ,{"Name":"frameStats","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"COMPOSITION_FRAME_STATS","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out"]} ,{"Name":"targetIdCount","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"targetIds","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"COMPOSITION_TARGET_ID","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out","Optional"]} + ,{"Name":"targetIds","Type":{"Kind":"LPArray","NullNullTerm":false,"CountConst":-1,"CountParamIndex":-1,"Child":{"Kind":"ApiRef","Name":"COMPOSITION_TARGET_ID","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out","Optional"]} ,{"Name":"actualTargetIdCount","Type":{"Kind":"PointerTo","Child":{"Kind":"Native","Name":"UInt32"}},"Attrs":["Out","Optional"]} ] } @@ -4661,7 +4661,7 @@ ,"Params":[ {"Name":"frameId","Type":{"Kind":"Native","Name":"UInt64"},"Attrs":["In"]} ,{"Name":"targetId","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"COMPOSITION_TARGET_ID","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["In","Const"]} - ,{"Name":"targetStats","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"COMPOSITION_TARGET_STATS","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out"]} + ,{"Name":"targetStats","Type":{"Kind":"PointerTo","Child":{"Kind":"ApiRef","Name":"COMPOSITION_TARGET_STATS","TargetKind":"Default","Api":"Graphics.DirectComposition","Parents":[]}},"Attrs":["Out","RetVal"]} ] } ,{ diff --git a/src/Generator/win32json/api/Graphics.Gdi.json b/src/Generator/win32json/api/Graphics.Gdi.json index 7ff0a1b..e2af146 100644 --- a/src/Generator/win32json/api/Graphics.Gdi.json +++ b/src/Generator/win32json/api/Graphics.Gdi.json @@ -3578,111 +3578,6 @@ ,"Value":256 ,"Attrs":[] } - ,{ - "Name":"DISPLAY_DEVICE_ATTACHED_TO_DESKTOP" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":1 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_MULTI_DRIVER" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":2 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_PRIMARY_DEVICE" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":4 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_MIRRORING_DRIVER" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":8 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_VGA_COMPATIBLE" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":16 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_REMOVABLE" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":32 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_ACC_DRIVER" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":64 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_MODESPRUNED" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":134217728 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_RDPUDD" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":16777216 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_REMOTE" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":67108864 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_DISCONNECT" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":33554432 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_TS_COMPATIBLE" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":2097152 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_UNSAFE_MODES_ON" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":524288 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_ACTIVE" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":1 - ,"Attrs":[] - } - ,{ - "Name":"DISPLAY_DEVICE_ATTACHED" - ,"Type":{"Kind":"Native","Name":"UInt32"} - ,"ValueType":"UInt32" - ,"Value":2 - ,"Attrs":[] - } ,{ "Name":"DISPLAYCONFIG_MAXPATH" ,"Type":{"Kind":"Native","Name":"UInt32"} @@ -7585,6 +7480,32 @@ ] ,"IntegerBase":"UInt32" } + ,{ + "Name":"DISPLAY_DEVICE_STATE_FLAGS" + ,"Architectures":[] + ,"Platform":null + ,"Kind":"Enum" + ,"Flags":true + ,"Scoped":false + ,"Values":[ + {"Name":"DISPLAY_DEVICE_ATTACHED_TO_DESKTOP","Value":1} + ,{"Name":"DISPLAY_DEVICE_MULTI_DRIVER","Value":2} + ,{"Name":"DISPLAY_DEVICE_PRIMARY_DEVICE","Value":4} + ,{"Name":"DISPLAY_DEVICE_MIRRORING_DRIVER","Value":8} + ,{"Name":"DISPLAY_DEVICE_VGA_COMPATIBLE","Value":16} + ,{"Name":"DISPLAY_DEVICE_REMOVABLE","Value":32} + ,{"Name":"DISPLAY_DEVICE_ACC_DRIVER","Value":64} + ,{"Name":"DISPLAY_DEVICE_MODESPRUNED","Value":134217728} + ,{"Name":"DISPLAY_DEVICE_RDPUDD","Value":16777216} + ,{"Name":"DISPLAY_DEVICE_REMOTE","Value":67108864} + ,{"Name":"DISPLAY_DEVICE_DISCONNECT","Value":33554432} + ,{"Name":"DISPLAY_DEVICE_TS_COMPATIBLE","Value":2097152} + ,{"Name":"DISPLAY_DEVICE_UNSAFE_MODES_ON","Value":524288} + ,{"Name":"DISPLAY_DEVICE_ACTIVE","Value":1} + ,{"Name":"DISPLAY_DEVICE_ATTACHED","Value":2} + ] + ,"IntegerBase":"UInt32" + } ,{ "Name":"HBITMAP" ,"Architectures":[] @@ -8740,7 +8661,7 @@ {"Name":"cb","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":[]} ,{"Name":"DeviceName","Type":{"Kind":"Array","Shape":{"Size":32},"Child":{"Kind":"ApiRef","Name":"CHAR","TargetKind":"Default","Api":"Foundation","Parents":[]}},"Attrs":[]} ,{"Name":"DeviceString","Type":{"Kind":"Array","Shape":{"Size":128},"Child":{"Kind":"ApiRef","Name":"CHAR","TargetKind":"Default","Api":"Foundation","Parents":[]}},"Attrs":[]} - ,{"Name":"StateFlags","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":[]} + ,{"Name":"StateFlags","Type":{"Kind":"ApiRef","Name":"DISPLAY_DEVICE_STATE_FLAGS","TargetKind":"Default","Api":"Graphics.Gdi","Parents":[]},"Attrs":[]} ,{"Name":"DeviceID","Type":{"Kind":"Array","Shape":{"Size":128},"Child":{"Kind":"ApiRef","Name":"CHAR","TargetKind":"Default","Api":"Foundation","Parents":[]}},"Attrs":[]} ,{"Name":"DeviceKey","Type":{"Kind":"Array","Shape":{"Size":128},"Child":{"Kind":"ApiRef","Name":"CHAR","TargetKind":"Default","Api":"Foundation","Parents":[]}},"Attrs":[]} ] @@ -8759,7 +8680,7 @@ {"Name":"cb","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":[]} ,{"Name":"DeviceName","Type":{"Kind":"Array","Shape":{"Size":32},"Child":{"Kind":"Native","Name":"Char"}},"Attrs":[]} ,{"Name":"DeviceString","Type":{"Kind":"Array","Shape":{"Size":128},"Child":{"Kind":"Native","Name":"Char"}},"Attrs":[]} - ,{"Name":"StateFlags","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":[]} + ,{"Name":"StateFlags","Type":{"Kind":"ApiRef","Name":"DISPLAY_DEVICE_STATE_FLAGS","TargetKind":"Default","Api":"Graphics.Gdi","Parents":[]},"Attrs":[]} ,{"Name":"DeviceID","Type":{"Kind":"Array","Shape":{"Size":128},"Child":{"Kind":"Native","Name":"Char"}},"Attrs":[]} ,{"Name":"DeviceKey","Type":{"Kind":"Array","Shape":{"Size":128},"Child":{"Kind":"Native","Name":"Char"}},"Attrs":[]} ] @@ -11477,10 +11398,10 @@ ,{"Name":"bItalic","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} ,{"Name":"bUnderline","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} ,{"Name":"bStrikeOut","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iCharSet","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iOutPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iClipPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iQuality","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} + ,{"Name":"iCharSet","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_CHARSET"}]} + ,{"Name":"iOutPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_OUTPUT_PRECISION"}]} + ,{"Name":"iClipPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_CLIP_PRECISION"}]} + ,{"Name":"iQuality","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_QUALITY"}]} ,{"Name":"iPitchAndFamily","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} ,{"Name":"pszFaceName","Type":{"Kind":"ApiRef","Name":"PSTR","TargetKind":"Default","Api":"Foundation","Parents":[]},"Attrs":["In","Optional","Const"]} ] @@ -11503,10 +11424,10 @@ ,{"Name":"bItalic","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} ,{"Name":"bUnderline","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} ,{"Name":"bStrikeOut","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iCharSet","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iOutPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iClipPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} - ,{"Name":"iQuality","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} + ,{"Name":"iCharSet","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_CHARSET"}]} + ,{"Name":"iOutPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_OUTPUT_PRECISION"}]} + ,{"Name":"iClipPrecision","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_CLIP_PRECISION"}]} + ,{"Name":"iQuality","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In",{"Kind":"AssociatedEnum","Enum":"FONT_QUALITY"}]} ,{"Name":"iPitchAndFamily","Type":{"Kind":"Native","Name":"UInt32"},"Attrs":["In"]} ,{"Name":"pszFaceName","Type":{"Kind":"ApiRef","Name":"PWSTR","TargetKind":"Default","Api":"Foundation","Parents":[]},"Attrs":["In","Optional","Const"]} ] diff --git a/src/Vortice.D3D12MA.Native/LICENSE.txt b/src/Vortice.D3D12MA.Native/LICENSE.txt new file mode 100644 index 0000000..0761191 --- /dev/null +++ b/src/Vortice.D3D12MA.Native/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2019-2024 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/Vortice.D3D12MA.Native/Vortice.D3D12MA.Native.csproj b/src/Vortice.D3D12MA.Native/Vortice.D3D12MA.Native.csproj new file mode 100644 index 0000000..8f9d58b --- /dev/null +++ b/src/Vortice.D3D12MA.Native/Vortice.D3D12MA.Native.csproj @@ -0,0 +1,30 @@ + + + + netstandard2.0;net4.6.1;net8.0;net9.0 + D3D12MemoryAllocator native libraries with C bindings + 1.0.0 + false + true + + LICENSE.txt + https://github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator + README.md + false + + + + + + + + + + + + + + + + + diff --git a/src/Vortice.D3D12MA.Native/_._ b/src/Vortice.D3D12MA.Native/_._ new file mode 100644 index 0000000..e69de29 diff --git a/src/Vortice.D3D12MA.Native/build/net461/Vortice.D3D12MA.Native.targets b/src/Vortice.D3D12MA.Native/build/net461/Vortice.D3D12MA.Native.targets new file mode 100644 index 0000000..c19e555 --- /dev/null +++ b/src/Vortice.D3D12MA.Native/build/net461/Vortice.D3D12MA.Native.targets @@ -0,0 +1,15 @@ + + + + <_Vortice_D3DMA_Native_IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true + <_Vortice_D3DMA_Native_NativeRuntime Condition=" '$(_Vortice_D3DMA_Native_IsWindows)' == '' And '$(_Vortice_D3DMA_Native_IsWindows)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">win-x64 + <_Vortice_D3DMA_Native_NativeRuntime Condition=" '$(_Vortice_D3DMA_Native_IsWindows)' == '' And '$(_Vortice_D3DMA_Native_IsWindows)' == 'true' And '$(PlatformTarget)' == 'ARM64'">win-arm64 + + + + %(Filename)%(Extension) + Always + False + + + diff --git a/src/Vortice.D3D12MA.Native/runtimes/win-arm64/native/D3D12MA.dll b/src/Vortice.D3D12MA.Native/runtimes/win-arm64/native/D3D12MA.dll new file mode 100644 index 0000000..988af96 Binary files /dev/null and b/src/Vortice.D3D12MA.Native/runtimes/win-arm64/native/D3D12MA.dll differ diff --git a/src/Vortice.D3D12MA.Native/runtimes/win-x64/native/D3D12MA.dll b/src/Vortice.D3D12MA.Native/runtimes/win-x64/native/D3D12MA.dll new file mode 100644 index 0000000..2ae5843 Binary files /dev/null and b/src/Vortice.D3D12MA.Native/runtimes/win-x64/native/D3D12MA.dll differ diff --git a/src/Vortice.Dxc.Native/Vortice.Dxc.Native.csproj b/src/Vortice.Dxc.Native/Vortice.Dxc.Native.csproj index 99072af..05f323a 100644 --- a/src/Vortice.Dxc.Native/Vortice.Dxc.Native.csproj +++ b/src/Vortice.Dxc.Native/Vortice.Dxc.Native.csproj @@ -1,9 +1,9 @@ - netstandard2.0;net4.6.1;net8.0 + netstandard2.0;net4.6.1;net8.0;net9.0 Dxc native libraries - 1.0.2 + 1.0.3 false true @@ -23,6 +23,7 @@ + diff --git a/src/Vortice.Pix.Native/Vortice.Pix.Native.csproj b/src/Vortice.Pix.Native/Vortice.Pix.Native.csproj index 4edabb9..4bc4b7a 100644 --- a/src/Vortice.Pix.Native/Vortice.Pix.Native.csproj +++ b/src/Vortice.Pix.Native/Vortice.Pix.Native.csproj @@ -1,9 +1,9 @@ - netstandard2.0;net4.6.1;net8.0 + netstandard2.0;net4.6.1;net8.0;net9.0 WinPixEventRuntime native libraries - 1.0.0 + 1.0.1 false true @@ -22,6 +22,7 @@ + diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Allocation.cs b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Allocation.cs new file mode 100644 index 0000000..161d68b --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Allocation.cs @@ -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 Win32.Graphics.Direct3D12; +using static Win32.Apis; +using static Win32.Graphics.D3D12MemoryAllocator.Apis; + +namespace Win32.Graphics.D3D12MemoryAllocator; + +[DebuggerDisplay("{DebuggerDisplay,nq}")] +public readonly partial struct Allocation : IEquatable +{ + public Allocation(nint handle) { Handle = handle; } + public nint Handle { get; } + public bool IsNull => Handle == 0; + public bool IsNotNull => Handle != 0; + public static Allocation Null => new(0); + public static implicit operator Allocation(nint handle) => new(handle); + public static implicit operator nint(Allocation handle) => handle.Handle; + public static bool operator ==(Allocation left, Allocation right) => left.Handle == right.Handle; + public static bool operator !=(Allocation left, Allocation right) => left.Handle != right.Handle; + public static bool operator ==(Allocation left, nint right) => left.Handle == right; + public static bool operator !=(Allocation left, nint right) => left.Handle != right; + public bool Equals(Allocation other) => Handle == other.Handle; + /// + public override bool Equals(object? obj) => obj is Allocation handle && Equals(handle); + /// + public override int GetHashCode() => Handle.GetHashCode(); + private string DebuggerDisplay => $"{nameof(Allocation)} [0x{Handle:X}]"; + + public uint AddRef() => D3D12MA_Allocation_AddRef(Handle); + public uint Release() => D3D12MA_Allocation_Release(Handle); + public ulong Offset => D3D12MA_Allocation_GetOffset(Handle); + public ulong Alignment => D3D12MA_Allocation_GetAlignment(Handle); + public ulong Size => D3D12MA_Allocation_GetSize(Handle); + public unsafe ID3D12Resource* Resource + { + get => D3D12MA_Allocation_GetResource(Handle); + set => D3D12MA_Allocation_SetResource(Handle, value); + } + + public unsafe ID3D12Heap* Heap => D3D12MA_Allocation_GetHeap(Handle); +} diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Allocator.cs b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Allocator.cs new file mode 100644 index 0000000..1ad2624 --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Allocator.cs @@ -0,0 +1,93 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +using Win32.Graphics.Direct3D12; +using Win32.Graphics.Dxgi.Common; +using static Win32.Apis; +using static Win32.Graphics.D3D12MemoryAllocator.Apis; + +namespace Win32.Graphics.D3D12MemoryAllocator; + +[DebuggerDisplay("{DebuggerDisplay,nq}")] +public readonly unsafe partial struct Allocator : IEquatable +{ + public Allocator(nint handle) { Handle = handle; } + public nint Handle { get; } + public bool IsNull => Handle == 0; + public bool IsNotNull => Handle != 0; + public static Allocator Null => new(0); + public static implicit operator Allocator(nint handle) => new(handle); + public static implicit operator nint(Allocator handle) => handle.Handle; + public static bool operator ==(Allocator left, Allocator right) => left.Handle == right.Handle; + public static bool operator !=(Allocator left, Allocator right) => left.Handle != right.Handle; + public static bool operator ==(Allocator left, nint right) => left.Handle == right; + public static bool operator !=(Allocator left, nint right) => left.Handle != right; + public bool Equals(Allocator other) => Handle == other.Handle; + /// + public override bool Equals(object? obj) => obj is Allocator handle && Equals(handle); + /// + public override int GetHashCode() => Handle.GetHashCode(); + private string DebuggerDisplay => $"{nameof(Allocator)} [0x{Handle:X}]"; + + public uint AddRef() => D3D12MA_Allocator_AddRef(Handle); + public uint Release() => D3D12MA_Allocator_Release(Handle); + + public bool IsUMA => D3D12MA_Allocator_IsUMA(Handle); + public bool IsCacheCoherentUMA => D3D12MA_Allocator_IsCacheCoherentUMA(Handle); + public bool IsGPUUploadHeapSupported => D3D12MA_Allocator_IsGPUUploadHeapSupported(Handle); + + public ulong GetMemoryCapacity(uint memorySegmentGroup) => D3D12MA_Allocator_GetMemoryCapacity(Handle, memorySegmentGroup); + + public HResult CreateResource(AllocationDesc* pAllocDesc, + in ResourceDescription resourceDesc, + ResourceStates initialResourceState, + ClearValue* pOptimizedClearValue, + Allocation* allocation, Guid* riidResource, void** ppvResource) + { + fixed (ResourceDescription* pResourceDesc = &resourceDesc) + { + return D3D12MA_Allocator_CreateResource(Handle, pAllocDesc, pResourceDesc, initialResourceState, pOptimizedClearValue, allocation, riidResource, ppvResource); + } + } + + public HResult CreateResource(AllocationDesc* pAllocDesc, + in ResourceDescription resourceDesc, + ResourceStates initialResourceState, + ClearValue* pOptimizedClearValue, + Allocation* allocation, TResource** ppvResource) + where TResource : unmanaged, ID3D12Resource.Interface + { + fixed (ResourceDescription* pResourceDesc = &resourceDesc) + { + return D3D12MA_Allocator_CreateResource(Handle, + pAllocDesc, + pResourceDesc, + initialResourceState, + pOptimizedClearValue, + allocation, + __uuidof(), (void**)ppvResource); + } + } + + public HResult CreateResource2(AllocationDesc* pAllocDesc, + ResourceDescription1* pResourceDesc, + ResourceStates initialResourceState, + ClearValue* pOptimizedClearValue, + Allocation* allocation, Guid* riidResource, void** ppvResource) + { + return D3D12MA_Allocator_CreateResource2(Handle, pAllocDesc, pResourceDesc, initialResourceState, pOptimizedClearValue, allocation, riidResource, ppvResource); + } + + public HResult CreateResource3(AllocationDesc* pAllocDesc, + ResourceDescription1* pResourceDesc, + BarrierLayout initialLayout, + ClearValue* pOptimizedClearValue, + uint numCastableFormats, Format* pCastableFormats, + Allocation* allocation, Guid* riidResource, void** ppvResource) + { + return D3D12MA_Allocator_CreateResource3(Handle, pAllocDesc, pResourceDesc, initialLayout, + pOptimizedClearValue, + numCastableFormats, pCastableFormats, + allocation, riidResource, ppvResource); + } +} diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Apis.cs b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Apis.cs new file mode 100644 index 0000000..5f03850 --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Apis.cs @@ -0,0 +1,96 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +using Win32.Graphics.Direct3D12; +using Win32.Graphics.Dxgi.Common; + +namespace Win32.Graphics.D3D12MemoryAllocator; + +public static unsafe partial class Apis +{ + private const string LibraryName = "D3D12MA"; + + [LibraryImport(LibraryName, EntryPoint = "D3D12MA_CreateAllocator")] + public static partial HResult CreateAllocator(in AllocatorDesc desc, out Allocator allocator); + + [LibraryImport(LibraryName, EntryPoint = "D3D12MA_CreateVirtualBlock")] + public static partial HResult CreateVirtualBlock(in VirtualBlockDesc desc, out VirtualBlock virtualBlock); + + [LibraryImport(LibraryName)] + internal static partial uint D3D12MA_Allocator_AddRef(nint pSelf); + [LibraryImport(LibraryName)] + internal static partial uint D3D12MA_Allocator_Release(nint pSelf); + + [LibraryImport(LibraryName)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool D3D12MA_Allocator_IsUMA(nint pSelf); + + [LibraryImport(LibraryName)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool D3D12MA_Allocator_IsCacheCoherentUMA(nint pSelf); + + [LibraryImport(LibraryName)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool D3D12MA_Allocator_IsGPUUploadHeapSupported(nint pSelf); + + [LibraryImport(LibraryName)] + internal static partial ulong D3D12MA_Allocator_GetMemoryCapacity(nint pSelf, uint memorySegmentGroup); + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_CreateResource(nint pSelf, AllocationDesc* allocationDesc, ResourceDescription* resourceDesc, ResourceStates initialResourceState, ClearValue* pOptimizedClearValue, Allocation* allocation, Guid* riidResource, void** ppvResource); + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_CreateResource2(nint pSelf, AllocationDesc* allocationDesc, ResourceDescription1* pResourceDesc, ResourceStates initialResourceState, ClearValue* pOptimizedClearValue, Allocation* ppAllocation, Guid* riidResource, void** ppvResource); + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_CreateResource3(nint pSelf, AllocationDesc* allocationDesc, ResourceDescription1* pResourceDesc, BarrierLayout InitialLayout, ClearValue* pOptimizedClearValue, uint NumCastableFormats, Format* pCastableFormats, Allocation* ppAllocation, Guid* riidResource, void** ppvResource); + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_AllocateMemory(nint pSelf, AllocationDesc* pAllocDesc, ResourceAllocationInfo* pAllocInfo, Allocation* ppAllocation); + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_CreateAliasingResource(nint pSelf, Allocation* pAllocation, ulong AllocationLocalOffset, ResourceDescription* pResourceDesc, ResourceStates InitialResourceState, ClearValue* pOptimizedClearValue, Guid* riidResource, void** ppvResource); + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_CreateAliasingResource1(nint pSelf, Allocation* pAllocation, ulong AllocationLocalOffset, ResourceDescription* pResourceDesc, ResourceStates InitialResourceState, ClearValue* pOptimizedClearValue, Guid* riidResource, void** ppvResource); + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_CreateAliasingResource2(nint pSelf, Allocation* pAllocation, ulong AllocationLocalOffset, ResourceDescription* pResourceDesc, BarrierLayout InitialLayout, ClearValue* pOptimizedClearValue, uint NumCastableFormats, Format* pCastableFormats, Guid* riidResource, void** ppvResource); + + [LibraryImport(LibraryName)] + internal static partial HResult D3D12MA_Allocator_CreatePool(nint pSelf, PoolDesc* pPoolDesc, Pool* ppPool); + [LibraryImport(LibraryName)] + internal static partial void D3D12MA_Allocator_SetCurrentFrameIndex(nint pSelf, uint frameIndex); + //[LibraryImport(LibraryName)] + //internal static partial void D3D12MA_Allocator_GetBudget(nint pSelf, D3D12MABudget* pLocalBudget, D3D12MABudget* pNonLocalBudget); + //[LibraryImport(LibraryName)] + //internal static partial void D3D12MA_Allocator_CalculateStatistics(nint pSelf, D3D12MATotalStatistics* pStats); + [LibraryImport(LibraryName)] + internal static partial void D3D12MA_Allocator_BuildStatsString(nint pSelf, char** ppStatsString, Bool32 DetailedMap); + [LibraryImport(LibraryName)] + internal static partial void D3D12MA_Allocator_FreeStatsString(nint pSelf, char* pStatsString); + //[LibraryImport(LibraryName)] + //internal static partial void D3D12MA_Allocator_BeginDefragmentation(void* pSelf, const D3D12MA_DEFRAGMENTATION_DESC* pDesc, D3D12MA_DefragmentationContext** ppContext); + + #region Allocation + [LibraryImport(LibraryName)] + internal static partial uint D3D12MA_Allocation_AddRef(nint pSelf); + [LibraryImport(LibraryName)] + internal static partial uint D3D12MA_Allocation_Release(nint pSelf); + + [LibraryImport(LibraryName)] + internal static partial ulong D3D12MA_Allocation_GetOffset(nint pSelf); + [LibraryImport(LibraryName)] + internal static partial ulong D3D12MA_Allocation_GetAlignment(nint pSelf); + [LibraryImport(LibraryName)] + internal static partial ulong D3D12MA_Allocation_GetSize(nint pSelf); + [LibraryImport(LibraryName)] + internal static partial ID3D12Resource* D3D12MA_Allocation_GetResource(nint pSelf); + + [LibraryImport(LibraryName)] + internal static partial void D3D12MA_Allocation_SetResource(nint pSelf, ID3D12Resource* pResource); + [LibraryImport(LibraryName)] + internal static partial ID3D12Heap* D3D12MA_Allocation_GetHeap(nint pSelf); + [LibraryImport(LibraryName)] + internal static partial void D3D12MA_Allocation_SetPrivateData(nint pSelf, void* pPrivateData); + [LibraryImport(LibraryName)] + internal static partial void* D3D12MA_Allocation_GetPrivateData(nint pSelf); + [LibraryImport(LibraryName)] + internal static partial void D3D12MA_Allocation_SetName(nint pSelf, char* Name); + [LibraryImport(LibraryName)] + internal static partial char* D3D12MA_Allocation_GetName(nint pSelf); + #endregion +} diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Enums.cs b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Enums.cs new file mode 100644 index 0000000..6396ee3 --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Enums.cs @@ -0,0 +1,121 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +namespace Win32.Graphics.D3D12MemoryAllocator; + +/// D3D12MA_ALLOCATOR_FLAGS +[Flags] +public enum AllocatorFlags +{ + /// D3D12MA_ALLOCATOR_FLAG_NONE + None = 0x00, + /// D3D12MA_ALLOCATOR_FLAG_SINGLETHREADED + SingleThreaded = 0x01, + /// D3D12MA_ALLOCATOR_FLAG_ALWAYS_COMMITTED + AlwaysCommitted = 0x02, + /// D3D12MA_ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED + DefaultPoolsNotZeroed = 0x04, + /// D3D12MA_ALLOCATOR_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED + MSAATexturesAlwaysCommitted = 0x08, + /// D3D12MA_ALLOCATOR_FLAG_DONT_PREFER_SMALL_BUFFERS_COMMITTED + DontPreferSmallBuffersCommitted = 0x10 +} + +/// D3D12MA_POOL_FLAGS +[Flags] +public enum PoolFlags +{ + /// D3D12MA_POOL_FLAG_NONE + None = 0x0, + /// D3D12MA_POOL_FLAG_ALGORITHM_LINEAR + AlgorithmLinear = 0x1, + /// D3D12MA_POOL_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED + MSAATexturesAlwaysCommitted = 0x2, + /// D3D12MA_POOL_FLAG_ALGORITHM_MASK + AlgorithmMask = AlgorithmLinear, +} + +/// D3D12MA_ALLOCATION_FLAGS +[Flags] +public enum AllocationFlags +{ + /// D3D12MA_ALLOCATION_FLAG_NONE + None = 0x00000000, + /// D3D12MA_ALLOCATION_FLAG_COMMITTED + Committed = 0x00000001, + /// D3D12MA_ALLOCATION_FLAG_NEVER_ALLOCATE + NeverAllocate = 0x00000002, + /// D3D12MA_ALLOCATION_FLAG_WITHIN_BUDGET + WithinBudget = 0x00000004, + /// D3D12MA_ALLOCATION_FLAG_UPPER_ADDRESS + UpperAddress = 0x00000008, + /// D3D12MA_ALLOCATION_FLAG_CAN_ALIAS + CanAlias = 0x00000010, + /// D3D12MA_ALLOCATION_FLAG_STRATEGY_MIN_MEMORY + StrategyMinMemory = 0x00010000, + /// D3D12MA_ALLOCATION_FLAG_STRATEGY_MIN_TIME + StrategyMinTime = 0x00020000, + /// D3D12MA_ALLOCATION_FLAG_STRATEGY_MIN_OFFSET + StrategyMinOffset = 0x0004000, + /// D3D12MA_ALLOCATION_FLAG_STRATEGY_BEST_FIT + StrategyBestFit = StrategyMinMemory, + /// D3D12MA_ALLOCATION_FLAG_STRATEGY_FIRST_FIT + StrategyFirstFit = StrategyMinTime, + /// D3D12MA_ALLOCATION_FLAG_STRATEGY_MASK + StrategyMask = StrategyMinMemory | StrategyMinTime | StrategyMinOffset +} + +/// D3D12MA_ALLOCATION_FLAGS +[Flags] +public enum VirtualBlockFlags +{ + /// D3D12MA_VIRTUAL_BLOCK_FLAG_NONE + None = 0, + /// D3D12MA_VIRTUAL_BLOCK_FLAG_ALGORITHM_LINEAR + AlgorithmLinear = PoolFlags.AlgorithmLinear, + /// D3D12MA_VIRTUAL_BLOCK_FLAG_ALGORITHM_MASK + AlgorithmMask = PoolFlags.AlgorithmMask, +} + +/// D3D12MA_DEFRAGMENTATION_FLAGS +[Flags] +public enum DefragmentationFlags +{ + /// D3D12MA_DEFRAGMENTATION_FLAG_ALGORITHM_FAST + AlgorithmFast = 0x1, + /// D3D12MA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED + AlgorithmBalanced = 0x2, + /// D3D12MA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL + AlgorithmFull = 0x4, + /// D3D12MA_DEFRAGMENTATION_FLAG_ALGORITHM_MASK + AlgorithmMask = AlgorithmFast | AlgorithmBalanced | AlgorithmFull, +} + +/// D3D12MA_DEFRAGMENTATION_MOVE_OPERATION +public enum DefragmentationMoveOperation +{ + /// D3D12MA_DEFRAGMENTATION_MOVE_OPERATION_COPY + Copy = 0, + /// D3D12MA_DEFRAGMENTATION_MOVE_OPERATION_IGNORE + Ignore = 1, + /// D3D12MA_DEFRAGMENTATION_MOVE_OPERATION_DESTROY + Destroy = 2, +} + +/// D3D12MA_VIRTUAL_ALLOCATION_FLAGS +[Flags] +public enum VirtualAllocationFlags +{ + /// D3D12MA_VIRTUAL_ALLOCATION_FLAG_NONE + None = 0, + /// D3D12MA_VIRTUAL_ALLOCATION_FLAG_UPPER_ADDRESS + UpperAddress = AllocationFlags.UpperAddress, + /// D3D12MA_VIRTUAL_ALLOCATION_FLAG_STRATEGY_MIN_MEMORY + StrategyMinMemory = AllocationFlags.StrategyMinMemory, + /// D3D12MA_VIRTUAL_ALLOCATION_FLAG_STRATEGY_MIN_TIME + StrategyMinTime = AllocationFlags.StrategyMinTime, + /// D3D12MA_VIRTUAL_ALLOCATION_FLAG_STRATEGY_MIN_OFFSET + StrategyMinOffset = AllocationFlags.StrategyMinOffset, + /// D3D12MA_ALLOCATION_FLAG_STRATEGY_MASK + StrategyMask = AllocationFlags.StrategyMask, +} diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Handles.cs b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Handles.cs new file mode 100644 index 0000000..0b22a05 --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Handles.cs @@ -0,0 +1,70 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +namespace Win32.Graphics.D3D12MemoryAllocator; + +[DebuggerDisplay("{DebuggerDisplay,nq}")] +public readonly partial struct Pool : IEquatable +{ + public Pool(nint handle) { Handle = handle; } + public nint Handle { get; } + public bool IsNull => Handle == 0; + public bool IsNotNull => Handle != 0; + public static Pool Null => new(0); + public static implicit operator Pool(nint handle) => new(handle); + public static implicit operator nint(Pool handle) => handle.Handle; + public static bool operator ==(Pool left, Pool right) => left.Handle == right.Handle; + public static bool operator !=(Pool left, Pool right) => left.Handle != right.Handle; + public static bool operator ==(Pool left, nint right) => left.Handle == right; + public static bool operator !=(Pool left, nint right) => left.Handle != right; + public bool Equals(Pool other) => Handle == other.Handle; + /// + public override bool Equals(object? obj) => obj is Pool handle && Equals(handle); + /// + public override int GetHashCode() => Handle.GetHashCode(); + private string DebuggerDisplay => $"{nameof(Pool)} [0x{Handle:X}]"; +} + +[DebuggerDisplay("{DebuggerDisplay,nq}")] +public readonly partial struct VirtualBlock : IEquatable +{ + public VirtualBlock(nint handle) { Handle = handle; } + public nint Handle { get; } + public bool IsNull => Handle == 0; + public bool IsNotNull => Handle != 0; + public static VirtualBlock Null => new(0); + public static implicit operator VirtualBlock(nint handle) => new(handle); + public static implicit operator nint(VirtualBlock handle) => handle.Handle; + public static bool operator ==(VirtualBlock left, VirtualBlock right) => left.Handle == right.Handle; + public static bool operator !=(VirtualBlock left, VirtualBlock right) => left.Handle != right.Handle; + public static bool operator ==(VirtualBlock left, nint right) => left.Handle == right; + public static bool operator !=(VirtualBlock left, nint right) => left.Handle != right; + public bool Equals(VirtualBlock other) => Handle == other.Handle; + /// + public override bool Equals(object? obj) => obj is VirtualBlock handle && Equals(handle); + /// + public override int GetHashCode() => Handle.GetHashCode(); + private string DebuggerDisplay => $"{nameof(VirtualBlock)} [0x{Handle:X}]"; +} + +[DebuggerDisplay("{DebuggerDisplay,nq}")] +public readonly partial struct DefragmentationContext : IEquatable +{ + public DefragmentationContext(nint handle) { Handle = handle; } + public nint Handle { get; } + public bool IsNull => Handle == 0; + public bool IsNotNull => Handle != 0; + public static DefragmentationContext Null => new(0); + public static implicit operator DefragmentationContext(nint handle) => new(handle); + public static implicit operator nint(DefragmentationContext handle) => handle.Handle; + public static bool operator ==(DefragmentationContext left, DefragmentationContext right) => left.Handle == right.Handle; + public static bool operator !=(DefragmentationContext left, DefragmentationContext right) => left.Handle != right.Handle; + public static bool operator ==(DefragmentationContext left, nint right) => left.Handle == right; + public static bool operator !=(DefragmentationContext left, nint right) => left.Handle != right; + public bool Equals(DefragmentationContext other) => Handle == other.Handle; + /// + public override bool Equals(object? obj) => obj is DefragmentationContext handle && Equals(handle); + /// + public override int GetHashCode() => Handle.GetHashCode(); + private string DebuggerDisplay => $"{nameof(DefragmentationContext)} [0x{Handle:X}]"; +} diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Pool.cs b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Pool.cs new file mode 100644 index 0000000..7c0740e --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Pool.cs @@ -0,0 +1,11 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +using static Win32.Apis; +using static Win32.Graphics.D3D12MemoryAllocator.Apis; + +namespace Win32.Graphics.D3D12MemoryAllocator; + +partial struct Pool +{ +} diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Structs.cs b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Structs.cs new file mode 100644 index 0000000..f4ec91e --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Structs.cs @@ -0,0 +1,80 @@ +// Copyright © Amer Koleci and Contributors. +// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. + +using Win32.Graphics.Direct3D12; +using Win32.Graphics.Dxgi; + +namespace Win32.Graphics.D3D12MemoryAllocator; + +/// D3D12MA_ALLOCATION_CALLBACKS +public unsafe partial struct AllocationCallbacks +{ + /// Allocation function. + /// D3D12MA_AllocateFunctionType + public delegate* unmanaged pAllocate; + + /// Dellocation function. + /// D3D12MA_FreeFunctionType + public delegate* unmanaged pFree; + + /// Custom data that will be passed to allocation and deallocation functions as pUserData parameter. + public void* pPrivateData; +} + +/// D3D12MA_ALLOCATOR_DESC +public unsafe partial struct AllocatorDesc +{ + public AllocatorFlags Flags; + public ID3D12Device* pDevice; + public ulong PreferredBlockSize; + public AllocationCallbacks* pAllocationCallbacks; + public IDXGIAdapter* pAdapter; +} + +/// D3D12MA_POOL_DESC +public unsafe partial struct PoolDesc +{ + public PoolFlags Flags; + public HeapProperties HeapProperties; + public HeapFlags HeapFlags; + public ulong BlockSize; + public uint MinBlockCount; + public uint MaxBlockCount; + public ulong MinAllocationAlignment; + public ID3D12ProtectedResourceSession* pProtectedSession; + public ResidencyPriority ResidencyPriority; +} + +/// D3D12MA_VIRTUAL_BLOCK_DESC +public unsafe partial struct VirtualBlockDesc +{ + public VirtualBlockFlags Flags; + public ulong Size; + public AllocationCallbacks* pAllocationCallbacks; +} + +/// D3D12MA_ALLOCATION_DESC +public unsafe partial struct AllocationDesc +{ + public AllocationFlags Flags; + public HeapType HeapType; + public HeapFlags ExtraHeapFlags; + public Pool* CustomPool; + public void* pPrivateData; +} + +/// D3D12MA_VIRTUAL_ALLOCATION_DESC +public unsafe partial struct D3D12MA_VIRTUAL_ALLOCATION_DESC +{ + public VirtualAllocationFlags Flags; + public ulong Size; + public ulong Alignment; + public void* pPrivateData; +} + +public unsafe partial struct D3D12MA_VIRTUAL_ALLOCATION_INFO +{ + public ulong Offset; + public ulong Size; + public void* pPrivateData; +} diff --git a/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Vortice.Win32.Graphics.D3D12MemoryAllocator.csproj b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Vortice.Win32.Graphics.D3D12MemoryAllocator.csproj new file mode 100644 index 0000000..f57c55a --- /dev/null +++ b/src/Vortice.Win32.Graphics.D3D12MemoryAllocator/Vortice.Win32.Graphics.D3D12MemoryAllocator.csproj @@ -0,0 +1,25 @@ + + + + net8.0;net9.0 + D3D12MemoryAllocator bindings + + $(NoWarn);CS0419;IDE0017 + + + + + + + + + + + + + + + + + + diff --git a/src/Vortice.Win32.Graphics.Direct2D/Vortice.Win32.Graphics.Direct2D.csproj b/src/Vortice.Win32.Graphics.Direct2D/Vortice.Win32.Graphics.Direct2D.csproj index 74ab3d5..aa4aaac 100644 --- a/src/Vortice.Win32.Graphics.Direct2D/Vortice.Win32.Graphics.Direct2D.csproj +++ b/src/Vortice.Win32.Graphics.Direct2D/Vortice.Win32.Graphics.Direct2D.csproj @@ -1,8 +1,8 @@ - net8.0 - Direct2D1 bindings. + net8.0;net9.0 + Direct2D1 bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.Direct3D.Dxc/Vortice.Win32.Graphics.Direct3D.Dxc.csproj b/src/Vortice.Win32.Graphics.Direct3D.Dxc/Vortice.Win32.Graphics.Direct3D.Dxc.csproj index 81fb2ab..e82432d 100644 --- a/src/Vortice.Win32.Graphics.Direct3D.Dxc/Vortice.Win32.Graphics.Direct3D.Dxc.csproj +++ b/src/Vortice.Win32.Graphics.Direct3D.Dxc/Vortice.Win32.Graphics.Direct3D.Dxc.csproj @@ -1,8 +1,8 @@ - net8.0 - DXC (DirectXShaderCompiler) bindings. + net8.0;net9.0 + DXC (DirectXShaderCompiler) bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.Direct3D.Fxc/Vortice.Win32.Graphics.Direct3D.Fxc.csproj b/src/Vortice.Win32.Graphics.Direct3D.Fxc/Vortice.Win32.Graphics.Direct3D.Fxc.csproj index 803acdf..78ab529 100644 --- a/src/Vortice.Win32.Graphics.Direct3D.Fxc/Vortice.Win32.Graphics.Direct3D.Fxc.csproj +++ b/src/Vortice.Win32.Graphics.Direct3D.Fxc/Vortice.Win32.Graphics.Direct3D.Fxc.csproj @@ -1,9 +1,8 @@ - net8.0 - FXC bindings. - + net8.0;net9.0 + FXC bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.Direct3D11/Vortice.Win32.Graphics.Direct3D11.csproj b/src/Vortice.Win32.Graphics.Direct3D11/Vortice.Win32.Graphics.Direct3D11.csproj index 08ea01d..4525bec 100644 --- a/src/Vortice.Win32.Graphics.Direct3D11/Vortice.Win32.Graphics.Direct3D11.csproj +++ b/src/Vortice.Win32.Graphics.Direct3D11/Vortice.Win32.Graphics.Direct3D11.csproj @@ -1,9 +1,8 @@ - net8.0 - Direct3D11 bindings. - + net8.0;net9.0 + Direct3D11 bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.Direct3D11on12/Vortice.Win32.Graphics.Direct3D11on12.csproj b/src/Vortice.Win32.Graphics.Direct3D11on12/Vortice.Win32.Graphics.Direct3D11on12.csproj index 918d972..744e555 100644 --- a/src/Vortice.Win32.Graphics.Direct3D11on12/Vortice.Win32.Graphics.Direct3D11on12.csproj +++ b/src/Vortice.Win32.Graphics.Direct3D11on12/Vortice.Win32.Graphics.Direct3D11on12.csproj @@ -1,8 +1,8 @@ - net8.0 - Direct3D11on12 bindings. + net8.0;net9.0 + Direct3D11on12 bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.Direct3D12/Vortice.Win32.Graphics.Direct3D12.csproj b/src/Vortice.Win32.Graphics.Direct3D12/Vortice.Win32.Graphics.Direct3D12.csproj index 2ff9ecb..4c8a8af 100644 --- a/src/Vortice.Win32.Graphics.Direct3D12/Vortice.Win32.Graphics.Direct3D12.csproj +++ b/src/Vortice.Win32.Graphics.Direct3D12/Vortice.Win32.Graphics.Direct3D12.csproj @@ -1,9 +1,8 @@ - net8.0 - Direct3D12 bindings. - + net8.0;net9.0 + Direct3D12 bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.DirectComposition/Vortice.Win32.Graphics.DirectComposition.csproj b/src/Vortice.Win32.Graphics.DirectComposition/Vortice.Win32.Graphics.DirectComposition.csproj index d728529..334edc9 100644 --- a/src/Vortice.Win32.Graphics.DirectComposition/Vortice.Win32.Graphics.DirectComposition.csproj +++ b/src/Vortice.Win32.Graphics.DirectComposition/Vortice.Win32.Graphics.DirectComposition.csproj @@ -1,9 +1,8 @@ - net8.0 - DirectComposition bindings. - + net8.0;net9.0 + DirectComposition bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.DirectWrite/Vortice.Win32.Graphics.DirectWrite.csproj b/src/Vortice.Win32.Graphics.DirectWrite/Vortice.Win32.Graphics.DirectWrite.csproj index 900c9b6..46d9445 100644 --- a/src/Vortice.Win32.Graphics.DirectWrite/Vortice.Win32.Graphics.DirectWrite.csproj +++ b/src/Vortice.Win32.Graphics.DirectWrite/Vortice.Win32.Graphics.DirectWrite.csproj @@ -1,9 +1,8 @@ - net8.0 - DirectWrite bindings. - + net8.0;net9.0 + DirectWrite bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.Dxgi/Vortice.Win32.Graphics.Dxgi.csproj b/src/Vortice.Win32.Graphics.Dxgi/Vortice.Win32.Graphics.Dxgi.csproj index 0dd316f..c053bb6 100644 --- a/src/Vortice.Win32.Graphics.Dxgi/Vortice.Win32.Graphics.Dxgi.csproj +++ b/src/Vortice.Win32.Graphics.Dxgi/Vortice.Win32.Graphics.Dxgi.csproj @@ -1,9 +1,8 @@ - net8.0 - Dxgi bindings. - + net8.0;net9.0 + DXGI bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Graphics.Imaging/Vortice.Win32.Graphics.Imaging.csproj b/src/Vortice.Win32.Graphics.Imaging/Vortice.Win32.Graphics.Imaging.csproj index 1323ce9..5159066 100644 --- a/src/Vortice.Win32.Graphics.Imaging/Vortice.Win32.Graphics.Imaging.csproj +++ b/src/Vortice.Win32.Graphics.Imaging/Vortice.Win32.Graphics.Imaging.csproj @@ -1,9 +1,8 @@ - net8.0 - WIC bindings. - + net8.0;net9.0 + WIC bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32.Media.Audio.XAudio2/Vortice.Win32.Media.Audio.XAudio2.csproj b/src/Vortice.Win32.Media.Audio.XAudio2/Vortice.Win32.Media.Audio.XAudio2.csproj index c2b1c8c..c48fc29 100644 --- a/src/Vortice.Win32.Media.Audio.XAudio2/Vortice.Win32.Media.Audio.XAudio2.csproj +++ b/src/Vortice.Win32.Media.Audio.XAudio2/Vortice.Win32.Media.Audio.XAudio2.csproj @@ -1,9 +1,8 @@ - net8.0 - XAudio2 and X3DAudio bindings. - + net8.0;net9.0 + XAudio2 and X3DAudio bindings $(NoWarn);CS0419;IDE0017 diff --git a/src/Vortice.Win32/ComPtr.cs b/src/Vortice.Win32/ComPtr.cs index 46aa6d3..f7e6498 100644 --- a/src/Vortice.Win32/ComPtr.cs +++ b/src/Vortice.Win32/ComPtr.cs @@ -13,7 +13,7 @@ namespace Win32; /// The type to wrap in the current instance. /// While this type is not marked as so that it can also be used in fields, make sure to keep the reference counts properly tracked if you do store instances on the heap. public unsafe struct ComPtr : IDisposable - where T : unmanaged + where T : unmanaged, IUnknown.Interface { /// The raw pointer to a COM object, if existing. private T* ptr_; @@ -38,7 +38,7 @@ public unsafe struct ComPtr : IDisposable /// The raw pointer to wrap. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ComPtr(T* other) - => new ComPtr(other); + => new(other); /// Unwraps a instance and returns the internal raw pointer. /// The instance to unwrap. @@ -52,9 +52,9 @@ public unsafe struct ComPtr : IDisposable /// The result of for the target type . /// This method will automatically release the target COM object pointed to by , if any. public readonly HResult As(ComPtr* p) - where U : unmanaged, INativeGuid + where U : unmanaged, IUnknown.Interface { - return ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)p->ReleaseAndGetAddressOf()); + return ptr_->QueryInterface(__uuidof(), (void**)p->ReleaseAndGetAddressOf()); } /// Converts the current object reference to type and assigns that to a target value. @@ -63,10 +63,10 @@ public unsafe struct ComPtr : IDisposable /// The result of for the target type . /// This method will automatically release the target COM object pointed to by , if any. public readonly HResult As(ref ComPtr other) - where U : unmanaged, INativeGuid + where U : unmanaged, IUnknown.Interface { U* ptr; - HResult result = ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)&ptr); + HResult result = ptr_->QueryInterface(__uuidof(), (void**)&ptr); other.Attach(ptr); return result; @@ -79,7 +79,7 @@ public unsafe struct ComPtr : IDisposable /// This method will automatically release the target COM object pointed to by , if any. public readonly HResult AsIID(Guid* riid, ComPtr* other) { - return ((IUnknown*)ptr_)->QueryInterface(riid, (void**)other->ReleaseAndGetAddressOf()); + return ptr_->QueryInterface(riid, (void**)other->ReleaseAndGetAddressOf()); } /// Converts the current object reference to a type indicated by the given IID and assigns that to a target value. @@ -90,7 +90,7 @@ public unsafe struct ComPtr : IDisposable public readonly HResult AsIID(Guid* riid, ref ComPtr other) { IUnknown* ptr; - HResult result = ((IUnknown*)ptr_)->QueryInterface(riid, (void**)&ptr); + HResult result = ptr_->QueryInterface(riid, (void**)&ptr); other.Attach(ptr); return result; @@ -103,7 +103,7 @@ public unsafe struct ComPtr : IDisposable { if (ptr_ != null) { - var @ref = ((IUnknown*)ptr_)->Release(); + var @ref = ptr_->Release(); Debug.Assert((@ref != 0) || (ptr_ != other)); } ptr_ = other; @@ -153,28 +153,28 @@ public unsafe struct ComPtr : IDisposable /// The target raw pointer to copy the address of the current COM object to. /// The result of for the target type . public readonly HResult CopyTo(U** ptr) - where U : unmanaged, INativeGuid + where U : unmanaged, IUnknown.Interface { - return ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)ptr); + return ptr_->QueryInterface(__uuidof(), (void**)ptr); } /// Converts the current COM object reference to a given interface type and assigns that to a target . /// The target raw pointer to copy the address of the current COM object to. /// The result of for the target type . public readonly HResult CopyTo(ComPtr* p) - where U : unmanaged, INativeGuid + where U : unmanaged, IUnknown.Interface { - return ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)p->ReleaseAndGetAddressOf()); + return ptr_->QueryInterface(__uuidof(), (void**)p->ReleaseAndGetAddressOf()); } /// Converts the current COM object reference to a given interface type and assigns that to a target . /// The target reference to copy the address of the current COM object to. /// The result of for the target type . public readonly HResult CopyTo(ref ComPtr other) - where U : unmanaged, INativeGuid + where U : unmanaged, IUnknown.Interface { U* ptr; - HResult result = ((IUnknown*)ptr_)->QueryInterface(__uuidof(), (void**)&ptr); + HResult result = ptr_->QueryInterface(__uuidof(), (void**)&ptr); other.Attach(ptr); return result; @@ -186,7 +186,7 @@ public unsafe struct ComPtr : IDisposable /// The result of for the target IID. public readonly HResult CopyTo(Guid* riid, void** ptr) { - return ((IUnknown*)ptr_)->QueryInterface(riid, ptr); + return ptr_->QueryInterface(riid, ptr); } /// Converts the current object reference to a type indicated by the given IID and assigns that to a target value. @@ -195,7 +195,7 @@ public unsafe struct ComPtr : IDisposable /// The result of for the target IID. public readonly HResult CopyTo(Guid* riid, ComPtr* p) { - return ((IUnknown*)ptr_)->QueryInterface(riid, (void**)p->ReleaseAndGetAddressOf()); + return ptr_->QueryInterface(riid, (void**)p->ReleaseAndGetAddressOf()); } /// Converts the current object reference to a type indicated by the given IID and assigns that to a target value. @@ -205,7 +205,7 @@ public unsafe struct ComPtr : IDisposable public readonly HResult CopyTo(Guid* riid, ref ComPtr other) { IUnknown* ptr; - HResult result = ((IUnknown*)ptr_)->QueryInterface(riid, (void**)&ptr); + HResult result = ptr_->QueryInterface(riid, (void**)&ptr); other.Attach(ptr); return result; @@ -220,7 +220,7 @@ public unsafe struct ComPtr : IDisposable if (pointer != null) { ptr_ = null; - _ = ((IUnknown*)pointer)->Release(); + _ = pointer->Release(); } } @@ -254,17 +254,6 @@ public unsafe struct ComPtr : IDisposable return (void**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); } - /// - /// Gets the address of the current instance as a raw double pointer. - /// This method is only valid when the current instance is on the stack or pinned. - /// - /// The raw pointer to the current instance. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly IUnknown** GetIUnknownAddressOf() - { - return (IUnknown**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); - } - /// Gets the address of the current instance as a raw double pointer. /// The raw pointer to the current instance. [EditorBrowsable(EditorBrowsableState.Never)] @@ -309,10 +298,7 @@ public unsafe struct ComPtr : IDisposable /// Resets the current instance by decrementing the reference count for the target COM object and setting the internal raw pointer to . /// The updated reference count for the COM object that was in use, if any. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint Reset() - { - return InternalRelease(); - } + public uint Reset() => InternalRelease(); /// Swaps the current COM object reference with that of a given instance. /// The target instance to swap with the current one. @@ -341,7 +327,7 @@ public unsafe struct ComPtr : IDisposable if (temp != null) { - _ = ((IUnknown*)temp)->AddRef(); + _ = temp->AddRef(); } } @@ -354,7 +340,7 @@ public unsafe struct ComPtr : IDisposable if (temp != null) { ptr_ = null; - @ref = ((IUnknown*)temp)->Release(); + @ref = temp->Release(); } return @ref; diff --git a/src/Vortice.Win32/Vortice.Win32.csproj b/src/Vortice.Win32/Vortice.Win32.csproj index 59ed162..ce223d0 100644 --- a/src/Vortice.Win32/Vortice.Win32.csproj +++ b/src/Vortice.Win32/Vortice.Win32.csproj @@ -1,8 +1,8 @@ - net8.0 - Windows API low level bindings. + net8.0;net9.0 + Windows API low level bindings diff --git a/src/Vortice.Win32/Win32.cs b/src/Vortice.Win32/Win32.cs index 692d49d..7a93bf8 100644 --- a/src/Vortice.Win32/Win32.cs +++ b/src/Vortice.Win32/Win32.cs @@ -10,7 +10,7 @@ public static unsafe partial class Apis [DoesNotReturn] public static void ThrowExternalException(string methodName, int errorCode) { - var message = string.Format("'{0}' failed with an error code of '{1}'", methodName, errorCode); + string message = string.Format("'{0}' failed with an error code of '{1}'", methodName, errorCode); throw new ExternalException(message, errorCode); }