MetaLocation?TryGetLocation(MetaLocation loc, string name, uint offset) { // TODO: Needs adjustments MetaLocation result; if (!MetaProperties.TryGetValue(name, out result)) { return(null); } if (offset > 0) { // Find location of offset 1 (First location previous to loc) while (result.NodeIndex > loc.NodeIndex || result.NodeIndex == loc.NodeIndex && result.BlockIndex >= loc.BlockIndex) { if (!PrevProperties.TryGetValue(result, out result)) { return(null); } } for (int i = 0; i < offset - 1; i++) { if (!PrevProperties.TryGetValue(result, out result)) { return(null); } } } return(result); }
public PlaceholderValue(MetaProperty mp, MetaLocation loc, Expression value, MetaStage stage) : base(value.Source) { Property = mp; Location = loc; Stage = stage; Value = value; }
public StructureValueCollection Serialize(IList <ITagClass> classList) { var result = new StructureValueCollection(); result.SetInteger("memory address", (MetaLocation != null) ? MetaLocation.AsPointer() : 0); result.SetInteger("class index", (Class != null) ? (uint)classList.IndexOf(Class) : 0xFFFFFFFF); result.SetInteger("datum index salt", Index.Salt); return(result); }
ScopeProcessor(ShaderGenerator g, Scope scope) : base(g.Compiler.Pass) { Generator = g; Location = g.LocationStack.Last(); Property = g.GetProperty(Location); Method = new Method(Property.Source, g.Path.DrawBlock.Method.DeclaringType, null, Modifiers.Private | Modifiers.Static | Modifiers.Generated, g.CreateFieldName(Property, Location), Property.ReturnType, new Parameter[0]); Method.SetBody(scope.CopyNullable(new CopyState(Method))); }
static string GetOutputFileNameCore(MetaLocation location, string fileName) { switch (location) { case MetaLocation.IntermediateOutput: return(fileName.ReplaceEnd(Generator.CSharpFileExtension, Generator.DefaultOutputFileEnd)); case MetaLocation.Project: return(fileName.ReplaceEnd(Generator.CSharpFileExtension, Generator.ProjectOutputFileEnd)); default: throw new InvalidOperationException(); } }
static string GetOutputDirectory(MetaLocation location, BuildConstants buildConstants) { switch (location) { case MetaLocation.IntermediateOutput: return(buildConstants.IntermediateOutputPath); case MetaLocation.Project: return(string.Empty); default: throw new InvalidOperationException(); } }
public Source CreateTrace(MetaProperty mp, MetaLocation loc, List <MetaLocation> circularRefStack) { var errors = FindErrors(loc, circularRefStack); foreach (var e in errors) { Log.Error(Path.Source, e.ErrorCode, e.Message); } var filename = System.IO.Path.Combine(Environment.CacheDirectory, "Traces", Path.DrawBlock.Method.DeclaringType.ToString().ToIdentifier() + "." + CreateLocalName(mp, loc).ToIdentifier() + ".unotrace"); using (var f = Compiler.Disk.CreateText(filename)) { f.WriteLine("Error trace generated on " + DateTime.Now); f.WriteLine(); f.WriteLine("Terminal: " + mp.Name + " in " + mp.Source); f.WriteLine("Drawable: " + Path.DrawableBlock + " in " + Path.DrawableBlock.Source); f.WriteLine("Root: " + Path.DrawBlock + " in " + Path.DrawBlock.Source); f.WriteLine(); f.WriteLine("----------"); for (int i = 0; i < errors.Length; i++) { f.WriteLine(); f.WriteLine(errors[i].ErrorCode + ": " + errors[i].Message); f.WriteLine(); if (errors[i].ReqStatement != null) { f.WriteLine("Req Statement:"); f.WriteLine(" " + errors[i].ReqStatement); f.WriteLine(); } f.WriteLine("Stack Trace:"); for (int j = errors[i].Stack.Length - 1; j >= 0; j--) { var pmp = GetProperty(errors[i].Stack[j]); f.WriteLine(" [" + j + "]: " + pmp.Name + " in " + pmp.Source); } f.WriteLine(); f.WriteLine("----------"); } } return(new Source(FrameScope.Source.Package, filename, 1)); }
TraceError[] FindErrors(MetaLocation loc, List <MetaLocation> circularRefStack) { var trace = new TraceData(); if (circularRefStack != null) { var mp = GetProperty(loc); circularRefStack.Add(loc); trace.Errors.Add(new TraceError(mp.Source, ErrorCode.E2507, "Circular reference to " + mp.Name.Quote() + " detected in " + Path.Quote(), null, circularRefStack.ToArray())); circularRefStack.RemoveLast(); } TraceMetaPropertyLocation(loc, trace); return(trace.Errors.ToArray()); }
public void PlayTitle() { if (MetaLocation.IsNullOrEmpty()) { return; } new Thread(() => { if (!Toolbelt.LaunchCemu(MetaLocation, SelectedGraphicPack)) { return; } TextLog.MesgLog.WriteLog($"Now Playing: {Name}"); }).Start(); }
StageValue ProcessShaderConstant(StageValue s, MetaLocation loc, MetaProperty mp) { s = ProcessStage(s, MetaStage.Volatile, MetaStage.Volatile); var key = s.Value.ToString(); int index; if (!Constants.TryGetValue(key, out index)) { index = DrawState.RuntimeConstants.Count; DrawState.RuntimeConstants.Add(new ShaderVariable(s.Value.ReturnType, CreateShaderName(mp, loc, s.Value), s.Value)); Constants.Add(key, index); } return(new StageValue(new RuntimeConst(s.Value.Source, DrawState, index), MetaStage.Vertex, MetaStage.Pixel)); }
public StructureValueCollection Serialize() { var result = new StructureValueCollection(); uint addr = 0; if (MetaLocation != null) { addr = (uint)MetaLocation.AsPointer(); } result.SetInteger("tag group magic", (Group != null) ? (uint)Group.Magic : 0xFFFFFFFF); result.SetInteger("datum index", Index.Value); result.SetInteger("offset", (uint)Offset); result.SetInteger("data size", (uint)DataSize); return(result); }
Expression EnqueueLocal(Source src, MetaProperty mp, MetaLocation loc, Expression e) { // TODO: Bugs without if test. if (e is PlaceholderArray) { var var = new Variable(src, null, Generator.CreateLocalName(mp, loc, e), e.ReturnType, VariableType.Default, new PlaceholderValue(mp, loc, e, CurrentMetaPropertyStage)); LocalQueue.Add(var); var result = new LoadLocal(e.Source, var); LoadHistory.Add(result); if (result.ReturnType is FixedArrayType) { return(new AddressOf(result)); } return(result); } return(e); }
private void btnUbicazione_Click(object sender, EventArgs e) { MetaData MetaLocation; MetaLocation = Disp.Get("stocklocationview"); MetaLocation.FilterLocked = true; MetaLocation.SearchEnabled = false; MetaLocation.MainSelectionEnabled = true; string edittype; edittype = "tree"; bool res = MetaLocation.Edit(this, edittype, true); if (!res) { return; } Selected = MetaLocation.LastSelectedRow; riempiTextBox(Selected); idstocklocation = Selected["idstocklocation"]; }
MetaDefinition GetValidDefinition(MetaLocation loc) { MetaDefinition result; if (ValidDefinitions.TryGetValue(loc, out result)) { return(result); } // Detect circular references foreach (var ploc in DefinitionLocationStack) { if (ploc == loc) { var mp = GetProperty(loc); Log.Error(CreateTrace(mp, loc, DefinitionLocationStack), ErrorCode.E5003, "Circular reference to " + mp.Name.Quote() + " detected while processing " + Path.Quote()); return(null); } } DefinitionLocationStack.Add(loc); foreach (var def in GetProperty(loc).Definitions) { if (IsDefinitionValid(loc, def)) { DefinitionLocationStack.RemoveLast(); Path.ReferencedMetaProperties.Add(loc, true); ValidDefinitions.Add(loc, def); return(def); } } DefinitionLocationStack.RemoveLast(); Path.ReferencedMetaProperties.Add(loc, false); ValidDefinitions.Add(loc, null); return(null); }
StageValue ProcessMetaProperty(MetaLocation loc, bool required = true) { StageValue result; if (ProcessedMetaProperties.TryGetValue(loc, out result)) { return(new StageValue(result.Value.CopyExpression(new CopyState(DrawState.Path.DrawBlock.Method)), result.MinStage, result.MaxStage)); } var mp = GetProperty(loc); var def = GetValidDefinition(loc); if (def == null) { if (required) { Log.Error(CreateTrace(mp, loc, null), ErrorCode.E5004, "No valid definition of " + mp.Name.Quote() + " was found in " + Path.Quote()); return(new StageValue(Expression.Invalid, MetaStage.Const)); } return(new StageValue(null, MetaStage.Const)); } // Detect circular references (should not happen) foreach (var ploc in LocationStack) { if (ploc == loc) { Log.Error(CreateTrace(mp, loc, LocationStack), ErrorCode.E5005, "Circular reference to " + mp.Name.Quote() + " detected while processing " + Path.Quote()); return(new StageValue(Expression.Invalid, MetaStage.Const)); } } LocationStack.Add(loc); switch (def.Value.StatementType) { case StatementType.Expression: result = ProcessValue(def.Value as Expression); result.Value = new FunctionCompiler(Compiler, mp).CompileImplicitCast(def.Value.Source, mp.ReturnType, result.Value); break; case StatementType.Scope: result = ScopeProcessor.Process(this, def.Value as Scope); break; case StatementType.FixedArrayDeclaration: result = ProcessFixedArrayDeclaration(def.Value as FixedArrayDeclaration); break; default: // Should not happen Log.Error(def.Value.Source, ErrorCode.I5006, "<" + def.Value.StatementType + "> is not supported by ShaderGenerator"); result = new StageValue(Expression.Invalid, MetaStage.Const); ProcessedMetaProperties.Add(loc, result); return(result); } LocationStack.RemoveLast(); if (!InlineOnStage(result.MinStage, result.Value)) { MetaStage resultStage; Scope resultScope; switch (result.MinStage) { case MetaStage.Pixel: resultStage = MetaStage.Pixel; resultScope = PixelScope; break; case MetaStage.Vertex: resultStage = MetaStage.Vertex; resultScope = VertexScope; break; case MetaStage.Volatile: resultStage = MetaStage.Volatile; resultScope = FrameScope; break; default: resultStage = MetaStage.ReadOnly; resultScope = InitScope; break; } var val = new PlaceholderValue(mp, loc, result.Value, resultStage); result = new StageValue(new PlaceholderReference(val), val.Stage); resultScope.Statements.Add(new VariableDeclaration(mp.Source, null, CreateLocalName(mp, loc), val.ReturnType, VariableType.Default, val)); } else if (!(result.Value is PlaceholderReference) && !(result.Value is PlaceholderValue) && !(result.Value is Constant)) { result.Value = new PlaceholderValue(mp, loc, result.Value, MetaStage.Undefined); } ProcessedMetaProperties.Add(loc, result); return(result); }
public void Generate() { // Verify and add path to meta property cache for (int i = 0; i < Path.Nodes.Length; i++) { for (int j = Path.Nodes[i].Top; j <= Path.Nodes[i].Bottom; j++) { var mp = (MetaProperty)Path.Nodes[i].Block.Members[j]; var loc = new MetaLocation(i, j); MetaLocation ploc; if (MetaProperties.TryGetValue(mp.Name, out ploc)) { var pmp = GetProperty(ploc); // TODO: This is not correct if (!pmp.ReturnType.Equals(mp.ReturnType)) { Log.Error(mp.Source, ErrorCode.E5000, mp.Name.Quote() + " does not have the same type as the previous declaration at " + pmp.Source + " when exposed from " + Path.Quote() + " at " + Path.Source); } PrevProperties.Add(loc, ploc); } MetaProperties[mp.Name] = loc; } } // Resolve terminal properties foreach (var tp in Backend.ShaderBackend.OutputProperties) { MetaLocation loc; if (!MetaProperties.TryGetValue(tp.Name, out loc)) { Log.Error(Path.Source, ErrorCode.I5001, "Terminal property " + tp.Name.Quote() + " was not found in " + Path.Quote()); continue; } var mp = GetProperty(loc); var dt = ILFactory.GetType(Path.Source, tp.TypeString); if (!mp.ReturnType.Equals(dt)) { Log.Error(Path.Source, ErrorCode.I5001, "Terminal property " + tp.Name.Quote() + " was found with type " + mp.ReturnType.Quote() + " when " + dt.Quote() + " was expected"); continue; } var sym = ProcessMetaProperty(loc, tp.Required); if (sym.Value == null) { continue; } LocationStack.Add(loc); switch (tp.Stage) { case MetaStage.Vertex: sym = ProcessStage(sym, MetaStage.Vertex, MetaStage.Vertex); DrawState.VertexShader.Terminals[tp.Name] = sym.Value; break; case MetaStage.Pixel: sym = ProcessStage(sym, MetaStage.Pixel, MetaStage.Pixel); DrawState.PixelShader.Terminals[tp.Name] = sym.Value; break; default: sym = ProcessStage(sym, MetaStage.Volatile, MetaStage.Volatile); DrawState.Terminals[tp.Name] = sym.Value; break; } LocationStack.RemoveLast(); } if (!DrawState.Terminals.ContainsKey("VertexCount")) { var loc = MetaProperties["VertexCount"]; var mp = GetProperty(loc); if (DetectedVertexCounts.Count == 1) { LocationStack.Add(loc); var fc = new FunctionCompiler(Compiler, IL); DrawState.Terminals["VertexCount"] = fc.CompileImplicitCast(DetectedVertexCounts[0].Value.Source, mp.ReturnType, ProcessStage(DetectedVertexCounts[0], MetaStage.Volatile, MetaStage.Volatile).Value); LocationStack.RemoveLast(); } else { Log.Error(CreateTrace(mp, loc, null), ErrorCode.E5002, "Unable to auto detect 'VertexCount' in " + Path.Quote()); } } MetaPropertyEmitter.Emit(this); ShaderProcessor.ProcessShader(this, DrawState.VertexShader); ShaderProcessor.ProcessShader(this, DrawState.PixelShader); ProcessStructs(); var p = new IndirectionTransform(Compiler.Pass); DrawState.VertexShader.Visit(p); DrawState.PixelShader.Visit(p); }
internal string CreateFieldName(MetaProperty mp, MetaLocation loc, Expression value = null) { return(Path.DrawBlock.Method.UnoName + "_" + CreateLocalName(mp, loc, value)); }
internal string CreateLocalName(MetaProperty mp, MetaLocation loc, Expression value = null) { return(GetBasename(mp, value) + "_" + Path.Suffix + "_" + loc.NodeIndex + "_" + loc.BlockIndex + "_" + FieldNameCount++); }
internal string CreateShaderName(MetaProperty mp, MetaLocation loc, Expression value = null) { return(GetBasename(mp, value) + "_" + loc.NodeIndex + "_" + loc.BlockIndex + "_" + ShaderNameCount++); }
bool TraceMetaPropertyLocation(MetaLocation loc, TraceData trace) { if (trace.VisitedLocations.Contains(loc)) { return(true); } trace.VisitedLocations.Add(loc); var mp = GetProperty(loc); // Detect circular references (should not happen) foreach (var ploc in trace.Stack) { if (ploc == loc) { return(false); } } if (mp.Definitions.Length == 0) { trace.Stack.Add(loc); trace.Errors.Add(new TraceError(mp.Source, ErrorCode.E2508, "Meta property " + mp.Name.Quote() + " has no definitions in " + Path.Quote(), null, trace.Stack.ToArray())); trace.Stack.RemoveLast(); return(true); } trace.Stack.Add(loc); bool errorsFound = false; for (int i = 0; i < mp.Definitions.Length; i++) { var def = mp.Definitions[i]; foreach (var req in def.Requirements) { if (Path.FailedReqStatements.Contains(Tuple.Create(loc, def, req))) { errorsFound = true; switch (req.Type) { case ReqStatementType.Object: { var ri = req as ReqObject; trace.Errors.Add(new TraceError(req.Source, ErrorCode.E2500, "An instance of " + ri.ObjectType.Quote() + " is not available in " + Path.Quote(), req, trace.Stack.ToArray())); break; } case ReqStatementType.File: { var rf = req as ReqFile; trace.Errors.Add(new TraceError(req.Source, ErrorCode.E2501, "Required file " + rf.Filename.Quote() + " does not exist", req, trace.Stack.ToArray())); break; } case ReqStatementType.Property: { var rmp = req as ReqProperty; var rloc = TryGetLocation(loc, rmp.PropertyName, rmp.Offset); if (rloc == null) { trace.Errors.Add(new TraceError(req.Source, ErrorCode.E2502, "Meta property " + rmp.PropertyName.Quote() + " was not found in " + Path.Quote(), req, trace.Stack.ToArray())); break; } var rdt = GetProperty(rloc.Value).ReturnType; if (rmp.PropertyType != null && !rmp.PropertyType.Equals(rdt)) { trace.Errors.Add(new TraceError(req.Source, ErrorCode.E2503, "Meta property " + rmp.PropertyName.Quote() + " did not have expected type " + rmp.PropertyType.Quote() + " in " + Path.Quote(), req, trace.Stack.ToArray())); break; } if (rmp.Tag != null) { var rdef = GetValidDefinition(rloc.Value); if (rdef != null && !rdef.Tags.Contains(rmp.Tag)) { trace.Errors.Add(new TraceError(req.Source, ErrorCode.E2504, "Meta property " + rmp.PropertyName.Quote() + " did not specify required tag " + rmp.Tag.Quote() + " in " + Path.Quote(), req, trace.Stack.ToArray())); break; } } if (!TraceMetaPropertyLocation(rloc.Value, trace)) { trace.Errors.Add(new TraceError(req.Source, ErrorCode.E2505, "Meta property " + rmp.PropertyName.Quote() + " could not be used in " + Path.Quote(), req, trace.Stack.ToArray())); break; } break; } default: trace.Errors.Add(new TraceError(req.Source, ErrorCode.E2506, "Unsupported req statement", req, trace.Stack.ToArray())); break; } continue; } } } trace.Stack.RemoveLast(); return(errorsFound); }
internal StageValue ProcessStageChange(StageValue s, MetaStage fromStage, MetaStage toStage, MetaLocation loc, MetaProperty mp) { if (s.Value == null) { return(new StageValue(null, toStage)); } if (s.MinStage > fromStage) { Log.Error(s.Value.Source, ErrorCode.I5016, "Stage error"); return(new StageValue(Expression.Invalid, toStage)); } switch (toStage) { case MetaStage.Pixel: case MetaStage.Vertex: if (fromStage == MetaStage.Vertex && toStage == MetaStage.Pixel) { // Vertex -> Pixel: Varying var key = s.Value.ToString(); int index; if (!Varyings.TryGetValue(key, out index)) { index = DrawState.Varyings.Count; DrawState.Varyings.Add(new ShaderVariable(s.Value.ReturnType, CreateShaderName(mp, loc, s.Value), s.Value)); Varyings.Add(key, index); } return(new StageValue(new LoadVarying(s.Value.Source, DrawState, index), MetaStage.Pixel, MetaStage.Pixel)); } else if (s.Value.ReturnType == Essentials.Bool || s.Value.ReturnType == Essentials.Int) { return(ProcessShaderConstant(s, loc, mp)); } else { // Init,Frame -> Vertex,Pixel: Uniform s = ProcessStage(s, MetaStage.Volatile, MetaStage.Volatile); var val = s.Value.ActualValue; var dt = val.ReturnType; var key = val.ToString(); int index; if (!Uniforms.TryGetValue(key, out index)) { index = DrawState.Uniforms.Count; switch (dt.TypeType) { case TypeType.FixedArray: // Ugly workaround. ResolvedMetaPropertyValue could already be an address if (!(val is PlaceholderValue && (val as PlaceholderValue).Value is AddressOf)) { val = new AddressOf(val.ActualValue, AddressType.Const); } break; case TypeType.RefArray: var at = dt as RefArrayType; var et = at.ElementType; var size = ProcessShaderConstant( new StageValue(ILFactory.GetProperty(s.Value.Source, s.Value, "Length"), s.MinStage, s.MaxStage), loc, mp).Value; dt = new FixedArrayType(s.Value.Source, et, size, Essentials.Int); break; } DrawState.Uniforms.Add(new ShaderVariable(dt, CreateShaderName(mp, loc, val), val)); Uniforms.Add(key, index); } Expression u = new LoadUniform(s.Value.Source, DrawState, index); if (u.ReturnType.IsFixedArray) { u = new AddressOf(u, AddressType.Const); } return(new StageValue(u, MetaStage.Vertex, MetaStage.Pixel)); } case MetaStage.Volatile: if (fromStage <= MetaStage.ReadOnly) { // Init -> Frame: Field var src = s.Value.Source; var dt = Path.DrawBlock.Method.DeclaringType; var obj = new This(src, dt).Address; var key = s.Value.ToString(); Field field; if (!Fields.TryGetValue(key, out field)) { for (int i = 0; i < InitScope.Statements.Count; i++) { if (InitScope.Statements[i] is StoreField) { var sf = InitScope.Statements[i] as StoreField; if (sf.Field.ReturnType.Equals(s.Value.ReturnType) && sf.Value.ToString() == key) { field = sf.Field; } } } if (field == null) { field = new Field(src, dt, CreateFieldName(mp, loc, s.Value), null, Modifiers.Private | Modifiers.Generated, 0, s.Value.ReturnType); dt.Fields.Add(field); InitScope.Statements.Add(new StoreField(src, obj, field, s.Value)); } Fields.Add(key, field); } return(new StageValue(new LoadField(src, obj, field), MetaStage.ReadOnly, MetaStage.Volatile)); } break; case MetaStage.ReadOnly: return(s); } Log.Error(s.Value.Source, ErrorCode.E5017, fromStage.ToLiteral().Quote() + " cannot be accessed from " + toStage.ToLiteral() + " stage while processing " + mp.Name.Quote() + " at " + mp.Source + " in " + Path.Quote() + " at " + Path.Source); return(new StageValue(Expression.Invalid, MetaStage.Const)); }
bool IsDefinitionValid(MetaLocation loc, MetaDefinition def) { foreach (var req in def.Requirements) { switch (req.Type) { case ReqStatementType.File: { if (File.Exists((req as ReqFile).Filename)) { continue; } Path.FailedReqStatements.Add(Tuple.Create(loc, def, req)); return(false); } case ReqStatementType.Object: { var obj = TryGetObject(loc); var dt = (req as ReqObject).ObjectType; if (obj != null && obj.ReturnType.IsSubclassOfOrEqual(dt)) { continue; } Path.FailedReqStatements.Add(Tuple.Create(loc, def, req)); return(false); } case ReqStatementType.Property: { var rmp = req as ReqProperty; var rloc = TryGetLocation(loc, rmp.PropertyName, rmp.Offset); if (rloc == null) { Path.FailedReqStatements.Add(Tuple.Create(loc, def, req)); return(false); } var rdt = GetProperty(rloc.Value).ReturnType; if (rmp.PropertyType != null && !rmp.PropertyType.Equals(rdt)) { Path.FailedReqStatements.Add(Tuple.Create(loc, def, req)); return(false); } var rdef = GetValidDefinition(rloc.Value); if (rdef == null || rmp.Tag != null && !rdef.Tags.Contains(rmp.Tag)) { Path.FailedReqStatements.Add(Tuple.Create(loc, def, req)); return(false); } continue; } } Path.FailedReqStatements.Add(Tuple.Create(loc, def, req)); return(false); } return(true); }
public MetaLocationAttribute(MetaLocation location, string fileName = null) : this(fileName, location) { }
internal MetaProperty GetProperty(MetaLocation loc) { return((MetaProperty)Path.Nodes[loc.NodeIndex].Block.Members[loc.BlockIndex]); }
Expression TryGetObject(MetaLocation loc) { return(Path.Nodes[loc.NodeIndex].Object); }