Exemple #1
0
 public ShaderReflection With(Capability node)
 {
     CapabilityInstructions.Add(node); return(this);
 }
Exemple #2
0
        public void BuildTree(Shader shader)
        {
            _shader      = shader;
            _nodeMap     = new IdRefDictionary <Node>(_shader.Bound);
            _decorations = new IdRefDictionary <NodeDecorations>(_shader.Bound);
            Function currentFunction = null;

            for (var index = 0; index < _shader.Instructions.Count; index++)
            {
                var instruction = _shader.Instructions[index];
                switch (instruction.OpCode)
                {
                case Op.OpCapability:
                    CapabilityInstructions.Add((Capability)ParseNode(instruction));
                    break;

                case Op.OpExtInstImport:
                    ExtInstImportInstructions.Add((ExtInstImport)ParseNode(instruction));
                    break;

                case Op.OpExtension:
                    ExtensionInstructions.Add((Extension)ParseNode(instruction));
                    break;

                case Op.OpMemoryModel:
                    MemoryModel = (MemoryModel)ParseNode(instruction);
                    break;

                case Op.OpEntryPoint:
                {
                    EntryPointInstructions.Add((EntryPoint)ParseNode(instruction));
                    break;
                }

                case Op.OpExecutionMode:
                {
                    ExecutionModeInstructions.Add((ExecutionMode)ParseNode(instruction));
                    break;
                }

                case Op.OpName:
                    _decorations.GetRef(((OpName)instruction).Target).Name = (OpName)instruction;
                    break;

                case Op.OpMemberName:
                    _decorations.GetRef(((OpMemberName)instruction).Type).AddDecoration(instruction);
                    break;

                case Op.OpDecorate:
                    _decorations.GetRef(((OpDecorate)instruction).Target).AddDecoration(instruction);
                    break;

                case Op.OpDecorateId:
                    _decorations.GetRef(((OpDecorateId)instruction).Target).AddDecoration(instruction);
                    break;

                case Op.OpDecorateString:
                    _decorations.GetRef(((OpDecorateString)instruction).Target).AddDecoration(instruction);
                    break;

                case Op.OpMemberDecorate:
                    _decorations.GetRef(((OpMemberDecorate)instruction).StructureType).AddDecoration(instruction);
                    break;

                case Op.OpGroupDecorate:
                case Op.OpGroupMemberDecorate:
                case Op.OpDecorationGroup:
                    throw new NotImplementedException(instruction.OpCode + " not implemented yet.");

                case Op.OpLine:
                case Op.OpExtInst:
                    break;

                case Op.OpTypeVoid:
                    ParseVoid((OpTypeVoid)instruction);
                    break;

                case Op.OpTypeBool:
                    ParseBool((OpTypeBool)instruction);
                    break;

                case Op.OpTypeInt:
                    ParseInt((OpTypeInt)instruction);
                    break;

                case Op.OpTypeFloat:
                    ParseFloat((OpTypeFloat)instruction);
                    break;

                case Op.OpTypeVector:
                    ParseVector((OpTypeVector)instruction);
                    break;

                case Op.OpTypeMatrix:
                    ParseMatrix((OpTypeMatrix)instruction);
                    break;

                case Op.OpFunction:
                {
                    var function = ParseNode(instruction);
                    currentFunction = (Function)function;
                    break;
                }

                case Op.OpFunctionParameter:
                {
                    var param = (FunctionParameter)ParseNode(instruction);
                    currentFunction.Parameters.Add(param);
                    break;
                }

                case Op.OpFunctionEnd:
                {
                    ParseNode(instruction);
                    currentFunction = null;
                    break;
                }

                default:
                    ParseNode(instruction);
                    break;
                }
            }

            // Fix forward references.
            INodeWithNext prevSequentialInstruction = null;

            foreach (var instructionAndNode in _nodes)
            {
                var key   = instructionAndNode.Key;
                var value = instructionAndNode.Value;
                value.SetUp(key, this);
                if (value is ExecutableNode executableNode)
                {
                    if (prevSequentialInstruction != null)
                    {
                        prevSequentialInstruction.Next = executableNode;
                    }
                    prevSequentialInstruction = null;
                }

                if (value is INodeWithNext nodeWithNext)
                {
                    prevSequentialInstruction = nodeWithNext;
                }
            }
        }