public static InterfaceSlot Parse(BytecodeReader reader, BytecodeReader interfaceSlotReader) { var slotSpan = interfaceSlotReader.ReadUInt32(); var count = interfaceSlotReader.ReadUInt32(); var typeIDsOffset = interfaceSlotReader.ReadUInt32(); var typeIDsReader = reader.CopyAtOffset((int) typeIDsOffset); var tableIDsOffset = interfaceSlotReader.ReadUInt32(); var tableIDsReader = reader.CopyAtOffset((int) tableIDsOffset); var result = new InterfaceSlot { SlotSpan = slotSpan }; for (int i = 0; i < count; i++) { result.TypeIDs.Add(typeIDsReader.ReadUInt16()); result.TableIDs.Add(tableIDsReader.ReadUInt32()); } return result; }
public static ShaderMessageDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); var length = reader.ReadUInt32() - 2; var result = new ShaderMessageDeclarationToken { DeclarationLength = length, InfoQueueMessageID = reader.ReadUInt32(), MessageFormat = (ShaderMessageFormat) reader.ReadUInt32(), NumCharacters = reader.ReadUInt32(), NumOperands = reader.ReadUInt32(), OperandsLength = reader.ReadUInt32() }; for (int i = 0; i < result.NumOperands; i++) result.Operands.Add(Operand.Parse(reader, OpcodeType.CustomData)); result.Format = reader.ReadString(); // String is padded to a multiple of DWORDs. uint remainingBytes = (4 - ((result.NumCharacters + 1) % 4)) % 4; reader.ReadBytes((int) remainingBytes); return result; }
public static ResourceDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); var resourceDimension = token0.DecodeValue<ResourceDimension>(11, 15); byte sampleCount; switch (resourceDimension) { case ResourceDimension.Texture2DMultiSampled: case ResourceDimension.Texture2DMultiSampledArray: sampleCount = token0.DecodeValue<byte>(16, 22); break; default: sampleCount = 0; break; } var operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)); var returnType = ResourceReturnTypeToken.Parse(reader); return new ResourceDeclarationToken { ResourceDimension = resourceDimension, SampleCount = sampleCount, Operand = operand, ReturnType = returnType }; }
public static ConstantBuffer Parse( BytecodeReader reader, BytecodeReader constantBufferReader, ShaderVersion target) { uint nameOffset = constantBufferReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int) nameOffset); uint variableCount = constantBufferReader.ReadUInt32(); uint variableOffset = constantBufferReader.ReadUInt32(); var result = new ConstantBuffer { Name = nameReader.ReadString() }; var variableReader = reader.CopyAtOffset((int) variableOffset); for (int i = 0; i < variableCount; i++) result.Variables.Add(ShaderVariable.Parse(reader, variableReader, target, i == 0)); result.Size = constantBufferReader.ReadUInt32(); result.Flags = (ConstantBufferFlags) constantBufferReader.ReadUInt32(); result.BufferType = (ConstantBufferType) constantBufferReader.ReadUInt32(); return result; }
public static ShaderProgramChunk Parse(BytecodeReader reader) { var program = new ShaderProgramChunk { Version = ShaderVersion.ParseShex(reader), // Length Token (LenTok) // Always follows VerTok // [31:00] Unsigned integer count of number of DWORDs in program code, including version and length tokens. // So the minimum value is 0x00000002 (if an empty program is ever valid). Length = reader.ReadUInt32() }; while (!reader.EndOfBuffer) { // Opcode Format (OpcodeToken0) // // [10:00] D3D10_SB_OPCODE_TYPE // if( [10:00] == D3D10_SB_OPCODE_CUSTOMDATA ) // { // Token starts a custom-data block. See "Custom-Data Block Format". // } // else // standard opcode token // { // [23:11] Opcode-Specific Controls // [30:24] Instruction length in DWORDs including the opcode token. // [31] 0 normally. 1 if extended operand definition, meaning next DWORD // contains extended opcode token. // } var opcodeHeaderReader = reader.CopyAtCurrentPosition(); var opcodeToken0 = opcodeHeaderReader.ReadUInt32(); var opcodeHeader = new OpcodeHeader { OpcodeType = opcodeToken0.DecodeValue<OpcodeType>(0, 10), Length = opcodeToken0.DecodeValue(24, 30), IsExtended = (opcodeToken0.DecodeValue(31, 31) == 1) }; OpcodeToken opcodeToken; if (opcodeHeader.OpcodeType == OpcodeType.CustomData) { opcodeToken = CustomDataToken.Parse(reader, opcodeToken0); } else if (opcodeHeader.OpcodeType.IsDeclaration()) { opcodeToken = DeclarationToken.Parse(reader, opcodeHeader.OpcodeType); } else // Not custom data or declaration, so must be instruction. { opcodeToken = InstructionToken.Parse(reader, opcodeHeader); } opcodeToken.Header = opcodeHeader; program.Tokens.Add(opcodeToken); } program.LinkControlFlowInstructions(); return program; }
public static ResourceDefinitionChunk Parse(BytecodeReader reader) { var headerReader = reader.CopyAtCurrentPosition(); uint constantBufferCount = headerReader.ReadUInt32(); uint constantBufferOffset = headerReader.ReadUInt32(); uint resourceBindingCount = headerReader.ReadUInt32(); uint resourceBindingOffset = headerReader.ReadUInt32(); var target = ShaderVersion.ParseRdef(headerReader); uint flags = headerReader.ReadUInt32(); var creatorOffset = headerReader.ReadUInt32(); var creatorReader = reader.CopyAtOffset((int) creatorOffset); var creator = creatorReader.ReadString(); var result = new ResourceDefinitionChunk { Target = target, Flags = (ShaderFlags) flags, Creator = creator }; if (target.MajorVersion >= 5) { string rd11 = headerReader.ReadUInt32().ToFourCcString(); if (rd11 != "RD11") throw new ParseException("Expected RD11."); var unknown1 = headerReader.ReadUInt32(); // TODO Debug.Assert(unknown1 == 60); var unknown2 = headerReader.ReadUInt32(); Debug.Assert(unknown2 == 24); var unknown3 = headerReader.ReadUInt32(); Debug.Assert(unknown3 == 32); var unknown4 = headerReader.ReadUInt32(); Debug.Assert(unknown4 == 40); var unknown5 = headerReader.ReadUInt32(); Debug.Assert(unknown5 == 36); var unknown6 = headerReader.ReadUInt32(); Debug.Assert(unknown6 == 12); result.InterfaceSlotCount = headerReader.ReadUInt32(); } var constantBufferReader = reader.CopyAtOffset((int) constantBufferOffset); for (int i = 0; i < constantBufferCount; i++) result.ConstantBuffers.Add(ConstantBuffer.Parse(reader, constantBufferReader, result.Target)); var resourceBindingReader = reader.CopyAtOffset((int) resourceBindingOffset); for (int i = 0; i < resourceBindingCount; i++) result.ResourceBindings.Add(ResourceBinding.Parse(reader, resourceBindingReader)); return result; }
public static GeometryShaderMaxOutputVertexCountDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new GeometryShaderMaxOutputVertexCountDeclarationToken { MaxPrimitives = reader.ReadUInt32() }; }
public static RawShaderResourceViewDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new RawShaderResourceViewDeclarationToken { Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)) }; }
public static GeometryShaderOutputPrimitiveTopologyDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new GeometryShaderOutputPrimitiveTopologyDeclarationToken { PrimitiveTopology = token0.DecodeValue<PrimitiveTopology>(11, 17) }; }
public static GeometryShaderInputPrimitiveDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new GeometryShaderInputPrimitiveDeclarationToken { Primitive = token0.DecodeValue<Primitive>(11, 16) }; }
public static ControlPointCountDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new ControlPointCountDeclarationToken { ControlPointCount = token0.DecodeValue(11, 16) }; }
public static TempRegisterDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new TempRegisterDeclarationToken { TempCount = reader.ReadUInt32() }; }
public static Number Parse(BytecodeReader reader) { const int byteCount = 4; var bytes = new byte[byteCount]; for (int i = 0; i < byteCount; i++) bytes[i] = reader.ReadByte(); return new Number(bytes); }
public static GeometryShaderInstanceCountDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new GeometryShaderInstanceCountDeclarationToken { InstanceCount = reader.ReadUInt32() }; }
public static TessellatorPartitioningDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new TessellatorPartitioningDeclarationToken { Partitioning = token0.DecodeValue<TessellatorPartitioning>(11, 13) }; }
public static FunctionBodyDeclarationToken Parse(BytecodeReader reader) { uint token0 = reader.ReadUInt32(); return new FunctionBodyDeclarationToken { Identifier = reader.ReadUInt32() }; }
public static HullShaderMaxTessFactorDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new HullShaderMaxTessFactorDeclarationToken { MaxTessFactor = reader.ReadSingle() }; }
public static HullShaderForkPhaseInstanceCountDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new HullShaderForkPhaseInstanceCountDeclarationToken { InstanceCount = reader.ReadUInt32() }; }
public static GlobalFlagsDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new GlobalFlagsDeclarationToken { Flags = token0.DecodeValue<GlobalFlags>(11, 18) }; }
public static TessellatorDomainDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new TessellatorDomainDeclarationToken { Domain = token0.DecodeValue<TessellatorDomain>(11, 12) }; }
public static TessellatorOutputPrimitiveDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new TessellatorOutputPrimitiveDeclarationToken { OutputPrimitive = token0.DecodeValue<TessellatorOutputPrimitive>(11, 13) }; }
public static StreamDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new StreamDeclarationToken { Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)) }; }
public static RawUnorderedAccessViewDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new RawUnorderedAccessViewDeclarationToken { Coherency = token0.DecodeValue<UnorderedAccessViewCoherency>(16, 16), Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)) }; }
public static RawThreadGroupSharedMemoryDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new RawThreadGroupSharedMemoryDeclarationToken { Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)), ElementCount = reader.ReadUInt32() }; }
public static ConstantBufferDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new ConstantBufferDeclarationToken { AccessPattern = token0.DecodeValue<ConstantBufferAccessPattern>(11, 11), Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)) }; }
public static IndexableTempRegisterDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new IndexableTempRegisterDeclarationToken { RegisterIndex = reader.ReadUInt32(), RegisterCount = reader.ReadUInt32(), NumComponents = reader.ReadUInt32() }; }
public static StructuredThreadGroupSharedMemoryDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return new StructuredThreadGroupSharedMemoryDeclarationToken { Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)), StructByteStride = reader.ReadUInt32(), StructCount = reader.ReadUInt32() }; }
public static ShaderVersion ParseShex(BytecodeReader reader) { uint versionToken = reader.ReadUInt32(); return new ShaderVersion { MinorVersion = versionToken.DecodeValue<byte>(0, 3), MajorVersion = versionToken.DecodeValue<byte>(4, 7), ProgramType = versionToken.DecodeValue<ProgramType>(16, 31) }; }
public static SamplerDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); var operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)); return new SamplerDeclarationToken { SamplerMode = token0.DecodeValue<SamplerMode>(11, 14), Operand = operand }; }
public static DebuggingChunk Parse(BytecodeReader reader, ChunkType chunkType, int chunkSize) { var result = new DebuggingChunk(); if (chunkType == ChunkType.Sdbg) // SDGB is not supported. return result; result.PdbBytes = reader.ReadBytes(chunkSize); return result; }