Restore D3D12MA support on .NET 6

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-18 10:57:03 +01:00
1 親 d7a94fdf37
コミット 9f07d7bb0c
10ファイル変更
+41 -41

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ComputeSharp.Core.Extensions;
using Microsoft.Toolkit.Diagnostics;
+6 -6
ファイルの表示
@@ -1,10 +1,10 @@
using System;
using System.Diagnostics.Contracts;
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using System.Runtime.CompilerServices;
#endif
using ComputeSharp.Core.Extensions;
#if !USE_D3D12MA
#if !NET6_0_OR_GREATER
using ComputeSharp.Graphics.Resources.Enums;
using Microsoft.Toolkit.Diagnostics;
#endif
@@ -12,19 +12,19 @@ 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;
#if !USE_D3D12MA
#if !NET6_0_OR_GREATER
using static TerraFX.Interop.DirectX.D3D12_CPU_PAGE_PROPERTY;
#endif
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;
#if !USE_D3D12MA
#if !NET6_0_OR_GREATER
using static TerraFX.Interop.DirectX.D3D12_HEAP_FLAGS;
using static TerraFX.Interop.DirectX.D3D12_MEMORY_POOL;
#endif
using static TerraFX.Interop.DirectX.D3D12_MESSAGE_ID;
#if !USE_D3D12MA
#if !NET6_0_OR_GREATER
using static TerraFX.Interop.DirectX.D3D12_HEAP_TYPE;
using static TerraFX.Interop.DirectX.D3D12_RESOURCE_FLAGS;
using static TerraFX.Interop.DirectX.D3D12_RESOURCE_STATES;
@@ -39,7 +39,7 @@ namespace ComputeSharp.Graphics.Extensions;
/// </summary>
internal static unsafe class ID3D12DeviceExtensions
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// Creates a <see cref="D3D12MA_Allocator"/> instance for a given device.
/// </summary>
+6 -6
ファイルの表示
@@ -74,7 +74,7 @@ public sealed unsafe class GraphicsDevice : NativeObject
/// </summary>
private ulong nextD3D12CopyFenceValue;
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocator"/> in use associated to the current device.
/// </summary>
@@ -120,7 +120,7 @@ public sealed unsafe class GraphicsDevice : NativeObject
IsCacheCoherentUMA = d3D12Architecture1Data.CacheCoherentUMA != 0;
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocator = d3D12Device->CreateAllocator(dxgiAdapter);
if (IsCacheCoherentUMA)
@@ -171,7 +171,7 @@ public sealed unsafe class GraphicsDevice : NativeObject
/// </summary>
internal ID3D12Device* D3D12Device => this.d3D12Device;
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// Gets the underlying <see cref="D3D12MA_Allocator"/> wrapped by the current instance.
/// </summary>
@@ -257,7 +257,7 @@ public sealed unsafe class GraphicsDevice : NativeObject
/// </summary>
internal void RegisterAllocatedResource()
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.pool.AddRef();
this.allocator.AddRef();
#endif
@@ -268,7 +268,7 @@ public sealed unsafe class GraphicsDevice : NativeObject
/// </summary>
internal void UnregisterAllocatedResource()
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.pool.Release();
this.allocator.Release();
#endif
@@ -408,7 +408,7 @@ public sealed unsafe class GraphicsDevice : NativeObject
this.computeCommandListPool.Dispose();
this.copyCommandListPool.Dispose();
this.shaderResourceViewDescriptorAllocator.Dispose();
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.pool.Dispose();
this.allocator.Dispose();
#endif
+3 -3
ファイルの表示
@@ -25,7 +25,7 @@ namespace ComputeSharp.Resources;
public unsafe abstract class Buffer<T> : NativeObject
where T : unmanaged
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
@@ -87,7 +87,7 @@ public unsafe abstract class Buffer<T> : NativeObject
GraphicsDevice = device;
Length = length;
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)effectiveSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
@@ -191,7 +191,7 @@ public unsafe abstract class Buffer<T> : NativeObject
protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
+6 -6
ファイルの表示
@@ -61,7 +61,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
nint byteOffset = (nint)sourceOffset * sizeof(T);
nint byteLength = count * sizeof(T);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
@@ -73,7 +73,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(allocation.Get()->GetResource(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
#else
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
@@ -81,7 +81,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
copyCommandList.ExecuteAndWaitForCompletion();
}
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map();
#else
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
@@ -220,7 +220,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
nint byteOffset = (nint)offset * sizeof(T);
nint byteLength = length * sizeof(T);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
@@ -230,7 +230,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
GraphicsDevice.IsCacheCoherentUMA);
#endif
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
#else
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
@@ -249,7 +249,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, allocation.Get()->GetResource(), 0, (ulong)byteLength);
#else
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteLength);
+5 -5
ファイルの表示
@@ -26,7 +26,7 @@ namespace ComputeSharp.Resources;
public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
@@ -86,7 +86,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
GraphicsDevice = device;
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
@@ -187,7 +187,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.ReadBack,
@@ -408,7 +408,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.Upload,
@@ -532,7 +532,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
+5 -5
ファイルの表示
@@ -26,7 +26,7 @@ namespace ComputeSharp.Resources;
public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
@@ -88,7 +88,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
GraphicsDevice = device;
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
@@ -203,7 +203,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.ReadBack,
@@ -450,7 +450,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.Upload,
@@ -585,7 +585,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
+3 -3
ファイルの表示
@@ -18,7 +18,7 @@ namespace ComputeSharp.Resources;
public abstract unsafe class TransferBuffer<T> : NativeObject, IMemoryOwner<T>
where T : unmanaged
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
@@ -54,7 +54,7 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IMemoryOwner<T>
ulong sizeInBytes = (uint)length * (uint)sizeof(T);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, sizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
@@ -116,7 +116,7 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IMemoryOwner<T>
protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
+3 -3
ファイルの表示
@@ -18,7 +18,7 @@ namespace ComputeSharp.Resources;
public unsafe abstract class TransferTexture2D<T> : NativeObject
where T : unmanaged
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
@@ -70,7 +70,7 @@ public unsafe abstract class TransferTexture2D<T> : NativeObject
out _,
out ulong totalSizeInBytes);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
@@ -125,7 +125,7 @@ public unsafe abstract class TransferTexture2D<T> : NativeObject
protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
+3 -3
ファイルの表示
@@ -18,7 +18,7 @@ namespace ComputeSharp.Resources;
public unsafe abstract class TransferTexture3D<T> : NativeObject
where T : unmanaged
{
#if USE_D3D12MA
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
@@ -73,7 +73,7 @@ public unsafe abstract class TransferTexture3D<T> : NativeObject
out _,
out ulong totalSizeInBytes);
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
@@ -133,7 +133,7 @@ public unsafe abstract class TransferTexture3D<T> : NativeObject
protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if USE_D3D12MA
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif