Switched ThreadIds to static type
このコミットが含まれているのは:
1 親
bbc8832023
コミット
c6aa194749
6ファイル変更
+73
-78
検索条件に一致するファイルはありません
@@ -171,18 +171,15 @@ namespace ComputeSharp.SourceGenerators
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods, constantDefinitions);
|
||||
|
||||
// Rewrite the method syntax tree
|
||||
var processedMethod = shaderSourceRewriter.Visit(methodDeclaration)!.WithoutTrivia();
|
||||
MethodDeclarationSyntax? processedMethod = shaderSourceRewriter.Visit(methodDeclaration)!.WithoutTrivia();
|
||||
|
||||
// If the method is the shader entry point, do additional processing
|
||||
if (methodDeclarationSymbol.Name == nameof(IComputeShader.Execute) &&
|
||||
methodDeclarationSymbol.ReturnsVoid &&
|
||||
methodDeclarationSymbol.TypeParameters.Length == 0 &&
|
||||
methodDeclarationSymbol.Parameters.Length == 1 &&
|
||||
methodDeclarationSymbol.Parameters[0].Type.ToDisplayString() == typeof(ThreadIds).FullName)
|
||||
methodDeclarationSymbol.Parameters.Length == 0)
|
||||
{
|
||||
var parameterName = methodDeclarationSymbol.Parameters[0].Name;
|
||||
|
||||
processedMethod = new ExecuteMethodRewriter(parameterName).Visit(processedMethod)!;
|
||||
processedMethod = new ExecuteMethodRewriter().Visit(processedMethod)!;
|
||||
|
||||
entryPoint = processedMethod.NormalizeWhitespace().ToFullString();
|
||||
}
|
||||
|
||||
@@ -190,6 +190,15 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"{item.Property.Name.ToLower()}");
|
||||
}
|
||||
|
||||
// Programmatically load mappings for the dispatch types
|
||||
foreach (var item in
|
||||
from type in HlslKnownTypes.HlslDispatchTypes
|
||||
from property in type.GetProperties(BindingFlags.Static | BindingFlags.Public)
|
||||
select (Type: type, Property: property))
|
||||
{
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"{item.Type.Name}.{item.Property.Name.ToLower()}");
|
||||
}
|
||||
|
||||
return knownMembers;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
[typeof(double).FullName] = "double",
|
||||
[typeof(Double2).FullName] = "double2",
|
||||
[typeof(Double3).FullName] = "double3",
|
||||
[typeof(Double4).FullName] = "double4",
|
||||
[typeof(ThreadIds).FullName] = "int3"
|
||||
[typeof(Double4).FullName] = "double4"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +49,6 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> HlslMappedVectorTypes { get; } = new[]
|
||||
{
|
||||
typeof(ThreadIds),
|
||||
typeof(Bool2), typeof(Bool3), typeof(Bool4),
|
||||
typeof(Int2), typeof(Int3), typeof(Int4),
|
||||
typeof(UInt2), typeof(UInt3), typeof(UInt4),
|
||||
@@ -58,6 +56,14 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
typeof(Double2), typeof(Double3), typeof(Double4)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the known HLSL dispatch types.
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> HlslDispatchTypes { get; } = new[]
|
||||
{
|
||||
typeof(ThreadIds)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a typed resource type.
|
||||
/// </summary>
|
||||
@@ -94,9 +100,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a typed resource type.</returns>
|
||||
public static bool IsScalarOrVectorType(string typeName)
|
||||
{
|
||||
return
|
||||
KnownTypes.ContainsKey(typeName) &&
|
||||
typeName != typeof(ThreadIds).FullName;
|
||||
return KnownTypes.ContainsKey(typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,20 +10,6 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
/// </summary>
|
||||
internal sealed class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
{
|
||||
/// <summary>
|
||||
/// The identifier name for the input <see langword="uint3"/> parameter.
|
||||
/// </summary>
|
||||
private readonly string threadIdsIdentifier;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ExecuteMethodRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="threadIdsIdentifier">The identifier name for the input <see langword="uint3"/> parameter.</param>
|
||||
public ExecuteMethodRewriter(string threadIdsIdentifier)
|
||||
{
|
||||
this.threadIdsIdentifier = threadIdsIdentifier;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public TNode? Visit<TNode>(TNode? node)
|
||||
where TNode : SyntaxNode
|
||||
@@ -32,11 +18,11 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitParameter(ParameterSyntax node)
|
||||
public override SyntaxNode? VisitParameterList(ParameterListSyntax node)
|
||||
{
|
||||
var updatedNode = (ParameterSyntax)base.VisitParameter(node)!;
|
||||
var updatedNode = (ParameterListSyntax)base.VisitParameterList(node)!;
|
||||
|
||||
return updatedNode.WithIdentifier(Identifier($"{updatedNode.Identifier.Text} : SV_DispatchThreadId"));
|
||||
return updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(ThreadIds)} : SV_DispatchThreadID")));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -48,9 +34,9 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
// check to ensure that invocation outside of the requested range are discarded.
|
||||
// The following snippet creates this prologue before the user provided body:
|
||||
//
|
||||
// if (ids.X < __x &&
|
||||
// ids.Y < __y &&
|
||||
// ids.Z < __z)
|
||||
// if (ThreadIds.x < __x &&
|
||||
// ThreadIds.y < __y &&
|
||||
// ThreadIds.z < __z)
|
||||
// {
|
||||
// <body>
|
||||
// }
|
||||
@@ -60,19 +46,19 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(this.threadIdsIdentifier),
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("x")),
|
||||
IdentifierName("__x")),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(this.threadIdsIdentifier),
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("y")),
|
||||
IdentifierName("__y"))),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(this.threadIdsIdentifier),
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("z")),
|
||||
IdentifierName("__z")));
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする