Optimized resource management for UMA devices
このコミットが含まれているのは:
1 親
8fcb369a70
コミット
b6f3290866
5ファイル変更
+126
-51
検索条件に一致するファイルはありません
@@ -64,7 +64,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
GraphicsDevice = device;
|
||||
Length = length;
|
||||
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)SizeInBytes);
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)SizeInBytes, device.IsCacheCoherentUMA);
|
||||
|
||||
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
|
||||
|
||||
@@ -37,28 +37,45 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
Guard.IsInRange(offset, 0, Length, nameof(offset));
|
||||
Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
|
||||
|
||||
nint
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteSize = size * sizeof(T);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
copyCommandList.CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset,(ulong)byteSize);
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
fixed (void* destinationPointer = &destination)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
resource.Pointer,
|
||||
(uint)offset,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
destinationPointer);
|
||||
}
|
||||
}
|
||||
|
||||
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
|
||||
|
||||
fixed (void* destinationPointer = &destination)
|
||||
else
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
resource.Pointer,
|
||||
0u,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
destinationPointer);
|
||||
nint
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteSize = size * sizeof(T);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize, false);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
|
||||
{
|
||||
copyCommandList.CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteSize);
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
|
||||
|
||||
fixed (void* destinationPointer = &destination)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
resource.Pointer,
|
||||
0u,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
destinationPointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,27 +89,44 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
Guard.IsInRange(offset, 0, Length, nameof(offset));
|
||||
Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
|
||||
|
||||
nint
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteSize = size * sizeof(T);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize);
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
sourcePointer,
|
||||
0u,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
resource.Pointer);
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
fixed (void* sourcePointer = &source)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
sourcePointer,
|
||||
(uint)offset,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
resource.Pointer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nint
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteSize = size * sizeof(T);
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize, false);
|
||||
|
||||
copyCommandList.CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0,(ulong)byteSize);
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
sourcePointer,
|
||||
0u,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
resource.Pointer);
|
||||
}
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
|
||||
copyCommandList.CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteSize);
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
device.IsCacheCoherentUMA,
|
||||
out this.d3D12ResourceState);
|
||||
|
||||
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
|
||||
@@ -148,7 +149,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
|
||||
{
|
||||
@@ -220,7 +221,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
(ushort)depth,
|
||||
device.IsCacheCoherentUMA,
|
||||
out this.d3D12ResourceState);
|
||||
|
||||
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
|
||||
@@ -162,7 +163,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
|
||||
{
|
||||
@@ -241,7 +242,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
|
||||
@@ -102,11 +102,13 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="resourceType">The resource type currently in use.</param>
|
||||
/// <param name="sizeInBytes">The size in bytes of the current buffer.</param>
|
||||
/// <param name="isCacheCoherentUMA">Indicates whether or not the current device has a cache coherent UMA architecture.</param>
|
||||
/// <returns>An <see cref="ID3D12Resource"/> reference for the current buffer.</returns>
|
||||
public static ComPtr<ID3D12Resource> CreateCommittedResource(
|
||||
this ref ID3D12Device d3D12Device,
|
||||
ResourceType resourceType,
|
||||
ulong sizeInBytes)
|
||||
ulong sizeInBytes,
|
||||
bool isCacheCoherentUMA)
|
||||
{
|
||||
(D3D12_HEAP_TYPE d3D12HeapType,
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags,
|
||||
@@ -123,11 +125,22 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = default;
|
||||
|
||||
D3D12_HEAP_PROPERTIES d3D12HeapProperties;
|
||||
d3D12HeapProperties.Type = d3D12HeapType;
|
||||
d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
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(
|
||||
@@ -150,6 +163,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// <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="isCacheCoherentUMA">Indicates whether or not the current device has a cache coherent UMA architecture.</param>
|
||||
/// <param name="d3D12ResourceStates">The default <see cref="D3D12_RESOURCE_STATES"/> value for the resource.</param>
|
||||
/// <returns>An <see cref="ID3D12Resource"/> reference for the current texture.</returns>
|
||||
public static ComPtr<ID3D12Resource> CreateCommittedResource(
|
||||
@@ -158,6 +172,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
DXGI_FORMAT dxgiFormat,
|
||||
uint width,
|
||||
uint height,
|
||||
bool isCacheCoherentUMA,
|
||||
out D3D12_RESOURCE_STATES d3D12ResourceStates)
|
||||
{
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
|
||||
@@ -172,11 +187,22 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = default;
|
||||
|
||||
D3D12_HEAP_PROPERTIES d3D12HeapProperties;
|
||||
d3D12HeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
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, flags: d3D12ResourceFlags);
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
@@ -200,6 +226,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// <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="isCacheCoherentUMA">Indicates whether or not the current device has a cache coherent UMA architecture.</param>
|
||||
/// <param name="d3D12ResourceStates">The default <see cref="D3D12_RESOURCE_STATES"/> value for the resource.</param>
|
||||
/// <returns>An <see cref="ID3D12Resource"/> reference for the current texture.</returns>
|
||||
public static ComPtr<ID3D12Resource> CreateCommittedResource(
|
||||
@@ -209,6 +236,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
uint width,
|
||||
uint height,
|
||||
ushort depth,
|
||||
bool isCacheCoherentUMA,
|
||||
out D3D12_RESOURCE_STATES d3D12ResourceStates)
|
||||
{
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
|
||||
@@ -223,11 +251,22 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = default;
|
||||
|
||||
D3D12_HEAP_PROPERTIES d3D12HeapProperties;
|
||||
d3D12HeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
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, flags: d3D12ResourceFlags);
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする