Move HlslKnownKeywords to shared generation project
このコミットが含まれているのは:
1 親
d6dd5cf7af
コミット
33235d68c8
8ファイル変更
+88
-113
検索条件に一致するファイルはありません
+1
@@ -9,6 +9,7 @@ using ComputeSharp.D2D1Interop.SourceGenerators.Mappings;
|
||||
using ComputeSharp.D2D1Interop.SourceGenerators.SyntaxRewriters;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
@@ -1,46 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.Core.Intrinsics.Attributes;
|
||||
using ComputeSharp.D2D1Interop;
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.SourceGenerators.Mappings;
|
||||
namespace ComputeSharp.SourceGeneration.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL identifier names valid HLSL names.
|
||||
/// </summary>
|
||||
internal static class HlslKnownKeywords
|
||||
/// <inheritdoc/>
|
||||
partial class HlslKnownKeywords
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of known HLSL keywords.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownKeywords = BuildKnownKeywordsMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of all known HLSL keywords.
|
||||
/// </summary>
|
||||
private static IReadOnlyCollection<string> BuildKnownKeywordsMap()
|
||||
/// <inheritdoc/>
|
||||
static partial void AddKnownKeyword(ICollection<string> knownKeywords)
|
||||
{
|
||||
// HLSL keywords
|
||||
HashSet<string> knownKeywords = new(new[]
|
||||
{
|
||||
"asm", "asm_fragment", "cbuffer", "centroid", "column_major",
|
||||
"compile", "discard", "dword", "export", "fxgroup", "groupshared",
|
||||
"half", "inline", "inout", "line", "lineadj", "linear", "matrix",
|
||||
"nointerpolation", "noperspective", "NULL", "packoffset", "pass",
|
||||
"pixelfragment", "point", "precise", "register", "row_major", "sample",
|
||||
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
|
||||
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
|
||||
"unsigned", "vector", "vertexfragment", "zero"
|
||||
});
|
||||
|
||||
// HLSL intrinsics method names
|
||||
foreach (var method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
string name = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
|
||||
|
||||
knownKeywords.Add(name);
|
||||
}
|
||||
|
||||
// D2D1 intrinsics method names
|
||||
foreach (var method in typeof(D2D1).GetMethods(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
@@ -48,24 +18,5 @@ internal static class HlslKnownKeywords
|
||||
|
||||
knownKeywords.Add(name);
|
||||
}
|
||||
|
||||
return knownKeywords;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible identifier name for the input identifier name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input identifier name.</param>
|
||||
/// <param name="mapped">The mapped identifier name, if a replacement is needed.</param>
|
||||
/// <returns>The HLSL-compatible identifier name that can be used in an HLSL shader.</returns>
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
mapped = KnownKeywords.Contains(name) switch
|
||||
{
|
||||
true => $"__reserved__{name}",
|
||||
false => null
|
||||
};
|
||||
|
||||
return mapped is not null;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using ComputeSharp.D2D1Interop.SourceGenerators.Extensions;
|
||||
using ComputeSharp.D2D1Interop.SourceGenerators.Mappings;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\Comparer{T,TSelf}.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\HashCode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\SemanticModelProvider.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Mappings\HlslKnownKeywords.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Models\DiagnosticInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Models\HierarchyInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Models\Result{T}.cs" />
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.Core.Intrinsics.Attributes;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL identifier names valid HLSL names.
|
||||
/// </summary>
|
||||
internal static partial class HlslKnownKeywords
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of known HLSL keywords.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownKeywords = BuildKnownKeywordsMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of all known HLSL keywords.
|
||||
/// </summary>
|
||||
private static IReadOnlyCollection<string> BuildKnownKeywordsMap()
|
||||
{
|
||||
// HLSL keywords
|
||||
HashSet<string> knownKeywords = new(new[]
|
||||
{
|
||||
"asm", "asm_fragment", "cbuffer", "centroid", "column_major",
|
||||
"compile", "discard", "dword", "export", "fxgroup", "groupshared",
|
||||
"half", "inline", "inout", "line", "lineadj", "linear", "matrix",
|
||||
"nointerpolation", "noperspective", "NULL", "packoffset", "pass",
|
||||
"pixelfragment", "point", "precise", "register", "row_major", "sample",
|
||||
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
|
||||
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
|
||||
"unsigned", "vector", "vertexfragment", "zero"
|
||||
});
|
||||
|
||||
// HLSL intrinsics method names
|
||||
foreach (var method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
string name = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
|
||||
|
||||
knownKeywords.Add(name);
|
||||
}
|
||||
|
||||
// Let other types inject additional keywords
|
||||
AddKnownKeyword(knownKeywords);
|
||||
|
||||
return knownKeywords;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds more known keywords to the collection to use.
|
||||
/// </summary>
|
||||
/// <param name="knownKeywords">The collection of known keywords being built.</param>
|
||||
static partial void AddKnownKeyword(ICollection<string> knownKeywords);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible identifier name for the input identifier name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input identifier name.</param>
|
||||
/// <param name="mapped">The mapped identifier name, if a replacement is needed.</param>
|
||||
/// <returns>The HLSL-compatible identifier name that can be used in an HLSL shader.</returns>
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
mapped = KnownKeywords.Contains(name) switch
|
||||
{
|
||||
true => $"__reserved__{name}",
|
||||
false => null
|
||||
};
|
||||
|
||||
return mapped is not null;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using ComputeSharp.SourceGenerators.Diagnostics;
|
||||
using ComputeSharp.SourceGenerators.Extensions;
|
||||
using ComputeSharp.SourceGenerators.Mappings;
|
||||
|
||||
@@ -1,69 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.Core.Intrinsics.Attributes;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Mappings;
|
||||
namespace ComputeSharp.SourceGeneration.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL identifier names valid HLSL names.
|
||||
/// </summary>
|
||||
internal static class HlslKnownKeywords
|
||||
/// <inheritdoc/>
|
||||
internal static partial class HlslKnownKeywords
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of known HLSL keywords.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownKeywords = BuildKnownKeywordsMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of all known HLSL keywords.
|
||||
/// </summary>
|
||||
private static IReadOnlyCollection<string> BuildKnownKeywordsMap()
|
||||
/// <inheritdoc/>
|
||||
static partial void AddKnownKeyword(ICollection<string> knownKeywords)
|
||||
{
|
||||
// HLSL keywords
|
||||
HashSet<string> knownKeywords = new(new[]
|
||||
{
|
||||
"asm", "asm_fragment", "cbuffer", "centroid", "column_major",
|
||||
"compile", "discard", "dword", "export", "fxgroup", "groupshared",
|
||||
"half", "inline", "inout", "line", "lineadj", "linear", "matrix",
|
||||
"nointerpolation", "noperspective", "NULL", "packoffset", "pass",
|
||||
"pixelfragment", "point", "precise", "register", "row_major", "sample",
|
||||
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
|
||||
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
|
||||
"unsigned", "vector", "vertexfragment", "zero"
|
||||
});
|
||||
|
||||
// Dispatch type names
|
||||
knownKeywords.Add(nameof(ThreadIds));
|
||||
knownKeywords.Add(nameof(GroupIds));
|
||||
knownKeywords.Add(nameof(GroupSize));
|
||||
knownKeywords.Add(nameof(GridIds));
|
||||
|
||||
// HLSL intrinsics method names
|
||||
foreach (var method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
string name = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
|
||||
|
||||
knownKeywords.Add(name);
|
||||
}
|
||||
|
||||
return knownKeywords;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible identifier name for the input identifier name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input identifier name.</param>
|
||||
/// <param name="mapped">The mapped identifier name, if a replacement is needed.</param>
|
||||
/// <returns>The HLSL-compatible identifier name that can be used in an HLSL shader.</returns>
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
mapped = KnownKeywords.Contains(name) switch
|
||||
{
|
||||
true => $"__reserved__{name}",
|
||||
false => null
|
||||
};
|
||||
|
||||
return mapped is not null;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGenerators.Diagnostics;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using ComputeSharp.SourceGenerators.Extensions;
|
||||
using ComputeSharp.SourceGenerators.Mappings;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする