Implemented name replacement for reserved keywords
このコミットが含まれているのは:
1 親
cc6fa095b1
コミット
ce8a2e49af
2ファイル変更
+11
-3
検索条件に一致するファイルはありません
@@ -21,7 +21,7 @@ namespace ComputeSharp.Shaders.Mappings
|
||||
"pixelfragment", "point", "precise", "register", "row_major", "sample",
|
||||
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
|
||||
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
|
||||
"unsigned", "vector", "vertexfragment"
|
||||
"unsigned", "vector", "vertexfragment", "zero"
|
||||
};
|
||||
|
||||
private static Regex _KeywordsRegex;
|
||||
@@ -52,5 +52,13 @@ namespace ComputeSharp.Shaders.Mappings
|
||||
/// <returns>The HLSL-compatible variable name name that can be used in an HLSL shader</returns>
|
||||
[Pure]
|
||||
public static string GetMappedName(string name) => KeywordsRegex.IsMatch(name) ? $"_{name}" : name;
|
||||
|
||||
/// <summary>
|
||||
/// Processes an input text and replaces all the occurrences of reserved keywords
|
||||
/// </summary>
|
||||
/// <param name="text">The input text to process</param>
|
||||
/// <returns>A valid shader body source code that can be used in HLSL</returns>
|
||||
[Pure]
|
||||
public static string GetMappedText(string text) => KeywordsRegex.Replace(text, m => $"_{m.Value}");
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
private void LoadFieldInfo(ReadableMember memberInfo, string? name = null)
|
||||
{
|
||||
Type fieldType = memberInfo.MemberType;
|
||||
string fieldName = name ?? memberInfo.Name;
|
||||
string fieldName = HlslKnownKeywords.GetMappedName(name ?? memberInfo.Name);
|
||||
|
||||
// Constant buffer
|
||||
if (HlslKnownTypes.IsConstantBufferType(fieldType))
|
||||
@@ -226,7 +226,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
// Additional preprocessing
|
||||
MethodBody = Regex.Replace(MethodBody, @"(?<=\W)(\d+)[fFdD]", m => m.Groups[1].Value);
|
||||
MethodBody = MethodBody.TrimEnd('\n', '\r', ' ');
|
||||
MethodBody = Regex.Replace(MethodBody, @"(?<!A-Za-z)vector(?!\w)", "_vector"); // The decompiler can name a local Vector[2,3,4] variable as "vector"
|
||||
MethodBody = HlslKnownKeywords.GetMappedText(MethodBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする