diff --git a/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs b/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs
index 5bdaa721..9a2f8fb9 100644
--- a/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs
+++ b/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs
@@ -80,31 +80,29 @@ internal static partial class BlasHelpers
///
/// Kernel for .
///
- [AutoConstructor]
[ThreadGroupSize(DefaultThreadGroupSizes.XYZ)]
[GeneratedComputeShaderDescriptor]
- public readonly partial struct FullyConnectedForwardKernel : IComputeShader
+ public readonly partial struct FullyConnectedForwardKernel(
+ int n,
+ int m,
+ int p,
+ ReadOnlyBuffer x,
+ ReadOnlyBuffer w,
+ ReadOnlyBuffer b,
+ ReadWriteBuffer y) : IComputeShader
{
- private readonly int n;
- private readonly int m;
- private readonly int p;
- private readonly ReadOnlyBuffer x;
- private readonly ReadOnlyBuffer w;
- private readonly ReadOnlyBuffer b;
- private readonly ReadWriteBuffer y;
-
///
public void Execute()
{
- int x_offset = (ThreadIds.X * this.n * this.p) + (ThreadIds.Y * this.m);
+ int x_offset = (ThreadIds.X * n * p) + (ThreadIds.Y * m);
float result = 0f;
- for (int k = 0; k < this.m; k++)
+ for (int k = 0; k < m; k++)
{
- result += this.x[x_offset + k] * this.w[(k * this.p) + ThreadIds.Z];
+ result += x[x_offset + k] * w[(k * p) + ThreadIds.Z];
}
- this.y[(ThreadIds.X * this.n * this.p) + (ThreadIds.Y * this.p) + ThreadIds.Z] = result + this.b[ThreadIds.Z];
+ y[(ThreadIds.X * n * p) + (ThreadIds.Y * p) + ThreadIds.Z] = result + b[ThreadIds.Z];
}
}
}
\ No newline at end of file
diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs
index 929f7c45..ed3798bc 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs
+++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs
@@ -6,6 +6,7 @@ using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
+using ComputeSharp.SourceGeneration.SyntaxProcessors;
using ComputeSharp.SourceGeneration.SyntaxRewriters;
using ComputeSharp.SourceGenerators.SyntaxRewriters;
using Microsoft.CodeAnalysis;
@@ -122,9 +123,16 @@ partial class ComputeShaderDescriptorGenerator
bool hlslResourceFound = false;
- foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType())
+ foreach (ISymbol memberSymbol in structDeclarationSymbol.GetMembers())
{
- if (fieldSymbol.IsStatic)
+ // Skip constants and static fields, we only care about instance ones here
+ if (memberSymbol is not IFieldSymbol { IsConst: false, IsStatic: false } fieldSymbol)
+ {
+ continue;
+ }
+
+ // Try to get the actual field name
+ if (!ConstantBufferSyntaxProcessor.TryGetFieldAccessorName(fieldSymbol, out string? fieldName, out _))
{
continue;
}
@@ -134,13 +142,13 @@ partial class ComputeShaderDescriptorGenerator
// Group shared fields must be static
if (attribute is not null)
{
- diagnostics.Add(InvalidGroupSharedFieldDeclaration, fieldSymbol, structDeclarationSymbol, fieldSymbol.Name);
+ diagnostics.Add(InvalidGroupSharedFieldDeclaration, fieldSymbol, structDeclarationSymbol, fieldName);
}
// Captured fields must be named type symbols
if (fieldSymbol.Type is not INamedTypeSymbol typeSymbol)
{
- diagnostics.Add(InvalidShaderField, fieldSymbol, structDeclarationSymbol, fieldSymbol.Name, fieldSymbol.Type);
+ diagnostics.Add(InvalidShaderField, fieldSymbol, structDeclarationSymbol, fieldName, fieldSymbol.Type);
continue;
}
@@ -148,7 +156,7 @@ partial class ComputeShaderDescriptorGenerator
string metadataName = typeSymbol.GetFullyQualifiedMetadataName();
string typeName = HlslKnownTypes.GetMappedName(typeSymbol);
- _ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping);
+ _ = HlslKnownKeywords.TryGetMappedName(fieldName, out string? mapping);
// Allowed fields must be either resources, unmanaged values or delegates
if (HlslKnownTypes.IsTypedResourceType(metadataName))
@@ -162,13 +170,13 @@ partial class ComputeShaderDescriptorGenerator
}
// Add the current mapping for the name (if the name used a reserved keyword)
- resources.Add((metadataName, mapping ?? fieldSymbol.Name, typeName));
+ resources.Add((metadataName, mapping ?? fieldName, typeName));
}
else if (!typeSymbol.IsUnmanagedType &&
typeSymbol.TypeKind != TypeKind.Delegate)
{
// Shaders can only capture valid HLSL resource types or unmanaged types
- diagnostics.Add(InvalidShaderField, fieldSymbol, structDeclarationSymbol, fieldSymbol.Name, typeSymbol);
+ diagnostics.Add(InvalidShaderField, fieldSymbol, structDeclarationSymbol, fieldName, typeSymbol);
continue;
}
@@ -180,7 +188,7 @@ partial class ComputeShaderDescriptorGenerator
types.Add(typeSymbol);
}
- values.Add((mapping ?? fieldSymbol.Name, typeName));
+ values.Add((mapping ?? fieldName, typeName));
}
}