From 0dd0bd587a5cc41fa5f9290d1a646f73380de432 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 9 Aug 2022 15:07:01 +0200 Subject: [PATCH] Move known samplers to HlslKnownMethods type --- .../Mappings/HlslKnownMethods.cs | 13 +++++++++ .../Mappings/HlslKnownProperties.cs | 13 --------- .../Mappings/HlslKnownMethods.cs | 22 +++++++++++++++ .../Mappings/HlslKnownProperties.cs | 22 --------------- .../Mappings/HlslKnownMethods.cs | 27 +++++++++++++++++++ .../Mappings/HlslKnownProperties.cs | 20 -------------- 6 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs index 2968f79c..debb52e2 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs @@ -37,4 +37,17 @@ partial class HlslKnownMethods knownMethods.Add($"{typeof(D2D).FullName}{Type.Delimiter}{method.Name}", hlslName); } } + + /// + private static partial IReadOnlyDictionary BuildKnownResourceSamplers() + { + return new Dictionary + { + [$"ComputeSharp.D2D1.D2D1ResourceTexture1D.Sample({typeof(float).FullName})"] = null, + [$"ComputeSharp.D2D1.D2D1ResourceTexture2D.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2", + [$"ComputeSharp.D2D1.D2D1ResourceTexture2D.Sample({typeof(Float2).FullName})"] = null, + [$"ComputeSharp.D2D1.D2D1ResourceTexture3D.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3", + [$"ComputeSharp.D2D1.D2D1ResourceTexture3D.Sample({typeof(Float3).FullName})"] = null + }; + } } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownProperties.cs b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownProperties.cs index 7b70b8f1..690d790c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownProperties.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownProperties.cs @@ -15,19 +15,6 @@ partial class HlslKnownProperties }; } - /// - 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() { diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs index 7a6f51ed..5856846c 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs @@ -149,6 +149,28 @@ internal static partial class HlslKnownMethods /// The mapping of known methods being built. static partial void AddKnownMethods(IDictionary knownMethods); + /// + /// 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(); + + /// + /// 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 HLSL-compatible method name for the input method name. /// diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs index 059e970e..de59abca 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownProperties.cs @@ -220,17 +220,6 @@ internal static partial class HlslKnownProperties /// 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. /// @@ -284,17 +273,6 @@ internal static partial class HlslKnownProperties 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. /// diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs new file mode 100644 index 00000000..eebfd2dd --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace ComputeSharp.SourceGeneration.Mappings; + +/// +partial class HlslKnownMethods +{ + /// + private static partial IReadOnlyDictionary BuildKnownResourceSamplers() + { + return new Dictionary + { + [$"ComputeSharp.ReadOnlyTexture2D`2.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2", + [$"ComputeSharp.ReadOnlyTexture2D`2.Sample({typeof(Float2).FullName})"] = null, + [$"ComputeSharp.IReadOnlyTexture2D`1.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2", + [$"ComputeSharp.IReadOnlyTexture2D`1.Sample({typeof(Float2).FullName})"] = null, + [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2", + [$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.Sample({typeof(Float2).FullName})"] = null, + [$"ComputeSharp.ReadOnlyTexture3D`2.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3", + [$"ComputeSharp.ReadOnlyTexture3D`2.Sample({typeof(Float3).FullName})"] = null, + [$"ComputeSharp.IReadOnlyTexture3D`1.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3", + [$"ComputeSharp.IReadOnlyTexture3D`1.Sample({typeof(Float3).FullName})"] = null, + [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3", + [$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.Sample({typeof(Float3).FullName})"] = null + }; + } +} diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs index 114e23e9..0b595b6e 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownProperties.cs @@ -32,26 +32,6 @@ partial class HlslKnownProperties }; } - /// - private static partial IReadOnlyDictionary BuildKnownResourceSamplers() - { - 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 - }; - } - /// private static partial IReadOnlyDictionary BuildKnownSizeAccessors() {