public override void Read(AssetReader reader) { if (IsSerialized(reader.Version)) { ReadNamedObject(reader); ParsedForm.Read(reader); Platforms = reader.ReadArray((t) => (GPUPlatform)t); if (IsDoubleArray(reader.Version)) { uint[][] offsets = reader.ReadUInt32ArrayArray(); uint[][] compressedLengths = reader.ReadUInt32ArrayArray(); uint[][] decompressedLengths = reader.ReadUInt32ArrayArray(); byte[] compressedBlob = reader.ReadByteArray(); reader.AlignStream(); UnpackSubProgramBlobs(reader.Layout, offsets, compressedLengths, decompressedLengths, compressedBlob); } else { uint[] offsets = reader.ReadUInt32Array(); uint[] compressedLengths = reader.ReadUInt32Array(); uint[] decompressedLengths = reader.ReadUInt32Array(); byte[] compressedBlob = reader.ReadByteArray(); reader.AlignStream(); UnpackSubProgramBlobs(reader.Layout, offsets, compressedLengths, decompressedLengths, compressedBlob); } } else { base.Read(reader); if (HasBlob(reader.Version)) { uint decompressedSize = reader.ReadUInt32(); byte[] compressedBlob = reader.ReadByteArray(); reader.AlignStream(); UnpackSubProgramBlobs(reader.Layout, 0, (uint)compressedBlob.Length, decompressedSize, compressedBlob); } if (HasFallback(reader.Version)) { Fallback.Read(reader); } if (HasDefaultProperties(reader.Version)) { DefaultProperties.Read(reader); } if (HasStaticProperties(reader.Version)) { StaticProperties.Read(reader); } } if (HasDependencies(reader.Version)) { Dependencies = reader.ReadAssetArray <PPtr <Shader> >(); } if (HasNonModifiableTextures(reader.Version)) { NonModifiableTextures = new Dictionary <string, PPtr <Texture> >(); NonModifiableTextures.Read(reader); } if (HasShaderIsBaked(reader.Version)) { ShaderIsBaked = reader.ReadBoolean(); reader.AlignStream(); } #if UNIVERSAL if (HasErrors(reader.Version, reader.Flags)) { Errors = reader.ReadAssetArray <ShaderError>(); } if (HasDefaultTextures(reader.Version, reader.Flags)) { DefaultTextures = new Dictionary <string, PPtr <Texture> >(); DefaultTextures.Read(reader); } if (HasCompileInfo(reader.Version, reader.Flags)) { CompileInfo.Read(reader); } #endif }
public override void Read(AssetReader reader) { if (IsSerialized(reader.Version)) { ReadNamedObject(reader); ParsedForm.Read(reader); Platforms = reader.ReadArray((t) => (GPUPlatform)t); uint[] offsets = reader.ReadUInt32Array(); uint[] compressedLengths = reader.ReadUInt32Array(); uint[] decompressedLengths = reader.ReadUInt32Array(); byte[] compressedBlob = reader.ReadByteArray(); reader.AlignStream(); SubProgramBlobs = new ShaderSubProgramBlob[Platforms.Length]; using (MemoryStream memStream = new MemoryStream(compressedBlob)) { for (int i = 0; i < Platforms.Length; i++) { uint offset = offsets[i]; uint compressedLength = compressedLengths[i]; uint decompressedLength = decompressedLengths[i]; memStream.Position = offset; byte[] decompressedBuffer = new byte[decompressedLength]; using (Lz4DecodeStream lz4Stream = new Lz4DecodeStream(memStream, (int)compressedLength)) { lz4Stream.ReadBuffer(decompressedBuffer, 0, decompressedBuffer.Length); } using (MemoryStream blobMem = new MemoryStream(decompressedBuffer)) { using (AssetReader blobReader = new AssetReader(blobMem, EndianType.LittleEndian, reader.Version, reader.Platform, reader.Flags)) { ShaderSubProgramBlob blob = new ShaderSubProgramBlob(); blob.Read(blobReader); SubProgramBlobs[i] = blob; } } } } } else { base.Read(reader); if (IsEncoded(reader.Version)) { uint decompressedSize = reader.ReadUInt32(); int comressedSize = reader.ReadInt32(); if (comressedSize > 0 && decompressedSize > 0) { byte[] subProgramBlob = new byte[comressedSize]; reader.ReadBuffer(subProgramBlob, 0, comressedSize); byte[] decompressedBuffer = new byte[decompressedSize]; using (MemoryStream memStream = new MemoryStream(subProgramBlob)) { using (Lz4DecodeStream lz4Stream = new Lz4DecodeStream(memStream)) { lz4Stream.ReadBuffer(decompressedBuffer, 0, decompressedBuffer.Length); } } using (MemoryStream memStream = new MemoryStream(decompressedBuffer)) { using (AssetReader blobReader = new AssetReader(memStream, EndianType.LittleEndian, reader.Version, reader.Platform, reader.Flags)) { SubProgramBlob.Read(blobReader); } } } reader.AlignStream(); } if (HasFallback(reader.Version)) { Fallback.Read(reader); } if (HasDefaultProperties(reader.Version)) { DefaultProperties.Read(reader); } if (HasStaticProperties(reader.Version)) { StaticProperties.Read(reader); } } if (HasDependencies(reader.Version)) { Dependencies = reader.ReadAssetArray <PPtr <Shader> >(); } if (HasNonModifiableTextures(reader.Version)) { NonModifiableTextures = new Dictionary <string, PPtr <Texture> >(); NonModifiableTextures.Read(reader); } if (HasShaderIsBaked(reader.Version)) { ShaderIsBaked = reader.ReadBoolean(); reader.AlignStream(); } #if UNIVERSAL if (HasErrors(reader.Version, reader.Flags)) { Errors = reader.ReadAssetArray <ShaderError>(); } if (HasDefaultTextures(reader.Version, reader.Flags)) { DefaultTextures = new Dictionary <string, PPtr <Texture> >(); DefaultTextures.Read(reader); } if (HasCompileInfo(reader.Version, reader.Flags)) { CompileInfo.Read(reader); } #endif }