internal static EffectInterfaceVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version) { var result = new EffectInterfaceVariable(); var nameOffset = variableReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); var typeOffset = variableReader.ReadUInt32(); var typeReader = reader.CopyAtOffset((int)typeOffset); result.Type = EffectType.Parse(reader, typeReader, version); //Pointer to InterfaceInitializer var defaultValueOffset = variableReader.ReadUInt32(); var initializerReader = reader.CopyAtOffset((int)defaultValueOffset); var instanceNameOffset = initializerReader.ReadUInt32(); var instanceNameReader = reader.CopyAtOffset((int)instanceNameOffset); result.InstanceName = instanceNameReader.ReadString(); result.Flags = variableReader.ReadUInt32(); var annotationCount = variableReader.ReadUInt32(); for (int i = 0; i < annotationCount; i++) { result.Annotations.Add(EffectAnnotation.Parse(reader, variableReader, version)); } return(result); }
public static RootParameter Parse(BytecodeReader reader, BytecodeReader paramReader, RootSignatureVersion version) { var type = (RootParameterType)paramReader.ReadUInt32(); var visibility = (ShaderVisibility)paramReader.ReadUInt32(); var bodyOffset = paramReader.ReadUInt32(); var bodyReader = reader.CopyAtOffset((int)bodyOffset); RootParameter result; switch (type) { case RootParameterType.DescriptorTable: result = RootDescriptorTable.Parse(reader, bodyReader, version); break; case RootParameterType._32BitConstants: result = RootConstants.Parse(bodyReader); break; case RootParameterType.Srv: case RootParameterType.Uav: case RootParameterType.Cbv: result = RootDescriptor.Parse(bodyReader, version); break; default: throw new InvalidOperationException($"Can't parse Root Parameter of type {type}"); } result.ParameterType = type; result.ShaderVisibility = visibility; return(result); }
public static ResourceBinding Parse(BytecodeReader reader, BytecodeReader resourceBindingReader, ShaderVersion target) { uint nameOffset = resourceBindingReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); var result = new ResourceBinding { Name = nameReader.ReadString(), Type = (ShaderInputType)resourceBindingReader.ReadUInt32(), ReturnType = (ResourceReturnType)resourceBindingReader.ReadUInt32(), Dimension = (ShaderResourceViewDimension)resourceBindingReader.ReadUInt32(), NumSamples = resourceBindingReader.ReadUInt32(), BindPoint = resourceBindingReader.ReadUInt32(), BindCount = resourceBindingReader.ReadUInt32(), Flags = (ShaderInputFlags)resourceBindingReader.ReadUInt32() }; if (target.MajorVersion == 5 && target.MinorVersion == 1) { result.m_IsSM51 = true; result.SpaceIndex = resourceBindingReader.ReadUInt32(); result.ID = resourceBindingReader.ReadUInt32(); } else { result.ID = result.BindPoint; } return(result); }
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 EffectAnnotation Parse(BytecodeReader reader, BytecodeReader annotationReader, ShaderVersion version) { var result = new EffectAnnotation(); var nameOffset = annotationReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); var typeOffset = annotationReader.ReadUInt32(); var typeReader = reader.CopyAtOffset((int)typeOffset); result.Type = EffectType.Parse(reader, typeReader, version); //Note: Points to 27 and "foo" in Texture2D tex<int bla=27;string blu="foo";>; /// Value format and stride depends on Type var valueOffset = annotationReader.ReadUInt32(); var defaultValueReader = reader.CopyAtOffset((int)valueOffset); if (result.Type.EffectVariableType == EffectVariableType.Numeric) { for (int i = 0; i < result.Type.PackedSize / 4; i++) { result.DefaultNumericValue.Add(Number.Parse(defaultValueReader)); } } else { for (int i = 0; i < result.ElementCount; i++) { result.DefaultStringValue.Add(defaultValueReader.ReadString()); } } return(result); }
public static ConstantDeclaration Parse(BytecodeReader reader, BytecodeReader decReader) { var result = new ConstantDeclaration(); var nameOffset = decReader.ReadUInt32(); result.RegisterSet = (RegisterSet)decReader.ReadUInt16(); result.RegisterIndex = decReader.ReadUInt16(); result.RegisterCount = decReader.ReadUInt16(); decReader.ReadUInt16(); //Reserved var typeInfoOffset = decReader.ReadUInt32(); var defaultValueOffset = decReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); var typeReader = reader.CopyAtOffset((int)typeInfoOffset); result.Type = ConstantType.Parse(reader, typeReader); var memberInfoOffset = typeReader.ReadUInt32(); if (defaultValueOffset != 0) { //Note: thre are corrisponding def instructions. TODO: check that they are the same var defaultValueReader = reader.CopyAtOffset((int)defaultValueOffset); for (int i = 0; i < 4; i++) { result.DefaultValue.Add(defaultValueReader.ReadSingle()); } } return(result); }
public static EffectGroup Parse(BytecodeReader reader, BytecodeReader groupReader, ShaderVersion version) { var result = new EffectGroup(); var nameOffset = groupReader.ReadUInt32(); if (nameOffset != 0) { var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); } else { result.Name = ""; } var techniqueCount = groupReader.ReadUInt32(); for (int i = 0; i < techniqueCount; i++) { result.Techniques.Add(EffectTechnique.Parse(reader, groupReader, version)); } var annotationCount = groupReader.ReadUInt32(); for (int i = 0; i < annotationCount; i++) { result.Annotations.Add(EffectAnnotation.Parse(reader, groupReader, version)); } return(result); }
public static ConstantTable Parse(BytecodeReader ctabReader) { var result = new ConstantTable(); var ctabSize = ctabReader.ReadUInt32(); var creatorOffset = ctabReader.ReadInt32(); result.MajorVersion = ctabReader.ReadByte(); result.MinorVersion = ctabReader.ReadByte(); var shaderType = (ShaderType)ctabReader.ReadUInt16(); var numConstants = ctabReader.ReadInt32(); var constantInfoOffset = ctabReader.ReadInt32(); var shaderFlags = (ShaderFlags)ctabReader.ReadUInt32(); var shaderModelOffset = ctabReader.ReadInt32(); for (int i = 0; i < numConstants; i++) { var decReader = ctabReader.CopyAtOffset(constantInfoOffset + i * 20); ConstantDeclaration declaration = ConstantDeclaration.Parse(ctabReader, decReader); result.ConstantDeclarations.Add(declaration); } var shaderModelReader = ctabReader.CopyAtOffset(shaderModelOffset); result.VersionString = shaderModelReader.ReadString(); var creatorReader = ctabReader.CopyAtOffset(creatorOffset); result.Creator = creatorReader.ReadString(); return(result); }
public static EffectMember Parse(BytecodeReader reader, BytecodeReader memberReader, ShaderVersion version) { var result = new EffectMember(); var nameOffset = memberReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); var semanticNameOffset = memberReader.ReadUInt32(); if (semanticNameOffset != 0) { var semanticNameReader = reader.CopyAtOffset((int)semanticNameOffset); result.Semantic = semanticNameReader.ReadString(); } else { result.Semantic = ""; } result.BufferOffset = memberReader.ReadUInt32(); var typeOffset = memberReader.ReadUInt32(); var typeReader = reader.CopyAtOffset((int)typeOffset); result.Type = EffectType.Parse(reader, typeReader, version); return(result); }
public static VariableBlob Parse(BytecodeReader reader, BytecodeReader dataReader) { var result = new VariableBlob(); result.Index = dataReader.ReadUInt32(); var blobSize = dataReader.ReadUInt32(); var paddedSize = blobSize + (blobSize % 4 == 0 ? 0 : 4 - blobSize % 4); var shaderReader = dataReader.CopyAtCurrentPosition(); var data = dataReader.ReadBytes((int)paddedSize); if (!_IsShader(data)) { if (blobSize == 0) { result.Value = ""; } else { result.Value = Encoding.UTF8.GetString(data, 0, (int)(blobSize - 1)); } } else { result.Shader = ShaderModel.Parse(shaderReader); } return(result); }
public static FxlcToken Parse(BytecodeReader reader) { var result = new FxlcToken(); var token = reader.ReadUInt32(); var tokenComponentCount = token.DecodeValue(0, 2); result.Opcode = (FxlcOpcode)token.DecodeValue(20, 30); result.IsScalarInstruction = token.DecodeValue <bool>(31, 31); Debug.Assert(Enum.IsDefined(typeof(FxlcOpcode), result.Opcode), $"Unknown FxlcOpcode {result.Opcode}"); Debug.Assert(token.DecodeValue(3, 19) == 0, $"Unexpected data in FxlcToken bits 3-19 {token.DecodeValue(3, 19)}"); var operandCount = reader.ReadUInt32(); for (int i = 0; i < operandCount; i++) { var isScalarOp = i == 0 && result.IsScalarInstruction; result.Operands.Add(FxlcOperand.Parse(reader, tokenComponentCount, isScalarOp)); } // destination operand result.Operands.Insert(0, FxlcOperand.Parse(reader, tokenComponentCount, false)); return(result); }
public static Variable Parse(BytecodeReader reader, BytecodeReader variableReader) { var result = new Variable(); var parameterOffset = variableReader.ReadUInt32(); var defaultValueOffset = variableReader.ReadUInt32(); result.IsShared = variableReader.ReadUInt32(); var annotationCount = variableReader.ReadUInt32(); for (int i = 0; i < annotationCount; i++) { result.Annotations.Add(Annotation.Parse(reader, variableReader)); } var parameterReader = reader.CopyAtOffset((int)parameterOffset); result.Parameter = Parameter.Parse(reader, parameterReader); if (result.Parameter.ParameterType.IsSampler()) { var elementCount = result.Parameter.ElementCount > 0 ? result.Parameter.ElementCount : 1; var samplerStateReader = reader.CopyAtOffset((int)defaultValueOffset); for (int i = 0; i < elementCount; i++) { result.SamplerStates.Add(SamplerState.Parse(reader, samplerStateReader)); } } else { var valueReader = reader.CopyAtOffset((int)defaultValueOffset); result.DefaultValue = result.Parameter.ReadParameterValue(valueReader); } return(result); }
public static GeometryShaderMaxOutputVertexCountDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return(new GeometryShaderMaxOutputVertexCountDeclarationToken { MaxPrimitives = reader.ReadUInt32() }); }
public static TempRegisterDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return(new TempRegisterDeclarationToken { TempCount = reader.ReadUInt32() }); }
public static GeometryShaderInstanceCountDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return(new GeometryShaderInstanceCountDeclarationToken { InstanceCount = reader.ReadUInt32() }); }
public static HullShaderForkPhaseInstanceCountDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return(new HullShaderForkPhaseInstanceCountDeclarationToken { InstanceCount = reader.ReadUInt32() }); }
public static RootConstants Parse(BytecodeReader constantsReader) { return(new RootConstants() { ShaderRegister = constantsReader.ReadUInt32(), RegisterSpace = constantsReader.ReadUInt32(), Num32BitValues = constantsReader.ReadUInt32(), }); }
public static FunctionBodyDeclarationToken Parse(BytecodeReader reader) { uint token0 = reader.ReadUInt32(); return(new FunctionBodyDeclarationToken { Identifier = reader.ReadUInt32() }); }
public static DSInfo Parse(BytecodeReader reader) { return(new DSInfo() { InputControlPointCount = reader.ReadUInt32(), OutputPositionPresent = reader.ReadByte() != 0, TessellatorDomain = reader.ReadUInt32(), }); }
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 HSInfo Parse(BytecodeReader reader) { return(new HSInfo() { InputControlPointCount = reader.ReadUInt32(), OutputControlPointCount = reader.ReadUInt32(), TessellatorDomain = (TessellatorDomain)reader.ReadUInt32(), TessellatorOutputPrimitive = (TessellatorOutputPrimitive)reader.ReadUInt32(), }); }
public static StructuredShaderResourceViewDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return(new StructuredShaderResourceViewDeclarationToken { Operand = Operand.Parse(reader, token0.DecodeValue <OpcodeType>(0, 10)), StructByteStride = reader.ReadUInt32() }); }
public static GSInfo Parse(BytecodeReader reader) { return(new GSInfo() { InputPrimitive = (Primitive)reader.ReadUInt32(), OutputTopology = (PrimitiveTopology)reader.ReadUInt32(), OutputStreamMask = reader.ReadUInt32(), OutputPositionPresent = reader.ReadByte() != 0 }); }
public new static EffectConstantIndexAssignment Parse(BytecodeReader reader, BytecodeReader assignmentReader) { var result = new EffectConstantIndexAssignment(); var arrayNameOffset = assignmentReader.ReadUInt32(); var arrayNameReader = reader.CopyAtOffset((int)arrayNameOffset); result.ArrayName = arrayNameReader.ReadString(); result.Index = assignmentReader.ReadUInt32(); return(result); }
public static EffectAssignment Parse(BytecodeReader reader, BytecodeReader annotationReader) { //MemberType type, such as AddressV or Filter var memberType = (EffectAssignmentType)annotationReader.ReadUInt32(); // $"EffectStateAnnotationType is {memberType}"); //MemberIndex is 1 for BlendEnable[1] = TRUE; var memberIndex = annotationReader.ReadUInt32(); var assignmentType = (EffectCompilerAssignmentType)annotationReader.ReadUInt32(); var valueOffset = annotationReader.ReadUInt32(); var typeSpecificReader = reader.CopyAtOffset((int)valueOffset); EffectAssignment result; switch (assignmentType) { case EffectCompilerAssignmentType.Constant: result = EffectConstantAssignment.Parse(reader, typeSpecificReader); break; case EffectCompilerAssignmentType.Variable: result = EffectVariableAssignment.Parse(reader, typeSpecificReader); break; case EffectCompilerAssignmentType.ConstantIndex: result = EffectConstantIndexAssignment.Parse(reader, typeSpecificReader); break; case EffectCompilerAssignmentType.VariableIndex: result = EffectVariableIndexAssignment.Parse(reader, typeSpecificReader); break; case EffectCompilerAssignmentType.ExpressionIndex: result = EffectExpressionIndexAssignment.Parse(reader, typeSpecificReader); break; case EffectCompilerAssignmentType.Expression: result = EffectExpressionAssignment.Parse(reader, typeSpecificReader); break; case EffectCompilerAssignmentType.InlineShader: result = EffectInlineShaderAssignment.Parse(reader, typeSpecificReader); break; case EffectCompilerAssignmentType.InlineShader5: result = EffectInlineShader5Assignment.Parse(reader, typeSpecificReader); break; default: throw new ParseException($"Unsupported EffectCompilerAssignmentType {assignmentType}"); } result.MemberType = memberType; result.MemberIndex = memberIndex; result.AssignmentType = assignmentType; result.ValueOffset = valueOffset; return(result); }
public static MSInfo Parse(BytecodeReader reader) { return(new MSInfo() { GroupSharedBytesUsed = reader.ReadUInt32(), GroupSharedBytesDependentOnViewID = reader.ReadUInt32(), PayloadSizeInBytes = reader.ReadUInt32(), MaxOutputVertices = reader.ReadUInt16(), MaxOutputPrimitives = reader.ReadUInt16(), }); }
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 StructuredUnorderedAccessViewDeclarationToken Parse(BytecodeReader reader) { var token0 = reader.ReadUInt32(); return(new StructuredUnorderedAccessViewDeclarationToken { Coherency = token0.DecodeValue <UnorderedAccessViewCoherency>(16, 16), HasOrderPreservingCounter = (token0.DecodeValue(23, 23) == 0), Operand = Operand.Parse(reader, token0.DecodeValue <OpcodeType>(0, 10)), ByteStride = reader.ReadUInt32() }); }
public new static EffectConstantAssignment Parse(BytecodeReader reader, BytecodeReader assignmentReader) { var result = new EffectConstantAssignment(); var assignmentCount = assignmentReader.ReadUInt32(); for (int i = 0; i < assignmentCount; i++) { result.Types.Add((EffectScalarType)assignmentReader.ReadUInt32()); result.Values.Add(Number.Parse(assignmentReader)); } return(result); }