diff --git a/nuget.config b/nuget.config
new file mode 100644
index 00000000..8459c53d
--- /dev/null
+++ b/nuget.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj
index b536e834..a5287ab1 100644
--- a/src/ComputeSharp/ComputeSharp.csproj
+++ b/src/ComputeSharp/ComputeSharp.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs
index 1e77beb6..2998ce2a 100644
--- a/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Interop/AllocatorExtensions.cs
@@ -2,7 +2,9 @@
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;
@@ -15,16 +17,39 @@ namespace ComputeSharp.Graphics.Extensions
///
internal static unsafe class AllocatorExtensions
{
+ ///
+ /// Creates a instance suited to be used for cache coherent UMA devices.
+ ///
+ /// The instance in use.
+ /// A instance suited to be used for cache coherent UMA devices.
+ public static UniquePtr CreatePoolForCacheCoherentUMA(this ref D3D12MA_Allocator allocator)
+ {
+ using UniquePtr pool = default;
+
+ D3D12MA_POOL_DESC poolDesc = default;
+ poolDesc.HeapProperties.CreationNodeMask = 1;
+ poolDesc.HeapProperties.VisibleNodeMask = 1;
+ poolDesc.HeapProperties.Type = D3D12_HEAP_TYPE_CUSTOM;
+ poolDesc.HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_WRITE_BACK;
+ poolDesc.HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_L0;
+
+ allocator.CreatePool(&poolDesc, pool.GetAddressOf()).Assert();
+
+ return pool.Move();
+ }
+
///
/// Creates a resource for a given buffer type.
///
/// The instance in use.
+ /// The instance to use, if any.
/// The resource type currently in use.
/// The allocation mode to use for the new resource.
/// The size in bytes of the current buffer.
/// An reference for the current object.
public static UniquePtr CreateResource(
this ref D3D12MA_Allocator allocator,
+ D3D12MA_Pool* pool,
ResourceType resourceType,
AllocationMode allocationMode,
ulong sizeInBytes)
@@ -49,6 +74,7 @@ namespace ComputeSharp.Graphics.Extensions
D3D12MA_ALLOCATION_DESC allocationDesc = default;
allocationDesc.HeapType = d3D12HeapType;
allocationDesc.Flags = allocationFlags;
+ allocationDesc.CustomPool = pool;
allocator.CreateResource(
&allocationDesc,
@@ -66,6 +92,7 @@ namespace ComputeSharp.Graphics.Extensions
/// Creates a resource for a given 2D texture type.
///
/// The instance in use.
+ /// The instance to use, if any.
/// The resource type currently in use.
/// The allocation mode to use for the new resource.
/// The value to use.
@@ -75,6 +102,7 @@ namespace ComputeSharp.Graphics.Extensions
/// An reference for the current object.
public static UniquePtr CreateResource(
this ref D3D12MA_Allocator allocator,
+ D3D12MA_Pool* pool,
ResourceType resourceType,
AllocationMode allocationMode,
DXGI_FORMAT dxgiFormat,
@@ -99,6 +127,7 @@ namespace ComputeSharp.Graphics.Extensions
D3D12MA_ALLOCATION_DESC allocationDesc = default;
allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;
allocationDesc.Flags = allocationFlags;
+ allocationDesc.CustomPool = pool;
allocator.CreateResource(
&allocationDesc,
@@ -116,6 +145,7 @@ namespace ComputeSharp.Graphics.Extensions
/// Creates a resource for a given 3D texture type.
///
/// The instance in use.
+ /// The instance to use, if any.
/// The resource type currently in use.
/// The allocation mode to use for the new resource.
/// The value to use.
@@ -126,6 +156,7 @@ namespace ComputeSharp.Graphics.Extensions
/// An reference for the current object.
public static UniquePtr CreateResource(
this ref D3D12MA_Allocator allocator,
+ D3D12MA_Pool* pool,
ResourceType resourceType,
AllocationMode allocationMode,
DXGI_FORMAT dxgiFormat,
@@ -151,6 +182,7 @@ namespace ComputeSharp.Graphics.Extensions
D3D12MA_ALLOCATION_DESC allocationDesc = default;
allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;
allocationDesc.Flags = allocationFlags;
+ allocationDesc.CustomPool = pool;
allocator.CreateResource(
&allocationDesc,
diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs
index e04ba09a..7d0f7dbf 100644
--- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs
@@ -1,25 +1,17 @@
using System;
using System.Diagnostics.Contracts;
using ComputeSharp.Core.Extensions;
-using ComputeSharp.Graphics.Helpers;
-using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_COMMAND_QUEUE_FLAGS;
using static TerraFX.Interop.D3D12_COMMAND_QUEUE_PRIORITY;
-using static TerraFX.Interop.D3D12_CPU_PAGE_PROPERTY;
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_MEMORY_POOL;
using static TerraFX.Interop.D3D12_MESSAGE_ID;
-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.D3D12_SRV_DIMENSION;
using static TerraFX.Interop.D3D12_UAV_DIMENSION;
using FX = TerraFX.Interop.Windows;
-using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
namespace ComputeSharp.Graphics.Extensions
{
@@ -125,197 +117,6 @@ namespace ComputeSharp.Graphics.Extensions
return d3D12DescriptorHeap.Move();
}
- ///
- /// Creates a committed 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.
- /// Indicates whether or not the current device has a cache coherent UMA architecture.
- /// An reference for the current buffer.
- public static ComPtr CreateCommittedResource(
- this ref ID3D12Device d3D12Device,
- ResourceType resourceType,
- AllocationMode allocationMode,
- ulong sizeInBytes,
- bool isCacheCoherentUMA)
- {
- (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 ComPtr d3D12Resource = default;
-
- D3D12_HEAP_PROPERTIES d3D12HeapProperties;
- d3D12HeapProperties.CreationNodeMask = 1;
- d3D12HeapProperties.VisibleNodeMask = 1;
-
- if (isCacheCoherentUMA)
- {
- d3D12HeapProperties.Type = D3D12_HEAP_TYPE_CUSTOM;
- d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_WRITE_BACK;
- d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_L0;
- }
- else
- {
- d3D12HeapProperties.Type = d3D12HeapType;
- d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
- d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
- }
-
- D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Buffer(sizeInBytes, d3D12ResourceFlags);
-
- d3D12Device.CreateCommittedResource(
- &d3D12HeapProperties,
- D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
- &d3D12ResourceDescription,
- d3D12ResourceStates,
- null,
- FX.__uuidof(),
- d3D12Resource.GetVoidAddressOf()).Assert();
-
- return d3D12Resource.Move();
- }
-
- ///
- /// Creates a committed 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.
- /// Indicates whether or not the current device has a cache coherent UMA architecture.
- /// The default value for the resource.
- /// An reference for the current texture.
- public static ComPtr CreateCommittedResource(
- this ref ID3D12Device d3D12Device,
- ResourceType resourceType,
- AllocationMode allocationMode,
- DXGI_FORMAT dxgiFormat,
- uint width,
- uint height,
- bool isCacheCoherentUMA,
- out D3D12_RESOURCE_STATES d3D12ResourceStates)
- {
- 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 ComPtr d3D12Resource = default;
-
- D3D12_HEAP_PROPERTIES d3D12HeapProperties;
- d3D12HeapProperties.CreationNodeMask = 1;
- d3D12HeapProperties.VisibleNodeMask = 1;
-
- if (isCacheCoherentUMA)
- {
- d3D12HeapProperties.Type = D3D12_HEAP_TYPE_CUSTOM;
- d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_WRITE_BACK;
- d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_L0;
- }
- else
- {
- d3D12HeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
- d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
- d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
- }
-
- D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(dxgiFormat, width, height, mipLevels: 1, flags: d3D12ResourceFlags);
-
- d3D12Device.CreateCommittedResource(
- &d3D12HeapProperties,
- D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
- &d3D12ResourceDescription,
- d3D12ResourceStates,
- null,
- FX.__uuidof(),
- d3D12Resource.GetVoidAddressOf()).Assert();
-
- return d3D12Resource.Move();
- }
-
- ///
- /// Creates a committed 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.
- /// Indicates whether or not the current device has a cache coherent UMA architecture.
- /// The default value for the resource.
- /// An reference for the current texture.
- public static ComPtr CreateCommittedResource(
- this ref ID3D12Device d3D12Device,
- ResourceType resourceType,
- AllocationMode allocationMode,
- DXGI_FORMAT dxgiFormat,
- uint width,
- uint height,
- ushort depth,
- bool isCacheCoherentUMA,
- out D3D12_RESOURCE_STATES d3D12ResourceStates)
- {
- 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 ComPtr d3D12Resource = default;
-
- D3D12_HEAP_PROPERTIES d3D12HeapProperties;
- d3D12HeapProperties.CreationNodeMask = 1;
- d3D12HeapProperties.VisibleNodeMask = 1;
-
- if (isCacheCoherentUMA)
- {
- d3D12HeapProperties.Type = D3D12_HEAP_TYPE_CUSTOM;
- d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_WRITE_BACK;
- d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_L0;
- }
- else
- {
- d3D12HeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
- d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
- d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
- }
-
- D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(dxgiFormat, width, height, depth, mipLevels: 1, flags: d3D12ResourceFlags);
-
- d3D12Device.CreateCommittedResource(
- &d3D12HeapProperties,
- D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
- &d3D12ResourceDescription,
- d3D12ResourceStates,
- null,
- FX.__uuidof(),
- d3D12Resource.GetVoidAddressOf()).Assert();
-
- return d3D12Resource.Move();
- }
-
///
/// Creates a view for a constant buffer.
///
diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs
index c9341815..ebdff56e 100644
--- a/src/ComputeSharp/Graphics/GraphicsDevice.cs
+++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs
@@ -77,6 +77,11 @@ namespace ComputeSharp
///
private UniquePtr allocator;
+ ///
+ /// The instance in use, if is .
+ ///
+ private UniquePtr pool;
+
///
/// Creates a new instance for the input .
///
@@ -114,12 +119,14 @@ namespace ComputeSharp
allocatorDesc.pDevice = d3D12Device;
allocatorDesc.pAdapter = dxgiAdapter;
- if (!IsCacheCoherentUMA)
+ fixed (D3D12MA_Allocator** allocator = this.allocator)
{
- fixed (D3D12MA_Allocator** allocator = this.allocator)
- {
- D3D12MemAlloc.D3D12MA_CreateAllocator(&allocatorDesc, allocator).Assert();
- }
+ D3D12MemAlloc.D3D12MA_CreateAllocator(&allocatorDesc, allocator).Assert();
+ }
+
+ if (IsCacheCoherentUMA)
+ {
+ this.pool = this.allocator.Get()->CreatePoolForCacheCoherentUMA();
}
}
@@ -169,6 +176,11 @@ namespace ComputeSharp
///
internal D3D12MA_Allocator* Allocator => this.allocator;
+ ///
+ /// Gets the underlying wrapped by the current instance, if any.
+ ///
+ internal D3D12MA_Pool* Pool => this.pool;
+
///
/// Gets whether or not the current device has a cache coherent UMA architecture.
///
@@ -339,6 +351,7 @@ namespace ComputeSharp
this.computeCommandAllocatorPool.Dispose();
this.copyCommandAllocatorPool.Dispose();
this.shaderResourceViewDescriptorAllocator.Dispose();
+ this.pool.Dispose();
this.allocator.Dispose();
return true;
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs
index 57723d53..b3bc0bb1 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs
@@ -20,6 +20,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class Buffer : NativeObject
where T : unmanaged
{
+ ///
+ /// The instance used to retrieve .
+ ///
+ private UniquePtr allocation;
+
///
/// The instance currently mapped.
///
@@ -40,12 +45,6 @@ namespace ComputeSharp.Resources
///
protected readonly nint SizeInBytes;
- ///
- /// The instance used to retrieve , if any.
- ///
- /// This will be if the owning device has set.
- private UniquePtr allocation;
-
///
/// Creates a new instance with the specified parameters.
///
@@ -78,15 +77,8 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
Length = length;
- 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());
- }
+ this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)SizeInBytes);
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs
index 1266141d..dc7ca98b 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/StructuredBuffer{T}.cs
@@ -59,7 +59,7 @@ namespace ComputeSharp.Resources
byteOffset = (nint)offset * sizeof(T),
byteLength = length * sizeof(T);
- using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
+ using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
@@ -157,7 +157,7 @@ namespace ComputeSharp.Resources
byteOffset = (nint)offset * sizeof(T),
byteLength = length * sizeof(T);
- using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
+ using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
fixed (void* sourcePointer = &source)
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs
index 5cfdce19..172ee5f9 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs
@@ -26,6 +26,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
+ ///
+ /// The instance used to retrieve .
+ ///
+ private UniquePtr allocation;
+
///
/// The instance currently mapped.
///
@@ -56,12 +61,6 @@ 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 UniquePtr allocation;
-
///
/// Creates a new instance with the specified parameters.
///
@@ -85,29 +84,16 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
- 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.allocation = device.Allocator->CreateResource(
+ device.Pool,
+ resourceType,
+ allocationMode,
+ DXGIFormatHelper.GetForType(),
+ (uint)width,
+ (uint)height,
+ out this.d3D12ResourceState);
- this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
- }
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
@@ -187,18 +173,13 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using UniquePtr allocation = default;
- using ComPtr d3D12Resource = default;
+ using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(
+ GraphicsDevice.Pool,
+ ResourceType.ReadBack,
+ AllocationMode.Default,
+ totalSizeInBytes);
- 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 ComPtr d3D12Resource = new(allocation.Get()->GetResource());
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -337,18 +318,13 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using UniquePtr allocation = default;
- using ComPtr d3D12Resource = default;
+ using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(
+ GraphicsDevice.Pool,
+ ResourceType.Upload,
+ AllocationMode.Default,
+ totalSizeInBytes);
- 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 ComPtr d3D12Resource = new(allocation.Get()->GetResource());
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs
index f0c14da2..917675c7 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs
@@ -26,6 +26,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
+ ///
+ /// The instance used to retrieve .
+ ///
+ private UniquePtr allocation;
+
///
/// The instance currently mapped.
///
@@ -56,12 +61,6 @@ 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 UniquePtr allocation;
-
///
/// Creates a new instance with the specified parameters.
///
@@ -87,31 +86,17 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
- 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.allocation = device.Allocator->CreateResource(
+ device.Pool,
+ resourceType,
+ allocationMode,
+ DXGIFormatHelper.GetForType(),
+ (uint)width,
+ (uint)height,
+ (ushort)depth,
+ out this.d3D12ResourceState);
- this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
- }
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
@@ -203,18 +188,13 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using UniquePtr allocation = default;
- using ComPtr d3D12Resource = default;
+ using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(
+ GraphicsDevice.Pool,
+ ResourceType.ReadBack,
+ AllocationMode.Default,
+ totalSizeInBytes);
- 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 ComPtr d3D12Resource = new(allocation.Get()->GetResource());
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -370,18 +350,13 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
- using UniquePtr allocation = default;
- using ComPtr d3D12Resource = default;
+ using UniquePtr allocation = GraphicsDevice.Allocator->CreateResource(
+ GraphicsDevice.Pool,
+ ResourceType.Upload,
+ AllocationMode.Default,
+ totalSizeInBytes);
- 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 ComPtr d3D12Resource = new(allocation.Get()->GetResource());
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs
index 66887f0c..d3625203 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs
@@ -17,6 +17,11 @@ namespace ComputeSharp.Resources
public abstract unsafe class TransferBuffer : NativeObject, IMemoryOwner
where T : unmanaged
{
+ ///
+ /// The instance used to retrieve .
+ ///
+ private UniquePtr allocation;
+
///
/// The instance currently mapped.
///
@@ -27,12 +32,6 @@ namespace ComputeSharp.Resources
///
private readonly T* mappedData;
- ///
- /// The instance used to retrieve , if any.
- ///
- /// This will be if the owning device has set.
- private UniquePtr allocation;
-
///
/// Creates a new instance with the specified parameters.
///
@@ -52,15 +51,8 @@ namespace ComputeSharp.Resources
ulong sizeInBytes = (uint)length * (uint)sizeof(T);
- if (device.IsCacheCoherentUMA)
- {
- this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, sizeInBytes, true);
- }
- else
- {
- this.allocation = device.Allocator->CreateResource(resourceType, allocationMode, sizeInBytes);
- this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
- }
+ this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, sizeInBytes);
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs
index 4a5e2d61..593c0079 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs
@@ -18,6 +18,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class TransferTexture2D : NativeObject
where T : unmanaged
{
+ ///
+ /// The instance used to retrieve .
+ ///
+ private UniquePtr allocation;
+
///
/// The instance currently mapped.
///
@@ -33,12 +38,6 @@ 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 UniquePtr allocation;
-
///
/// Creates a new instance with the specified parameters.
///
@@ -69,15 +68,8 @@ namespace ComputeSharp.Resources
out _,
out ulong totalSizeInBytes);
- if (device.IsCacheCoherentUMA)
- {
- this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, true);
- }
- else
- {
- this.allocation = device.Allocator->CreateResource(resourceType, allocationMode, totalSizeInBytes);
- this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
- }
+ this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs
index 0085661b..0f82c7b9 100644
--- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs
+++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs
@@ -18,6 +18,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class TransferTexture3D : NativeObject
where T : unmanaged
{
+ ///
+ /// The instance used to retrieve .
+ ///
+ private UniquePtr allocation;
+
///
/// The instance currently mapped.
///
@@ -33,12 +38,6 @@ 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 UniquePtr allocation;
-
///
/// Creates a new instance with the specified parameters.
///
@@ -72,15 +71,8 @@ namespace ComputeSharp.Resources
out _,
out ulong totalSizeInBytes);
- if (device.IsCacheCoherentUMA)
- {
- this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, true);
- }
- else
- {
- this.allocation = device.Allocator->CreateResource(resourceType, allocationMode, totalSizeInBytes);
- this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
- }
+ this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
+ this.d3D12Resource = new ComPtr(this.allocation.Get()->GetResource());
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;