Add support for "this." field accesses
このコミットが含まれているのは:
1 親
ba0cb5c00f
コミット
a1ab03f48c
5ファイル変更
+52
-21
検索条件に一致するファイルはありません
-2
@@ -14,8 +14,6 @@
|
||||
<!-- Same setup as ComputeSharp.Core.SourceGenerators, just with also APIs from ComputeSharp -->
|
||||
<ItemGroup>
|
||||
|
||||
<!-- ComputeSharp.Core.SourceGenerator APIs -->
|
||||
|
||||
<!-- ComputeSharp.Core APIs -->
|
||||
<Compile Include="..\ComputeSharp.Core\Attributes\AutoConstructorAttribute.cs" Link="ComputeSharp.Core\Attributes\AutoConstructorAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Exceptions\InvalidExecutionContextException.cs" Link="ComputeSharp.Core\Exceptions\InvalidExecutionContextException.cs" />
|
||||
|
||||
+16
-8
@@ -222,17 +222,25 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
|
||||
{
|
||||
// If the member access is a constant, track it and replace the tree with the processed constant name
|
||||
if (operation is IFieldReferenceOperation fieldOperation &&
|
||||
fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
if (operation is IFieldReferenceOperation fieldOperation)
|
||||
{
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
// If the member access is a constant, track it and replace the tree with the processed constant name
|
||||
if (fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
{
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
// If the member access is a this.<FIELD> access, rewrite it to strip "this."
|
||||
if (node.Expression.IsKind(SyntaxKind.ThisExpression))
|
||||
{
|
||||
return node.Name;
|
||||
}
|
||||
}
|
||||
|
||||
// If the current member access is a field or property access, check the lookup table
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Shared project with .NET Standard 2.0 polyfills for Dxc -->
|
||||
<Import Condition="'$(TargetFramework)' == 'netstandard2.0'"
|
||||
Project="..\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems"
|
||||
Label="Shared" />
|
||||
<Import Condition="'$(TargetFramework)' == 'netstandard2.0'" Project="..\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems" Label="Shared" />
|
||||
|
||||
<Choose>
|
||||
|
||||
|
||||
@@ -254,17 +254,25 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
|
||||
{
|
||||
// If the member access is a constant, track it and replace the tree with the processed constant name
|
||||
if (operation is IFieldReferenceOperation fieldOperation &&
|
||||
fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
if (operation is IFieldReferenceOperation fieldOperation)
|
||||
{
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
// If the member access is a constant, track it and replace the tree with the processed constant name
|
||||
if (fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
{
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
// If the member access is a this.<FIELD> access, rewrite it to strip "this."
|
||||
if (node.Expression.IsKind(SyntaxKind.ThisExpression))
|
||||
{
|
||||
return node.Name;
|
||||
}
|
||||
}
|
||||
|
||||
// If the current member access is a field or property access, check the lookup table
|
||||
|
||||
@@ -214,6 +214,25 @@ namespace ComputeSharp.Tests
|
||||
buffer[ThreadIds.X] *= factor + 3.14;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FieldAccessWithThisExpression()
|
||||
{
|
||||
_ = ReflectionServices.GetShaderInfo<FieldAccessWithThisExpressionShader>();
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct FieldAccessWithThisExpressionShader : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
public readonly float number;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
this.buffer[ThreadIds.X] *= this.number;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする