Enabled Allocator utilization in resource types
このコミットが含まれているのは:
1 親
c263489b24
コミット
57c4d816c1
8ファイル変更
+299
-72
検索条件に一致するファイルはありません
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with extensions for the <see cref="Allocator"/> type.
|
||||
/// </summary>
|
||||
internal static unsafe class AllocatorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a resource for a given buffer type.
|
||||
/// </summary>
|
||||
/// <param name="allocator">The <see cref="Allocator"/> 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>
|
||||
/// <returns>An <see cref="AllocationPtr"/> reference for the current buffer.</returns>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a resource for a given 2D texture type.
|
||||
/// </summary>
|
||||
/// <param name="allocator">The <see cref="Allocator"/> 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="d3D12ResourceStates">The default <see cref="D3D12_RESOURCE_STATES"/> value for the resource.</param>
|
||||
/// <returns>An <see cref="AllocationPtr"/> reference for the current texture.</returns>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a resource for a given 3D texture type.
|
||||
/// </summary>
|
||||
/// <param name="allocator">The <see cref="Allocator"/> 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="d3D12ResourceStates">The default <see cref="D3D12_RESOURCE_STATES"/> value for the resource.</param>
|
||||
/// <returns>An <see cref="AllocationPtr"/> reference for the current texture.</returns>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace ComputeSharp
|
||||
/// <summary>
|
||||
/// The <see cref="Allocator"/> in use associated to the current device.
|
||||
/// </summary>
|
||||
internal AllocatorPtr allocator;
|
||||
private AllocatorPtr allocator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>.
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="AllocationPtr"/> instance as a managed <see cref="Allocation"/> reference to pointer.
|
||||
/// </summary>
|
||||
/// <returns>The reference to the current <see cref="AllocationPtr"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public readonly ref Allocation* GetPinnableReference()
|
||||
{
|
||||
fixed (Allocation** ptr = &this.pointer)
|
||||
{
|
||||
return ref *ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="AllocationPtr"/> instance as a raw <see langword="void"/> double pointer.
|
||||
/// </summary>
|
||||
|
||||
@@ -64,18 +64,6 @@ namespace ComputeSharp.Graphics
|
||||
return this.pointer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="AllocatorPtr"/> instance as a raw <see cref="Allocator"/> double pointer.
|
||||
/// This method is only valid when the current <see cref="AllocatorPtr"/> instance is on the stack or pinned.
|
||||
/// </summary>
|
||||
/// <returns>The raw pointer to the current <see cref="AllocatorPtr"/> instance.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly Allocator** GetAddressOf()
|
||||
{
|
||||
return (Allocator**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="AllocatorPtr"/> instance as a managed <see cref="Allocator"/> reference to pointer.
|
||||
/// </summary>
|
||||
@@ -89,20 +77,5 @@ namespace ComputeSharp.Graphics
|
||||
return ref *ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the current <see cref="AllocatorPtr"/> instance as a raw <see langword="void"/> double pointer.
|
||||
/// </summary>
|
||||
/// <returns>The raw pointer to the input <see cref="AllocatorPtr"/> instance.</returns>
|
||||
/// <remarks>This method is only valid when the current <see cref="AllocatorPtr"/> instance is on the stack or pinned.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AllocatorPtr Move()
|
||||
{
|
||||
AllocatorPtr copy = this;
|
||||
|
||||
this = default;
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// </summary>
|
||||
protected readonly nint SizeInBytes;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="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 AllocationPtr allocation;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Buffer{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
@@ -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<ID3D12Resource>(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)
|
||||
{
|
||||
|
||||
@@ -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<ID3D12Resource> 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<ID3D12Resource> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
|
||||
|
||||
/// The <see cref="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 AllocationPtr allocation;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Texture2D{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
@@ -79,14 +85,28 @@ namespace ComputeSharp.Resources
|
||||
|
||||
GraphicsDevice = device;
|
||||
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
|
||||
resourceType,
|
||||
allocationMode,
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
device.IsCacheCoherentUMA,
|
||||
out this.d3D12ResourceState);
|
||||
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.d3D12Resource = new ComPtr<ID3D12Resource>(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<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using AllocationPtr allocation = default;
|
||||
using ComPtr<ID3D12Resource> 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<ID3D12Resource>(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<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using AllocationPtr allocation = default;
|
||||
using ComPtr<ID3D12Resource> 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<ID3D12Resource>(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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
|
||||
|
||||
/// The <see cref="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 AllocationPtr allocation;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Texture3D{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
@@ -81,15 +87,30 @@ namespace ComputeSharp.Resources
|
||||
|
||||
GraphicsDevice = device;
|
||||
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
|
||||
resourceType,
|
||||
allocationMode,
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
(ushort)depth,
|
||||
device.IsCacheCoherentUMA,
|
||||
out this.d3D12ResourceState);
|
||||
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.d3D12Resource = new ComPtr<ID3D12Resource>(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<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using AllocationPtr allocation = default;
|
||||
using ComPtr<ID3D12Resource> 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<ID3D12Resource>(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<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using AllocationPtr allocation = default;
|
||||
using ComPtr<ID3D12Resource> 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<ID3D12Resource>(allocation.Get()->GetResource());
|
||||
}
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする