public DebugBytecodeContainer(DebugBytecodeReader reader)
        {
            try
            {
                Chunks = new List <DebugBytecodeChunk>();

                _reader = reader;
                var magicNumber = reader.PeakUint32();
                if (magicNumber == 0xFEFF2001)
                {
                    Chunks.Add(DebugEffectChunk.Parse(reader, (uint)reader.Count));
                    return;
                }
                Header = DebugBytecodeContainerHeader.Parse(reader);

                for (uint i = 0; i < Header.ChunkCount; i++)
                {
                    uint chunkOffset = reader.ReadUInt32("chunkOffset");
                    var  fourCC      = DebugUtil.ToReadable(reader.PeakUInt32At((int)chunkOffset).ToFourCcString());
                    var  chunkReader = reader.CopyAtOffset($"Chunk{fourCC}", reader, (int)chunkOffset);

                    var chunk = DebugBytecodeChunk.ParseChunk(chunkReader, this);
                    if (chunk != null)
                    {
                        Chunks.Add(chunk);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception = ex;
                Error     = ex.ToString();
            }
        }
        public static DebugBytecodeChunk ParseChunk(DebugBytecodeReader chunkReader, DebugBytecodeContainer container)
        {
            // Type of chunk this is.
            uint fourCc = BitConverter.ToUInt32(chunkReader.ReadBytes("fourCc", 4), 0);

            // Total length of the chunk in bytes.
            uint chunkSize = chunkReader.ReadUInt32("chunkSize");

            ChunkType chunkType;

            if (KnownChunkTypes.ContainsKey(fourCc))
            {
                chunkType = KnownChunkTypes[fourCc];
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "Chunk type '" + fourCc.ToFourCcString() + "' is not yet supported.");
                System.Diagnostics.Debug.WriteLine("Chunk type '" + fourCc.ToFourCcString() + "' is not yet supported.");
                return(null);
            }

            var chunkContentReader   = chunkReader.CopyAtCurrentPosition($"{fourCc.ToFourCcString()}", chunkReader, (int)chunkSize);
            DebugBytecodeChunk chunk = null;

            switch (chunkType)
            {
            case ChunkType.Ifce:
                chunk = DebugInterfacesChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Isgn:
            case ChunkType.Osgn:
            case ChunkType.Osg5:
            case ChunkType.Pcsg:
            case ChunkType.Isg1:
            case ChunkType.Osg1:
                chunk = DebugInputOutputSignatureChunk.Parse(chunkContentReader, chunkType,
                                                             container.ResourceDefinition?.Target?.ProgramType ??
                                                             (SlimShader.Chunks.Common.ProgramType) 100);
                break;

            case ChunkType.Rdef:
                chunk = DebugResourceDefinitionChunk.Parse(chunkContentReader);
                break;

            case ChunkType.Sdbg:
            case ChunkType.Spdb:
                //chunk = DebuggingChunk.Parse(chunkContentReader, chunkType, (int)chunkSize);
                break;

            case ChunkType.Sfi0:
                chunk = DebugSfi0Chunk.Parse(chunkContentReader, null, chunkSize);
                break;

            case ChunkType.Shdr:
            case ChunkType.Shex:
                chunk = DebugShaderProgramChunk.Parse(chunkContentReader);
                break;

            case ChunkType.Stat:
                chunk = DebugStatisticsChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Xnas:
            case ChunkType.Xnap:
            case ChunkType.Aon9:
                chunk = DebugLevel9ShaderChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Priv:
                break;

            case ChunkType.Libf:
                chunk = DebugLibfChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Libh:
                chunk = DebugLibHeaderChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Lfs0:
                chunk = DebugLibraryParameterSignatureChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Fx10:
                chunk = DebugEffectChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Ctab:
                chunk = DebugCtabChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Cli4:
                chunk = DebugCli4Chunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Fxlc:
                chunk = DebugFxlcChunk.Parse(chunkContentReader, chunkSize, container);
                break;
                //default:
                //	throw new ParseException("Invalid chunk type: " + chunkType);
            }
            if (chunk == null)
            {
                chunkReader.ReadBytes("UnknownChunk", (int)chunkSize);
                return(null);
            }
            chunk.Container = container;
            chunk.FourCc    = fourCc;
            chunk.ChunkSize = chunkSize;
            chunk.ChunkType = chunkType;

            return(chunk);
        }