Esempio n. 1
0
        public static DebugStateBlob Parse(DebugBytecodeReader reader, DebugBytecodeReader blobReader)
        {
            var result = new DebugStateBlob();

            result.TechniqueIndex    = blobReader.ReadUInt32("TechniqueIndex");
            result.PassIndex         = blobReader.ReadUInt32("PassIndex");
            result.SamplerStateIndex = blobReader.ReadUInt32("SamplerStateIndex");
            result.AssignmentIndex   = blobReader.ReadUInt32("AssignmentIndex");
            result.BlobType          = blobReader.ReadEnum32 <StateBlobType>("BlobType");
            if (result.BlobType == StateBlobType.Shader)
            {
                result.ShaderSize = blobReader.ReadUInt32("BlobSize");
                var startPosition = blobReader._reader.BaseStream.Position;
                var shaderReader  = blobReader.CopyAtCurrentPosition("ShaderReader", blobReader);
                result.Shader = DebugShaderModel.Parse(shaderReader);
                blobReader._reader.BaseStream.Position = startPosition + result.ShaderSize;
            }
            if (result.BlobType == StateBlobType.Variable)
            {
                result.VariableName = blobReader.TryReadString("VariableName");
            }
            else if (result.BlobType == StateBlobType.IndexShader)
            {
                result.ShaderSize = blobReader.ReadUInt32("BlobSize");
                var startPosition = blobReader._reader.BaseStream.Position;
                var variableSize  = blobReader.ReadUInt32("VariableNameSize");
                var variableData  = blobReader.ReadBytes("VariableData", (int)variableSize);
                result.VariableName = Encoding.UTF8.GetString(variableData, 0, variableData.Length - 1);
                var shaderReader = blobReader.CopyAtCurrentPosition("ShaderReader", blobReader);
                result.Shader = DebugShaderModel.Parse(shaderReader);
                blobReader._reader.BaseStream.Position = startPosition + result.ShaderSize;
            }
            return(result);
        }
        } = new byte[4];                                                                 // Array for GS Stream Out Index

        public static DebugPipelineStateValidationChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var result = new DebugPipelineStateValidationChunk();

            result.Reader = reader.CopyAtCurrentPosition("DebugPipelineStateValidationChunk", reader);
            return(result);
        }
