Always generate unsafe accessors for all fields
このコミットが含まれているのは:
1 親
35a73051d7
コミット
531262e6f2
4ファイル変更
+14
-25
検索条件に一致するファイルはありません
+6
-13
@@ -265,19 +265,16 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
|
||||
using ImmutableHashSetBuilder<(string ContainerType, string FieldName)> generatedAccessors = new();
|
||||
|
||||
// Define all field accessors
|
||||
// Define all field accessors. Note that these are generated regardless of the accessibility
|
||||
// of the field they're getting the value for. This simplifies the rest of the code, and allows
|
||||
// stripping the readonly-ness of the field references, and has no binary size impact anyway.
|
||||
// This is because the fields are compiled to be exactly equivalent to direct field references.
|
||||
foreach (FieldInfo fieldInfo in info.Fields)
|
||||
{
|
||||
for (int i = 0; i < fieldInfo.FieldPath.Length; i++)
|
||||
{
|
||||
FieldPathPart pathPart = fieldInfo.FieldPath[i];
|
||||
|
||||
// Only generate field accessors for fields that are not accessible
|
||||
if (pathPart.IsAccessible)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the friendly type name for the field:
|
||||
// - If the part path is a nested struct, the type name is embedded
|
||||
// - Otherwise, get the correct HLSL mapped type name for the field
|
||||
@@ -330,14 +327,10 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
{
|
||||
string fieldExpression = "shader";
|
||||
|
||||
// Format the field access expression, there's two options:
|
||||
// - If the field is accessible, just access it directly
|
||||
// - If the field is not accessible, use the unsafe accessor
|
||||
// Invoke all generated field accessors to get to the target field
|
||||
foreach (FieldPathPart part in fieldInfo.FieldPath)
|
||||
{
|
||||
fieldExpression = part.IsAccessible
|
||||
? $"{fieldExpression}.{part.Name}"
|
||||
: $"{part.Name}(in {fieldExpression})";
|
||||
fieldExpression = $"{part.Name}(in {fieldExpression})";
|
||||
}
|
||||
|
||||
// Return a mutable ref if needed (the expression is always readonly here)
|
||||
|
||||
+2
-3
@@ -58,7 +58,6 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
|
||||
string fieldName = fieldSymbol.Name;
|
||||
string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName();
|
||||
bool isAccessible = fieldSymbol.IsAccessibleFromCompilationAssembly(compilation);
|
||||
|
||||
// The first item in each nested struct needs to be aligned to 16 bytes
|
||||
if (isFirstField && fieldPath.Length > 0)
|
||||
@@ -70,14 +69,14 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
|
||||
if (HlslKnownTypes.IsKnownHlslType(typeName))
|
||||
{
|
||||
ImmutableArray<FieldPathPart> nestedFieldPath = fieldPath.Add(new FieldPathPart.Leaf(fieldName, isAccessible));
|
||||
ImmutableArray<FieldPathPart> nestedFieldPath = fieldPath.Add(new FieldPathPart.Leaf(fieldName));
|
||||
|
||||
yield return GetHlslKnownTypeFieldInfo(nestedFieldPath, typeName, ref rawDataOffset.Value);
|
||||
}
|
||||
else if (fieldSymbol.Type.IsUnmanagedType)
|
||||
{
|
||||
string nestedTypeName = fieldSymbol.Type.GetFullyQualifiedName(includeGlobal: true);
|
||||
ImmutableArray<FieldPathPart> nestedFieldPath = fieldPath.Add(new FieldPathPart.Nested(fieldName, isAccessible, nestedTypeName));
|
||||
ImmutableArray<FieldPathPart> nestedFieldPath = fieldPath.Add(new FieldPathPart.Nested(fieldName, nestedTypeName));
|
||||
|
||||
// Custom struct type defined by the user
|
||||
foreach (FieldInfo fieldInfo in GetCapturedFieldInfos(compilation, fieldSymbol.Type, nestedFieldPath, rawDataOffset))
|
||||
|
||||
@@ -39,21 +39,18 @@ internal abstract record FieldInfo(EquatableArray<FieldPathPart> FieldPath, stri
|
||||
/// A model for a part of a field path, ie. the name of the immediate parent field, and whether it's accessible.
|
||||
/// </summary>
|
||||
/// <param name="Name">The name of the immediate parent field to access (or self).</param>
|
||||
/// <param name="IsAccessible">Whether the current path part is accessible from the compilation.</param>
|
||||
internal abstract record FieldPathPart(string Name, bool IsAccessible)
|
||||
internal abstract record FieldPathPart(string Name)
|
||||
{
|
||||
/// <summary>
|
||||
/// A model for a leaf part of a field path.
|
||||
/// </summary>
|
||||
/// <param name="Name"><inheritdoc cref="FieldPathPart(string, bool)" path="/param[@name='Name']/node()"/></param>
|
||||
/// <param name="IsAccessible"><inheritdoc cref="FieldPathPart(string, bool)" path="/param[@name='IsAccessible']/node()"/></param>
|
||||
public sealed record Leaf(string Name, bool IsAccessible) : FieldPathPart(Name, IsAccessible);
|
||||
public sealed record Leaf(string Name) : FieldPathPart(Name);
|
||||
|
||||
/// <summary>
|
||||
/// A model for a nested field part path (ie. going through a nested struct type).
|
||||
/// </summary>
|
||||
/// <param name="Name"><inheritdoc cref="FieldPathPart(string, bool)" path="/param[@name='Name']/node()"/></param>
|
||||
/// <param name="IsAccessible"><inheritdoc cref="FieldPathPart(string, bool)" path="/param[@name='IsAccessible']/node()"/></param>
|
||||
/// <param name="TypeName">The fully qualified type name of the containing type.</param>
|
||||
public sealed record Nested(string Name, bool IsAccessible, string TypeName) : FieldPathPart(Name, IsAccessible);
|
||||
public sealed record Nested(string Name, string TypeName) : FieldPathPart(Name);
|
||||
}
|
||||
+3
-3
@@ -82,13 +82,13 @@ partial class ComputeShaderDescriptorGenerator
|
||||
}
|
||||
else if (HlslKnownTypes.IsKnownHlslType(typeName))
|
||||
{
|
||||
// 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));
|
||||
// TODO: share the logic and fix the field path parts
|
||||
fields.Add(GetHlslKnownTypeFieldInfo(fieldPath.Add(new FieldPathPart.Leaf(fieldName)), typeName, ref rawDataOffset));
|
||||
}
|
||||
else if (fieldSymbol.Type.IsUnmanagedType)
|
||||
{
|
||||
// Custom struct type defined by the user
|
||||
GetInfo(compilation, fieldSymbol.Type, fieldPath.Add(new FieldPathPart.Leaf(fieldName, true)), ref resourceOffset, ref rawDataOffset, fields, resources);
|
||||
GetInfo(compilation, fieldSymbol.Type, fieldPath.Add(new FieldPathPart.Leaf(fieldName)), ref resourceOffset, ref rawDataOffset, fields, resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする