Bug fixes, enable multiple resource texture diagnostics

このコミットが含まれているのは:
Sergio Pedri committed 2023-12-31 00:33:51 +01:00
1 親 0f21e629ed
コミット 5a638be970
3ファイル変更
+73 -21

検索条件に一致するファイルはありません

@@ -60,17 +60,23 @@ public sealed class InvalidD2DResourceTextureIndexAttributeUseAnalyzer : Diagnos
foreach (ISymbol memberSymbol in typeSymbol.GetMembers())
{
// Only look for valid candidate fields (same logic as in D2DPixelShaderDescriptorGenerator.InputTypes)
if (memberSymbol is not IFieldSymbol { IsStatic: false, Type: INamedTypeSymbol { IsUnmanagedType: true, IsGenericType: true } } fieldSymbol)
if (memberSymbol is not IFieldSymbol { IsStatic: false, Type: INamedTypeSymbol { IsUnmanagedType: true } } fieldSymbol)
{
continue;
}
// Specifically check that the type is generic and grab the source one
if (fieldSymbol.Type is not INamedTypeSymbol { ConstructedFrom: { } nonGenericFieldTypeSymbol })
{
continue;
}
// Check that the field is a D2D resource texture and get the rank
int rank = fieldSymbol.Type switch
int rank = nonGenericFieldTypeSymbol switch
{
_ when SymbolEqualityComparer.Default.Equals(d2D1ResourceTexture1DSymbol, fieldSymbol.Type) => 1,
_ when SymbolEqualityComparer.Default.Equals(d2D1ResourceTexture2DSymbol, fieldSymbol.Type) => 2,
_ when SymbolEqualityComparer.Default.Equals(d2D1ResourceTexture3DSymbol, fieldSymbol.Type) => 3,
_ when SymbolEqualityComparer.Default.Equals(d2D1ResourceTexture1DSymbol, nonGenericFieldTypeSymbol) => 1,
_ when SymbolEqualityComparer.Default.Equals(d2D1ResourceTexture2DSymbol, nonGenericFieldTypeSymbol) => 2,
_ when SymbolEqualityComparer.Default.Equals(d2D1ResourceTexture3DSymbol, nonGenericFieldTypeSymbol) => 3,
_ => 0
};
@@ -132,7 +138,7 @@ public sealed class InvalidD2DResourceTextureIndexAttributeUseAnalyzer : Diagnos
typeSymbol.Locations.First(),
typeSymbol));
return;
break;
}
}
@@ -146,7 +152,7 @@ public sealed class InvalidD2DResourceTextureIndexAttributeUseAnalyzer : Diagnos
typeSymbol.Locations.First(),
typeSymbol));
return;
break;
}
}
@@ -154,9 +160,17 @@ public sealed class InvalidD2DResourceTextureIndexAttributeUseAnalyzer : Diagnos
selectedResourceTextureIndices.Clear();
// All input description indices must be unique (also take this path for invalid indices)
// All input description indices must be unique
foreach ((int? index, _) in resourceTextureInfos.WrittenSpan)
{
// Skip this path for invalid indices, as those will receive other diagnostics.
// We have to do this to avoid generating false positives for the default value.
// Because indices could be out of range, we also have to skip any of those.
if (index is null or >= 16)
{
continue;
}
ref bool isResourceTextureIndexUsed = ref selectedResourceTextureIndices[index ?? 0];
if (isResourceTextureIndexUsed)
@@ -166,7 +180,7 @@ public sealed class InvalidD2DResourceTextureIndexAttributeUseAnalyzer : Diagnos
typeSymbol.Locations.First(),
typeSymbol));
return;
break;
}
isResourceTextureIndexUsed = true;
+2 -2
ファイルの表示
@@ -654,9 +654,9 @@ partial class DiagnosticDescriptors
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a shader with an out of range resource texture index (or more).
/// Gets a <see cref="DiagnosticDescriptor"/> for a shader with an overlapping resource texture index (or more).
/// <para>
/// Format: <c>"The D2D1 shader of type {0} is using some out of range resource texture indices"</c>.
/// Format: <c>"The D2D1 shader of type {0} is using some resource texture indices that overlap with the shader input indices"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor ResourceTextureIndexOverlappingWithInputIndex = new(
+48 -10
ファイルの表示
@@ -457,10 +457,10 @@ public class Test_Analyzers
using ComputeSharp.D2D1;
[D2DInputCount(2)]
internal partial struct MyType : ID2D1PixelShader
internal partial struct {|CMPSD2D0046:MyType|} : ID2D1PixelShader
{
[D2DResourceTextureIndex(1)]
public D2D1ResourceTexture1D<float> {|CMPSD2D0046:texture|};
public D2D1ResourceTexture1D<float> texture;
public Float4 Execute()
{
@@ -480,10 +480,10 @@ public class Test_Analyzers
using ComputeSharp.D2D1;
[D2DInputCount(2)]
internal partial struct MyType : ID2D1PixelShader
internal partial struct {|CMPSD2D0046:MyType|} : ID2D1PixelShader
{
[D2DResourceTextureIndex(0)]
public D2D1ResourceTexture1D<float> {|CMPSD2D0046:texture1D|};
public D2D1ResourceTexture1D<float> texture1D;
[D2DResourceTextureIndex(1)]
public D2D1ResourceTexture2D<float> texture2D;
@@ -506,10 +506,10 @@ public class Test_Analyzers
using ComputeSharp.D2D1;
[D2DInputCount(0)]
internal partial struct MyType : ID2D1PixelShader
internal partial struct {|CMPSD2D0047:MyType|} : ID2D1PixelShader
{
[D2DResourceTextureIndex(16)]
public D2D1ResourceTexture1D<float> {|CMPSD2D0047:texture|};
public D2D1ResourceTexture1D<float> texture;
public Float4 Execute()
{
@@ -529,10 +529,10 @@ public class Test_Analyzers
using ComputeSharp.D2D1;
[D2DInputCount(0)]
internal partial struct MyType : ID2D1PixelShader
internal partial struct {|CMPSD2D0047:MyType|} : ID2D1PixelShader
{
[D2DResourceTextureIndex(16)]
public D2D1ResourceTexture1D<float> {|CMPSD2D0047:texture1D|};
public D2D1ResourceTexture1D<float> texture1D;
[D2DResourceTextureIndex(17)]
public D2D1ResourceTexture2D<float> texture2D;
@@ -555,10 +555,10 @@ public class Test_Analyzers
using ComputeSharp.D2D1;
[D2DInputCount(0)]
internal partial struct MyType : ID2D1PixelShader
internal partial struct {|CMPSD2D0048:MyType|} : ID2D1PixelShader
{
[D2DResourceTextureIndex(0)]
public D2D1ResourceTexture1D<float> {|CMPSD2D0048:texture1|};
public D2D1ResourceTexture1D<float> texture1;
[D2DResourceTextureIndex(0)]
public D2D1ResourceTexture1D<float> texture2;
@@ -572,4 +572,42 @@ public class Test_Analyzers
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2DResourceTextureIndexAttributeUseAnalyzer>.VerifyAnalyzerAsync(source);
}
[TestMethod]
public async Task InvalidD2DResourceTextureIndices_MultipleErrors_WarnsOncePerDiagnosticId()
{
const string source = """
using ComputeSharp;
using ComputeSharp.D2D1;
[D2DInputCount(3)]
internal partial struct {|CMPSD2D0046:{|CMPSD2D0047:{|CMPSD2D0048:MyType|}|}|} : ID2D1PixelShader
{
[D2DResourceTextureIndex(0)]
public D2D1ResourceTexture1D<float> texture1;
[D2DResourceTextureIndex(1)]
public D2D1ResourceTexture1D<float> texture2;
[D2DResourceTextureIndex(16)]
public D2D1ResourceTexture1D<float> texture3;
[D2DResourceTextureIndex(17)]
public D2D1ResourceTexture2D<float> texture4;
[D2DResourceTextureIndex(2)]
public D2D1ResourceTexture1D<float> texture5;
[D2DResourceTextureIndex(2)]
public D2D1ResourceTexture1D<float> texture6;
public Float4 Execute()
{
return 0;
}
}
""";
await CSharpAnalyzerWithLanguageVersionTest<InvalidD2DResourceTextureIndexAttributeUseAnalyzer>.VerifyAnalyzerAsync(source);
}
}