From 2d952769ee4f1d272c847a610e377f925b4c28d1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 7 Dec 2023 11:43:38 +0100 Subject: [PATCH] Add unit test for D2D shader reflection stripping --- .../D2D1ShaderCompilerTests.cs | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs index 1594f759..64dfdfcd 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs @@ -78,12 +78,56 @@ public partial class D2D1ShaderCompilerTests """; ReadOnlyMemory bytecode = D2D1ShaderCompiler.Compile( + source.AsSpan(), + "PSMain".AsSpan(), + D2D1ShaderProfile.PixelShader40Level93, + D2D1CompileOptions.Default); + + ReadOnlyMemory bytecodeWithLinking = D2D1ShaderCompiler.Compile( source.AsSpan(), "PSMain".AsSpan(), D2D1ShaderProfile.PixelShader40Level93, D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking); - Assert.IsTrue(bytecode.Length > 0); + Assert.IsTrue(bytecode.Length > 800); + Assert.IsTrue(bytecodeWithLinking.Length > 1600); + Assert.IsTrue(bytecodeWithLinking.Length > bytecode.Length); + Assert.IsTrue((bytecodeWithLinking.Length - bytecode.Length) > 800); + } + + [TestMethod] + public void CompileInvertEffectWithDefaultOptionsAndStripReflectionData() + { + 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 bytecodeWithStripReflectionData = D2D1ShaderCompiler.Compile( + source.AsSpan(), + "PSMain".AsSpan(), + D2D1ShaderProfile.PixelShader40Level93, + D2D1CompileOptions.Default | D2D1CompileOptions.StripReflectionData); + + Assert.IsTrue(bytecode.Length > 800); + Assert.IsTrue(bytecodeWithStripReflectionData.Length > 500); + Assert.IsTrue(bytecode.Length > bytecodeWithStripReflectionData.Length); + Assert.IsTrue((bytecode.Length - bytecodeWithStripReflectionData.Length) > 200); } [TestMethod]