From a1b606741f07b26edb45c12e3d2bcc612abff18d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 7 Dec 2021 16:57:50 +0100 Subject: [PATCH] Add double support requirement to reflection info --- .../Shaders/Interop/ReflectionServices.cs | 1 + src/ComputeSharp/Shaders/Interop/ShaderInfo.cs | 5 +++++ .../DirectX/um/d3d11shader/D3D.cs | 16 ++++++++++++++++ .../TerraFX.Interop.Windows.projitems | 1 + tests/ComputeSharp.Tests/ShadersTests.cs | 13 +++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 src/TerraFX.Interop.Windows/DirectX/um/d3d11shader/D3D.cs diff --git a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs index c54769da..d7e61c80 100644 --- a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs +++ b/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs @@ -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 } } diff --git a/src/ComputeSharp/Shaders/Interop/ShaderInfo.cs b/src/ComputeSharp/Shaders/Interop/ShaderInfo.cs index b495f99e..3403f74b 100644 --- a/src/ComputeSharp/Shaders/Interop/ShaderInfo.cs +++ b/src/ComputeSharp/Shaders/Interop/ShaderInfo.cs @@ -124,4 +124,9 @@ public readonly struct ShaderInfo /// The number of interface slots used. /// public readonly uint InterfaceSlotCount; + + /// + /// Indicates whether support for double precision floating point numbers is required. + /// + public readonly bool RequiresDoublePrecisionSupport; } diff --git a/src/TerraFX.Interop.Windows/DirectX/um/d3d11shader/D3D.cs b/src/TerraFX.Interop.Windows/DirectX/um/d3d11shader/D3D.cs new file mode 100644 index 00000000..1bb7a5a9 --- /dev/null +++ b/src/TerraFX.Interop.Windows/DirectX/um/d3d11shader/D3D.cs @@ -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; + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems index dafa39be..c5562388 100644 --- a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems +++ b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems @@ -53,6 +53,7 @@ + diff --git a/tests/ComputeSharp.Tests/ShadersTests.cs b/tests/ComputeSharp.Tests/ShadersTests.cs index 3099466f..580d610f 100644 --- a/tests/ComputeSharp.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.Tests/ShadersTests.cs @@ -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(out var info); + + Assert.IsFalse(info.RequiresDoublePrecisionSupport); + RunAndCompareShader(device, shaderType, 0.00011f); } @@ -156,6 +161,10 @@ public class ShadersTests static void RunComputeShader(ReadWriteTexture2D texture) where T : struct, IComputeShader { + ReflectionServices.GetShaderInfo(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(out var info); + + Assert.IsFalse(info.RequiresDoublePrecisionSupport); + Assert.AreEqual(typeof(TCompute), shaderType); texture.GraphicsDevice.For(texture.Width, texture.Height, computeFactory(texture));