From f941d710b82e09b17273bcf79a1488440a5429e8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 7 Jan 2024 21:05:40 +0100 Subject: [PATCH] Add ExcedeedPixelShaderDispatchDataSizeAnalyzer tests --- ...ixelShaderDescriptorGenerator_Analyzers.cs | 1 - .../Test_ComputeShaderDescriptorGenerator.cs | 1 + ...puteShaderDescriptorGenerator_Analyzers.cs | 156 ++++++++++++++++++ ...teShaderDescriptorGenerator_Diagnostics.cs | 28 ---- 4 files changed, 157 insertions(+), 29 deletions(-) diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs index c834aab6..31ea0031 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs @@ -722,7 +722,6 @@ public class Test_D2DPixelShaderDescriptorGenerator_Analyzers public float s0; } - [D2DInputCount(0)] internal readonly partial struct {|CMPSD2D0032:MyType|}(Data4 data4) : ID2D1PixelShader { diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs index 4d69b6e3..3ef2ed33 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs @@ -863,6 +863,7 @@ public class Test_ComputeShaderDescriptorGenerator /// The task for the operation. private static async Task VerifyGeneratedDiagnosticsAsync(string source, (string Filename, string Source) result) { + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Analyzers.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Analyzers.cs index 26a029a9..4ead59b9 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Analyzers.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Analyzers.cs @@ -545,4 +545,160 @@ public class Test_ComputeShaderDescriptorGenerator_Analyzers await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } + + [TestMethod] + public async Task ExceededDispatchDataSize_ConstantBufferTooLarge_WithNestedTypes_Warns() + { + const string source = """ + using ComputeSharp; + using float1x3 = ComputeSharp.Float1x3; + using float2x2 = ComputeSharp.Float2x2; + using float3x2 = ComputeSharp.Float3x2; + using float4x4 = ComputeSharp.Float4x4; + using float2 = ComputeSharp.Float2; + using float3 = ComputeSharp.Float3; + using float4 = ComputeSharp.Float4; + + public struct Data0 + { + public float4x4 m0; + public float4 v0; + public float4 v1; + public float s0; + public float s1; + public float s2; + public float s3; + } + + public struct Data1 + { + public Data0 d0; + public Data0 d1; + public Data0 d2; + public Data0 d3; + public Data0 d4; + public float3x2 m0; + public float2x2 m1; + public float3 v0; + public float s0; + public float s1; + } + + public struct Data2 + { + public Data1 d0; + public Data1 d1; + public Data1 d2; + public Data1 d3; + public float2x2 m0; + public float1x3 m1; + public float3 v0; + public float4 v1; + public float2 v2; + public float s0; + } + + internal partial struct {|CMPS0041:MyType|}(Data2 data2) : IComputeShader + { + ReadWriteBuffer result; + + public void Execute() + { + result[ThreadIds.X] = data2.s0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task ExceededDispatchDataSize_ConstantBufferTooLarge_WithDoubles_Warns() + { + const string source = """ + using ComputeSharp; + using double4x4 = ComputeSharp.Double4x4; + using float4 = ComputeSharp.Float4; + + internal partial struct {|CMPS0041:MyType|} : IComputeShader + { + public readonly ReadWriteBuffer buffer; + public readonly double4x4 a; + public readonly double4x4 b; + public readonly int c; + public readonly float4 d; + + public void Execute() + { + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task ExceededDispatchDataSize_ConstantBufferTooLarge_WithManyResources_Warns() + { + const string source = """ + using ComputeSharp; + using float4x4 = ComputeSharp.Float4x4; + using float4 = ComputeSharp.Float4; + + public struct Data0 + { + public float4x4 m0; + public float4 v0; + public float4 v1; + public float4 v2; + public float s0; + public float s1; + public float s2; + public float s3; + } + + internal partial struct {|CMPS0041:MyType|}(Data0 data0) : IComputeShader + { + ReadWriteBuffer result0; + ReadWriteBuffer result1; + ReadWriteBuffer result2; + ReadWriteBuffer result3; + ReadWriteBuffer result4; + ReadWriteBuffer result5; + ReadWriteBuffer result6; + ReadWriteBuffer result7; + ReadWriteBuffer result8; + ReadWriteBuffer result9; + ReadWriteBuffer result10; + ReadWriteBuffer result11; + ReadWriteBuffer result12; + ReadWriteBuffer result13; + ReadWriteBuffer result14; + ReadWriteBuffer result15; + ReadWriteBuffer result16; + ReadWriteBuffer result17; + ReadWriteBuffer result18; + ReadWriteBuffer result19; + ReadWriteBuffer result20; + ReadWriteBuffer result21; + ReadWriteBuffer result22; + ReadWriteBuffer result23; + ReadWriteBuffer result24; + ReadWriteBuffer result25; + ReadWriteBuffer result26; + ReadWriteBuffer result27; + ReadWriteBuffer result28; + ReadWriteBuffer result29; + ReadWriteBuffer result30; + ReadWriteBuffer result31; + + public void Execute() + { + result0[ThreadIds.X] = data0.s0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs index c09e2063..2f4a468d 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs @@ -1079,34 +1079,6 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040"); } - [TestMethod] - public void ShaderDispatchDataSizeExceeded() - { - const string source = """ - using ComputeSharp; - using double4x4 = ComputeSharp.Double4x4; - using float4 = ComputeSharp.Float4; - - namespace MyFancyApp.Sample; - - [GeneratedComputeShaderDescriptor] - public partial 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() - { - } - } - """; - - CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0041"); - } - [TestMethod] public void InvalidMethodCall() {