Finished support for mapping type names from SG
このコミットが含まれているのは:
1 親
d0bfcefc79
コミット
0723c04b59
5ファイル変更
+46
-113
検索条件に一致するファイルはありません
@@ -102,16 +102,18 @@ namespace ComputeSharp.SourceGenerators
|
||||
{
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type;
|
||||
string typeName = HlslKnownTypes.GetMappedName(typeSymbol);
|
||||
|
||||
_ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping);
|
||||
|
||||
// Yield back the current mapping for the name (if the name used a reserved keyword)
|
||||
yield return new[] { fieldSymbol.Name, mapping ?? fieldSymbol.Name };
|
||||
yield return new[] { fieldSymbol.Name, mapping ?? fieldSymbol.Name, typeName };
|
||||
|
||||
// Track the type of items in the current buffer
|
||||
if (fieldSymbol.Type is INamedTypeSymbol fieldType &&
|
||||
HlslKnownTypes.IsStructuredBufferType(fieldType.GetFullMetadataName()))
|
||||
if (HlslKnownTypes.IsStructuredBufferType(typeSymbol.GetFullMetadataName()))
|
||||
{
|
||||
types.Add((INamedTypeSymbol)fieldType.TypeArguments[0]);
|
||||
types.Add((INamedTypeSymbol)typeSymbol.TypeArguments[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
[typeof(Double2).FullName] = "double2",
|
||||
[typeof(Double3).FullName] = "double3",
|
||||
[typeof(Double4).FullName] = "double4",
|
||||
[typeof(ThreadIds).FullName] = "uint3",
|
||||
[typeof(ThreadIds).FullName] = "uint3"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -68,6 +68,38 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
typeName == "ComputeSharp.ReadWriteBuffer`1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input type symbol.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input type to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
public static string GetMappedName(INamedTypeSymbol typeSymbol)
|
||||
{
|
||||
string typeName = typeSymbol.GetFullMetadataName();
|
||||
|
||||
// Special case for the structured buffer types
|
||||
if (IsStructuredBufferType(typeName))
|
||||
{
|
||||
string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments[0]).GetFullMetadataName();
|
||||
|
||||
// If the current type is a custom type, format it as needed
|
||||
if (!KnownTypes.TryGetValue(genericArgumentName, out string? mapped))
|
||||
{
|
||||
mapped = genericArgumentName.Replace(".", "__");
|
||||
}
|
||||
|
||||
// Construct the HLSL type name
|
||||
return typeName switch
|
||||
{
|
||||
"ComputeSharp.ReadOnlyBuffer`1" => $"StructuredBuffer<{mapped}>",
|
||||
"ComputeSharp.ReadWriteBuffer`1" => $"RWStructuredBuffer<{mapped}>",
|
||||
_ => throw new ArgumentException()
|
||||
};
|
||||
}
|
||||
|
||||
return KnownTypes[typeName];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input type name.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする