Merge pull request #163 from Sergio0694/feature/d3d12ma-com-interop
Switch to COM support in D3D12MA
このコミットが含まれているのは:
59ファイル変更
+351
-503
検索条件に一致するファイルはありません
@@ -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<T> : Win32Application
|
||||
{
|
||||
using ComPtr<IDXGIFactory2> dxgiFactory2 = default;
|
||||
|
||||
_ = Windows.CreateDXGIFactory2(Windows.DXGI_CREATE_FACTORY_DEBUG, Windows.__uuidof<IDXGIFactory2>(), (void**)dxgiFactory2.GetAddressOf());
|
||||
_ = DirectX.CreateDXGIFactory2(DXGI.DXGI_CREATE_FACTORY_DEBUG, Windows.__uuidof<IDXGIFactory2>(), (void**)dxgiFactory2.GetAddressOf());
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default;
|
||||
dxgiSwapChainDesc1.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_IGNORE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Backend;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
@@ -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 = &WindowProc,
|
||||
hInstance = hInstance,
|
||||
hCursor = Windows.LoadCursorW(IntPtr.Zero, Windows.IDC_ARROW),
|
||||
hCursor = Windows.LoadCursorW(HINSTANCE.NULL, IDC.IDC_ARROW),
|
||||
lpszClassName = (ushort*)name
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
@@ -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;
|
||||
|
||||
@@ -137,9 +137,9 @@ 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)
|
||||
if (Windows.PeekMessageW(&msg, HWND.NULL, 0, 0, PM.PM_REMOVE) != 0)
|
||||
{
|
||||
_ = Windows.TranslateMessage(&msg);
|
||||
_ = Windows.DispatchMessageW(&msg);
|
||||
@@ -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 == WM.WM_KEYUP && (msg.wParam == (WPARAM)VK.VK_ESCAPE || msg.wParam == 'Q'))
|
||||
{
|
||||
_ = Windows.DestroyWindow(hwnd);
|
||||
}
|
||||
@@ -173,12 +173,12 @@ internal unsafe static class Win32ApplicationRunner
|
||||
/// <param name="lParam">Additional message information (the contents depend on the value of <paramref name="uMsg"/>).</param>
|
||||
/// <returns>The result of the message processing for the input message.</returns>
|
||||
[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)
|
||||
{
|
||||
// Change the paused state on window activation
|
||||
case Windows.WM_ACTIVATE:
|
||||
case WM.WM_ACTIVATE:
|
||||
{
|
||||
if (Windows.LOWORD(wParam) == Windows.WA_INACTIVE)
|
||||
{
|
||||
@@ -192,9 +192,9 @@ 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)
|
||||
if (wParam == (byte)ConsoleKey.Escape)
|
||||
{
|
||||
|
||||
if (isPaused)
|
||||
@@ -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,9 +230,9 @@ internal unsafe static class Win32ApplicationRunner
|
||||
}
|
||||
|
||||
// Size update
|
||||
case Windows.WM_SIZE:
|
||||
case WM.WM_SIZE:
|
||||
{
|
||||
if (!isResizing && wParam != Windows.SIZE_MINIMIZED)
|
||||
if (!isResizing && wParam != (byte)Windows.SIZE_MINIMIZED)
|
||||
{
|
||||
application.OnResize();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Toolkit.Diagnostics" Version="7.1.1" />
|
||||
<PackageReference Include="TerraFX.Interop.D3D12MemoryAllocator" Version="2.0.0-beta2" />
|
||||
<PackageReference Include="TerraFX.Interop.D3D12MemoryAllocator" Version="2.0.0-beta3" />
|
||||
</ItemGroup>
|
||||
|
||||
<Choose>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Commands;
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
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;
|
||||
@@ -22,9 +22,9 @@ internal static unsafe class AllocatorExtensions
|
||||
/// </summary>
|
||||
/// <param name="allocator">The <see cref="D3D12MA_Allocator"/> instance in use.</param>
|
||||
/// <returns>A <see cref="D3D12MA_Pool"/> instance suited to be used for cache coherent UMA devices.</returns>
|
||||
public static ReferenceCountPtr<D3D12MA_Pool> CreatePoolForCacheCoherentUMA(this ref D3D12MA_Allocator allocator)
|
||||
public static ComPtr<D3D12MA_Pool> CreatePoolForCacheCoherentUMA(this ref D3D12MA_Allocator allocator)
|
||||
{
|
||||
using ReferenceCountPtr<D3D12MA_Pool> pool = default;
|
||||
using ComPtr<D3D12MA_Pool> pool = default;
|
||||
|
||||
D3D12MA_POOL_DESC poolDesc = default;
|
||||
poolDesc.HeapProperties.CreationNodeMask = 1;
|
||||
@@ -46,8 +46,8 @@ internal static unsafe class AllocatorExtensions
|
||||
/// <param name="resourceType">The resource type currently in use.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <param name="sizeInBytes">The size in bytes of the current buffer.</param>
|
||||
/// <returns>An <see cref="UniquePtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
|
||||
public static UniquePtr<D3D12MA_Allocation> CreateResource(
|
||||
/// <returns>An <see cref="ComPtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
|
||||
public static ComPtr<D3D12MA_Allocation> CreateResource(
|
||||
this ref D3D12MA_Allocator allocator,
|
||||
D3D12MA_Pool* pool,
|
||||
ResourceType resourceType,
|
||||
@@ -67,7 +67,7 @@ internal static unsafe class AllocatorExtensions
|
||||
_ => ThrowHelper.ThrowArgumentException<(D3D12_HEAP_TYPE, D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
|
||||
};
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = default;
|
||||
using ComPtr<D3D12MA_Allocation> allocation = default;
|
||||
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Buffer(sizeInBytes, d3D12ResourceFlags);
|
||||
|
||||
@@ -99,8 +99,8 @@ internal static unsafe class AllocatorExtensions
|
||||
/// <param name="width">The width of the texture resource.</param>
|
||||
/// <param name="height">The height of the texture resource.</param>
|
||||
/// <param name="d3D12ResourceStates">The default <see cref="D3D12_RESOURCE_STATES"/> value for the resource.</param>
|
||||
/// <returns>An <see cref="UniquePtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
|
||||
public static UniquePtr<D3D12MA_Allocation> CreateResource(
|
||||
/// <returns>An <see cref="ComPtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
|
||||
public static ComPtr<D3D12MA_Allocation> CreateResource(
|
||||
this ref D3D12MA_Allocator allocator,
|
||||
D3D12MA_Pool* pool,
|
||||
ResourceType resourceType,
|
||||
@@ -120,7 +120,7 @@ internal static unsafe class AllocatorExtensions
|
||||
_ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
|
||||
};
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = default;
|
||||
using ComPtr<D3D12MA_Allocation> allocation = default;
|
||||
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(dxgiFormat, width, height, mipLevels: 1, flags: d3D12ResourceFlags);
|
||||
|
||||
@@ -153,8 +153,8 @@ internal static unsafe class AllocatorExtensions
|
||||
/// <param name="height">The height of the texture resource.</param>
|
||||
/// <param name="depth">The depth of the texture resource.</param>
|
||||
/// <param name="d3D12ResourceStates">The default <see cref="D3D12_RESOURCE_STATES"/> value for the resource.</param>
|
||||
/// <returns>An <see cref="UniquePtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
|
||||
public static UniquePtr<D3D12MA_Allocation> CreateResource(
|
||||
/// <returns>An <see cref="ComPtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
|
||||
public static ComPtr<D3D12MA_Allocation> CreateResource(
|
||||
this ref D3D12MA_Allocator allocator,
|
||||
D3D12MA_Pool* pool,
|
||||
ResourceType resourceType,
|
||||
@@ -175,7 +175,7 @@ internal static unsafe class AllocatorExtensions
|
||||
_ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
|
||||
};
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = default;
|
||||
using ComPtr<D3D12MA_Allocation> allocation = default;
|
||||
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(dxgiFormat, width, height, depth, mipLevels: 1, flags: d3D12ResourceFlags);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Core.Extensions;
|
||||
|
||||
@@ -9,6 +9,50 @@ namespace ComputeSharp.Core.Extensions;
|
||||
/// </summary>
|
||||
internal static class ComPtrExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Invokes <see cref="IUnknown.AddRef"/> on the wrapped object for an input <see cref="ComPtr{T}"/> value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the current <see cref="ComPtr{T}"/> instance.</typeparam>
|
||||
/// <param name="ptr">The input <see cref="ComPtr{T}"/> instance to increment the reference count for.</param>
|
||||
/// <returns>A <see cref="ComPtr{T}"/> instance of type <see cref="IUnknown"/>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe uint AddRef<T>(this ComPtr<T> ptr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
if (ptr.Get() is not null)
|
||||
{
|
||||
return ptr.Get()->AddRef();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes <see cref="IUnknown.Release"/> on the wrapped object for an input <see cref="ComPtr{T}"/> value.
|
||||
/// If the object has been deleted, it also resets <paramref name="ptr"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the current <see cref="ComPtr{T}"/> instance.</typeparam>
|
||||
/// <param name="ptr">The input <see cref="ComPtr{T}"/> instance to release.</param>
|
||||
/// <returns>A <see cref="ComPtr{T}"/> instance of type <see cref="IUnknown"/>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe uint Release<T>(this ref ComPtr<T> ptr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
if (ptr.Get() is not null)
|
||||
{
|
||||
uint count = ptr.Get()->Release();
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
ptr = default;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reinterprets the current <see cref="ComPtr{T}"/> instance as one of type <see cref="IUnknown"/>.
|
||||
/// </summary>
|
||||
@@ -22,7 +66,7 @@ internal static class ComPtrExtensions
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ref readonly ComPtr<IUnknown> AsIUnknown<T>(this in ComPtr<T> ptr)
|
||||
where T : unmanaged
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
return ref Unsafe.As<ComPtr<T>, ComPtr<IUnknown>>(ref Unsafe.AsRef(in ptr));
|
||||
}
|
||||
@@ -37,7 +81,7 @@ internal static class ComPtrExtensions
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void** GetVoidAddressOf<T>(this in ComPtr<T> ptr)
|
||||
where T : unmanaged
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
return (void**)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr));
|
||||
}
|
||||
@@ -50,7 +94,7 @@ internal static class ComPtrExtensions
|
||||
/// <returns>The moved <see cref="ComPtr{T}"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ComPtr<T> Move<T>(this in ComPtr<T> ptr)
|
||||
where T : unmanaged
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
ComPtr<T> copy = default;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
#endif
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using HRESULT = System.Int32;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Core.Extensions;
|
||||
|
||||
@@ -22,6 +22,17 @@ internal static class HResultExtensions
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Assert(this HRESULT result)
|
||||
{
|
||||
Assert((int)result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="int"/> to check.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Assert(this int result)
|
||||
{
|
||||
#if DEBUG
|
||||
bool hasErrorsOrWarnings = DeviceHelper.FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -27,9 +27,9 @@ internal static unsafe class ID3D12DeviceExtensions
|
||||
/// <param name="d3D12Device">The target <see cref="ID3D12Device"/> to use to create the allocator.</param>
|
||||
/// <param name="dxgiAdapter">The <see cref="IDXGIAdapter"/> that <paramref name="d3D12Device"/> was created from.</param>
|
||||
/// <returns>A <see cref="D3D12MA_Allocator"/> instance to create resources on the device in use.</returns>
|
||||
public static ReferenceCountPtr<D3D12MA_Allocator> CreateAllocator(this ref ID3D12Device d3D12Device, IDXGIAdapter* dxgiAdapter)
|
||||
public static ComPtr<D3D12MA_Allocator> CreateAllocator(this ref ID3D12Device d3D12Device, IDXGIAdapter* dxgiAdapter)
|
||||
{
|
||||
using ReferenceCountPtr<D3D12MA_Allocator> allocator = default;
|
||||
using ComPtr<D3D12MA_Allocator> allocator = default;
|
||||
|
||||
D3D12MA_ALLOCATOR_DESC allocatorDesc = default;
|
||||
allocatorDesc.pDevice = (ID3D12Device*)Unsafe.AsPointer(ref d3D12Device);
|
||||
@@ -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 = 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 = Windows.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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace ComputeSharp.Graphics.Extensions;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -76,12 +77,12 @@ public sealed unsafe class GraphicsDevice : NativeObject
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Allocator"/> in use associated to the current device.
|
||||
/// </summary>
|
||||
private ReferenceCountPtr<D3D12MA_Allocator> allocator;
|
||||
private ComPtr<D3D12MA_Allocator> allocator;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Pool"/> instance in use, if <see cref="IsCacheCoherentUMA"/> is <see langword="true"/>.
|
||||
/// </summary>
|
||||
private ReferenceCountPtr<D3D12MA_Pool> pool;
|
||||
private ComPtr<D3D12MA_Pool> pool;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>.
|
||||
@@ -259,8 +260,8 @@ public sealed unsafe class GraphicsDevice : NativeObject
|
||||
/// </summary>
|
||||
internal void UnregisterAllocatedResource()
|
||||
{
|
||||
this.pool.Dispose();
|
||||
this.allocator.Dispose();
|
||||
this.pool.Release();
|
||||
this.allocator.Release();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Rent"/>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -50,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -121,7 +123,7 @@ internal static partial class DeviceHelper
|
||||
Windows.__uuidof<IDXGIAdapter1>(),
|
||||
dxgiAdapter1.GetVoidAddressOf());
|
||||
|
||||
if (enumAdapters1Result == Windows.DXGI_ERROR_NOT_FOUND)
|
||||
if (enumAdapters1Result == DXGI.DXGI_ERROR_NOT_FOUND)
|
||||
{
|
||||
this.dxgiFactory6.Get()->EnumWarpAdapter(Windows.__uuidof<IDXGIAdapter1>(), dxgiAdapter1.GetVoidAddressOf()).Assert();
|
||||
|
||||
@@ -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<ID3D12Device>(),
|
||||
@@ -140,7 +142,7 @@ internal static partial class DeviceHelper
|
||||
{
|
||||
using ComPtr<ID3D12Device> d3D12Device = default;
|
||||
|
||||
Windows.D3D12CreateDevice(
|
||||
DirectX.D3D12CreateDevice(
|
||||
dxgiAdapter1.AsIUnknown().Get(),
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
Windows.__uuidof<ID3D12Device>(),
|
||||
@@ -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<ID3D12Device>(),
|
||||
@@ -181,7 +183,7 @@ internal static partial class DeviceHelper
|
||||
{
|
||||
using ComPtr<ID3D12Device> d3D12Device = default;
|
||||
|
||||
Windows.D3D12CreateDevice(
|
||||
DirectX.D3D12CreateDevice(
|
||||
dxgiAdapter1.AsIUnknown().Get(),
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
Windows.__uuidof<ID3D12Device>(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
private const uint IDXGIFactoryCreationFlags =
|
||||
#if DEBUG
|
||||
Windows.DXGI_CREATE_FACTORY_DEBUG;
|
||||
DXGI.DXGI_CREATE_FACTORY_DEBUG;
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
@@ -31,16 +33,16 @@ internal static partial class DeviceHelper
|
||||
|
||||
EnableDebugMode();
|
||||
|
||||
Windows.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof<IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert();
|
||||
DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof<IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert();
|
||||
|
||||
HRESULT result = dxgiFactory4.CopyTo(dxgiFactory6);
|
||||
|
||||
if (result == Windows.S_OK)
|
||||
if (result == S.S_OK)
|
||||
{
|
||||
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<ID3D12Debug> d3D12Debug = default;
|
||||
using ComPtr<ID3D12Debug1> d3D12Debug1 = default;
|
||||
|
||||
Windows.D3D12GetDebugInterface(Windows.__uuidof<ID3D12Debug>(), d3D12Debug.GetVoidAddressOf()).Assert();
|
||||
DirectX.D3D12GetDebugInterface(Windows.__uuidof<ID3D12Debug>(), d3D12Debug.GetVoidAddressOf()).Assert();
|
||||
|
||||
d3D12Debug.Get()->EnableDebugLayer();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -97,7 +99,7 @@ internal static partial class DeviceHelper
|
||||
Windows.__uuidof<IDXGIAdapter1>(),
|
||||
dxgiAdapter1.GetVoidAddressOf());
|
||||
|
||||
if (enumAdapters1Result == Windows.DXGI_ERROR_NOT_FOUND)
|
||||
if (enumAdapters1Result == DXGI.DXGI_ERROR_NOT_FOUND)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -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<ID3D12Device>(),
|
||||
@@ -129,7 +131,7 @@ internal static partial class DeviceHelper
|
||||
{
|
||||
using ComPtr<ID3D12Device> d3D12DeviceCandidate = default;
|
||||
|
||||
createDeviceResult = Windows.D3D12CreateDevice(
|
||||
createDeviceResult = DirectX.D3D12CreateDevice(
|
||||
dxgiAdapter1.AsIUnknown().Get(),
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
Windows.__uuidof<ID3D12Device>(),
|
||||
@@ -146,7 +148,7 @@ internal static partial class DeviceHelper
|
||||
{
|
||||
using ComPtr<ID3D12Device> d3D12DeviceCandidate = default;
|
||||
|
||||
HRESULT createDeviceResult = Windows.D3D12CreateDevice(
|
||||
HRESULT createDeviceResult = DirectX.D3D12CreateDevice(
|
||||
dxgiAdapter1.AsIUnknown().Get(),
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
Windows.__uuidof<ID3D12Device>(),
|
||||
@@ -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<ID3D12Device>(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -23,11 +23,11 @@ internal static class WICFormatHelper
|
||||
public static Guid GetForType<T>()
|
||||
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<Guid>("Invalid texture type");
|
||||
}
|
||||
|
||||
@@ -42,58 +42,58 @@ internal static class WICFormatHelper
|
||||
public static bool TryGetIntermediateFormatForType<T>(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<Guid>("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<Guid>("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<Guid>("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<Guid>("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<Guid>("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<Guid>("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<Guid>("Invalid filename"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<IWICImagingFactory2> 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<IWICImagingFactory2>(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="ComPtr{T}"/>-equivalent type to safely work with pointers to public <see cref="D3D12MemAlloc"/> 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 <see cref="D3D12MemAlloc"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Must be either <see cref="D3D12MA_Allocator"/>, <see cref="D3D12MA_Allocation"/>, <see cref="D3D12MA_Pool"/> or <see cref="D3D12MA_VirtualBlock"/>.</typeparam>
|
||||
/// <remarks>
|
||||
/// This type is not marked as <see langword="ref"/> 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.
|
||||
/// </remarks>
|
||||
internal unsafe struct ReferenceCountPtr<T> : IDisposable
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// The raw pointer to an <typeparamref name="T"/> object, if existing.
|
||||
/// </summary>
|
||||
private T* pointer;
|
||||
|
||||
/// <summary>
|
||||
/// The current reference count - 1 for <see cref="pointer"/>.
|
||||
/// </summary>
|
||||
private volatile int count;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ReferenceCountPtr{T}"/> instance from a raw pointer.
|
||||
/// </summary>
|
||||
/// <param name="other">The raw pointer to wrap.</param>
|
||||
public ReferenceCountPtr(T* other)
|
||||
{
|
||||
this.pointer = other;
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unwraps a <see cref="ReferenceCountPtr{T}"/> instance and returns the internal raw pointer.
|
||||
/// </summary>
|
||||
/// <param name="other">The <see cref="ReferenceCountPtr{T}"/> instance to unwrap.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator T*(ReferenceCountPtr<T> other)
|
||||
{
|
||||
return other.Get();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increments the internal reference count.
|
||||
/// </summary>
|
||||
public void AddRef()
|
||||
{
|
||||
Interlocked.Increment(ref this.count);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently wrapped raw pointer to an <typeparamref name="T"/> object.
|
||||
/// </summary>
|
||||
/// <returns>The raw pointer wrapped by the current <typeparamref name="T"/> instance.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly T* Get()
|
||||
{
|
||||
return this.pointer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="ReferenceCountPtr{T}"/> instance as a raw <typeparamref name="T"/> double pointer.
|
||||
/// </summary>
|
||||
/// <returns>The raw pointer to the current <see cref="ReferenceCountPtr{T}"/> instance.</returns>
|
||||
/// <remarks>This method is only valid when the current <see cref="ReferenceCountPtr{T}"/> instance is on the stack or pinned.</remarks>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly T** GetAddressOf()
|
||||
{
|
||||
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="ReferenceCountPtr{T}"/> instance as a managed <typeparamref name="T"/> reference to pointer.
|
||||
/// </summary>
|
||||
/// <returns>The reference to the current <see cref="ReferenceCountPtr{T}"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public readonly ref T* GetPinnableReference()
|
||||
{
|
||||
fixed (T** ptr = &this.pointer)
|
||||
{
|
||||
return ref *ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the current <see cref="ReferenceCountPtr{T}"/> instance and resets it without releasing the reference.
|
||||
/// </summary>
|
||||
/// <returns>The moved <see cref="ReferenceCountPtr{T}"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ReferenceCountPtr<T> Move()
|
||||
{
|
||||
ReferenceCountPtr<T> copy = this;
|
||||
|
||||
this = default;
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="ComPtr{T}"/>-equivalent type to safely work with pointers to public <see cref="D3D12MemAlloc"/> APIs.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Must be either <see cref="D3D12MA_Allocator"/>, <see cref="D3D12MA_Allocation"/>, <see cref="D3D12MA_Pool"/> or <see cref="D3D12MA_VirtualBlock"/>.</typeparam>
|
||||
/// <remarks>
|
||||
/// This type is not marked as <see langword="ref"/> 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.
|
||||
/// </remarks>
|
||||
internal unsafe struct UniquePtr<T> : IDisposable
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// The raw pointer to an <typeparamref name="T"/> object, if existing.
|
||||
/// </summary>
|
||||
private T* pointer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="UniquePtr{T}"/> instance from a raw pointer.
|
||||
/// </summary>
|
||||
/// <param name="other">The raw pointer to wrap.</param>
|
||||
public UniquePtr(T* other)
|
||||
{
|
||||
this.pointer = other;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unwraps a <see cref="UniquePtr{T}"/> instance and returns the internal raw pointer.
|
||||
/// </summary>
|
||||
/// <param name="other">The <see cref="UniquePtr{T}"/> instance to unwrap.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator T*(UniquePtr<T> other)
|
||||
{
|
||||
return other.Get();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[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");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently wrapped raw pointer to an <typeparamref name="T"/> object.
|
||||
/// </summary>
|
||||
/// <returns>The raw pointer wrapped by the current <typeparamref name="T"/> instance.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly T* Get()
|
||||
{
|
||||
return this.pointer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="UniquePtr{T}"/> instance as a raw <typeparamref name="T"/> double pointer.
|
||||
/// </summary>
|
||||
/// <returns>The raw pointer to the current <see cref="UniquePtr{T}"/> instance.</returns>
|
||||
/// <remarks>This method is only valid when the current <see cref="UniquePtr{T}"/> instance is on the stack or pinned.</remarks>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly T** GetAddressOf()
|
||||
{
|
||||
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="UniquePtr{T}"/> instance as a managed <typeparamref name="T"/> reference to pointer.
|
||||
/// </summary>
|
||||
/// <returns>The reference to the current <see cref="UniquePtr{T}"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public readonly ref T* GetPinnableReference()
|
||||
{
|
||||
fixed (T** ptr = &this.pointer)
|
||||
{
|
||||
return ref *ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the current <see cref="UniquePtr{T}"/> instance and resets it without releasing the reference.
|
||||
/// </summary>
|
||||
/// <returns>The moved <see cref="UniquePtr{T}"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public UniquePtr<T> Move()
|
||||
{
|
||||
UniquePtr<T> copy = this;
|
||||
|
||||
this = default;
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -23,7 +24,7 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
|
||||
/// </summary>
|
||||
private UniquePtr<D3D12MA_Allocation> allocation;
|
||||
private ComPtr<D3D12MA_Allocation> allocation;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
@@ -59,7 +60,7 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
|
||||
if (resourceType == ResourceType.Constant)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(length, 1, Windows.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT, nameof(length));
|
||||
Guard.IsBetweenOrEqualTo(length, 1, D3D12.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT, nameof(length));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -74,7 +75,7 @@ public unsafe abstract class Buffer<T> : 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, D3D12.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes;
|
||||
|
||||
SizeInBytes = usableSizeInBytes;
|
||||
GraphicsDevice = device;
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
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;
|
||||
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;
|
||||
@@ -61,7 +61,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
nint byteOffset = (nint)sourceOffset * sizeof(T);
|
||||
nint byteLength = count * sizeof(T);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
|
||||
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
|
||||
{
|
||||
@@ -204,7 +204,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
nint byteOffset = (nint)offset * sizeof(T);
|
||||
nint byteLength = length * sizeof(T);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
|
||||
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
|
||||
|
||||
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
|
||||
@@ -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
|
||||
@@ -28,7 +29,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
|
||||
/// </summary>
|
||||
private UniquePtr<D3D12MA_Allocation> allocation;
|
||||
private ComPtr<D3D12MA_Allocation> allocation;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
@@ -73,8 +74,8 @@ public unsafe abstract class Texture2D<T> : 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, 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<T>(), d3D12FormatSupport))
|
||||
{
|
||||
@@ -173,7 +174,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
GraphicsDevice.Pool,
|
||||
ResourceType.ReadBack,
|
||||
AllocationMode.Default,
|
||||
@@ -386,7 +387,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
GraphicsDevice.Pool,
|
||||
ResourceType.Upload,
|
||||
AllocationMode.Default,
|
||||
|
||||
@@ -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
|
||||
@@ -28,7 +29,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
|
||||
/// </summary>
|
||||
private UniquePtr<D3D12MA_Allocation> allocation;
|
||||
private ComPtr<D3D12MA_Allocation> allocation;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
@@ -74,9 +75,9 @@ public unsafe abstract class Texture3D<T> : 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, 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<T>(), d3D12FormatSupport))
|
||||
{
|
||||
@@ -188,7 +189,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
GraphicsDevice.Pool,
|
||||
ResourceType.ReadBack,
|
||||
AllocationMode.Default,
|
||||
@@ -427,7 +428,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
GraphicsDevice.Pool,
|
||||
ResourceType.Upload,
|
||||
AllocationMode.Default,
|
||||
|
||||
@@ -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;
|
||||
@@ -20,7 +21,7 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IMemoryOwner<T>
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
|
||||
/// </summary>
|
||||
private UniquePtr<D3D12MA_Allocation> allocation;
|
||||
private ComPtr<D3D12MA_Allocation> allocation;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
|
||||
@@ -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;
|
||||
@@ -20,7 +21,7 @@ public unsafe abstract class TransferTexture2D<T> : NativeObject
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
|
||||
/// </summary>
|
||||
private UniquePtr<D3D12MA_Allocation> allocation;
|
||||
private ComPtr<D3D12MA_Allocation> allocation;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
@@ -49,8 +50,8 @@ public unsafe abstract class TransferTexture2D<T> : 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, 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<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
@@ -20,7 +21,7 @@ public unsafe abstract class TransferTexture3D<T> : NativeObject
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
|
||||
/// </summary>
|
||||
private UniquePtr<D3D12MA_Allocation> allocation;
|
||||
private ComPtr<D3D12MA_Allocation> allocation;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
@@ -50,9 +51,9 @@ public unsafe abstract class TransferTexture3D<T> : 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, 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<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D))
|
||||
{
|
||||
|
||||
@@ -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<T> : Buffer<T>
|
||||
/// <summary>
|
||||
/// The alignment boundary for elements in a constant buffer.
|
||||
/// </summary>
|
||||
private const int ElementAlignment = Windows.D3D12_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT;
|
||||
private const int ElementAlignment = D3D12.D3D12_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ConstantBuffer{T}"/> instance with the specified parameters.
|
||||
|
||||
@@ -8,35 +8,35 @@ internal enum ResourceType
|
||||
/// <summary>
|
||||
/// 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 <see langword="cbuffer"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.DirectX.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
|
||||
/// </summary>
|
||||
Constant,
|
||||
|
||||
/// <summary>
|
||||
/// A readonly resource, that can store arbitrary arrays of values and can only be read from by the GPU.
|
||||
/// This is mapped to either <see langword="StructuredBuffer<T>"/> or <see langword="TextureND<T>"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.DirectX.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
|
||||
/// </summary>
|
||||
ReadOnly,
|
||||
|
||||
/// <summary>
|
||||
/// A read write resource, that can store arbitrary arrays with both read and write access for the GPU.
|
||||
/// This is mapped to either <see langword="RWStructuredBuffer<T>"/> or <see langword="RWTextureND<T>"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.DirectX.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
|
||||
/// </summary>
|
||||
ReadWrite,
|
||||
|
||||
/// <summary>
|
||||
/// A readback resource, used temporarily to read data back from <see cref="ReadOnly"/> and <see cref="ReadWrite"/> 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 <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_READBACK"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.DirectX.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_READBACK"/>.
|
||||
/// </summary>
|
||||
ReadBack,
|
||||
|
||||
/// <summary>
|
||||
/// A transfer resource, used temporarily to set data to <see cref="ReadOnly"/> and <see cref="ReadWrite"/> resources.
|
||||
/// This has no direct mapping to a type in HLSL, as it's only used for copy operations (like <see cref="ReadBack"/>).
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
|
||||
/// Resources of this type are located in <see cref="TerraFX.Interop.DirectX.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
|
||||
/// </summary>
|
||||
Upload
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 = D3D12.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<IDxcUtils> dxcUtils = default;
|
||||
|
||||
Guid dxcLibraryClsid = Windows.CLSID_DxcLibrary;
|
||||
|
||||
Windows.DxcCreateInstance(&dxcLibraryClsid, Windows.__uuidof<IDxcUtils>(), dxcUtils.GetVoidAddressOf()).Assert();
|
||||
DirectX.DxcCreateInstance(
|
||||
(Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcLibrary)),
|
||||
Windows.__uuidof<IDxcUtils>(),
|
||||
dxcUtils.GetVoidAddressOf()).Assert();
|
||||
|
||||
using ComPtr<ID3D12ShaderReflection> d3D12ShaderReflection = default;
|
||||
|
||||
|
||||
@@ -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<T>
|
||||
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, 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;
|
||||
@@ -173,8 +174,8 @@ internal static class ShaderRunner<T>
|
||||
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, 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<IDxcLibrary> dxcLibrary = default;
|
||||
using ComPtr<IDxcIncludeHandler> 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<IDxcCompiler>(),
|
||||
dxcCompiler.GetVoidAddressOf()).Assert();
|
||||
|
||||
Windows.DxcCreateInstance(&dxcCompilerCLGuid, Windows.__uuidof<IDxcCompiler>(), dxcCompiler.GetVoidAddressOf()).Assert();
|
||||
Windows.DxcCreateInstance(&dxcLibraryCLGuid, Windows.__uuidof<IDxcLibrary>(), dxcLibrary.GetVoidAddressOf()).Assert();
|
||||
DirectX.DxcCreateInstance(
|
||||
(Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcLibrary)),
|
||||
Windows.__uuidof<IDxcLibrary>(),
|
||||
dxcLibrary.GetVoidAddressOf()).Assert();
|
||||
|
||||
dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).Assert();
|
||||
|
||||
@@ -116,7 +121,7 @@ internal sealed unsafe partial class ShaderCompiler
|
||||
dxcOperationResult.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
int status;
|
||||
HRESULT status;
|
||||
|
||||
dxcOperationResult.Get()->GetStatus(&status).Assert();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -31,7 +32,7 @@ public unsafe partial class InteropServicesTests
|
||||
|
||||
int hResult = InteropServices.TryGetID3D12Device(device.Get(), Windows.__uuidof<ID3D12Device>(), (void**)d3D12Device.GetAddressOf());
|
||||
|
||||
Assert.AreEqual(hResult, Windows.S_OK);
|
||||
Assert.AreEqual(hResult, S.S_OK);
|
||||
Assert.IsTrue(d3D12Device.Get() != null);
|
||||
|
||||
luid = d3D12Device.Get()->GetAdapterLuid();
|
||||
@@ -59,7 +60,7 @@ public unsafe partial class InteropServicesTests
|
||||
|
||||
int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (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);
|
||||
}
|
||||
@@ -83,7 +84,7 @@ public unsafe partial class InteropServicesTests
|
||||
|
||||
int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (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);
|
||||
}
|
||||
@@ -107,7 +108,7 @@ public unsafe partial class InteropServicesTests
|
||||
|
||||
int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (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);
|
||||
}
|
||||
@@ -131,7 +132,7 @@ public unsafe partial class InteropServicesTests
|
||||
|
||||
int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (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);
|
||||
}
|
||||
@@ -155,7 +156,7 @@ public unsafe partial class InteropServicesTests
|
||||
|
||||
int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (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);
|
||||
}
|
||||
@@ -179,7 +180,7 @@ public unsafe partial class InteropServicesTests
|
||||
|
||||
int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (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);
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする