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 isPixelShaderLike) { 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)) { isPixelShaderLike = false; return true; } else if (SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol)) { isPixelShaderLike = true; return true; } } isPixelShaderLike = false; return false; } }