Added more texture type validation APIs

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-15 20:16:48 +01:00
1 親 345cd58d19
コミット 7629dee8c0
13ファイル変更
+68 -26

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

+3 -3
ファイルの表示
@@ -35,12 +35,12 @@ namespace ComputeSharp.Exceptions
builder.AppendLine(rank switch
{
2 => $"{nameof(GraphicsDevice.IsTexture2DSupportedForType)}<T>().",
3 => $"{nameof(GraphicsDevice.IsTexture3DSupportedForType)}<T>().",
2 => $"{nameof(GraphicsDevice.IsReadOnlyTexture2DSupportedForType)}<T>() or {nameof(GraphicsDevice.IsReadWriteTexture2DSupportedForType)}<T>().",
3 => $"{nameof(GraphicsDevice.IsReadOnlyTexture3DSupportedForType)}<T>() or {nameof(GraphicsDevice.IsReadWriteTexture3DSupportedForType)}<T>().",
_ => ThrowHelper.ThrowArgumentException<string>("Invalid texture rank")
});
builder.AppendLine($"As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
builder.AppendLine("As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
builder.ToString();
return new(builder.ToString());
+1 -1
ファイルの表示
@@ -505,7 +505,7 @@ namespace ComputeSharp.Graphics.Extensions
d3D12Device.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &d3D12FeatureDataFormatSupport, (uint)sizeof(D3D12_FEATURE_DATA_FORMAT_SUPPORT)).Assert();
return (d3D12FeatureDataFormatSupport.Support1 & d3D12FormatSupport1) != 0;
return (d3D12FeatureDataFormatSupport.Support1 & d3D12FormatSupport1) == d3D12FormatSupport1;
}
}
}
+42 -8
ファイルの表示
@@ -152,13 +152,13 @@ namespace ComputeSharp
internal bool IsCacheCoherentUMA { get; }
/// <summary>
/// Checks whether the current device supports the creation of <see cref="Resources.Texture2D{T}"/>
/// resources for a specified type <typeparamref name="T"/>.
/// Checks whether the current device supports the creation of
/// <see cref="ReadOnlyTexture2D{T}"/> resources for a specified type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of values to check support for.</typeparam>
/// <returns>Whether <see cref="Resources.Texture2D{T}"/> instances can be created by the current device.</returns>
/// <returns>Whether <see cref="ReadOnlyTexture2D{T}"/> instances can be created by the current device.</returns>
[Pure]
public bool IsTexture2DSupportedForType<T>()
public bool IsReadOnlyTexture2DSupportedForType<T>()
where T : unmanaged
{
ThrowIfDisposed();
@@ -167,13 +167,30 @@ namespace ComputeSharp
}
/// <summary>
/// Checks whether the current device supports the creation of <see cref="Resources.Texture3D{T}"/>
/// resources for a specified type <typeparamref name="T"/>.
/// Checks whether the current device supports the creation of
/// <see cref="ReadWriteTexture2D{T}"/> resources for a specified type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of values to check support for.</typeparam>
/// <returns>Whether <see cref="Resources.Texture3D{T}"/> instances can be created by the current device.</returns>
/// <returns>Whether <see cref="ReadWriteTexture2D{T}"/> instances can be created by the current device.</returns>
[Pure]
public bool IsTexture3DSupportedForType<T>()
public bool IsReadWriteTexture2DSupportedForType<T>()
where T : unmanaged
{
ThrowIfDisposed();
return this.d3D12Device.Get()->IsDxgiFormatSupported(
DXGIFormatHelper.GetForType<T>(),
D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
}
/// <summary>
/// Checks whether the current device supports the creation of
/// <see cref="ReadOnlyTexture3D{T}"/> resources for a specified type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of values to check support for.</typeparam>
/// <returns>Whether <see cref="ReadOnlyTexture3D{T}"/> instances can be created by the current device.</returns>
[Pure]
public bool IsReadOnlyTexture3DSupportedForType<T>()
where T : unmanaged
{
ThrowIfDisposed();
@@ -181,6 +198,23 @@ namespace ComputeSharp
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D);
}
/// <summary>
/// Checks whether the current device supports the creation of
/// <see cref="ReadWriteTexture3D{T}"/> resources for a specified type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of values to check support for.</typeparam>
/// <returns>Whether <see cref="ReadWriteTexture3D{T}"/> instances can be created by the current device.</returns>
[Pure]
public bool IsReadWriteTexture3DSupportedForType<T>()
where T : unmanaged
{
ThrowIfDisposed();
return this.d3D12Device.Get()->IsDxgiFormatSupported(
DXGIFormatHelper.GetForType<T>(),
D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
}
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Rent"/>
internal void RentShaderResourceViewDescriptorHandles(
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
+3 -3
ファイルの表示
@@ -10,7 +10,6 @@ using ComputeSharp.Interop;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
using static TerraFX.Interop.D3D12_SRV_DIMENSION;
using static TerraFX.Interop.D3D12_UAV_DIMENSION;
@@ -60,14 +59,15 @@ 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>
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType)
/// <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)
{
device.ThrowIfDisposed();
Guard.IsBetweenOrEqualTo(width, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width));
Guard.IsBetweenOrEqualTo(height, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height));
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
{
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
+3 -3
ファイルの表示
@@ -10,7 +10,6 @@ using ComputeSharp.Interop;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
using static TerraFX.Interop.D3D12_SRV_DIMENSION;
using static TerraFX.Interop.D3D12_UAV_DIMENSION;
@@ -61,7 +60,8 @@ 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>
private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType)
/// <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)
{
device.ThrowIfDisposed();
@@ -69,7 +69,7 @@ namespace ComputeSharp.Resources
Guard.IsBetweenOrEqualTo(height, 1, FX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height));
Guard.IsBetweenOrEqualTo(depth, 1, FX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth));
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
{
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
+2 -1
ファイルの表示
@@ -4,6 +4,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
#pragma warning disable CS0618
@@ -27,7 +28,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, ResourceType.ReadOnly)
: base(device, width, height, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
{
}
+2 -1
ファイルの表示
@@ -3,6 +3,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
namespace ComputeSharp
{
@@ -22,7 +23,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, ResourceType.ReadOnly)
: base(device, width, height, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
{
}
+2 -1
ファイルの表示
@@ -4,6 +4,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
#pragma warning disable CS0618
@@ -28,7 +29,7 @@ namespace ComputeSharp
/// <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)
: base(device, width, height, depth, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
{
}
+2 -1
ファイルの表示
@@ -3,6 +3,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
namespace ComputeSharp
{
@@ -23,7 +24,7 @@ namespace ComputeSharp
/// <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)
: base(device, width, height, depth, ResourceType.ReadOnly, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
{
}
+2 -1
ファイルの表示
@@ -4,6 +4,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
#pragma warning disable CS0618
@@ -27,7 +28,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, ResourceType.ReadWrite)
: base(device, width, height, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}
+2 -1
ファイルの表示
@@ -3,6 +3,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
namespace ComputeSharp
{
@@ -22,7 +23,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, ResourceType.ReadWrite)
: base(device, width, height, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}
+2 -1
ファイルの表示
@@ -4,6 +4,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
#pragma warning disable CS0618
@@ -28,7 +29,7 @@ namespace ComputeSharp
/// <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)
: base(device, width, height, depth, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}
+2 -1
ファイルの表示
@@ -3,6 +3,7 @@ using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Resources.Enums;
using ComputeSharp.Resources;
using ComputeSharp.Resources.Views;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
namespace ComputeSharp
{
@@ -23,7 +24,7 @@ namespace ComputeSharp
/// <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)
: base(device, width, height, depth, ResourceType.ReadWrite, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
{
}