Switch GraphicsDevice to use new allocator APIs

このコミットが含まれているのは:
Sergio Pedri committed 2023-07-01 21:18:48 +02:00
1 親 c9bee1a047
コミット 9eac016ae9
13ファイル変更
+304 -353

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

-32
ファイルの表示
@@ -1,32 +1,21 @@
using System;
#if NET6_0_OR_GREATER
using System.Runtime.CompilerServices;
#endif
using ComputeSharp.Core.Extensions;
#if !NET6_0_OR_GREATER
using ComputeSharp.Graphics.Resources.Enums;
#endif
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 !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 !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 !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;
#endif
using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
using static TerraFX.Interop.DirectX.D3D12_UAV_DIMENSION;
@@ -37,26 +26,6 @@ namespace ComputeSharp.Graphics.Extensions;
/// </summary>
internal static unsafe class ID3D12DeviceExtensions
{
#if NET6_0_OR_GREATER
/// <summary>
/// Creates a <see cref="D3D12MA_Allocator"/> instance for a given device.
/// </summary>
/// <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 ComPtr<D3D12MA_Allocator> CreateAllocator(this ref ID3D12Device d3D12Device, IDXGIAdapter* dxgiAdapter)
{
using ComPtr<D3D12MA_Allocator> allocator = default;
D3D12MA_ALLOCATOR_DESC allocatorDesc = default;
allocatorDesc.pDevice = (ID3D12Device*)Unsafe.AsPointer(ref d3D12Device);
allocatorDesc.pAdapter = dxgiAdapter;
D3D12MemAlloc.D3D12MA_CreateAllocator(&allocatorDesc, allocator.GetAddressOf()).Assert();
return allocator.Move();
}
#else
/// <summary>
/// Creates a committed resource for a given buffer type.
/// </summary>
@@ -301,7 +270,6 @@ internal static unsafe class ID3D12DeviceExtensions
return d3D12Resource.Move();
}
#endif
/// <summary>
/// Creates a new <see cref="ID3D12InfoQueue"/> for a given device.
+179
ファイルの表示
@@ -0,0 +1,179 @@
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
namespace ComputeSharp;
/// <inheritdoc/>
unsafe partial class GraphicsDevice
{
/// <summary>
/// Creates or allocates a resource for a given buffer type.
/// </summary>
/// <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>
/// <param name="allocation">The resulting <see cref="ID3D12Allocation"/> object, if one is used.</param>
/// <param name="d3D12Resource">The resulting <see cref="ID3D12Resource"/> object for the buffer.</param>
internal void CreateOrAllocateResource(
ResourceType resourceType,
AllocationMode allocationMode,
ulong sizeInBytes,
out ComPtr<ID3D12Allocation> allocation,
out ComPtr<ID3D12Resource> d3D12Resource)
{
if (this.allocator.Get() is not null)
{
allocation = this.allocator.Get()->AllocateResource(resourceType, allocationMode, sizeInBytes);
d3D12Resource = allocation.Get()->GetD3D12Resource();
}
else
{
allocation = null;
d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource(resourceType, sizeInBytes, IsCacheCoherentUMA);
}
}
/// <summary>
/// Creates or allocates a resource for a given 1D texture type.
/// </summary>
/// <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="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
/// <param name="width">The width of the texture resource.</param>
/// <param name="d3D12ResourceStates">The default <see cref="D3D12_RESOURCE_STATES"/> value for the resource.</param>
/// <param name="allocation">The resulting <see cref="ID3D12Allocation"/> object, if one is used.</param>
/// <param name="d3D12Resource">The resulting <see cref="ID3D12Resource"/> object for the 1D texture.</param>
internal void CreateOrAllocateResource(
ResourceType resourceType,
AllocationMode allocationMode,
DXGI_FORMAT dxgiFormat,
uint width,
out ComPtr<ID3D12Allocation> allocation,
out ComPtr<ID3D12Resource> d3D12Resource,
out D3D12_RESOURCE_STATES d3D12ResourceStates)
{
if (this.allocator.Get() is not null)
{
allocation = this.allocator.Get()->AllocateResource(
resourceType,
allocationMode,
dxgiFormat,
width,
out d3D12ResourceStates);
d3D12Resource = allocation.Get()->GetD3D12Resource();
}
else
{
allocation = null;
d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource(
resourceType,
dxgiFormat,
width,
IsCacheCoherentUMA,
out d3D12ResourceStates);
}
}
/// <summary>
/// Creates or allocates a resource for a given 2D texture type.
/// </summary>
/// <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="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
/// <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>
/// <param name="allocation">The resulting <see cref="ID3D12Allocation"/> object, if one is used.</param>
/// <param name="d3D12Resource">The resulting <see cref="ID3D12Resource"/> object for the 2D texture.</param>
internal void CreateOrAllocateResource(
ResourceType resourceType,
AllocationMode allocationMode,
DXGI_FORMAT dxgiFormat,
uint width,
uint height,
out ComPtr<ID3D12Allocation> allocation,
out ComPtr<ID3D12Resource> d3D12Resource,
out D3D12_RESOURCE_STATES d3D12ResourceStates)
{
if (this.allocator.Get() is not null)
{
allocation = this.allocator.Get()->AllocateResource(
resourceType,
allocationMode,
dxgiFormat,
width,
height,
out d3D12ResourceStates);
d3D12Resource = allocation.Get()->GetD3D12Resource();
}
else
{
allocation = null;
d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource(
resourceType,
dxgiFormat,
width,
height,
IsCacheCoherentUMA,
out d3D12ResourceStates);
}
}
/// <summary>
/// Creates or allocates a resource for a given 3D texture type.
/// </summary>
/// <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="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
/// <param name="width">The width of the texture resource.</param>
/// <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>
/// <param name="allocation">The resulting <see cref="ID3D12Allocation"/> object, if one is used.</param>
/// <param name="d3D12Resource">The resulting <see cref="ID3D12Resource"/> object for the 3D texture.</param>
internal void CreateOrAllocateResource(
ResourceType resourceType,
AllocationMode allocationMode,
DXGI_FORMAT dxgiFormat,
uint width,
uint height,
ushort depth,
out ComPtr<ID3D12Allocation> allocation,
out ComPtr<ID3D12Resource> d3D12Resource,
out D3D12_RESOURCE_STATES d3D12ResourceStates)
{
if (this.allocator.Get() is not null)
{
allocation = this.allocator.Get()->AllocateResource(
resourceType,
allocationMode,
dxgiFormat,
width,
height,
depth,
out d3D12ResourceStates);
d3D12Resource = allocation.Get()->GetD3D12Resource();
}
else
{
allocation = null;
d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource(
resourceType,
dxgiFormat,
width,
height,
depth,
IsCacheCoherentUMA,
out d3D12ResourceStates);
}
}
}
+8 -70
ファイルの表示
@@ -4,12 +4,10 @@ using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.Graphics.Commands.Interop;
#if NET6_0_OR_GREATER
using ComputeSharp.Core.Extensions;
#endif
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using ComputeSharp.Shaders.Models;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -81,17 +79,10 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject
/// </summary>
private ulong nextD3D12CopyFenceValue;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocator"/> in use associated to the current device.
/// The <see cref="ID3D12MemoryAllocator"/> in use associated to the current device, if available.
/// </summary>
private ComPtr<D3D12MA_Allocator> allocator;
/// <summary>
/// The <see cref="D3D12MA_Pool"/> instance in use, if <see cref="IsCacheCoherentUMA"/> is <see langword="true"/>.
/// </summary>
private ComPtr<D3D12MA_Pool> pool;
#endif
private ComPtr<ID3D12MemoryAllocator> allocator;
/// <summary>
/// A weak <see cref="GCHandle"/> to the current instance (used to support the device lost callback).
@@ -149,20 +140,20 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance.</param>
/// <param name="dxgiAdapter">The <see cref="IDXGIAdapter"/> that <paramref name="d3D12Device"/> was created from.</param>
/// <param name="dxgiDescription1">The available info for the new <see cref="GraphicsDevice"/> instance.</param>
internal GraphicsDevice(ID3D12Device* d3D12Device, IDXGIAdapter* dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
/// <param name="allocator">The optional <see cref="ID3D12MemoryAllocator"/> instance to use.</param>
internal GraphicsDevice(ID3D12Device* d3D12Device, IDXGIAdapter* dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1, ID3D12MemoryAllocator* allocator)
{
using ReferenceTracker.Lease _0 = ReferenceTracker.Create(this, out this.referenceTracker);
this.d3D12Device = new ComPtr<ID3D12Device>(d3D12Device);
this.d3D12ComputeCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE);
this.d3D12CopyCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COPY);
this.d3D12ComputeFence = d3D12Device->CreateFence();
this.d3D12CopyFence = d3D12Device->CreateFence();
this.shaderResourceViewDescriptorAllocator = new ID3D12DescriptorHandleAllocator(d3D12Device);
this.computeCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COMPUTE);
this.copyCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COPY);
this.allocator = new ComPtr<ID3D12MemoryAllocator>(allocator);
Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid);
Name = new string((char*)dxgiDescription1->Description);
@@ -179,15 +170,6 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject
IsCacheCoherentUMA = d3D12Architecture1Data.CacheCoherentUMA != 0;
#if NET6_0_OR_GREATER
this.allocator = d3D12Device->CreateAllocator(dxgiAdapter);
if (IsCacheCoherentUMA)
{
this.pool = this.allocator.Get()->CreatePoolForCacheCoherentUMA();
}
#endif
this.deviceRemovedReason = S.S_OK;
this.cachedPipelineData = new List<PipelineData>();
@@ -233,19 +215,7 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject
/// <summary>
/// Gets the underlying <see cref="ID3D12Device"/> wrapped by the current instance.
/// </summary>
internal ID3D12Device* D3D12Device => this.d3D12Device;
#if NET6_0_OR_GREATER
/// <summary>
/// Gets the underlying <see cref="D3D12MA_Allocator"/> wrapped by the current instance.
/// </summary>
internal D3D12MA_Allocator* Allocator => this.allocator;
/// <summary>
/// Gets the underlying <see cref="D3D12MA_Pool"/> wrapped by the current instance, if any.
/// </summary>
internal D3D12MA_Pool* Pool => this.pool;
#endif
internal ID3D12Device* D3D12Device => this.d3D12Device.Get();
/// <summary>
/// Gets whether or not the current device has a cache coherent UMA architecture.
@@ -369,28 +339,6 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject
D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
}
/// <summary>
/// Registers that a new resource has been allocated on the current device.
/// </summary>
internal void RegisterAllocatedResource()
{
#if NET6_0_OR_GREATER
this.pool.AddRef();
this.allocator.AddRef();
#endif
}
/// <summary>
/// Unregisters a generic resource that was allocated on the current device.
/// </summary>
internal void UnregisterAllocatedResource()
{
#if NET6_0_OR_GREATER
this.pool.Release();
this.allocator.Release();
#endif
}
/// <summary>
/// Registers a <see cref="PipelineData"/> object for the current device to enable early disposal.
/// </summary>
@@ -484,17 +432,7 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject
this.computeCommandListPool.Dispose();
this.copyCommandListPool.Dispose();
this.shaderResourceViewDescriptorAllocator.Dispose();
// On .NET 6, D3D12MA is used. In this case, the pool and allocator must be kept alive
// until all associated resources are returned and destroyed. Because of this, when the
// device is disposed (since there might be outstanding resources that are still alive),
// the pool and allocator are only released, but not disposed. This allows reosurces to
// also release them when disposed (since each resource keeps a reference back to the
// parent device). When the last one is disposed, the pool and allocator will be deleted.
#if NET6_0_OR_GREATER
this.pool.Release();
this.allocator.Release();
#endif
this.allocator.Dispose();
UnregisterDeviceLostCallback(this);
+1 -1
ファイルの表示
@@ -128,7 +128,7 @@ unsafe partial class DeviceHelper
_ = TryGetMemoryAllocator(d3D12Device, dxgiAdapter, memoryAllocator.GetAddressOf());
// Create the device passing the underlying device, adapter, and optional allocator
device = new GraphicsDevice(d3D12Device, dxgiAdapter, dxgiDescription1);
device = new GraphicsDevice(d3D12Device, dxgiAdapter, dxgiDescription1, memoryAllocator.Get());
DevicesCache.Add(luid, device);
+9 -14
ファイルの表示
@@ -13,6 +13,7 @@ using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_FEATURE;
using static TerraFX.Interop.DirectX.DXGI_FORMAT;
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
using ComputeSharp.Interop.Allocation;
#if NET6_0_OR_GREATER
using MemoryMarshal = System.Runtime.InteropServices.MemoryMarshal;
#else
@@ -33,12 +34,10 @@ public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraph
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -100,14 +99,13 @@ public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraph
GraphicsDevice = device;
Length = length;
#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
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)effectiveSizeInBytes, device.IsCacheCoherentUMA);
#endif
device.CreateOrAllocateResource(
resourceType,
allocationMode,
(ulong)effectiveSizeInBytes,
out this.allocation,
out this.d3D12Resource);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView);
@@ -214,13 +212,10 @@ public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraph
void IReferenceTrackedObject.DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandles);
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView);
}
+17 -28
ファイルの表示
@@ -5,6 +5,7 @@ using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Interop;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE;
@@ -65,30 +66,23 @@ public abstract class StructuredBuffer<T> : Buffer<T>
nint byteOffset = (nint)sourceOffset * sizeof(T);
nint byteLength = count * sizeof(T);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(GraphicsDevice.Pool, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.ReadBack,
AllocationMode.Default,
(ulong)byteLength,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
#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);
#endif
copyCommandList.ExecuteAndWaitForCompletion();
}
#if NET6_0_OR_GREATER
using ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map();
#else
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
#endif
fixed (void* destinationPointer = &destination)
{
@@ -229,20 +223,18 @@ public abstract class StructuredBuffer<T> : Buffer<T>
nint byteOffset = (nint)offset * sizeof(T);
nint byteLength = length * sizeof(T);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(GraphicsDevice.Pool, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.Upload,
AllocationMode.Default,
(ulong)byteLength,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
#if NET6_0_OR_GREATER
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
#else
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
#endif
{
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy<T>(
@@ -254,14 +246,11 @@ public abstract class StructuredBuffer<T> : Buffer<T>
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
}
}
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
#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);
#endif
copyCommandList.ExecuteAndWaitForCompletion();
}
}
+18 -43
ファイルの表示
@@ -9,6 +9,7 @@ using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Helpers;
using ComputeSharp.Graphics.Resources.Interop;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE;
@@ -33,12 +34,10 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -90,25 +89,15 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
GraphicsDevice = device;
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(
device.Pool,
device.CreateOrAllocateResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
out this.allocation,
out this.d3D12Resource,
out this.d3D12ResourceState);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
device.IsCacheCoherentUMA,
out this.d3D12ResourceState);
#endif
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
@@ -120,7 +109,6 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
out _,
out _);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
switch (resourceType)
@@ -181,20 +169,15 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.ReadBack,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -379,20 +362,15 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.Upload,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
{
@@ -495,13 +473,10 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
protected virtual partial void DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandles);
}
}
+18 -44
ファイルの表示
@@ -9,6 +9,7 @@ using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Helpers;
using ComputeSharp.Graphics.Resources.Interop;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE;
@@ -33,12 +34,10 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -92,27 +91,16 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
GraphicsDevice = device;
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(
device.Pool,
device.CreateOrAllocateResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.allocation,
out this.d3D12Resource,
out this.d3D12ResourceState);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
device.IsCacheCoherentUMA,
out this.d3D12ResourceState);
#endif
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
@@ -125,7 +113,6 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
out _,
out _);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
switch (resourceType)
@@ -197,20 +184,15 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.ReadBack,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -420,20 +402,15 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.Upload,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
{
@@ -546,13 +523,10 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
protected virtual partial void DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandles);
}
}
+18 -45
ファイルの表示
@@ -9,6 +9,7 @@ using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Helpers;
using ComputeSharp.Graphics.Resources.Interop;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE;
@@ -33,12 +34,10 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -94,29 +93,17 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
GraphicsDevice = device;
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(
device.Pool,
device.CreateOrAllocateResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.allocation,
out this.d3D12Resource,
out this.d3D12ResourceState);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
device.IsCacheCoherentUMA,
out this.d3D12ResourceState);
#endif
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
@@ -130,7 +117,6 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
out _,
out _);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
switch (resourceType)
@@ -213,20 +199,15 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.ReadBack,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -462,20 +443,15 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
using ComPtr<ID3D12Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
GraphicsDevice.CreateOrAllocateResource(
ResourceType.Upload,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
out *&allocation,
out *&d3D12Resource);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
{
@@ -599,13 +575,10 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
protected virtual partial void DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandles);
}
}
+9 -19
ファイルの表示
@@ -6,6 +6,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_FEATURE;
@@ -27,12 +28,10 @@ public abstract unsafe partial class TransferBuffer<T> : IReferenceTrackedObject
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -74,14 +73,12 @@ public abstract unsafe partial class TransferBuffer<T> : IReferenceTrackedObject
ulong sizeInBytes = (uint)length * (uint)sizeof(T);
#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
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, sizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.CreateOrAllocateResource(
resourceType,
allocationMode,
sizeInBytes,
out this.allocation,
out this.d3D12Resource);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
@@ -134,14 +131,7 @@ public abstract unsafe partial class TransferBuffer<T> : IReferenceTrackedObject
void IReferenceTrackedObject.DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
}
}
/// <summary>
+9 -19
ファイルの表示
@@ -5,6 +5,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1;
@@ -26,12 +27,10 @@ public abstract unsafe partial class TransferTexture1D<T> : IReferenceTrackedObj
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -79,14 +78,12 @@ public abstract unsafe partial class TransferTexture1D<T> : IReferenceTrackedObj
out _,
out ulong totalSizeInBytes);
#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
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, totalSizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.CreateOrAllocateResource(
resourceType,
allocationMode,
totalSizeInBytes,
out this.allocation,
out this.d3D12Resource);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
@@ -139,14 +136,7 @@ public abstract unsafe partial class TransferTexture1D<T> : IReferenceTrackedObj
void IReferenceTrackedObject.DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
}
}
/// <summary>
+9 -19
ファイルの表示
@@ -4,6 +4,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1;
@@ -25,12 +26,10 @@ public abstract unsafe partial class TransferTexture2D<T> : IReferenceTrackedObj
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -81,14 +80,12 @@ public abstract unsafe partial class TransferTexture2D<T> : IReferenceTrackedObj
out _,
out ulong totalSizeInBytes);
#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
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, totalSizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.CreateOrAllocateResource(
resourceType,
allocationMode,
totalSizeInBytes,
out this.allocation,
out this.d3D12Resource);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
@@ -134,14 +131,7 @@ public abstract unsafe partial class TransferTexture2D<T> : IReferenceTrackedObj
void IReferenceTrackedObject.DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
}
}
/// <summary>
+9 -19
ファイルの表示
@@ -4,6 +4,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using ComputeSharp.Interop.Allocation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1;
@@ -25,12 +26,10 @@ public abstract unsafe partial class TransferTexture3D<T> : IReferenceTrackedObj
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// The <see cref="ID3D12Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if available.
/// </summary>
private ComPtr<D3D12MA_Allocation> allocation;
#endif
private ComPtr<ID3D12Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
@@ -84,14 +83,12 @@ public abstract unsafe partial class TransferTexture3D<T> : IReferenceTrackedObj
out _,
out ulong totalSizeInBytes);
#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
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, totalSizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.CreateOrAllocateResource(
resourceType,
allocationMode,
totalSizeInBytes,
out this.allocation,
out this.d3D12Resource);
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
@@ -142,14 +139,7 @@ public abstract unsafe partial class TransferTexture3D<T> : IReferenceTrackedObj
void IReferenceTrackedObject.DangerousOnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
this.allocation.Dispose();
#endif
if (GraphicsDevice is GraphicsDevice device)
{
device.UnregisterAllocatedResource();
}
}
/// <summary>