diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs index f80e792e..398a93a9 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs @@ -113,7 +113,7 @@ namespace ComputeSharp.Resources ? D3D12_COMMAND_LIST_TYPE_COPY : D3D12_COMMAND_LIST_TYPE_COMPUTE; - GraphicsDevice.D3D12Device->GetCopyableFootprint( + device.D3D12Device->GetCopyableFootprint( DXGIFormatHelper.GetForType(), (uint)width, (uint)height, diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs index 6b5871f8..ba1d3035 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs @@ -117,7 +117,7 @@ namespace ComputeSharp.Resources ? D3D12_COMMAND_LIST_TYPE_COPY : D3D12_COMMAND_LIST_TYPE_COMPUTE; - GraphicsDevice.D3D12Device->GetCopyableFootprint( + device.D3D12Device->GetCopyableFootprint( DXGIFormatHelper.GetForType(), (uint)width, (uint)height, @@ -502,6 +502,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/TransferBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs index 9c52d2a3..922b6e79 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs @@ -2,6 +2,7 @@ using System.Buffers; using System.Runtime.CompilerServices; using ComputeSharp.Exceptions; +using ComputeSharp.Graphics; using ComputeSharp.Graphics.Extensions; using ComputeSharp.Interop; using Microsoft.Toolkit.Diagnostics; @@ -27,6 +28,12 @@ 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. /// @@ -46,7 +53,16 @@ namespace ComputeSharp.Resources ulong sizeInBytes = (uint)length * (uint)sizeof(T); - this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, sizeInBytes, device.IsCacheCoherentUMA); + 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.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer; this.d3D12Resource.Get()->SetName(this); @@ -100,6 +116,7 @@ namespace ComputeSharp.Resources protected override bool OnDispose() { this.d3D12Resource.Dispose(); + this.allocation.Dispose(); return true; } diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs index 003a04c2..bd2f4318 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs @@ -1,5 +1,6 @@ using System.Runtime.CompilerServices; using ComputeSharp.Exceptions; +using ComputeSharp.Graphics; using ComputeSharp.Graphics.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Interop; @@ -33,6 +34,12 @@ 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. /// @@ -55,7 +62,7 @@ namespace ComputeSharp.Resources GraphicsDevice = device; - GraphicsDevice.D3D12Device->GetCopyableFootprint( + device.D3D12Device->GetCopyableFootprint( DXGIFormatHelper.GetForType(), (uint)width, (uint)height, @@ -63,7 +70,16 @@ namespace ComputeSharp.Resources out _, out ulong totalSizeInBytes); - this.d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA); + 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.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer; this.d3D12Resource.Get()->SetName(this); @@ -110,6 +126,7 @@ namespace ComputeSharp.Resources protected override bool OnDispose() { this.d3D12Resource.Dispose(); + this.allocation.Dispose(); return true; } diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs index 3e92d0e5..ce51f3e8 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs @@ -33,6 +33,12 @@ 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. /// @@ -57,7 +63,7 @@ namespace ComputeSharp.Resources GraphicsDevice = device; - GraphicsDevice.D3D12Device->GetCopyableFootprint( + device.D3D12Device->GetCopyableFootprint( DXGIFormatHelper.GetForType(), (uint)width, (uint)height, @@ -66,7 +72,16 @@ namespace ComputeSharp.Resources out _, out ulong totalSizeInBytes); - this.d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(resourceType, allocationMode, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA); + 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.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer; this.d3D12Resource.Get()->SetName(this); @@ -117,6 +132,7 @@ namespace ComputeSharp.Resources protected override bool OnDispose() { this.d3D12Resource.Dispose(); + this.allocation.Dispose(); return true; }