Skip to content

Commit

Permalink
Merge pull request #806 from Sergio0694/dev/constant-buffer-length
Browse files Browse the repository at this point in the history
Don't rewrite 'ConstantBuffer<T>.Length'
  • Loading branch information
Sergio0694 authored Jun 6, 2024
2 parents 908d691 + 94a1f85 commit bb861f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@ public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyn
if (!this.staticMethods.TryGetValue(key, out MethodDeclarationSyntax? methodSyntax))
{
INamedTypeSymbol resourceType = (INamedTypeSymbol)SemanticModel.For(node).GetTypeInfo(node.Expression, CancellationToken).Type!;

// Explicitly ignore 'ConstantBuffer<T>.Length', as that is not valid in HLSL.
// The type should just be reworked entirely at some point, but not today.
if (resourceType.Name == "ConstantBuffer")
{
return updatedNode;
}

string resourceName = HlslKnownTypes.GetMappedName(resourceType);

// Create a static method to get a specified dimension for a target resource type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ private static partial Dictionary<string, string> BuildKnownResourceIndexers()
/// <inheritdoc/>
private static partial Dictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors()
{
// For 'Buffer`1', which is used by the '[RW]StructuredBuffer<T>' types in HLSL, the rank is
// 2 because 'GetDimensions' still has two parameters, even if the actual rank of the array
// is just 1. That is because the length is the first output, and the second is the stride.
// The latter will always be ignored by the generated code.
return new()
{
["ComputeSharp.Resources.Buffer`1.Length"] = (2, 0),
Expand Down

0 comments on commit bb861f7

Please sign in to comment.