public static DebugBytecodeContainer Parse(byte[] bytes)
        {
            var result = new DebugBytecodeContainer(bytes);

            result._rawBytes = bytes;
            return(result);
        }
        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.");
                var unknownChunkReader = chunkReader.CopyAtCurrentPosition($"{fourCc.ToFourCcString()}", chunkReader, (int)chunkSize);
                unknownChunkReader.ReadBytes("UnknownChunk", (int)chunkSize);
                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 ??
                                                             (DXDecompiler.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:
                try
                {
                    chunk = DebugStatisticsChunk.Parse(chunkContentReader, chunkSize);
                }
                catch (ParseException ex)
                {
                    return(null);
                }
                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;

            case ChunkType.Dxil:
                chunk = DebugDxilChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Psv0:
                chunk = DebugPipelineStateValidationChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Ildn:
                chunk = DebugDebugNameChunk.Parse(chunkContentReader, chunkSize);
                break;

            case ChunkType.Ildb:
                chunk = DebugDebugInfoDXILChunk.Parse(chunkContentReader, chunkSize);
                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);
        }