From 2c36f2c40f801fb5c255e0858559d15c211846a6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 7 Jun 2024 19:17:00 -0700 Subject: [PATCH] Update all runtime and generator tests --- .../Test_D2DPixelShaderDescriptorGenerator.cs | 10 ++--- .../D2D1PixelShaderTests.cs | 28 +++++++------- .../D2D1ShaderCompilerTests.cs | 37 ++++++++++++++++++- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs index f2507eba..26f0f706 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs @@ -166,7 +166,7 @@ public class Test_D2DPixelShaderDescriptorGenerator [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking; + static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default; /// [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] @@ -466,7 +466,7 @@ public class Test_D2DPixelShaderDescriptorGenerator [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking; + static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default; /// [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] @@ -818,7 +818,7 @@ public class Test_D2DPixelShaderDescriptorGenerator [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking; + static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default; /// [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] @@ -1116,7 +1116,7 @@ public class Test_D2DPixelShaderDescriptorGenerator [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking; + static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default; /// [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] @@ -1694,7 +1694,7 @@ public class Test_D2DPixelShaderDescriptorGenerator [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking; + static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default; /// [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", )] diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs index dea905b7..fd0c2545 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs @@ -417,13 +417,13 @@ namespace ComputeSharp.D2D1.Tests Assert.IsTrue(manager!.GetType().Name.Contains("HlslBytecodeMemoryManager")); // Matching compile options - bytecode = D2D1PixelShader.LoadBytecode(D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking); + bytecode = D2D1PixelShader.LoadBytecode(D2D1CompileOptions.Default); Assert.IsTrue(MemoryMarshal.TryGetMemoryManager(bytecode, out manager)); Assert.IsTrue(manager!.GetType().Name.Contains("HlslBytecodeMemoryManager")); // Matching shader profile and compile options - bytecode = D2D1PixelShader.LoadBytecode(D2D1ShaderProfile.PixelShader40Level91, D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking); + bytecode = D2D1PixelShader.LoadBytecode(D2D1ShaderProfile.PixelShader40Level91, D2D1CompileOptions.Default); Assert.IsTrue(MemoryMarshal.TryGetMemoryManager(bytecode, out manager)); Assert.IsTrue(manager!.GetType().Name.Contains("HlslBytecodeMemoryManager")); @@ -534,7 +534,7 @@ namespace ComputeSharp.D2D1.Tests _ = D2D1PixelShader.LoadBytecode(out D2D1ShaderProfile shaderProfile, out D2D1CompileOptions compileOptions); Assert.AreEqual(shaderProfile, D2D1ShaderProfile.PixelShader40Level91); - Assert.AreEqual(compileOptions, D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking); + Assert.AreEqual(compileOptions, D2D1CompileOptions.Default); _ = D2D1PixelShader.LoadBytecode(out shaderProfile, out compileOptions); @@ -598,7 +598,7 @@ namespace ComputeSharp.D2D1.Tests { ReadOnlyMemory hlslBytecode = D2D1PixelShader.LoadBytecode(out _, out D2D1CompileOptions compileOptions); - Assert.AreEqual(D2D1CompileOptions.OptimizationLevel3 | D2D1CompileOptions.PackMatrixRowMajor, compileOptions); + Assert.AreEqual(D2D1CompileOptions.Default & ~D2D1CompileOptions.WarningsAreErrors, compileOptions); Assert.IsTrue(hlslBytecode.Length > 0); } @@ -618,11 +618,11 @@ namespace ComputeSharp.D2D1.Tests [TestMethod] public void LoadBytecode_EnableLinkingIsAppliedCorrectly() { - ReadOnlyMemory hlslBytecode1 = D2D1PixelShader.LoadBytecode(out _, out D2D1CompileOptions compileOptions1); - ReadOnlyMemory hlslBytecode2 = D2D1PixelShader.LoadBytecode(out _, out D2D1CompileOptions compileOptions2); + ReadOnlyMemory hlslBytecode1 = D2D1PixelShader.LoadBytecode(out _, out D2D1CompileOptions compileOptions1); + ReadOnlyMemory hlslBytecode2 = D2D1PixelShader.LoadBytecode(out _, out D2D1CompileOptions compileOptions2); - Assert.AreEqual(D2D1CompileOptions.Default | D2D1CompileOptions.PackMatrixRowMajor, compileOptions1); - Assert.AreEqual(D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking | D2D1CompileOptions.PackMatrixRowMajor, compileOptions2); + Assert.AreEqual(D2D1CompileOptions.Default & ~D2D1CompileOptions.EnableLinking, compileOptions1); + Assert.AreEqual(D2D1CompileOptions.Default, compileOptions2); Assert.IsTrue(MemoryMarshal.TryGetMemoryManager(hlslBytecode1, out MemoryManager? manager1)); Assert.IsTrue(manager1!.GetType().Name.Contains("HlslBytecodeMemoryManager")); @@ -630,9 +630,9 @@ namespace ComputeSharp.D2D1.Tests Assert.IsTrue(MemoryMarshal.TryGetMemoryManager(hlslBytecode2, out MemoryManager? manager2)); Assert.IsTrue(manager2!.GetType().Name.Contains("HlslBytecodeMemoryManager")); - // Same checks as in D2D1ShaderCompilerTests.CompileInvertEffectWithDefaultOptionsAndLinking + // Very similar checks to those in D2D1ShaderCompilerTests.CompileInvertEffectWithDefaultOptionsAndLinking Assert.IsTrue(hlslBytecode1.Length > 700); - Assert.IsTrue(hlslBytecode2.Length > 1400); + Assert.IsTrue(hlslBytecode2.Length > 1500); Assert.IsTrue(hlslBytecode2.Length > hlslBytecode1.Length); Assert.IsTrue((hlslBytecode2.Length - hlslBytecode1.Length) > 700); } @@ -656,9 +656,9 @@ namespace ComputeSharp.D2D1.Tests [D2DInputCount(1)] [D2DInputSimple(0)] [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] - [D2DCompileOptions(D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking)] + [D2DCompileOptions(D2D1CompileOptions.Default & ~D2D1CompileOptions.EnableLinking)] [D2DGeneratedPixelShaderDescriptor] - public readonly partial struct ReferenceShaderWithEnableLinking : ID2D1PixelShader + public readonly partial struct ReferenceShaderWithDefaultCompileOptionsAndNoLinking : ID2D1PixelShader { public float4 Execute() { @@ -675,8 +675,8 @@ namespace ComputeSharp.D2D1.Tests ReadOnlyMemory hlslBytecode1 = D2D1PixelShader.LoadBytecode(out _, out D2D1CompileOptions compileOptions1); ReadOnlyMemory hlslBytecode2 = D2D1PixelShader.LoadBytecode(out _, out D2D1CompileOptions compileOptions2); - Assert.AreEqual(D2D1CompileOptions.Default | D2D1CompileOptions.PackMatrixRowMajor, compileOptions1); - Assert.AreEqual(D2D1CompileOptions.Default | D2D1CompileOptions.StripReflectionData | D2D1CompileOptions.PackMatrixRowMajor, compileOptions2); + Assert.AreEqual(D2D1CompileOptions.Default, compileOptions1); + Assert.AreEqual(D2D1CompileOptions.Default | D2D1CompileOptions.StripReflectionData, compileOptions2); Assert.IsTrue(MemoryMarshal.TryGetMemoryManager(hlslBytecode1, out MemoryManager? manager1)); Assert.IsTrue(manager1!.GetType().Name.Contains("HlslBytecodeMemoryManager")); diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs index 2337dd38..577ca088 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs @@ -80,13 +80,13 @@ public partial class D2D1ShaderCompilerTests source.AsSpan(), "PSMain".AsSpan(), D2D1ShaderProfile.PixelShader40Level93, - D2D1CompileOptions.Default); + D2D1CompileOptions.Default & ~D2D1CompileOptions.EnableLinking); ReadOnlyMemory bytecodeWithLinking = D2D1ShaderCompiler.Compile( source.AsSpan(), "PSMain".AsSpan(), D2D1ShaderProfile.PixelShader40Level93, - D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking); + D2D1CompileOptions.Default); Assert.IsTrue(bytecode.Length > 800); Assert.IsTrue(bytecodeWithLinking.Length > 1600); @@ -94,6 +94,39 @@ public partial class D2D1ShaderCompilerTests Assert.IsTrue((bytecodeWithLinking.Length - bytecode.Length) > 800); } + [TestMethod] + public void CompileInvertEffectWithDefaultOptionsAndOptimizeForSize() + { + const string source = """ + #define D2D_INPUT_COUNT 1 + #define D2D_INPUT0_SIMPLE + + #include "d2d1effecthelpers.hlsli" + + D2D_PS_ENTRY(PSMain) + { + float4 color = D2DGetInput(0); + float3 rgb = saturate(1.0 - color.rgb); + return float4(rgb, 1); + } + """; + + ReadOnlyMemory bytecode = D2D1ShaderCompiler.Compile( + source.AsSpan(), + "PSMain".AsSpan(), + D2D1ShaderProfile.PixelShader40Level93, + D2D1CompileOptions.Default); + + ReadOnlyMemory bytecodeWithOptimizeForSize = D2D1ShaderCompiler.Compile( + source.AsSpan(), + "PSMain".AsSpan(), + D2D1ShaderProfile.PixelShader40Level93, + D2D1CompileOptions.OptimizeForSize); + + Assert.IsTrue(bytecode.Length > 1800); + Assert.IsTrue(bytecodeWithOptimizeForSize.Length < 600); + } + [TestMethod] public void CompileInvertEffectWithDefaultOptionsAndStripReflectionData() {