Esempio n. 3
0
        public static DebugConstantTable Parse(DebugBytecodeReader reader)
        {
            var result = new DebugConstantTable();

            var ctabReader         = reader.CopyAtCurrentPosition("CTabReader", reader);
            var ctabSize           = ctabReader.ReadUInt32("CtabSize");
            var creatorOffset      = ctabReader.ReadInt32("CreatorPosition");
            var minorVersion       = ctabReader.ReadByte("MinorVersion");
            var majorVersion       = ctabReader.ReadByte("MajorVersion");
            var shaderType         = ctabReader.ReadEnum16 <ShaderType>("ShaderType");
            var numConstants       = ctabReader.ReadInt32("NumConstants");
            var constantInfoOffset = ctabReader.ReadInt32("ConstantInfoOffset");
            var shaderFlags        = ctabReader.ReadEnum32 <ShaderFlags>("ShaderFlags");
            var shaderModelOffset  = ctabReader.ReadInt32("ShaderModelOffset");

            for (int i = 0; i < numConstants; i++)
            {
                var decReader = ctabReader.CopyAtOffset($"Declaration {i}", ctabReader, constantInfoOffset + i * 20);
                DebugConstantDeclaration declaration = DebugConstantDeclaration.Parse(ctabReader, decReader);
                result.ConstantDeclarations.Add(declaration);
            }

            var shaderModelReader = ctabReader.CopyAtOffset("ShaderModelReader", ctabReader, shaderModelOffset);
            var shaderModel       = shaderModelReader.ReadString("ShaderModel");

            var creatorReader = ctabReader.CopyAtOffset("CreaterReader", ctabReader, creatorOffset);
            var creatorString = creatorReader.ReadString("CreatorString");

            return(result);
        }
        public static DebugLibHeaderChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var chunkReader         = reader.CopyAtCurrentPosition("chunkReader", reader);
            var result              = new DebugLibHeaderChunk();
            var unknown1            = chunkReader.ReadUInt32("LibHeader.Unknown1");
            var creatorStringOffset = chunkReader.ReadUInt32("CreatorStringOffset");

            result.Flags = chunkReader.ReadUInt32("Flags");
            var functionCount       = chunkReader.ReadUInt32("functionCount");
            var functionInfoOffset  = chunkReader.ReadUInt32("functionInfoOffset");
            var creatorStringReader = chunkReader.CopyAtOffset("creatorStringReader", chunkReader, (int)creatorStringOffset);

            result.CreatorString = creatorStringReader.ReadString("CreatorString");
            var functionInfoReader = reader.CopyAtOffset("functionInfoReader", chunkReader, (int)functionInfoOffset);

            for (int i = 0; i < functionCount; i++)
            {
                // is 0 for lib_4_0, lib_4_1, lib_5_0
                // is 1 for lib_4_0_level_9_1_vs_only, lib_4_0_level_9_3_vs_only
                // is 2 for lib_4_0_level_9_1_ps_only, lib_4_0_level_9_3_ps_only
                // is 3 for lib_4_0_level_9_1, lib_4_0_level_9_3
                var mode = (ProfileMode)functionInfoReader.ReadUInt32("mode");
                var functionNameOffset = functionInfoReader.ReadUInt32("functionNameOffset");
                var functionNameReader = reader.CopyAtOffset("functionNameReader", reader, (int)functionNameOffset);
                var name = functionNameReader.ReadString("name");
                result.FunctionDescs.Add(new LibraryDesc(name, mode));
            }
            return(result);
        }
Esempio n. 5
0
        public static DebugLibfChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var result      = new DebugLibfChunk();
            var chunkReader = reader.CopyAtCurrentPosition("LibfChunkReader", reader);

            result.LibraryContainer = new DebugBytecodeContainer(chunkReader);
            return(result);
        }
Esempio n. 6
0
        public static DebugBytecodeChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            //TODO: Merge Ctab parsing with DX9 Ctab
            var result      = new DebugCtabChunk();
            var chunkReader = reader.CopyAtCurrentPosition("ChunkReader", reader, (int)chunkSize);

            result.ConstantTable = DebugConstantTable.Parse(chunkReader);
            return(result);
        }
Esempio n. 7
0
        public static DebugBytecodeChunk Parse(DebugBytecodeReader reader, uint chunkSize, DebugBytecodeContainer container)
        {
            var result      = new DebugFxlcChunk();
            var chunkReader = reader.CopyAtCurrentPosition("FxlcChunkReader", reader);

            result.Fxlc = DebugFxlc.Parse(chunkReader, chunkSize);
            var padding = chunkReader.ReadUInt32("Padding");

            Debug.Assert(padding == 0xFFFF);
            return(result);
        }
Esempio n. 8
0
        public new static DebugEffectExpressionAssignment Parse(DebugBytecodeReader reader, DebugBytecodeReader assignmentReader)
        {
            var result     = new DebugEffectExpressionAssignment();
            var shaderSize = assignmentReader.ReadUInt32("ShaderSize");

            if (shaderSize != 0)
            {
                result.Shader = DebugBytecodeContainer.Parse(assignmentReader.CopyAtCurrentPosition("ExpressionReader", assignmentReader));
            }
            return(result);
        }
        protected void ParseInstance(DebugBytecodeReader reader, uint chunkSize)
        {
            Version = DebugShaderVersion.ParseShex(reader);
            var sizeInUint32 = reader.ReadUInt32("SizeInUint32");
            var dxilMagic    = reader.ReadUInt32("DxilMagic");

            DxilVersion = reader.ReadUInt32("DxilVersion");
            var bitcodeOffset = reader.ReadUInt32("BitcodeOffset");
            var bitcodeLength = reader.ReadInt32("BitcodeLength");
            var bitcodeReader = reader.CopyAtCurrentPosition("BitcodeReader", reader);

            Bitcode = bitcodeReader.ReadBytes("Bitcode", bitcodeLength);
        }
        public static DebugInterfacesChunk Parse(DebugBytecodeReader reader, uint sizeInBytes)
        {
            var headerReader = reader.CopyAtCurrentPosition("InterfaceHeaderReader", reader);

            var result = new DebugInterfacesChunk();

            var classInstanceCount       = headerReader.ReadUInt32("classInstanceCount");
            var classTypeCount           = headerReader.ReadUInt32("classTypeCount");
            var interfaceSlotRecordCount = headerReader.ReadUInt32("interfaceSlotRecordCount");

            // Will be same as interfaceSlotRecordCount unless there are interface arrays.
            result.InterfaceSlotCount = headerReader.ReadUInt32("InterfaceSlotCount");

            headerReader.ReadUInt32("Think this is offset to start of interface slot info, but we don't need it.");             // Think this is offset to start of interface slot info, but we don't need it.

            var classTypeOffset      = headerReader.ReadUInt32("classTypeOffset");
            var availableClassReader = reader.CopyAtOffset("availableClassReader", headerReader, (int)classTypeOffset);

            var interfaceSlotOffset = headerReader.ReadUInt32("interfaceSlotOffset");
            var interfaceSlotReader = reader.CopyAtOffset("interfaceSlotReader", headerReader, (int)interfaceSlotOffset);

            var unknown1 = headerReader.ReadBytes("InterfaceChunkUnknown1", 4);
            var unknown2 = headerReader.ReadUInt16("InterfaceChunkUnknown2");
            var unknown3 = headerReader.ReadUInt16("InterfaceChunkUnknown3");

            for (uint i = 0; i < classTypeCount; i++)
            {
                var classType = DebugClassType.Parse(reader, availableClassReader);
                classType.ID = i;                 // Really??
                result.AvailableClassTypes.Add(classType);
            }

            for (uint i = 0; i < classInstanceCount; i++)
            {
                var classInstance = DebugClassInstance.Parse(reader, availableClassReader);
                result.AvailableClassInstances.Add(classInstance);
            }

            uint startSlot = 0;

            for (uint i = 0; i < interfaceSlotRecordCount; i++)
            {
                var interfaceSlot = DebugInterfaceSlot.Parse(reader, interfaceSlotReader);
                interfaceSlot.StartSlot = startSlot;                 // Really??
                result.InterfaceSlots.Add(interfaceSlot);

                startSlot += interfaceSlot.SlotSpan;
            }

            return(result);
        }
        public static DebugLibraryParameterSignatureChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var result          = new DebugLibraryParameterSignatureChunk();
            var chunkReader     = reader.CopyAtCurrentPosition("LibraryParameterSignatureChunkReader", reader);
            var parameterCount  = chunkReader.ReadUInt32("ParameterCount");
            var parameterOffset = chunkReader.ReadUInt32("ParameterOffset");

            for (int i = 0; i < parameterCount; i++)
            {
                var parameterReader = chunkReader.CopyAtOffset($"ParameterReader{i}", chunkReader, (int)parameterOffset + 12 * 4 * i);
                result.Parameters.Add(DebugLibraryParameterDescription.Parse(reader, parameterReader));
            }
            return(result);
        }
Esempio n. 12
0
        public static DebugEffectChunk Parse(DebugBytecodeReader reader, uint length)
        {
            var result       = new DebugEffectChunk();
            var footerOffset = reader.ReadUInt32("footerOffset");
            var bodyReader   = reader.CopyAtCurrentPosition("BodyReader", reader);
            var dummyReader  = bodyReader.CopyAtCurrentPosition("Dummy", bodyReader);

            dummyReader.ReadUInt32("Zero");
            var footerReader   = bodyReader.CopyAtOffset("FooterReader", reader, (int)footerOffset);
            var variableCount  = result.VariableCount = footerReader.ReadUInt32("VariableCount");
            var techniqueCount = result.TechniqueCount = footerReader.ReadUInt32("TechniqueCount");

            result.PassCount   = footerReader.ReadUInt32("PassCount");
            result.ShaderCount = footerReader.ReadUInt32("ShaderCount");

            for (int i = 0; i < variableCount; i++)
            {
                footerReader.AddIndent($"Variable {i}");
                result.Variables.Add(DebugVariable.Parse(bodyReader, footerReader));
                footerReader.RemoveIndent();
            }
            for (int i = 0; i < techniqueCount; i++)
            {
                footerReader.AddIndent($"Technique {i}");
                result.Techniques.Add(DebugTechnique.Parse(bodyReader, footerReader));
                footerReader.RemoveIndent();
            }

            result.VariableBlobCount = footerReader.ReadUInt32("VariableBlobCount");
            result.StateBlobCount    = footerReader.ReadUInt32("StateBlobCount");
            for (int i = 0; i < result.VariableBlobCount; i++)
            {
                footerReader.AddIndent($"VariableBlob {i}");
                result.VariableBlobs.Add(DebugBinaryData.Parse(bodyReader, footerReader));
                footerReader.RemoveIndent();
            }
            for (int i = 0; i < result.StateBlobCount; i++)
            {
                footerReader.AddIndent($"StateBlob {i}");
                result.StateBlobs.Add(DebugStateBlob.Parse(bodyReader, footerReader));
                footerReader.RemoveIndent();
            }
            return(result);
        }
