Fix MissingComputeShaderDescriptorOnComputeShaderAnalyzer

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-16 11:15:48 +02:00
1 親 0f0ecab6fc
コミット ba20d0db76
2ファイル変更
+29 -13

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

@@ -45,21 +45,14 @@ public sealed class InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyz
return;
}
// If the type implements IComputeShader or IComputeShader<TPixel>, it is valid
foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces)
// If the type doesn't implement IComputeShader nor IComputeShader<TPixel>, we can emit a diagnostic
if (!MissingComputeShaderDescriptorOnComputeShaderAnalyzer.IsComputeShaderType(typeSymbol, computeShaderSymbol, pixelShaderSymbol))
{
if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol) ||
SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol))
{
return;
}
}
// If we got here, the type is not valid, so we can emit a diagnostic
context.ReportDiagnostic(Diagnostic.Create(
context.ReportDiagnostic(Diagnostic.Create(
InvalidGeneratedPixelShaderDescriptorAttributeTarget,
attribute.GetLocation(),
typeSymbol));
}
}, SymbolKind.NamedType);
});
}
@@ -42,8 +42,7 @@ public sealed class MissingComputeShaderDescriptorOnComputeShaderAnalyzer : Diag
}
// If the type is not a compute shader type, immediately bail out
if (!typeSymbol.HasInterfaceWithType(computeShaderSymbol) &&
!typeSymbol.HasInterfaceWithType(pixelShaderSymbol))
if (!IsComputeShaderType(typeSymbol, computeShaderSymbol, pixelShaderSymbol))
{
return;
}
@@ -60,4 +59,28 @@ public sealed class MissingComputeShaderDescriptorOnComputeShaderAnalyzer : Diag
}, SymbolKind.NamedType);
});
}
/// <summary>
/// Checks whether a given type is a compute shader type.
/// </summary>
/// <param name="typeSymbol">The type to check.</param>
/// <param name="computeShaderSymbol">The type symbol for <c>IComputeShader</c>.</param>
/// <param name="pixelShaderSymbol">The type symbol for <c>IComputeShader&lt;TPixel&gt;</c>.</param>
/// <returns></returns>
internal static bool IsComputeShaderType(
INamedTypeSymbol typeSymbol,
INamedTypeSymbol computeShaderSymbol,
INamedTypeSymbol pixelShaderSymbol)
{
foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces)
{
if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol) ||
SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol))
{
return true;
}
}
return false;
}
}