From e0b2c6a9fde77235da202e516d2c83fca56d4d75 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 17 Oct 2023 03:11:44 +0200 Subject: [PATCH 1/6] Switch to CsWin32 for DXC APIs in D3D12 generator --- ComputeSharp.sln | 2 - .../Primitives/Internals/UndefinedData.cs | 11 ++- .../ComputeSharp.SourceGenerators.csproj | 7 +- .../Dxc/DxcShaderCompiler.cs | 75 +++++++++---------- .../Dxc/Interop/ComPtr{T}.cs | 62 +++++++++++++++ .../NativeMethods.json | 10 +++ .../NativeMethods.txt | 7 ++ 7 files changed, 121 insertions(+), 53 deletions(-) create mode 100644 src/ComputeSharp.SourceGenerators/Dxc/Interop/ComPtr{T}.cs create mode 100644 src/ComputeSharp.SourceGenerators/NativeMethods.json create mode 100644 src/ComputeSharp.SourceGenerators/NativeMethods.txt diff --git a/ComputeSharp.sln b/ComputeSharp.sln index e3be080b..1a592848 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -495,10 +495,8 @@ Global src\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e7c9247d-016b-4819-af9f-0e9b3591e04b}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e91f4d24-922a-4921-a8d7-9c45a143c45d}*SharedItemsImports = 5 - src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 - src\ComputeSharp.Win32.D3D12\ComputeSharp.Win32.D3D12.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{f8bf7666-7ccf-4fe4-b055-2eba4bcd4564}*SharedItemsImports = 13 EndGlobalSection EndGlobal diff --git a/src/ComputeSharp.Core/Primitives/Internals/UndefinedData.cs b/src/ComputeSharp.Core/Primitives/Internals/UndefinedData.cs index 6e25e4ac..1659d4db 100644 --- a/src/ComputeSharp.Core/Primitives/Internals/UndefinedData.cs +++ b/src/ComputeSharp.Core/Primitives/Internals/UndefinedData.cs @@ -1,7 +1,5 @@ -#if NET6_0_OR_GREATER +#if !SOURCE_GENERATOR using System.Runtime.CompilerServices; -#else -using RuntimeHelpers = ComputeSharp.NetStandard.RuntimeHelpers; #endif namespace ComputeSharp; @@ -15,5 +13,10 @@ internal static class UndefinedData /// /// The shared memory with undefined data (has size of , as it's the maximum needed at once). /// - public static readonly unsafe void* Memory = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UndefinedData), sizeof(Double4)); + public static readonly unsafe void* Memory = +#if SOURCE_GENERATOR + null; +#else + (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UndefinedData), sizeof(Double4)); +#endif } diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 66666ac9..63332f06 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -70,6 +70,7 @@ + @@ -88,12 +89,6 @@ - - - - - - diff --git a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs index 9360ef72..d3980d85 100644 --- a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs @@ -1,10 +1,11 @@ using System; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading; -using TerraFX.Interop.DirectX; -using TerraFX.Interop.Windows; +using ComputeSharp.SourceGenerators.Dxc.Interop; +using Windows.Win32; +using Windows.Win32.Foundation; +using Windows.Win32.Graphics.Direct3D.Dxc; namespace ComputeSharp.SourceGenerators.Dxc; @@ -42,19 +43,20 @@ internal sealed unsafe class DxcShaderCompiler { using ComPtr dxcCompiler = default; using ComPtr dxcLibrary = default; + + _ = PInvoke.DxcCreateInstance( + PInvoke.CLSID_DxcCompiler, + IDxcCompiler.IID_Guid, + out *(void**)dxcCompiler.GetAddressOf()).ThrowOnFailure(); + + _ = PInvoke.DxcCreateInstance( + PInvoke.CLSID_DxcLibrary, + IDxcLibrary.IID_Guid, + out *(void**)dxcLibrary.GetAddressOf()).ThrowOnFailure(); + using ComPtr dxcIncludeHandler = default; - Marshal.ThrowExceptionForHR(DirectX.DxcCreateInstance( - (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcCompiler)), - Windows.__uuidof(), - (void**)dxcCompiler.GetAddressOf())); - - Marshal.ThrowExceptionForHR(DirectX.DxcCreateInstance( - (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcLibrary)), - Windows.__uuidof(), - (void**)dxcLibrary.GetAddressOf())); - - Marshal.ThrowExceptionForHR(dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf())); + _ = dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).ThrowOnFailure(); this.dxcCompiler = new ComPtr(dxcCompiler.Get()); this.dxcLibrary = new ComPtr(dxcLibrary.Get()); @@ -90,54 +92,45 @@ internal sealed unsafe class DxcShaderCompiler // Get the encoded blob from the source code fixed (char* p = source) { - int hresult = this.dxcLibrary.Get()->CreateBlobWithEncodingOnHeapCopy( - p, - (uint)source.Length * 2, - 1200, - dxcBlobEncoding.GetAddressOf()); - - Marshal.ThrowExceptionForHR(hresult); + _ = this.dxcLibrary.Get()->CreateBlobWithEncodingOnHeapCopy( + pText: p, + size: (uint)source.Length * 2, + codePage: DXC_CP.DXC_CP_UTF16, + pBlobEncoding: dxcBlobEncoding.GetAddressOf()).ThrowOnFailure(); } token.ThrowIfCancellationRequested(); // Try to compile the new compute shader - fixed (char* shaderName = "") - fixed (char* entryPoint = nameof(IComputeShader.Execute)) - fixed (char* shaderProfile = "cs_6_0") fixed (char* optimization = "-O3") fixed (char* rowMajor = "-Zpr") fixed (char* warningsAsErrors = "-Werror") { - char** arguments = stackalloc char*[3] { optimization, rowMajor, warningsAsErrors }; + Span arguments = stackalloc PCWSTR[] { optimization, rowMajor, warningsAsErrors }; - int hresult = this.dxcCompiler.Get()->Compile( - (IDxcBlob*)dxcBlobEncoding.Get(), - (ushort*)shaderName, - (ushort*)entryPoint, - (ushort*)shaderProfile, - (ushort**)arguments, - 3, - null, - 0, - this.dxcIncludeHandler.Get(), - dxcOperationResult.GetAddressOf()); - - Marshal.ThrowExceptionForHR(hresult); + _ = this.dxcCompiler.Get()->Compile( + pSource: (IDxcBlob*)dxcBlobEncoding.Get(), + pSourceName: "", + pEntryPoint: "Execute", + pTargetProfile: "cs_6_0", + pArguments: arguments, + pDefines: ReadOnlySpan.Empty, + pIncludeHandler: this.dxcIncludeHandler.Get(), + ppResult: dxcOperationResult.GetAddressOf()).ThrowOnFailure(); } token.ThrowIfCancellationRequested(); HRESULT status; - Marshal.ThrowExceptionForHR(dxcOperationResult.Get()->GetStatus(&status)); + _ = dxcOperationResult.Get()->GetStatus(&status).ThrowOnFailure(); // The compilation was successful, so we can extract the shader bytecode if (status == 0) { using ComPtr dxcBlobBytecode = default; - Marshal.ThrowExceptionForHR(dxcOperationResult.Get()->GetResult(dxcBlobBytecode.GetAddressOf())); + _ = dxcOperationResult.Get()->GetResult(dxcBlobBytecode.GetAddressOf()).ThrowOnFailure(); byte* buffer = (byte*)dxcBlobBytecode.Get()->GetBufferPointer(); int length = checked((int)dxcBlobBytecode.Get()->GetBufferSize()); @@ -158,7 +151,7 @@ internal sealed unsafe class DxcShaderCompiler { using ComPtr dxcBlobEncodingError = default; - Marshal.ThrowExceptionForHR(dxcOperationResult->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf())); + _ = dxcOperationResult->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf()).ThrowOnFailure(); string message = new((sbyte*)dxcBlobEncodingError.Get()->GetBufferPointer()); diff --git a/src/ComputeSharp.SourceGenerators/Dxc/Interop/ComPtr{T}.cs b/src/ComputeSharp.SourceGenerators/Dxc/Interop/ComPtr{T}.cs new file mode 100644 index 00000000..c4789ba6 --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/Dxc/Interop/ComPtr{T}.cs @@ -0,0 +1,62 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from winrt/wrl/client.h in the Windows SDK for Windows 10.0.20348.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System; +using System.Runtime.CompilerServices; +using Windows.Win32.System.Com; + +namespace ComputeSharp.SourceGenerators.Dxc.Interop; + +/// A type that allows working with pointers to COM objects more securely. +/// The type to wrap in the current instance. +internal unsafe struct ComPtr : IDisposable + where T : unmanaged +{ + /// The raw pointer to a COM object, if existing. + private T* ptr; + + /// Creates a new instance from a raw pointer and increments the ref count. + /// The raw pointer to wrap. + public ComPtr(T* other) + { + this.ptr = other; + + if (other is not null) + { + _ = ((IUnknown*)other)->AddRef(); + } + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() + { + T* pointer = this.ptr; + + if (pointer is not null) + { + this.ptr = null; + + _ = ((IUnknown*)pointer)->Release(); + } + } + + /// Gets the currently wrapped raw pointer to a COM object. + /// The raw pointer wrapped by the current instance. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly T* Get() + { + return this.ptr; + } + + /// 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 T** GetAddressOf() + { + return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/NativeMethods.json b/src/ComputeSharp.SourceGenerators/NativeMethods.json new file mode 100644 index 00000000..f491f43c --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/NativeMethods.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://aka.ms/CsWin32.schema.json", + "allowMarshaling": false, + "useSafeHandles": false, + "comInterop": { + "preserveSigMethods": [ + "*" + ] + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/NativeMethods.txt b/src/ComputeSharp.SourceGenerators/NativeMethods.txt new file mode 100644 index 00000000..396fba96 --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/NativeMethods.txt @@ -0,0 +1,7 @@ +CLSID_DxcCompiler +CLSID_DxcLibrary +DxcCreateInstance +IDxcCompiler +IDxcLibrary +IDxcIncludeHandler +IUnknown \ No newline at end of file From 8730e9241c3569427f88051cbfa8904399167a05 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 17 Oct 2023 03:11:55 +0200 Subject: [PATCH 2/6] Remove leftover DXC bindings --- .../ComputeSharp.Win32.D3D12.projitems | 11 -- .../DirectX/um/dxcapi/CLSID.cs | 64 ----------- .../DirectX/um/dxcapi/DirectX.cs | 16 --- .../DirectX/um/dxcapi/DxcBuffer.cs | 17 --- .../DirectX/um/dxcapi/DxcDefine.cs | 15 --- .../DirectX/um/dxcapi/IDxcBlob.cs | 58 ---------- .../DirectX/um/dxcapi/IDxcBlobEncoding.cs | 65 ----------- .../DirectX/um/dxcapi/IDxcCompiler.cs | 63 ----------- .../DirectX/um/dxcapi/IDxcIncludeHandler.cs | 49 -------- .../DirectX/um/dxcapi/IDxcLibrary.cs | 98 ---------------- .../DirectX/um/dxcapi/IDxcOperationResult.cs | 63 ----------- .../DirectX/um/dxcapi/IDxcUtils.cs | 105 ------------------ 12 files changed, 624 deletions(-) delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DirectX.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcBuffer.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcDefine.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlob.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlobEncoding.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcCompiler.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcIncludeHandler.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcLibrary.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcOperationResult.cs delete mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcUtils.cs diff --git a/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems b/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems index c4f97da4..8c3cebd6 100644 --- a/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems +++ b/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems @@ -208,17 +208,6 @@ - - - - - - - - - - - diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs deleted file mode 100644 index 754391c8..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace TerraFX.Interop.Windows; - -internal static partial class CLSID -{ - [NativeTypeName("const CLSID")] - public static ref readonly Guid CLSID_DxcCompiler - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - ReadOnlySpan data = new byte[] { - 0x93, 0x2D, 0xE2, 0x73, - 0xCE, 0xE6, - 0xF3, 0x47, - 0xB5, - 0xBF, - 0xF0, - 0x66, - 0x4F, - 0x39, - 0xC1, - 0xB0 - }; - - Debug.Assert(data.Length == Unsafe.SizeOf()); - return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); - } - } - - [NativeTypeName("const GUID")] - public static ref readonly Guid CLSID_DxcLibrary - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - ReadOnlySpan data = new byte[] { - 0xAF, 0xD6, 0x45, 0x62, - 0xE0, 0x66, - 0xFD, 0x48, - 0x80, - 0xB4, - 0x4D, - 0x27, - 0x17, - 0x96, - 0x74, - 0x8C - }; - - Debug.Assert(data.Length == Unsafe.SizeOf()); - return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); - } - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DirectX.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DirectX.cs deleted file mode 100644 index 7da23460..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DirectX.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -internal static unsafe partial class DirectX -{ - [DllImport("dxcompiler", ExactSpelling = true)] - public static extern HRESULT DxcCreateInstance([NativeTypeName("const IID &")] Guid* rclsid, [NativeTypeName("const IID &")] Guid* riid, [NativeTypeName("LPVOID *")] void** ppv); -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcBuffer.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcBuffer.cs deleted file mode 100644 index 6cd7b2b5..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcBuffer.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -namespace TerraFX.Interop.DirectX; - -internal unsafe partial struct DxcBuffer -{ - [NativeTypeName("LPCVOID")] - public void* Ptr; - - [NativeTypeName("SIZE_T")] - public nuint Size; - - public uint Encoding; -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcDefine.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcDefine.cs deleted file mode 100644 index f2c9b9fb..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcDefine.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -namespace TerraFX.Interop.DirectX; - -internal unsafe partial struct DxcDefine -{ - [NativeTypeName("LPCWSTR")] - public ushort* Name; - - [NativeTypeName("LPCWSTR")] - public ushort* Value; -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlob.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlob.cs deleted file mode 100644 index b3f8a455..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlob.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -[Guid("8BA5FB08-5195-40E2-AC58-0D989C3A0102")] -[NativeTypeName("struct IDxcBlob : IUnknown")] -[NativeInheritance("IUnknown")] -internal unsafe partial struct IDxcBlob -{ - public void** lpVtbl; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(0)] - public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IDxcBlob*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(1)] - [return: NativeTypeName("ULONG")] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IDxcBlob*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(2)] - [return: NativeTypeName("ULONG")] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IDxcBlob*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(3)] - [return: NativeTypeName("LPVOID")] - public void* GetBufferPointer() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IDxcBlob*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(4)] - [return: NativeTypeName("SIZE_T")] - public nuint GetBufferSize() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IDxcBlob*)Unsafe.AsPointer(ref this)); - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlobEncoding.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlobEncoding.cs deleted file mode 100644 index 6c9a9df2..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcBlobEncoding.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -[Guid("7241D424-2646-4191-97C0-98E96E42FC68")] -[NativeTypeName("struct IDxcBlobEncoding : IDxcBlob")] -[NativeInheritance("IDxcBlob")] -internal unsafe partial struct IDxcBlobEncoding -{ - public void** lpVtbl; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(0)] - public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IDxcBlobEncoding*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(1)] - [return: NativeTypeName("ULONG")] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IDxcBlobEncoding*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(2)] - [return: NativeTypeName("ULONG")] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IDxcBlobEncoding*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(3)] - [return: NativeTypeName("LPVOID")] - public void* GetBufferPointer() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IDxcBlobEncoding*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(4)] - [return: NativeTypeName("SIZE_T")] - public nuint GetBufferSize() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IDxcBlobEncoding*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(5)] - public HRESULT GetEncoding(BOOL* pKnown, [NativeTypeName("UINT32 *")] uint* pCodePage) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[5]))((IDxcBlobEncoding*)Unsafe.AsPointer(ref this), pKnown, pCodePage); - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcCompiler.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcCompiler.cs deleted file mode 100644 index 996c51e9..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcCompiler.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -[Guid("8C210BF3-011F-4422-8D70-6F9ACB8DB617")] -[NativeTypeName("struct IDxcCompiler : IUnknown")] -[NativeInheritance("IUnknown")] -internal unsafe partial struct IDxcCompiler -{ - public void** lpVtbl; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(0)] - public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IDxcCompiler*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(1)] - [return: NativeTypeName("ULONG")] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IDxcCompiler*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(2)] - [return: NativeTypeName("ULONG")] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IDxcCompiler*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(3)] - public HRESULT Compile(IDxcBlob* pSource, [NativeTypeName("LPCWSTR")] ushort* pSourceName, [NativeTypeName("LPCWSTR")] ushort* pEntryPoint, [NativeTypeName("LPCWSTR")] ushort* pTargetProfile, [NativeTypeName("LPCWSTR *")] ushort** pArguments, [NativeTypeName("UINT32")] uint argCount, [NativeTypeName("const DxcDefine *")] DxcDefine* pDefines, [NativeTypeName("UINT32")] uint defineCount, IDxcIncludeHandler* pIncludeHandler, IDxcOperationResult** ppResult) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IDxcCompiler*)Unsafe.AsPointer(ref this), pSource, pSourceName, pEntryPoint, pTargetProfile, pArguments, argCount, pDefines, defineCount, pIncludeHandler, ppResult); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(4)] - public HRESULT Preprocess(IDxcBlob* pSource, [NativeTypeName("LPCWSTR")] ushort* pSourceName, [NativeTypeName("LPCWSTR *")] ushort** pArguments, [NativeTypeName("UINT32")] uint argCount, [NativeTypeName("const DxcDefine *")] DxcDefine* pDefines, [NativeTypeName("UINT32")] uint defineCount, IDxcIncludeHandler* pIncludeHandler, IDxcOperationResult** ppResult) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IDxcCompiler*)Unsafe.AsPointer(ref this), pSource, pSourceName, pArguments, argCount, pDefines, defineCount, pIncludeHandler, ppResult); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(5)] - public HRESULT Disassemble(IDxcBlob* pSource, IDxcBlobEncoding** ppDisassembly) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[5]))((IDxcCompiler*)Unsafe.AsPointer(ref this), pSource, ppDisassembly); - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcIncludeHandler.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcIncludeHandler.cs deleted file mode 100644 index fcf8edd2..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcIncludeHandler.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -[Guid("7F61FC7D-950D-467F-B3E3-3C02FB49187C")] -[NativeTypeName("struct IDxcIncludeHandler : IUnknown")] -[NativeInheritance("IUnknown")] -internal unsafe partial struct IDxcIncludeHandler -{ - public void** lpVtbl; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(0)] - public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IDxcIncludeHandler*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(1)] - [return: NativeTypeName("ULONG")] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IDxcIncludeHandler*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(2)] - [return: NativeTypeName("ULONG")] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IDxcIncludeHandler*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(3)] - public HRESULT LoadSource([NativeTypeName("LPCWSTR")] ushort* pFilename, IDxcBlob** ppIncludeSource) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IDxcIncludeHandler*)Unsafe.AsPointer(ref this), pFilename, ppIncludeSource); - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcLibrary.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcLibrary.cs deleted file mode 100644 index b59b9ead..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcLibrary.cs +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -[Guid("E5204DC7-D18C-4C3C-BDFB-851673980FE7")] -[NativeTypeName("struct IDxcLibrary : IUnknown")] -[NativeInheritance("IUnknown")] -internal unsafe partial struct IDxcLibrary -{ - public void** lpVtbl; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(0)] - public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IDxcLibrary*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(1)] - [return: NativeTypeName("ULONG")] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IDxcLibrary*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(2)] - [return: NativeTypeName("ULONG")] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IDxcLibrary*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(4)] - public HRESULT CreateBlobFromBlob(IDxcBlob* pBlob, [NativeTypeName("UINT32")] uint offset, [NativeTypeName("UINT32")] uint length, IDxcBlob** ppResult) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IDxcLibrary*)Unsafe.AsPointer(ref this), pBlob, offset, length, ppResult); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(5)] - public HRESULT CreateBlobFromFile([NativeTypeName("LPCWSTR")] ushort* pFileName, [NativeTypeName("UINT32 *")] uint* codePage, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[5]))((IDxcLibrary*)Unsafe.AsPointer(ref this), pFileName, codePage, pBlobEncoding); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(6)] - public HRESULT CreateBlobWithEncodingFromPinned([NativeTypeName("LPCVOID")] void* pText, [NativeTypeName("UINT32")] uint size, [NativeTypeName("UINT32")] uint codePage, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[6]))((IDxcLibrary*)Unsafe.AsPointer(ref this), pText, size, codePage, pBlobEncoding); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(7)] - public HRESULT CreateBlobWithEncodingOnHeapCopy([NativeTypeName("LPCVOID")] void* pText, [NativeTypeName("UINT32")] uint size, [NativeTypeName("UINT32")] uint codePage, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[7]))((IDxcLibrary*)Unsafe.AsPointer(ref this), pText, size, codePage, pBlobEncoding); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(9)] - public HRESULT CreateIncludeHandler(IDxcIncludeHandler** ppResult) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[9]))((IDxcLibrary*)Unsafe.AsPointer(ref this), ppResult); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(10)] - public HRESULT CreateStreamFromBlobReadOnly(IDxcBlob* pBlob, IStream** ppStream) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[10]))((IDxcLibrary*)Unsafe.AsPointer(ref this), pBlob, ppStream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(11)] - public HRESULT GetBlobAsUtf8(IDxcBlob* pBlob, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[11]))((IDxcLibrary*)Unsafe.AsPointer(ref this), pBlob, pBlobEncoding); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(12)] - public HRESULT GetBlobAsUtf16(IDxcBlob* pBlob, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[12]))((IDxcLibrary*)Unsafe.AsPointer(ref this), pBlob, pBlobEncoding); - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcOperationResult.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcOperationResult.cs deleted file mode 100644 index 2a65379a..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcOperationResult.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -[Guid("CEDB484A-D4E9-445A-B991-CA21CA157DC2")] -[NativeTypeName("struct IDxcOperationResult : IUnknown")] -[NativeInheritance("IUnknown")] -internal unsafe partial struct IDxcOperationResult -{ - public void** lpVtbl; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(0)] - public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IDxcOperationResult*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(1)] - [return: NativeTypeName("ULONG")] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IDxcOperationResult*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(2)] - [return: NativeTypeName("ULONG")] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IDxcOperationResult*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(3)] - public HRESULT GetStatus(HRESULT* pStatus) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IDxcOperationResult*)Unsafe.AsPointer(ref this), pStatus); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(4)] - public HRESULT GetResult(IDxcBlob** ppResult) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IDxcOperationResult*)Unsafe.AsPointer(ref this), ppResult); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(5)] - public HRESULT GetErrorBuffer(IDxcBlobEncoding** ppErrors) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[5]))((IDxcOperationResult*)Unsafe.AsPointer(ref this), ppErrors); - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcUtils.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcUtils.cs deleted file mode 100644 index 111d7be7..00000000 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcUtils.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 -// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. - -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using TerraFX.Interop.Windows; - -namespace TerraFX.Interop.DirectX; - -[Guid("4605C4CB-2019-492A-ADA4-65F20BB7D67F")] -[NativeTypeName("struct IDxcUtils : IUnknown")] -[NativeInheritance("IUnknown")] -internal unsafe partial struct IDxcUtils -{ - public void** lpVtbl; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(0)] - public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IDxcUtils*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(1)] - [return: NativeTypeName("ULONG")] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IDxcUtils*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(2)] - [return: NativeTypeName("ULONG")] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IDxcUtils*)Unsafe.AsPointer(ref this)); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(3)] - public HRESULT CreateBlobFromBlob(IDxcBlob* pBlob, [NativeTypeName("UINT32")] uint offset, [NativeTypeName("UINT32")] uint length, IDxcBlob** ppResult) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IDxcUtils*)Unsafe.AsPointer(ref this), pBlob, offset, length, ppResult); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(4)] - public HRESULT CreateBlobFromPinned([NativeTypeName("LPCVOID")] void* pData, [NativeTypeName("UINT32")] uint size, [NativeTypeName("UINT32")] uint codePage, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IDxcUtils*)Unsafe.AsPointer(ref this), pData, size, codePage, pBlobEncoding); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(6)] - public HRESULT CreateBlob([NativeTypeName("LPCVOID")] void* pData, [NativeTypeName("UINT32")] uint size, [NativeTypeName("UINT32")] uint codePage, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[6]))((IDxcUtils*)Unsafe.AsPointer(ref this), pData, size, codePage, pBlobEncoding); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(7)] - public HRESULT LoadFile([NativeTypeName("LPCWSTR")] ushort* pFileName, [NativeTypeName("UINT32 *")] uint* pCodePage, IDxcBlobEncoding** pBlobEncoding) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[7]))((IDxcUtils*)Unsafe.AsPointer(ref this), pFileName, pCodePage, pBlobEncoding); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(8)] - public HRESULT CreateReadOnlyStreamFromBlob(IDxcBlob* pBlob, IStream** ppStream) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[8]))((IDxcUtils*)Unsafe.AsPointer(ref this), pBlob, ppStream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(9)] - public HRESULT CreateDefaultIncludeHandler(IDxcIncludeHandler** ppResult) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[9]))((IDxcUtils*)Unsafe.AsPointer(ref this), ppResult); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(12)] - public HRESULT GetDxilContainerPart([NativeTypeName("const DxcBuffer *")] DxcBuffer* pShader, [NativeTypeName("UINT32")] uint DxcPart, void** ppPartData, [NativeTypeName("UINT32 *")] uint* pPartSizeInBytes) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[12]))((IDxcUtils*)Unsafe.AsPointer(ref this), pShader, DxcPart, ppPartData, pPartSizeInBytes); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(13)] - public HRESULT CreateReflection([NativeTypeName("const DxcBuffer *")] DxcBuffer* pData, [NativeTypeName("const IID &")] Guid* iid, void** ppvReflection) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[13]))((IDxcUtils*)Unsafe.AsPointer(ref this), pData, iid, ppvReflection); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(15)] - public HRESULT GetPDBContents(IDxcBlob* pPDBBlob, IDxcBlob** ppHash, IDxcBlob** ppContainer) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[15]))((IDxcUtils*)Unsafe.AsPointer(ref this), pPDBBlob, ppHash, ppContainer); - } -} \ No newline at end of file From af66cb941c2c6e2ae5d3e0507565f43ea9c25f1c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 17 Oct 2023 11:45:42 +0200 Subject: [PATCH 3/6] Fix format provider in IndentedTextWriter --- .../Helpers/IndentedTextWriter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs index 37c51870..e9b26bf9 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs @@ -4,6 +4,7 @@ using System; using System.ComponentModel; +using System.Globalization; using System.Runtime.CompilerServices; using System.Text; @@ -342,7 +343,7 @@ internal sealed class IndentedTextWriter : IDisposable { if (value is IFormattable) { - this.writer.Write(((IFormattable)value).ToString(format)); + this.writer.Write(((IFormattable)value).ToString(format, CultureInfo.InvariantCulture)); } else if (value is not null) { From b8ed4c67e502259113b52aed081bb0330f7b3bad Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 17 Oct 2023 12:01:56 +0200 Subject: [PATCH 4/6] Tweak local ComPtr type for CsWin32 --- src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs | 1 - .../Dxc/{Interop => Windows.Win32}/ComPtr{T}.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) rename src/ComputeSharp.SourceGenerators/Dxc/{Interop => Windows.Win32}/ComPtr{T}.cs (97%) diff --git a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs index d3980d85..5751ffe0 100644 --- a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs @@ -2,7 +2,6 @@ using System; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using System.Threading; -using ComputeSharp.SourceGenerators.Dxc.Interop; using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.Graphics.Direct3D.Dxc; diff --git a/src/ComputeSharp.SourceGenerators/Dxc/Interop/ComPtr{T}.cs b/src/ComputeSharp.SourceGenerators/Dxc/Windows.Win32/ComPtr{T}.cs similarity index 97% rename from src/ComputeSharp.SourceGenerators/Dxc/Interop/ComPtr{T}.cs rename to src/ComputeSharp.SourceGenerators/Dxc/Windows.Win32/ComPtr{T}.cs index c4789ba6..7f6fbfc1 100644 --- a/src/ComputeSharp.SourceGenerators/Dxc/Interop/ComPtr{T}.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/Windows.Win32/ComPtr{T}.cs @@ -7,7 +7,7 @@ using System; using System.Runtime.CompilerServices; using Windows.Win32.System.Com; -namespace ComputeSharp.SourceGenerators.Dxc.Interop; +namespace Windows.Win32; /// A type that allows working with pointers to COM objects more securely. /// The type to wrap in the current instance. From 54d11f7c8f6e23fef39a9583c99c7a2231e3f92a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 17 Oct 2023 12:50:27 +0200 Subject: [PATCH 5/6] Add HRESULT.Assert() to D3D12 generator --- .../Dxc/DxcShaderCompiler.cs | 24 +++++++++---------- .../Dxc/Windows.Win32/HRESULT.cs | 21 ++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 src/ComputeSharp.SourceGenerators/Dxc/Windows.Win32/HRESULT.cs diff --git a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs index 5751ffe0..281a8794 100644 --- a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs @@ -43,19 +43,19 @@ internal sealed unsafe class DxcShaderCompiler using ComPtr dxcCompiler = default; using ComPtr dxcLibrary = default; - _ = PInvoke.DxcCreateInstance( + PInvoke.DxcCreateInstance( PInvoke.CLSID_DxcCompiler, IDxcCompiler.IID_Guid, - out *(void**)dxcCompiler.GetAddressOf()).ThrowOnFailure(); + out *(void**)dxcCompiler.GetAddressOf()).Assert(); - _ = PInvoke.DxcCreateInstance( + PInvoke.DxcCreateInstance( PInvoke.CLSID_DxcLibrary, IDxcLibrary.IID_Guid, - out *(void**)dxcLibrary.GetAddressOf()).ThrowOnFailure(); + out *(void**)dxcLibrary.GetAddressOf()).Assert(); using ComPtr dxcIncludeHandler = default; - _ = dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).ThrowOnFailure(); + dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).Assert(); this.dxcCompiler = new ComPtr(dxcCompiler.Get()); this.dxcLibrary = new ComPtr(dxcLibrary.Get()); @@ -91,11 +91,11 @@ internal sealed unsafe class DxcShaderCompiler // Get the encoded blob from the source code fixed (char* p = source) { - _ = this.dxcLibrary.Get()->CreateBlobWithEncodingOnHeapCopy( + this.dxcLibrary.Get()->CreateBlobWithEncodingOnHeapCopy( pText: p, size: (uint)source.Length * 2, codePage: DXC_CP.DXC_CP_UTF16, - pBlobEncoding: dxcBlobEncoding.GetAddressOf()).ThrowOnFailure(); + pBlobEncoding: dxcBlobEncoding.GetAddressOf()).Assert(); } token.ThrowIfCancellationRequested(); @@ -107,7 +107,7 @@ internal sealed unsafe class DxcShaderCompiler { Span arguments = stackalloc PCWSTR[] { optimization, rowMajor, warningsAsErrors }; - _ = this.dxcCompiler.Get()->Compile( + this.dxcCompiler.Get()->Compile( pSource: (IDxcBlob*)dxcBlobEncoding.Get(), pSourceName: "", pEntryPoint: "Execute", @@ -115,21 +115,21 @@ internal sealed unsafe class DxcShaderCompiler pArguments: arguments, pDefines: ReadOnlySpan.Empty, pIncludeHandler: this.dxcIncludeHandler.Get(), - ppResult: dxcOperationResult.GetAddressOf()).ThrowOnFailure(); + ppResult: dxcOperationResult.GetAddressOf()).Assert(); } token.ThrowIfCancellationRequested(); HRESULT status; - _ = dxcOperationResult.Get()->GetStatus(&status).ThrowOnFailure(); + dxcOperationResult.Get()->GetStatus(&status).Assert(); // The compilation was successful, so we can extract the shader bytecode if (status == 0) { using ComPtr dxcBlobBytecode = default; - _ = dxcOperationResult.Get()->GetResult(dxcBlobBytecode.GetAddressOf()).ThrowOnFailure(); + dxcOperationResult.Get()->GetResult(dxcBlobBytecode.GetAddressOf()).Assert(); byte* buffer = (byte*)dxcBlobBytecode.Get()->GetBufferPointer(); int length = checked((int)dxcBlobBytecode.Get()->GetBufferSize()); @@ -150,7 +150,7 @@ internal sealed unsafe class DxcShaderCompiler { using ComPtr dxcBlobEncodingError = default; - _ = dxcOperationResult->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf()).ThrowOnFailure(); + dxcOperationResult->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf()).Assert(); string message = new((sbyte*)dxcBlobEncodingError.Get()->GetBufferPointer()); diff --git a/src/ComputeSharp.SourceGenerators/Dxc/Windows.Win32/HRESULT.cs b/src/ComputeSharp.SourceGenerators/Dxc/Windows.Win32/HRESULT.cs new file mode 100644 index 00000000..357f1cf0 --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/Dxc/Windows.Win32/HRESULT.cs @@ -0,0 +1,21 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Windows.Win32.Foundation; + +/// +partial struct HRESULT +{ + /// + /// Throws a if the current value represents an error. + /// + /// Thrown if the current value represents an error. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly void Assert() + { + if (Failed) + { + throw new Win32Exception(this.Value); + } + } +} \ No newline at end of file From ac79e64e384554cbae9d1d70ccc9ffda83881b64 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 17 Oct 2023 14:31:47 +0200 Subject: [PATCH 6/6] Add workaround for Span pointer constructor bug --- .../Dxc/DxcShaderCompiler.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs index 281a8794..37636a9e 100644 --- a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using System.Threading; @@ -105,17 +106,30 @@ internal sealed unsafe class DxcShaderCompiler fixed (char* rowMajor = "-Zpr") fixed (char* warningsAsErrors = "-Werror") { - Span arguments = stackalloc PCWSTR[] { optimization, rowMajor, warningsAsErrors }; + // We can't use stackalloc here, because the portable Span type has a bug that causes + // the constructor taking a pointer to throw if T is a type that contains a pointer field. + // So we can just rent a buffer from the pool and use that instead, at least for now. + PCWSTR[] arguments = ArrayPool.Shared.Rent(3); - this.dxcCompiler.Get()->Compile( + arguments[0] = optimization; + arguments[1] = rowMajor; + arguments[2] = warningsAsErrors; + + HRESULT hresult = this.dxcCompiler.Get()->Compile( pSource: (IDxcBlob*)dxcBlobEncoding.Get(), pSourceName: "", pEntryPoint: "Execute", pTargetProfile: "cs_6_0", - pArguments: arguments, + pArguments: arguments.AsSpan(0, 3), pDefines: ReadOnlySpan.Empty, pIncludeHandler: this.dxcIncludeHandler.Get(), - ppResult: dxcOperationResult.GetAddressOf()).Assert(); + ppResult: dxcOperationResult.GetAddressOf()); + + ArrayPool.Shared.Return(arguments); + + // Only assert the HRESULT after returning the array from the pool. Since the method itself + // can return a failure but doesn't actually throw, there's no need to throw the buffer away. + hresult.Assert(); } token.ThrowIfCancellationRequested();