Merge pull request #587 from Sergio0694/dev/generated-marshaller-attribute
Add [D2DGeneratedPixelShaderDescriptor] attribute and use FAWMN
このコミットが含まれているのは:
75ファイル変更
+1080
-124
検索条件に一致するファイルはありません
@@ -118,6 +118,11 @@ jobs:
|
||||
- name: Run ComputeSharp.D2D1.Tests.AssemblyLevelAttributes
|
||||
run: dotnet test tests\ComputeSharp.D2D1.Tests.AssemblyLevelAttributes\ComputeSharp.D2D1.Tests.AssemblyLevelAttributes.csproj -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed"
|
||||
|
||||
# Run the D2D1 source generators tests as well (only on .NET 6, like for the DX12 ones)
|
||||
- if: matrix.framework == 'net6.0'
|
||||
name: Run ComputeSharp.D2D1.Tests.SourceGenerators
|
||||
run: dotnet test tests\ComputeSharp.D2D1.Tests.SourceGenerators\ComputeSharp.D2D1.Tests.SourceGenerators.csproj -v n -l "console;verbosity=detailed"
|
||||
|
||||
# Run all unit tests using D3D12MA
|
||||
run-tests-d3d12ma:
|
||||
needs: [build-solution]
|
||||
|
||||
+22
-1
@@ -156,7 +156,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.D2D1.Uwp.Tests
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.WinUI.Tests", "tests\ComputeSharp.D2D1.WinUI.Tests\ComputeSharp.D2D1.WinUI.Tests.csproj", "{73C32D0F-64DB-4674-84E9-8FCC41228474}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.D3D12MemoryAllocator", "src\ComputeSharp.D3D12MemoryAllocator\ComputeSharp.D3D12MemoryAllocator.csproj", "{E017B3B6-C7D3-4E53-A7F6-1036178E98C3}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D3D12MemoryAllocator", "src\ComputeSharp.D3D12MemoryAllocator\ComputeSharp.D3D12MemoryAllocator.csproj", "{E017B3B6-C7D3-4E53-A7F6-1036178E98C3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.CodeFixers", "src\ComputeSharp.D2D1.CodeFixers\ComputeSharp.D2D1.CodeFixers.csproj", "{54654960-54B5-4E19-B3ED-993591CA39E5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.D2D1.Tests.SourceGenerators", "tests\ComputeSharp.D2D1.Tests.SourceGenerators\ComputeSharp.D2D1.Tests.SourceGenerators.csproj", "{59A17380-24A0-4BD7-9012-B105A9E7D46F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -454,6 +458,22 @@ Global
|
||||
{E017B3B6-C7D3-4E53-A7F6-1036178E98C3}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{E017B3B6-C7D3-4E53-A7F6-1036178E98C3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E017B3B6-C7D3-4E53-A7F6-1036178E98C3}.Release|x64.Build.0 = Release|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{54654960-54B5-4E19-B3ED-993591CA39E5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -494,6 +514,7 @@ Global
|
||||
{346AEB10-A4EA-427E-8578-F60915DB3053} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{73C32D0F-64DB-4674-84E9-8FCC41228474} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
|
||||
|
||||
@@ -142,8 +142,12 @@
|
||||
<IsPublishedProject>$(ProjectDirectoryPathFromSourceRoot.StartsWith('src\'))</IsPublishedProject>
|
||||
<IsSourceGeneratorProject>false</IsSourceGeneratorProject>
|
||||
<IsSourceGeneratorProject Condition="$(IsPublishedProject) AND $(MSBuildProjectName.EndsWith('.SourceGenerators'))">true</IsSourceGeneratorProject>
|
||||
<IsCodeFixersProject>false</IsCodeFixersProject>
|
||||
<IsCodeFixersProject Condition="$(IsPublishedProject) AND $(MSBuildProjectName.EndsWith('.CodeFixers'))">true</IsCodeFixersProject>
|
||||
<IsAnalyzersProject>false</IsAnalyzersProject>
|
||||
<IsAnalyzersProject Condition="$(IsSourceGeneratorProject) OR $(IsCodeFixersProject)">true</IsAnalyzersProject>
|
||||
<IsPackagedProject>false</IsPackagedProject>
|
||||
<IsPackagedProject Condition="$(IsPublishedProject) AND !$(IsSourceGeneratorProject)">true</IsPackagedProject>
|
||||
<IsPackagedProject Condition="$(IsPublishedProject) AND !$(IsAnalyzersProject)">true</IsPackagedProject>
|
||||
<IsTestProject>$(ProjectDirectoryPathFromSourceRoot.StartsWith('tests\'))</IsTestProject>
|
||||
<IsInternalsTestProject>false</IsInternalsTestProject>
|
||||
<IsInternalsTestProject Condition="$(IsTestProject) AND $(MSBuildProjectName.EndsWith('.Internals'))">true</IsInternalsTestProject>
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ColorfulInfinity : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ContouredLayers : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct FractalTiling : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct HelloWorld : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MengerJourney : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct Octagrams : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ProteanClouds : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct PyramidPattern : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct TerracedHills : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct TriangleGridContouring : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct TwoTiledTruchet : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,208 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Composition;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CodeActions;
|
||||
using Microsoft.CodeAnalysis.CodeFixes;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Editing;
|
||||
using Microsoft.CodeAnalysis.Simplification;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
|
||||
namespace ComputeSharp.D2D1.CodeFixers;
|
||||
|
||||
/// <summary>
|
||||
/// A code fixer that adds the <c>[D2DGeneratedPixelShaderDescriptor]</c> to D2D1 shader types with no descriptor.
|
||||
/// </summary>
|
||||
[ExportCodeFixProvider(LanguageNames.CSharp)]
|
||||
[Shared]
|
||||
public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : CodeFixProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// The set of type names for all D2D attributes that can be over shader types.
|
||||
/// </summary>
|
||||
private static readonly ImmutableArray<string> D2DAttributeTypeNames = ImmutableArray.Create(
|
||||
"ComputeSharp.D2D1.D2DCompileOptionsAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectAuthorAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectCategoryAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectDescriptionAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectDisplayNameAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectIdAttribute",
|
||||
"ComputeSharp.D2D1.D2DInputComplexAttribute",
|
||||
"ComputeSharp.D2D1.D2DInputCountAttribute",
|
||||
"ComputeSharp.D2D1.D2DInputDescriptionAttribute",
|
||||
"ComputeSharp.D2D1.D2DInputSimpleAttribute",
|
||||
"ComputeSharp.D2D1.D2DOutputBufferAttribute",
|
||||
"ComputeSharp.D2D1.D2DPixelOptionsAttribute",
|
||||
"ComputeSharp.D2D1.D2DRequiresScenePositionAttribute",
|
||||
"ComputeSharp.D2D1.D2DShaderProfileAttribute");
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(MissingPixelShaderDescriptorOnPixelShaderTypeId);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Microsoft.CodeAnalysis.CodeFixes.FixAllProvider? GetFixAllProvider()
|
||||
{
|
||||
return new FixAllProvider();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
|
||||
{
|
||||
Diagnostic diagnostic = context.Diagnostics[0];
|
||||
TextSpan diagnosticSpan = context.Span;
|
||||
|
||||
SyntaxNode? root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Get the struct declaration from the target diagnostic
|
||||
if (root?.FindNode(diagnosticSpan) is StructDeclarationSyntax structDeclaration)
|
||||
{
|
||||
// Register the code fix to update the return type to be Task instead
|
||||
context.RegisterCodeFix(
|
||||
CodeAction.Create(
|
||||
title: "Add [D2DGeneratedPixelShaderDescriptor] attribute",
|
||||
createChangedDocument: token => AddMissingD2DGeneratedPixelShaderDescriptorAttribute(context.Document, root, structDeclaration, token),
|
||||
equivalenceKey: "Add [D2DGeneratedPixelShaderDescriptor] attribute"),
|
||||
diagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the code fix to add the [D2DGeneratedPixelShaderDescriptor] attribute to a target type.
|
||||
/// </summary>
|
||||
/// <param name="document">The original document being fixed.</param>
|
||||
/// <param name="root">The original tree root belonging to the current document.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> to update.</param>
|
||||
/// <param name="cancellationToken">The cancellation token for the operation.</param>
|
||||
/// <returns>An updated document with the applied code fix, and the return type of the method being <see cref="Task"/>.</returns>
|
||||
private static async Task<Document> AddMissingD2DGeneratedPixelShaderDescriptorAttribute(
|
||||
Document document,
|
||||
SyntaxNode root,
|
||||
StructDeclarationSyntax structDeclaration,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the new struct declaration
|
||||
SyntaxNode updatedStructDeclaration = await AddMissingD2DGeneratedPixelShaderDescriptorAttribute(
|
||||
document,
|
||||
structDeclaration,
|
||||
cancellationToken);
|
||||
|
||||
// Replace the node in the document tree
|
||||
return document.WithSyntaxRoot(root.ReplaceNode(structDeclaration, updatedStructDeclaration));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the code fix to add the [D2DGeneratedPixelShaderDescriptor] attribute to a target type.
|
||||
/// </summary>
|
||||
/// <param name="document">The original document being fixed.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> to update.</param>
|
||||
/// <param name="cancellationToken">The cancellation token for the operation.</param>
|
||||
/// <returns>An updated document with the applied code fix, and the return type of the method being <see cref="Task"/>.</returns>
|
||||
private static async Task<SyntaxNode> AddMissingD2DGeneratedPixelShaderDescriptorAttribute(
|
||||
Document document,
|
||||
StructDeclarationSyntax structDeclaration,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the semantic model (bail if it's not available)
|
||||
if (await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false) is not SemanticModel semanticModel)
|
||||
{
|
||||
return structDeclaration;
|
||||
}
|
||||
|
||||
// Build the map of D2D attributes to look for
|
||||
if (!semanticModel.Compilation.TryBuildNamedTypeSymbolSet(D2DAttributeTypeNames, out ImmutableHashSet<INamedTypeSymbol>? d2DAttributeTypeSymbols))
|
||||
{
|
||||
return structDeclaration;
|
||||
}
|
||||
|
||||
// Also bail if we can't resolve the [D2DGeneratedPixelShaderDescriptor] attribute symbol (this should really never happen)
|
||||
if (semanticModel.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DGeneratedPixelShaderDescriptorAttribute") is not INamedTypeSymbol attributeSymbol)
|
||||
{
|
||||
return structDeclaration;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
|
||||
// Find the index to use to insert the attribute. We want to make it so that if the struct declaration
|
||||
// has a bunch of D2D attributes, the new one will be inserted right after that. This way the final list
|
||||
// will be nicely sorted, instead of having D2D attributes interleaving other unrelated attributes, if any.
|
||||
foreach (AttributeListSyntax attributeList in structDeclaration.AttributeLists)
|
||||
{
|
||||
// Make sure we have an attribute to check
|
||||
if (attributeList.Attributes is not [AttributeSyntax attribute, ..])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resolve the symbol for the attribute (stop here if this failed for whatever reason)
|
||||
if (!semanticModel.GetSymbolInfo(attribute, cancellationToken).TryGetAttributeTypeSymbol(out INamedTypeSymbol? attributeTypeSymbol))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// If the attribute is D2D one, increment the index and continue
|
||||
if (d2DAttributeTypeSymbols.Contains(attributeTypeSymbol))
|
||||
{
|
||||
index++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, stop here, we reached the end of the sequence
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SyntaxGenerator syntaxGenerator = SyntaxGenerator.GetGenerator(document);
|
||||
|
||||
// Create the attribute syntax for the new attribute. Also annotate it
|
||||
// to automatically add using directives to the document, if needed.
|
||||
// Then create the attribute syntax and insert it at the right position.
|
||||
SyntaxNode attributeTypeSyntax = syntaxGenerator.TypeExpression(attributeSymbol).WithAdditionalAnnotations(Simplifier.AddImportsAnnotation);
|
||||
SyntaxNode attributeSyntax = syntaxGenerator.Attribute(attributeTypeSyntax);
|
||||
SyntaxNode updatedStructDeclarationSyntax = syntaxGenerator.InsertAttributes(structDeclaration, index, attributeSyntax);
|
||||
|
||||
// Replace the node in the syntax tree
|
||||
return updatedStructDeclarationSyntax;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="FixAllProvider"/> with the logic from <see cref="MissingPixelShaderDescriptorOnPixelShaderCodeFixer"/>.
|
||||
/// </summary>
|
||||
private sealed class FixAllProvider : DocumentBasedFixAllProvider
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<Document?> FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
|
||||
{
|
||||
// Get the document root (this should always succeed)
|
||||
if (await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false) is not SyntaxNode root)
|
||||
{
|
||||
return document;
|
||||
}
|
||||
|
||||
SyntaxEditor syntaxEditor = new(root, fixAllContext.Solution.Services);
|
||||
|
||||
foreach (Diagnostic diagnostic in diagnostics)
|
||||
{
|
||||
// Get the current struct declaration for the diagnostic
|
||||
if (root.FindNode(diagnostic.Location.SourceSpan) is not StructDeclarationSyntax structDeclaration)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the syntax node with the updated declaration
|
||||
SyntaxNode updatedStructDeclaration = await AddMissingD2DGeneratedPixelShaderDescriptorAttribute(
|
||||
document,
|
||||
structDeclaration,
|
||||
fixAllContext.CancellationToken);
|
||||
|
||||
// Replace the node via the editor
|
||||
syntaxEditor.ReplaceNode(structDeclaration, updatedStructDeclaration);
|
||||
}
|
||||
|
||||
return document.WithSyntaxRoot(syntaxEditor.GetChangedRoot());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,3 +71,5 @@ CMPSD2D0061 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
|
||||
CMPSD2D0062 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPSD2D0063 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPSD2D0064 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPSD2D0065 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPSD2D0066 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
@@ -108,4 +108,9 @@
|
||||
|
||||
<!-- Shared project with .NET Standard 2.0 polyfills -->
|
||||
<Import Project="..\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems" Label="Shared" />
|
||||
|
||||
<!-- Give access to the code fixers project for the exported diagnostic ids and properties -->
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="ComputeSharp.D2D1.CodeFixers, PublicKey=$(AssemblySignPublicKey)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+2
-2
@@ -6,7 +6,7 @@ using ComputeSharp.SourceGeneration.Mappings;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class CreateFromConstantBuffer
|
||||
@@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator
|
||||
string typeName = info.Hierarchy.Hierarchy[0].QualifiedName;
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]");
|
||||
writer.WriteLine($"readonly unsafe {typeName} global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.CreateFromConstantBuffer(global::System.ReadOnlySpan<byte> data)");
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class EffectId
|
||||
@@ -18,7 +18,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly ref readonly global::System.Guid global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.EffectId");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
+1
-1
@@ -11,7 +11,7 @@ using Microsoft.CodeAnalysis;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>EffectId</c> property.
|
||||
+2
-2
@@ -5,7 +5,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class EffectMetadata
|
||||
@@ -60,7 +60,7 @@ partial class ID2D1ShaderGenerator
|
||||
private static void WriteEffectMetadataSyntax(string qualifiedName, string propertyName, string? metadataValue, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.Write($"readonly string? global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{qualifiedName}>.{propertyName} => ");
|
||||
|
||||
// Append null or the metadata value as a string literal
|
||||
+1
-1
@@ -4,7 +4,7 @@ using Microsoft.CodeAnalysis;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the effect metadata properties.
|
||||
+7
-7
@@ -7,7 +7,7 @@ using Microsoft.CodeAnalysis;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class HlslBytecode
|
||||
@@ -20,8 +20,8 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteShaderProfileSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.EffectiveShaderProfile};");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.ShaderProfile};");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -33,14 +33,14 @@ partial class ID2D1ShaderGenerator
|
||||
{
|
||||
// Get a formatted representation of the compile options being used
|
||||
string compileOptionsExpression =
|
||||
info.HlslInfoKey.EffectiveCompileOptions
|
||||
info.HlslInfoKey.CompileOptions
|
||||
.ToString()
|
||||
.Split(',')
|
||||
.Select(static name => $"global::ComputeSharp.D2D1.D2D1CompileOptions.{name.Trim()}")
|
||||
.Aggregate("", static (left, right) => left.Length > 0 ? $"{left} | {right}" : right);
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.CompileOptions => {compileOptionsExpression};");
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteHlslBytecodeSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<byte> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslBytecode => ");
|
||||
|
||||
// If there is no bytecode, just return a default expression.
|
||||
@@ -98,7 +98,7 @@ partial class ID2D1ShaderGenerator
|
||||
writer.WriteLine($$"""/// <summary>""");
|
||||
writer.WriteLine($$"""/// <see cref="MemoryManager{T}"/> implementation to get the HLSL bytecode.""");
|
||||
writer.WriteLine($$"""/// </summary>""");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
|
||||
writer.WriteGeneratedAttributes(GeneratorName, useFullyQualifiedTypeNames: false);
|
||||
writer.WriteLine($$"""file sealed class HlslBytecodeMemoryManager : MemoryManager<byte>""");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
+10
-7
@@ -18,7 +18,7 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the HLSL bytecode properties.
|
||||
@@ -87,9 +87,13 @@ partial class ID2D1ShaderGenerator
|
||||
/// Gets the effective shader profile to use.
|
||||
/// </summary>
|
||||
/// <param name="shaderProfile">The requested shader profile.</param>
|
||||
/// <param name="isCompilationEnabled">Whether compilation should be performed with the input profile.</param>
|
||||
/// <returns>The effective shader profile.</returns>
|
||||
public static D2D1ShaderProfile GetEffectiveShaderProfile(D2D1ShaderProfile? shaderProfile)
|
||||
public static D2D1ShaderProfile GetEffectiveShaderProfile(D2D1ShaderProfile? shaderProfile, out bool isCompilationEnabled)
|
||||
{
|
||||
// Compilation is only enabled if the user explicitly selected a shader profile
|
||||
isCompilationEnabled = shaderProfile is not null;
|
||||
|
||||
// The effective shader profile is either be the requested one, or the default value (which maps to PS5.0)
|
||||
return shaderProfile ?? D2D1ShaderProfile.PixelShader50;
|
||||
}
|
||||
@@ -150,11 +154,10 @@ partial class ID2D1ShaderGenerator
|
||||
{
|
||||
static unsafe HlslBytecodeInfo GetInfo(HlslBytecodeInfoKey key, CancellationToken token)
|
||||
{
|
||||
// No embedded shader was requested, or there were some errors earlier in the pipeline.
|
||||
// Check if the compilation is not enabled (eg. if there's been errors earlier in the pipeline).
|
||||
// In this case, skip the compilation, as diagnostic will be emitted for those anyway.
|
||||
// Compiling would just add overhead and result in more errors, as the HLSL would be invalid.
|
||||
// We also skip compilation if no shader profile has been requested (we never just assume one).
|
||||
if (key.HasErrors || key.RequestedShaderProfile is null)
|
||||
if (!key.IsCompilationEnabled)
|
||||
{
|
||||
return HlslBytecodeInfo.Missing.Instance;
|
||||
}
|
||||
@@ -166,8 +169,8 @@ partial class ID2D1ShaderGenerator
|
||||
// Compile the shader bytecode using the effective parameters
|
||||
using ComPtr<ID3DBlob> dxcBlobBytecode = D3DCompiler.Compile(
|
||||
key.HlslSource.AsSpan(),
|
||||
key.EffectiveShaderProfile,
|
||||
key.EffectiveCompileOptions);
|
||||
key.ShaderProfile,
|
||||
key.CompileOptions);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class HlslSource
|
||||
@@ -18,7 +18,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly string global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslSource =>");
|
||||
writer.IncreaseIndent();
|
||||
writer.WriteLine("\"\"\"");
|
||||
+1
-1
@@ -17,7 +17,7 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>HlslSource</c> property.
|
||||
+3
-3
@@ -7,7 +7,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritoc/>
|
||||
private static partial class InputDescriptions
|
||||
@@ -20,7 +20,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1InputDescription> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputDescriptions => ");
|
||||
|
||||
// If there are no input descriptions, just return a default expression.
|
||||
@@ -66,7 +66,7 @@ partial class ID2D1ShaderGenerator
|
||||
writer.WriteLine($$"""/// <summary>""");
|
||||
writer.WriteLine($$"""/// A container type for additional data needed by the shader.""");
|
||||
writer.WriteLine($$"""/// </summary>""");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
|
||||
writer.WriteGeneratedAttributes(GeneratorName, useFullyQualifiedTypeNames: false);
|
||||
writer.WriteLine($$"""file static class Data""");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
+1
-1
@@ -10,7 +10,7 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>InputDescriptions</c> property.
|
||||
+3
-3
@@ -5,7 +5,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class InputTypes
|
||||
@@ -18,7 +18,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputTypes => ");
|
||||
|
||||
// If there are no inputs, simply return a default expression. Otherwise, create
|
||||
@@ -65,7 +65,7 @@ partial class ID2D1ShaderGenerator
|
||||
writer.WriteLine($$"""/// <summary>""");
|
||||
writer.WriteLine($$"""/// A <see cref="MemoryManager{T}"/> implementation to get the input types.""");
|
||||
writer.WriteLine($$"""/// </summary>""");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
|
||||
writer.WriteGeneratedAttributes(GeneratorName, useFullyQualifiedTypeNames: false);
|
||||
writer.WriteLine($$"""file sealed class InputTypesMemoryManager : MemoryManager<D2D1PixelShaderInputType>""");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
+1
-1
@@ -9,7 +9,7 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>InputTypes</c> properties.
|
||||
+3
-3
@@ -6,7 +6,7 @@ using ComputeSharp.SourceGeneration.Mappings;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class LoadConstantBuffer
|
||||
@@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator
|
||||
string typeName = info.Hierarchy.Hierarchy[0].QualifiedName;
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]");
|
||||
writer.WriteLine($"readonly unsafe void global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.LoadConstantBuffer<TLoader>(in {typeName} shader, ref TLoader loader)");
|
||||
|
||||
@@ -105,7 +105,7 @@ partial class ID2D1ShaderGenerator
|
||||
writer.WriteLine($$"""/// <summary>""");
|
||||
writer.WriteLine($$"""/// A type representing the constant buffer native layout for <see cref="{{fullyQualifiedTypeName}}"/>.""");
|
||||
writer.WriteLine($$"""/// </summary>""");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator), useFullyQualifiedTypeNames: false);
|
||||
writer.WriteGeneratedAttributes(GeneratorName, useFullyQualifiedTypeNames: false);
|
||||
writer.WriteLine($$"""[StructLayout(LayoutKind.Explicit, Size = {{info.ConstantBufferSizeInBytes}})]""");
|
||||
writer.WriteLine($$"""file struct ConstantBuffer""");
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>LoadConstantBuffer</c> method.
|
||||
+4
-4
@@ -5,7 +5,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the available numeric properties.
|
||||
@@ -20,7 +20,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteConstantBufferSizeSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};");
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteInputCountSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputCount => {info.InputTypes.Length};");
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteResourceTextureCountSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceTextureCount => {info.ResourceTextureDescriptions.Length};");
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -6,7 +6,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class OutputBuffer
|
||||
@@ -27,7 +27,7 @@ partial class ID2D1ShaderGenerator
|
||||
};
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1BufferPrecision global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.BufferPrecision => {bufferPrecisionExpression};");
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ partial class ID2D1ShaderGenerator
|
||||
};
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ChannelDepth global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ChannelDepth => {channelDepthExpression};");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ using Microsoft.CodeAnalysis;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the output buffer properties.
|
||||
+2
-2
@@ -5,7 +5,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class PixelOptions
|
||||
@@ -25,7 +25,7 @@ partial class ID2D1ShaderGenerator
|
||||
};
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.PixelOptions => {pixelOptionsExpression};");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ using Microsoft.CodeAnalysis;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>PixelOptions</c> property.
|
||||
+2
-2
@@ -7,7 +7,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <inheritoc/>
|
||||
private static partial class ResourceTextureDescriptions
|
||||
@@ -20,7 +20,7 @@ partial class ID2D1ShaderGenerator
|
||||
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceTextureDescriptions => ");
|
||||
|
||||
// If there are no resource texture descriptions, just return a default expression.
|
||||
+1
-1
@@ -11,7 +11,7 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>ResourceTextureDescriptions</c> property.
|
||||
+16
-14
@@ -5,24 +5,29 @@ using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Models;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A source generator creating data loaders for the <see cref="ID2D1PixelShader"/> type.
|
||||
/// A source generator creating pixel shader descriptors for annotated D2D1 pixel shader types.
|
||||
/// </summary>
|
||||
[Generator(LanguageNames.CSharp)]
|
||||
public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of generator to include in the generated code.
|
||||
/// </summary>
|
||||
private const string GeneratorName = "ComputeSharp.D2D1.D2DPixelShaderDescriptorGenerator";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
// Discover all shader types and extract all the necessary info from each of them
|
||||
IncrementalValuesProvider<D2D1ShaderInfo> shaderInfo =
|
||||
context.SyntaxProvider
|
||||
.CreateSyntaxProvider(
|
||||
.ForAttributeWithMetadataName(
|
||||
"ComputeSharp.D2D1.D2DGeneratedPixelShaderDescriptorAttribute",
|
||||
static (node, _) => node.IsTypeDeclarationWithOrPotentiallyWithBaseTypes<StructDeclarationSyntax>(),
|
||||
static (context, token) =>
|
||||
{
|
||||
@@ -32,16 +37,16 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
return default;
|
||||
}
|
||||
|
||||
StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.Node;
|
||||
|
||||
// If the type symbol doesn't have at least one interface, it can't possibly be a shader type
|
||||
if (context.SemanticModel.GetDeclaredSymbol(typeDeclaration, token) is not INamedTypeSymbol { AllInterfaces.Length: > 0 } typeSymbol)
|
||||
if (context.TargetSymbol is not INamedTypeSymbol { AllInterfaces.Length: > 0 } typeSymbol)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.TargetNode;
|
||||
|
||||
// Check that the shader implements the ID2D1PixelShader interface
|
||||
if (!IsD2D1PixelShaderType(typeSymbol, context.SemanticModel.Compilation))
|
||||
if (!typeSymbol.HasInterfaceWithType(context.SemanticModel.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.ID2D1PixelShader")!))
|
||||
{
|
||||
return default;
|
||||
}
|
||||
@@ -135,9 +140,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
bool isLinkingSupported = HlslBytecode.IsSimpleInputShader(typeSymbol, inputCount);
|
||||
D2D1ShaderProfile? requestedShaderProfile = HlslBytecode.GetRequestedShaderProfile(typeSymbol);
|
||||
D2D1CompileOptions? requestedCompileOptions = HlslBytecode.GetRequestedCompileOptions(diagnostics, typeSymbol);
|
||||
D2D1ShaderProfile effectiveShaderProfile = HlslBytecode.GetEffectiveShaderProfile(requestedShaderProfile);
|
||||
D2D1ShaderProfile effectiveShaderProfile = HlslBytecode.GetEffectiveShaderProfile(requestedShaderProfile, out bool isCompilationEnabled);
|
||||
D2D1CompileOptions effectiveCompileOptions = HlslBytecode.GetEffectiveCompileOptions(requestedCompileOptions, isLinkingSupported);
|
||||
bool hasErrors = diagnostics.Count > 0;
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -145,13 +149,11 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
// This is done last so that it can be skipped if any errors happened before.
|
||||
HlslBytecodeInfoKey hlslInfoKey = new(
|
||||
hlslSource,
|
||||
requestedShaderProfile,
|
||||
requestedCompileOptions,
|
||||
effectiveShaderProfile,
|
||||
effectiveCompileOptions,
|
||||
hasErrors);
|
||||
isCompilationEnabled);
|
||||
|
||||
// TODO: cache this across transform runs
|
||||
// Get the existing compiled shader, or compile the processed HLSL code
|
||||
HlslBytecodeInfo hlslInfo = HlslBytecode.GetInfo(ref hlslInfoKey, token);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
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 the [D2DGeneratedPixelShaderDescriptor] attribute is used on an invalid target type.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class InvalidD2DGeneratedPixelShaderDescriptorAttributeTargetAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterCompilationStartAction(static context =>
|
||||
{
|
||||
// Get the ID2D1PixelShader and [D2DGeneratedPixelShaderDescriptor] symbols
|
||||
if (context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.ID2D1PixelShader") is not { } d2D1PixelShaderSymbol ||
|
||||
context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DGeneratedPixelShaderDescriptorAttribute") is not { } d2DGeneratedPixelShaderDescriptorAttributeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.RegisterSymbolAction(context =>
|
||||
{
|
||||
// Only struct types are possible targets
|
||||
if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Emit a diagnostic if the target type is using [D2DGeneratedPixelShaderDescriptor] but does not implement ID2D1PixelShader
|
||||
if (typeSymbol.TryGetAttributeWithType(d2DGeneratedPixelShaderDescriptorAttributeSymbol, out AttributeData? attribute) &&
|
||||
!typeSymbol.HasInterfaceWithType(d2D1PixelShaderSymbol))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget,
|
||||
attribute.GetLocation(),
|
||||
typeSymbol));
|
||||
}
|
||||
}, SymbolKind.NamedType);
|
||||
});
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
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 a warning whenever a D2D1 shader type does not have an associated descriptor.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class MissingPixelShaderDescriptorOnPixelShaderAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(MissingPixelShaderDescriptorOnPixelShaderType);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterCompilationStartAction(static context =>
|
||||
{
|
||||
// Get the ID2D1PixelShader, ID2D1PixelShaderDescriptor<T> and [D2DGeneratedPixelShaderDescriptor] symbols
|
||||
if (context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.ID2D1PixelShader") is not { } d2D1PixelShaderSymbol ||
|
||||
context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor`1") is not { } d2D1PixelShaderDescriptorSymbol ||
|
||||
context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DGeneratedPixelShaderDescriptorAttribute") is not { } d2DGeneratedPixelShaderDescriptorAttributeSymbol)
|
||||
{
|
||||
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 a pixel shader type, immediately bail out
|
||||
if (!typeSymbol.HasInterfaceWithType(d2D1PixelShaderSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Emit a diagnostic if the descriptor is missing for the shader type
|
||||
if (!typeSymbol.HasInterfaceWithType(d2D1PixelShaderDescriptorSymbol) &&
|
||||
!typeSymbol.HasAttributeWithType(d2DGeneratedPixelShaderDescriptorAttributeSymbol))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
MissingPixelShaderDescriptorOnPixelShaderType,
|
||||
typeSymbol.Locations.FirstOrDefault(),
|
||||
typeSymbol));
|
||||
}
|
||||
}, SymbolKind.NamedType);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,11 @@ namespace ComputeSharp.SourceGeneration.Diagnostics;
|
||||
/// <inheritdoc/>
|
||||
partial class DiagnosticDescriptors
|
||||
{
|
||||
/// <summary>
|
||||
/// The diagnostic id for <see cref="MissingPixelShaderDescriptorOnPixelShaderType"/>.
|
||||
/// </summary>
|
||||
public const string MissingPixelShaderDescriptorOnPixelShaderTypeId = "CMPSD2D0065";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid shader field.
|
||||
/// <para>
|
||||
@@ -954,4 +959,37 @@ partial class DiagnosticDescriptors
|
||||
description: "Unsafe blocks must be enabled for the source generators to emit valid code (the <AllowUnsafeBlocks>true</AllowUnsafeBlocks> option must be set in the .csproj/.props file).",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp",
|
||||
customTags: WellKnownDiagnosticTags.CompilationEnd);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when a pixel shader type doesn't have an associated descriptor.
|
||||
/// <para>
|
||||
/// Format: <c>"The D2D1 shader of type {0} does not have an associated descriptor (it can be autogenerated via the [D2DGeneratedPixelShaderDescriptor] attribute)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor MissingPixelShaderDescriptorOnPixelShaderType = new DiagnosticDescriptor(
|
||||
id: MissingPixelShaderDescriptorOnPixelShaderTypeId,
|
||||
title: "Missing descriptor for D2D1 pixel shader type",
|
||||
messageFormat: "The D2D1 shader of type {0} does not have an associated descriptor (it can be autogenerated via the [D2DGeneratedPixelShaderDescriptor] attribute)",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Warning,
|
||||
isEnabledByDefault: true,
|
||||
description: "All D2D1 shader types must have an associated descriptor (it can be autogenerated via the [D2DGeneratedPixelShaderDescriptor] attribute).",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp",
|
||||
customTags: WellKnownDiagnosticTags.CompilationEnd);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DGeneratedPixelShaderDescriptor]</c> attribute is being used on an invalid target type.
|
||||
/// <para>
|
||||
/// Format: <c>"The type {0} is not a valid target for the [D2DGeneratedPixelShaderDescriptor] attribute (only types implementing the ID2D1PixelShader interface are valid)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget = new DiagnosticDescriptor(
|
||||
id: "CMPSD2D0066",
|
||||
title: "Invalid [D2DGeneratedPixelShaderDescriptor] attribute target",
|
||||
messageFormat: "The type {0} is not a valid target for the [D2DGeneratedPixelShaderDescriptor] attribute (only types implementing ID2D1PixelShader interface are valid)",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The [D2DGeneratedPixelShaderDescriptor] attribute must be used on types that implement the ID2D1PixelShader interface.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
+2
-4
@@ -52,15 +52,13 @@ public sealed class D2D1ResourceTextureUninitializedFieldDiagnosticSuppressor :
|
||||
HlslKnownTypes.IsResourceTextureType(fieldSymbol.Type.GetFullyQualifiedMetadataName()))
|
||||
{
|
||||
// Get the ID2D1PixelShader interface symbol to the check the containing type of the field
|
||||
INamedTypeSymbol? pixelShaderInterfaceSymbol = semanticModel.Compilation.GetTypeByMetadataName(typeof(ID2D1PixelShader).FullName)!;
|
||||
|
||||
if (pixelShaderInterfaceSymbol is null)
|
||||
if (semanticModel.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.ID2D1PixelShader") is not { } d2D1PixelShaderSymbol)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Also check if the containing type is in fact a D2D1 pixel shader type
|
||||
if (ID2D1ShaderGenerator.IsD2D1PixelShaderType(structSymbol, semanticModel.Compilation))
|
||||
if (structSymbol.HasInterfaceWithType(d2D1PixelShaderSymbol))
|
||||
{
|
||||
context.ReportSuppression(Suppression.Create(UninitializedD2D1ResourceTextureField, diagnostic));
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the shader type for a given shader, if any.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input <see cref="INamedTypeSymbol"/> instance to check.</param>
|
||||
/// <param name="compilation">The <see cref="Compilation"/> instance currently in use.</param>
|
||||
/// <returns>Whether or not <paramref name="typeSymbol"/> is a D2D1 interface type.</returns>
|
||||
public static bool IsD2D1PixelShaderType(INamedTypeSymbol typeSymbol, Compilation compilation)
|
||||
{
|
||||
foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces)
|
||||
{
|
||||
if (interfaceSymbol.Name == nameof(ID2D1PixelShader))
|
||||
{
|
||||
INamedTypeSymbol d2D1PixelShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.D2D1.ID2D1PixelShader")!;
|
||||
|
||||
if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, d2D1PixelShaderSymbol))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,11 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// A model with info to be a unique key for <see cref="HlslBytecodeInfo"/> instances.
|
||||
/// </summary>
|
||||
/// <param name="HlslSource">The input HLSL source code.</param>
|
||||
/// <param name="RequestedShaderProfile">The requested shader profile, if available.</param>
|
||||
/// <param name="RequestedCompileOptions">The requested compile options, if available.</param>
|
||||
/// <param name="EffectiveShaderProfile">The effective shader profile.</param>
|
||||
/// <param name="EffectiveCompileOptions">The effective compile options.</param>
|
||||
/// <param name="HasErrors">Whether any errors were produced when analyzing the shader.</param>
|
||||
/// <param name="ShaderProfile">The shader profile.</param>
|
||||
/// <param name="CompileOptions">The compile options.</param>
|
||||
/// <param name="IsCompilationEnabled">Whether compilation should be attempted for the current info.</param>
|
||||
internal sealed record HlslBytecodeInfoKey(
|
||||
string HlslSource,
|
||||
D2D1ShaderProfile? RequestedShaderProfile,
|
||||
D2D1CompileOptions? RequestedCompileOptions,
|
||||
D2D1ShaderProfile EffectiveShaderProfile,
|
||||
D2D1CompileOptions EffectiveCompileOptions,
|
||||
bool HasErrors);
|
||||
D2D1ShaderProfile ShaderProfile,
|
||||
D2D1CompileOptions CompileOptions,
|
||||
bool IsCompilationEnabled);
|
||||
@@ -15,8 +15,6 @@ namespace ComputeSharp.D2D1;
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Note that the <see cref="D2D1CompileOptions.PackMatrixRowMajor"/> is always enabled automatically and does not need to be
|
||||
/// specified. This option is mandatory, as the generated code to load the constant buffer from a shader assumes the layout
|
||||
/// for matrix types is row major. For the same reason, using <see cref="D2D1CompileOptions.PackMatrixColumnMajor"/> is not
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.D2D1;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a given D2D1 shader should have its associated descriptor code being generated.
|
||||
/// <para>
|
||||
/// This attribute can be used on shader types that are declared as <see langword="partial"/>:
|
||||
/// <code>
|
||||
/// [D2DGeneratedPixelShaderDescriptor]
|
||||
/// partial struct MyShader : ID2D1PixelShader
|
||||
/// {
|
||||
/// }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// When a shader is annotated with <see cref="D2DGeneratedPixelShaderDescriptorAttribute"/>, the source generator will also add
|
||||
/// <see cref="Descriptors.ID2D1PixelShaderDescriptor{T}"/> to its implemented interfaces, and implement its APIs automatically.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class D2DGeneratedPixelShaderDescriptorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IFieldSymbolExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ITypeSymbolExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ISymbolExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\SymbolInfoExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)helpers\DynamicCache{TKey,TValue}.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\EquatableArray{T}.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\HashCode.cs" />
|
||||
|
||||
@@ -27,6 +27,17 @@ internal static class ISymbolExtensions
|
||||
return symbol.ToDisplayString(FullyQualifiedWithoutGlobalFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given symbol has an attribute with the specified type.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="ISymbol"/> instance to check.</param>
|
||||
/// <param name="typeSymbol">The <see cref="ITypeSymbol"/> instance for the attribute type to look for.</param>
|
||||
/// <returns>Whether or not <paramref name="symbol"/> has an attribute with the specified type.</returns>
|
||||
public static bool HasAttributeWithType(this ISymbol symbol, ITypeSymbol typeSymbol)
|
||||
{
|
||||
return TryGetAttributeWithType(symbol, typeSymbol, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get an attribute with the specified type.
|
||||
/// </summary>
|
||||
|
||||
@@ -24,6 +24,25 @@ internal static class ITypeSymbolExtensions
|
||||
return builder.WrittenSpan.SequenceEqual(name.AsSpan());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given <see cref="ITypeSymbol"/> implements an interface of a specified type.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The target <see cref="ITypeSymbol"/> instance to check.</param>
|
||||
/// <param name="interfaceSymbol">The <see cref="ITypeSymbol"/> instane to check for inheritance from.</param>
|
||||
/// <returns>Whether or not <paramref name="typeSymbol"/> has an interface of type <paramref name="interfaceSymbol"/>.</returns>
|
||||
public static bool HasInterfaceWithType(this ITypeSymbol typeSymbol, ITypeSymbol interfaceSymbol)
|
||||
{
|
||||
foreach (INamedTypeSymbol interfaceType in typeSymbol.AllInterfaces)
|
||||
{
|
||||
if (SymbolEqualityComparer.Default.Equals(interfaceType, interfaceSymbol))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fully qualified metadata name for a given <see cref="ITypeSymbol"/> instance.
|
||||
/// </summary>
|
||||
|
||||
@@ -17,19 +17,23 @@ internal static class IndentedTextWriterExtensions
|
||||
/// </code>
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
/// <param name="generatorType">The type of the running generator.</param>
|
||||
/// <param name="generatorName">The name of the generator.</param>
|
||||
/// <param name="useFullyQualifiedTypeNames">Whether to use fully qualified type names or not.</param>
|
||||
public static void WriteGeneratedAttributes(this IndentedTextWriter writer, Type generatorType, bool useFullyQualifiedTypeNames = true)
|
||||
public static void WriteGeneratedAttributes(this IndentedTextWriter writer, string generatorName, bool useFullyQualifiedTypeNames = true)
|
||||
{
|
||||
// We can use this class to get the assembly, as all files for generators are just included
|
||||
// via shared projects. As such, the assembly will be the same as the generator type itself.
|
||||
Version assemblyVersion = typeof(IndentedTextWriterExtensions).Assembly.GetName().Version;
|
||||
|
||||
if (useFullyQualifiedTypeNames)
|
||||
{
|
||||
writer.WriteLine($$"""[global::System.CodeDom.Compiler.GeneratedCode("{{generatorType.FullName}}", "{{generatorType.Assembly.GetName().Version}}")]""");
|
||||
writer.WriteLine($$"""[global::System.CodeDom.Compiler.GeneratedCode("{{generatorName}}", "{{assemblyVersion}}")]""");
|
||||
writer.WriteLine($$"""[global::System.Diagnostics.DebuggerNonUserCode]""");
|
||||
writer.WriteLine($$"""[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]""");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteLine($$"""[GeneratedCode("{{generatorType.FullName}}", "{{generatorType.Assembly.GetName().Version}}")]""");
|
||||
writer.WriteLine($$"""[GeneratedCode("{{generatorName}}", "{{assemblyVersion}}")]""");
|
||||
writer.WriteLine($$"""[DebuggerNonUserCode]""");
|
||||
writer.WriteLine($$"""[ExcludeFromCodeCoverage]""");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for the <see cref="SymbolInfo"/> type.
|
||||
/// </summary>
|
||||
internal static class SymbolInfoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to get the resolved attribute type symbol from a given <see cref="SymbolInfo"/> value.
|
||||
/// </summary>
|
||||
/// <param name="symbolInfo">The <see cref="SymbolInfo"/> value to check.</param>
|
||||
/// <param name="typeSymbol">The resulting attribute type symbol, if correctly resolved.</param>
|
||||
/// <returns>Whether <paramref name="symbolInfo"/> is resolved to a symbol.</returns>
|
||||
/// <remarks>
|
||||
/// This can be used to ensure users haven't eg. spelled names incorrecty or missed a using directive. Normally, code would just
|
||||
/// not compile if that was the case, but that doesn't apply for attributes using invalid targets. In that case, Roslyn will ignore
|
||||
/// any errors, meaning the generator has to validate the type symbols are correctly resolved on its own.
|
||||
/// </remarks>
|
||||
public static bool TryGetAttributeTypeSymbol(this SymbolInfo symbolInfo, [NotNullWhen(true)] out INamedTypeSymbol? typeSymbol)
|
||||
{
|
||||
ISymbol? attributeSymbol = symbolInfo.Symbol;
|
||||
|
||||
// If no symbol is selected and there is a single candidate symbol, use that
|
||||
if (attributeSymbol is null && symbolInfo.CandidateSymbols is [ISymbol candidateSymbol])
|
||||
{
|
||||
attributeSymbol = candidateSymbol;
|
||||
}
|
||||
|
||||
// Extract the symbol from either the current one or the containing type
|
||||
if ((attributeSymbol as INamedTypeSymbol ?? attributeSymbol?.ContainingType) is not INamedTypeSymbol resultingSymbol)
|
||||
{
|
||||
typeSymbol = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
typeSymbol = resultingSymbol;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -45,11 +45,11 @@
|
||||
<!-- Additional properties for all source projects-->
|
||||
<PropertyGroup>
|
||||
|
||||
<!-- Disable packing symbols for source generators -->
|
||||
<PackSymbols Condition="$(IsSourceGeneratorProject)">false</PackSymbols>
|
||||
<!-- Disable packing symbols for all analyzers -->
|
||||
<PackSymbols Condition="$(IsAnalyzersProject)">false</PackSymbols>
|
||||
|
||||
<!-- Enable extended analyzer rules for all source generators -->
|
||||
<EnforceExtendedAnalyzerRules Condition="$(IsSourceGeneratorProject)">true</EnforceExtendedAnalyzerRules>
|
||||
<!-- Enable extended analyzer rules for all analyzers -->
|
||||
<EnforceExtendedAnalyzerRules Condition="$(IsAnalyzersProject)">true</EnforceExtendedAnalyzerRules>
|
||||
|
||||
<!-- Check whether the project has a .targets file to bundle -->
|
||||
<IsTargetsFileAvailableForPacking>false</IsTargetsFileAvailableForPacking>
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
<!--
|
||||
Reference PolySharp for all .NET Standard 2.0 polyfills.
|
||||
Only needed for the .Core project and all source generators.
|
||||
Only needed for the .Core project and all analyzers.
|
||||
-->
|
||||
<ItemGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp.Core' OR $(MSBuildProjectName.EndsWith('.SourceGenerators'))">
|
||||
<PackageReference Include="PolySharp" Version="1.13.2">
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
<Project>
|
||||
<Import Project="..\build\Directory.Build.targets" />
|
||||
|
||||
<!-- Check whether there is a source generator that should be packed with the project -->
|
||||
<!-- Check whether any analyzers are available for packing -->
|
||||
<PropertyGroup Condition="$(IsPackagedProject)">
|
||||
|
||||
<!-- Source generator project, if available -->
|
||||
<IsSourceGeneratorAvailableForPacking>false</IsSourceGeneratorAvailableForPacking>
|
||||
<IsSourceGeneratorAvailableForPacking Condition="Exists('..\$(MSBuildProjectName).SourceGenerators')">true</IsSourceGeneratorAvailableForPacking>
|
||||
<SourceGeneratorReferenceTargetFramework Condition="$(IsSourceGeneratorAvailableForPacking)">$(TargetFrameworks.Split(';')[0].Trim())</SourceGeneratorReferenceTargetFramework>
|
||||
|
||||
<!-- Code fixers project, if available -->
|
||||
<IsCodeFixersAvailableForPacking>false</IsCodeFixersAvailableForPacking>
|
||||
<IsCodeFixersAvailableForPacking Condition="Exists('..\$(MSBuildProjectName).CodeFixers')">true</IsCodeFixersAvailableForPacking>
|
||||
<CodeFixersReferenceTargetFramework Condition="$(IsCodeFixersAvailableForPacking)">$(TargetFrameworks.Split(';')[0].Trim())</CodeFixersReferenceTargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Pack the source generator, if present -->
|
||||
@@ -24,6 +31,21 @@
|
||||
Visible="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Pack the code fixers, if present -->
|
||||
<ItemGroup Condition="'$(IsCodeFixersAvailableForPacking)' == 'true'" Label="Package">
|
||||
|
||||
<!-- Code fixers reference (to trigger building the project) -->
|
||||
<ProjectReference Condition="'$(TargetFramework)' == '$(CodeFixersReferenceTargetFramework)'"
|
||||
Include="..\$(MSBuildProjectName).CodeFixers\$(MSBuildProjectName).CodeFixers.csproj"
|
||||
ReferenceOutputAssembly="false" />
|
||||
|
||||
<!-- Pack the code fixers project from its output directory -->
|
||||
<None Include="..\$(MSBuildProjectName).CodeFixers\bin\$(Configuration)\$(CodeFixersReferenceTargetFramework)\$(MSBuildProjectName).CodeFixers.dll"
|
||||
PackagePath="analyzers\dotnet\cs"
|
||||
Pack="true"
|
||||
Visible="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
Enable trimming support on .NET 6 (we need to use StartsWith since it
|
||||
could be a Windows TFM too). This can't be in a target unlike the other
|
||||
|
||||
@@ -49,6 +49,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputSimple(0)]
|
||||
[D2DInputSimple(1)]
|
||||
[D2DInputSimple(2)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithNoCompileAttributes : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -94,6 +95,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputSimple(1)]
|
||||
[D2DInputSimple(2)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithOverriddenProfile : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -139,6 +141,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputSimple(1)]
|
||||
[D2DInputSimple(2)]
|
||||
[D2DCompileOptions(D2D1CompileOptions.Debug | D2D1CompileOptions.AvoidFlowControl | D2D1CompileOptions.PartialPrecision)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithOverriddenOptions : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -175,6 +178,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputSimple(2)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DCompileOptions(D2D1CompileOptions.Debug | D2D1CompileOptions.AvoidFlowControl | D2D1CompileOptions.PartialPrecision)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithOverriddenProfileAndOptions : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.MSTest" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" Aliases="Core" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" Aliases="D2D1" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.CodeFixers\ComputeSharp.D2D1.CodeFixers.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+361
@@ -0,0 +1,361 @@
|
||||
extern alias Core;
|
||||
extern alias D2D1;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis.Testing;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using CSharpCodeFixTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest<
|
||||
ComputeSharp.D2D1.SourceGenerators.MissingPixelShaderDescriptorOnPixelShaderAnalyzer,
|
||||
ComputeSharp.D2D1.CodeFixers.MissingPixelShaderDescriptorOnPixelShaderCodeFixer,
|
||||
Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>;
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests.SourceGenerators;
|
||||
|
||||
[TestClass]
|
||||
public class Test_MissingPixelShaderDescriptorOnPixelShaderCodeFixer
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task FileContainsComputeSharpD2D1UsingDirective()
|
||||
{
|
||||
string original = """
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
""";
|
||||
|
||||
string @fixed = """
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
""";
|
||||
|
||||
CSharpCodeFixTest test = new()
|
||||
{
|
||||
TestCode = original,
|
||||
FixedCode = @fixed,
|
||||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60
|
||||
};
|
||||
|
||||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly);
|
||||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly);
|
||||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
|
||||
|
||||
await test.RunAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FileContainsComputeSharpD2D1UsingDirective_MultipleOccurrences()
|
||||
{
|
||||
string original = """
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
partial struct {|CMPSD2D0065:MyShader1|} : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[TestAttribute]
|
||||
partial struct {|CMPSD2D0065:MyShader2|} : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
string @fixed = """
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct MyShader1 : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[TestAttribute]
|
||||
partial struct MyShader2 : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
CSharpCodeFixTest test = new()
|
||||
{
|
||||
TestCode = original,
|
||||
FixedCode = @fixed,
|
||||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60
|
||||
};
|
||||
|
||||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly);
|
||||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly);
|
||||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
|
||||
|
||||
await test.RunAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FileDoesNotContainComputeSharpD2D1UsingDirective()
|
||||
{
|
||||
string original = """
|
||||
partial struct {|CMPSD2D0065:MyShader|} : ComputeSharp.D2D1.ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
""";
|
||||
|
||||
string @fixed = """
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct MyShader : ComputeSharp.D2D1.ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
""";
|
||||
|
||||
CSharpCodeFixTest test = new()
|
||||
{
|
||||
TestCode = original,
|
||||
FixedCode = @fixed,
|
||||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60
|
||||
};
|
||||
|
||||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly);
|
||||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly);
|
||||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
|
||||
|
||||
await test.RunAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FileDoesNotContainComputeSharpD2D1UsingDirective_MultipleOccurrences()
|
||||
{
|
||||
string original = """
|
||||
using System;
|
||||
|
||||
partial struct {|CMPSD2D0065:MyShader1|} : ComputeSharp.D2D1.ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
[TestAttribute]
|
||||
partial struct {|CMPSD2D0065:MyShader2|} : ComputeSharp.D2D1.ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
string @fixed = """
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct MyShader1 : ComputeSharp.D2D1.ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[TestAttribute]
|
||||
partial struct MyShader2 : ComputeSharp.D2D1.ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
CSharpCodeFixTest test = new()
|
||||
{
|
||||
TestCode = original,
|
||||
FixedCode = @fixed,
|
||||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60
|
||||
};
|
||||
|
||||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly);
|
||||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly);
|
||||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
|
||||
|
||||
await test.RunAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task InsertsAttributeAfterAllOtherD2DAttributes()
|
||||
{
|
||||
string original = """
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
""";
|
||||
|
||||
string @fixed = """
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
""";
|
||||
|
||||
CSharpCodeFixTest test = new()
|
||||
{
|
||||
TestCode = original,
|
||||
FixedCode = @fixed,
|
||||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60
|
||||
};
|
||||
|
||||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly);
|
||||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly);
|
||||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
|
||||
|
||||
await test.RunAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task InsertsAttributeAfterAllOtherD2DAttributes_WithOtherNonD2DAttribute()
|
||||
{
|
||||
string original = """
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[Test]
|
||||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
string @fixed = """
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[Test]
|
||||
partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
CSharpCodeFixTest test = new()
|
||||
{
|
||||
TestCode = original,
|
||||
FixedCode = @fixed,
|
||||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60
|
||||
};
|
||||
|
||||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly);
|
||||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly);
|
||||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
|
||||
|
||||
await test.RunAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task InsertsAttributeAfterAllOtherD2DAttributes_WithFakeAttributes()
|
||||
{
|
||||
string original = """
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DInputCount(2)]
|
||||
[D2DInputSimple(0)]
|
||||
[ComputeSharp.D2D1.D2DInputSimple(1)]
|
||||
[D2DFake]
|
||||
[Test]
|
||||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
public class D2DFakeAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
string @fixed = """
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
[D2DInputCount(2)]
|
||||
[D2DInputSimple(0)]
|
||||
[ComputeSharp.D2D1.D2DInputSimple(1)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[D2DFake]
|
||||
[Test]
|
||||
partial struct {|CMPSD2D0065:MyShader|} : ID2D1PixelShader
|
||||
{
|
||||
public ComputeSharp.Float4 Execute() => 0;
|
||||
}
|
||||
|
||||
public class TestAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
public class D2DFakeAttribute : Attribute
|
||||
{
|
||||
}
|
||||
""";
|
||||
|
||||
CSharpCodeFixTest test = new()
|
||||
{
|
||||
TestCode = original,
|
||||
FixedCode = @fixed,
|
||||
ReferenceAssemblies = ReferenceAssemblies.Net.Net60
|
||||
};
|
||||
|
||||
test.TestState.AdditionalReferences.Add(typeof(Core::ComputeSharp.Float4).Assembly);
|
||||
test.TestState.AdditionalReferences.Add(typeof(D2D1::ComputeSharp.D2D1.ID2D1PixelShader).Assembly);
|
||||
test.TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
|
||||
|
||||
await test.RunAsync();
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.CodeFixers\ComputeSharp.D2D1.CodeFixers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public partial class D2D1EffectRegistrationDataTests
|
||||
|
||||
[D2DInputCount(2)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private readonly partial struct TestRegistrationBlobShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -96,6 +97,7 @@ public partial class D2D1EffectRegistrationDataTests
|
||||
[D2DEffectDescription("A test effect with some custom metadata")]
|
||||
[D2DEffectCategory("Test effects")]
|
||||
[D2DEffectAuthor("Bob Ross")]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private readonly partial struct TestRegistrationBlobWithCustomMetadataShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -192,6 +194,7 @@ public partial class D2D1EffectRegistrationDataTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private readonly partial struct TestRegistrationBlobWithResourceTextures : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -120,6 +120,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct NullConstantBufferShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -151,6 +152,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct ConstantBufferSizeTestShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -185,6 +187,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWithDefaultEffectId : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -194,6 +197,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWithDefaultEffectId2 : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -217,6 +221,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DEffectId("8E1F7F49-EF0D-4242-8912-08ADA36AB4EC")]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWithExplicitEffectId : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -235,6 +240,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWithDefaultEffectDisplayName : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -254,6 +260,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DEffectDisplayName("Fancy blur")]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWithExplicitEffectDisplayName1 : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -276,6 +283,7 @@ public partial class D2D1PixelShaderEffectTests
|
||||
[D2DEffectDescription("A test effect with \nsome custom metadata")]
|
||||
[D2DEffectCategory("Test effects!")]
|
||||
[D2DEffectAuthor("Bob \r\nRoss")]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWithExplicitEffectDisplayName2 : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
|
||||
@@ -66,6 +66,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputComplex(3)]
|
||||
[D2DInputComplex(5)]
|
||||
[D2DInputSimple(6)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct ShaderWithMultipleInputs : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute()
|
||||
@@ -93,6 +94,7 @@ public partial class D2D1PixelShaderTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct EmptyShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute()
|
||||
@@ -103,6 +105,7 @@ public partial class D2D1PixelShaderTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DOutputBuffer(D2D1BufferPrecision.UInt16Normalized)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct OnlyBufferPrecisionShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute()
|
||||
@@ -113,6 +116,7 @@ public partial class D2D1PixelShaderTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DOutputBuffer(D2D1ChannelDepth.Four)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct OnlyChannelDepthShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute()
|
||||
@@ -123,6 +127,7 @@ public partial class D2D1PixelShaderTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DOutputBuffer(D2D1BufferPrecision.UInt8NormalizedSrgb, D2D1ChannelDepth.One)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct CustomBufferOutputShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute()
|
||||
@@ -189,6 +194,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputDescription(2, D2D1Filter.MinLinearMagPointMinLinear, LevelOfDetailCount = 4)]
|
||||
[D2DInputDescription(5, D2D1Filter.MinMagPointMipLinear)]
|
||||
[D2DInputDescription(6, D2D1Filter.MinPointMagMipLinear, LevelOfDetailCount = 3)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
partial struct ShaderWithInputDescriptions : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute()
|
||||
@@ -249,6 +255,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputComplex(1)]
|
||||
[D2DInputComplex(3)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
partial struct ShaderWithoutResourceTextures : ID2D1PixelShader
|
||||
{
|
||||
@@ -260,6 +267,7 @@ public partial class D2D1PixelShaderTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
partial struct ShaderWithJustOneResourceTextures : ID2D1PixelShader
|
||||
{
|
||||
@@ -278,6 +286,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputComplex(1)]
|
||||
[D2DInputComplex(3)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
partial struct ShaderWithResourceTextures : ID2D1PixelShader
|
||||
{
|
||||
@@ -322,6 +331,7 @@ public partial class D2D1PixelShaderTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithoutEmbeddedBytecode : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -393,6 +403,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputSimple(1)]
|
||||
[D2DInputSimple(2)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader40Level91)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithEmbeddedBytecode : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -442,6 +453,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputSimple(2)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader40Level91)]
|
||||
[D2DCompileOptions(D2D1CompileOptions.IeeeStrictness | D2D1CompileOptions.OptimizationLevel2)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithEmbeddedBytecodeAndCompileOptions : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -473,6 +485,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader40Level91)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct SimpleShaderWithExplicitShaderProfileAndNoCompileOptions : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -484,6 +497,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputComplex(0)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader40Level91)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ComplexShaderWithExplicitShaderProfileAndNoCompileOptions : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -509,6 +523,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DCompileOptions(D2D1CompileOptions.OptimizationLevel2 | D2D1CompileOptions.IeeeStrictness)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithExplicitCompileOptionsAndNoShaderProfile : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -557,6 +572,7 @@ public partial class D2D1PixelShaderTests
|
||||
[D2DInputSimple(0)]
|
||||
[D2DInputDescription(0, D2D1Filter.MinMagMipPoint)]
|
||||
[D2DPixelOptions(D2D1PixelOptions.TrivialSampling)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ShaderWithNoCapturedValues : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -804,6 +820,7 @@ public partial class D2D1PixelShaderTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ShaderWithScalarVectorAndMatrixTypes : ID2D1PixelShader
|
||||
{
|
||||
@@ -896,6 +913,7 @@ public partial class D2D1PixelShaderTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ShaderWithScalarVectorAndMatrixTypesInNestedStructs : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -60,6 +60,7 @@ public partial class D2D1ReflectionServicesTests
|
||||
[D2DInputComplex(2)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader41)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ReflectedShader : ID2D1PixelShader
|
||||
{
|
||||
private readonly float2 offset;
|
||||
@@ -119,6 +120,7 @@ public partial class D2D1ReflectionServicesTests
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private readonly partial struct ReflectedShaderWithDoubleOperations : ID2D1PixelShader
|
||||
{
|
||||
private readonly double amount;
|
||||
|
||||
@@ -171,6 +171,7 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct DummyShaderWithResourceTexture : ID2D1PixelShader
|
||||
{
|
||||
[D2DResourceTextureIndex(0)]
|
||||
@@ -459,6 +460,7 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct IndexFrom2DResourceTextureShader : ID2D1PixelShader
|
||||
{
|
||||
[D2DResourceTextureIndex(0)]
|
||||
@@ -533,6 +535,7 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct IndexFrom3DResourceTextureShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -620,6 +623,7 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct CopyFromResourceTexture1DShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -717,6 +721,7 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct CopyFromResourceTexture2DShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -823,6 +828,7 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct CopyFromResourceTexture3DShader : ID2D1PixelShader
|
||||
{
|
||||
@@ -868,6 +874,7 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct NullResourceTextureShader : ID2D1PixelShader
|
||||
{
|
||||
[D2DResourceTextureIndex(0)]
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ namespace ComputeSharp.D2D1.Tests;
|
||||
internal sealed partial class D2D1ResourceTextureUninitializedFieldDiagnosticSuppressorTests
|
||||
{
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public readonly partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
// This test just needs to validate the project builds fine with this shader.
|
||||
|
||||
@@ -198,6 +198,7 @@ public partial class D2D1TransformMapperTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct DummyShader : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -287,6 +288,7 @@ public partial class D2D1TransformMapperTests
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct ShaderWithDispatchArea : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -509,6 +509,7 @@ public sealed partial class BokehBlurEffect
|
||||
[D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
public readonly partial struct Shader : ID2D1PixelShader
|
||||
{
|
||||
@@ -558,6 +559,7 @@ public sealed partial class BokehBlurEffect
|
||||
[D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
public readonly partial struct Shader : ID2D1PixelShader
|
||||
{
|
||||
@@ -602,6 +604,7 @@ public sealed partial class BokehBlurEffect
|
||||
[D2DInputDescription(0, D2D1Filter.MinMagMipPoint)]
|
||||
[D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct GammaHighlight : ID2D1PixelShader
|
||||
{
|
||||
@@ -624,6 +627,7 @@ public sealed partial class BokehBlurEffect
|
||||
[D2DInputDescription(0, D2D1Filter.MinMagMipPoint)]
|
||||
[D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct InverseGammaHighlight : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace ComputeSharp.D2D1.Tests.Effects;
|
||||
[D2DInputSimple(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
public partial struct CheckerboardClipEffect : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace ComputeSharp.D2D1.Tests.Effects;
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public partial struct InvertEffect : ID2D1PixelShader
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace ComputeSharp.D2D1.Tests.Effects;
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
public partial struct InvertWithThresholdEffect : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace ComputeSharp.D2D1.Tests.Effects;
|
||||
[D2DInputComplex(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader40)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
public readonly partial struct PixelateEffect : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ internal static class MathF
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
public readonly partial struct ZonePlateEffect : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -698,6 +698,7 @@ public partial class CanvasEffectTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct ShaderWithNoInputs : ID2D1PixelShader
|
||||
{
|
||||
|
||||
@@ -459,6 +459,7 @@ public partial class PixelShaderEffectTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct ShaderWithSomeProperties : ID2D1PixelShader
|
||||
{
|
||||
@@ -475,6 +476,7 @@ public partial class PixelShaderEffectTests
|
||||
}
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
[AutoConstructor]
|
||||
private partial struct ShaderWithSomePropertiesAndInputs : ID2D1PixelShader
|
||||
{
|
||||
@@ -487,6 +489,7 @@ public partial class PixelShaderEffectTests
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWith0Inputs : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -497,6 +500,7 @@ public partial class PixelShaderEffectTests
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWith1Input : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
@@ -508,6 +512,7 @@ public partial class PixelShaderEffectTests
|
||||
[D2DInputCount(2)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DInputSimple(1)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
private partial struct ShaderWith2Inputs : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする