From c6df0fc6ae42734bf791b1e3355f4a056ea84351 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 2 Nov 2021 23:46:18 +0100 Subject: [PATCH 1/7] Updated TerraFX and D3D12MA packages --- Directory.Build.props | 3 +++ .../Backend/Win32ApplicationRunner.cs | 16 ++++++++-------- src/ComputeSharp/ComputeSharp.csproj | 2 +- .../Extensions/Interop/HResultExtensions.cs | 13 ++++++++++++- .../Shaders/Translation/ShaderCompiler.cs | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 7169705b..a90caba2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,5 +6,8 @@ true Sergio Pedri Copyright (c) 2021 Sergio Pedri + + https://pkgs.terrafx.dev/index.json; + \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 833cddf3..8f301650 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -51,7 +51,7 @@ internal unsafe static class Win32ApplicationRunner { Win32ApplicationRunner.application = application; - IntPtr hInstance = Windows.GetModuleHandleW(null); + HMODULE hInstance = Windows.GetModuleHandleW(null); fixed (char* name = Assembly.GetExecutingAssembly().FullName) fixed (char* windowTitle = application.GetType().ToString()) @@ -61,9 +61,9 @@ internal unsafe static class Win32ApplicationRunner { cbSize = (uint)sizeof(WNDCLASSEXW), style = Windows.CS_HREDRAW | Windows.CS_VREDRAW, - lpfnWndProc = &WindowProc, + lpfnWndProc = (delegate* unmanaged)(delegate* unmanaged)&WindowProc, hInstance = hInstance, - hCursor = Windows.LoadCursorW(IntPtr.Zero, Windows.IDC_ARROW), + hCursor = Windows.LoadCursorW(HINSTANCE.NULL, Windows.IDC_ARROW), lpszClassName = (ushort*)name }; @@ -150,7 +150,7 @@ internal unsafe static class Win32ApplicationRunner } // Also listen to Escape and 'Q' to quit - if (msg.message == Windows.WM_KEYUP && (msg.wParam == Windows.VK_ESCAPE || msg.wParam == 'Q')) + if (msg.message == Windows.WM_KEYUP && (msg.wParam == (WPARAM)Windows.VK_ESCAPE || msg.wParam == 'Q')) { _ = Windows.DestroyWindow(hwnd); } @@ -199,7 +199,7 @@ internal unsafe static class Win32ApplicationRunner if (isPaused) { - Windows.SetCapture(hwnd); + Windows.SetCapture((HWND)hwnd); } else { @@ -253,7 +253,7 @@ internal unsafe static class Win32ApplicationRunner RECT rect; _ = Windows.GetCursorPos(&point); - _ = Windows.GetWindowRect(hwnd, &rect); + _ = Windows.GetWindowRect((HWND)hwnd, &rect); bool isAtTop = Math.Abs(point.y - rect.top) < 12; bool isAtRight = Math.Abs(point.x - rect.right) < 12; @@ -300,7 +300,7 @@ internal unsafe static class Win32ApplicationRunner margins.cyTopHeight = -1; margins.cyBottomHeight = -1; - _ = Windows.DwmExtendFrameIntoClientArea(hwnd, &margins); + _ = Windows.DwmExtendFrameIntoClientArea((HWND)hwnd, &margins); return 0; } @@ -313,6 +313,6 @@ internal unsafe static class Win32ApplicationRunner } } - return Windows.DefWindowProcW(hwnd, uMsg, wParam, lParam); + return Windows.DefWindowProcW((HWND)hwnd, uMsg, wParam, lParam); } } diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 05cc80a2..223d3a4e 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs index f29c4851..7832dfe0 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs @@ -5,7 +5,7 @@ using System.Runtime.CompilerServices; using ComputeSharp.Graphics.Helpers; #endif using Microsoft.Toolkit.Diagnostics; -using HRESULT = System.Int32; +using TerraFX.Interop; namespace ComputeSharp.Core.Extensions; @@ -22,6 +22,17 @@ internal static class HResultExtensions /// Thrown if represents an error. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Assert(this HRESULT result) + { + Assert((int)result); + } + + /// + /// Throws a if represents an error. + /// + /// The input to check. + /// Thrown if represents an error. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Assert(this int result) { #if DEBUG bool hasErrorsOrWarnings = DeviceHelper.FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings(); diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs index 03d22b81..92432853 100644 --- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs @@ -116,7 +116,7 @@ internal sealed unsafe partial class ShaderCompiler dxcOperationResult.GetAddressOf()).Assert(); } - int status; + HRESULT status; dxcOperationResult.Get()->GetStatus(&status).Assert(); From 702b880b89e365f0596fc668087932d38236dbe6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 3 Nov 2021 00:08:04 +0100 Subject: [PATCH 2/7] Removed ReferenceCountPtr and UniquePtr types --- .../Extensions/Interop/AllocatorExtensions.cs | 23 ++- .../Extensions/Interop/ComPtrExtensions.cs | 44 ++++++ .../Interop/ID3D12DeviceExtensions.cs | 4 +- src/ComputeSharp/Graphics/GraphicsDevice.cs | 8 +- .../Graphics/Interop/ReferenceCountPtr{T}.cs | 132 ------------------ .../Graphics/Interop/UniquePtr{T}.cs | 112 --------------- .../Graphics/Resources/Abstract/Buffer{T}.cs | 2 +- .../Resources/Abstract/StructuredBuffer{T}.cs | 5 +- .../Resources/Abstract/Texture2D{T}.cs | 6 +- .../Resources/Abstract/Texture3D{T}.cs | 6 +- .../Resources/Abstract/TransferBuffer{T}.cs | 2 +- .../Abstract/TransferTexture2D{T}.cs | 2 +- .../Abstract/TransferTexture3D{T}.cs | 2 +- 13 files changed, 73 insertions(+), 275 deletions(-) delete mode 100644 src/ComputeSharp/Graphics/Interop/ReferenceCountPtr{T}.cs delete mode 100644 src/ComputeSharp/Graphics/Interop/UniquePtr{T}.cs diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs index 95dffd84..aa1fbfa0 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs @@ -1,5 +1,4 @@ using ComputeSharp.Core.Extensions; -using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; using TerraFX.Interop; using static TerraFX.Interop.D3D12_CPU_PAGE_PROPERTY; @@ -22,9 +21,9 @@ internal static unsafe class AllocatorExtensions /// /// The instance in use. /// A instance suited to be used for cache coherent UMA devices. - public static ReferenceCountPtr CreatePoolForCacheCoherentUMA(this ref D3D12MA_Allocator allocator) + public static ComPtr CreatePoolForCacheCoherentUMA(this ref D3D12MA_Allocator allocator) { - using ReferenceCountPtr pool = default; + using ComPtr pool = default; D3D12MA_POOL_DESC poolDesc = default; poolDesc.HeapProperties.CreationNodeMask = 1; @@ -46,8 +45,8 @@ internal static unsafe class AllocatorExtensions /// The resource type currently in use. /// The allocation mode to use for the new resource. /// The size in bytes of the current buffer. - /// An reference for the current object. - public static UniquePtr CreateResource( + /// An reference for the current object. + public static ComPtr CreateResource( this ref D3D12MA_Allocator allocator, D3D12MA_Pool* pool, ResourceType resourceType, @@ -67,7 +66,7 @@ internal static unsafe class AllocatorExtensions _ => ThrowHelper.ThrowArgumentException<(D3D12_HEAP_TYPE, D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>() }; - using UniquePtr allocation = default; + using ComPtr allocation = default; D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Buffer(sizeInBytes, d3D12ResourceFlags); @@ -99,8 +98,8 @@ internal static unsafe class AllocatorExtensions /// The width of the texture resource. /// The height of the texture resource. /// The default value for the resource. - /// An reference for the current object. - public static UniquePtr CreateResource( + /// An reference for the current object. + public static ComPtr CreateResource( this ref D3D12MA_Allocator allocator, D3D12MA_Pool* pool, ResourceType resourceType, @@ -120,7 +119,7 @@ internal static unsafe class AllocatorExtensions _ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>() }; - using UniquePtr allocation = default; + using ComPtr allocation = default; D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(dxgiFormat, width, height, mipLevels: 1, flags: d3D12ResourceFlags); @@ -153,8 +152,8 @@ internal static unsafe class AllocatorExtensions /// The height of the texture resource. /// The depth of the texture resource. /// The default value for the resource. - /// An reference for the current object. - public static UniquePtr CreateResource( + /// An reference for the current object. + public static ComPtr CreateResource( this ref D3D12MA_Allocator allocator, D3D12MA_Pool* pool, ResourceType resourceType, @@ -175,7 +174,7 @@ internal static unsafe class AllocatorExtensions _ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>() }; - using UniquePtr allocation = default; + using ComPtr allocation = default; D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(dxgiFormat, width, height, depth, mipLevels: 1, flags: d3D12ResourceFlags); diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs index 5906b523..1a87e316 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs @@ -9,6 +9,50 @@ namespace ComputeSharp.Core.Extensions; /// internal static class ComPtrExtensions { + /// + /// Invokes on the wrapped object for an input value. + /// + /// The type of the current instance. + /// The input instance to increment the reference count for. + /// A instance of type . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe uint AddRef(this ComPtr ptr) + where T : unmanaged + { + if (ptr.Get() is not null) + { + return ((IUnknown*)ptr.Get())->AddRef(); + } + + return 0; + } + + /// + /// Invokes on the wrapped object for an input value. + /// If the object has been deleted, it also resets . + /// + /// The type of the current instance. + /// The input instance to release. + /// A instance of type . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe uint Release(this ref ComPtr ptr) + where T : unmanaged + { + if (ptr.Get() is not null) + { + uint count = ((IUnknown*)ptr.Get())->Release(); + + if (count == 0) + { + ptr = default; + } + + return count; + } + + return 0; + } + /// /// Reinterprets the current instance as one of type . /// diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs index c08dfc4c..bbc772f9 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs @@ -27,9 +27,9 @@ internal static unsafe class ID3D12DeviceExtensions /// The target to use to create the allocator. /// The that was created from. /// A instance to create resources on the device in use. - public static ReferenceCountPtr CreateAllocator(this ref ID3D12Device d3D12Device, IDXGIAdapter* dxgiAdapter) + public static ComPtr CreateAllocator(this ref ID3D12Device d3D12Device, IDXGIAdapter* dxgiAdapter) { - using ReferenceCountPtr allocator = default; + using ComPtr allocator = default; D3D12MA_ALLOCATOR_DESC allocatorDesc = default; allocatorDesc.pDevice = (ID3D12Device*)Unsafe.AsPointer(ref d3D12Device); diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index 12ac2757..2970de18 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -76,12 +76,12 @@ public sealed unsafe class GraphicsDevice : NativeObject /// /// The in use associated to the current device. /// - private ReferenceCountPtr allocator; + private ComPtr allocator; /// /// The instance in use, if is . /// - private ReferenceCountPtr pool; + private ComPtr pool; /// /// Creates a new instance for the input . @@ -259,8 +259,8 @@ public sealed unsafe class GraphicsDevice : NativeObject /// internal void UnregisterAllocatedResource() { - this.pool.Dispose(); - this.allocator.Dispose(); + this.pool.Release(); + this.allocator.Release(); } /// diff --git a/src/ComputeSharp/Graphics/Interop/ReferenceCountPtr{T}.cs b/src/ComputeSharp/Graphics/Interop/ReferenceCountPtr{T}.cs deleted file mode 100644 index 0cf8d2f0..00000000 --- a/src/ComputeSharp/Graphics/Interop/ReferenceCountPtr{T}.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.ComponentModel; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using System.Threading; -using TerraFX.Interop; - -namespace ComputeSharp.Interop; - -/// -/// A -equivalent type to safely work with pointers to public APIs. -/// This special type internally keeps track of a reference count for the wrapped native object. -/// This works around the lack of internal reference counting for objects from . -/// -/// Must be either , , or . -/// -/// This type is not marked as so that it can also be used in fields, so make sure to -/// avoid copying it and disposing it multiple times, as that would lead to a access violation exceptions. -/// -internal unsafe struct ReferenceCountPtr : IDisposable - where T : unmanaged -{ - /// - /// The raw pointer to an object, if existing. - /// - private T* pointer; - - /// - /// The current reference count - 1 for . - /// - private volatile int count; - - /// - /// Creates a new instance from a raw pointer. - /// - /// The raw pointer to wrap. - public ReferenceCountPtr(T* other) - { - this.pointer = other; - this.count = 0; - } - - /// - /// Unwraps a instance and returns the internal raw pointer. - /// - /// The instance to unwrap. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator T*(ReferenceCountPtr other) - { - return other.Get(); - } - - /// - /// Increments the internal reference count. - /// - public void AddRef() - { - Interlocked.Increment(ref this.count); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dispose() - { - if (Interlocked.Decrement(ref this.count) < 0) - { - T* pointer = this.pointer; - - if (pointer != null) - { - this.pointer = null; - - if (typeof(T) == typeof(D3D12MA_Allocator)) ((D3D12MA_Allocator*)pointer)->Release(); - else if (typeof(T) == typeof(D3D12MA_Allocation)) ((D3D12MA_Allocation*)pointer)->Release(); - else if (typeof(T) == typeof(D3D12MA_Pool)) ((D3D12MA_Pool*)pointer)->Release(); - else if (typeof(T) == typeof(D3D12MA_VirtualBlock)) ((D3D12MA_VirtualBlock*)pointer)->Release(); - else throw new ArgumentException("Invalid pointer type"); - } - } - } - - /// - /// Gets the currently wrapped raw pointer to an object. - /// - /// The raw pointer wrapped by the current instance. - [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly T* Get() - { - return this.pointer; - } - - /// - /// Gets the address of the current instance as a raw double pointer. - /// - /// The raw pointer to the current instance. - /// This method is only valid when the current instance is on the stack or pinned. - [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly T** GetAddressOf() - { - return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); - } - - /// - /// Gets the address of the current instance as a managed reference to pointer. - /// - /// The reference to the current instance. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [EditorBrowsable(EditorBrowsableState.Never)] - public readonly ref T* GetPinnableReference() - { - fixed (T** ptr = &this.pointer) - { - return ref *ptr; - } - } - - /// - /// Moves the current instance and resets it without releasing the reference. - /// - /// The moved instance. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReferenceCountPtr Move() - { - ReferenceCountPtr copy = this; - - this = default; - - return copy; - } -} diff --git a/src/ComputeSharp/Graphics/Interop/UniquePtr{T}.cs b/src/ComputeSharp/Graphics/Interop/UniquePtr{T}.cs deleted file mode 100644 index f76b1fa1..00000000 --- a/src/ComputeSharp/Graphics/Interop/UniquePtr{T}.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.ComponentModel; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using TerraFX.Interop; - -namespace ComputeSharp.Interop; - -/// -/// A -equivalent type to safely work with pointers to public APIs. -/// -/// Must be either , , or . -/// -/// This type is not marked as so that it can also be used in fields, so make sure to -/// avoid copying it and disposing it multiple times, as that would lead to a access violation exceptions. -/// -internal unsafe struct UniquePtr : IDisposable - where T : unmanaged -{ - /// - /// The raw pointer to an object, if existing. - /// - private T* pointer; - - /// - /// Creates a new instance from a raw pointer. - /// - /// The raw pointer to wrap. - public UniquePtr(T* other) - { - this.pointer = other; - } - - /// - /// Unwraps a instance and returns the internal raw pointer. - /// - /// The instance to unwrap. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator T*(UniquePtr other) - { - return other.Get(); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dispose() - { - T* pointer = this.pointer; - - if (pointer != null) - { - this.pointer = null; - - if (typeof(T) == typeof(D3D12MA_Allocator)) ((D3D12MA_Allocator*)pointer)->Release(); - else if (typeof(T) == typeof(D3D12MA_Allocation)) ((D3D12MA_Allocation*)pointer)->Release(); - else if (typeof(T) == typeof(D3D12MA_Pool)) ((D3D12MA_Pool*)pointer)->Release(); - else if (typeof(T) == typeof(D3D12MA_VirtualBlock)) ((D3D12MA_VirtualBlock*)pointer)->Release(); - else throw new ArgumentException("Invalid pointer type"); - } - } - - /// - /// Gets the currently wrapped raw pointer to an object. - /// - /// The raw pointer wrapped by the current instance. - [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly T* Get() - { - return this.pointer; - } - - /// - /// Gets the address of the current instance as a raw double pointer. - /// - /// The raw pointer to the current instance. - /// This method is only valid when the current instance is on the stack or pinned. - [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly T** GetAddressOf() - { - return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); - } - - /// - /// Gets the address of the current instance as a managed reference to pointer. - /// - /// The reference to the current instance. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [EditorBrowsable(EditorBrowsableState.Never)] - public readonly ref T* GetPinnableReference() - { - fixed (T** ptr = &this.pointer) - { - return ref *ptr; - } - } - - /// - /// Moves the current instance and resets it without releasing the reference. - /// - /// The moved instance. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public UniquePtr Move() - { - UniquePtr copy = this; - - this = default; - - return copy; - } -} diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs index 034f0c6e..9a3c57e5 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs @@ -23,7 +23,7 @@ public unsafe abstract class Buffer : NativeObject /// /// The instance used to retrieve . /// - private UniquePtr allocation; + private ComPtr allocation; /// /// The instance currently mapped. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs index 4992bab5..83fd562e 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs @@ -2,7 +2,6 @@ using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Graphics.Resources.Interop; -using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; using TerraFX.Interop; using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; @@ -61,7 +60,7 @@ public abstract class StructuredBuffer : Buffer nint byteOffset = (nint)sourceOffset * sizeof(T); nint byteLength = count * sizeof(T); - using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength); + using ComPtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength); using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY)) { @@ -204,7 +203,7 @@ public abstract class StructuredBuffer : Buffer nint byteOffset = (nint)offset * sizeof(T); nint byteLength = length * sizeof(T); - using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength); + using ComPtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength); using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map()) fixed (void* sourcePointer = &source) diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs index efd1761e..57b8220d 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs @@ -28,7 +28,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper /// /// The instance used to retrieve . /// - private UniquePtr allocation; + private ComPtr allocation; /// /// The instance currently mapped. @@ -173,7 +173,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper out ulong rowSizeInBytes, out ulong totalSizeInBytes); - using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource( + using ComPtr allocation = GraphicsDevice.Allocator->CreateResource( GraphicsDevice.Pool, ResourceType.ReadBack, AllocationMode.Default, @@ -386,7 +386,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper out ulong rowSizeInBytes, out ulong totalSizeInBytes); - using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource( + using ComPtr allocation = GraphicsDevice.Allocator->CreateResource( GraphicsDevice.Pool, ResourceType.Upload, AllocationMode.Default, diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs index b2a26d23..883c180e 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs @@ -28,7 +28,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper /// /// The instance used to retrieve . /// - private UniquePtr allocation; + private ComPtr allocation; /// /// The instance currently mapped. @@ -188,7 +188,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper out ulong rowSizeInBytes, out ulong totalSizeInBytes); - using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource( + using ComPtr allocation = GraphicsDevice.Allocator->CreateResource( GraphicsDevice.Pool, ResourceType.ReadBack, AllocationMode.Default, @@ -427,7 +427,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper out ulong rowSizeInBytes, out ulong totalSizeInBytes); - using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource( + using ComPtr allocation = GraphicsDevice.Allocator->CreateResource( GraphicsDevice.Pool, ResourceType.Upload, AllocationMode.Default, diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs index 8c8ff41d..fd9ab1d9 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs @@ -20,7 +20,7 @@ public abstract unsafe class TransferBuffer : NativeObject, IMemoryOwner /// /// The instance used to retrieve . /// - private UniquePtr allocation; + private ComPtr allocation; /// /// The instance currently mapped. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs index dfa83ac1..80526093 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs @@ -20,7 +20,7 @@ public unsafe abstract class TransferTexture2D : NativeObject /// /// The instance used to retrieve . /// - private UniquePtr allocation; + private ComPtr allocation; /// /// The instance currently mapped. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs index d9bf3be6..e5a72cad 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs @@ -20,7 +20,7 @@ public unsafe abstract class TransferTexture3D : NativeObject /// /// The instance used to retrieve . /// - private UniquePtr allocation; + private ComPtr allocation; /// /// The instance currently mapped. From e17f622032c18ccdab3d5020ecb7ed6cf971ca29 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 14 Nov 2021 17:48:44 +0100 Subject: [PATCH 3/7] Bump D3D12MA to version 2.0.0-beta3.1459250354 --- .../Backend/SwapChainApplication{T}.cs | 7 +++-- .../Backend/Win32Application.cs | 2 +- .../Backend/Win32ApplicationRunner.cs | 28 +++++++++---------- src/ComputeSharp/ComputeSharp.csproj | 2 +- .../Graphics/Commands/CommandList.cs | 5 ++-- .../Commands/Interop/ID3D12CommandListPool.cs | 3 +- .../ID3D12DescriptorHandleAllocator.cs | 5 ++-- .../Graphics/Commands/PipelineData.cs | 3 +- .../Extensions/Interop/AllocatorExtensions.cs | 15 +++++----- .../Extensions/Interop/ComPtrExtensions.cs | 16 +++++------ .../Extensions/Interop/HResultExtensions.cs | 2 +- .../Interop/ID3D12DeviceExtensions.cs | 26 ++++++++--------- .../ID3D12GraphicsCommandListExtensions.cs | 2 +- .../Interop/ID3D12ResourceExtensions.cs | 2 +- src/ComputeSharp/Graphics/GraphicsDevice.cs | 11 ++++---- .../Graphics/GraphicsDeviceInfo.cs | 4 +-- .../Graphics/Helpers/D3D12FeatureHelper.cs | 5 ++-- .../Graphics/Helpers/DXGIFormatHelper.cs | 4 +-- .../Helpers/DeviceHelper.Enumerator.cs | 20 +++++++------ .../Graphics/Helpers/DeviceHelper.Factory.cs | 3 +- .../Helpers/DeviceHelper.ID3D12InfoQueue.cs | 4 +-- .../Helpers/DeviceHelper.IDXGIFactory6.cs | 14 ++++++---- .../Graphics/Helpers/DeviceHelper.cs | 20 +++++++------ .../Graphics/Helpers/WICFormatHelper.cs | 2 +- .../Graphics/Helpers/WICHelper.cs | 8 ++++-- .../__Internals/GraphicsResourceHelper.cs | 2 +- src/ComputeSharp/Graphics/Luid.cs | 2 +- .../Graphics/Resources/Abstract/Buffer{T}.cs | 9 +++--- .../Resources/Abstract/StructuredBuffer{T}.cs | 5 ++-- .../Resources/Abstract/Texture2D{T}.cs | 15 +++++----- .../Resources/Abstract/Texture3D{T}.cs | 17 +++++------ .../Resources/Abstract/TransferBuffer{T}.cs | 3 +- .../Abstract/TransferTexture2D{T}.cs | 9 +++--- .../Abstract/TransferTexture3D{T}.cs | 11 ++++---- .../Graphics/Resources/ConstantBuffer{T}.cs | 4 +-- .../Graphics/Resources/Enums/ResourceType.cs | 10 +++---- .../Resources/Interop/ID3D12ResourceMap.cs | 2 +- .../Interop/__Internals/ResourceDescriptor.cs | 6 ++-- .../Resources/ReadOnlyTexture2D{T,TPixel}.cs | 2 +- .../Resources/ReadOnlyTexture2D{T}.cs | 2 +- .../Resources/ReadOnlyTexture3D{T,TPixel}.cs | 2 +- .../Resources/ReadOnlyTexture3D{T}.cs | 2 +- .../Resources/ReadWriteTexture2D{T,TPixel}.cs | 2 +- .../Resources/ReadWriteTexture2D{T}.cs | 2 +- .../Resources/ReadWriteTexture3D{T,TPixel}.cs | 2 +- .../Resources/ReadWriteTexture3D{T}.cs | 2 +- .../ComputeShaderDispatchDataLoader.cs | 2 +- .../PixelShaderDispatchDataLoader.cs | 4 +-- .../ShaderDispatchMetadataLoader.cs | 3 +- .../Extensions/ID3D12DeviceExtensions.cs | 13 +++++---- .../Shaders/Interop/ReflectionServices.cs | 10 ++++--- src/ComputeSharp/Shaders/ShaderRunner{T}.cs | 13 +++++---- .../Translation/Models/CachedShader.cs | 3 +- .../ShaderCompiler.LibraryLoading.cs | 2 +- .../Shaders/Translation/ShaderCompiler.cs | 15 ++++++---- .../ShaderCompilerTests.cs | 3 +- .../InteropServicesTests.cs | 5 ++-- 57 files changed, 218 insertions(+), 179 deletions(-) diff --git a/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs b/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs index ea816a6e..04867578 100644 --- a/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs +++ b/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs @@ -1,6 +1,9 @@ using System; using ComputeSharp.Interop; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +#pragma warning disable CA1416 namespace ComputeSharp.SwapChain.Backend; @@ -120,7 +123,7 @@ internal sealed class SwapChainApplication : Win32Application { using ComPtr dxgiFactory2 = default; - _ = Windows.CreateDXGIFactory2(Windows.DXGI_CREATE_FACTORY_DEBUG, Windows.__uuidof(), (void**)dxgiFactory2.GetAddressOf()); + _ = DirectX.CreateDXGIFactory2(DirectX.DXGI_CREATE_FACTORY_DEBUG, Windows.__uuidof(), (void**)dxgiFactory2.GetAddressOf()); DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default; dxgiSwapChainDesc1.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_IGNORE; diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs b/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs index 2dfe60da..a097a84b 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs @@ -1,5 +1,5 @@ using System; -using TerraFX.Interop; +using TerraFX.Interop.Windows; namespace ComputeSharp.SwapChain.Backend; diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 8f301650..1f60d717 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -4,7 +4,7 @@ using System.Drawing; using System.Reflection; using System.Runtime.InteropServices; using System.Threading; -using TerraFX.Interop; +using TerraFX.Interop.Windows; namespace ComputeSharp.SwapChain.Backend; @@ -73,7 +73,7 @@ internal unsafe static class Win32ApplicationRunner Rectangle windowRect = new(0, 0, 1280, 720); // Set the target window size - _ = Windows.AdjustWindowRect((RECT*)&windowRect, Windows.WS_OVERLAPPEDWINDOW, Windows.FALSE); + _ = Windows.AdjustWindowRect((RECT*)&windowRect, WS.WS_OVERLAPPEDWINDOW, Windows.FALSE); uint height = (uint)(windowRect.Bottom - windowRect.Top); uint width = (uint)(windowRect.Right - windowRect.Left); @@ -83,7 +83,7 @@ internal unsafe static class Win32ApplicationRunner 0, windowClassEx.lpszClassName, (ushort*)windowTitle, - Windows.WS_OVERLAPPEDWINDOW, + WS.WS_OVERLAPPEDWINDOW, Windows.CW_USEDEFAULT, Windows.CW_USEDEFAULT, (int)width, @@ -137,7 +137,7 @@ internal unsafe static class Win32ApplicationRunner renderThread.Start((application, tokenSource.Token)); // Process any messages in the queue - while (msg.message != Windows.WM_QUIT) + while (msg.message != WM.WM_QUIT) { if (Windows.PeekMessageW(&msg, HWND.NULL, 0, 0, Windows.PM_REMOVE) != 0) { @@ -150,7 +150,7 @@ internal unsafe static class Win32ApplicationRunner } // Also listen to Escape and 'Q' to quit - if (msg.message == Windows.WM_KEYUP && (msg.wParam == (WPARAM)Windows.VK_ESCAPE || msg.wParam == 'Q')) + if (msg.message == WM.WM_KEYUP && (msg.wParam == (WPARAM)VK.VK_ESCAPE || msg.wParam == 'Q')) { _ = Windows.DestroyWindow(hwnd); } @@ -178,7 +178,7 @@ internal unsafe static class Win32ApplicationRunner switch (uMsg) { // Change the paused state on window activation - case Windows.WM_ACTIVATE: + case WM.WM_ACTIVATE: { if (Windows.LOWORD(wParam) == Windows.WA_INACTIVE) { @@ -192,7 +192,7 @@ internal unsafe static class Win32ApplicationRunner } // Change the paused state when ESC is pressed - case Windows.WM_KEYDOWN: + case WM.WM_KEYDOWN: { if ((ConsoleKey)wParam == ConsoleKey.Escape) { @@ -213,7 +213,7 @@ internal unsafe static class Win32ApplicationRunner } // Window resize started - case Windows.WM_ENTERSIZEMOVE: + case WM.WM_ENTERSIZEMOVE: { isResizing = true; @@ -221,7 +221,7 @@ internal unsafe static class Win32ApplicationRunner } // Window resize completed - case Windows.WM_EXITSIZEMOVE: + case WM.WM_EXITSIZEMOVE: { isResizing = false; application.OnResize(); @@ -230,7 +230,7 @@ internal unsafe static class Win32ApplicationRunner } // Size update - case Windows.WM_SIZE: + case WM.WM_SIZE: { if (!isResizing && wParam != Windows.SIZE_MINIMIZED) { @@ -241,13 +241,13 @@ internal unsafe static class Win32ApplicationRunner } // Size and position of the window (needed to enable the borderless mode) - case Windows.WM_NCCALCSIZE: + case WM.WM_NCCALCSIZE: { return 0; } // Enable dragging the window - case Windows.WM_NCHITTEST: + case WM.WM_NCHITTEST: { POINT point; RECT rect; @@ -292,7 +292,7 @@ internal unsafe static class Win32ApplicationRunner } // Restore the drop shadow - case Windows.WM_DWMCOMPOSITIONCHANGED: + case WM.WM_DWMCOMPOSITIONCHANGED: { MARGINS margins = default; margins.cxLeftWidth = -1; @@ -306,7 +306,7 @@ internal unsafe static class Win32ApplicationRunner } // Shutdown - case Windows.WM_DESTROY: + case WM.WM_DESTROY: { Windows.PostQuitMessage(0); return 0; diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 223d3a4e..66955537 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/ComputeSharp/Graphics/Commands/CommandList.cs b/src/ComputeSharp/Graphics/Commands/CommandList.cs index 37fca894..54f1c790 100644 --- a/src/ComputeSharp/Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp/Graphics/Commands/CommandList.cs @@ -1,8 +1,9 @@ using System; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE; namespace ComputeSharp.Graphics.Commands; diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs index 167282d2..cd46d8d1 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs @@ -3,7 +3,8 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Extensions; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace ComputeSharp.Graphics.Commands.Interop; diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs index 2b1df78a..ca2bbeb3 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs @@ -1,8 +1,9 @@ using System; using ComputeSharp.Graphics.Extensions; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_HEAP_TYPE; namespace ComputeSharp.Graphics.Commands.Interop; diff --git a/src/ComputeSharp/Graphics/Commands/PipelineData.cs b/src/ComputeSharp/Graphics/Commands/PipelineData.cs index 53416b0d..6d075f19 100644 --- a/src/ComputeSharp/Graphics/Commands/PipelineData.cs +++ b/src/ComputeSharp/Graphics/Commands/PipelineData.cs @@ -1,5 +1,6 @@ using ComputeSharp.Interop; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace ComputeSharp.Graphics.Commands; diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs index aa1fbfa0..4502b004 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs @@ -1,12 +1,13 @@ using ComputeSharp.Core.Extensions; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_CPU_PAGE_PROPERTY; -using static TerraFX.Interop.D3D12_HEAP_TYPE; -using static TerraFX.Interop.D3D12_MEMORY_POOL; -using static TerraFX.Interop.D3D12_RESOURCE_FLAGS; -using static TerraFX.Interop.D3D12_RESOURCE_STATES; -using static TerraFX.Interop.D3D12MA_ALLOCATION_FLAGS; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_CPU_PAGE_PROPERTY; +using static TerraFX.Interop.DirectX.D3D12_HEAP_TYPE; +using static TerraFX.Interop.DirectX.D3D12_MEMORY_POOL; +using static TerraFX.Interop.DirectX.D3D12_RESOURCE_FLAGS; +using static TerraFX.Interop.DirectX.D3D12_RESOURCE_STATES; +using static TerraFX.Interop.DirectX.D3D12MA_ALLOCATION_FLAGS; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; namespace ComputeSharp.Graphics.Extensions; diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs index 1a87e316..e589b564 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs @@ -1,6 +1,6 @@ using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; -using TerraFX.Interop; +using TerraFX.Interop.Windows; namespace ComputeSharp.Core.Extensions; @@ -17,11 +17,11 @@ internal static class ComPtrExtensions /// A instance of type . [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe uint AddRef(this ComPtr ptr) - where T : unmanaged + where T : unmanaged, IUnknown.Interface { if (ptr.Get() is not null) { - return ((IUnknown*)ptr.Get())->AddRef(); + return ptr.Get()->AddRef(); } return 0; @@ -36,11 +36,11 @@ internal static class ComPtrExtensions /// A instance of type . [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe uint Release(this ref ComPtr ptr) - where T : unmanaged + where T : unmanaged, IUnknown.Interface { if (ptr.Get() is not null) { - uint count = ((IUnknown*)ptr.Get())->Release(); + uint count = ptr.Get()->Release(); if (count == 0) { @@ -66,7 +66,7 @@ internal static class ComPtrExtensions [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe ref readonly ComPtr AsIUnknown(this in ComPtr ptr) - where T : unmanaged + where T : unmanaged, IUnknown.Interface { return ref Unsafe.As, ComPtr>(ref Unsafe.AsRef(in ptr)); } @@ -81,7 +81,7 @@ internal static class ComPtrExtensions [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe void** GetVoidAddressOf(this in ComPtr ptr) - where T : unmanaged + where T : unmanaged, IUnknown.Interface { return (void**)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr)); } @@ -94,7 +94,7 @@ internal static class ComPtrExtensions /// The moved instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe ComPtr Move(this in ComPtr ptr) - where T : unmanaged + where T : unmanaged, IUnknown.Interface { ComPtr copy = default; diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs index 7832dfe0..0c2bcadf 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/HResultExtensions.cs @@ -5,7 +5,7 @@ using System.Runtime.CompilerServices; using ComputeSharp.Graphics.Helpers; #endif using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.Windows; namespace ComputeSharp.Core.Extensions; diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs index bbc772f9..f7cc50f6 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs @@ -2,17 +2,17 @@ using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; -using ComputeSharp.Interop; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMMAND_QUEUE_FLAGS; -using static TerraFX.Interop.D3D12_COMMAND_QUEUE_PRIORITY; -using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_FLAGS; -using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE; -using static TerraFX.Interop.D3D12_FEATURE; -using static TerraFX.Interop.D3D12_FENCE_FLAGS; -using static TerraFX.Interop.D3D12_MESSAGE_ID; -using static TerraFX.Interop.D3D12_SRV_DIMENSION; -using static TerraFX.Interop.D3D12_UAV_DIMENSION; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_COMMAND_QUEUE_FLAGS; +using static TerraFX.Interop.DirectX.D3D12_COMMAND_QUEUE_PRIORITY; +using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_HEAP_FLAGS; +using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_HEAP_TYPE; +using static TerraFX.Interop.DirectX.D3D12_FEATURE; +using static TerraFX.Interop.DirectX.D3D12_FENCE_FLAGS; +using static TerraFX.Interop.DirectX.D3D12_MESSAGE_ID; +using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION; +using static TerraFX.Interop.DirectX.D3D12_UAV_DIMENSION; namespace ComputeSharp.Graphics.Extensions; @@ -176,7 +176,7 @@ internal static unsafe class ID3D12DeviceExtensions { D3D12_SHADER_RESOURCE_VIEW_DESC d3D12ShaderResourceViewDescription = default; d3D12ShaderResourceViewDescription.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; - d3D12ShaderResourceViewDescription.Shader4ComponentMapping = Windows.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + d3D12ShaderResourceViewDescription.Shader4ComponentMapping = DirectX.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; d3D12ShaderResourceViewDescription.Buffer.NumElements = bufferSize; d3D12ShaderResourceViewDescription.Buffer.StructureByteStride = elementSize; @@ -201,7 +201,7 @@ internal static unsafe class ID3D12DeviceExtensions D3D12_SHADER_RESOURCE_VIEW_DESC d3D12ShaderResourceViewDescription = default; d3D12ShaderResourceViewDescription.ViewDimension = d3D12SrvDimension; d3D12ShaderResourceViewDescription.Format = dxgiFormat; - d3D12ShaderResourceViewDescription.Shader4ComponentMapping = Windows.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + d3D12ShaderResourceViewDescription.Shader4ComponentMapping = DirectX.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; d3D12ShaderResourceViewDescription.Texture2D.MipLevels = uint.MaxValue; d3D12Device.CreateShaderResourceView(d3D12Resource, &d3D12ShaderResourceViewDescription, d3D12CpuDescriptorHandle); diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs index 25f7a512..9e52abec 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs @@ -1,5 +1,5 @@ using System; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; namespace ComputeSharp.Graphics.Extensions; diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12ResourceExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12ResourceExtensions.cs index 9a262d1a..3d46e96e 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12ResourceExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12ResourceExtensions.cs @@ -3,7 +3,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Resources.Interop; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; namespace ComputeSharp.Graphics.Extensions; diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index 2970de18..9f3947fb 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -9,11 +9,12 @@ using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; -using static TerraFX.Interop.D3D12_FEATURE; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; -using static TerraFX.Interop.DXGI_ADAPTER_FLAG; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE; +using static TerraFX.Interop.DirectX.D3D12_FEATURE; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.DXGI_ADAPTER_FLAG; namespace ComputeSharp; diff --git a/src/ComputeSharp/Graphics/GraphicsDeviceInfo.cs b/src/ComputeSharp/Graphics/GraphicsDeviceInfo.cs index 9b077b67..d66a86c5 100644 --- a/src/ComputeSharp/Graphics/GraphicsDeviceInfo.cs +++ b/src/ComputeSharp/Graphics/GraphicsDeviceInfo.cs @@ -1,5 +1,5 @@ -using TerraFX.Interop; -using static TerraFX.Interop.DXGI_ADAPTER_FLAG; +using TerraFX.Interop.DirectX; +using static TerraFX.Interop.DirectX.DXGI_ADAPTER_FLAG; namespace ComputeSharp; diff --git a/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs b/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs index f196faa7..e7188897 100644 --- a/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_FEATURE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_FEATURE; namespace ComputeSharp.Graphics.Helpers; diff --git a/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs b/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs index f9eddcfe..76081fcc 100644 --- a/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs @@ -2,8 +2,8 @@ using System.Numerics; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.DXGI_FORMAT; +using TerraFX.Interop.DirectX; +using static TerraFX.Interop.DirectX.DXGI_FORMAT; namespace ComputeSharp.Graphics.Helpers; diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs index 8c711bbf..7023875f 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs @@ -4,11 +4,13 @@ using System.Collections.Generic; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Extensions; using ComputeSharp.Interop; -using TerraFX.Interop; -using HRESULT = System.Int32; -using static TerraFX.Interop.D3D_FEATURE_LEVEL; -using static TerraFX.Interop.D3D_SHADER_MODEL; -using static TerraFX.Interop.DXGI_GPU_PREFERENCE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D_FEATURE_LEVEL; +using static TerraFX.Interop.DirectX.D3D_SHADER_MODEL; +using static TerraFX.Interop.DirectX.DXGI_GPU_PREFERENCE; + +#pragma warning disable CA1416 namespace ComputeSharp.Graphics.Helpers; @@ -129,7 +131,7 @@ internal static partial class DeviceHelper dxgiAdapter1.Get()->GetDesc1(&dxgiDescription1).Assert(); - HRESULT createDeviceResult = Windows.D3D12CreateDevice( + HRESULT createDeviceResult = DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), @@ -140,7 +142,7 @@ internal static partial class DeviceHelper { using ComPtr d3D12Device = default; - Windows.D3D12CreateDevice( + DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), @@ -170,7 +172,7 @@ internal static partial class DeviceHelper continue; } - HRESULT createDeviceResult = Windows.D3D12CreateDevice( + HRESULT createDeviceResult = DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), @@ -181,7 +183,7 @@ internal static partial class DeviceHelper { using ComPtr d3D12Device = default; - Windows.D3D12CreateDevice( + DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs index 992c8152..eb8d0c48 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs @@ -2,7 +2,8 @@ #if DEBUG using ComputeSharp.Graphics.Extensions; #endif -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace ComputeSharp.Graphics.Helpers; diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs index 4884f5ca..4bab8ef4 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs @@ -4,8 +4,8 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_MESSAGE_SEVERITY; +using TerraFX.Interop.DirectX; +using static TerraFX.Interop.DirectX.D3D12_MESSAGE_SEVERITY; namespace ComputeSharp.Graphics.Helpers; diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs index d3c3493c..74fbccd8 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs @@ -3,8 +3,10 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.Core.Extensions; -using TerraFX.Interop; -using HRESULT = System.Int32; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +#pragma warning disable CA1416 namespace ComputeSharp.Graphics.Helpers; @@ -16,7 +18,7 @@ internal static partial class DeviceHelper /// private const uint IDXGIFactoryCreationFlags = #if DEBUG - Windows.DXGI_CREATE_FACTORY_DEBUG; + DirectX.DXGI_CREATE_FACTORY_DEBUG; #else 0; #endif @@ -31,7 +33,7 @@ internal static partial class DeviceHelper EnableDebugMode(); - Windows.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof(), dxgiFactory4.GetVoidAddressOf()).Assert(); + DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof(), dxgiFactory4.GetVoidAddressOf()).Assert(); HRESULT result = dxgiFactory4.CopyTo(dxgiFactory6); @@ -40,7 +42,7 @@ internal static partial class DeviceHelper return; } - if (result == Windows.E_NOINTERFACE) + if (result == E.E_NOINTERFACE) { IDXGIFactory4As6Backcompat.Create(dxgiFactory4.Get(), dxgiFactory6); @@ -61,7 +63,7 @@ internal static partial class DeviceHelper using ComPtr d3D12Debug = default; using ComPtr d3D12Debug1 = default; - Windows.D3D12GetDebugInterface(Windows.__uuidof(), d3D12Debug.GetVoidAddressOf()).Assert(); + DirectX.D3D12GetDebugInterface(Windows.__uuidof(), d3D12Debug.GetVoidAddressOf()).Assert(); d3D12Debug.Get()->EnableDebugLayer(); diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs index ecd4383b..353497f6 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs @@ -3,11 +3,13 @@ using System.Diagnostics.Contracts; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Extensions; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using HRESULT = System.Int32; -using static TerraFX.Interop.D3D_FEATURE_LEVEL; -using static TerraFX.Interop.D3D_SHADER_MODEL; -using static TerraFX.Interop.DXGI_GPU_PREFERENCE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D_FEATURE_LEVEL; +using static TerraFX.Interop.DirectX.D3D_SHADER_MODEL; +using static TerraFX.Interop.DirectX.DXGI_GPU_PREFERENCE; + +#pragma warning disable CA1416 namespace ComputeSharp.Graphics.Helpers; @@ -119,7 +121,7 @@ internal static partial class DeviceHelper // a device for adapters that would've failed at the FL11 check already. if (d3D12Device == null) { - HRESULT createDeviceResult = Windows.D3D12CreateDevice( + HRESULT createDeviceResult = DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), @@ -129,7 +131,7 @@ internal static partial class DeviceHelper { using ComPtr d3D12DeviceCandidate = default; - createDeviceResult = Windows.D3D12CreateDevice( + createDeviceResult = DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), @@ -146,7 +148,7 @@ internal static partial class DeviceHelper { using ComPtr d3D12DeviceCandidate = default; - HRESULT createDeviceResult = Windows.D3D12CreateDevice( + HRESULT createDeviceResult = DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), @@ -183,7 +185,7 @@ internal static partial class DeviceHelper dxgiAdapter1.Get()->GetDesc1(dxgiDescription1).Assert(); - HRESULT createDeviceResult = Windows.D3D12CreateDevice( + HRESULT createDeviceResult = DirectX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), diff --git a/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs b/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs index 96c44060..cf75c4b1 100644 --- a/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs @@ -3,7 +3,7 @@ using System.Diagnostics.Contracts; using System.IO; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.Windows; namespace ComputeSharp.Graphics.Helpers; diff --git a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs index 6b321c7c..1090d5bb 100644 --- a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs @@ -1,7 +1,10 @@ using System; using System.Diagnostics.Contracts; +using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; -using TerraFX.Interop; +using TerraFX.Interop.Windows; + +#pragma warning disable CA1416 namespace ComputeSharp.Graphics.Helpers; @@ -21,10 +24,9 @@ internal sealed unsafe class WICHelper private WICHelper() { using ComPtr wicImagingFactory2 = default; - Guid wicImagingFactor2Clsid = Windows.CLSID_WICImagingFactory2; Windows.CoCreateInstance( - &wicImagingFactor2Clsid, + (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_WICImagingFactory2)), null, (uint)CLSCTX.CLSCTX_INPROC_SERVER, Windows.__uuidof(), diff --git a/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs b/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs index 89a703f2..fb40d83b 100644 --- a/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/__Internals/GraphicsResourceHelper.cs @@ -3,7 +3,7 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using ComputeSharp.Resources; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; namespace ComputeSharp.__Internals; diff --git a/src/ComputeSharp/Graphics/Luid.cs b/src/ComputeSharp/Graphics/Luid.cs index 89db2015..7eccacb2 100644 --- a/src/ComputeSharp/Graphics/Luid.cs +++ b/src/ComputeSharp/Graphics/Luid.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; -using TerraFX.Interop; +using TerraFX.Interop.Windows; namespace ComputeSharp; diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs index 9a3c57e5..0a361b06 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs @@ -7,8 +7,9 @@ using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_FEATURE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_FEATURE; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; namespace ComputeSharp.Resources; @@ -59,7 +60,7 @@ public unsafe abstract class Buffer : NativeObject if (resourceType == ResourceType.Constant) { - Guard.IsBetweenOrEqualTo(length, 1, Windows.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT, nameof(length)); + Guard.IsBetweenOrEqualTo(length, 1, DirectX.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT, nameof(length)); } else { @@ -74,7 +75,7 @@ public unsafe abstract class Buffer : NativeObject } nint usableSizeInBytes = checked((nint)(length * elementSizeInBytes)); - nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, Windows.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes; + nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, DirectX.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes; SizeInBytes = usableSizeInBytes; GraphicsDevice = device; diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs index 83fd562e..e510e336 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs @@ -3,8 +3,9 @@ using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Graphics.Resources.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; namespace ComputeSharp.Resources; diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs index 57b8220d..8b47d9a2 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs @@ -7,11 +7,12 @@ using ComputeSharp.Graphics.Helpers; using ComputeSharp.Graphics.Resources.Interop; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; -using static TerraFX.Interop.D3D12_RESOURCE_STATES; -using static TerraFX.Interop.D3D12_SRV_DIMENSION; -using static TerraFX.Interop.D3D12_UAV_DIMENSION; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE; +using static TerraFX.Interop.DirectX.D3D12_RESOURCE_STATES; +using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION; +using static TerraFX.Interop.DirectX.D3D12_UAV_DIMENSION; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; #pragma warning disable CS0618 @@ -73,8 +74,8 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, Windows.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, Windows.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), d3D12FormatSupport)) { diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs index 883c180e..c8d8b1ea 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs @@ -7,11 +7,12 @@ using ComputeSharp.Graphics.Helpers; using ComputeSharp.Graphics.Resources.Interop; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; -using static TerraFX.Interop.D3D12_RESOURCE_STATES; -using static TerraFX.Interop.D3D12_SRV_DIMENSION; -using static TerraFX.Interop.D3D12_UAV_DIMENSION; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE; +using static TerraFX.Interop.DirectX.D3D12_RESOURCE_STATES; +using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION; +using static TerraFX.Interop.DirectX.D3D12_UAV_DIMENSION; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; #pragma warning disable CS0618 @@ -74,9 +75,9 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, Windows.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, Windows.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); - Guard.IsBetweenOrEqualTo(depth, 1, Windows.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); + Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(depth, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), d3D12FormatSupport)) { diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs index fd9ab1d9..00ff3ae7 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs @@ -5,7 +5,8 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Extensions; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; namespace ComputeSharp.Resources; diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs index 80526093..169811b3 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs @@ -4,8 +4,9 @@ using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; namespace ComputeSharp.Resources; @@ -49,8 +50,8 @@ public unsafe abstract class TransferTexture2D : NativeObject { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, Windows.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, Windows.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), D3D12_FORMAT_SUPPORT1_TEXTURE2D)) { diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs index e5a72cad..c137340d 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs @@ -4,8 +4,9 @@ using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; namespace ComputeSharp.Resources; @@ -50,9 +51,9 @@ public unsafe abstract class TransferTexture3D : NativeObject { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, Windows.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, Windows.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); - Guard.IsBetweenOrEqualTo(depth, 1, Windows.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); + Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(depth, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), D3D12_FORMAT_SUPPORT1_TEXTURE3D)) { diff --git a/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs index 38aa3b47..beb59215 100644 --- a/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs @@ -9,7 +9,7 @@ using ComputeSharp.Graphics.Resources.Interop; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; namespace ComputeSharp; @@ -26,7 +26,7 @@ public sealed class ConstantBuffer : Buffer /// /// The alignment boundary for elements in a constant buffer. /// - private const int ElementAlignment = Windows.D3D12_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT; + private const int ElementAlignment = DirectX.D3D12_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT; /// /// Creates a new instance with the specified parameters. diff --git a/src/ComputeSharp/Graphics/Resources/Enums/ResourceType.cs b/src/ComputeSharp/Graphics/Resources/Enums/ResourceType.cs index 4dadf0c1..3c61b131 100644 --- a/src/ComputeSharp/Graphics/Resources/Enums/ResourceType.cs +++ b/src/ComputeSharp/Graphics/Resources/Enums/ResourceType.cs @@ -8,35 +8,35 @@ internal enum ResourceType /// /// A constant resource, with items aligned to 16 bytes, used for individual values or very small arrays. /// This is only supported for buffers and is mapped to a . - /// Resources of this type are located in . + /// Resources of this type are located in . /// Constant, /// /// A readonly resource, that can store arbitrary arrays of values and can only be read from by the GPU. /// This is mapped to either or . - /// Resources of this type are located in . + /// Resources of this type are located in . /// ReadOnly, /// /// A read write resource, that can store arbitrary arrays with both read and write access for the GPU. /// This is mapped to either or . - /// Resources of this type are located in . + /// Resources of this type are located in . /// ReadWrite, /// /// A readback resource, used temporarily to read data back from and resources. /// This has no direct mapping to a type in HLSL, as it's only used for copy operations. - /// Resources of this type are located in . + /// Resources of this type are located in . /// ReadBack, /// /// A transfer resource, used temporarily to set data to and resources. /// This has no direct mapping to a type in HLSL, as it's only used for copy operations (like ). - /// Resources of this type are located in . + /// Resources of this type are located in . /// Upload } diff --git a/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs b/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs index 17732cd2..e5b71cfb 100644 --- a/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs +++ b/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.CompilerServices; using ComputeSharp.Graphics.Extensions; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; namespace ComputeSharp.Graphics.Resources.Interop; diff --git a/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs b/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs index 028f3613..da04ea73 100644 --- a/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs +++ b/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs @@ -1,7 +1,7 @@ using System; using System.ComponentModel; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_DESCRIPTOR_RANGE_FLAGS; +using TerraFX.Interop.DirectX; +using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_RANGE_FLAGS; #pragma warning disable IDE0052, CS0414 @@ -45,6 +45,6 @@ public struct ResourceDescriptor descriptor.BaseShaderRegister = offset; descriptor.RegisterSpace = 0; descriptor.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE; - descriptor.OffsetInDescriptorsFromTableStart = Windows.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND; + descriptor.OffsetInDescriptorsFromTableStart = DirectX.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND; } } diff --git a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs index a3a6d81d..2e8ec3e4 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs @@ -4,7 +4,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; #pragma warning disable CS0618 diff --git a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T}.cs index f2f71afc..a59b1919 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture2D{T}.cs @@ -3,7 +3,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; namespace ComputeSharp; diff --git a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs index a5c64fef..a97300b5 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs @@ -4,7 +4,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; #pragma warning disable CS0618 diff --git a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T}.cs index 2a5fc5a9..9d7082b7 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T}.cs @@ -3,7 +3,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; namespace ComputeSharp; diff --git a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs index 96aadf00..09472c1e 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs @@ -4,7 +4,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; #pragma warning disable CS0618 diff --git a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T}.cs index 617863b5..f341e786 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture2D{T}.cs @@ -3,7 +3,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; namespace ComputeSharp; diff --git a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs index 27d6e2a0..25765ebe 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs @@ -4,7 +4,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; #pragma warning disable CS0618 diff --git a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T}.cs index af759c96..1e5e6f89 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture3D{T}.cs @@ -3,7 +3,7 @@ using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Resources.Enums; using ComputeSharp.Resources; using ComputeSharp.Resources.Debug; -using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; namespace ComputeSharp; diff --git a/src/ComputeSharp/Shaders/Dispatching/ComputeShaderDispatchDataLoader.cs b/src/ComputeSharp/Shaders/Dispatching/ComputeShaderDispatchDataLoader.cs index e7e70812..b565ad62 100644 --- a/src/ComputeSharp/Shaders/Dispatching/ComputeShaderDispatchDataLoader.cs +++ b/src/ComputeSharp/Shaders/Dispatching/ComputeShaderDispatchDataLoader.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using ComputeSharp.Graphics.Extensions; using ComputeSharp.__Internals; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; using System.Runtime.InteropServices; #pragma warning disable CS0618 diff --git a/src/ComputeSharp/Shaders/Dispatching/PixelShaderDispatchDataLoader.cs b/src/ComputeSharp/Shaders/Dispatching/PixelShaderDispatchDataLoader.cs index 6bc27fb7..2c8792e0 100644 --- a/src/ComputeSharp/Shaders/Dispatching/PixelShaderDispatchDataLoader.cs +++ b/src/ComputeSharp/Shaders/Dispatching/PixelShaderDispatchDataLoader.cs @@ -1,9 +1,9 @@ using System; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using ComputeSharp.Graphics.Extensions; using ComputeSharp.__Internals; -using TerraFX.Interop; -using System.Runtime.InteropServices; +using TerraFX.Interop.DirectX; #pragma warning disable CS0618 diff --git a/src/ComputeSharp/Shaders/Dispatching/ShaderDispatchMetadataLoader.cs b/src/ComputeSharp/Shaders/Dispatching/ShaderDispatchMetadataLoader.cs index 9f56d2ce..4dc6de76 100644 --- a/src/ComputeSharp/Shaders/Dispatching/ShaderDispatchMetadataLoader.cs +++ b/src/ComputeSharp/Shaders/Dispatching/ShaderDispatchMetadataLoader.cs @@ -4,7 +4,8 @@ using System.Runtime.InteropServices; using ComputeSharp.Shaders.Extensions; using ComputeSharp.__Internals; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; #pragma warning disable CS0618 diff --git a/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs index a5979b2c..122ad5c9 100644 --- a/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs @@ -1,10 +1,11 @@ using System; using ComputeSharp.Core.Extensions; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMPARISON_FUNC; -using static TerraFX.Interop.D3D12_FILTER; -using static TerraFX.Interop.D3D12_PIPELINE_STATE_FLAGS; -using static TerraFX.Interop.D3D12_TEXTURE_ADDRESS_MODE; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_COMPARISON_FUNC; +using static TerraFX.Interop.DirectX.D3D12_FILTER; +using static TerraFX.Interop.DirectX.D3D12_PIPELINE_STATE_FLAGS; +using static TerraFX.Interop.DirectX.D3D12_TEXTURE_ADDRESS_MODE; namespace ComputeSharp.Shaders.Extensions; @@ -71,7 +72,7 @@ internal static unsafe class ID3D12DeviceExtensions // Serialize the root signature from the data just computed. When this is done // we just work with the resulting blobs, so the input data can be unpinned. - Windows.D3D12SerializeVersionedRootSignature( + DirectX.D3D12SerializeVersionedRootSignature( &d3D12VersionedRootSignatureDescription, d3D3Blob.GetAddressOf(), d3D3BlobError.GetAddressOf()).Assert(); diff --git a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs index d7b6c39c..2d9467c4 100644 --- a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs +++ b/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs @@ -3,7 +3,8 @@ using System.Runtime.CompilerServices; using ComputeSharp.__Internals; using ComputeSharp.Core.Extensions; using ComputeSharp.Shaders.Translation; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; #pragma warning disable CS0618 @@ -109,9 +110,10 @@ public static class ReflectionServices using ComPtr dxcUtils = default; - Guid dxcLibraryClsid = Windows.CLSID_DxcLibrary; - - Windows.DxcCreateInstance(&dxcLibraryClsid, Windows.__uuidof(), dxcUtils.GetVoidAddressOf()).Assert(); + DirectX.DxcCreateInstance( + (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcLibrary)), + Windows.__uuidof(), + dxcUtils.GetVoidAddressOf()).Assert(); using ComPtr d3D12ShaderReflection = default; diff --git a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs index 58bb4df9..0619fcf8 100644 --- a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs @@ -8,7 +8,8 @@ using ComputeSharp.Shaders.Translation; using ComputeSharp.Shaders.Translation.Models; using ComputeSharp.__Internals; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; #pragma warning disable CS0618 @@ -118,9 +119,9 @@ internal static class ShaderRunner int groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1); int groupsZ = Math.DivRem(z, threadsZ, out int modZ) + (modZ == 0 ? 0 : 1); - Guard.IsBetweenOrEqualTo(groupsX, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); - Guard.IsBetweenOrEqualTo(groupsY, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); - Guard.IsBetweenOrEqualTo(groupsZ, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsX, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsY, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsZ, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); ShaderKey key = new(shader.GetDispatchId(), threadsX, threadsY, threadsZ); PipelineData? pipelineData; @@ -173,8 +174,8 @@ internal static class ShaderRunner int groupsX = Math.DivRem(x, threadsX, out int modX) + (modX == 0 ? 0 : 1); int groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1); - Guard.IsBetweenOrEqualTo(groupsX, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); - Guard.IsBetweenOrEqualTo(groupsY, 1, Windows.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsX, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsY, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); ShaderKey key = new(shader.GetDispatchId(), threadsX, threadsY, 1); PipelineData? pipelineData; diff --git a/src/ComputeSharp/Shaders/Translation/Models/CachedShader.cs b/src/ComputeSharp/Shaders/Translation/Models/CachedShader.cs index 1144b691..2afec884 100644 --- a/src/ComputeSharp/Shaders/Translation/Models/CachedShader.cs +++ b/src/ComputeSharp/Shaders/Translation/Models/CachedShader.cs @@ -1,7 +1,8 @@ using System.Runtime.CompilerServices; using ComputeSharp.Graphics.Commands; using ComputeSharp.Interop; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace ComputeSharp.Shaders.Translation.Models; diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs index b0ee3aae..64e4bd3a 100644 --- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs +++ b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs @@ -2,7 +2,7 @@ using System.IO; using System.Runtime.InteropServices; using Microsoft.Toolkit.Diagnostics; -using TerraFX.Interop; +using TerraFX.Interop.Windows; namespace ComputeSharp.Shaders.Translation; diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs index 92432853..21da886d 100644 --- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs @@ -3,7 +3,8 @@ using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; using ComputeSharp.Exceptions; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace ComputeSharp.Shaders.Translation; @@ -43,11 +44,15 @@ internal sealed unsafe partial class ShaderCompiler using ComPtr dxcLibrary = default; using ComPtr dxcIncludeHandler = default; - Guid dxcCompilerCLGuid = Windows.CLSID_DxcCompiler; - Guid dxcLibraryCLGuid = Windows.CLSID_DxcLibrary; + DirectX.DxcCreateInstance( + (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcCompiler)), + Windows.__uuidof(), + dxcCompiler.GetVoidAddressOf()).Assert(); - Windows.DxcCreateInstance(&dxcCompilerCLGuid, Windows.__uuidof(), dxcCompiler.GetVoidAddressOf()).Assert(); - Windows.DxcCreateInstance(&dxcLibraryCLGuid, Windows.__uuidof(), dxcLibrary.GetVoidAddressOf()).Assert(); + DirectX.DxcCreateInstance( + (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcLibrary)), + Windows.__uuidof(), + dxcLibrary.GetVoidAddressOf()).Assert(); dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).Assert(); diff --git a/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs index 8a38c67a..4e487777 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs @@ -1,7 +1,8 @@ using ComputeSharp.Exceptions; using ComputeSharp.Shaders.Translation; using Microsoft.VisualStudio.TestTools.UnitTesting; -using TerraFX.Interop; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace ComputeSharp.Tests.Internals; diff --git a/tests/ComputeSharp.Tests/InteropServicesTests.cs b/tests/ComputeSharp.Tests/InteropServicesTests.cs index cc163ea1..bfc9a13c 100644 --- a/tests/ComputeSharp.Tests/InteropServicesTests.cs +++ b/tests/ComputeSharp.Tests/InteropServicesTests.cs @@ -4,8 +4,9 @@ using ComputeSharp.Resources; using ComputeSharp.Tests.Attributes; using ComputeSharp.Tests.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; -using TerraFX.Interop; -using static TerraFX.Interop.D3D12_RESOURCE_DIMENSION; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using static TerraFX.Interop.DirectX.D3D12_RESOURCE_DIMENSION; namespace ComputeSharp.Tests; From 87343a313762a065cd37c6446a8b6448eb9a8868 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 15 Nov 2021 19:39:33 +0100 Subject: [PATCH 4/7] Bump D3D12MA to version 2.0.0-beta3.1463073211 --- .../Backend/SwapChainApplication{T}.cs | 2 +- .../Backend/Win32ApplicationRunner.cs | 6 +- src/ComputeSharp/ComputeSharp.csproj | 2 +- .../Interop/ID3D12DeviceExtensions.cs | 4 +- .../Graphics/Helpers/D3D12FeatureHelper.cs | 2 +- .../Helpers/DeviceHelper.Enumerator.cs | 2 +- .../Helpers/DeviceHelper.IDXGIFactory6.cs | 4 +- .../Graphics/Helpers/DeviceHelper.cs | 2 +- .../Graphics/Helpers/WICFormatHelper.cs | 66 +++++++++---------- .../Graphics/Resources/Abstract/Buffer{T}.cs | 4 +- .../Resources/Abstract/Texture2D{T}.cs | 4 +- .../Resources/Abstract/Texture3D{T}.cs | 6 +- .../Abstract/TransferTexture2D{T}.cs | 4 +- .../Abstract/TransferTexture3D{T}.cs | 6 +- .../Graphics/Resources/ConstantBuffer{T}.cs | 2 +- .../Interop/__Internals/ResourceDescriptor.cs | 2 +- src/ComputeSharp/Shaders/ShaderRunner{T}.cs | 10 +-- .../InteropServicesTests.cs | 14 ++-- 18 files changed, 71 insertions(+), 71 deletions(-) diff --git a/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs b/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs index 04867578..db765d50 100644 --- a/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs +++ b/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication{T}.cs @@ -123,7 +123,7 @@ internal sealed class SwapChainApplication : Win32Application { using ComPtr dxgiFactory2 = default; - _ = DirectX.CreateDXGIFactory2(DirectX.DXGI_CREATE_FACTORY_DEBUG, Windows.__uuidof(), (void**)dxgiFactory2.GetAddressOf()); + _ = DirectX.CreateDXGIFactory2(DXGI.DXGI_CREATE_FACTORY_DEBUG, Windows.__uuidof(), (void**)dxgiFactory2.GetAddressOf()); DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default; dxgiSwapChainDesc1.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_IGNORE; diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 1f60d717..75cd8583 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -60,10 +60,10 @@ internal unsafe static class Win32ApplicationRunner WNDCLASSEXW windowClassEx = new() { cbSize = (uint)sizeof(WNDCLASSEXW), - style = Windows.CS_HREDRAW | Windows.CS_VREDRAW, + style = CS.CS_HREDRAW | CS.CS_VREDRAW, lpfnWndProc = (delegate* unmanaged)(delegate* unmanaged)&WindowProc, hInstance = hInstance, - hCursor = Windows.LoadCursorW(HINSTANCE.NULL, Windows.IDC_ARROW), + hCursor = Windows.LoadCursorW(HINSTANCE.NULL, IDC.IDC_ARROW), lpszClassName = (ushort*)name }; @@ -107,7 +107,7 @@ internal unsafe static class Win32ApplicationRunner application.OnInitialize(hwnd); // Display the window - _ = Windows.ShowWindow(hwnd, Windows.SW_SHOWDEFAULT); + _ = Windows.ShowWindow(hwnd, SW.SW_SHOWDEFAULT); MSG msg = default; diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 66955537..166a7bc1 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs index f7cc50f6..a5d074d6 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs @@ -176,7 +176,7 @@ internal static unsafe class ID3D12DeviceExtensions { D3D12_SHADER_RESOURCE_VIEW_DESC d3D12ShaderResourceViewDescription = default; d3D12ShaderResourceViewDescription.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; - d3D12ShaderResourceViewDescription.Shader4ComponentMapping = DirectX.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + d3D12ShaderResourceViewDescription.Shader4ComponentMapping = D3D12.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; d3D12ShaderResourceViewDescription.Buffer.NumElements = bufferSize; d3D12ShaderResourceViewDescription.Buffer.StructureByteStride = elementSize; @@ -201,7 +201,7 @@ internal static unsafe class ID3D12DeviceExtensions D3D12_SHADER_RESOURCE_VIEW_DESC d3D12ShaderResourceViewDescription = default; d3D12ShaderResourceViewDescription.ViewDimension = d3D12SrvDimension; d3D12ShaderResourceViewDescription.Format = dxgiFormat; - d3D12ShaderResourceViewDescription.Shader4ComponentMapping = DirectX.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + d3D12ShaderResourceViewDescription.Shader4ComponentMapping = D3D12.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; d3D12ShaderResourceViewDescription.Texture2D.MipLevels = uint.MaxValue; d3D12Device.CreateShaderResourceView(d3D12Resource, &d3D12ShaderResourceViewDescription, d3D12CpuDescriptorHandle); diff --git a/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs b/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs index e7188897..1b9520c8 100644 --- a/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/D3D12FeatureHelper.cs @@ -51,7 +51,7 @@ internal static class D3D12FeatureHelper &d3D12Options7, (uint)sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS7)); - if (result == Windows.S_OK) + if (result == S.S_OK) { return D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_CREATE_NOT_ZEROED; } diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs index 7023875f..1fcb0248 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs @@ -123,7 +123,7 @@ internal static partial class DeviceHelper Windows.__uuidof(), dxgiAdapter1.GetVoidAddressOf()); - if (enumAdapters1Result == Windows.DXGI_ERROR_NOT_FOUND) + if (enumAdapters1Result == DXGI.DXGI_ERROR_NOT_FOUND) { this.dxgiFactory6.Get()->EnumWarpAdapter(Windows.__uuidof(), dxgiAdapter1.GetVoidAddressOf()).Assert(); diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs index 74fbccd8..71532feb 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs @@ -18,7 +18,7 @@ internal static partial class DeviceHelper /// private const uint IDXGIFactoryCreationFlags = #if DEBUG - DirectX.DXGI_CREATE_FACTORY_DEBUG; + DXGI.DXGI_CREATE_FACTORY_DEBUG; #else 0; #endif @@ -37,7 +37,7 @@ internal static partial class DeviceHelper HRESULT result = dxgiFactory4.CopyTo(dxgiFactory6); - if (result == Windows.S_OK) + if (result == S.S_OK) { return; } diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs index 353497f6..28b9bbfe 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs @@ -99,7 +99,7 @@ internal static partial class DeviceHelper Windows.__uuidof(), dxgiAdapter1.GetVoidAddressOf()); - if (enumAdapters1Result == Windows.DXGI_ERROR_NOT_FOUND) + if (enumAdapters1Result == DXGI.DXGI_ERROR_NOT_FOUND) { return false; } diff --git a/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs b/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs index cf75c4b1..5d08fe7c 100644 --- a/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/WICFormatHelper.cs @@ -23,11 +23,11 @@ internal static class WICFormatHelper public static Guid GetForType() where T : unmanaged { - if (typeof(T) == typeof(Bgra32)) return Windows.GUID_WICPixelFormat32bppBGRA; - else if (typeof(T) == typeof(Rgba32)) return Windows.GUID_WICPixelFormat32bppRGBA; - else if (typeof(T) == typeof(Rgba64)) return Windows.GUID_WICPixelFormat64bppRGBA; - else if (typeof(T) == typeof(R8)) return Windows.GUID_WICPixelFormat8bppGray; - else if (typeof(T) == typeof(R16)) return Windows.GUID_WICPixelFormat16bppGray; + if (typeof(T) == typeof(Bgra32)) return GUID.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(Rgba32)) return GUID.GUID_WICPixelFormat32bppRGBA; + else if (typeof(T) == typeof(Rgba64)) return GUID.GUID_WICPixelFormat64bppRGBA; + else if (typeof(T) == typeof(R8)) return GUID.GUID_WICPixelFormat8bppGray; + else if (typeof(T) == typeof(R16)) return GUID.GUID_WICPixelFormat16bppGray; else return ThrowHelper.ThrowArgumentException("Invalid texture type"); } @@ -42,58 +42,58 @@ internal static class WICFormatHelper public static bool TryGetIntermediateFormatForType(Guid containerFormat, out Guid intermediateFormat) where T : unmanaged { - if (containerFormat == Windows.GUID_ContainerFormatBmp) + if (containerFormat == GUID.GUID_ContainerFormatBmp) { if (typeof(T) == typeof(Bgra32)) intermediateFormat = default; - else if (typeof(T) == typeof(Rgba32)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; - else if (typeof(T) == typeof(Rgba64)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; - else if (typeof(T) == typeof(R8)) intermediateFormat = Windows.GUID_WICPixelFormat24bppBGR; - else if (typeof(T) == typeof(R16)) intermediateFormat = Windows.GUID_WICPixelFormat24bppBGR; + else if (typeof(T) == typeof(Rgba32)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(Rgba64)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(R8)) intermediateFormat = GUID.GUID_WICPixelFormat24bppBGR; + else if (typeof(T) == typeof(R16)) intermediateFormat = GUID.GUID_WICPixelFormat24bppBGR; else intermediateFormat = ThrowHelper.ThrowArgumentException("Invalid texture type"); } - else if (containerFormat == Windows.GUID_ContainerFormatPng) + else if (containerFormat == GUID.GUID_ContainerFormatPng) { if (typeof(T) == typeof(Bgra32)) intermediateFormat = default; - else if (typeof(T) == typeof(Rgba32)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(Rgba32)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; else if (typeof(T) == typeof(Rgba64)) intermediateFormat = default; else if (typeof(T) == typeof(R8)) intermediateFormat = default; - else if (typeof(T) == typeof(R16)) intermediateFormat = Windows.GUID_WICPixelFormat8bppGray; + else if (typeof(T) == typeof(R16)) intermediateFormat = GUID.GUID_WICPixelFormat8bppGray; else intermediateFormat = ThrowHelper.ThrowArgumentException("Invalid texture type"); } - else if (containerFormat == Windows.GUID_ContainerFormatJpeg) + else if (containerFormat == GUID.GUID_ContainerFormatJpeg) { - if (typeof(T) == typeof(Bgra32)) intermediateFormat = Windows.GUID_WICPixelFormat24bppBGR; - else if (typeof(T) == typeof(Rgba32)) intermediateFormat = Windows.GUID_WICPixelFormat24bppBGR; - else if (typeof(T) == typeof(Rgba64)) intermediateFormat = Windows.GUID_WICPixelFormat24bppBGR; + if (typeof(T) == typeof(Bgra32)) intermediateFormat = GUID.GUID_WICPixelFormat24bppBGR; + else if (typeof(T) == typeof(Rgba32)) intermediateFormat = GUID.GUID_WICPixelFormat24bppBGR; + else if (typeof(T) == typeof(Rgba64)) intermediateFormat = GUID.GUID_WICPixelFormat24bppBGR; else if (typeof(T) == typeof(R8)) intermediateFormat = default; - else if (typeof(T) == typeof(R16)) intermediateFormat = Windows.GUID_WICPixelFormat8bppGray; + else if (typeof(T) == typeof(R16)) intermediateFormat = GUID.GUID_WICPixelFormat8bppGray; else intermediateFormat = ThrowHelper.ThrowArgumentException("Invalid texture type"); } - else if (containerFormat == Windows.GUID_ContainerFormatWmp) + else if (containerFormat == GUID.GUID_ContainerFormatWmp) { if (typeof(T) == typeof(Bgra32)) intermediateFormat = default; - else if (typeof(T) == typeof(Rgba32)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(Rgba32)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; else if (typeof(T) == typeof(Rgba64)) intermediateFormat = default; else if (typeof(T) == typeof(R8)) intermediateFormat = default; else if (typeof(T) == typeof(R16)) intermediateFormat = default; else intermediateFormat = ThrowHelper.ThrowArgumentException("Invalid texture type"); } - else if (containerFormat == Windows.GUID_ContainerFormatTiff) + else if (containerFormat == GUID.GUID_ContainerFormatTiff) { if (typeof(T) == typeof(Bgra32)) intermediateFormat = default; - else if (typeof(T) == typeof(Rgba32)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(Rgba32)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; else if (typeof(T) == typeof(Rgba64)) intermediateFormat = default; else if (typeof(T) == typeof(R8)) intermediateFormat = default; else if (typeof(T) == typeof(R16)) intermediateFormat = default; else intermediateFormat = ThrowHelper.ThrowArgumentException("Invalid texture type"); } - else if (containerFormat == Windows.GUID_ContainerFormatDds) + else if (containerFormat == GUID.GUID_ContainerFormatDds) { if (typeof(T) == typeof(Bgra32)) intermediateFormat = default; - else if (typeof(T) == typeof(Rgba32)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; - else if (typeof(T) == typeof(Rgba64)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; - else if (typeof(T) == typeof(R8)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; - else if (typeof(T) == typeof(R16)) intermediateFormat = Windows.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(Rgba32)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(Rgba64)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(R8)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; + else if (typeof(T) == typeof(R16)) intermediateFormat = GUID.GUID_WICPixelFormat32bppBGRA; else intermediateFormat = ThrowHelper.ThrowArgumentException("Invalid texture type"); } else @@ -115,16 +115,16 @@ internal static class WICFormatHelper { return Path.GetExtension(filename).ToString() switch { - ".bmp" => Windows.GUID_ContainerFormatBmp, - ".png" => Windows.GUID_ContainerFormatPng, + ".bmp" => GUID.GUID_ContainerFormatBmp, + ".png" => GUID.GUID_ContainerFormatPng, ".jpg" or - ".jpeg" => Windows.GUID_ContainerFormatJpeg, + ".jpeg" => GUID.GUID_ContainerFormatJpeg, ".jxr" or ".hdp" or ".wdp" or - ".wmp" => Windows.GUID_ContainerFormatWmp, - ".tiff" => Windows.GUID_ContainerFormatTiff, - ".dds" => Windows.GUID_ContainerFormatDds, + ".wmp" => GUID.GUID_ContainerFormatWmp, + ".tiff" => GUID.GUID_ContainerFormatTiff, + ".dds" => GUID.GUID_ContainerFormatDds, _ => ThrowHelper.ThrowArgumentException("Invalid filename"), }; } diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs index 0a361b06..dca6efdd 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs @@ -60,7 +60,7 @@ public unsafe abstract class Buffer : NativeObject if (resourceType == ResourceType.Constant) { - Guard.IsBetweenOrEqualTo(length, 1, DirectX.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT, nameof(length)); + Guard.IsBetweenOrEqualTo(length, 1, D3D12.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT, nameof(length)); } else { @@ -75,7 +75,7 @@ public unsafe abstract class Buffer : NativeObject } nint usableSizeInBytes = checked((nint)(length * elementSizeInBytes)); - nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, DirectX.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes; + nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, D3D12.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes; SizeInBytes = usableSizeInBytes; GraphicsDevice = device; diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs index 8b47d9a2..db46dfae 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs @@ -74,8 +74,8 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), d3D12FormatSupport)) { diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs index c8d8b1ea..492be47d 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs @@ -75,9 +75,9 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); - Guard.IsBetweenOrEqualTo(depth, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); + Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(depth, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), d3D12FormatSupport)) { diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs index 169811b3..90ce33fd 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs @@ -50,8 +50,8 @@ public unsafe abstract class TransferTexture2D : NativeObject { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), D3D12_FORMAT_SUPPORT1_TEXTURE2D)) { diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs index c137340d..f7765687 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs @@ -51,9 +51,9 @@ public unsafe abstract class TransferTexture3D : NativeObject { device.ThrowIfDisposed(); - Guard.IsBetweenOrEqualTo(width, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); - Guard.IsBetweenOrEqualTo(height, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); - Guard.IsBetweenOrEqualTo(depth, 1, DirectX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); + Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width)); + Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height)); + Guard.IsBetweenOrEqualTo(depth, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), D3D12_FORMAT_SUPPORT1_TEXTURE3D)) { diff --git a/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs index beb59215..3bd413f7 100644 --- a/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/ConstantBuffer{T}.cs @@ -26,7 +26,7 @@ public sealed class ConstantBuffer : Buffer /// /// The alignment boundary for elements in a constant buffer. /// - private const int ElementAlignment = DirectX.D3D12_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT; + private const int ElementAlignment = D3D12.D3D12_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT; /// /// Creates a new instance with the specified parameters. diff --git a/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs b/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs index da04ea73..e0cb246b 100644 --- a/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs +++ b/src/ComputeSharp/Graphics/Resources/Interop/__Internals/ResourceDescriptor.cs @@ -45,6 +45,6 @@ public struct ResourceDescriptor descriptor.BaseShaderRegister = offset; descriptor.RegisterSpace = 0; descriptor.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE; - descriptor.OffsetInDescriptorsFromTableStart = DirectX.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND; + descriptor.OffsetInDescriptorsFromTableStart = D3D12.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND; } } diff --git a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs index 0619fcf8..a86d812e 100644 --- a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs @@ -119,9 +119,9 @@ internal static class ShaderRunner int groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1); int groupsZ = Math.DivRem(z, threadsZ, out int modZ) + (modZ == 0 ? 0 : 1); - Guard.IsBetweenOrEqualTo(groupsX, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); - Guard.IsBetweenOrEqualTo(groupsY, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); - Guard.IsBetweenOrEqualTo(groupsZ, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsX, 1, D3D11.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsY, 1, D3D11.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsZ, 1, D3D11.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); ShaderKey key = new(shader.GetDispatchId(), threadsX, threadsY, threadsZ); PipelineData? pipelineData; @@ -174,8 +174,8 @@ internal static class ShaderRunner int groupsX = Math.DivRem(x, threadsX, out int modX) + (modX == 0 ? 0 : 1); int groupsY = Math.DivRem(y, threadsY, out int modY) + (modY == 0 ? 0 : 1); - Guard.IsBetweenOrEqualTo(groupsX, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); - Guard.IsBetweenOrEqualTo(groupsY, 1, DirectX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsX, 1, D3D11.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); + Guard.IsBetweenOrEqualTo(groupsY, 1, D3D11.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX)); ShaderKey key = new(shader.GetDispatchId(), threadsX, threadsY, 1); PipelineData? pipelineData; diff --git a/tests/ComputeSharp.Tests/InteropServicesTests.cs b/tests/ComputeSharp.Tests/InteropServicesTests.cs index bfc9a13c..fa7b36ee 100644 --- a/tests/ComputeSharp.Tests/InteropServicesTests.cs +++ b/tests/ComputeSharp.Tests/InteropServicesTests.cs @@ -32,7 +32,7 @@ public unsafe partial class InteropServicesTests int hResult = InteropServices.TryGetID3D12Device(device.Get(), Windows.__uuidof(), (void**)d3D12Device.GetAddressOf()); - Assert.AreEqual(hResult, Windows.S_OK); + Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Device.Get() != null); luid = d3D12Device.Get()->GetAdapterLuid(); @@ -60,7 +60,7 @@ public unsafe partial class InteropServicesTests int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof(), (void**)d3D12Resource.GetAddressOf()); - Assert.AreEqual(hResult, Windows.S_OK); + Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER); } @@ -84,7 +84,7 @@ public unsafe partial class InteropServicesTests int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof(), (void**)d3D12Resource.GetAddressOf()); - Assert.AreEqual(hResult, Windows.S_OK); + Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE2D); } @@ -108,7 +108,7 @@ public unsafe partial class InteropServicesTests int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof(), (void**)d3D12Resource.GetAddressOf()); - Assert.AreEqual(hResult, Windows.S_OK); + Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE3D); } @@ -132,7 +132,7 @@ public unsafe partial class InteropServicesTests int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof(), (void**)d3D12Resource.GetAddressOf()); - Assert.AreEqual(hResult, Windows.S_OK); + Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER); } @@ -156,7 +156,7 @@ public unsafe partial class InteropServicesTests int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof(), (void**)d3D12Resource.GetAddressOf()); - Assert.AreEqual(hResult, Windows.S_OK); + Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER); } @@ -180,7 +180,7 @@ public unsafe partial class InteropServicesTests int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof(), (void**)d3D12Resource.GetAddressOf()); - Assert.AreEqual(hResult, Windows.S_OK); + Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER); } From 775e976455e1b4a5f5c642094eea2053bbf2bd9f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 15 Nov 2021 22:04:04 +0100 Subject: [PATCH 5/7] Minor code tweaks --- .../Backend/Win32ApplicationRunner.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 75cd8583..680c9b3e 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -61,7 +61,7 @@ internal unsafe static class Win32ApplicationRunner { cbSize = (uint)sizeof(WNDCLASSEXW), style = CS.CS_HREDRAW | CS.CS_VREDRAW, - lpfnWndProc = (delegate* unmanaged)(delegate* unmanaged)&WindowProc, + lpfnWndProc = &WindowProc, hInstance = hInstance, hCursor = Windows.LoadCursorW(HINSTANCE.NULL, IDC.IDC_ARROW), lpszClassName = (ushort*)name @@ -173,7 +173,7 @@ internal unsafe static class Win32ApplicationRunner /// Additional message information (the contents depend on the value of ). /// The result of the message processing for the input message. [UnmanagedCallersOnly] - private static nint WindowProc(IntPtr hwnd, uint uMsg, nuint wParam, nint lParam) + private static LRESULT WindowProc(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { @@ -194,12 +194,12 @@ internal unsafe static class Win32ApplicationRunner // Change the paused state when ESC is pressed case WM.WM_KEYDOWN: { - if ((ConsoleKey)wParam == ConsoleKey.Escape) + if (wParam == (byte)ConsoleKey.Escape) { if (isPaused) { - Windows.SetCapture((HWND)hwnd); + Windows.SetCapture(hwnd); } else { @@ -232,7 +232,7 @@ internal unsafe static class Win32ApplicationRunner // Size update case WM.WM_SIZE: { - if (!isResizing && wParam != Windows.SIZE_MINIMIZED) + if (!isResizing && wParam != (byte)Windows.SIZE_MINIMIZED) { application.OnResize(); } @@ -253,7 +253,7 @@ internal unsafe static class Win32ApplicationRunner RECT rect; _ = Windows.GetCursorPos(&point); - _ = Windows.GetWindowRect((HWND)hwnd, &rect); + _ = Windows.GetWindowRect(hwnd, &rect); bool isAtTop = Math.Abs(point.y - rect.top) < 12; bool isAtRight = Math.Abs(point.x - rect.right) < 12; @@ -300,7 +300,7 @@ internal unsafe static class Win32ApplicationRunner margins.cyTopHeight = -1; margins.cyBottomHeight = -1; - _ = Windows.DwmExtendFrameIntoClientArea((HWND)hwnd, &margins); + _ = Windows.DwmExtendFrameIntoClientArea(hwnd, &margins); return 0; } @@ -313,6 +313,6 @@ internal unsafe static class Win32ApplicationRunner } } - return Windows.DefWindowProcW((HWND)hwnd, uMsg, wParam, lParam); + return Windows.DefWindowProcW(hwnd, uMsg, wParam, lParam); } } From 871e1c784831b3bbadcf254029c3e8ede5369dfa Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 15 Nov 2021 23:38:43 +0100 Subject: [PATCH 6/7] Bump D3D12MA to version 2.0.0-beta3.1464316930 --- .../ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs | 2 +- src/ComputeSharp/ComputeSharp.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 680c9b3e..281a26cf 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -139,7 +139,7 @@ internal unsafe static class Win32ApplicationRunner // Process any messages in the queue while (msg.message != WM.WM_QUIT) { - if (Windows.PeekMessageW(&msg, HWND.NULL, 0, 0, Windows.PM_REMOVE) != 0) + if (Windows.PeekMessageW(&msg, HWND.NULL, 0, 0, PM.PM_REMOVE) != 0) { _ = Windows.TranslateMessage(&msg); _ = Windows.DispatchMessageW(&msg); diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 166a7bc1..839adc52 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -9,7 +9,7 @@ - + From 9b98c5163fb3d50e1490e5763e1d6a4f6e040ca2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 16 Nov 2021 00:46:30 +0100 Subject: [PATCH 7/7] Bump D3D12MA to version 2.0.0-beta3 --- Directory.Build.props | 3 --- src/ComputeSharp/ComputeSharp.csproj | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index a90caba2..7169705b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,8 +6,5 @@ true Sergio Pedri Copyright (c) 2021 Sergio Pedri - - https://pkgs.terrafx.dev/index.json; - \ No newline at end of file diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 839adc52..d077610d 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -9,7 +9,7 @@ - +