Added AllocationMode option to create resources

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-16 17:23:54 +01:00
1 親 97a2bbc69b
コミット 052e50a8d2
20ファイル変更
+140 -83

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

+1 -1
ファイルの表示
@@ -257,7 +257,7 @@ namespace ComputeSharp.BokehBlur.Processors
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
using ReadWriteTexture2D<Rgba32, Vector4> texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Vector4> temporary = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadWriteTexture2D<Vector4> temporary = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
using ReadWriteTexture2D<Vector4> reals = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadWriteTexture2D<Vector4> imaginaries = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadOnlyBuffer<Complex64> kernel = Gpu.Default.AllocateReadOnlyBuffer<Complex64>(KernelSize);
+12 -3
ファイルの表示
@@ -101,15 +101,18 @@ namespace ComputeSharp.Graphics.Extensions
/// </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_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
(D3D12_HEAP_TYPE d3D12HeapType,
D3D12_RESOURCE_FLAGS d3D12ResourceFlags,
D3D12_RESOURCE_STATES d3D12ResourceStates) = resourceType switch
@@ -145,7 +148,7 @@ namespace ComputeSharp.Graphics.Extensions
d3D12Device.CreateCommittedResource(
&d3D12HeapProperties,
D3D12_HEAP_FLAG_NONE,
d3D12HeapFlags,
&d3D12ResourceDescription,
d3D12ResourceStates,
null,
@@ -160,6 +163,7 @@ namespace ComputeSharp.Graphics.Extensions
/// </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>
@@ -169,12 +173,14 @@ namespace ComputeSharp.Graphics.Extensions
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_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
@@ -207,7 +213,7 @@ namespace ComputeSharp.Graphics.Extensions
d3D12Device.CreateCommittedResource(
&d3D12HeapProperties,
D3D12_HEAP_FLAG_NONE,
d3D12HeapFlags,
&d3D12ResourceDescription,
d3D12ResourceStates,
null,
@@ -222,6 +228,7 @@ namespace ComputeSharp.Graphics.Extensions
/// </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>
@@ -232,6 +239,7 @@ namespace ComputeSharp.Graphics.Extensions
public static ComPtr<ID3D12Resource> CreateCommittedResource(
this ref ID3D12Device d3D12Device,
ResourceType resourceType,
AllocationMode allocationMode,
DXGI_FORMAT dxgiFormat,
uint width,
uint height,
@@ -239,6 +247,7 @@ namespace ComputeSharp.Graphics.Extensions
bool isCacheCoherentUMA,
out D3D12_RESOURCE_STATES d3D12ResourceStates)
{
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
@@ -271,7 +280,7 @@ namespace ComputeSharp.Graphics.Extensions
d3D12Device.CreateCommittedResource(
&d3D12HeapProperties,
D3D12_HEAP_FLAG_NONE,
d3D12HeapFlags,
&d3D12ResourceDescription,
d3D12ResourceStates,
null,
+3 -2
ファイルの表示
@@ -50,7 +50,8 @@ namespace ComputeSharp.Resources
/// <param name="length">The number of items to store in the current buffer.</param>
/// <param name="elementSizeInBytes">The size in bytes of each buffer item (including padding, if any).</param>
/// <param name="resourceType">The resource type for the current buffer.</param>
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, ResourceType resourceType)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, ResourceType resourceType, AllocationMode allocationMode)
{
device.ThrowIfDisposed();
@@ -68,7 +69,7 @@ namespace ComputeSharp.Resources
GraphicsDevice = device;
Length = length;
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)SizeInBytes, device.IsCacheCoherentUMA);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, (ulong)SizeInBytes, device.IsCacheCoherentUMA);
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
+5 -4
ファイルの表示
@@ -22,8 +22,9 @@ namespace ComputeSharp.Resources
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="length">The number of items to store in the current buffer.</param>
/// <param name="resourceType">The buffer type for the current buffer.</param>
private protected unsafe StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType)
: base(device, length, (uint)sizeof(T), resourceType)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
private protected unsafe StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType, AllocationMode allocationMode)
: base(device, length, (uint)sizeof(T), resourceType, allocationMode)
{
}
@@ -57,7 +58,7 @@ namespace ComputeSharp.Resources
byteOffset = (nint)offset * sizeof(T),
byteSize = size * sizeof(T);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize, false);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteSize, false);
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
@@ -109,7 +110,7 @@ namespace ComputeSharp.Resources
byteOffset = (nint)offset * sizeof(T),
byteSize = size * sizeof(T);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize, false);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteSize, false);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
+5 -3
ファイルの表示
@@ -59,8 +59,9 @@ namespace ComputeSharp.Resources
/// <param name="height">The height of the texture.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="resourceType">The resource type for the current texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <param name="d3D12FormatSupport">The format support for the current texture type.</param>
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
{
device.ThrowIfDisposed();
@@ -78,6 +79,7 @@ namespace ComputeSharp.Resources
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
@@ -152,7 +154,7 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -224,7 +226,7 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
+5 -3
ファイルの表示
@@ -60,8 +60,9 @@ namespace ComputeSharp.Resources
/// <param name="width">The width of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="resourceType">The resource type for the current texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <param name="d3D12FormatSupport">The format support for the current texture type.</param>
private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
{
device.ThrowIfDisposed();
@@ -81,6 +82,7 @@ namespace ComputeSharp.Resources
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
@@ -166,7 +168,7 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
@@ -245,7 +247,7 @@ namespace ComputeSharp.Resources
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
+3 -2
ファイルの表示
@@ -35,8 +35,9 @@ namespace ComputeSharp
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="length">The number of items to store in the current buffer.</param>
internal ConstantBuffer(GraphicsDevice device, int length)
: base(device, length, (uint)GetPaddedSize(), ResourceType.Constant)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ConstantBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
: base(device, length, (uint)GetPaddedSize(), ResourceType.Constant, allocationMode)
{
}
+20
ファイルの表示
@@ -0,0 +1,20 @@
namespace ComputeSharp
{
/// <summary>
/// An <see langword="enum"/> that indicates a mode to use when allocating resources.
/// </summary>
public enum AllocationMode
{
/// <summary>
/// The default allocation mode for graphics resources. Allocated buffers are not explicitly cleared when created.
/// They can still be cleared for security reasons in some situations, but this step will be skipped whenever possible.
/// As such, always make sure not to read directly to buffers created this way before writing data to them first.
/// </summary>
Default,
/// <summary>
/// Clear allocated buffers when creating them.
/// </summary>
Clear
}
}
+3 -2
ファイルの表示
@@ -20,8 +20,9 @@ namespace ComputeSharp
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="length">The number of items to store in the current buffer.</param>
internal ReadOnlyBuffer(GraphicsDevice device, int length)
: base(device, length, ResourceType.ReadOnly)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadOnlyBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
: base(device, length, ResourceType.ReadOnly, allocationMode)
{
}
+3 -2
ファイルの表示
@@ -27,8 +27,9 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height)
: base(device, width, height, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
: base(device, width, height, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
{
}
+3 -2
ファイルの表示
@@ -22,8 +22,9 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height)
: base(device, width, height, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
: base(device, width, height, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
{
}
+3 -2
ファイルの表示
@@ -28,8 +28,9 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth)
: base(device, width, height, depth, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
: base(device, width, height, depth, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
{
}
+3 -2
ファイルの表示
@@ -23,8 +23,9 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth)
: base(device, width, height, depth, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
: base(device, width, height, depth, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
{
}
+3 -2
ファイルの表示
@@ -20,8 +20,9 @@ namespace ComputeSharp
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="length">The number of items to store in the current buffer.</param>
internal ReadWriteBuffer(GraphicsDevice device, int length)
: base(device, length, ResourceType.ReadWrite)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadWriteBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
: base(device, length, ResourceType.ReadWrite, allocationMode)
{
}
+3 -2
ファイルの表示
@@ -27,8 +27,9 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height)
: base(device, width, height, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
: base(device, width, height, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}
+3 -2
ファイルの表示
@@ -22,8 +22,9 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height)
: base(device, width, height, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
: base(device, width, height, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}
+3 -2
ファイルの表示
@@ -28,8 +28,9 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth)
: base(device, width, height, depth, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
: base(device, width, height, depth, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}
+3 -2
ファイルの表示
@@ -23,8 +23,9 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth)
: base(device, width, height, depth, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
: base(device, width, height, depth, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}
+1 -1
ファイルの表示
@@ -37,7 +37,7 @@ namespace ComputeSharp.Shaders
{
ConditionalWeakTable<GraphicsDevice, ConstantBuffer<Int4>> map = variablesBuffers ??= new();
return map.GetValue(device, static gpu => new(gpu, 256));
return map.GetValue(device, static gpu => new(gpu, 256, AllocationMode.Default));
}
}
+55 -44
ファイルの表示
@@ -19,12 +19,13 @@ namespace ComputeSharp
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="length">The length of the buffer to allocate.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ConstantBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
[Pure]
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, int length)
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return new(device, length);
return new(device, length, allocationMode);
}
/// <summary>
@@ -52,7 +53,7 @@ namespace ComputeSharp
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> span)
where T : unmanaged
{
ConstantBuffer<T> buffer = new(device, span.Length);
ConstantBuffer<T> buffer = new(device, span.Length, AllocationMode.Default);
buffer.SetData(span);
@@ -70,7 +71,7 @@ namespace ComputeSharp
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
where T : unmanaged
{
ConstantBuffer<T> constantBuffer = new(device, buffer.Length);
ConstantBuffer<T> constantBuffer = new(device, buffer.Length, AllocationMode.Default);
constantBuffer.SetData(buffer);
@@ -83,12 +84,13 @@ namespace ComputeSharp
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="length">The length of the buffer to allocate.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadOnlyBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
[Pure]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, int length)
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return new(device, length);
return new(device, length, allocationMode);
}
/// <summary>
@@ -116,7 +118,7 @@ namespace ComputeSharp
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> span)
where T : unmanaged
{
ReadOnlyBuffer<T> buffer = new(device, span.Length);
ReadOnlyBuffer<T> buffer = new(device, span.Length, AllocationMode.Default);
buffer.SetData(span);
@@ -134,7 +136,7 @@ namespace ComputeSharp
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
where T : unmanaged
{
ReadOnlyBuffer<T> readWriteBuffer = new(device, buffer.Length);
ReadOnlyBuffer<T> readWriteBuffer = new(device, buffer.Length, AllocationMode.Default);
readWriteBuffer.SetData(buffer);
@@ -148,12 +150,13 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadOnlyTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, int width, int height)
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return new(device, width, height);
return new(device, width, height, allocationMode);
}
/// <summary>
@@ -200,7 +203,7 @@ namespace ComputeSharp
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, T[,] array)
where T : unmanaged
{
ReadOnlyTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0));
ReadOnlyTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -220,7 +223,7 @@ namespace ComputeSharp
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height)
where T : unmanaged
{
ReadOnlyTexture2D<T> texture = new(device, width, height);
ReadOnlyTexture2D<T> texture = new(device, width, height, AllocationMode.Default);
texture.SetData(span);
@@ -235,13 +238,14 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadOnlyTexture2D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static ReadOnlyTexture2D<T, TPixel> AllocateReadOnlyTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height)
public static ReadOnlyTexture2D<T, TPixel> AllocateReadOnlyTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
return new(device, width, height);
return new(device, width, height, allocationMode);
}
/// <summary>
@@ -294,7 +298,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadOnlyTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0));
ReadOnlyTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -316,7 +320,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadOnlyTexture2D<T, TPixel> texture = new(device, width, height);
ReadOnlyTexture2D<T, TPixel> texture = new(device, width, height, AllocationMode.Default);
texture.SetData(span);
@@ -331,12 +335,13 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadOnlyTexture3D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>, <paramref name="depth"/>].</returns>
[Pure]
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, int width, int height, int depth)
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return new(device, width, height, depth);
return new(device, width, height, depth, allocationMode);
}
/// <summary>
@@ -389,7 +394,7 @@ namespace ComputeSharp
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, T[,,] array)
where T : unmanaged
{
ReadOnlyTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
ReadOnlyTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -410,7 +415,7 @@ namespace ComputeSharp
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height, int depth)
where T : unmanaged
{
ReadOnlyTexture3D<T> texture = new(device, width, height, depth);
ReadOnlyTexture3D<T> texture = new(device, width, height, depth, AllocationMode.Default);
texture.SetData(span);
@@ -426,13 +431,14 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadOnlyTexture3D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>, <paramref name="depth"/>].</returns>
[Pure]
public static ReadOnlyTexture3D<T, TPixel> AllocateReadOnlyTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth)
public static ReadOnlyTexture3D<T, TPixel> AllocateReadOnlyTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
return new(device, width, height, depth);
return new(device, width, height, depth, allocationMode);
}
/// <summary>
@@ -491,7 +497,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadOnlyTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
ReadOnlyTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -514,7 +520,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadOnlyTexture3D<T, TPixel> texture = new(device, width, height, depth);
ReadOnlyTexture3D<T, TPixel> texture = new(device, width, height, depth, AllocationMode.Default);
texture.SetData(span);
@@ -527,12 +533,13 @@ namespace ComputeSharp
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="length">The length of the buffer to allocate.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadWriteBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
[Pure]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, int length)
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return new(device, length);
return new(device, length, allocationMode);
}
/// <summary>
@@ -560,7 +567,7 @@ namespace ComputeSharp
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> span)
where T : unmanaged
{
ReadWriteBuffer<T> buffer = new(device, span.Length);
ReadWriteBuffer<T> buffer = new(device, span.Length, AllocationMode.Default);
buffer.SetData(span);
@@ -578,7 +585,7 @@ namespace ComputeSharp
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
where T : unmanaged
{
ReadWriteBuffer<T> readWriteBuffer = new(device, buffer.Length);
ReadWriteBuffer<T> readWriteBuffer = new(device, buffer.Length, AllocationMode.Default);
readWriteBuffer.SetData(buffer);
@@ -592,12 +599,13 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadWriteTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, int width, int height)
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return new(device, width, height);
return new(device, width, height, allocationMode);
}
/// <summary>
@@ -644,7 +652,7 @@ namespace ComputeSharp
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, T[,] array)
where T : unmanaged
{
ReadWriteTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0));
ReadWriteTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -664,7 +672,7 @@ namespace ComputeSharp
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height)
where T : unmanaged
{
ReadWriteTexture2D<T> texture = new(device, width, height);
ReadWriteTexture2D<T> texture = new(device, width, height, AllocationMode.Default);
texture.SetData(span);
@@ -679,13 +687,14 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadWriteTexture2D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static ReadWriteTexture2D<T, TPixel> AllocateReadWriteTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height)
public static ReadWriteTexture2D<T, TPixel> AllocateReadWriteTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
return new(device, width, height);
return new(device, width, height, allocationMode);
}
/// <summary>
@@ -738,7 +747,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadWriteTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0));
ReadWriteTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -760,7 +769,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadWriteTexture2D<T, TPixel> texture = new(device, width, height);
ReadWriteTexture2D<T, TPixel> texture = new(device, width, height, AllocationMode.Default);
texture.SetData(span);
@@ -775,12 +784,13 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadWriteTexture3D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, int width, int height, int depth)
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return new(device, width, height, depth);
return new(device, width, height, depth, allocationMode);
}
/// <summary>
@@ -833,7 +843,7 @@ namespace ComputeSharp
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, T[,,] array)
where T : unmanaged
{
ReadWriteTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
ReadWriteTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -854,7 +864,7 @@ namespace ComputeSharp
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height, int depth)
where T : unmanaged
{
ReadWriteTexture3D<T> texture = new(device, width, height, depth);
ReadWriteTexture3D<T> texture = new(device, width, height, depth, AllocationMode.Default);
texture.SetData(span);
@@ -870,13 +880,14 @@ namespace ComputeSharp
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadWriteTexture3D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static ReadWriteTexture3D<T, TPixel> AllocateReadWriteTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth)
public static ReadWriteTexture3D<T, TPixel> AllocateReadWriteTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
return new(device, width, height, depth);
return new(device, width, height, depth, allocationMode);
}
/// <summary>
@@ -935,7 +946,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadWriteTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
ReadWriteTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
texture.SetData(array);
@@ -958,7 +969,7 @@ namespace ComputeSharp
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
ReadWriteTexture3D<T, TPixel> texture = new(device, width, height, depth);
ReadWriteTexture3D<T, TPixel> texture = new(device, width, height, depth, AllocationMode.Default);
texture.SetData(span);