Merge branch 'dev' into pr/79

このコミットが含まれているのは:
Sergio Pedri committed 2020-12-19 02:26:07 +01:00
コミット fa3b6cb1f6
9ファイル変更
+137 -7

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

+6
ファイルの表示
@@ -9,6 +9,7 @@ using ComputeSharp.Graphics.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;
@@ -63,6 +64,11 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
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))
{
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
GraphicsDevice = device;
Width = width;
Height = height;
+6
ファイルの表示
@@ -9,6 +9,7 @@ using ComputeSharp.Graphics.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;
@@ -65,6 +66,11 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
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))
{
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
GraphicsDevice = device;
Width = width;
Height = height;
-3
ファイルの表示
@@ -52,7 +52,6 @@ namespace ComputeSharp.Exceptions
/// <typeparam name="T">The type of values in the input buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> that was used.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance that was used.</param>
[Pure]
internal static void Throw<T>(Buffer<T> buffer, GraphicsDevice device)
where T : unmanaged
{
@@ -65,7 +64,6 @@ namespace ComputeSharp.Exceptions
/// <typeparam name="T">The type of values in the input buffer.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> that was used.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance that was used.</param>
[Pure]
internal static void Throw<T>(Texture2D<T> texture, GraphicsDevice device)
where T : unmanaged
{
@@ -78,7 +76,6 @@ namespace ComputeSharp.Exceptions
/// <typeparam name="T">The type of values in the input buffer.</typeparam>
/// <param name="texture">The input <see cref="Texture3D{T}"/> that was used.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance that was used.</param>
[Pure]
internal static void Throw<T>(Texture3D<T> texture, GraphicsDevice device)
where T : unmanaged
{
+70
ファイルの表示
@@ -0,0 +1,70 @@
using System;
using System.Diagnostics.Contracts;
using System.Text;
using ComputeSharp.Graphics;
using Microsoft.Toolkit.Diagnostics;
namespace ComputeSharp.Exceptions
{
/// <summary>
/// A custom <see cref="InvalidOperationException"/> that indicates when a texture was attempted to be created with an unsupported type.
/// </summary>
public sealed class UnsupportedTextureTypeException : InvalidOperationException
{
/// <summary>
/// Creates a new <see cref="UnsupportedTextureTypeException"/> instance.
/// </summary>
/// <param name="message">The message that describes the error.</param>
private UnsupportedTextureTypeException(string message)
: base(message)
{
}
/// <summary>
/// Creates a new <see cref="UnsupportedTextureTypeException"/> instance from the specified parameters.
/// </summary>
/// <param name="rank">The rank of the texture that couldn't be created.</param>
/// <param name="type">The element type of texture that was being created.</param>
/// <returns>A new <see cref="UnsupportedTextureTypeException"/> instance with a formatted error message.</returns>
[Pure]
private static UnsupportedTextureTypeException Create(int rank, Type type)
{
StringBuilder builder = new(256);
builder.AppendLine($"The device in use does not support creating {rank}D textures of type {type}.");
builder.Append($"Make sure to check the support at runtime by using {nameof(GraphicsDevice)}.");
builder.AppendLine(rank switch
{
2 => $"{nameof(GraphicsDevice.IsTexture2DSupportedForType)}<T>().",
3 => $"{nameof(GraphicsDevice.IsTexture3DSupportedForType)}<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.ToString();
return new(builder.ToString());
}
/// <summary>
/// Throws a new <see cref="UnsupportedTextureTypeException"/> instance from the specified parameters.
/// </summary>
/// <typeparam name="T">The type of values in the texture that couldn't be created.</typeparam>
internal static void ThrowForTexture2D<T>()
where T : unmanaged
{
throw Create(2, typeof(T));
}
/// <summary>
/// Throws a new <see cref="UnsupportedTextureTypeException"/> instance from the specified parameters.
/// </summary>
/// <typeparam name="T">The type of values in the texture that couldn't be created.</typeparam>
internal static void ThrowForTexture3D<T>()
where T : unmanaged
{
throw Create(3, typeof(T));
}
}
}
+19
ファイルの表示
@@ -9,6 +9,7 @@ using static TerraFX.Interop.D3D12_COMMAND_QUEUE_PRIORITY;
using static TerraFX.Interop.D3D12_CPU_PAGE_PROPERTY;
using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_FLAGS;
using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE;
using static TerraFX.Interop.D3D12_FEATURE;
using static TerraFX.Interop.D3D12_FENCE_FLAGS;
using static TerraFX.Interop.D3D12_MEMORY_POOL;
using static TerraFX.Interop.D3D12_HEAP_FLAGS;
@@ -448,5 +449,23 @@ namespace ComputeSharp.Graphics.Extensions
return feature;
}
/// <summary>
/// Checks whether or not a given DXGI format is supported for the specified resource type.
/// </summary>
/// <param name="d3D12Device">The target <see cref="ID3D12Device"/> to use to check features for.</param>
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> type to check support for.</param>
/// <param name="d3D12FormatSupport1">The resource type to check support for.</param>
/// <returns>Whether or not the input device supports the requested format for the specified resource type.</returns>
[Pure]
public static unsafe bool IsDxgiFormatSupported(this ref ID3D12Device d3D12Device, DXGI_FORMAT dxgiFormat, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport1)
{
D3D12_FEATURE_DATA_FORMAT_SUPPORT d3D12FeatureDataFormatSupport = default;
d3D12FeatureDataFormatSupport.Format = dxgiFormat;
d3D12Device.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &d3D12FeatureDataFormatSupport, (uint)sizeof(D3D12_FEATURE_DATA_FORMAT_SUPPORT)).Assert();
return (d3D12FeatureDataFormatSupport.Support1 & d3D12FormatSupport1) != 0;
}
}
}
+32
ファイルの表示
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Graphics.Commands;
@@ -10,6 +11,7 @@ using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
using static TerraFX.Interop.D3D12_FEATURE;
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
namespace ComputeSharp.Graphics
{
@@ -126,6 +128,36 @@ namespace ComputeSharp.Graphics
/// </summary>
internal ID3D12Device* D3D12Device => this.d3D12Device;
/// <summary>
/// Checks whether the current device supports the creation of <see cref="Buffers.Abstract.Texture2D{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="Buffers.Abstract.Texture2D{T}"/> instances can be created by the current device.</returns>
[Pure]
public bool IsTexture2DSupportedForType<T>()
where T : unmanaged
{
ThrowIfDisposed();
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D);
}
/// <summary>
/// Checks whether the current device supports the creation of <see cref="Buffers.Abstract.Texture3D{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="Buffers.Abstract.Texture3D{T}"/> instances can be created by the current device.</returns>
[Pure]
public bool IsTexture3DSupportedForType<T>()
where T : unmanaged
{
ThrowIfDisposed();
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D);
}
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Allocate"/>
internal void RentShaderResourceViewDescriptorHandles(
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
+2 -2
ファイルの表示
@@ -126,7 +126,7 @@ namespace ComputeSharp.Graphics.Helpers
HRESULT createDeviceResult = FX.D3D12CreateDevice(
dxgiAdapter1.AsIUnknown().Get(),
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0,
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
FX.__uuidof<ID3D12Device>(),
null);
@@ -137,7 +137,7 @@ namespace ComputeSharp.Graphics.Helpers
FX.D3D12CreateDevice(
dxgiAdapter1.AsIUnknown().Get(),
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0,
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
FX.__uuidof<ID3D12Device>(),
d3D12Device.GetVoidAddressOf()).Assert();
+1 -1
ファイルの表示
@@ -95,7 +95,7 @@ namespace ComputeSharp.Graphics.Helpers
HRESULT createDeviceResult = FX.D3D12CreateDevice(
dxgiAdapter1.AsIUnknown().Get(),
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0,
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
FX.__uuidof<ID3D12Device>(),
(void**)d3D12Device);
+1 -1
ファイルの表示
@@ -76,7 +76,7 @@ namespace ComputeSharp.Shaders.Translation
// Try to compile the new compute shader
fixed (char* shaderName = "")
fixed (char* entryPoint = nameof(IComputeShader.Execute))
fixed (char* shaderProfile = "cs_6_1")
fixed (char* shaderProfile = "cs_6_0")
fixed (char* optimization = "-O3")
{
DxcCompiler.Get()->Compile(