From fb6b94c632b73236143d8014ad5903f7c9bd1d07 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 14:03:02 +0200 Subject: [PATCH] Simplify code in diagnostic tests and diagnostic values --- .../Diagnostics/DiagnosticDescriptors.cs | 52 +- .../Diagnostics/DiagnosticDescriptors.cs | 20 +- .../DiagnosticsTests.cs | 1173 ++++++----------- 3 files changed, 430 insertions(+), 815 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 7b884420..e395e8a6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -15,13 +15,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid shader field. /// - /// Format: "The compute shader of type {0} contains a field \"{1}\" of an invalid type {2}". + /// Format: "The compute shader of type {0} contains a field "{1}" of an invalid type {2}". /// /// public static readonly DiagnosticDescriptor InvalidShaderField = new DiagnosticDescriptor( id: "CMPSD2D0001", title: "Invalid shader field", - messageFormat: "The compute shader of type {0} contains a field \"{1}\" of an invalid type {2}", + messageFormat: """The compute shader of type {0} contains a field "{1}" of an invalid type {2}""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -401,13 +401,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid shader static readonly field type. /// - /// Format: "The compute shader of type {0} contains a static readonly field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)". + /// Format: "The compute shader of type {0} contains a static readonly field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)". /// /// public static readonly DiagnosticDescriptor InvalidShaderStaticFieldType = new DiagnosticDescriptor( id: "CMPSD2D0030", title: "Invalid shader static readonly field type", - messageFormat: "The compute shader of type {0} contains a static readonly field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)", + messageFormat: """The compute shader of type {0} contains a static readonly field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -417,13 +417,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a property declaration. /// - /// Format: "The D2D1 shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)". + /// Format: "The D2D1 shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)". /// /// public static readonly DiagnosticDescriptor InvalidPropertyDeclaration = new DiagnosticDescriptor( id: "CMPSD2D0031", title: "Invalid property declaration", - messageFormat: "The D2D1 shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)", + messageFormat: """The D2D1 shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -455,7 +455,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new DiagnosticDescriptor( id: "CMPSD2D0033", title: "Embedded bytecode compilation failed due to Win32 exception", - messageFormat: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: \"{2}\")", + messageFormat: """The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -471,7 +471,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithFxcCompilationException = new DiagnosticDescriptor( id: "CMPSD2D0034", title: "Embedded bytecode compilation failed due to an HLSL compiler error", - messageFormat: "The shader of type {0} failed to compile due to an HLSL compiler error (Message: \"{1}\")", + messageFormat: """The shader of type {0} failed to compile due to an HLSL compiler error (Message: "{1}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -706,13 +706,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid use of [D2DResourceTextureIndex]. /// - /// Format: "The field \"{0}\" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})". + /// Format: "The field "{0}" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})". /// /// public static readonly DiagnosticDescriptor InvalidD2DResourceTextureIndexAttributeUse = new DiagnosticDescriptor( id: "CMPSD2D0049", title: "Invalid [D2DResourceTextureIndex] use", - messageFormat: "The field \"{0}\" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})", + messageFormat: """The field "{0}" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -722,13 +722,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a missing [D2DResourceTextureIndex]. /// - /// Format: "The field \"{0}\" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute". + /// Format: "The field "{0}" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute". /// /// public static readonly DiagnosticDescriptor MissingD2DResourceTextureIndexAttribute = new DiagnosticDescriptor( id: "CMPSD2D0050", title: "Missing [D2DResourceTextureIndex] attribute", - messageFormat: "The field \"{0}\" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute", + messageFormat: """The field "{0}" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -738,13 +738,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a resource texture using an invalid element type. /// - /// Format: "The field \"{0}\" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)". + /// Format: "The field "{0}" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)". /// /// public static readonly DiagnosticDescriptor InvalidResourceTextureElementType = new DiagnosticDescriptor( id: "CMPSD2D0051", title: "Invalid D2D1 resource texture element type", - messageFormat: "The field \"{0}\" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)", + messageFormat: """The field "{0}" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -754,13 +754,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid HLSL source in [D2DPixelShaderSource]. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument". /// /// public static readonly DiagnosticDescriptor InvalidD2DPixelShaderSource = new DiagnosticDescriptor( id: "CMPSD2D0052", title: "Invalid [D2DPixelShaderSource] HLSL source argument", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -770,13 +770,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader failed due to a Win32 exception. /// - /// Format: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: \"{3}\")". + /// Format: "Compiling the HLSL source for method "{1}" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: "{3}")". /// /// public static readonly DiagnosticDescriptor D2DPixelShaderSourceCompilationFailedWithWin32Exception = new DiagnosticDescriptor( id: "CMPSD2D0053", title: "D2D shader compilation failed due to Win32 exception", - messageFormat: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: \"{3}\")", + messageFormat: """Compiling the HLSL source for method "{1}" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: "{3}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -786,13 +786,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader failed due to an HLSL compilation exception. /// - /// Format: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to an HLSL compiler error (Message: \"{2}\")". + /// Format: "Compiling the HLSL source for method "{1}" (in type {0}) failed due to an HLSL compiler error (Message: "{2}")". /// /// public static readonly DiagnosticDescriptor D2DPixelShaderSourceCompilationFailedWithFxcCompilationException = new DiagnosticDescriptor( id: "CMPSD2D0054", title: "D2D shader compilation failed due to an HLSL compiler error", - messageFormat: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to an HLSL compiler error (Message: \"{2}\")", + messageFormat: """Compiling the HLSL source for method "{1}" (in type {0}) failed due to an HLSL compiler error (Message: "{2}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -802,13 +802,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader with no shader profile set. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use". /// /// public static readonly DiagnosticDescriptor MissingShaderProfileForD2DPixelShaderSource = new DiagnosticDescriptor( id: "CMPSD2D0055", title: "Missing shader profile for D2D pixel shader source", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -818,13 +818,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader with no compile options set. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use". /// /// public static readonly DiagnosticDescriptor MissingCompileOptionsForD2DPixelShaderSource = new DiagnosticDescriptor( id: "CMPSD2D0056", title: "Missing compile options for D2D pixel shader source", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -834,13 +834,13 @@ partial class DiagnosticDescriptors /// /// Gets a for when a method with [D2DPixelShaderSource] has an invalid return type. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan<byte>)". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan<byte>)". /// /// public static readonly DiagnosticDescriptor InvalidD2DPixelShaderSourceMethodReturnType = new DiagnosticDescriptor( id: "CMPSD2D0057", title: "Missing compile options for D2D pixel shader source", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan)", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 8fd642cb..0d5f840a 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -21,7 +21,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidShaderField = new DiagnosticDescriptor( id: "CMPS0001", title: "Invalid shader field", - messageFormat: "The compute shader of type {0} contains a field \"{1}\" of an invalid type {2}", + messageFormat: """The compute shader of type {0} contains a field "{1}" of an invalid type {2}""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -37,7 +37,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidGroupSharedFieldType = new DiagnosticDescriptor( id: "CMPS0002", title: "Invalid group shared field type", - messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be an array)", + messageFormat: """The compute shader of type {0} contains a group shared field "{1}" of an invalid type {2} (it must be an array)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -53,7 +53,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidGroupSharedFieldElementType = new DiagnosticDescriptor( id: "CMPS0003", title: "Invalid group shared field element type", - messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be a primitive or unmanaged type)", + messageFormat: """The compute shader of type {0} contains a group shared field "{1}" of an invalid type {2} (it must be a primitive or unmanaged type)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -69,7 +69,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidGroupSharedFieldDeclaration = new DiagnosticDescriptor( id: "CMPS0004", title: "Invalid group shared field declaration", - messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" that is not static", + messageFormat: """The compute shader of type {0} contains a group shared field "{1}" that is not static""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -517,13 +517,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid shader static field type. /// - /// Format: "The compute shader of type {0} contains a static field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)". + /// Format: "The compute shader of type {0} contains a static field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)". /// /// public static readonly DiagnosticDescriptor InvalidShaderStaticFieldType = new DiagnosticDescriptor( id: "CMPS0038", title: "Invalid shader static field type", - messageFormat: "The compute shader of type {0} contains a static field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)", + messageFormat: """The compute shader of type {0} contains a static field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -546,13 +546,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a property declaration. /// - /// Format: "The compute shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)". + /// Format: "The compute shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)". /// /// public static readonly DiagnosticDescriptor InvalidPropertyDeclaration = new DiagnosticDescriptor( id: "CMPS0040", title: "Invalid property declaration", - messageFormat: "The compute shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)", + messageFormat: """The compute shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -616,7 +616,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new DiagnosticDescriptor( id: "CMPS0045", title: "Embedded bytecode compilation failed due to Win32 exception", - messageFormat: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: \"{2}\")", + messageFormat: """The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -632,7 +632,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithDxcCompilationException = new DiagnosticDescriptor( id: "CMPS0046", title: "Embedded bytecode compilation failed due to an HLSL compiler error", - messageFormat: "The shader of type {0} failed to compile due to an HLSL compiler error (Message: \"{1}\")", + messageFormat: """The shader of type {0} failed to compile due to an HLSL compiler error (Message: "{1}")""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index 4d701d54..a291d85e 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -19,20 +19,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [GeneratedComputeShaderDescriptor] + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; - public string text; + public ReadWriteBuffer buffer; + public string text; - public void Execute() { } - } + public void Execute() { } } """; @@ -45,20 +40,14 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public unsafe struct MyShader : IComputeShader { - public unsafe struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; - public fixed int text[16]; + public ReadWriteBuffer buffer; + public fixed int text[16]; - public void Execute() { } - } + public void Execute() { } } """; @@ -71,23 +60,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - public class GroupSharedAttribute : Attribute { } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + [GroupShared] + public static string text; - [GroupShared] - public static string text; - - public void Execute() { } - } + public void Execute() { } } """; @@ -100,23 +82,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - public class GroupSharedAttribute : Attribute { } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + [GroupShared] + public static string[] text; - [GroupShared] - public static string[] text; - - public void Execute() { } - } + public void Execute() { } } """; @@ -129,21 +104,14 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public class GroupSharedAttribute : Attribute { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - [GroupShared] - public ReadWriteBuffer buffer; + [GroupShared] + public ReadWriteBuffer buffer; - public void Execute() { } - } + public void Execute() { } } """; @@ -156,12 +124,11 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace MyFancyApp.Sample + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public void Execute() { } - } + public void Execute() { } } """; @@ -179,24 +146,17 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public static class {{typeName}} { public static int X => 0; } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; + static int Fail() => {{typeName}}.X; - public void Execute() - { - static int Fail() => {{typeName}}.X; - - Fail(); - } + Fail(); } } """; @@ -215,22 +175,15 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - public static class {{typeName}} { public static int X => 0; } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public static int Fail() => {{typeName}}.X; - public static int Fail() => {{typeName}}.X; - - public void Execute() => Fail(); - } + public void Execute() => Fail(); } """; @@ -243,24 +196,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public static class ThreadIds { public static class Normalized { public static int X => 0; } } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public static int Fail() => ThreadIds.Normalized.X; + + public void Execute() { - public ReadWriteBuffer buffer; - - public static int Fail() => ThreadIds.Normalized.X; - - public void Execute() - { - buffer[0] = Fail(); - } + buffer[0] = Fail(); } } """; @@ -274,21 +220,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - object o = new object(); - } + object o = new object(); } } """; @@ -302,21 +242,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - object o = new(); - } + object o = new(); } } """; @@ -330,21 +264,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - var o = new { Age = 12 }; - } + var o = new { Age = 12 }; } } """; @@ -358,23 +286,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; + static async void Fail() { } - public void Execute() - { - static async void Fail() { } - - Fail(); - } + Fail(); } } """; @@ -388,21 +310,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public static async void Fail() { } - public static async void Fail() { } - - public void Execute() => Fail(); - } + public void Execute() => Fail(); } """; @@ -415,21 +331,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public async void Execute() { - public ReadWriteBuffer buffer; - - public async void Execute() - { - await null; - } + await null; } } """; @@ -445,21 +355,15 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - int a = {{text}}(1 + 1); - } + int a = {{text}}(1 + 1); } } """; @@ -475,23 +379,17 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + {{text}} { - {{text}} - { - int a = 1 + 1; - } + int a = 1 + 1; } } } @@ -506,25 +404,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - fixed (void* p = buffer.Data) - { - } + public void Execute() + { + fixed (void* p = buffer.Data) + { } } } @@ -539,25 +428,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - foreach (int i in buffer.Data) - { - } + public void Execute() + { + foreach (int i in buffer.Data) + { } } } @@ -572,22 +452,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - lock (buffer) - { - } + public void Execute() + { + lock (buffer) + { } } } @@ -602,24 +476,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - _ = from x in buffer.Data select x; - } + public void Execute() + { + _ = from x in buffer.Data select x; } } """; @@ -633,24 +498,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - _ = buffer.Data[1..]; - } + public void Execute() + { + _ = buffer.Data[1..]; } } """; @@ -664,25 +520,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public object Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - if (buffer.Data is int[] { Length: 50 } foo) - { - } + public void Execute() + { + if (buffer.Data is int[] { Length: 50 } foo) + { } } } @@ -697,24 +544,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public ref T this[int x] => throw null; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - ref float x = ref buffer[0]; - } + public void Execute() + { + ref float x = ref buffer[0]; } } """; @@ -728,25 +566,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - if (buffer.Data is > 0 and < 10) - { - } + public void Execute() + { + if (buffer.Data is > 0 and < 10) + { } } } @@ -761,21 +590,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - _ = sizeof(float); - } + public void Execute() + { + _ = sizeof(float); } } """; @@ -789,21 +612,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - int* p = stackalloc int[10]; - } + public void Execute() + { + int* p = stackalloc int[10]; } } """; @@ -817,21 +634,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - throw null; - } + public void Execute() + { + throw null; } } """; @@ -845,25 +656,19 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + try + { + } + catch { - try - { - } - catch - { - } } } } @@ -878,21 +683,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - (int, float) foo; - } + (int, float) foo; } } """; @@ -906,21 +705,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - using IDisposable foo = null - } + using IDisposable foo = null } } """; @@ -934,22 +727,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + using (IDisposable foo = null) { - using (IDisposable foo = null) - { - } } } } @@ -965,26 +752,20 @@ public class DiagnosticsTests using System.Collections.Generic; using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public static IEnumerable Fail() { - public ReadWriteBuffer buffer; + yield return 3.14f; + } - public static IEnumerable Fail() - { - yield return 3.14f; - } - - public void Execute() - { - Fail(); - } + public void Execute() + { + Fail(); } } """; @@ -998,21 +779,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - string bar; - } + string bar; } } """; @@ -1026,21 +801,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - int* p; - } + int* p; } } """; @@ -1054,21 +823,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - delegate* f; - } + delegate* f; } } """; @@ -1082,22 +845,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + unsafe { - unsafe - { - } } } } @@ -1112,23 +869,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; + static unsafe void Fail() { } - public void Execute() - { - static unsafe void Fail() { } - - Fail(); - } + Fail(); } } """; @@ -1142,23 +893,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public static unsafe void Fail() { } + + public ReadWriteBuffer buffer; + + public void Execute() { - public static unsafe void Fail() { } - - public ReadWriteBuffer buffer; - - public void Execute() - { - Fail(); - } + Fail(); } } """; @@ -1172,21 +917,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - _ = "Hello world"; - } + _ = "Hello world"; } } """; @@ -1203,34 +942,17 @@ public class DiagnosticsTests using float4 = ComputeSharp.Float4; using float4x4 = ComputeSharp.Float4x4; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public enum MatrixIndex - { - M11, - M12, - M13 - }, - public struct Float4 { } - public struct Float4x4 - { - public Float4 this[MatrixIndex m0, MatrixIndex m1, MatrixIndex m2, MatrixIndex m3] => default; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - float4x4 m = default; - MatrixIndex index = M12; - float4 = m[M11, index, M13, M11]; - } + public void Execute() + { + float4x4 m = default; + MatrixIndex index = M12; + float4 = m[M11, index, M13, M11]; } } """; @@ -1244,22 +966,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static string Pi = ""Hello""; + + public void Execute() { - public ReadWriteBuffer buffer; - - private static string Pi = ""Hello""; - - public void Execute() - { - } } } """; @@ -1273,22 +989,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static float Pi { get; } = 3.14f; + + public void Execute() { - public ReadWriteBuffer buffer; - - private static float Pi { get; } = 3.14f; - - public void Execute() - { - } } } """; @@ -1302,27 +1012,21 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public interface IFoo { - public class ReadWriteBuffer { } + float Pi { get; } } - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader, IFoo { - public interface IFoo + public ReadWriteBuffer buffer; + + float IFoo.Pi { get; } = 3.14f; + + public void Execute() { - float Pi { get; } - } - - public struct MyShader : IComputeShader, IFoo - { - public ReadWriteBuffer buffer; - - float IFoo.Pi { get; } = 3.14f; - - public void Execute() - { - } } } """; @@ -1336,25 +1040,19 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static float Pi { - public ReadWriteBuffer buffer; + get => 3.14f; + } - private static float Pi - { - get => 3.14f; - } - - public void Execute() - { - } + public void Execute() + { } } """; @@ -1368,22 +1066,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static float Pi { get; set; } = 3.14f; + + public void Execute() { - public ReadWriteBuffer buffer; - - private static float Pi { get; set; } = 3.14f; - - public void Execute() - { - } } } """; @@ -1397,22 +1089,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private float Pi => 3.14f; + + public void Execute() { - public ReadWriteBuffer buffer; - - private float Pi => 3.14f; - - public void Execute() - { - } } } """; @@ -1428,26 +1114,18 @@ public class DiagnosticsTests using double4x4 = ComputeSharp.Double4x4; using float4 = ComputeSharp.Float4; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public struct Double4x4 { } - public struct Float4 { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public readonly ReadWriteBuffer buffer; + public readonly double4x4 a; + public readonly double4x4 b; + public readonly int c; + public readonly float4 d; + + public void Execute() { - public readonly ReadWriteBuffer buffer; - public readonly double4x4 a; - public readonly double4x4 b; - public readonly int c; - public readonly float4 d; - - public void Execute() - { - } } } """; @@ -1461,19 +1139,12 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public interface IComputeShader { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader, IComputeShader { - public struct MyShader : IComputeShader, IComputeShader + public void Execute() { - public void Execute() - { - } } } """; @@ -1494,26 +1165,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(int threadsX, int threadsY, int threadsZ) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode({{threadsX}}, {{threadsY}}, {{threadsZ}})] + public struct MyShader : IComputeShader { - [EmbeddedBytecode({{threadsX}}, {{threadsY}}, {{threadsZ}})] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1528,27 +1188,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public enum DispatchAxis { X, Y, Z, XY, XZ, YZ, XYZ } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode(DispatchAxis.XYZ | DispatchAxis.Y)] + public struct MyShader : IComputeShader { - [EmbeddedBytecode(DispatchAxis.XYZ | DispatchAxis.Y)] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1563,27 +1211,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public enum DispatchAxis { X, Y, Z, XY, XZ, YZ, XYZ } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode((DispatchAxis)243712)] + public struct MyShader : IComputeShader { - [EmbeddedBytecode((DispatchAxis)243712)] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1598,27 +1234,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public enum DispatchAxis { X, Y, Z, XY, XZ, YZ, XYZ } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode((DispatchAxis)(-289))] + public struct MyShader : IComputeShader { - [EmbeddedBytecode((DispatchAxis)(-289))] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1633,21 +1257,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public readonly ReadWriteBuffer buffer; + + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - buffer[0] = Convert.ToSingle(42); - } + buffer[0] = Convert.ToSingle(42); } } """; @@ -1662,21 +1280,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public readonly ReadWriteBuffer buffer; + + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - buffer[0] = (byte)42; - } + buffer[0] = (byte)42; } } """; @@ -1691,27 +1303,21 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct Foo { - public class ReadWriteBuffer { } + public DateTime bar; } - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct Foo - { - public DateTime bar; - } + public readonly ReadWriteBuffer buffer; - public struct MyShader : IComputeShader + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - Foo foo = default; - buffer[0] = 42; - } + Foo foo = default; + buffer[0] = 42; } } """; @@ -1726,25 +1332,19 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct Foo { - public class ReadWriteBuffer { } + public bool bar; } - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct Foo - { - public bool bar; - } + public readonly ReadWriteBuffer buffer; - public struct MyShader : IComputeShader + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - } } } """; @@ -1761,8 +1361,11 @@ public class DiagnosticsTests private static void VerifyGeneratedDiagnostics(string source, params string[] diagnosticsIds) where TGenerator : class, IIncrementalGenerator, new() { - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); + // Ensure ComputeSharp.Core and ComputeSharp are loaded + Type hlslType = typeof(Hlsl); + Type computeShaderType = typeof(IComputeShader); + // Get all assembly references for the loaded assemblies (easy way to pull in all necessary dependencies) IEnumerable references = from assembly in AppDomain.CurrentDomain.GetAssemblies() where !assembly.IsDynamic @@ -1771,7 +1374,7 @@ public class DiagnosticsTests CSharpCompilation compilation = CSharpCompilation.Create( "original", - new SyntaxTree[] { syntaxTree }, + new SyntaxTree[] { CSharpSyntaxTree.ParseText(source) }, references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)); @@ -1784,5 +1387,17 @@ public class DiagnosticsTests HashSet resultingIds = diagnostics.Select(diagnostic => diagnostic.Id).ToHashSet(); Assert.IsTrue(resultingIds.SetEquals(diagnosticsIds)); + + // If the compilation was supposed to succeed, ensure that no further errors were generated + if (diagnosticsIds.Length == 0) + { + // Compute diagnostics for the final compiled output (just include errors) + List outputCompilationDiagnostics = outputCompilation.GetDiagnostics().Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error).ToList(); + + Assert.IsTrue(outputCompilationDiagnostics.Count == 0, $"resultingIds: {string.Join(", ", outputCompilationDiagnostics)}"); + } + + GC.KeepAlive(hlslType); + GC.KeepAlive(computeShaderType); } } \ No newline at end of file