internal void UpdateVersion(DebugShaderVersion version)
        {
            if (Reader == null)
            {
                return;
            }
            Reader.ReadUInt32("Unknown");
            switch (version.ProgramType)
            {
            case ProgramType.VertexShader:
                Info = DebugVSInfo.Parse(Reader);
                break;

            case ProgramType.HullShader:
                Info = DebugHSInfo.Parse(Reader);
                break;

            case ProgramType.DomainShader:
                Info = DebugDSInfo.Parse(Reader);
                break;

            case ProgramType.GeometryShader:
                Info = DebugGSInfo.Parse(Reader);
                break;

            case ProgramType.PixelShader:
                Info = DebugPSInfo.Parse(Reader);
                break;

            default:
                Reader.ReadBytes("Unknown", 32);
                break;
            }
            if (Info != null && Info.StructSize < DebugValidationInfo.UnionSize)
            {
                Reader.ReadBytes("Padding", DebugValidationInfo.UnionSize - Info.StructSize);
            }
            MinimumExpectedWaveLaneCount = Reader.ReadUInt32("MinimumExpectedWaveLaneCount");
            MaximumExpectedWaveLaneCount = Reader.ReadUInt32("MaximumExpectedWaveLaneCount");
            if (ChunkSize > 20)
            {
                Reader.ReadEnum8 <PSVShaderKind>("ShaderStage");
                UsesViewID                  = Reader.ReadByte("UsesViewID");
                GSMaxVertexCount            = Reader.ReadByte("MaxVertexCount");
                SigInputElements            = Reader.ReadByte("SigInputElements");
                SigOutputElements           = Reader.ReadByte("SigOutputElements");
                SigPatchConstOrPrimElements = Reader.ReadByte("SigPatchConstOrPrimElements");
                SigInputVectors             = Reader.ReadByte("SigInputVectors");
                SigOutputVectors            = Reader.ReadBytes("SigOutputVectors", 4);
            }
            Reader = null;
        }
Beispiel #2
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);
        }
        public static DebugShaderMessageDeclarationToken Parse(DebugBytecodeReader reader)
        {
            var token0 = reader.ReadUInt32("token0");

            DebugOpcodeHeader.AddNotes(reader, token0);
            var member = reader.LocalMembers.Last();
            var length = reader.ReadUInt32("length") - 2;

            var result = new DebugShaderMessageDeclarationToken
            {
                DeclarationLength  = length,
                InfoQueueMessageID = reader.ReadUInt32("InfoQueueMessageID"),
                MessageFormat      = reader.ReadEnum32 <ShaderMessageFormat>("MessageFormat"),
                NumCharacters      = reader.ReadUInt32("NumCharacters"),
                NumOperands        = reader.ReadUInt32("NumOperands"),
                OperandsLength     = reader.ReadUInt32("OperandsLength")
            };

            for (int i = 0; i < result.NumOperands; i++)
            {
                result.Operands.Add(DebugOperand.Parse(reader, OpcodeType.CustomData));
            }

            result.Format = reader.ReadString("Format");

            // String is padded to a multiple of DWORDs.
            uint remainingBytes = (4 - ((result.NumCharacters + 1) % 4)) % 4;

            reader.ReadBytes("StringPadding", (int)remainingBytes);

            return(result);
        }
Beispiel #4
0
        public static DebugHashChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var result = new DebugHashChunk();

            result.Flags  = reader.ReadUInt32("Flags");
            result.Digest = reader.ReadBytes("Digest", DigestSize);
            return(result);
        }
Beispiel #5
0
        public static DebugShaderProgramChunk Parse(DebugBytecodeReader reader)
        {
            var program = new DebugShaderProgramChunk
            {
                Version = DebugShaderVersion.ParseShex(reader),
                Length  = reader.ReadUInt32("Length")
            };

            while (!reader.EndOfBuffer)
            {
                var opcodeIndex  = program.Tokens.Count;
                var opcodeToken0 = reader.PeakUint32();
                var opcodeHeader = new DebugOpcodeHeader
                {
                    OpcodeType = opcodeToken0.DecodeValue <OpcodeType>(0, 10),
                    Length     = opcodeToken0.DecodeValue(24, 30),
                    IsExtended = (opcodeToken0.DecodeValue(31, 31) == 1)
                };
                DebugOpcodeToken opcodeToken = null;
                if (opcodeHeader.Length == 0 && opcodeHeader.OpcodeType != OpcodeType.CustomData)
                {
                    throw new Exception("Error parsing shader");
                }
                if (opcodeHeader.OpcodeType == OpcodeType.CustomData)
                {
                    //opcodeToken = DebugCustomDataToken.Parse(reader, opcodeToken0);
                    var customDataClass = opcodeToken0.DecodeValue <CustomDataClass>(11, 31);
                    var length          = reader.PeakUInt32Ahead(4);
                    if (length == 0)
                    {
                        throw new Exception("Error parsing shader");
                    }
                    var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType}-{customDataClass})", (int)length * 4);
                }
                else if (opcodeHeader.OpcodeType.IsDeclaration())
                {
                    var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType})", (int)opcodeHeader.Length * 4);
                }
                else                 // Not custom data or declaration, so must be instruction.
                {
                    var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType})", (int)opcodeHeader.Length * 4);
                }
                program.Tokens.Add(opcodeToken);
            }
            return(program);
        }
