Merge pull request #811 from Sergio0694/dev/shader-linking-fixes2
Rework linking analyzer, remove generator heuristic, change D2D compile options
このコミットが含まれているのは:
11ファイル変更
+270
-295
検索条件に一致するファイルはありません
+2
-74
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
@@ -76,83 +75,12 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
/// Gets the effective compile options to use.
|
||||
/// </summary>
|
||||
/// <param name="compileOptions">The requested compile options.</param>
|
||||
/// <param name="isLinkingSupported">Whether the input shader supports linking.</param>
|
||||
/// <returns>The effective compile options.</returns>
|
||||
public static D2D1CompileOptions GetEffectiveCompileOptions(D2D1CompileOptions? compileOptions, bool isLinkingSupported)
|
||||
public static D2D1CompileOptions GetEffectiveCompileOptions(D2D1CompileOptions? compileOptions)
|
||||
{
|
||||
// If an explicit set of compile options is provided, use that directly. Otherwise, use the default
|
||||
// options plus the option to enable linking only if the shader can potentially support it.
|
||||
return compileOptions ?? (D2D1CompileOptions.Default | (isLinkingSupported ? D2D1CompileOptions.EnableLinking : 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the metadata definition for the current shader.
|
||||
/// </summary>
|
||||
/// <param name="compilation">The input <see cref="Compilation"/> object currently in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="inputCount">The number of inputs for the shader.</param>
|
||||
/// <returns>Whether the shader only has simple inputs.</returns>
|
||||
public static bool IsSimpleInputShader(
|
||||
Compilation compilation,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
int inputCount)
|
||||
{
|
||||
return IsSimpleInputShader(
|
||||
structDeclarationSymbol,
|
||||
compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DInputSimpleAttribute")!,
|
||||
inputCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the metadata definition for the current shader.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="d2DInputSimpleSymbolAttributeSymbol">The symbol for the <c>[D2DInputSimple]</c> attribute.</param>
|
||||
/// <param name="inputCount">The number of inputs for the shader.</param>
|
||||
/// <returns>Whether the shader only has simple inputs.</returns>
|
||||
public static bool IsSimpleInputShader(
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
INamedTypeSymbol d2DInputSimpleSymbolAttributeSymbol,
|
||||
int inputCount)
|
||||
{
|
||||
// We cannot trust the input count to be valid at this point (it may be invalid and
|
||||
// with diagnostic already emitted for it). So first, just clamp it in the right range.
|
||||
inputCount = Math.Max(0, Math.Min(8, inputCount));
|
||||
|
||||
// If there are no inputs, the shader is as if only had simple inputs
|
||||
if (inputCount == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Build a map of all simple inputs (unmarked inputs default to being complex).
|
||||
// We can never have more than 8 inputs, and if there are it means the shader is
|
||||
// not valid. Just ignore them, and the generator will emit a separate diagnostic.
|
||||
Span<bool> simpleInputsMap = stackalloc bool[8];
|
||||
|
||||
// We first start with all inputs marked as complex (ie. not simple)
|
||||
simpleInputsMap.Clear();
|
||||
|
||||
foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes())
|
||||
{
|
||||
// Only retrieve indices of simple inputs that are in range. If an input is out of
|
||||
// range, the diagnostic for it will already be emitted by a previous generator step.
|
||||
if (SymbolEqualityComparer.Default.Equals(attributeData.AttributeClass, d2DInputSimpleSymbolAttributeSymbol) &&
|
||||
attributeData.ConstructorArguments is [{ Value: >= 0 and < 8 and int index }])
|
||||
{
|
||||
simpleInputsMap[index] = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool isSimpleInputShader = true;
|
||||
|
||||
// Validate all inputs in our range (filtered by the allowed one)
|
||||
foreach (bool isSimpleInput in simpleInputsMap[..inputCount])
|
||||
{
|
||||
isSimpleInputShader &= isSimpleInput;
|
||||
}
|
||||
|
||||
return isSimpleInputShader;
|
||||
return compileOptions ?? D2D1CompileOptions.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,11 +128,10 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// Get the shader profile and linking info for the HLSL bytecode properties
|
||||
bool isLinkingSupported = HlslBytecode.IsSimpleInputShader(context.SemanticModel.Compilation, typeSymbol, inputCount);
|
||||
D2D1ShaderProfile? requestedShaderProfile = HlslBytecode.GetRequestedShaderProfile(typeSymbol);
|
||||
D2D1CompileOptions? requestedCompileOptions = HlslBytecode.GetRequestedCompileOptions(typeSymbol);
|
||||
D2D1ShaderProfile effectiveShaderProfile = HlslBytecode.GetEffectiveShaderProfile(requestedShaderProfile, out bool isCompilationEnabled);
|
||||
D2D1CompileOptions effectiveCompileOptions = HlslBytecode.GetEffectiveCompileOptions(requestedCompileOptions, isLinkingSupported);
|
||||
D2D1CompileOptions effectiveCompileOptions = HlslBytecode.GetEffectiveCompileOptions(requestedCompileOptions);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A diagnostic analyzer that generates an error whenever [D2DCompileOptions] is used on a shader type to request linking when not supported.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = [InvalidD2D1CompileOptionsEnableLinkingOnShaderType];
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterCompilationStartAction(static context =>
|
||||
{
|
||||
// Get the [D2DCompileOptions], [D2DInputCount] and [D2DInputSimple] symbols
|
||||
if (context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute") is not { } d2DCompileOptionsAttributeSymbol ||
|
||||
context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DInputCountAttribute") is not { } d2DInputCountAttributeSymbol ||
|
||||
context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DInputSimpleAttribute") is not { } d2DInputSimpleAttributeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.RegisterSymbolAction(context =>
|
||||
{
|
||||
// Only struct types are possible targets
|
||||
if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If the type is not using [D2DCompileOptions] with D2D1CompileOptions.EnableLinking, there's nothing to do
|
||||
if (!typeSymbol.TryGetAttributeWithType(d2DCompileOptionsAttributeSymbol, out AttributeData? compileOptionsAttribute) ||
|
||||
!((D2D1CompileOptions)compileOptionsAttribute.ConstructorArguments[0].Value!).HasFlag(D2D1CompileOptions.EnableLinking))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we have the [D2DInputCount] (if not present, the shader is invalid anyway) and with a valid value
|
||||
if (!typeSymbol.TryGetAttributeWithType(d2DInputCountAttributeSymbol, out AttributeData? inputCountAttribute) ||
|
||||
inputCountAttribute.ConstructorArguments is not [{ Value: >= 0 and < 8 and int inputCount }])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Emit a diagnostic if the compile options are not valid for the shader type
|
||||
if (!D2DPixelShaderDescriptorGenerator.HlslBytecode.IsSimpleInputShader(typeSymbol, d2DInputSimpleAttributeSymbol, inputCount))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
InvalidD2D1CompileOptionsEnableLinkingOnShaderType,
|
||||
compileOptionsAttribute.GetLocation(),
|
||||
typeSymbol));
|
||||
}
|
||||
}, SymbolKind.NamedType);
|
||||
});
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A diagnostic analyzer that generates an error whenever [D2DPixelOptions] is used on a shader type to incorrectly request trivial sampling.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class InvalidD2D1PixelOptionsTrivialSamplingOnShaderTypeAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = [InvalidD2D1PixelOptionsTrivialSamplingOnShaderType];
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterCompilationStartAction(static context =>
|
||||
{
|
||||
// Get the [D2DPixelOptions], [D2DInputCount] and [D2DInputSimple] symbols
|
||||
if (context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute") is not { } d2DPixelOptionsAttributeSymbol ||
|
||||
context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DInputCountAttribute") is not { } d2DInputCountAttributeSymbol ||
|
||||
context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DInputSimpleAttribute") is not { } d2DInputSimpleAttributeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.RegisterSymbolAction(context =>
|
||||
{
|
||||
// Only struct types are possible targets
|
||||
if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If the type is not using [D2DPixelOptions] with D2D1PixelOptions.TrivialSampling, there's nothing to do
|
||||
if (!typeSymbol.TryGetAttributeWithType(d2DPixelOptionsAttributeSymbol, out AttributeData? pixelOptionsAttribute) ||
|
||||
!((D2D1PixelOptions)pixelOptionsAttribute.ConstructorArguments[0].Value!).HasFlag(D2D1PixelOptions.TrivialSampling))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we have the [D2DInputCount] (if not present, the shader is invalid anyway) and with a valid value
|
||||
if (!typeSymbol.TryGetAttributeWithType(d2DInputCountAttributeSymbol, out AttributeData? inputCountAttribute) ||
|
||||
inputCountAttribute.ConstructorArguments is not [{ Value: >= 0 and < 8 and int inputCount }])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Emit a diagnostic if the compile options are not valid for the shader type
|
||||
if (!IsSimpleInputShader(typeSymbol, d2DInputSimpleAttributeSymbol, inputCount))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
InvalidD2D1PixelOptionsTrivialSamplingOnShaderType,
|
||||
pixelOptionsAttribute.GetLocation(),
|
||||
typeSymbol));
|
||||
}
|
||||
}, SymbolKind.NamedType);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given shader only has simple inputs.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="d2DInputSimpleSymbolAttributeSymbol">The symbol for the <c>[D2DInputSimple]</c> attribute.</param>
|
||||
/// <param name="inputCount">The number of inputs for the shader.</param>
|
||||
/// <returns>Whether the shader only has simple inputs.</returns>
|
||||
private static bool IsSimpleInputShader(
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
INamedTypeSymbol d2DInputSimpleSymbolAttributeSymbol,
|
||||
int inputCount)
|
||||
{
|
||||
// We cannot trust the input count to be valid at this point (it may be invalid and
|
||||
// with diagnostic already emitted for it). So first, just clamp it in the right range.
|
||||
inputCount = Math.Max(0, Math.Min(8, inputCount));
|
||||
|
||||
// If there are no inputs, the shader is as if only had simple inputs
|
||||
if (inputCount == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Build a map of all simple inputs (unmarked inputs default to being complex).
|
||||
// We can never have more than 8 inputs, and if there are it means the shader is
|
||||
// not valid. Just ignore them, and the generator will emit a separate diagnostic.
|
||||
Span<bool> simpleInputsMap = stackalloc bool[8];
|
||||
|
||||
// We first start with all inputs marked as complex (ie. not simple)
|
||||
simpleInputsMap.Clear();
|
||||
|
||||
foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes())
|
||||
{
|
||||
// Only retrieve indices of simple inputs that are in range. If an input is out of
|
||||
// range, the diagnostic for it will already be emitted by a previous generator step.
|
||||
if (SymbolEqualityComparer.Default.Equals(attributeData.AttributeClass, d2DInputSimpleSymbolAttributeSymbol) &&
|
||||
attributeData.ConstructorArguments is [{ Value: >= 0 and < 8 and int index }])
|
||||
{
|
||||
simpleInputsMap[index] = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool isSimpleInputShader = true;
|
||||
|
||||
// Validate all inputs in our range (filtered by the allowed one)
|
||||
foreach (bool isSimpleInput in simpleInputsMap[..inputCount])
|
||||
{
|
||||
isSimpleInputShader &= isSimpleInput;
|
||||
}
|
||||
|
||||
return isSimpleInputShader;
|
||||
}
|
||||
}
|
||||
@@ -1024,19 +1024,19 @@ partial class DiagnosticDescriptors
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid use of <c>[D2DCompileOptions]</c> requesting to enable linking.
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid use of <c>[D2DPixelOptions]</c> indicating trivial sampling.
|
||||
/// <para>
|
||||
/// Format: <c>"The D2D1 shader of type {0} cannot use D2D1CompileOptions.EnableLinking in its [D2DCompileOptions] attribute, as it doesn't support linking (only D2D1 shaders with no complex inputs can use this option)"</c>.
|
||||
/// Format: <c>"The D2D1 shader of type {0} shouldn't use D2D1PixelOptions.TrivialSampling in its [D2DPixelOptions] attribute, as it has one or more complex inputs (either mark the inputs as simple, or remove the trivial sampling option)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidD2D1CompileOptionsEnableLinkingOnShaderType = new(
|
||||
public static readonly DiagnosticDescriptor InvalidD2D1PixelOptionsTrivialSamplingOnShaderType = new(
|
||||
id: "CMPSD2D0069",
|
||||
title: "Invalid [D2DResourceTextureIndex] use",
|
||||
messageFormat: """The D2D1 shader of type {0} cannot use D2D1CompileOptions.EnableLinking in its [D2DCompileOptions] attribute, as it doesn't support linking (only D2D1 shaders with no complex inputs can use this option)""",
|
||||
title: "Invalid [D2DPixelOptions] use",
|
||||
messageFormat: """The D2D1 shader of type {0} shouldn't use D2D1PixelOptions.TrivialSampling in its [D2DPixelOptions] attribute, as it has one or more complex inputs (either mark the inputs as simple, or remove the trivial sampling option)""",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Warning,
|
||||
isEnabledByDefault: true,
|
||||
description: "A D2D1 shader cannot use D2D1CompileOptions.EnableLinking in its [D2DCompileOptions] attribute if it doesn't support linking (only D2D1 shaders with no complex inputs can use this option).",
|
||||
description: "A D2D1 shader shouldn't use D2D1PixelOptions.TrivialSampling in its [D2DPixelOptions] attribute if it has one or more complex inputs (because trivial sampling shaders can only sample pixels at the same scene coordinate as the output pixel, a shader using this option should only have simple inputs).",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -176,14 +176,28 @@ public enum D2D1CompileOptions
|
||||
EnableLinking = 1 << 31,
|
||||
|
||||
/// <summary>
|
||||
/// The default options for shaders compiled by ComputeSharp.D2D1. Specifically, this combination
|
||||
/// of options is the one used by precompiled shaders (ie. when using <see cref="D2DShaderProfileAttribute"/>),
|
||||
/// and when using <see cref="D2D1PixelShader.LoadBytecode{T}()"/> or any of the overloads.
|
||||
/// The default options for shaders compiled by ComputeSharp.D2D1. Specifically, this combination of options
|
||||
/// is the one used by precompiled shaders (ie. when using <see cref="D2DShaderProfileAttribute"/>), and when
|
||||
/// using <see cref="D2D1PixelShader.LoadBytecode{T}()"/> or any of the overloads, if not manually set.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This option does not include <see cref="EnableLinking"/>, which is instead automatically enabled by shaders
|
||||
/// compiled using any of the APIs mentioned above. When manually compiling shaders from source using the APIs
|
||||
/// from <see cref="D2D1ShaderCompiler"/> instance, <see cref="EnableLinking"/> should be manually used when needed.
|
||||
/// <para>
|
||||
/// This combination is also meant to provide the maximum speed possible without potentially introducing visual artifacts or altering
|
||||
/// the shader outputs in any way. For instance, <see cref="PartialPrecision"/> is not included, because it might affect all computations
|
||||
/// inside the shader on some GPU devices, making issues hard to investigate. As such, it can be considered equivalent to "OptimizeForSpeed",
|
||||
/// which is not available on <see cref="D2D1CompileOptions"/> specifically because it would be identical to this.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// In order to ensure the best performance possible, this combination also includes <see cref="EnableLinking"/>. This will include an
|
||||
/// export function for all shaders, to allow D2D to opportunistically link them for better performance whenever possible. Doing so
|
||||
/// incurs a small binary size cost, as this option will also enable linking for shaders that D2D might never actually link. For most
|
||||
/// scenarios, this cost is minimal and not noticeable. If size is critical, consider using <see cref="OptimizeForSize"/> instead.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
Default = OptimizationLevel3 | WarningsAreErrors | PackMatrixRowMajor
|
||||
Default = OptimizationLevel3 | WarningsAreErrors | PackMatrixRowMajor | EnableLinking,
|
||||
|
||||
/// <summary>
|
||||
/// A combination of options to optimize for minimum size.
|
||||
/// </summary>
|
||||
OptimizeForSize = OptimizationLevel3 | WarningsAreErrors | PackMatrixRowMajor | StripReflectionData
|
||||
}
|
||||
+6
-6
@@ -166,7 +166,7 @@ public class Test_D2DPixelShaderDescriptorGenerator
|
||||
[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>)]
|
||||
@@ -466,7 +466,7 @@ public class Test_D2DPixelShaderDescriptorGenerator
|
||||
[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>)]
|
||||
@@ -818,7 +818,7 @@ public class Test_D2DPixelShaderDescriptorGenerator
|
||||
[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>)]
|
||||
@@ -1116,7 +1116,7 @@ public class Test_D2DPixelShaderDescriptorGenerator
|
||||
[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>)]
|
||||
@@ -1694,7 +1694,7 @@ public class Test_D2DPixelShaderDescriptorGenerator
|
||||
[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>)]
|
||||
@@ -1784,7 +1784,7 @@ public class Test_D2DPixelShaderDescriptorGenerator
|
||||
await CSharpAnalyzerWithLanguageVersionTest<D2DEnableRuntimeCompilationOnTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<ExceededPixelShaderDispatchDataSizeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidAssemblyLevelCompileOptionsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1PixelOptionsTrivialSamplingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2DGeneratedPixelShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2DInputDescriptionAttributeUseAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2DRequiresDoublePrecisionSupportAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
|
||||
+65
@@ -1117,4 +1117,69 @@ public class Test_D2DPixelShaderDescriptorGenerator_Analyzers
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidShaderTypeInputsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TrivialSamplingWithComplexInput_Warns()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1;
|
||||
using float4 = ComputeSharp.Float4;
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[{|CMPSD2D0069:D2DPixelOptions(D2D1PixelOptions.TrivialSampling)|}]
|
||||
internal readonly partial struct MyType : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1PixelOptionsTrivialSamplingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TrivialSamplingWithExplicitComplexInput_Warns()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1;
|
||||
using float4 = ComputeSharp.Float4;
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputComplex(1)]
|
||||
[{|CMPSD2D0069:D2DPixelOptions(D2D1PixelOptions.TrivialSampling)|}]
|
||||
internal readonly partial struct MyType : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1PixelOptionsTrivialSamplingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TrivialSamplingWithLeftoverComplexInput_Warns()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1;
|
||||
using float4 = ComputeSharp.Float4;
|
||||
|
||||
[D2DInputCount(2)]
|
||||
[D2DInputSimple(1)]
|
||||
[{|CMPSD2D0069:D2DPixelOptions(D2D1PixelOptions.TrivialSampling)|}]
|
||||
internal readonly partial struct MyType : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1PixelOptionsTrivialSamplingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.D2D1.SourceGenerators;
|
||||
using ComputeSharp.Tests.SourceGenerators.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests.SourceGenerators;
|
||||
|
||||
[TestClass]
|
||||
public class Test_InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task NoCompileOptionsDoesNotWarn()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
public partial class Foo
|
||||
{
|
||||
[D2DInputCount(0)]
|
||||
private partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute() => 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ValidCompileOptionsDoesNotWarn()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
public partial class Foo
|
||||
{
|
||||
[D2DInputCount(0)]
|
||||
[D2DCompileOptions(D2D1CompileOptions.PackMatrixRowMajor)]
|
||||
private partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute() => 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task EnableLinkingWithNoInputCountDoesNotWarn()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
public partial class Foo
|
||||
{
|
||||
[D2DInputComplex(0)]
|
||||
[D2DCompileOptions(D2D1CompileOptions.EnableLinking)]
|
||||
private partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute() => 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task EnableLinkingWithImplicitComplexInputWarns()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
public partial class Foo
|
||||
{
|
||||
[D2DInputCount(2)]
|
||||
[D2DInputSimple(1)]
|
||||
[{|CMPSD2D0069:D2DCompileOptions(D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking)|}]
|
||||
private partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute() => 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task EnableLinkingWithExplicitComplexInputWarns()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
public partial class Foo
|
||||
{
|
||||
[D2DInputCount(2)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DInputComplex(1)]
|
||||
[{|CMPSD2D0069:D2DCompileOptions(D2D1CompileOptions.Default | D2D1CompileOptions.EnableLinking)|}]
|
||||
private partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute() => 0;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2D1CompileOptionsEnableLinkingOnShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
}
|
||||
@@ -417,13 +417,13 @@ namespace ComputeSharp.D2D1.Tests
|
||||
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"));
|
||||
@@ -534,7 +534,7 @@ namespace ComputeSharp.D2D1.Tests
|
||||
_ = 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);
|
||||
|
||||
@@ -598,7 +598,7 @@ namespace ComputeSharp.D2D1.Tests
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -618,11 +618,11 @@ namespace ComputeSharp.D2D1.Tests
|
||||
[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"));
|
||||
@@ -630,9 +630,9 @@ namespace ComputeSharp.D2D1.Tests
|
||||
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);
|
||||
}
|
||||
@@ -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<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"));
|
||||
|
||||
@@ -80,13 +80,13 @@ public partial class D2D1ShaderCompilerTests
|
||||
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);
|
||||
@@ -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<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()
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする