Added initial Texture2D<T> base type
このコミットが含まれているのは:
1 親
5fdf6d4c5c
コミット
4c8fadac6f
5ファイル変更
+121
-16
検索条件に一致するファイルはありません
@@ -40,7 +40,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <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>
|
||||
internal Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, BufferType bufferType)
|
||||
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, BufferType bufferType)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="GraphicsDevice"/> associated with the current instance.
|
||||
/// Gets the <see cref="Graphics.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ 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="bufferType">The buffer type for the current buffer.</param>
|
||||
internal StructuredBuffer(GraphicsDevice device, int length, BufferType bufferType)
|
||||
private protected StructuredBuffer(GraphicsDevice device, int length, BufferType bufferType)
|
||||
: base(device, length, (uint)Unsafe.SizeOf<T>(), bufferType)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Core.Interop;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> representing a typed 2D texture stored on GPU memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
public unsafe abstract class Texture2D<T> : NativeObject
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Resource> d3D12Resource;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Buffer{T}"/> instance with the specified parameters.
|
||||
/// </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="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 Texture2D(GraphicsDevice device, int height, int width, TextureType textureType)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
|
||||
Guard.IsGreaterThanOrEqualTo(height, 0, nameof(height));
|
||||
Guard.IsGreaterThanOrEqualTo(width, 0, nameof(width));
|
||||
|
||||
GraphicsDevice = device;
|
||||
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(textureType, DXGIFormatHelper.GetForType<T>(), (uint)height, (uint)width);
|
||||
|
||||
device.AllocateShaderResourceViewDescriptorHandles(out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
|
||||
switch (textureType)
|
||||
{
|
||||
case TextureType.ReadOnly:
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, DXGIFormatHelper.GetForType<T>(), d3D12CpuDescriptorHandle);
|
||||
break;
|
||||
case TextureType.ReadWrite:
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, DXGIFormatHelper.GetForType<T>(), d3D12CpuDescriptorHandle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Graphics.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
/// </summary>
|
||||
internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
{
|
||||
this.d3D12Resource.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a <see cref="GraphicsDeviceMismatchException"/> if the target device doesn't match the current one.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void ThrowIfDeviceMismatch(GraphicsDevice device)
|
||||
{
|
||||
if (GraphicsDevice != device)
|
||||
{
|
||||
GraphicsDeviceMismatchException.Throw(this, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする