Correctly generate accessors for nested/unaccessible fields
このコミットが含まれているのは:
1 親
99a0c2b8b6
コミット
2961612f47
15ファイル変更
+181
-109
検索条件に一致するファイルはありません
+5
-4
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Models;
|
||||
@@ -44,19 +45,19 @@ partial class ComputeShaderDescriptorGenerator
|
||||
// Read a boolean value and cast it to Bool first, which will apply the correct size expansion
|
||||
writer.WriteLine(
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<byte, global::ComputeSharp.Bool>(ref span[{primitive.Offset}]) = " +
|
||||
$"(global::ComputeSharp.Bool)shader.{string.Join(".", primitive.FieldPath)};");
|
||||
$"(global::ComputeSharp.Bool)shader.{string.Join(".", primitive.FieldPath.Select(static path => path.Name))};");
|
||||
break;
|
||||
case FieldInfo.Primitive primitive:
|
||||
|
||||
// Read a primitive value and serialize it into the target buffer
|
||||
writer.WriteLine(
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<byte, global::{primitive.TypeName}>(ref span[{primitive.Offset}]) = " +
|
||||
$"shader.{string.Join(".", primitive.FieldPath)};");
|
||||
$"shader.{string.Join(".", primitive.FieldPath.Select(static path => path.Name))};");
|
||||
break;
|
||||
|
||||
case FieldInfo.NonLinearMatrix matrix:
|
||||
string rowTypeName = $"global::ComputeSharp.{matrix.ElementName}{matrix.Columns}";
|
||||
string rowLocalName = $"__{string.Join("_", matrix.FieldPath)}__row0";
|
||||
string rowLocalName = $"__{string.Join("_", matrix.FieldPath.Select(static path => path.Name))}__row0";
|
||||
|
||||
// Declare a local to index into individual rows. This will generate:
|
||||
//
|
||||
@@ -64,7 +65,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
// ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in <FIELD_PATH>));
|
||||
writer.WriteLine(
|
||||
$"ref {rowTypeName} {rowLocalName} = ref global::System.Runtime.CompilerServices.Unsafe.As<global::{matrix.TypeName}, {rowTypeName}>(" +
|
||||
$"ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in shader.{string.Join(".", matrix.FieldPath)}));");
|
||||
$"ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in shader.{string.Join(".", matrix.FieldPath.Select(static path => path.Name))}));");
|
||||
|
||||
// Generate the loading code for each individual row, with proper alignment.
|
||||
// This will result in the following (assuming Float2x3 m):
|
||||
|
||||
+6
-5
@@ -43,7 +43,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
static void GetInfo(
|
||||
Compilation compilation,
|
||||
ITypeSymbol currentTypeSymbol,
|
||||
ImmutableArray<string> fieldPath,
|
||||
ImmutableArray<FieldPathPart> fieldPath,
|
||||
ref int resourceOffset,
|
||||
ref int rawDataOffset,
|
||||
ImmutableArrayBuilder<FieldInfo> fields,
|
||||
@@ -82,12 +82,13 @@ partial class ComputeShaderDescriptorGenerator
|
||||
}
|
||||
else if (HlslKnownTypes.IsKnownHlslType(typeName))
|
||||
{
|
||||
fields.Add(GetHlslKnownTypeFieldInfo(fieldPath.Add(fieldName), typeName, ref rawDataOffset));
|
||||
// TODO: share the logic and fix the field path parts (here they just always return accessible leaves for now)
|
||||
fields.Add(GetHlslKnownTypeFieldInfo(fieldPath.Add(new FieldPathPart.Leaf(fieldName, true)), typeName, ref rawDataOffset));
|
||||
}
|
||||
else if (fieldSymbol.Type.IsUnmanagedType)
|
||||
{
|
||||
// Custom struct type defined by the user
|
||||
GetInfo(compilation, fieldSymbol.Type, fieldPath.Add(fieldName), ref resourceOffset, ref rawDataOffset, fields, resources);
|
||||
GetInfo(compilation, fieldSymbol.Type, fieldPath.Add(new FieldPathPart.Leaf(fieldName, true)), ref resourceOffset, ref rawDataOffset, fields, resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +105,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
GetInfo(
|
||||
compilation,
|
||||
structDeclarationSymbol,
|
||||
ImmutableArray<string>.Empty,
|
||||
ImmutableArray<FieldPathPart>.Empty,
|
||||
ref resourceOffset,
|
||||
ref rawDataOffset,
|
||||
fieldBuilder,
|
||||
@@ -144,7 +145,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
/// <param name="typeName">The type name currently being read.</param>
|
||||
/// <param name="rawDataOffset">The current offset within the loaded data buffer.</param>
|
||||
private static FieldInfo GetHlslKnownTypeFieldInfo(
|
||||
ImmutableArray<string> fieldPath,
|
||||
ImmutableArray<FieldPathPart> fieldPath,
|
||||
string typeName,
|
||||
ref int rawDataOffset)
|
||||
{
|
||||
|
||||
+7
-7
@@ -50,13 +50,13 @@ partial class ComputeShaderDescriptorGenerator
|
||||
return;
|
||||
}
|
||||
|
||||
usingDirectives.Add("global::System");
|
||||
usingDirectives.Add("global::System.Buffers");
|
||||
usingDirectives.Add("global::System.CodeDom.Compiler");
|
||||
usingDirectives.Add("global::System.Diagnostics");
|
||||
usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
|
||||
usingDirectives.Add("global::System.Runtime.CompilerServices");
|
||||
usingDirectives.Add("global::System.Runtime.InteropServices");
|
||||
_ = usingDirectives.Add("global::System");
|
||||
_ = usingDirectives.Add("global::System.Buffers");
|
||||
_ = usingDirectives.Add("global::System.CodeDom.Compiler");
|
||||
_ = usingDirectives.Add("global::System.Diagnostics");
|
||||
_ = usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
|
||||
_ = usingDirectives.Add("global::System.Runtime.CompilerServices");
|
||||
_ = usingDirectives.Add("global::System.Runtime.InteropServices");
|
||||
|
||||
// Declare the HlslBytecodeMemoryManager custom memory manager type
|
||||
static void Callback(ShaderInfo info, IndentedTextWriter writer)
|
||||
|
||||
+4
-4
@@ -49,10 +49,10 @@ partial class ComputeShaderDescriptorGenerator
|
||||
return;
|
||||
}
|
||||
|
||||
usingDirectives.Add("global::System.CodeDom.Compiler");
|
||||
usingDirectives.Add("global::System.Diagnostics");
|
||||
usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
|
||||
usingDirectives.Add("global::ComputeSharp.Interop");
|
||||
_ = usingDirectives.Add("global::System.CodeDom.Compiler");
|
||||
_ = usingDirectives.Add("global::System.Diagnostics");
|
||||
_ = usingDirectives.Add("global::System.Diagnostics.CodeAnalysis");
|
||||
_ = usingDirectives.Add("global::ComputeSharp.Interop");
|
||||
|
||||
// Declare the additional data type and the shared array with resource descriptor ranges
|
||||
static void Callback(ShaderInfo info, IndentedTextWriter writer)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする