using Microsoft.CodeAnalysis; namespace ComputeSharp.SourceGenerators; /// partial class ComputeShaderDescriptorGenerator { /// /// Gets whether a given type is a compute shader type (ie. implements any of the interfaces). /// /// The input instance to check. /// The instance currently in use. /// Whether is a "pixel shader like" type. /// Whether is a compute shader type at all. private static bool TryGetIsPixelShaderLike(INamedTypeSymbol typeSymbol, Compilation compilation, out bool result) { INamedTypeSymbol computeShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader")!; INamedTypeSymbol pixelShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader`1")!; foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces) { if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol)) { result = false; return true; } else if (SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol)) { result = true; return true; } } result = false; return false; } }