diff --git a/Editor/ABI/ParamOrReturnType.cs b/Editor/ABI/ParamOrReturnType.cs index 7e933ec..9ee3737 100644 --- a/Editor/ABI/ParamOrReturnType.cs +++ b/Editor/ABI/ParamOrReturnType.cs @@ -35,5 +35,9 @@ namespace HybridCLR.Editor.ABI STRUCTURE_ALIGN2, STRUCTURE_ALIGN4, STRUCTURE_ALIGN8, + SPECIAL_STRUCTURE_ALIGN1, + SPECIAL_STRUCTURE_ALIGN2, + SPECIAL_STRUCTURE_ALIGN4, + SPECIAL_STRUCTURE_ALIGN8, } } diff --git a/Editor/ABI/TypeCreatorBase.cs b/Editor/ABI/TypeCreatorBase.cs index 9c98490..a5485ee 100644 --- a/Editor/ABI/TypeCreatorBase.cs +++ b/Editor/ABI/TypeCreatorBase.cs @@ -15,7 +15,7 @@ namespace HybridCLR.Editor.ABI public virtual bool IsSupportHFA => false; - public virtual bool IsSupportSingletonStruct => false; + public virtual bool IsSupportWebGLSpecialValueType => false; public TypeInfo GetNativeIntTypeInfo() => IsArch32 ? TypeInfo.s_i4 : TypeInfo.s_i8; @@ -249,6 +249,21 @@ namespace HybridCLR.Editor.ABI return true; } + public static bool IsWebGLSpeicalValueType(TypeSig type) + { + TypeDef typeDef = type.ToTypeDefOrRef().ResolveTypeDefThrow(); + if (typeDef.IsEnum) + { + return false; + } + var fields = typeDef.Fields;// typeDef.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + if (fields.Count == 0) + { + return true; + } + return fields.All(f => f.IsStatic); + } + protected static TypeInfo CreateGeneralValueType(TypeSig type, int size, int aligment) { System.Diagnostics.Debug.Assert(size % aligment == 0); @@ -276,10 +291,17 @@ namespace HybridCLR.Editor.ABI default: throw new NotSupportedException(); } } - //else if(IsSupportSingletonStruct && TryComputSingletonStruct(type, out var ssTypeInfo)) - //{ - // return CreateTypeInfo(ssTypeInfo.Type); - //} + if (IsSupportWebGLSpecialValueType && IsWebGLSpeicalValueType(type)) + { + switch (typeAligment) + { + case 1: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1, typeSize); + case 2: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2, typeSize); + case 4: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4, typeSize); + case 8: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8, typeSize); + default: throw new NotSupportedException(); + } + } else { // 64位下结构体内存对齐规则是一样的 diff --git a/Editor/ABI/TypeCreatorWebGL32.cs b/Editor/ABI/TypeCreatorWebGL32.cs index 0309acc..b4e18ec 100644 --- a/Editor/ABI/TypeCreatorWebGL32.cs +++ b/Editor/ABI/TypeCreatorWebGL32.cs @@ -19,7 +19,7 @@ namespace HybridCLR.Editor.ABI public override bool IsSupportHFA => false; - public override bool IsSupportSingletonStruct => true; + public override bool IsSupportWebGLSpecialValueType => true; protected override TypeInfo OptimizeSigType(TypeInfo type, bool returnType) diff --git a/Editor/ABI/TypeInfo.cs b/Editor/ABI/TypeInfo.cs index ebc6d38..647c9fc 100644 --- a/Editor/ABI/TypeInfo.cs +++ b/Editor/ABI/TypeInfo.cs @@ -90,6 +90,10 @@ namespace HybridCLR.Editor.ABI case ParamOrReturnType.STRUCTURE_ALIGN2: return "A" + Size; case ParamOrReturnType.STRUCTURE_ALIGN4: return "B" + Size; case ParamOrReturnType.STRUCTURE_ALIGN8: return "C" + Size; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1: return "X" + Size; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2: return "Y" + Size; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4: return "Z" + Size; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8: return "W" + Size; default: throw new NotSupportedException(PorType.ToString()); }; } @@ -121,6 +125,10 @@ namespace HybridCLR.Editor.ABI case ParamOrReturnType.STRUCTURE_ALIGN2: return $"ValueTypeSizeAlign2<{Size}>"; case ParamOrReturnType.STRUCTURE_ALIGN4: return $"ValueTypeSizeAlign4<{Size}>"; case ParamOrReturnType.STRUCTURE_ALIGN8: return $"ValueTypeSizeAlign8<{Size}>"; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1: return $"WebGLSpeicalValueType<{Size}>"; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2: return $"WebGLSpeicalValueTypeAlign2<{Size}>"; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4: return $"WebGLSpeicalValueTypeAlign4<{Size}>"; + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8: return $"WebGLSpeicalValueTypeAlign8<{Size}>"; default: throw new NotImplementedException(PorType.ToString()); }; } @@ -141,7 +149,12 @@ namespace HybridCLR.Editor.ABI case ParamOrReturnType.STRUCTURE_ALIGN1: case ParamOrReturnType.STRUCTURE_ALIGN2: case ParamOrReturnType.STRUCTURE_ALIGN4: - case ParamOrReturnType.STRUCTURE_ALIGN8: return (Size + 7) / 8; + case ParamOrReturnType.STRUCTURE_ALIGN8: + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1: + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2: + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4: + case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8: + return (Size + 7) / 8; default: { Debug.Assert(PorType < ParamOrReturnType.STRUCT_NOT_PASS_AS_VALUE); diff --git a/package.json b/package.json index c7f24c8..e0b71d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "2.0.3", + "version": "2.0.4", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",