Merge pull request #173 from Sergio0694/feature/double-requirement-info

Improve double precision support
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2021-12-07 22:17:47 +01:00
コミット 816c2f1acd
8ファイル変更
+107

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

+14
ファイルの表示
@@ -188,6 +188,20 @@ public sealed unsafe class GraphicsDevice : NativeObject
/// </summary>
internal bool IsCacheCoherentUMA { get; }
/// <summary>
/// Checks whether the current device supports double precision floating point operations in shaders.
/// </summary>
/// <returns>Whether the current device supports double precision floating point operations in shaders.</returns>
[Pure]
public bool IsDoublePrecisionSupportAvailable()
{
ThrowIfDisposed();
var d3D12OptionsData = this.d3D12Device.Get()->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS>(D3D12_FEATURE_D3D12_OPTIONS);
return d3D12OptionsData.DoublePrecisionFloatShaderOps;
}
/// <summary>
/// Checks whether the current device supports the creation of
/// <see cref="ReadOnlyTexture2D{T}"/> resources for a specified type <typeparamref name="T"/>.
+1
ファイルの表示
@@ -168,6 +168,7 @@ public static class ReflectionServices
Unsafe.AsRef(shaderInfo.MovcInstructionCount) = d3D12ShaderReflection.Get()->GetMovcInstructionCount();
Unsafe.AsRef(shaderInfo.MovInstructionCount) = d3D12ShaderReflection.Get()->GetMovInstructionCount();
Unsafe.AsRef(shaderInfo.InterfaceSlotCount) = d3D12ShaderReflection.Get()->GetNumInterfaceSlots();
Unsafe.AsRef(shaderInfo.RequiresDoublePrecisionSupport) = (d3D12ShaderReflection.Get()->GetRequiresFlags() & (D3D.D3D_SHADER_REQUIRES_DOUBLES | D3D.D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS)) != 0;
#endif
}
}
+5
ファイルの表示
@@ -124,4 +124,9 @@ public readonly struct ShaderInfo
/// The number of interface slots used.
/// </summary>
public readonly uint InterfaceSlotCount;
/// <summary>
/// Indicates whether support for double precision floating point numbers is required.
/// </summary>
public readonly bool RequiresDoublePrecisionSupport;
}
+16
ファイルの表示
@@ -0,0 +1,16 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
// Ported from um/d3d11shader.h in the Windows SDK for Windows 10.0.20348.0
// Original source is Copyright © Microsoft. All rights reserved.
namespace TerraFX.Interop.DirectX
{
public static partial class D3D
{
[NativeTypeName("#define D3D_SHADER_REQUIRES_DOUBLES 0x00000001")]
public const int D3D_SHADER_REQUIRES_DOUBLES = 0x00000001;
[NativeTypeName("#define D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS 0x00000020")]
public const int D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS = 0x00000020;
}
}
+1
ファイルの表示
@@ -53,6 +53,7 @@
<Compile Include="$(MSBuildThisFileDirectory)DirectX\shared\dxgi\IDXGIOutput.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\shared\dxgi\IDXGISwapChain.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\D2D1_FEATURE_LEVEL.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11shader\D3D.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11\D3D11.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d12sdklayers\D3D12_INFO_QUEUE_FILTER.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d12sdklayers\D3D12_INFO_QUEUE_FILTER_DESC.cs" />
+36
ファイルの表示
@@ -371,4 +371,40 @@ public partial class BufferTests
destination[ThreadIds.X] = source[ThreadIds.X];
}
}
[CombinatorialTestMethod]
[AllDevices]
public void Dispatch_ReadWriteBuffer_DoublePrecision(Device device)
{
if (!device.Get().IsDoublePrecisionSupportAvailable())
{
Assert.Inconclusive();
}
double[] array = Enumerable.Range(0, 128).Select(static i => (double)i).ToArray();
using ReadWriteBuffer<double> buffer = device.Get().AllocateReadWriteBuffer(array);
device.Get().For(128, new DoublePrecisionSupportShader(buffer, 2.0));
double[] result = buffer.ToArray();
for (int i = 0; i < 128; i++)
{
Assert.IsTrue(Math.Abs(result[i] - (array[i] * 2.0 + 3.14)) < 0.00001);
}
}
[AutoConstructor]
public readonly partial struct DoublePrecisionSupportShader : IComputeShader
{
public readonly ReadWriteBuffer<double> buffer;
public readonly double factor;
/// <inheritdoc/>
public void Execute()
{
buffer[ThreadIds.X] = buffer[ThreadIds.X] * factor + 3.14;
}
}
}
+21
ファイルの表示
@@ -193,6 +193,27 @@ namespace ComputeSharp.Tests
{
ReflectionServices.GetShaderInfo<LoopWithVarCounterShader>(out var info);
}
[TestMethod]
public void DoublePrecisionSupport()
{
ReflectionServices.GetShaderInfo<DoublePrecisionSupportShader>(out var info);
Assert.IsTrue(info.RequiresDoublePrecisionSupport);
}
[AutoConstructor]
public readonly partial struct DoublePrecisionSupportShader : IComputeShader
{
public readonly ReadWriteBuffer<double> buffer;
public readonly double factor;
/// <inheritdoc/>
public void Execute()
{
buffer[ThreadIds.X] *= factor + 3.14;
}
}
}
}
+13
ファイルの表示
@@ -2,6 +2,7 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.Interop;
using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
@@ -94,6 +95,10 @@ public class ShadersTests
[Data(typeof(SwapChain.Shaders.Compute.ExtrudedTruchetPattern))]
public void ExtrudedTruchetPattern(Device device, Type shaderType)
{
ReflectionServices.GetShaderInfo<SwapChain.Shaders.Compute.ExtrudedTruchetPattern>(out var info);
Assert.IsFalse(info.RequiresDoublePrecisionSupport);
RunAndCompareShader(device, shaderType, 0.00011f);
}
@@ -156,6 +161,10 @@ public class ShadersTests
static void RunComputeShader<T>(ReadWriteTexture2D<Rgba32, float4> texture)
where T : struct, IComputeShader
{
ReflectionServices.GetShaderInfo<T>(out var info);
Assert.IsFalse(info.RequiresDoublePrecisionSupport);
texture.GraphicsDevice.For(texture.Width, texture.Height, (T)Activator.CreateInstance(typeof(T), texture, 0f)!);
}
@@ -221,6 +230,10 @@ public class ShadersTests
{
if (typeof(IComputeShader).IsAssignableFrom(shaderType))
{
ReflectionServices.GetShaderInfo<TCompute>(out var info);
Assert.IsFalse(info.RequiresDoublePrecisionSupport);
Assert.AreEqual(typeof(TCompute), shaderType);
texture.GraphicsDevice.For(texture.Width, texture.Height, computeFactory(texture));