Code refactoring, removed TextureType enum

このコミットが含まれているのは:
Sergio Pedri committed 2020-12-02 23:51:23 +01:00
1 親 02a6fb266e
コミット fcdc69f9fb
12ファイル変更
+79 -94

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

+7 -7
ファイルの表示
@@ -39,8 +39,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
/// <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="elementSizeInBytes">The size in bytes of each buffer item (including padding, if any).</param>
/// <param name="bufferType">The buffer type for the current buffer.</param>
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, BufferType bufferType)
/// <param name="resourceType">The resource type for the current buffer.</param>
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, ResourceType resourceType)
{
device.ThrowIfDisposed();
@@ -50,19 +50,19 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
GraphicsDevice = device;
Length = length;
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(bufferType, (ulong)SizeInBytes);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)SizeInBytes);
device.AllocateShaderResourceViewDescriptorHandles(out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
switch (bufferType)
switch (resourceType)
{
case BufferType.Constant:
case ResourceType.Constant:
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource, SizeInBytes, d3D12CpuDescriptorHandle);
break;
case BufferType.ReadOnly:
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, (uint)length, elementSizeInBytes, d3D12CpuDescriptorHandle);
break;
case BufferType.ReadWrite:
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, (uint)length, elementSizeInBytes, d3D12CpuDescriptorHandle);
break;
}
+5 -5
ファイルの表示
@@ -23,9 +23,9 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
/// </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>
/// <param name="bufferType">The buffer type for the current buffer.</param>
private protected StructuredBuffer(GraphicsDevice device, int length, BufferType bufferType)
: base(device, length, (uint)Unsafe.SizeOf<T>(), bufferType)
/// <param name="resourceType">The buffer type for the current buffer.</param>
private protected StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType)
: base(device, length, (uint)Unsafe.SizeOf<T>(), resourceType)
{
}
@@ -43,7 +43,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
byteOffset = (nint)offset * ElementSizeInBytes,
byteSize = (nint)destination.Length * ElementSizeInBytes;
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(BufferType.ReadBack, (ulong)byteSize);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize);
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
@@ -70,7 +70,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
byteOffset = (nint)offset * ElementSizeInBytes,
byteSize = (nint)source.Length * ElementSizeInBytes;
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(BufferType.Upload, (ulong)byteSize);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
{
+6 -6
ファイルの表示
@@ -34,8 +34,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
/// <param name="device">The <see cref="Graphics.GraphicsDevice"/> associated with the current instance.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="textureType">The texture type for the current texture.</param>
private protected Texture2D(GraphicsDevice device, int width, int height, TextureType textureType)
/// <param name="resourceType">The resource type for the current texture.</param>
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType)
{
device.ThrowIfDisposed();
@@ -46,16 +46,16 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
Width = width;
Height = height;
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(textureType, DXGIFormatHelper.GetForType<T>(), (uint)width, (uint)height);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, DXGIFormatHelper.GetForType<T>(), (uint)width, (uint)height);
device.AllocateShaderResourceViewDescriptorHandles(out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
switch (textureType)
switch (resourceType)
{
case TextureType.ReadOnly:
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, DXGIFormatHelper.GetForType<T>(), d3D12CpuDescriptorHandle);
break;
case TextureType.ReadWrite:
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, DXGIFormatHelper.GetForType<T>(), d3D12CpuDescriptorHandle);
break;
}
+1 -1
ファイルの表示
@@ -32,7 +32,7 @@ namespace ComputeSharp
/// <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(), BufferType.Constant)
: base(device, length, (uint)GetPaddedSize(), ResourceType.Constant)
{
}
-38
ファイルの表示
@@ -1,38 +0,0 @@
namespace ComputeSharp.Graphics.Buffers.Enums
{
/// <summary>
/// An <see langword="enum"/> that indicates the type of a given HLSL buffer.
/// </summary>
internal enum BufferType
{
/// <summary>
/// A constant buffer, with items aligned to 16 bytes, used for individual values or very small arrays.
/// This is mapped to a <see langword="cbuffer"/> in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
/// </summary>
Constant,
/// <summary>
/// A readonly buffer, that can store arbitrary arrays of values and can only be read from by the GPU.
/// This is mapped to a <see langword="StructuredBuffer&lt;T&gt;"/> in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
/// </summary>
ReadOnly,
/// <summary>
/// A read write buffer, that can store arbitrary arrays with both read and write access for the GPU.
/// This is mapped to a <see langword="RWStructuredBuffer&lt;T&gt;"/> in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
/// </summary>
ReadWrite,
/// <summary>
/// A readback buffer, used as temporary buffer to read data back from <see cref="ReadOnly"/> and <see cref="ReadWrite"/> buffers.
/// This has no mapping in HLSL, and is allocated in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_READBACK"/>.
/// </summary>
ReadBack,
/// <summary>
/// A transfer buffer, used as a temporary buffer to set data to <see cref="ReadOnly"/> and <see cref="ReadWrite"/> buffers.
/// This has no mapping in HLSL, and is allocated in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
/// </summary>
Upload
}
}
+43
ファイルの表示
@@ -0,0 +1,43 @@
namespace ComputeSharp.Graphics.Buffers.Enums
{
/// <summary>
/// An <see langword="enum"/> that indicates the type of a given HLSL resource.
/// </summary>
internal enum ResourceType
{
/// <summary>
/// A constant resource, with items aligned to 16 bytes, used for individual values or very small arrays.
/// This is only supported for buffers and is mapped to a <see langword="cbuffer"/>.
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
/// </summary>
Constant,
/// <summary>
/// A readonly resource, that can store arbitrary arrays of values and can only be read from by the GPU.
/// This is mapped to either <see langword="StructuredBuffer&lt;T&gt;"/> or <see langword="TextureND&lt;T&gt;"/>.
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
/// </summary>
ReadOnly,
/// <summary>
/// A read write resource, that can store arbitrary arrays with both read and write access for the GPU.
/// This is mapped to either <see langword="RWStructuredBuffer&lt;T&gt;"/> or <see langword="RWTextureND&lt;T&gt;"/>.
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
/// </summary>
ReadWrite,
/// <summary>
/// A readback resource, used temporarily to read data back from <see cref="ReadOnly"/> and <see cref="ReadWrite"/> resources.
/// This has no direct mapping to a type in HLSL, as it's only used for copy operations.
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_READBACK"/>.
/// </summary>
ReadBack,
/// <summary>
/// A transfer resource, used temporarily to set data to <see cref="ReadOnly"/> and <see cref="ReadWrite"/> resources.
/// This has no direct mapping to a type in HLSL, as it's only used for copy operations (like <see cref="ReadBack"/>).
/// Resources of this type are located in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_UPLOAD"/>.
/// </summary>
Upload
}
}
-20
ファイルの表示
@@ -1,20 +0,0 @@
namespace ComputeSharp.Graphics.Buffers.Enums
{
/// <summary>
/// An <see langword="enum"/> that indicates the type of a given HLSL texture.
/// </summary>
internal enum TextureType
{
/// <summary>
/// A readonly texture, that can store arbitrary arrays of supported values and can only be read from by the GPU.
/// This is mapped to a <see langword="TextureND&lt;T&gt;"/> in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
/// </summary>
ReadOnly,
/// <summary>
/// A read write buffer, that can store arbitrary arrays with both read and write access for the GPU.
/// This is mapped to a <see langword="RWSTextureND&lt;T&gt;"/> in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
/// </summary>
ReadWrite
}
}
+1 -1
ファイルの表示
@@ -22,7 +22,7 @@ namespace ComputeSharp
/// <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, BufferType.ReadOnly)
: base(device, length, ResourceType.ReadOnly)
{
}
+1 -1
ファイルの表示
@@ -21,7 +21,7 @@ namespace ComputeSharp
/// <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, TextureType.ReadOnly)
: base(device, width, height, ResourceType.ReadOnly)
{
}
+1 -1
ファイルの表示
@@ -22,7 +22,7 @@ namespace ComputeSharp
/// <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, BufferType.ReadWrite)
: base(device, length, ResourceType.ReadWrite)
{
}
+1 -1
ファイルの表示
@@ -21,7 +21,7 @@ namespace ComputeSharp
/// <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, TextureType.ReadWrite)
: base(device, width, height, ResourceType.ReadWrite)
{
}
+13 -13
ファイルの表示
@@ -99,23 +99,23 @@ namespace ComputeSharp.Graphics.Extensions
/// Creates a committed resource for a given buffer type.
/// </summary>
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
/// <param name="bufferType">The buffer type currently in use.</param>
/// <param name="resourceType">The resource type currently in use.</param>
/// <param name="sizeInBytes">The size in bytes of the current buffer.</param>
/// <returns>An <see cref="ID3D12Resource"/> reference for the current buffer.</returns>
public static ComPtr<ID3D12Resource> CreateCommittedResource(
this ref ID3D12Device d3D12Device,
BufferType bufferType,
ResourceType resourceType,
ulong sizeInBytes)
{
(D3D12_HEAP_TYPE d3D12HeapType,
D3D12_RESOURCE_FLAGS d3D12ResourceFlags,
D3D12_RESOURCE_STATES d3D12ResourceStates) = bufferType switch
D3D12_RESOURCE_STATES d3D12ResourceStates) = resourceType switch
{
BufferType.Constant => (D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_GENERIC_READ),
BufferType.ReadOnly => (D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COMMON),
BufferType.ReadWrite => (D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COMMON),
BufferType.ReadBack => (D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_DEST),
BufferType.Upload => (D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_GENERIC_READ),
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)>()
};
@@ -145,22 +145,22 @@ namespace ComputeSharp.Graphics.Extensions
/// Creates a committed resource for a given 2D texture type.
/// </summary>
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
/// <param name="textureType">The texture type currently in use.</param>
/// <param name="resourceType">The resource type currently in use.</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>
/// <returns>An <see cref="ID3D12Resource"/> reference for the current texture.</returns>
public static ComPtr<ID3D12Resource> CreateCommittedResource(
this ref ID3D12Device d3D12Device,
TextureType textureType,
ResourceType resourceType,
DXGI_FORMAT dxgiFormat,
uint width,
uint height)
{
D3D12_RESOURCE_FLAGS d3D12ResourceFlags = textureType switch
D3D12_RESOURCE_FLAGS d3D12ResourceFlags = resourceType switch
{
TextureType.ReadOnly => D3D12_RESOURCE_FLAG_NONE,
TextureType.ReadWrite => D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS,
ResourceType.ReadOnly => D3D12_RESOURCE_FLAG_NONE,
ResourceType.ReadWrite => D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS,
_ => ThrowHelper.ThrowArgumentException<D3D12_RESOURCE_FLAGS>()
};