Switched to D3D12MA for all resource allocations

このコミットが含まれているのは:
Sergio Pedri committed 2021-07-12 13:39:48 +02:00
1 親 d0dc1252f0
コミット 862f9e2cdd
12ファイル変更
+140 -369

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

+6
ファイルの表示
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="TerraFX-CI" value="https://pkgs.dev.azure.com/tagoo/terrafx/_packaging/terrafx/nuget/v3/index.json" />
</packageSources>
</configuration>
+1 -1
ファイルの表示
@@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Diagnostics" Version="7.0.1" />
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.19041-beta2" />
<PackageReference Include="TerraFX.Interop.D3D12MemoryAllocator" Version="2.0.0-beta1" />
<PackageReference Include="TerraFX.Interop.D3D12MemoryAllocator" Version="2.0.0-beta2-640232997" />
</ItemGroup>
<ItemGroup>
+32
ファイルの表示
@@ -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
/// </summary>
internal static unsafe class AllocatorExtensions
{
/// <summary>
/// Creates a <see cref="D3D12MA_Pool"/> instance suited to be used for cache coherent UMA devices.
/// </summary>
/// <param name="allocator">The <see cref="D3D12MA_Allocator"/> instance in use.</param>
/// <returns>A <see cref="D3D12MA_Pool"/> instance suited to be used for cache coherent UMA devices.</returns>
public static UniquePtr<D3D12MA_Pool> CreatePoolForCacheCoherentUMA(this ref D3D12MA_Allocator allocator)
{
using UniquePtr<D3D12MA_Pool> 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();
}
/// <summary>
/// Creates a resource for a given buffer type.
/// </summary>
/// <param name="allocator">The <see cref="D3D12MA_Allocator"/> instance in use.</param>
/// <param name="pool">The <see cref="D3D12MA_Pool"/> instance to use, if any.</param>
/// <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>
/// <returns>An <see cref="UniquePtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
public static UniquePtr<D3D12MA_Allocation> 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.
/// </summary>
/// <param name="allocator">The <see cref="D3D12MA_Allocator"/> instance in use.</param>
/// <param name="pool">The <see cref="D3D12MA_Pool"/> instance to use, if any.</param>
/// <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>
@@ -75,6 +102,7 @@ namespace ComputeSharp.Graphics.Extensions
/// <returns>An <see cref="UniquePtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
public static UniquePtr<D3D12MA_Allocation> 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.
/// </summary>
/// <param name="allocator">The <see cref="D3D12MA_Allocator"/> instance in use.</param>
/// <param name="pool">The <see cref="D3D12MA_Pool"/> instance to use, if any.</param>
/// <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>
@@ -126,6 +156,7 @@ namespace ComputeSharp.Graphics.Extensions
/// <returns>An <see cref="UniquePtr{T}"/> reference for the current <see cref="D3D12MA_Allocation"/> object.</returns>
public static UniquePtr<D3D12MA_Allocation> 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,
-199
ファイルの表示
@@ -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();
}
/// <summary>
/// Creates a committed resource for a given buffer type.
/// </summary>
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
/// <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="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,
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<ID3D12Resource> 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<ID3D12Resource>(),
d3D12Resource.GetVoidAddressOf()).Assert();
return d3D12Resource.Move();
}
/// <summary>
/// Creates a committed resource for a given 2D texture type.
/// </summary>
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
/// <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="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(
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<ID3D12Resource> 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<ID3D12Resource>(),
d3D12Resource.GetVoidAddressOf()).Assert();
return d3D12Resource.Move();
}
/// <summary>
/// Creates a committed resource for a given 3D texture type.
/// </summary>
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
/// <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="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(
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<ID3D12Resource> 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<ID3D12Resource>(),
d3D12Resource.GetVoidAddressOf()).Assert();
return d3D12Resource.Move();
}
/// <summary>
/// Creates a view for a constant buffer.
/// </summary>
+18 -5
ファイルの表示
@@ -77,6 +77,11 @@ namespace ComputeSharp
/// </summary>
private UniquePtr<D3D12MA_Allocator> allocator;
/// <summary>
/// The <see cref="D3D12MA_Pool"/> instance in use, if <see cref="IsCacheCoherentUMA"/> is <see langword="true"/>.
/// </summary>
private UniquePtr<D3D12MA_Pool> pool;
/// <summary>
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>.
/// </summary>
@@ -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
/// </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;
/// <summary>
/// Gets whether or not the current device has a cache coherent UMA architecture.
/// </summary>
@@ -339,6 +351,7 @@ namespace ComputeSharp
this.computeCommandAllocatorPool.Dispose();
this.copyCommandAllocatorPool.Dispose();
this.shaderResourceViewDescriptorAllocator.Dispose();
this.pool.Dispose();
this.allocator.Dispose();
return true;
+7 -15
ファイルの表示
@@ -20,6 +20,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class Buffer<T> : NativeObject
where T : unmanaged
{
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
/// </summary>
@@ -40,12 +45,6 @@ namespace ComputeSharp.Resources
/// </summary>
protected readonly nint SizeInBytes;
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if any.
/// </summary>
/// <remarks>This will be <see langword="null"/> if the owning device has <see cref="GraphicsDevice.IsCacheCoherentUMA"/> set.</remarks>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// Creates a new <see cref="Buffer{T}"/> instance with the specified parameters.
/// </summary>
@@ -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<ID3D12Resource>(this.allocation.Get()->GetResource());
}
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)SizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
+2 -2
ファイルの表示
@@ -59,7 +59,7 @@ namespace ComputeSharp.Resources
byteOffset = (nint)offset * sizeof(T),
byteLength = length * sizeof(T);
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
using UniquePtr<D3D12MA_Allocation> 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<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
fixed (void* sourcePointer = &source)
+26 -50
ファイルの表示
@@ -26,6 +26,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
/// </summary>
@@ -56,12 +61,6 @@ namespace ComputeSharp.Resources
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if any.
/// </summary>
/// <remarks>This will be <see langword="null"/> if the owning device has <see cref="GraphicsDevice.IsCacheCoherentUMA"/> set.</remarks>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// Creates a new <see cref="Texture2D{T}"/> instance with the specified parameters.
/// </summary>
@@ -85,29 +84,16 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
if (device.IsCacheCoherentUMA)
{
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
true,
out this.d3D12ResourceState);
}
else
{
this.allocation = device.Allocator->CreateResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12ResourceState);
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12ResourceState);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
}
this.d3D12Resource = new ComPtr<ID3D12Resource>(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<D3D12MA_Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
using UniquePtr<D3D12MA_Allocation> 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<ID3D12Resource>(allocation.Get()->GetResource());
}
using ComPtr<ID3D12Resource> 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<D3D12MA_Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
using UniquePtr<D3D12MA_Allocation> 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<ID3D12Resource>(allocation.Get()->GetResource());
}
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
+27 -52
ファイルの表示
@@ -26,6 +26,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
/// </summary>
@@ -56,12 +61,6 @@ namespace ComputeSharp.Resources
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if any.
/// </summary>
/// <remarks>This will be <see langword="null"/> if the owning device has <see cref="GraphicsDevice.IsCacheCoherentUMA"/> set.</remarks>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// Creates a new <see cref="Texture3D{T}"/> instance with the specified parameters.
/// </summary>
@@ -87,31 +86,17 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
if (device.IsCacheCoherentUMA)
{
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
true,
out this.d3D12ResourceState);
}
else
{
this.allocation = device.Allocator->CreateResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12ResourceState);
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12ResourceState);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
}
this.d3D12Resource = new ComPtr<ID3D12Resource>(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<D3D12MA_Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
using UniquePtr<D3D12MA_Allocation> 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<ID3D12Resource>(allocation.Get()->GetResource());
}
using ComPtr<ID3D12Resource> 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<D3D12MA_Allocation> allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
using UniquePtr<D3D12MA_Allocation> 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<ID3D12Resource>(allocation.Get()->GetResource());
}
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
+7 -15
ファイルの表示
@@ -17,6 +17,11 @@ namespace ComputeSharp.Resources
public abstract unsafe class TransferBuffer<T> : NativeObject, IMemoryOwner<T>
where T : unmanaged
{
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
/// </summary>
@@ -27,12 +32,6 @@ namespace ComputeSharp.Resources
/// </summary>
private readonly T* mappedData;
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if any.
/// </summary>
/// <remarks>This will be <see langword="null"/> if the owning device has <see cref="GraphicsDevice.IsCacheCoherentUMA"/> set.</remarks>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// Creates a new <see cref="TransferBuffer{T}"/> instance with the specified parameters.
/// </summary>
@@ -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<ID3D12Resource>(this.allocation.Get()->GetResource());
}
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, sizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
+7 -15
ファイルの表示
@@ -18,6 +18,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class TransferTexture2D<T> : NativeObject
where T : unmanaged
{
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
/// </summary>
@@ -33,12 +38,6 @@ namespace ComputeSharp.Resources
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if any.
/// </summary>
/// <remarks>This will be <see langword="null"/> if the owning device has <see cref="GraphicsDevice.IsCacheCoherentUMA"/> set.</remarks>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// Creates a new <see cref="TransferTexture2D{T}"/> instance with the specified parameters.
/// </summary>
@@ -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<ID3D12Resource>(this.allocation.Get()->GetResource());
}
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
+7 -15
ファイルの表示
@@ -18,6 +18,11 @@ namespace ComputeSharp.Resources
public unsafe abstract class TransferTexture3D<T> : NativeObject
where T : unmanaged
{
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
/// </summary>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// The <see cref="ID3D12Resource"/> instance currently mapped.
/// </summary>
@@ -33,12 +38,6 @@ namespace ComputeSharp.Resources
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>, if any.
/// </summary>
/// <remarks>This will be <see langword="null"/> if the owning device has <see cref="GraphicsDevice.IsCacheCoherentUMA"/> set.</remarks>
private UniquePtr<D3D12MA_Allocation> allocation;
/// <summary>
/// Creates a new <see cref="TransferTexture3D{T}"/> instance with the specified parameters.
/// </summary>
@@ -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<ID3D12Resource>(this.allocation.Get()->GetResource());
}
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;