Improved type display in comments in the HLSL shader
このコミットが含まれているのは:
1 親
b6eca71e2d
コミット
035ce5f627
2ファイル変更
+53
-2
検索条件に一致するファイルはありません
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
|
||||
namespace ComputeSharp.Shaders.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that provides extension methods for the <see cref="Type"/> type
|
||||
/// </summary>
|
||||
internal static class TypeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of supported known types to display string
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<Type, string> KnownTypes = new Dictionary<Type, string>
|
||||
{
|
||||
[typeof(bool)] = "bool",
|
||||
[typeof(int)] = "int",
|
||||
[typeof(uint)] = "uint",
|
||||
[typeof(float)] = "float",
|
||||
[typeof(double)] = "double"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a friendly display <see langword="string"/> for the input type
|
||||
/// </summary>
|
||||
/// <param name="type">The input type to analyze</param>
|
||||
[Pure]
|
||||
public static string ToFriendlyString(this Type type)
|
||||
{
|
||||
// Array types of arbitrary rank
|
||||
if (type.IsArray)
|
||||
{
|
||||
int rank = type.GetArrayRank();
|
||||
return $"{type.GetElementType().ToFriendlyString()}[{new string(Enumerable.Repeat(',', rank - 1).ToArray())}]";
|
||||
}
|
||||
|
||||
// Non generic types
|
||||
string name;
|
||||
if (type.GetGenericArguments().Length == 0) return KnownTypes.TryGetValue(type, out name) ? name : type.Name;
|
||||
|
||||
// Generic types
|
||||
Type[] genericArguments = type.GetGenericArguments();
|
||||
string typeDefeninition = KnownTypes.TryGetValue(type, out name) ? name : type.Name;
|
||||
string polishedName = typeDefeninition.Substring(0, typeDefeninition.IndexOf("`"));
|
||||
return $"{polishedName}<{string.Join(",", genericArguments.Select(ToFriendlyString))}>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ComputeSharp.Shaders.Extensions;
|
||||
|
||||
namespace ComputeSharp.Shaders.Renderer.Models.Fields
|
||||
{
|
||||
@@ -10,7 +11,7 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
|
||||
/// <summary>
|
||||
/// Gets the type of the current field in the C# source
|
||||
/// </summary>
|
||||
public Type FieldCsharpType { get; }
|
||||
public string FieldCsharpType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the current field in the HLSL shader
|
||||
@@ -30,7 +31,7 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
|
||||
/// <param name="fieldName">The name to use for the current field</param>
|
||||
public CapturedFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName)
|
||||
{
|
||||
FieldCsharpType = fieldCsharpType;
|
||||
FieldCsharpType = fieldCsharpType.ToFriendlyString();
|
||||
FieldHlslType = fieldHlslType;
|
||||
FieldName = fieldName;
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする