Implemented initial dispatch data loader SG logic

このコミットが含まれているのは:
Sergio Pedri committed 2020-12-29 23:54:05 +01:00
1 親 29e2931a8a
コミット 2b2ec28597
4ファイル変更
+56 -5

検索条件に一致するファイルはありません

+30 -2
ファイルの表示
@@ -2,6 +2,7 @@
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using ComputeSharp.SourceGenerators.Extensions;
using ComputeSharp.SourceGenerators.Mappings;
@@ -39,8 +40,34 @@ namespace ComputeSharp.SourceGenerators
if (!structDeclarationSymbol.Interfaces.Any(static interfaceSymbol => interfaceSymbol.Name == nameof(IComputeShader))) continue;
TypeSyntax shaderType = ParseTypeName(structDeclarationSymbol.ToDisplayString());
BlockSyntax block = Block();
int
resourceOffset = 0,
rawDataOffset = 0;
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
{
INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type;
string typeName = typeSymbol.GetFullMetadataName();
if (HlslKnownTypes.IsTypedResourceType(typeName))
{
block = block.AddStatements(ExpressionStatement(
AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
ParseExpression($"Unsafe.Add(ref r0, {resourceOffset++})"),
ParseExpression($"GraphicsResourceHelper.ValidateAndGetGpuDescriptorHandle(shader.{fieldSymbol.Name}, device)"))));
}
else if (HlslKnownTypes.IsScalarOrVectorType(typeName))
{
var info = HlslKnownSizes.GetTypeInfo(typeName);
block = block.AddStatements(ExpressionStatement(
ParseExpression($"Unsafe.WriteUnaligned(ref Unsafe.Add(ref r1, {rawDataOffset}), shader.{fieldSymbol.Name})")));
rawDataOffset += info.Size;
}
}
// Create a static method to create the combined hashcode for a given shader type.
// This code takes a block syntax and produces a compilation unit as follows:
@@ -63,7 +90,8 @@ namespace ComputeSharp.SourceGenerators
var source =
CompilationUnit().AddUsings(
UsingDirective(IdentifierName("System")),
UsingDirective(IdentifierName("System.ComponentModel"))).AddMembers(
UsingDirective(IdentifierName("System.ComponentModel")),
UsingDirective(IdentifierName("System.Runtime.CompilerServices"))).AddMembers(
NamespaceDeclaration(IdentifierName("ComputeSharp.__Internals")).AddMembers(
ClassDeclaration("DispatchDataLoader").AddModifiers(
Token(SyntaxKind.InternalKeyword),
-1
ファイルの表示
@@ -39,7 +39,6 @@ namespace ComputeSharp.SourceGenerators
if (!structDeclarationSymbol.Interfaces.Any(static interfaceSymbol => interfaceSymbol.Name == nameof(IComputeShader))) continue;
TypeSyntax shaderType = ParseTypeName(structDeclarationSymbol.ToDisplayString());
BlockSyntax block = Block();
// Process all the captured delegate types
+14 -2
ファイルの表示
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Numerics;
namespace ComputeSharp.SourceGenerators.Mappings
@@ -9,9 +10,9 @@ namespace ComputeSharp.SourceGenerators.Mappings
internal static class HlslKnownSizes
{
/// <summary>
/// Gets the mapping of supported known sizes to HLSL type names.
/// The mapping of supported known sizes to HLSL type names.
/// </summary>
public static IReadOnlyDictionary<string, (int Size, int Pack)> KnownSizes { get; } = new Dictionary<string, (int, int)>
private static IReadOnlyDictionary<string, (int, int)> KnownSizes = new Dictionary<string, (int, int)>
{
[typeof(bool).FullName] = (4, 4),
[typeof(int).FullName] = (4, 4),
@@ -43,5 +44,16 @@ namespace ComputeSharp.SourceGenerators.Mappings
[typeof(Double3).FullName] = (24, 8),
[typeof(Double3).FullName] = (32, 8)
};
/// <summary>
/// Gets the size and alignment info for a specified primitive type.
/// </summary>
/// <param name="typeName">The type name to get info for.</param>
/// <returns>The size and and alignment for the input type.</returns>
[Pure]
public static (int Size, int Pack) GetTypeInfo(string typeName)
{
return KnownSizes[typeName];
}
}
}
+12
ファイルの表示
@@ -78,6 +78,18 @@ namespace ComputeSharp.SourceGenerators.Mappings
};
}
/// <summary>
/// Checks whether or not a given type name matches a typed resource type.
/// </summary>
/// <param name="typeName">The input type name to check.</param>
/// <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;
}
/// <summary>
/// Gets the mapped HLSL-compatible type name for the input type symbol.
/// </summary>