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))
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする