From c7722305ca1870b1d174507dd2e685483c0ec447 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Oct 2023 00:48:35 +0200 Subject: [PATCH] Bring back minimal DXC bindings for reflection --- .../Interop/ReflectionServices.cs | 3 -- .../ComputeSharp.Win32.D3D12.projitems | 4 ++ .../DirectX/um/dxcapi/CLSID.cs | 39 +++++++++++++++ .../DirectX/um/dxcapi/DirectX.cs | 16 ++++++ .../DirectX/um/dxcapi/DxcBuffer.cs | 17 +++++++ .../DirectX/um/dxcapi/IDxcUtils.cs | 49 +++++++++++++++++++ 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs create mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DirectX.cs create mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcBuffer.cs create mode 100644 src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcUtils.cs diff --git a/src/ComputeSharp.Dxc/Interop/ReflectionServices.cs b/src/ComputeSharp.Dxc/Interop/ReflectionServices.cs index 44d51921..da6a0120 100644 --- a/src/ComputeSharp.Dxc/Interop/ReflectionServices.cs +++ b/src/ComputeSharp.Dxc/Interop/ReflectionServices.cs @@ -4,9 +4,6 @@ using ComputeSharp.Core.Extensions; using ComputeSharp.Descriptors; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; -#if !NET6_0_OR_GREATER -using DirectX = TerraFX.Interop.DirectX.DirectX2; -#endif namespace ComputeSharp.Interop; diff --git a/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems b/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems index 8c3cebd6..69456bce 100644 --- a/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems +++ b/src/ComputeSharp.Win32.D3D12/ComputeSharp.Win32.D3D12.projitems @@ -208,6 +208,10 @@ + + + + diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs new file mode 100644 index 00000000..56a14f6f --- /dev/null +++ b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs @@ -0,0 +1,39 @@ +// 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 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 new file mode 100644 index 00000000..7da23460 --- /dev/null +++ b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DirectX.cs @@ -0,0 +1,16 @@ +// 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 new file mode 100644 index 00000000..6cd7b2b5 --- /dev/null +++ b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/DxcBuffer.cs @@ -0,0 +1,17 @@ +// 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/IDxcUtils.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcUtils.cs new file mode 100644 index 00000000..097df146 --- /dev/null +++ b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/IDxcUtils.cs @@ -0,0 +1,49 @@ +// 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(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); + } +} \ No newline at end of file