public override void Load(ChunkMeta meta, BinaryReader br) { base.Load(meta, br); Descriptor = D3D11Reader.Read_D3D11_BUFFER_DESC(br) as D3D11_BUFFER_DESC; // Descriptor pInitialData = D3D11Reader.Read_D3D11_Nullable <D3D11_SUBRESOURCE_DATA>(br); // pInitialData resourceId = br.ReadUInt64(); // pBuffer int dataOffset; int count; D3D11Reader.Read_BytesArray(br, out dataOffset, out count, true); ulong InitialDataLength = br.ReadUInt64(); Debug.Assert((int)InitialDataLength == count); data = new D3D11_SUBRESOURCE_DATA(); data.pSysMem = null; data.SysMemPitch = Descriptor.ByteWidth; data.SysMemSlicePitch = Descriptor.ByteWidth; data.sysMemDataOffset = dataOffset; data.sysMemLength = count; }
public override void Load(ChunkMeta meta, BinaryReader br) { base.Load(meta, br); type = (D3D11ResourceType)br.ReadUInt32(); parentId = br.ReadUInt64(); // id // RenderDoc 可以保证对应的资源已创建 D3D11_TEXTURE2D_DESC desc; var createChunk = chunkManager.GetResourceChunk(parentId); if (createChunk == null) { Console.WriteLine($"unsupported resouce on [Chunk_InitialContents] with id {parentId}"); return; // 尚未支持的资源类型 } else { if (createChunk is Chunk_CreateTexture2D) { desc = (createChunk as Chunk_CreateTexture2D).Descriptor; } else if (createChunk is Chunk_CreateSwapBuffer) { desc = (createChunk as Chunk_CreateSwapBuffer).BackbufferDescriptor; } else { throw new Exception($"unknown resource type {createChunk.GetType().Name}"); } } if (type == D3D11ResourceType.Resource_UnorderedAccessView) { // TODO } else if (type == D3D11ResourceType.Resource_Buffer) { // TODO } else if (type == D3D11ResourceType.Resource_Texture1D) { // TODO } else if (type == D3D11ResourceType.Resource_Texture2D) { uint NumSubresources = desc.MipLevels * desc.ArraySize; bool multisampled = desc.SampleDesc.Count > 1 || desc.SampleDesc.Quality > 0; if (multisampled) { NumSubresources *= desc.SampleDesc.Count; } uint numReaded = br.ReadUInt32(); Debug.Assert(NumSubresources == numReaded); NumSubresources = numReaded; bool OmittedContents = br.ReadBoolean(); // for compatibility if (OmittedContents) { return; } subDatas = new D3D11_SUBRESOURCE_DATA[NumSubresources]; for (int i = 0; i < NumSubresources; i++) { // 数据格式与 CreteTexture2D 时的SubResource不同,原因不明, 可能是历史遗留问题? uint numRows = Math.Max(1, desc.Height >> i); if (Common.IsBlockFormat(desc.Format)) { numRows = Common.AlignUp4(numRows) / 4; } else if (Common.IsYUVPlanarFormat(desc.Format)) { numRows = Common.GetYUVNumRows(desc.Format, desc.Height); } subDatas[i] = new D3D11_SUBRESOURCE_DATA(); subDatas[i].SysMemPitch = br.ReadUInt32(); subDatas[i].SysMemSlicePitch = subDatas[i].SysMemPitch * numRows; subDatas[i].pSysMem = D3D11Reader.Read_BytesArray(br, out subDatas[i].sysMemDataOffset, out subDatas[i].sysMemLength, true); } } }