diff --git a/samples/ComputeSharp.Sample.Shared/Program.cs b/samples/ComputeSharp.Sample.Shared/Program.cs index a4e38ca1..ee01f2a1 100644 --- a/samples/ComputeSharp.Sample.Shared/Program.cs +++ b/samples/ComputeSharp.Sample.Shared/Program.cs @@ -21,7 +21,7 @@ namespace ComputeSharp.Sample using ReadWriteBuffer gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array); // Run the shader - Gpu.Default.For(100, new MainKernel()); + Gpu.Default.For(100, new MainKernel(gpuBuffer)); // Print the initial matrix PrintMatrix(array, width, height, "BEFORE"); @@ -41,9 +41,6 @@ namespace ComputeSharp.Sample { public readonly ReadWriteBuffer buffer; - [GroupShared] - public static string[] Foo; - /// public void Execute() { diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs index aba966b1..db8e5ccd 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs @@ -95,6 +95,8 @@ namespace ComputeSharp.SourceGenerators { foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType()) { + if (fieldSymbol.IsStatic) continue; + // Captured fields must be named type symbols if (fieldSymbol.Type is not INamedTypeSymbol typeSymbol) { @@ -106,15 +108,6 @@ namespace ComputeSharp.SourceGenerators continue; } - if (fieldSymbol.IsStatic) continue; - - string typeName = HlslKnownTypes.GetMappedName(typeSymbol); - - _ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping); - - // Yield back the current mapping for the name (if the name used a reserved keyword) - yield return new[] { fieldSymbol.Name, mapping ?? fieldSymbol.Name, typeName }; - // Track the type of items in the current buffer if (HlslKnownTypes.IsTypedResourceType(typeSymbol.GetFullMetadataName()) && typeSymbol.TypeArguments.Length == 1) @@ -129,6 +122,13 @@ namespace ComputeSharp.SourceGenerators fieldSymbol.Locations.FirstOrDefault(), structDeclarationSymbol, fieldSymbol.Name, typeSymbol)); } + + string typeName = HlslKnownTypes.GetMappedName(typeSymbol); + + _ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping); + + // Yield back the current mapping for the name (if the name used a reserved keyword) + yield return new[] { fieldSymbol.Name, mapping ?? fieldSymbol.Name, typeName }; } } @@ -163,7 +163,7 @@ namespace ComputeSharp.SourceGenerators continue; } - if (typeSymbol.ElementType.IsUnmanagedType) + if (!typeSymbol.ElementType.IsUnmanagedType) { context.ReportDiagnostic(Diagnostic.Create( DiagnosticDescriptors.InvalidGroupSharedFieldElementType, diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs index c6716afd..17e9e6bb 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -195,7 +195,7 @@ namespace ComputeSharp.SourceGenerators.Mappings { if (KnownTypes.ContainsKey(type.GetFullMetadataName())) return; - customTypes.Add(type); + if (!customTypes.Add(type)) return; foreach (var field in type.GetMembers().OfType()) {