diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index 994adc48..16e64716 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Immutable; using ComputeSharp.__Internals; using ComputeSharp.D2D1Interop.__Internals; using ComputeSharp.D2D1Interop.SourceGenerators.Models; @@ -78,7 +77,7 @@ partial class ID2D1ShaderGenerator Argument(IdentifierName("loader")).WithRefKindKeyword(Token(SyntaxKind.RefKeyword)), Argument(ThisExpression()).WithRefKindKeyword(Token(SyntaxKind.InKeyword)), Argument(IdentifierName("shaderProfile")), - Argument(LiteralExpression(bytecodeInfo.isLinkingSupported ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression)))); + Argument(LiteralExpression(bytecodeInfo.IsLinkingSupported ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression)))); // If there is no precompiled bytecode, just return the dynamic path if (bytecodeInfo.Bytecode.IsDefaultOrEmpty) @@ -88,8 +87,6 @@ partial class ID2D1ShaderGenerator return Block(dynamicLoadingStatement); } - ImmutableArray.Builder statements = ImmutableArray.CreateBuilder(); - bytecodeLiterals = BuildShaderBytecodeExpressionString(bytecodeInfo.Bytecode.AsSpan()); // This code produces a branch as follows: @@ -113,8 +110,8 @@ partial class ID2D1ShaderGenerator ConstantPattern( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(D2D1ShaderProfile)), - IdentifierName(D2D1ShaderProfile.PixelShader50.ToString()))))), + IdentifierName("global::ComputeSharp.D2D1Interop.D2D1ShaderProfile"), + IdentifierName(bytecodeInfo.ShaderProfile.GetValueOrDefault().ToString()))))), Block( LocalDeclarationStatement( VariableDeclaration( diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs index b142236f..f1c250b6 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs @@ -147,7 +147,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator token.ThrowIfCancellationRequested(); - EmbeddedBytecodeInfo bytecodeInfo = new(item.Source.HlslSource, item.Source.IsLinkingSupported, bytecode); + EmbeddedBytecodeInfo bytecodeInfo = new(item.Source.HlslSource, item.Source.ShaderProfile, item.Source.IsLinkingSupported, bytecode); return (item.Hierarchy, bytecodeInfo, diagnostic); }); diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/EmbeddedBytecodeInfo.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/EmbeddedBytecodeInfo.cs index 10c36d2c..c10fb270 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/EmbeddedBytecodeInfo.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/EmbeddedBytecodeInfo.cs @@ -9,9 +9,10 @@ namespace ComputeSharp.D2D1Interop.SourceGenerators.Models; /// A model representing a shared and its compiled bytecode, if available. /// /// The HLSL source for the shader. -/// Whether linking is supported for the current shader. +/// The shader profile to use to compile the shader, if requested. +/// Whether linking is supported for the current shader. /// The compiled shader bytecode, if available. -internal sealed record EmbeddedBytecodeInfo(string HlslSource, bool isLinkingSupported, ImmutableArray Bytecode) +internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, bool IsLinkingSupported, ImmutableArray Bytecode) { /// /// An implementation for . @@ -43,7 +44,8 @@ internal sealed record EmbeddedBytecodeInfo(string HlslSource, bool isLinkingSup return x.HlslSource == y.HlslSource && - x.isLinkingSupported == y.isLinkingSupported && + x.ShaderProfile == y.ShaderProfile && + x.IsLinkingSupported == y.IsLinkingSupported && x.Bytecode.SequenceEqual(y.Bytecode); } @@ -53,7 +55,8 @@ internal sealed record EmbeddedBytecodeInfo(string HlslSource, bool isLinkingSup HashCode hashCode = default; hashCode.Add(obj.HlslSource); - hashCode.Add(obj.isLinkingSupported); + hashCode.Add(obj.ShaderProfile); + hashCode.Add(obj.IsLinkingSupported); hashCode.AddBytes(obj.Bytecode.AsSpan()); return hashCode.ToHashCode();