Esempio n. 13
0
        public static DebugCli4Chunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var result      = new DebugCli4Chunk();
            var chunkReader = reader.CopyAtCurrentPosition("ChunkReader", reader);
            var count       = chunkReader.ReadUInt32("Count");

            for (int i = 0; i < count; i++)
            {
                chunkReader.AddIndent($"Number {i}");
                var info   = chunkReader.Members.Last();
                var number = DebugNumber.Parse(chunkReader);
                result.Numbers.Add(number);
                info.AddNote("Int", number.Int.ToString());
                info.AddNote("Uint", number.UInt.ToString());
                info.AddNote("Float", number.Float.ToString());
                chunkReader.RemoveIndent();
            }
            return(result);
        }
        public static DebugBinaryData Parse(DebugBytecodeReader reader, DebugBytecodeReader blobReader)
        {
            var result = new DebugBinaryData();

            result.Index = blobReader.ReadUInt32("Index");
            result.Size  = blobReader.ReadUInt32("Size");
            var startPosition = blobReader._reader.BaseStream.Position;
            var header        = blobReader.PeakUint32();
            var shaderType    = (ShaderType)(header >> 16);
            var paddedSize    = result.Size + (result.Size % 4 == 0 ? 0 : 4 - result.Size % 4);

            if (shaderType == ShaderType.Pixel || shaderType == ShaderType.Vertex || shaderType == ShaderType.Expression)
            {
                var shaderReader = blobReader.CopyAtCurrentPosition("ShaderReader", blobReader);
                result.Shader = DebugShaderModel.Parse(shaderReader);
            }
            else if (result.Size > 0)
            {
                blobReader.ReadBytes("Value", (int)paddedSize);
            }
            blobReader._reader.BaseStream.Position = startPosition + paddedSize;
            return(result);
        }
        public static DebugResourceDefinitionChunk Parse(DebugBytecodeReader reader)
        {
            var headerReader = reader.CopyAtCurrentPosition("RDefHeader", reader);

            uint constantBufferCount   = headerReader.ReadUInt32("constantBufferCount");
            uint constantBufferOffset  = headerReader.ReadUInt32("constantBufferOffset");
            uint resourceBindingCount  = headerReader.ReadUInt32("resourceBindingCount");
            uint resourceBindingOffset = headerReader.ReadUInt32("resourceBindingOffset");
            var  target = DebugShaderVersion.ParseRdef(headerReader);
            var  flags  = headerReader.ReadEnum32 <ShaderFlags>("flags");

            var creatorOffset = headerReader.ReadUInt32("creatorOffset");
            var creatorReader = reader.CopyAtOffset("CreatorString", headerReader, (int)creatorOffset);
            var creator       = creatorReader.ReadString("creator");

            var result = new DebugResourceDefinitionChunk
            {
                Target  = target,
                Flags   = flags,
                Creator = creator
            };

            if (target.MajorVersion == 5 || target.ProgramType == ProgramType.LibraryShader)
            {
                var isVersion5_1 = target.MajorVersion == 5 && target.MinorVersion == 1;
                if (isVersion5_1)
                {
                    var unknown0 = headerReader.ReadUInt32("unkRdefHeader");
                }
                else
                {
                    string rd11 = headerReader.ReadUInt32("rd11").ToFourCcString();
                    if (rd11 != "RD11")
                    {
                        throw new ParseException("Expected RD11.");
                    }
                }

                var unkStride1            = headerReader.ReadUInt32("unkStride1");      // TODO
                var constantBufferStride  = headerReader.ReadUInt32("constantBufferStride");
                var resourceBindingStride = headerReader.ReadUInt32("resourceBindingStride");
                //Shader Variable Stride?
                var unkStride2 = headerReader.ReadUInt32("unkStride2");
                var unkStride3 = headerReader.ReadUInt32("unkStride3");
                //Shader Type Member Stride?
                var unkStride4 = headerReader.ReadUInt32("unkStride4");

                Debug.Assert(unkStride1 == 60, $"unkStride1 is {unkStride1}");
                Debug.Assert(constantBufferStride == 24, $"constantBufferStride is {constantBufferStride}");
                Debug.Assert(resourceBindingStride == CalculateResourceBindingStride(target),
                             $"resourceBindingStride is {resourceBindingStride}");
                Debug.Assert(unkStride2 == 40, $"unkStride2 is {unkStride2}");
                Debug.Assert(unkStride3 == 36, $"unkStride3 is {unkStride3}");
                Debug.Assert(unkStride4 == 12, $"unkStride4 is {unkStride4}");

                result.InterfaceSlotCount = headerReader.ReadUInt32("InterfaceSlotCount");
            }

            var resourceBindingReader = reader.CopyAtOffset("ResourceBindings", headerReader, (int)resourceBindingOffset);

            for (int i = 0; i < resourceBindingCount; i++)
            {
                result.ResourceBindings.Add(DebugResourceBinding.Parse(reader, resourceBindingReader, target));
            }

            var constantBufferReader = reader.CopyAtOffset("ContantBuffers", headerReader, (int)constantBufferOffset);

            constantBufferReader.Indent++;
            for (int i = 0; i < constantBufferCount; i++)
            {
                result.ConstantBuffers.Add(DebugConstantBuffer.Parse(reader, constantBufferReader, result.Target));
            }

            return(result);
        }
        public static DebugInputOutputSignatureChunk Parse(DebugBytecodeReader reader, ChunkType chunkType,
                                                           ProgramType programType)
        {
            DebugInputOutputSignatureChunk result;

            switch (chunkType)
            {
            case ChunkType.Isgn:
            case ChunkType.Isg1:
                result = new DebugInputSignatureChunk();
                break;

            case ChunkType.Osgn:
            case ChunkType.Osg1:
            case ChunkType.Osg5:
                result = new DebugOutputSignatureChunk();
                break;

            case ChunkType.Pcsg:
                result = new DebugPatchConstantSignatureChunk();
                break;

            default:
                throw new ArgumentOutOfRangeException("chunkType", "Unrecognised chunk type: " + chunkType);
            }

            var chunkReader  = reader.CopyAtCurrentPosition("ChunkReader", reader);
            var elementCount = chunkReader.ReadUInt32("ElementCount");
            var uniqueKey    = chunkReader.ReadUInt32("UniqueKey");

            SignatureElementSize elementSize;

            switch (chunkType)
            {
            case ChunkType.Isgn:
            case ChunkType.Osgn:
            case ChunkType.Pcsg:
                elementSize = SignatureElementSize._6;
                break;

            case ChunkType.Osg5:
                elementSize = SignatureElementSize._7;
                break;

            case ChunkType.Osg1:
            case ChunkType.Isg1:
                elementSize = SignatureElementSize._8;
                break;

            default:
                throw new ArgumentOutOfRangeException("chunkType", "Unrecognised chunk type: " + chunkType);
            }

            for (int i = 0; i < elementCount; i++)
            {
                result.Parameters.Add(DebugSignatureParameterDescription.Parse(reader, chunkReader, chunkType, elementSize,
                                                                               programType));
            }

            return(result);
        }
Esempio n. 17
0
        public static DebugEffectChunk Parse(DebugBytecodeReader reader, uint size)
        {
            var headerReader = reader.CopyAtCurrentPosition("Header", reader);
            var result       = new DebugEffectChunk();

            result.Size = size;
            var header     = result.Header = DebugEffectHeader.Parse(headerReader);
            var bodyOffset = header.Version.MajorVersion < 5 ?
                             0x4C : 0x60;
            var footerOffset = (int)(result.Header.FooterOffset + bodyOffset);
            var bodyReader   = reader.CopyAtOffset("Body", reader, (int)bodyOffset);
            var dummyReader  = bodyReader.CopyAtCurrentPosition("DummyReader", bodyReader);

            dummyReader.ReadUInt32("Zero");
            var footerReader = reader.CopyAtOffset("Footer", reader, footerOffset);
            var version      = header.Version;

            for (int i = 0; i < header.ConstantBuffers; i++)
            {
                footerReader.AddIndent($"ConstantBuffer {i}");
                result.LocalBuffers.Add(DebugEffectBuffer.Parse(bodyReader, footerReader, version, false));
                footerReader.RemoveIndent();
            }
            for (int i = 0; i < header.ObjectCount; i++)
            {
                footerReader.AddIndent($"Variable {i}");
                result.LocalVariables.Add(DebugEffectObjectVariable.Parse(bodyReader, footerReader, version, false));
                footerReader.RemoveIndent();
            }
            for (int i = 0; i < header.SharedConstantBuffers; i++)
            {
                footerReader.AddIndent($"SharedConstantBuffer {i}");
                result.SharedBuffers.Add(DebugEffectBuffer.Parse(bodyReader, footerReader, version, true));
                footerReader.RemoveIndent();
            }
            for (int i = 0; i < header.SharedObjectCount; i++)
            {
                footerReader.AddIndent($"SharedVariable {i}");
                result.SharedVariables.Add(DebugEffectObjectVariable.Parse(bodyReader, footerReader, version, true));
                footerReader.RemoveIndent();
            }
            if (header.Version.MajorVersion >= 5)
            {
                for (int i = 0; i < header.InterfaceVariableCount; i++)
                {
                    footerReader.AddIndent($"Interface {i}");
                    result.InterfaceVariables.Add(DebugEffectInterfaceVariable.Parse(bodyReader, footerReader, version));
                    footerReader.RemoveIndent();
                }
                for (int i = 0; i < header.GroupCount; i++)
                {
                    footerReader.AddIndent($"Group {i}");
                    result.Groups.Add(DebugEffectGroup.Parse(bodyReader, footerReader, header.Version));
                    footerReader.RemoveIndent();
                }
            }
            else
            {
                for (int i = 0; i < header.Techniques; i++)
                {
                    footerReader.AddIndent($"Technique {i}");
                    result.Techniques.Add(DebugEffectTechnique.Parse(bodyReader, footerReader, header.Version));
                    footerReader.RemoveIndent();
                }
            }

            return(result);
        }