Beispiel #6
0
        public static List <Number> ReadParameterValue(this DebugParameter parameter, DebugBytecodeReader valueReader)
        {
            var result = new List <Number>();

            if (parameter.ParameterClass == ParameterClass.Object)
            {
                var defaultValueCount = parameter.GetSize() / 4;
                var data = valueReader.ReadBytes("ParameterValue", (int)defaultValueCount * 4);
                result.Add(new Number(data));
            }
            else
            {
                var defaultValueCount = parameter.GetSize() / 4;
                var data = valueReader.ReadBytes("ParameterValue", (int)defaultValueCount * 4);
                for (int i = 0; i < defaultValueCount; i++)
                {
                    result.Add(Number.FromByteArray(data, i * 4));
                }
            }
            return(result);
        }
Beispiel #7
0
        bool ReadCommentToken(DebugBytecodeReader reader)
        {
            var fourCC = reader.PeakUInt32Ahead(4);

            if (KnownCommentTypes.ContainsKey(fourCC))
            {
                reader.AddIndent(KnownCommentTypes[fourCC].ToString());
            }
            else
            {
                return(false);
            }
            var    instructionToken = reader.ReadUInt32("Token");
            var    startPosition    = reader._reader.BaseStream.Position;
            var    entry            = reader.Members.Last();
            Opcode opcode           = (Opcode)(instructionToken & 0xffff);

            entry.AddNote("TokenOpcode", opcode.ToString());
            var size = (int)((instructionToken >> 16) & 0x7FFF);

            entry.AddNote("TokenSize", size.ToString());
            reader.ReadBytes("FourCC", 4);

            switch (KnownCommentTypes[fourCC])
            {
            case CommentType.CTAB:
                ConstantTable = DebugConstantTable.Parse(reader);
                break;

            case CommentType.C**T:
                Cli = DebugCliToken.Parse(reader);
                break;

            case CommentType.FXLC:
                Fxlc = DebugFxlc.Parse(reader, (uint)size * 4);
                break;

            case CommentType.PRES:
                Preshader = DebugPreshader.Parse(reader);
                break;

            case CommentType.PRSI:
                Prsi = DebugPrsiToken.Parse(reader, (uint)size);
                break;

            default:
                return(false);
            }
            reader.RemoveIndent();
            reader._reader.BaseStream.Position = startPosition + size * 4;
            return(true);
        }
        public static DebugDebugNameChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var result     = new DebugDebugNameChunk();
            var flags      = reader.ReadUInt16("Flags");        //Currently unused
            var nameLength = reader.ReadUInt16("NameLength");

            result.Name = reader.ReadString("Name");
            var padding = 4 - (nameLength + 1) % 4;             //Aligned to 4 byte boundary

            if (padding > 0)
            {
                reader.ReadBytes("Padding", padding);
            }
            return(result);
        }
        IDebugToken ReadInstruction(DebugBytecodeReader reader)
        {
            uint   instructionToken = reader.ReadUInt32("Token");
            Opcode opcode           = (Opcode)(instructionToken & 0xffff);
            uint   size;

            if (opcode == Opcode.Comment)
            {
                size = (uint)((instructionToken >> 16) & 0x7FFF);
            }
            else
            {
                size = (uint)((instructionToken >> 24) & 0x0f);
            }
            var entry = reader.LocalMembers.Last();

            entry.AddNote("TokenOpcode", opcode.ToString());
            entry.AddNote("TokenSize", size.ToString());
            IDebugToken result;

            if (opcode == Opcode.Comment)
            {
                var token = new DebugToken();
                token.Token  = instructionToken;
                token.Opcode = opcode;
                token.Data   = reader.ReadBytes("CommentData", (int)size * 4);
                result       = token;
            }
            else
            {
                result = DebugInstructionToken.Parse(reader, instructionToken, opcode, size);
            }
            if (opcode != Opcode.Comment)
            {
                var token = result as DebugInstructionToken;
                token.Modifier   = (int)((instructionToken >> 16) & 0xff);
                token.Predicated = (instructionToken & 0x10000000) != 0;
                token.CoIssue    = (instructionToken & 0x40000000) != 0;
                entry.AddNote("Modifer", token.Modifier);
                entry.AddNote("Predicated", token.Predicated);
                entry.AddNote("CoIssue", token.CoIssue);
            }
            return(result);
        }
Beispiel #10
0
        public static DebugFxlc Parse(DebugBytecodeReader reader, uint size)
        {
            var result       = new DebugFxlc();
            var basePosition = reader._reader.BaseStream.Position;
            var tokenCount   = reader.ReadUInt32("TokenCount");

            for (int i = 0; i < tokenCount; i++)
            {
                var token = reader.PeakUint32();
                var type  = (FxlcOpcode)token.DecodeValue(20, 30);
                reader.AddIndent($"Token{i}({type})");
                result.Tokens.Add(DebugFxlcToken.Parse(reader));
                reader.RemoveIndent();
            }
            var padding       = reader.ReadBytes($"Padding", 8);
            var paddingUint64 = BitConverter.ToInt64(padding, 0);
            var expected      = 0x0F0F0f0FF0F0F0F0;

            Debug.Assert(paddingUint64 == expected);
            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);
        }