Esempio n. 1
0
        public ShaderIrLabel GetLabel(int Position)
        {
            if (LabelsToInsert.TryGetValue(Position, out ShaderIrLabel Label))
            {
                return(Label);
            }

            Label = new ShaderIrLabel();

            LabelsToInsert.Add(Position, Label);

            return(Label);
        }
Esempio n. 2
0
        private void PrintBlockScope(
            ShaderIrNode[] Nodes,
            int Start,
            int Count,
            string ScopeName,
            int IdentationLevel)
        {
            string Identation = string.Empty;

            for (int Index = 0; Index < IdentationLevel - 1; Index++)
            {
                Identation += IdentationStr;
            }

            if (ScopeName != string.Empty)
            {
                ScopeName += " ";
            }

            SB.AppendLine(Identation + ScopeName + "{");

            string LastLine = Identation + "}";

            if (IdentationLevel > 0)
            {
                Identation += IdentationStr;
            }

            for (int Index = Start; Index < Start + Count; Index++)
            {
                ShaderIrNode Node = Nodes[Index];

                if (Node is ShaderIrCond Cond)
                {
                    string IfExpr = GetSrcExpr(Cond.Pred, true);

                    if (Cond.Not)
                    {
                        IfExpr = "!(" + IfExpr + ")";
                    }

                    if (Cond.Child is ShaderIrOp Op && Op.Inst == ShaderIrInst.Bra)
                    {
                        ShaderIrLabel Label = (ShaderIrLabel)Op.OperandA;

                        int Target = FindLabel(Nodes, Label, Index + 1);

                        int IfCount = Target - Index - 1;

                        string SubScopeName = "if (!" + IfExpr + ")";

                        if (Nodes[Index + IfCount] is ShaderIrOp LastOp && LastOp.Inst == ShaderIrInst.Bra)
                        {
                            Target = FindLabel(Nodes, (ShaderIrLabel)LastOp.OperandA, Index + 1);

                            int ElseCount = Target - (Index + 1 + IfCount);

                            PrintBlockScope(Nodes, Index + 1, IfCount - 1, SubScopeName, IdentationLevel + 1);

                            PrintBlockScope(Nodes, Index + 1 + IfCount, ElseCount, "else", IdentationLevel + 1);

                            Index += IfCount + ElseCount;
                        }
                        else
                        {
                            PrintBlockScope(Nodes, Index + 1, IfCount, SubScopeName, IdentationLevel + 1);

                            Index += IfCount;
                        }
                    }