diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs
new file mode 100644
index 00000000..d3ee4e58
--- /dev/null
+++ b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs
@@ -0,0 +1,166 @@
+using ComputeSharp.Core.Extensions;
+using ComputeSharp.Graphics.Resources.Enums;
+using Microsoft.Toolkit.Diagnostics;
+using TerraFX.Interop;
+using static TerraFX.Interop.D3D12_HEAP_TYPE;
+using static TerraFX.Interop.D3D12_RESOURCE_FLAGS;
+using static TerraFX.Interop.D3D12_RESOURCE_STATES;
+using static TerraFX.Interop.ALLOCATION_FLAGS;
+
+namespace ComputeSharp.Graphics.Extensions
+{
+ ///
+ /// A with extensions for the type.
+ ///
+ internal static unsafe class AllocatorExtensions
+ {
+ ///
+ /// Creates a resource for a given buffer type.
+ ///
+ /// The instance in use.
+ /// The resource type currently in use.
+ /// The allocation mode to use for the new resource.
+ /// The size in bytes of the current buffer.
+ /// An reference for the current buffer.
+ public static AllocationPtr CreateResource(
+ this ref Allocator allocator,
+ ResourceType resourceType,
+ AllocationMode allocationMode,
+ ulong sizeInBytes)
+ {
+ ALLOCATION_FLAGS allocationFlags = allocationMode == AllocationMode.Default ? ALLOCATION_FLAG_NONE : ALLOCATION_FLAG_COMMITTED;
+ (D3D12_HEAP_TYPE d3D12HeapType,
+ D3D12_RESOURCE_FLAGS d3D12ResourceFlags,
+ D3D12_RESOURCE_STATES d3D12ResourceStates) = resourceType switch
+ {
+ ResourceType.Constant => (D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_GENERIC_READ),
+ ResourceType.ReadOnly => (D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COMMON),
+ ResourceType.ReadWrite => (D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COMMON),
+ ResourceType.ReadBack => (D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_DEST),
+ ResourceType.Upload => (D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_GENERIC_READ),
+ _ => ThrowHelper.ThrowArgumentException<(D3D12_HEAP_TYPE, D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
+ };
+
+ using AllocationPtr allocation = default;
+
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Buffer(sizeInBytes, d3D12ResourceFlags);
+
+ ALLOCATION_DESC allocationDesc = default;
+ allocationDesc.HeapType = d3D12HeapType;
+ allocationDesc.Flags = allocationFlags;
+
+ allocator.CreateResource(
+ &allocationDesc,
+ &d3D12ResourceDescription,
+ d3D12ResourceStates,
+ null,
+ allocation.GetAddressOf(),
+ null,
+ null).Assert();
+
+ return allocation.Move();
+ }
+
+ ///
+ /// Creates a resource for a given 2D texture type.
+ ///
+ /// The instance in use.
+ /// The resource type currently in use.
+ /// The allocation mode to use for the new resource.
+ /// The value to use.
+ /// The width of the texture resource.
+ /// The height of the texture resource.
+ /// The default value for the resource.
+ /// An reference for the current texture.
+ public static AllocationPtr CreateResource(
+ this ref Allocator allocator,
+ ResourceType resourceType,
+ AllocationMode allocationMode,
+ DXGI_FORMAT dxgiFormat,
+ uint width,
+ uint height,
+ out D3D12_RESOURCE_STATES d3D12ResourceStates)
+ {
+ ALLOCATION_FLAGS allocationFlags = allocationMode == AllocationMode.Default ? ALLOCATION_FLAG_NONE : ALLOCATION_FLAG_COMMITTED;
+ D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
+
+ (d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
+ {
+ ResourceType.ReadOnly => (D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COMMON),
+ ResourceType.ReadWrite => (D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
+ _ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
+ };
+
+ using AllocationPtr allocation = default;
+
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(dxgiFormat, width, height, flags: d3D12ResourceFlags);
+
+ ALLOCATION_DESC allocationDesc = default;
+ allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;
+ allocationDesc.Flags = allocationFlags;
+
+ allocator.CreateResource(
+ &allocationDesc,
+ &d3D12ResourceDescription,
+ d3D12ResourceStates,
+ null,
+ allocation.GetAddressOf(),
+ null,
+ null);
+
+ return allocation.Move();
+ }
+
+ ///
+ /// Creates a resource for a given 3D texture type.
+ ///
+ /// The instance in use.
+ /// The resource type currently in use.
+ /// The allocation mode to use for the new resource.
+ /// The value to use.
+ /// The width of the texture resource.
+ /// The height of the texture resource.
+ /// The depth of the texture resource.
+ /// The default value for the resource.
+ /// An reference for the current texture.
+ public static AllocationPtr CreateResource(
+ this ref Allocator allocator,
+ ResourceType resourceType,
+ AllocationMode allocationMode,
+ DXGI_FORMAT dxgiFormat,
+ uint width,
+ uint height,
+ ushort depth,
+ out D3D12_RESOURCE_STATES d3D12ResourceStates)
+ {
+ ALLOCATION_FLAGS allocationFlags = allocationMode == AllocationMode.Default ? ALLOCATION_FLAG_NONE : ALLOCATION_FLAG_COMMITTED;
+ D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
+
+ (d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
+ {
+ ResourceType.ReadOnly => (D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COMMON),
+ ResourceType.ReadWrite => (D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
+ _ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
+ };
+
+ using AllocationPtr allocation = default;
+
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(dxgiFormat, width, height, depth, flags: d3D12ResourceFlags);
+
+ ALLOCATION_DESC allocationDesc = default;
+ allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;
+ allocationDesc.Flags = allocationFlags;
+
+ allocator.CreateResource(
+ &allocationDesc,
+ &d3D12ResourceDescription,
+ d3D12ResourceStates,
+ null,
+ allocation.GetAddressOf(),
+ null,
+ null);
+
+ return allocation.Move();
+ }
+ }
+}
diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs
index 8462f7ce..b4879f2b 100644
--- a/src/ComputeSharp/Graphics/GraphicsDevice.cs
+++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs
@@ -76,7 +76,7 @@ namespace ComputeSharp
///
/// The in use associated to the current device.
///
- internal AllocatorPtr allocator;
+ private AllocatorPtr allocator;
///
/// Creates a new instance for the input .
diff --git a/src/ComputeSharp/Graphics/Interop/AllocationPtr.cs b/src/ComputeSharp/Graphics/Interop/AllocationPtr.cs
index e9a04e54..9d49141d 100644
--- a/src/ComputeSharp/Graphics/Interop/AllocationPtr.cs
+++ b/src/ComputeSharp/Graphics/Interop/AllocationPtr.cs
@@ -1,5 +1,4 @@
using System;
-using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using TerraFX.Interop;
@@ -76,20 +75,6 @@ namespace ComputeSharp.Graphics
return (Allocation**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
}
- ///
- /// Gets the address of the current instance as a managed reference to pointer.
- ///
- /// The reference to the current instance.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public readonly ref Allocation* GetPinnableReference()
- {
- fixed (Allocation** ptr = &this.pointer)
- {
- return ref *ptr;
- }
- }
-
///
/// Gets the address of the current instance as a raw double pointer.
///
diff --git a/src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs b/src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs
index 1d7033a4..bee25d48 100644
--- a/src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs
+++ b/src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs
@@ -64,18 +64,6 @@ namespace ComputeSharp.Graphics
return this.pointer;
}
- ///
- /// Gets the address of the current instance as a raw double pointer.
- /// This method is only valid when the current instance is on the stack or pinned.
- ///
- /// The raw pointer to the current instance.
- [Pure]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly Allocator** GetAddressOf()
- {
- return (Allocator**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
- }
-
///
/// Gets the address of the current instance as a managed reference to pointer.
///
@@ -89,20 +77,5 @@ namespace ComputeSharp.Graphics
return ref *ptr;
}
}
-
- ///
- /// Gets the address of the current instance as a raw double pointer.
- ///
- /// The raw pointer to the input instance.
- /// This method is only valid when the current instance is on the stack or pinned.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public AllocatorPtr Move()
- {
- AllocatorPtr copy = this;
-
- this = default;
-
- return copy;
- }
}
}
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs
index fbb8ba9b..37164e8f 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs
@@ -2,6 +2,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
+using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Interop;
using Microsoft.Toolkit.Diagnostics;
@@ -38,6 +39,12 @@ namespace ComputeSharp.Resources
///
protected readonly nint SizeInBytes;
+ ///
+ /// The instance used to retrieve , if any.
+ ///
+ /// This will be if the owning device has set.
+ private AllocationPtr allocation;
+
///
/// Creates a new instance with the specified parameters.
///
@@ -64,7 +71,15 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
Length = length;
- this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, (ulong)SizeInBytes, device.IsCacheCoherentUMA);
+ if (device.IsCacheCoherentUMA)
+ {
+ this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, (ulong)SizeInBytes, true);
+ }
+ else
+ {
+ this.allocation = device.Allocator->CreateResource(resourceType, allocationMode, (ulong)SizeInBytes);
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
+ }
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
@@ -156,6 +171,7 @@ namespace ComputeSharp.Resources
protected override bool OnDispose()
{
this.d3D12Resource.Dispose();
+ this.allocation.Dispose();
if (GraphicsDevice?.IsDisposed == false)
{
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs
index 5c25645e..b37a9ad4 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs
@@ -1,4 +1,5 @@
-using ComputeSharp.Graphics.Commands;
+using ComputeSharp.Graphics;
+using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Interop;
@@ -58,15 +59,15 @@ namespace ComputeSharp.Resources
byteOffset = (nint)offset * sizeof(T),
byteLength = length * sizeof(T);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength, false);
+ using AllocationPtr allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteSize);
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
- copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
+ copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(allocation.Get()->GetResource(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteSize);
copyCommandList.ExecuteAndWaitForCompletion();
}
- using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
+ using ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map();
fixed (void* destinationPointer = &destination)
{
@@ -156,9 +157,9 @@ namespace ComputeSharp.Resources
byteOffset = (nint)offset * sizeof(T),
byteLength = length * sizeof(T);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteLength, false);
+ using AllocationPtr allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteSize);
- using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
+ using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy(
@@ -171,7 +172,7 @@ namespace ComputeSharp.Resources
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
- copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteLength);
+ copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, allocation.Get()->GetResource(), 0, (ulong)byteSize);
copyCommandList.ExecuteAndWaitForCompletion();
}
}
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs
index 9510905c..ca07242b 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using ComputeSharp.Exceptions;
+using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
@@ -56,6 +57,11 @@ namespace ComputeSharp.Resources
///
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
+ /// The instance used to retrieve , if any.
+ ///
+ /// This will be if the owning device has set.
+ private AllocationPtr allocation;
+
///
/// Creates a new instance with the specified parameters.
///
@@ -79,14 +85,28 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
- this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
- resourceType,
- allocationMode,
- DXGIFormatHelper.GetForType(),
- (uint)width,
- (uint)height,
- device.IsCacheCoherentUMA,
- out this.d3D12ResourceState);
+ if (device.IsCacheCoherentUMA)
+ {
+ this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
+ resourceType,
+ allocationMode,
+ DXGIFormatHelper.GetForType(),
+ (uint)width,
+ (uint)height,
+ true,
+ out this.d3D12ResourceState);
+ }
+ else
+ {
+ this.allocation = device.Allocator->CreateResource(
+ resourceType,
+ allocationMode,
+ DXGIFormatHelper.GetForType(),
+ (uint)width,
+ (uint)height,
+ out this.d3D12ResourceState);
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
+ }
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
@@ -166,7 +186,18 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
+ using AllocationPtr allocation = default;
+ using ComPtr d3D12Resource = default;
+
+ if (GraphicsDevice.IsCacheCoherentUMA)
+ {
+ *&d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, true);
+ }
+ else
+ {
+ *&allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes);
+ *&d3D12Resource = new ComPtr(allocation.Get()->GetResource());
+ }
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -305,7 +336,18 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
+ using AllocationPtr allocation = default;
+ using ComPtr d3D12Resource = default;
+
+ if (GraphicsDevice.IsCacheCoherentUMA)
+ {
+ *&d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, true);
+ }
+ else
+ {
+ *&allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes);
+ *&d3D12Resource = new ComPtr(allocation.Get()->GetResource());
+ }
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
@@ -415,6 +457,7 @@ namespace ComputeSharp.Resources
protected override bool OnDispose()
{
this.d3D12Resource.Dispose();
+ this.allocation.Dispose();
if (GraphicsDevice?.IsDisposed == false)
{
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs
index 3b1c9253..8de2ee64 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using ComputeSharp.Exceptions;
+using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
@@ -56,6 +57,11 @@ namespace ComputeSharp.Resources
///
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
+ /// The instance used to retrieve , if any.
+ ///
+ /// This will be if the owning device has set.
+ private AllocationPtr allocation;
+
///
/// Creates a new instance with the specified parameters.
///
@@ -81,15 +87,30 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
- this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
- resourceType,
- allocationMode,
- DXGIFormatHelper.GetForType(),
- (uint)width,
- (uint)height,
- (ushort)depth,
- device.IsCacheCoherentUMA,
- out this.d3D12ResourceState);
+ if (device.IsCacheCoherentUMA)
+ {
+ this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
+ resourceType,
+ allocationMode,
+ DXGIFormatHelper.GetForType(),
+ (uint)width,
+ (uint)height,
+ (ushort)depth,
+ true,
+ out this.d3D12ResourceState);
+ }
+ else
+ {
+ this.allocation = device.Allocator->CreateResource(
+ resourceType,
+ allocationMode,
+ DXGIFormatHelper.GetForType(),
+ (uint)width,
+ (uint)height,
+ (ushort)depth,
+ out this.d3D12ResourceState);
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
+ }
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
@@ -181,7 +202,18 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
+ using AllocationPtr allocation = default;
+ using ComPtr d3D12Resource = default;
+
+ if (GraphicsDevice.IsCacheCoherentUMA)
+ {
+ *&d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, true);
+ }
+ else
+ {
+ *&allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes);
+ *&d3D12Resource = new ComPtr(allocation.Get()->GetResource());
+ }
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -337,7 +369,18 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
+ using AllocationPtr allocation = default;
+ using ComPtr d3D12Resource = default;
+
+ if (GraphicsDevice.IsCacheCoherentUMA)
+ {
+ *&d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, true);
+ }
+ else
+ {
+ *&allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes);
+ *&d3D12Resource = new ComPtr(allocation.Get()->GetResource());
+ }
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)