Use concrete types for all generator mapping fields

このコミットが含まれているのは:
Sergio Pedri committed 2023-12-30 23:12:03 +01:00
1 親 4cf19792a5
コミット f8f2e9c1e6
11ファイル変更
+79 -80

検索条件に一致するファイルはありません

+13 -13
ファイルの表示
@@ -21,6 +21,19 @@ partial class HlslKnownMethods
return name is "ComputeSharp.D2D1.D2D.GetScenePosition" or "ComputeSharp.D2D1.D2D.SampleInputAtPosition";
}
/// <inheritdoc/>
private static partial Dictionary<string, string?> BuildKnownResourceSamplers()
{
return new()
{
[$"ComputeSharp.D2D1.D2D1ResourceTexture1D`1.Sample({typeof(float).FullName})"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D`1.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2",
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D`1.Sample({typeof(Float2).FullName})"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D`1.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3",
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D`1.Sample({typeof(Float3).FullName})"] = null
};
}
/// <inheritdoc/>
static partial void AddKnownMethods(IDictionary<string, string> knownMethods)
@@ -37,17 +50,4 @@ partial class HlslKnownMethods
knownMethods.Add($"{typeof(D2D).FullName}{Type.Delimiter}{method.Name}", hlslName);
}
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers()
{
return new Dictionary<string, string?>
{
[$"ComputeSharp.D2D1.D2D1ResourceTexture1D`1.Sample({typeof(float).FullName})"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D`1.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2",
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D`1.Sample({typeof(Float2).FullName})"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D`1.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3",
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D`1.Sample({typeof(Float3).FullName})"] = null
};
}
}
+4 -4
ファイルの表示
@@ -6,9 +6,9 @@ namespace ComputeSharp.SourceGeneration.Mappings;
partial class HlslKnownProperties
{
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string> BuildKnownResourceIndexers()
private static partial Dictionary<string, string> BuildKnownResourceIndexers()
{
return new Dictionary<string, string>
return new()
{
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
@@ -16,9 +16,9 @@ partial class HlslKnownProperties
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors()
private static partial Dictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors()
{
return new Dictionary<string, (int, int)>
return new()
{
["ComputeSharp.D2D1.D2D1ResourceTexture1D`1.Width"] = (1, 0),
["ComputeSharp.D2D1.D2D1ResourceTexture2D`1.Width"] = (2, 0),
+1 -1
ファイルの表示
@@ -10,7 +10,7 @@ internal static partial class HlslKnownFields
/// <summary>
/// The mapping of supported known fields to HLSL names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownFields = BuildKnownFieldsMap();
private static readonly Dictionary<string, string> KnownFields = BuildKnownFieldsMap();
/// <summary>
/// Builds the mapping of supported known fields to HLSL names.
+1 -1
ファイルの表示
@@ -16,7 +16,7 @@ internal static partial class HlslKnownKeywords
/// <summary>
/// The mapping of known HLSL keywords.
/// </summary>
private static readonly IReadOnlyCollection<string> KnownKeywords = BuildKnownKeywordsMap();
private static readonly HashSet<string> KnownKeywords = BuildKnownKeywordsMap();
/// <summary>
/// Builds the mapping of all known HLSL keywords.
+13 -13
ファイルの表示
@@ -14,12 +14,17 @@ internal static partial class HlslKnownMethods
/// <summary>
/// The mapping of supported known methods to HLSL names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownMethods = BuildKnownMethodsMap();
private static readonly Dictionary<string, string> KnownMethods = BuildKnownMethodsMap();
/// <summary>
/// The mapping of supported known methods that require parameters mapping to HLSL names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownMethodsParametersMapping = BuildKnownMethodsParametersMappingMap();
private static readonly Dictionary<string, string> KnownMethodsParametersMapping = BuildKnownMethodsParametersMappingMap();
/// <summary>
/// The mapping of supported known samplers to HLSL resource type names.
/// </summary>
private static readonly Dictionary<string, string?> KnownResourceSamplers = BuildKnownResourceSamplers();
/// <summary>
/// Builds the mapping of supported known methods to HLSL names.
@@ -94,23 +99,18 @@ internal static partial class HlslKnownMethods
return knownMethods;
}
/// <summary>
/// Builds the mapping of supported known samplers to HLSL resource type names.
/// </summary>
/// <returns>The mapping of supported known samplers to HLSL resource type names.</returns>
private static partial Dictionary<string, string?> BuildKnownResourceSamplers();
/// <summary>
/// Adds more known methods to the mapping to use.
/// </summary>
/// <param name="knownMethods">The mapping of known methods being built.</param>
static partial void AddKnownMethods(IDictionary<string, string> knownMethods);
/// <summary>
/// The mapping of supported known samplers to HLSL resource type names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string?> KnownResourceSamplers = BuildKnownResourceSamplers();
/// <summary>
/// Builds the mapping of supported known samplers to HLSL resource type names.
/// </summary>
/// <returns>The mapping of supported known samplers to HLSL resource type names.</returns>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers();
/// <summary>
/// Tries to get the mapped HLSL-compatible sampler resource type name for the input indexer name.
/// </summary>
+1 -1
ファイルの表示
@@ -14,7 +14,7 @@ internal static partial class HlslKnownOperators
/// <summary>
/// The mapping of supported known operators to HLSL names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownOperators = BuildKnownOperatorsMap();
private static readonly Dictionary<string, string> KnownOperators = BuildKnownOperatorsMap();
/// <summary>
/// Builds the mapping of supported known operators to HLSL names.
+35 -36
ファイルの表示
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
@@ -15,7 +14,27 @@ internal static partial class HlslKnownProperties
/// <summary>
/// The mapping of supported known properties to HLSL names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownProperties = BuildKnownPropertiesMap();
private static readonly Dictionary<string, string> KnownProperties = BuildKnownPropertiesMap();
/// <summary>
/// The mapping of supported known properties to HLSL names.
/// </summary>
private static readonly HashSet<string> KnownMatrixIndexers = BuildKnownMatrixIndexers();
/// <summary>
/// The mapping of supported known members to HLSL names.
/// </summary>
private static readonly HashSet<string> KnownMatrixIndices = BuildKnownMatrixIndices();
/// <summary>
/// The mapping of supported known indexers to HLSL resource type names.
/// </summary>
private static readonly Dictionary<string, string> KnownResourceIndexers = BuildKnownResourceIndexers();
/// <summary>
/// The mapping of supported known size accessors for HLSL resource types.
/// </summary>
private static readonly Dictionary<string, (int Rank, int Axis)> KnownSizeAccessors = BuildKnownSizeAccessors();
/// <summary>
/// Builds the mapping of supported known properties to HLSL names.
@@ -143,23 +162,12 @@ internal static partial class HlslKnownProperties
return knownProperties;
}
/// <summary>
/// Adds more known members to the mapping to use.
/// </summary>
/// <param name="knownProperties">The mapping of known properties being built.</param>
static partial void AddKnownProperties(IDictionary<string, string> knownProperties);
/// <summary>
/// The mapping of supported known properties to HLSL names.
/// </summary>
private static readonly IReadOnlyCollection<string> KnownMatrixIndexers = BuildKnownMatrixIndexers();
/// <summary>
/// Builds the mapping of swizzled matrix indexer properties.
/// </summary>
private static IReadOnlyCollection<string> BuildKnownMatrixIndexers()
private static HashSet<string> BuildKnownMatrixIndexers()
{
return (
return new(
from type in Assembly.GetExecutingAssembly().ExportedTypes
where Regex.IsMatch(type.FullName, @"ComputeSharp\.(Bool|Double|Float|Int|UInt)[1-4]x[1-4]")
from property in type.GetProperties()
@@ -167,45 +175,36 @@ internal static partial class HlslKnownProperties
where indices.Length > 0 &&
indices.All(static index => index.ParameterType == typeof(MatrixIndex))
let metadataName = $"{type.FullName}.this[{string.Join(", ", indices.Select(index => index.ParameterType))}]"
select metadataName).ToImmutableHashSet();
select metadataName);
}
/// <summary>
/// The mapping of supported known members to HLSL names.
/// </summary>
private static readonly IReadOnlyCollection<string> KnownMatrixIndices = BuildKnownMatrixIndices();
/// <summary>
/// Builds the mapping of swizzled matrix indices.
/// </summary>
private static IReadOnlyCollection<string> BuildKnownMatrixIndices()
private static HashSet<string> BuildKnownMatrixIndices()
{
return (
return new(
from name in Enum.GetNames(typeof(MatrixIndex))
select $"{typeof(MatrixIndex).FullName}.{name}").ToImmutableHashSet();
select $"{typeof(MatrixIndex).FullName}.{name}");
}
/// <summary>
/// The mapping of supported known indexers to HLSL resource type names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownResourceIndexers = BuildKnownResourceIndexers();
/// <summary>
/// Builds the mapping of supported known indexers to HLSL resource type names.
/// </summary>
/// <returns>The mapping of supported known indexers to HLSL resource type names.</returns>
private static partial IReadOnlyDictionary<string, string> BuildKnownResourceIndexers();
/// <summary>
/// The mapping of supported known size accessors for HLSL resource types.
/// </summary>
private static readonly IReadOnlyDictionary<string, (int Rank, int Axis)> KnownSizeAccessors = BuildKnownSizeAccessors();
private static partial Dictionary<string, string> BuildKnownResourceIndexers();
/// <summary>
/// Builds the mapping of supported known size accessors for HLSL resource types.
/// </summary>
/// <returns>The mapping of supported known size accessors for HLSL resource types.</returns>
private static partial IReadOnlyDictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors();
private static partial Dictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors();
/// <summary>
/// Adds more known members to the mapping to use.
/// </summary>
/// <param name="knownProperties">The mapping of known properties being built.</param>
static partial void AddKnownProperties(IDictionary<string, string> knownProperties);
/// <summary>
/// Checks whether or not a given property fullname matches a matrix swizzled indexer.
+1 -1
ファイルの表示
@@ -14,7 +14,7 @@ internal static class HlslKnownSizes
/// <summary>
/// The mapping of supported known sizes to HLSL type names.
/// </summary>
private static readonly IReadOnlyDictionary<string, (int, int)> KnownSizes = BuildKnownSizesMap();
private static readonly Dictionary<string, (int, int)> KnownSizes = BuildKnownSizesMap();
/// <summary>
/// Builds the mapping of known type sizes and alignments.
+4 -4
ファイルの表示
@@ -57,22 +57,22 @@ internal static partial class HlslKnownTypes
/// <summary>
/// The mapping of supported known vector types to HLSL types.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownVectorTypeMetadataNames = BuildKnownVectorTypeMetadataNames();
private static readonly Dictionary<string, string> KnownVectorTypeMetadataNames = BuildKnownVectorTypeMetadataNames();
/// <summary>
/// The mapping of supported known matrix types to HLSL types.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownMatrixTypesMetadataNames = BuildKnownMatrixTypeMetadataNames();
private static readonly Dictionary<string, string> KnownMatrixTypesMetadataNames = BuildKnownMatrixTypeMetadataNames();
/// <summary>
/// The mapping of supported known types to HLSL types.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownHlslTypeMetadataNames = BuildKnownHlslTypeMetadataNames();
private static readonly Dictionary<string, string> KnownHlslTypeMetadataNames = BuildKnownHlslTypeMetadataNames();
/// <summary>
/// The mapping of type info for all supported known matrix types to HLSL types.
/// </summary>
private static readonly IReadOnlyDictionary<string, NonLinearMatrixTypeInfo> KnownNonLinearMatrixTypeInfo = BuildKnownNonLinearMatrixTypeInfo();
private static readonly Dictionary<string, NonLinearMatrixTypeInfo> KnownNonLinearMatrixTypeInfo = BuildKnownNonLinearMatrixTypeInfo();
/// <summary>
/// Builds the mapping of known HLSL vector types.
+2 -2
ファイルの表示
@@ -6,9 +6,9 @@ namespace ComputeSharp.SourceGeneration.Mappings;
partial class HlslKnownMethods
{
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers()
private static partial Dictionary<string, string?> BuildKnownResourceSamplers()
{
return new Dictionary<string, string?>
return new()
{
[$"ComputeSharp.ReadOnlyTexture1D`2.Sample({typeof(float).FullName})"] = null,
[$"ComputeSharp.IReadOnlyTexture1D`1.Sample({typeof(float).FullName})"] = null,
+4 -4
ファイルの表示
@@ -9,9 +9,9 @@ namespace ComputeSharp.SourceGeneration.Mappings;
partial class HlslKnownProperties
{
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string> BuildKnownResourceIndexers()
private static partial Dictionary<string, string> BuildKnownResourceIndexers()
{
return new Dictionary<string, string>
return new()
{
[$"ComputeSharp.ReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
@@ -33,9 +33,9 @@ partial class HlslKnownProperties
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors()
private static partial Dictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors()
{
return new Dictionary<string, (int, int)>
return new()
{
["ComputeSharp.Resources.Buffer`1.Length"] = (2, 0),
["ComputeSharp.Resources.Texture1D`1.Width"] = (1, 0),