diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownProperties.cs b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownProperties.cs
new file mode 100644
index 00000000..7b70b8f1
--- /dev/null
+++ b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownProperties.cs
@@ -0,0 +1,44 @@
+using System.Collections.Generic;
+
+namespace ComputeSharp.SourceGeneration.Mappings;
+
+///
+partial class HlslKnownProperties
+{
+ ///
+ private static partial IReadOnlyDictionary BuildKnownResourceIndexers()
+ {
+ return new Dictionary
+ {
+ [$"ComputeSharp.D2D1.D2D1ResourceTexture2D.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.D2D1.D2D1ResourceTexture3D.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
+ };
+ }
+
+ ///
+ private static partial IReadOnlyDictionary BuildKnownResourceSamplers()
+ {
+ return new Dictionary
+ {
+ [$"ComputeSharp.D2D1.D2D1ResourceTexture1D.this[{typeof(float).FullName}]"] = null,
+ [$"ComputeSharp.D2D1.D2D1ResourceTexture2D.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
+ [$"ComputeSharp.D2D1.D2D1ResourceTexture2D.this[{typeof(Float2).FullName}]"] = null,
+ [$"ComputeSharp.D2D1.D2D1ResourceTexture3D.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
+ [$"ComputeSharp.D2D1.D2D1ResourceTexture3D.this[{typeof(Float3).FullName}]"] = null
+ };
+ }
+
+ ///
+ private static partial IReadOnlyDictionary BuildKnownSizeAccessors()
+ {
+ return new Dictionary
+ {
+ ["ComputeSharp.D2D1.D2D1ResourceTexture1D.Width"] = (1, 0),
+ ["ComputeSharp.D2D1.D2D1ResourceTexture2D.Width"] = (2, 0),
+ ["ComputeSharp.D2D1.D2D1ResourceTexture2D.Height"] = (2, 1),
+ ["ComputeSharp.D2D1.D2D1ResourceTexture3D.Width"] = (3, 0),
+ ["ComputeSharp.D2D1.D2D1ResourceTexture3D.Height"] = (3, 1),
+ ["ComputeSharp.D2D1.D2D1ResourceTexture3D.Depth"] = (3, 2)
+ };
+ }
+}
diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs
index c39af7a0..059e970e 100644
--- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs
+++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs
@@ -209,6 +209,39 @@ internal static partial class HlslKnownProperties
select $"{typeof(MatrixIndex).FullName}.{name}").ToImmutableHashSet();
}
+ ///
+ /// The mapping of supported known indexers to HLSL resource type names.
+ ///
+ private static readonly IReadOnlyDictionary KnownResourceIndexers = BuildKnownResourceIndexers();
+
+ ///
+ /// Builds the mapping of supported known indexers to HLSL resource type names.
+ ///
+ /// The mapping of supported known indexers to HLSL resource type names.
+ private static partial IReadOnlyDictionary BuildKnownResourceIndexers();
+
+ ///
+ /// The mapping of supported known samplers to HLSL resource type names.
+ ///
+ private static readonly IReadOnlyDictionary KnownResourceSamplers = BuildKnownResourceSamplers();
+
+ ///
+ /// Builds the mapping of supported known samplers to HLSL resource type names.
+ ///
+ /// The mapping of supported known samplers to HLSL resource type names.
+ private static partial IReadOnlyDictionary BuildKnownResourceSamplers();
+
+ ///
+ /// The mapping of supported known size accessors for HLSL resource types.
+ ///
+ private static readonly IReadOnlyDictionary KnownSizeAccessors = BuildKnownSizeAccessors();
+
+ ///
+ /// Builds the mapping of supported known size accessors for HLSL resource types.
+ ///
+ /// The mapping of supported known size accessors for HLSL resource types.
+ private static partial IReadOnlyDictionary BuildKnownSizeAccessors();
+
///
/// Checks whether or not a given property fullname matches a matrix swizzled indexer.
///
@@ -239,4 +272,47 @@ internal static partial class HlslKnownProperties
{
return KnownProperties.TryGetValue(name, out mapped);
}
+
+ ///
+ /// Tries to get the mapped HLSL-compatible indexer resource type name for the input indexer name.
+ ///
+ /// The input fully qualified indexer name.
+ /// The mapped type name, if one is found.
+ /// The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.
+ public static bool TryGetMappedResourceIndexerTypeName(string name, out string? mapped)
+ {
+ return KnownResourceIndexers.TryGetValue(name, out mapped);
+ }
+
+ ///
+ /// Tries to get the mapped HLSL-compatible sampler resource type name for the input indexer name.
+ ///
+ /// The input fully qualified indexer name.
+ /// The mapped type name, if one is found.
+ /// The HLSL-compatible type name that can be used in an HLSL shader for the given sampler.
+ public static bool TryGetMappedResourceSamplerAccessType(string name, out string? mapped)
+ {
+ return KnownResourceSamplers.TryGetValue(name, out mapped);
+ }
+
+ ///
+ /// Tries to get the mapped rank and axis for a given indexer name.
+ ///
+ /// The input fully qualified indexer name.
+ /// The resulting indexer rank, if found.
+ /// The resulting indexer axis, if found.
+ /// Whether or not a rank and axis could be resolved by the input indexer name.
+ public static bool TryGetAccessorRankAndAxis(string name, out int rank, out int axis)
+ {
+ if (KnownSizeAccessors.TryGetValue(name, out var info))
+ {
+ (rank, axis) = info;
+
+ return true;
+ }
+
+ (rank, axis) = default((int, int));
+
+ return false;
+ }
}
diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs
index 6baf91aa..114e23e9 100644
--- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs
+++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs
@@ -8,75 +8,78 @@ namespace ComputeSharp.SourceGeneration.Mappings;
///
partial class HlslKnownProperties
{
- ///
- /// The mapping of supported known indexers to HLSL resource type names.
- ///
- private static readonly IReadOnlyDictionary KnownResourceIndexers = new Dictionary
+ ///
+ private static partial IReadOnlyDictionary BuildKnownResourceIndexers()
{
- [$"ComputeSharp.ReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.ReadWriteTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.IReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.IReadWriteNormalizedTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
- [$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
- [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
- [$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
- [$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
- [$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
- [$"ComputeSharp.IReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
- [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
- [$"ComputeSharp.IReadWriteNormalizedTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
- };
+ return new Dictionary
+ {
+ [$"ComputeSharp.ReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.ReadWriteTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.IReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.IReadWriteNormalizedTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.IReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.IReadWriteNormalizedTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
+ };
+ }
- ///
- /// The mapping of supported known samplers to HLSL resource type names.
- ///
- private static readonly IReadOnlyDictionary KnownResourceSamplers = new Dictionary
+ ///
+ private static partial IReadOnlyDictionary BuildKnownResourceSamplers()
{
- [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
- [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(Float2).FullName}]"] = null,
- [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
- [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float2).FullName}]"] = null,
- [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
- [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(Float2).FullName}]"] = null,
- [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
- [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(Float3).FullName}]"] = null,
- [$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
- [$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(Float3).FullName}]"] = null,
- [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
- [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(Float3).FullName}]"] = null
- };
+ return new Dictionary
+ {
+ [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
+ [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(Float2).FullName}]"] = null,
+ [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
+ [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float2).FullName}]"] = null,
+ [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
+ [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(Float2).FullName}]"] = null,
+ [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
+ [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(Float3).FullName}]"] = null,
+ [$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
+ [$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(Float3).FullName}]"] = null,
+ [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
+ [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(Float3).FullName}]"] = null
+ };
+ }
- ///
- /// The mapping of supported known size accessors for HLSL resource types.
- ///
- private static readonly IReadOnlyDictionary KnownSizeAccessors = new Dictionary
+ ///
+ private static partial IReadOnlyDictionary BuildKnownSizeAccessors()
{
- ["ComputeSharp.Resources.Buffer`1.Length"] = (2, 0),
- ["ComputeSharp.Resources.Texture2D`1.Width"] = (2, 0),
- ["ComputeSharp.Resources.Texture2D`1.Height"] = (2, 1),
- ["ComputeSharp.Resources.Texture3D`1.Width"] = (3, 0),
- ["ComputeSharp.Resources.Texture3D`1.Height"] = (3, 1),
- ["ComputeSharp.Resources.Texture3D`1.Depth"] = (3, 2),
- ["ComputeSharp.IReadOnlyTexture2D`1.Width"] = (2, 0),
- ["ComputeSharp.IReadOnlyTexture2D`1.Height"] = (2, 1),
- ["ComputeSharp.IReadOnlyTexture3D`1.Width"] = (3, 0),
- ["ComputeSharp.IReadOnlyTexture3D`1.Height"] = (3, 1),
- ["ComputeSharp.IReadOnlyTexture3D`1.Depth"] = (3, 2),
- ["ComputeSharp.IReadOnlyNormalizedTexture2D`1.Width"] = (2, 0),
- ["ComputeSharp.IReadOnlyNormalizedTexture2D`1.Height"] = (2, 1),
- ["ComputeSharp.IReadOnlyNormalizedTexture3D`1.Width"] = (3, 0),
- ["ComputeSharp.IReadOnlyNormalizedTexture3D`1.Height"] = (3, 1),
- ["ComputeSharp.IReadOnlyNormalizedTexture3D`1.Depth"] = (3, 2),
- ["ComputeSharp.IReadWriteNormalizedTexture2D`1.Width"] = (2, 0),
- ["ComputeSharp.IReadWriteNormalizedTexture2D`1.Height"] = (2, 1),
- ["ComputeSharp.IReadWriteNormalizedTexture3D`1.Width"] = (3, 0),
- ["ComputeSharp.IReadWriteNormalizedTexture3D`1.Height"] = (3, 1),
- ["ComputeSharp.IReadWriteNormalizedTexture3D`1.Depth"] = (3, 2)
- };
+ return new Dictionary
+ {
+ ["ComputeSharp.Resources.Buffer`1.Length"] = (2, 0),
+ ["ComputeSharp.Resources.Texture2D`1.Width"] = (2, 0),
+ ["ComputeSharp.Resources.Texture2D`1.Height"] = (2, 1),
+ ["ComputeSharp.Resources.Texture3D`1.Width"] = (3, 0),
+ ["ComputeSharp.Resources.Texture3D`1.Height"] = (3, 1),
+ ["ComputeSharp.Resources.Texture3D`1.Depth"] = (3, 2),
+ ["ComputeSharp.IReadOnlyTexture2D`1.Width"] = (2, 0),
+ ["ComputeSharp.IReadOnlyTexture2D`1.Height"] = (2, 1),
+ ["ComputeSharp.IReadOnlyTexture3D`1.Width"] = (3, 0),
+ ["ComputeSharp.IReadOnlyTexture3D`1.Height"] = (3, 1),
+ ["ComputeSharp.IReadOnlyTexture3D`1.Depth"] = (3, 2),
+ ["ComputeSharp.IReadOnlyNormalizedTexture2D`1.Width"] = (2, 0),
+ ["ComputeSharp.IReadOnlyNormalizedTexture2D`1.Height"] = (2, 1),
+ ["ComputeSharp.IReadOnlyNormalizedTexture3D`1.Width"] = (3, 0),
+ ["ComputeSharp.IReadOnlyNormalizedTexture3D`1.Height"] = (3, 1),
+ ["ComputeSharp.IReadOnlyNormalizedTexture3D`1.Depth"] = (3, 2),
+ ["ComputeSharp.IReadWriteNormalizedTexture2D`1.Width"] = (2, 0),
+ ["ComputeSharp.IReadWriteNormalizedTexture2D`1.Height"] = (2, 1),
+ ["ComputeSharp.IReadWriteNormalizedTexture3D`1.Width"] = (3, 0),
+ ["ComputeSharp.IReadWriteNormalizedTexture3D`1.Height"] = (3, 1),
+ ["ComputeSharp.IReadWriteNormalizedTexture3D`1.Depth"] = (3, 2)
+ };
+ }
///
static partial void AddKnownProperties(IDictionary knownProperties)
@@ -175,47 +178,4 @@ partial class HlslKnownProperties
}
}
}
-
- ///
- /// Tries to get the mapped HLSL-compatible indexer resource type name for the input indexer name.
- ///
- /// The input fully qualified indexer name.
- /// The mapped type name, if one is found.
- /// The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.
- public static bool TryGetMappedResourceIndexerTypeName(string name, out string? mapped)
- {
- return KnownResourceIndexers.TryGetValue(name, out mapped);
- }
-
- ///
- /// Tries to get the mapped HLSL-compatible sampler resource type name for the input indexer name.
- ///
- /// The input fully qualified indexer name.
- /// The mapped type name, if one is found.
- /// The HLSL-compatible type name that can be used in an HLSL shader for the given sampler.
- public static bool TryGetMappedResourceSamplerAccessType(string name, out string? mapped)
- {
- return KnownResourceSamplers.TryGetValue(name, out mapped);
- }
-
- ///
- /// Tries to get the mapped rank and axis for a given indexer name.
- ///
- /// The input fully qualified indexer name.
- /// The resulting indexer rank, if found.
- /// The resulting indexer axis, if found.
- /// Whether or not a rank and axis could be resolved by the input indexer name.
- public static bool TryGetAccessorRankAndAxis(string name, out int rank, out int axis)
- {
- if (KnownSizeAccessors.TryGetValue(name, out var info))
- {
- (rank, axis) = info;
-
- return true;
- }
-
- (rank, axis) = default((int, int));
-
- return false;
- }
}