public string GetTypeFormat() { if (MinPrecision == MinPrecision.None) { return(ComponentType.GetDescription()); } else { return(MinPrecision.GetDescription()); } }
public static SignatureParameterDescription Parse(BytecodeReader reader, BytecodeReader parameterReader, ChunkType chunkType, SignatureElementSize size) { uint stream = 0; if (size == SignatureElementSize._7 || size == SignatureElementSize._8) { stream = parameterReader.ReadUInt32(); } uint nameOffset = parameterReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); var result = new SignatureParameterDescription { SemanticName = nameReader.ReadString(), SemanticIndex = parameterReader.ReadUInt32(), SystemValueType = (Name)parameterReader.ReadUInt32(), ComponentType = (RegisterComponentType)parameterReader.ReadUInt32(), Register = parameterReader.ReadUInt32(), Stream = stream, }; uint mask = parameterReader.ReadUInt32(); result.Mask = mask.DecodeValue <ComponentMask>(0, 7); result.ReadWriteMask = mask.DecodeValue <ComponentMask>(8, 15); if (size == SignatureElementSize._8) { MinPrecision minPrecision = (MinPrecision)parameterReader.ReadUInt32(); result.MinPrecision = minPrecision; } // This is my guesswork, but it works so far... if (chunkType == ChunkType.Osg5 || chunkType == ChunkType.Osgn || chunkType == ChunkType.Osg1) { result.ReadWriteMask = (ComponentMask)(ComponentMask.All - result.ReadWriteMask); } return(result); }
public static string GetTypeName(this MinPrecision minPrecision) { switch (minPrecision) { case MinPrecision.Min16f: return("min16float"); case MinPrecision.Min10f: return("min10float"); case MinPrecision.Min12i: return("min12int"); case MinPrecision.Min16i: return("min16int"); case MinPrecision.Min16u: return("min16uint"); default: throw new ArgumentException($"Invalid MinPrecision {minPrecision}"); } }
public override string ToString() { switch (OperandType) { case OperandType.Immediate32: case OperandType.Immediate64: { string result = (OperandType == OperandType.Immediate64) ? "d(" : "l("; bool addSpaces = ParentType != OpcodeType.Mov && ParentType != OpcodeType.MovC && ParentType != OpcodeType.StoreStructured; for (int i = 0; i < NumComponents; i++) { var parentType = ParentType.GetNumberType(); result += (OperandType == OperandType.Immediate64) ? ImmediateValues.GetDouble(i).ToString() : ImmediateValues.GetNumber(i).ToString(parentType); if (i < NumComponents - 1) { result += ","; if (addSpaces) { result += " "; } } } result += ")"; return(result); } case OperandType.Null: { return(OperandType.GetDescription()); } default: { string index = string.Empty; switch (IndexDimension) { case OperandIndexDimension._0D: break; case OperandIndexDimension._1D: index = (Indices[0].Representation == OperandIndexRepresentation.Relative || Indices[0].Representation == OperandIndexRepresentation.Immediate32PlusRelative || !OperandType.RequiresRegisterNumberFor1DIndex()) ? string.Format("[{0}]", Indices[0]) : Indices[0].ToString(); break; case OperandIndexDimension._2D: index = (Indices[0].Representation == OperandIndexRepresentation.Relative || Indices[0].Representation == OperandIndexRepresentation.Immediate32PlusRelative || !OperandType.RequiresRegisterNumberFor2DIndex()) ? string.Format("[{0}][{1}]", Indices[0], Indices[1]) : string.Format("{0}[{1}]", Indices[0], Indices[1]); break; case OperandIndexDimension._3D: index = ParentType.IsDeclaration() ? string.Format("{0}[{1}:{2}]", Indices[0], Indices[1], Indices[2]) : string.Format("{0}[{1}][{2}]", Indices[0], Indices[1], Indices[2]); break; } string components = string.Empty; if (ParentType.OpcodeHasSwizzle()) { switch (SelectionMode) { case Operand4ComponentSelectionMode.Mask: components = ComponentMask.GetDescription(); break; case Operand4ComponentSelectionMode.Swizzle: components = Swizzles[0].GetDescription() + Swizzles[1].GetDescription() + Swizzles[2].GetDescription() + Swizzles[3].GetDescription(); break; case Operand4ComponentSelectionMode.Select1: components = Swizzles[0].GetDescription(); break; default: throw new InvalidOperationException("Unrecognised selection mode: " + SelectionMode); } if (!string.IsNullOrEmpty(components)) { components = "." + components; } } string minPrecision = MinPrecision == OperandMinPrecision.Default ? string.Empty : $" {MinPrecision.GetDescription()}"; return(Modifier.Wrap(string.Format("{0}{1}{2}{3}", GetOperandDescription(), index, components, minPrecision))); } } }
public static SignatureParameterDescription Parse(BytecodeReader reader, BytecodeReader parameterReader, ChunkType chunkType, SignatureElementSize size, ProgramType programType) { uint stream = 0; if (size == SignatureElementSize._7 || size == SignatureElementSize._8) { stream = parameterReader.ReadUInt32(); } uint nameOffset = parameterReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); var result = new SignatureParameterDescription { SemanticName = nameReader.ReadString(), SemanticIndex = parameterReader.ReadUInt32(), SystemValueType = (Name)parameterReader.ReadUInt32(), ComponentType = (RegisterComponentType)parameterReader.ReadUInt32(), Register = parameterReader.ReadUInt32(), Stream = stream, }; uint mask = parameterReader.ReadUInt32(); result.Mask = mask.DecodeValue <ComponentMask>(0, 7); result.ReadWriteMask = mask.DecodeValue <ComponentMask>(8, 15); if (size == SignatureElementSize._8) { MinPrecision minPrecision = (MinPrecision)parameterReader.ReadUInt32(); result.MinPrecision = minPrecision; } // This is my guesswork, but it works so far... if (chunkType == ChunkType.Osg5 || chunkType == ChunkType.Osgn || chunkType == ChunkType.Osg1 || (chunkType == ChunkType.Pcsg && programType == ProgramType.HullShader)) { result.ReadWriteMask = (ComponentMask)(ComponentMask.All - result.ReadWriteMask); } // Vertex and pixel shaders need special handling for SystemValueType in the output signature. if ((programType == ProgramType.PixelShader || programType == ProgramType.VertexShader) && (chunkType == ChunkType.Osg5 || chunkType == ChunkType.Osgn || chunkType == ChunkType.Osg1)) { if (result.Register == 0xffffffff) { switch (result.SemanticName.ToUpper()) { case "SV_DEPTH": result.SystemValueType = Name.Depth; break; case "SV_COVERAGE": result.SystemValueType = Name.Coverage; break; case "SV_DEPTHGREATEREQUAL": result.SystemValueType = Name.DepthGreaterEqual; break; case "SV_DEPTHLESSEQUAL": result.SystemValueType = Name.DepthLessEqual; break; case "SV_STENCILREF": result.SystemValueType = Name.StencilRef; break; } } else if (programType == ProgramType.PixelShader) { result.SystemValueType = Name.Target; } } return(result); }