diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs index 7f29ba5d..08445119 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs @@ -38,6 +38,11 @@ partial class ID2D1ShaderGenerator return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!; } + if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DEmbeddedBytecodeAttribute", out attributeData)) + { + return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!; + } + return null; } @@ -65,6 +70,12 @@ partial class ID2D1ShaderGenerator return options | D2D1CompileOptions.PackMatrixRowMajor; } + if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out attributeData)) + { + // No need to validate against PackMatrixColumnMajor as that's checked separately + return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value! | D2D1CompileOptions.PackMatrixRowMajor; + } + return null; } diff --git a/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs index 385aacee..232ad1bd 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs @@ -16,12 +16,17 @@ namespace ComputeSharp.D2D1; /// /// /// +/// /// Note that the is always enabled automatically and does not need to be /// specified. This option is mandatory, as the generated code to load the constant buffer from a shader assumes the layout /// for matrix types is row major. For the same reason, using is not /// allowed, as it would cause the constant buffer retrieved from a shader to be potentially incorrect. +/// +/// +/// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type. +/// /// -[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] +[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)] public sealed class D2DCompileOptionsAttribute : Attribute { /// diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs index d3fab2d6..1a8cf87d 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DEmbeddedBytecodeAttribute.cs @@ -16,10 +16,15 @@ namespace ComputeSharp.D2D1; /// /// /// +/// /// The runtime compilation will automatically be skipped if the shader bytecode is then retrieved using a matching profile, /// otherwise the usual runtime compilation will be used as fallback (or an exception will be thrown, depending on the API). +/// +/// +/// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type. +/// /// -[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] +[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)] public sealed class D2DEmbeddedBytecodeAttribute : Attribute { ///