Example #1
0
 private string GetNodeCategory(SpirvInstruction instruction)
 {
     /*
      * Unknown,
      * Function,
      * Converter,
      * Procedure,
      * Event,
      * Parameter,
      * Value,
      * Result
      */
     if (instruction.Name == "OpConstant")
     {
         return("Value");
     }
     if (instruction.Name == "OpReturn" || instruction.Name == "OpReturnValue")
     {
         return("Result");
     }
     if (instruction.Name == "OpFunctionParameter" || instruction.Name == "OpVariable")
     {
         return("Parameter");
     }
     if (instruction.HasDefaultExit)
     {
         return("Procedure");
     }
     if (instruction.IdResultType != null)
     {
         return("Function");
     }
     return("Unknown");
 }
Example #2
0
        public NodeTemplate(SpirvInstruction instruction)
        {
            _instruction = instruction;
            opname       = _instruction.Name;
            switch (instruction.Kind)
            {
            case InstructionKind.Type:
                baseClass = "SpirvTypeBase";
                name      = _instruction.Name.Substring(2);
                break;

            default:
                baseClass = _instruction.HasDefaultEnter ? "ExecutableNode" : "Node";
                name      = _instruction.Name.Substring(2);
                break;
            }

            _operands = new List <KeyValuePair <string, string> >(_instruction.Operands.Count + 1);
            if (_instruction.IdResultType != null)
            {
                _operands.Add(new KeyValuePair <string, string>("ResultType", "SpirvTypeBase"));
            }
            _operands.AddRange(_instruction.Operands.Select(MakeOperandKeyValue));
        }
 private InstructionKind EvaluateInstructionKind(SpirvInstruction spirvInstruction)
 {
     if (spirvInstruction.LastInstructionInABlock)
     {
         return(InstructionKind.Executable);
     }
     if (spirvInstruction.Name.StartsWith("OpType"))
     {
         return(InstructionKind.Type);
     }
     if (spirvInstruction.Name == "OpFunction")
     {
         return(InstructionKind.Executable);
     }
     if (spirvInstruction.Name == "OpFunctionCall")
     {
         return(InstructionKind.Executable);
     }
     if (spirvInstruction.IdResultType != null)
     {
         return(InstructionKind.Function);
     }
     if (spirvInstruction.Name == "OpDecorate")
     {
         return(InstructionKind.Other);
     }
     if (spirvInstruction.OpCode <= 40)
     {
         return(InstructionKind.Other);
     }
     if (spirvInstruction.Class == InstructionClass.Annotation)
     {
         return(InstructionKind.Other);
     }
     return(InstructionKind.Executable);
 }
Example #4
0
 public InstructionTemplate(SpirvInstruction instruction)
 {
     _instruction = instruction;
 }
Example #5
0
 public TypeTemplate(SpirvInstruction instruction)
 {
     _instruction = instruction;
     name         = _instruction.Name.Substring(2);
 }
        private SpirvInstruction CreateInstruction(Instruction instruction)
        {
            var spirvInstruction = new SpirvInstruction()
            {
                Name   = instruction.opname,
                OpCode = instruction.opcode,
                Class  = GetInstructionClass(instruction.@class)
            };

            if (instruction.capabilities != null)
            {
                spirvInstruction.Capabilities.AddRange(instruction.capabilities);
            }
            if (instruction.extensions != null)
            {
                spirvInstruction.Extensions.AddRange(instruction.extensions);
            }
            switch (spirvInstruction.Name)
            {
            case "OpUnreachable":
            case "OpReturnValue":
            case "OpReturn":
            case "OpKill":
            case "OpSwitch":
            case "OpBranchConditional":
            case "OpBranch":
                spirvInstruction.LastInstructionInABlock = true;
                break;
            }

            for (var index = 0; index < instruction.operands.Count; index++)
            {
                var operand      = instruction.operands[index];
                var spirvOperand = CreateOperand(instruction, operand);
                switch (spirvOperand.Kind)
                {
                case SpirvOperandKind.IdResult:
                    if (instruction.operands[0].kind == "IdResultType")
                    {
                        if (index != 1)
                        {
                            throw new Exception("IdResult expected to be second operand");
                        }
                    }
                    else
                    {
                        if (index != 0)
                        {
                            throw new Exception("IdResult expected to be first operand");
                        }
                    }
                    spirvInstruction.IdResult = spirvOperand;
                    break;

                case SpirvOperandKind.IdResultType:
                    if (index != 0)
                    {
                        throw new Exception("IdResultType expected to be first operand");
                    }
                    spirvInstruction.IdResultType = spirvOperand;
                    break;

                default:
                    int suffix = 1;
                    var prefix = spirvOperand.Name;
                    foreach (var op in spirvInstruction.Operands)
                    {
                        if (op.Name == spirvOperand.Name)
                        {
                            ++suffix;
                            spirvOperand.Name = $"{prefix}{suffix}";
                        }
                    }
                    spirvInstruction.Operands.Add(spirvOperand);
                    break;
                }
            }

            spirvInstruction.Kind = EvaluateInstructionKind(spirvInstruction);
            switch (spirvInstruction.Kind)
            {
            case InstructionKind.Function:
                spirvInstruction.HasDefaultEnter = false;
                spirvInstruction.HasDefaultExit  = false;
                break;

            case InstructionKind.Executable:
                spirvInstruction.HasDefaultEnter = spirvInstruction.Name != "OpFunction";
                if (spirvInstruction.LastInstructionInABlock)
                {
                    spirvInstruction.HasDefaultExit = false;
                }
                else
                {
                    spirvInstruction.HasDefaultExit = true;
                }
                break;

            default:
                spirvInstruction.HasDefaultEnter = false;
                spirvInstruction.HasDefaultExit  = false;
                break;
            }

            return(spirvInstruction);
        }