Skip to content

Commit

Permalink
Update all runtime and generator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jun 8, 2024
1 parent d70f861 commit 23b5879
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ partial struct MyShader : global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShader
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking;
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default;
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
Expand Down Expand Up @@ -466,7 +466,7 @@ partial struct MyShader : global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShader
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking;
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default;
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
Expand Down Expand Up @@ -818,7 +818,7 @@ partial struct MyShader : global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShader
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking;
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default;
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
Expand Down Expand Up @@ -1116,7 +1116,7 @@ partial struct MyShader : global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShader
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking;
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default;
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
Expand Down Expand Up @@ -1694,7 +1694,7 @@ partial struct MyShader : global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShader
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default | global::ComputeSharp.D2D1.D2D1CompileOptions.EnableLinking;
static ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<MyShader>.CompileOptions => global::ComputeSharp.D2D1.D2D1CompileOptions.Default;
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
Expand Down
28 changes: 14 additions & 14 deletions tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ public void GetBytecode_FromEmbeddedBytecode()
Assert.IsTrue(manager!.GetType().Name.Contains("HlslBytecodeMemoryManager"));

// Matching compile options
bytecode = D2D1PixelShader.LoadBytecode<ShaderWithEmbeddedBytecode>(D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking);
bytecode = D2D1PixelShader.LoadBytecode<ShaderWithEmbeddedBytecode>(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<ShaderWithEmbeddedBytecode>(D2D1ShaderProfile.PixelShader40Level91, D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking);
bytecode = D2D1PixelShader.LoadBytecode<ShaderWithEmbeddedBytecode>(D2D1ShaderProfile.PixelShader40Level91, D2D1CompileOptions.Default);

Assert.IsTrue(MemoryMarshal.TryGetMemoryManager(bytecode, out manager));
Assert.IsTrue(manager!.GetType().Name.Contains("HlslBytecodeMemoryManager"));
Expand Down Expand Up @@ -534,7 +534,7 @@ public void LoadBytecode_VerifyEffectiveValues_ExplicitShaderProfile()
_ = D2D1PixelShader.LoadBytecode<SimpleShaderWithExplicitShaderProfileAndNoCompileOptions>(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<ComplexShaderWithExplicitShaderProfileAndNoCompileOptions>(out shaderProfile, out compileOptions);

Expand Down Expand Up @@ -598,7 +598,7 @@ public void LoadBytecode_ShaderWithSuppressedFxcWarning()
{
ReadOnlyMemory<byte> hlslBytecode = D2D1PixelShader.LoadBytecode<ShaderWithSuppressedFxcWarning>(out _, out D2D1CompileOptions compileOptions);

Assert.AreEqual(D2D1CompileOptions.OptimizationLevel3 | D2D1CompileOptions.PackMatrixRowMajor, compileOptions);
Assert.AreEqual(D2D1CompileOptions.Default & ~D2D1CompileOptions.WarningsAreErrors, compileOptions);
Assert.IsTrue(hlslBytecode.Length > 0);
}

Expand All @@ -618,21 +618,21 @@ public float4 Execute()
[TestMethod]
public void LoadBytecode_EnableLinkingIsAppliedCorrectly()
{
ReadOnlyMemory<byte> hlslBytecode1 = D2D1PixelShader.LoadBytecode<ReferenceShaderWithDefaultCompileOptions>(out _, out D2D1CompileOptions compileOptions1);
ReadOnlyMemory<byte> hlslBytecode2 = D2D1PixelShader.LoadBytecode<ReferenceShaderWithEnableLinking>(out _, out D2D1CompileOptions compileOptions2);
ReadOnlyMemory<byte> hlslBytecode1 = D2D1PixelShader.LoadBytecode<ReferenceShaderWithDefaultCompileOptionsAndNoLinking>(out _, out D2D1CompileOptions compileOptions1);
ReadOnlyMemory<byte> hlslBytecode2 = D2D1PixelShader.LoadBytecode<ReferenceShaderWithDefaultCompileOptions>(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<byte>? manager1));
Assert.IsTrue(manager1!.GetType().Name.Contains("HlslBytecodeMemoryManager"));

Assert.IsTrue(MemoryMarshal.TryGetMemoryManager(hlslBytecode2, out MemoryManager<byte>? 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);
}
Expand All @@ -656,9 +656,9 @@ public float4 Execute()
[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()
{
Expand All @@ -675,8 +675,8 @@ public void LoadBytecode_StripReflectionDataIsAppliedCorrectly()
ReadOnlyMemory<byte> hlslBytecode1 = D2D1PixelShader.LoadBytecode<ReferenceShaderWithDefaultCompileOptions>(out _, out D2D1CompileOptions compileOptions1);
ReadOnlyMemory<byte> hlslBytecode2 = D2D1PixelShader.LoadBytecode<ReferenceShaderWithStripReflectionData>(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<byte>? manager1));
Assert.IsTrue(manager1!.GetType().Name.Contains("HlslBytecodeMemoryManager"));
Expand Down
37 changes: 35 additions & 2 deletions tests/ComputeSharp.D2D1.Tests/D2D1ShaderCompilerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,53 @@ public void CompileInvertEffectWithDefaultOptionsAndLinking()
source.AsSpan(),
"PSMain".AsSpan(),
D2D1ShaderProfile.PixelShader40Level93,
D2D1CompileOptions.Default);
D2D1CompileOptions.Default & ~D2D1CompileOptions.EnableLinking);

ReadOnlyMemory<byte> 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);
Assert.IsTrue(bytecodeWithLinking.Length > bytecode.Length);
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<byte> bytecode = D2D1ShaderCompiler.Compile(
source.AsSpan(),
"PSMain".AsSpan(),
D2D1ShaderProfile.PixelShader40Level93,
D2D1CompileOptions.Default);

ReadOnlyMemory<byte> 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()
{
Expand Down

0 comments on commit 23b5879

Please sign in to comment.